* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
    line-height: 1.6;
}

.alloy-phase-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    background: white;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

header {
    text-align: center;
    padding: 30px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 10px;
    margin-bottom: 30px;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    font-weight: 700;
}

header .subtitle {
    font-size: 1.1em;
    opacity: 0.95;
}

main {
    padding: 0 20px 20px;
}

/* System Selector */
.system-selector {
    margin-bottom: 30px;
    text-align: center;
}

.system-selector h3 {
    font-size: 1.5em;
    margin-bottom: 15px;
    color: #2c3e50;
}

.system-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

.system-btn {
    padding: 12px 24px;
    font-size: 1em;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.system-btn:hover {
    background: #667eea;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.system-btn.active {
    background: #667eea;
    color: white;
}

/* Visualization Area */
.visualization-area {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

.diagram-section,
.microstructure-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.diagram-section h3,
.microstructure-section h3 {
    font-size: 1.3em;
    margin-bottom: 15px;
    color: #2c3e50;
    text-align: center;
}

#mainCanvas,
#microCanvas {
    width: 100%;
    height: auto;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.diagram-info,
.micro-info {
    margin-top: 15px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.info-item {
    margin-bottom: 8px;
    font-size: 0.95em;
}

.info-item:last-child {
    margin-bottom: 0;
}

/* Controls Panel */
.controls-panel {
    background: #f8f9fa;
    padding: 25px;
    border-radius: 10px;
    margin-bottom: 30px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.controls-panel h3 {
    font-size: 1.5em;
    margin-bottom: 20px;
    color: #2c3e50;
    text-align: center;
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.control-group {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.control-group h4 {
    font-size: 1.1em;
    margin-bottom: 15px;
    color: #2c3e50;
    border-bottom: 2px solid #667eea;
    padding-bottom: 8px;
}

.control-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #555;
}

.control-group input[type="range"] {
    width: 100%;
    margin-bottom: 15px;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.control-group input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    border: none;
}

.checkbox-label {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    cursor: pointer;
}

.checkbox-input {
    margin-right: 10px;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Lever Rule Section */
.lever-rule-section,
.cooling-curve-section {
    background: white;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 25px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.lever-rule-section h3,
.cooling-curve-section h3 {
    font-size: 1.3em;
    margin-bottom: 15px;
    color: #2c3e50;
}

.lever-rule-content {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 6px;
}

.formula-display {
    margin-bottom: 15px;
    padding: 12px;
    background: white;
    border-radius: 6px;
    border-left: 4px solid #667eea;
}

.formula-label {
    font-weight: 600;
    color: #2c3e50;
    margin-right: 10px;
}

.formula {
    font-family: 'Courier New', monospace;
    font-size: 1.1em;
    color: #667eea;
}

.lever-calculations {
    margin-top: 15px;
}

.lever-item {
    padding: 8px 12px;
    background: white;
    margin-bottom: 8px;
    border-radius: 4px;
    font-size: 0.95em;
}

.lever-item:last-child {
    margin-bottom: 0;
}

/* Formulas Section */
.formulas-section {
    background: white;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 25px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.formulas-section h3 {
    font-size: 1.3em;
    margin-bottom: 15px;
    color: #2c3e50;
}

.formula-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.formula-item {
    padding: 12px;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 4px solid #667eea;
}

/* Phase Regions Section */
.phase-regions-section {
    background: white;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 25px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.phase-regions-section h3 {
    font-size: 1.3em;
    margin-bottom: 15px;
    color: #2c3e50;
}

.regions-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.region-item {
    padding: 12px;
    background: #f8f9fa;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.region-name {
    font-weight: 600;
    color: #667eea;
    font-size: 1.1em;
}

.region-desc {
    font-size: 0.9em;
    color: #666;
}

/* Instructions */
.instructions {
    background: #e8f4f8;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 25px;
    border-left: 4px solid #17a2b8;
}

.instructions h4 {
    font-size: 1.2em;
    margin-bottom: 12px;
    color: #0c5460;
}

.instructions ul {
    list-style-position: inside;
    color: #495057;
}

.instructions li {
    margin-bottom: 8px;
    line-height: 1.5;
}

/* Explanation Section */
.explanation {
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.explanation h2 {
    font-size: 2em;
    margin-bottom: 20px;
    color: #2c3e50;
    border-bottom: 3px solid #667eea;
    padding-bottom: 10px;
}

.explanation h3 {
    font-size: 1.5em;
    margin-top: 25px;
    margin-bottom: 15px;
    color: #2c3e50;
}

.explanation p {
    margin-bottom: 15px;
    line-height: 1.8;
    color: #495057;
    text-align: justify;
}

/* Micro Details */
.micro-details {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.micro-phase {
    padding: 8px 12px;
    background: #667eea;
    color: white;
    border-radius: 20px;
    font-size: 0.9em;
    font-weight: 500;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .visualization-area {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .alloy-phase-container {
        padding: 10px;
    }

    header h1 {
        font-size: 1.8em;
    }

    .controls-grid {
        grid-template-columns: 1fr;
    }

    .system-buttons {
        flex-direction: column;
        align-items: stretch;
    }

    .regions-list {
        grid-template-columns: 1fr;
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: #5568d3;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.diagram-section,
.microstructure-section,
.controls-panel {
    animation: fadeIn 0.5s ease-out;
}

/* Loading State */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(102, 126, 234, 0.3);
    border-radius: 50%;
    border-top-color: #667eea;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
