* {
    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%);
    min-height: 100vh;
    padding: 20px;
}

.binary-phase-container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    color: white;
    padding: 30px;
    text-align: center;
}

header h1 {
    font-size: 2.2rem;
    font-weight: 700;
    margin-bottom: 10px;
}

header .subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

main {
    padding: 30px;
}

.system-selector {
    text-align: center;
    margin-bottom: 25px;
}

.system-selector h3 {
    font-size: 1.2rem;
    font-weight: 700;
    color: #0c4a6e;
    margin-bottom: 15px;
}

.system-options {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.system-btn {
    padding: 10px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    border: 2px solid #059669;
    background: white;
    color: #059669;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.system-btn:hover {
    background: #059669;
    color: white;
    transform: translateY(-2px);
}

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

.main-display {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 20px;
    margin-bottom: 30px;
}

.diagram-container {
    background: #f8fafc;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

#phaseDiagramCanvas {
    width: 100%;
    height: 450px;
    display: block;
}

.microstructure-panel {
    background: #f8fafc;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.microstructure-panel h4 {
    font-size: 1rem;
    font-weight: 700;
    color: #0c4a6e;
    margin-bottom: 15px;
}

#microstructureCanvas {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.microstructure-info {
    margin-top: 15px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: #374151;
}

.point-control {
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    border-radius: 12px;
    padding: 25px;
    margin-bottom: 30px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.point-control h3 {
    font-size: 1.3rem;
    font-weight: 700;
    color: #0c4a6e;
    margin-bottom: 20px;
}

.control-sliders {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 25px;
}

.slider-group {
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.slider-group label {
    display: block;
    font-weight: 600;
    color: #374151;
    margin-bottom: 10px;
    font-size: 0.95rem;
}

.slider-group label span:last-child {
    color: #059669;
    font-weight: 700;
}

.slider-group input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e2e8f0;
    outline: none;
}

.slider-group input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #059669;
    cursor: pointer;
    transition: all 0.2s ease;
}

.slider-group input[type="range"]::-webkit-slider-thumb:hover {
    background: #047857;
    transform: scale(1.1);
}

.phase-state-display {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 25px;
}

.state-item {
    background: white;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.state-item span:first-child {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: #64748b;
    margin-bottom: 8px;
}

.phase-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: #059669;
}

.fraction-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: #3b82f6;
}

.lever-rule-panel {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.lever-rule-panel h4 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #0c4a6e;
    margin-bottom: 15px;
}

.lever-rule-formula {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.formula-display {
    background: #f0fdf4;
    padding: 12px;
    border-radius: 6px;
    text-align: center;
}

.formula-label {
    font-family: 'Times New Roman', serif;
    font-size: 1.1rem;
    color: #059669;
    font-weight: 600;
}

.lever-values {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.lever-item {
    font-size: 0.9rem;
    color: #374151;
    padding: 8px;
    background: #f8fafc;
    border-radius: 4px;
}

.controls-panel {
    background: #f8fafc;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    margin-bottom: 30px;
}

.controls-panel h3 {
    font-size: 1.3rem;
    font-weight: 700;
    color: #0c4a6e;
    margin-bottom: 20px;
}

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

.control-group {
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.control-group label {
    display: block;
    font-weight: 600;
    color: #374151;
    margin-bottom: 10px;
    font-size: 0.95rem;
}

.control-group label span:last-child {
    color: #059669;
    font-weight: 700;
}

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

.control-group input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #059669;
    cursor: pointer;
    transition: all 0.2s ease;
}

.control-group input[type="range"]::-webkit-slider-thumb:hover {
    background: #047857;
    transform: scale(1.1);
}

.eutectic-only {
    display: block;
}

.toggle-options {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 25px;
    justify-content: center;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: #374151;
    cursor: pointer;
    background: white;
    padding: 10px 15px;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
}

.toggle-label:hover {
    background: #f0fdf4;
}

.toggle-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.formulas-section {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
}

.formulas-section h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #0c4a6e;
    margin-bottom: 15px;
}

.formula-list {
    display: grid;
    gap: 12px;
}

.formula-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: #f8fafc;
    border-radius: 6px;
}

.formula-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #475569;
    min-width: 150px;
}

.formula {
    font-family: 'Times New Roman', serif;
    font-size: 1rem;
    color: #059669;
    font-style: italic;
}

.phase-regions-info {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.phase-regions-info h4 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #0c4a6e;
    margin-bottom: 15px;
}

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

.region-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: #f8fafc;
    border-radius: 6px;
}

.region-color {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    flex-shrink: 0;
}

.region-name {
    font-weight: 700;
    color: #1e293b;
    min-width: 60px;
}

.region-desc {
    font-size: 0.85rem;
    color: #64748b;
}

.explanation {
    padding: 30px;
    background: #fafafa;
    border-top: 1px solid #e5e7eb;
}

.explanation h2 {
    font-size: 1.6rem;
    font-weight: 700;
    color: #0c4a6e;
    margin-bottom: 15px;
}

.explanation h3 {
    font-size: 1.2rem;
    font-weight: 600;
    color: #0369a1;
    margin: 20px 0 10px;
}

.explanation p {
    line-height: 1.8;
    color: #374151;
    margin-bottom: 12px;
}

@media (max-width: 1024px) {
    .main-display {
        grid-template-columns: 1fr;
    }

    .control-sliders {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    header h1 {
        font-size: 1.6rem;
    }

    main {
        padding: 15px;
    }

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

    .phase-state-display {
        grid-template-columns: 1fr;
    }

    .system-options {
        flex-direction: column;
    }

    .system-btn {
        width: 100%;
    }

    .lever-values {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .regions-list {
        grid-template-columns: 1fr;
    }
}
