:root {
    --bg-color: #f4f7f6;
    --panel-bg: #ffffff;
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #4b5563;
    --secondary-hover: #374151;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --success-color: #16a34a;
    --text-color: #1f2937;
    --border-color: #cbd5e1;
    --accent-gold: #f59e0b;
    --accent-cyan: #06b6d4;
    --accent-purple: #8b5cf6;
}

*:not(mjx-container):not(mjx-container *) {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    padding: 1.2rem 1rem;
    display: flex;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
}

.container {
    max-width: 1160px;
    width: 100%;
}

/* Top Navigation Bar */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.2rem;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid var(--border-color);
}

.nav-home-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.5rem 1rem;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: #1e293b;
    font-size: 0.88rem;
    font-weight: 700;
    text-decoration: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
    min-height: 40px;
}

.nav-home-btn:hover {
    background: #f8fafc;
    border-color: #94a3b8;
    color: var(--primary-color);
    transform: translateY(-1px);
}

.nav-dept-tag {
    font-size: 0.82rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

@media (max-width: 600px) {
    .nav-dept-tag {
        display: none;
    }
}

header {
    text-align: center;
    margin-bottom: 1.5rem;
}

header h1 {
    font-size: 2.1rem;
    color: #0f172a;
    font-weight: 800;
    margin-bottom: 0.35rem;
}

header p {
    color: #64748b;
    font-size: 0.95rem;
    line-height: 1.55;
    max-width: 900px;
    margin: 0 auto;
}

.series-card {
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.02);
}

.series-card h3 {
    font-size: 1rem;
    color: #1e3a8a;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.series-card p {
    font-size: 0.88rem;
    color: #4b5563;
    line-height: 1.55;
    margin-bottom: 0.5rem;
}

.series-card .series-tagline {
    font-weight: 700;
    color: #111827;
    font-style: italic;
}

/* Rigid Grid Layout Track Guards & Option A Mobile Layout */
.sim-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 900px) {
    .sim-layout {
        display: flex;
        flex-direction: column;
        gap: 1.25rem;
    }

    /* Option A: Visualizer & Canvas render first on mobile */
    .visualizer-panel {
        order: 1;
    }

    /* Controls follow naturally below without internal scroll traps */
    .controls-panel {
        order: 2;
        max-height: none;
        overflow-y: visible;
        padding-right: 1.5rem;
        padding-bottom: 1.5rem;
        touch-action: pan-y;
        -webkit-overflow-scrolling: touch;
    }
}

.panel {
    background: var(--panel-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.controls-panel {
    max-height: min(calc(100vh - 120px), 780px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 1.25rem;
    padding-bottom: 2.5rem;
    box-sizing: border-box;
}

.controls-panel::-webkit-scrollbar {
    width: 6px;
}
.controls-panel::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}
.controls-panel::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}
.controls-panel::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.control-group {
    margin-bottom: 1.15rem;
    padding-bottom: 1.15rem;
    border-bottom: 1px dashed var(--border-color);
}

.control-group:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.control-group h3 {
    font-size: 0.95rem;
    margin-bottom: 0.45rem;
    color: #334155;
    font-weight: 700;
}

/* Mode Switcher Buttons */
.mode-toggle-group {
    display: flex;
    gap: 0.5rem;
    width: 100%;
    flex-wrap: wrap;
}

.mode-btn {
    flex: 1 1 calc(50% - 0.5rem);
    padding: 0.6rem 0.65rem;
    border: 1px solid var(--border-color);
    background: #f8fafc;
    color: #475569;
    font-size: 0.8rem;
    font-weight: 700;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    min-height: 42px;
    touch-action: manipulation;
}

.mode-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.mode-btn.active {
    background: var(--primary-color);
    color: #ffffff;
    border-color: var(--primary-color);
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.25);
}

@media (max-width: 680px) {
    .mode-toggle-group {
        display: flex;
        flex-direction: column;
        gap: 0.45rem;
        width: 100%;
    }

    .mode-btn {
        width: 100%;
        min-height: 42px;
        padding: 0.65rem 0.85rem;
        font-size: 0.85rem;
    }
}

/* Material Pills Grid */
.material-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin-top: 0.45rem;
}

.material-chip {
    padding: 0.55rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #f8fafc;
    color: #334155;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s ease;
    touch-action: manipulation;
    min-height: 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.material-chip span {
    font-size: 0.7rem;
    color: #64748b;
    font-weight: normal;
}

.material-chip:hover {
    background: #e2e8f0;
}

.material-chip.active {
    background: #eff6ff;
    border-color: var(--primary-color);
    color: var(--primary-color);
    box-shadow: 0 0 0 1px var(--primary-color);
}

.material-chip.active span {
    color: #2563eb;
    font-weight: 600;
}

/* Sliders and Steppers (Mobile Compliant Section 1.2) */
.slider-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    margin-bottom: 0.75rem;
}

.slider-row label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #334155;
    flex: 0 0 32%;
}

.stepper-container {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex: 1;
}

.stepper-container input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    outline: none;
}

.stepper-container input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: transform 0.1s;
}

.stepper-container input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.step-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    background: #f1f5f9;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1.1rem;
    font-weight: bold;
    color: #475569;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    touch-action: manipulation;
}

.step-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.stat-badge {
    background: #f1f5f9;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.35rem 0.5rem;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.82rem;
    font-weight: 700;
    color: #0f172a;
    min-width: 88px;
    max-width: 96px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    flex-shrink: 0;
}

@media (max-width: 680px) {
    .slider-row {
        display: flex;
        flex-wrap: wrap;
        height: auto;
        min-height: auto;
        max-height: none;
        gap: 0.35rem 0.5rem;
        margin-bottom: 0.85rem;
        align-items: center;
    }

    .slider-row label {
        flex: 1;
        width: auto;
        min-width: 0;
        max-width: none;
        font-size: 0.85rem;
    }

    .slider-row .stat-badge {
        flex: 0 0 auto;
        width: auto;
        min-width: 78px;
        max-width: none;
        margin-left: auto;
        order: 2;
        padding: 0.25rem 0.6rem;
    }

    .slider-row .stepper-container {
        flex: 0 0 100%;
        width: 100%;
        order: 3;
        display: flex;
        align-items: center;
        gap: 0.5rem;
        margin-top: 0.15rem;
    }

    .stepper-container .step-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
        font-size: 1.25rem;
        border-radius: 8px;
    }

    .stepper-container input[type="range"] {
        flex: 1;
        min-width: 0;
        height: 8px;
    }
}

.slider-hint {
    font-size: 0.74rem;
    color: #64748b;
    font-style: italic;
    line-height: 1.35;
    margin-top: 0.25rem;
}

/* Action Buttons */
.button-split-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.4rem;
}

.btn {
    width: 100%;
    padding: 0.65rem;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}

.btn-primary {
    background: var(--primary-color);
    color: #ffffff;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--secondary-color);
    color: #ffffff;
}

.btn-secondary:hover {
    background: var(--secondary-hover);
}

.btn-neutral {
    background: #e2e8f0;
    color: #334155;
    border: 1px solid var(--border-color);
}

.btn-neutral:hover {
    background: #cbd5e1;
    color: #0f172a;
}

/* Visualizer Panel (Right Column) */
.visualizer-panel {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    min-height: 520px;
}

/* Live Stats Bar */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    background: #0f172a;
    border-radius: 8px;
    padding: 0.65rem 0.75rem;
    border: 1px solid #1e293b;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    overflow: hidden;
}

.stat-label {
    font-size: 0.68rem;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.2rem;
    white-space: nowrap;
    text-overflow: ellipsis;
    width: 100%;
}

.stat-value {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.96rem;
    font-weight: 800;
    color: #38bdf8;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

@media (max-width: 600px) {
    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.6rem 0.4rem;
        padding: 0.75rem;
    }
    
    .stat-value {
        font-size: 0.92rem;
    }
}

/* Status Pill */
.status-pill {
    padding: 0.5rem 0.85rem;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    line-height: 1.35;
    transition: all 0.25s ease;
}

.status-normal {
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
}

.status-warning {
    background: #fffbeb;
    color: #b45309;
    border: 1px solid #fde68a;
}

.status-alert {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

/* 3D Canvas Container */
.canvas-container {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 11;
    min-height: 380px;
    max-height: 520px;
    background: #020617;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid #1e293b;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

@media (max-width: 768px) {
    .canvas-container {
        aspect-ratio: auto;
        height: 380px;
        min-height: 350px;
        max-height: 55vh;
    }
}

#threeCanvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

/* Gesture Hint Overlay */
.gesture-overlay {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #e2e8f0;
    padding: 0.35rem 0.85rem;
    border-radius: 20px;
    font-size: 0.74rem;
    font-weight: 600;
    pointer-events: none;
    z-index: 10;
    transition: opacity 0.6s ease;
    white-space: nowrap;
}

/* Floating Viewport Legend */
.viewport-legend {
    position: absolute;
    bottom: 12px;
    right: 12px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 0.45rem 0.75rem;
    display: flex;
    gap: 0.75rem;
    align-items: center;
    z-index: 5;
    pointer-events: none;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.72rem;
    color: #e2e8f0;
    font-weight: 600;
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

@media (max-width: 768px) {
    .viewport-legend {
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        padding: 5px 8px;
        gap: 6px 12px;
        justify-content: center;
        background: rgba(8, 12, 20, 0.92);
    }
    .legend-item { font-size: 0.65rem; gap: 4px; }
    .legend-dot { width: 7px; height: 7px; }
}

/* Auxiliary 2D Canvas (B-H Curves, Vector Decomposition, Curie Plot) */
.aux-card {
    background: #0f172a;
    border: 1px solid #1e293b;
    border-radius: 8px;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.aux-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.aux-title {
    font-size: 0.78rem;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.aux-legend {
    display: flex;
    gap: 0.5rem;
}

.aux-tag {
    font-size: 0.68rem;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-weight: 600;
}

#auxCanvas {
    width: 100%;
    height: 120px;
    display: block;
    background: #020617;
    border-radius: 6px;
    border: 1px solid #1e293b;
}

/* Concepts Box */
.concepts-box {
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    margin-top: 1.15rem;
}

.concepts-box h3 {
    font-size: 0.92rem;
    color: #1e3a8a;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.concepts-box ul {
    list-style: none;
    padding-left: 0;
}

.concepts-box li {
    font-size: 0.84rem;
    color: #334155;
    line-height: 1.5;
    margin-bottom: 0.45rem;
    position: relative;
    padding-left: 1.15rem;
}

.concepts-box li::before {
    content: "•";
    color: var(--primary-color);
    font-size: 1.2rem;
    position: absolute;
    left: 0.2rem;
    top: -0.15rem;
}

/* Vector Breakdown Row */
.vector-breakdown-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-top: 0.6rem;
    padding: 0.6rem;
    background: #f1f5f9;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
}

.breakdown-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.breakdown-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: #475569;
    margin-bottom: 0.15rem;
}

.breakdown-val {
    font-family: 'Consolas', monospace;
    font-size: 0.85rem;
    font-weight: 800;
    color: #0f172a;
}

/* Callout & Feedback Cards */
.admission-card {
    background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
    border-radius: 12px;
    padding: 1.75rem 1.5rem;
    color: #ffffff;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 12px rgba(30, 58, 138, 0.25);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.promo-copy .promo-kicker {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #93c5fd;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.promo-copy .promo-lead {
    font-size: 1.1rem;
    font-weight: 600;
    color: #dbeafe;
    margin-bottom: 0.2rem;
}

.promo-copy .promo-headline {
    font-size: 1.5rem;
    font-weight: 800;
    color: #ffffff;
}

.program-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
}

.program-card {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.program-card strong {
    font-size: 1.05rem;
    color: #ffffff;
}

.program-card span {
    font-size: 0.85rem;
    color: #bfdbfe;
}

.program-card small {
    font-size: 0.75rem;
    color: #fde047;
    margin-top: 0.25rem;
    font-weight: 600;
}

.promo-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.promo-button {
    padding: 0.65rem 1.25rem;
    border-radius: 6px;
    font-size: 0.88rem;
    font-weight: 700;
    text-decoration: none;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
}

.promo-button.main-cta {
    background: #f59e0b;
    color: #0f172a;
}

.promo-button.main-cta:hover {
    background: #d97706;
}

.promo-button.sub-cta {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.promo-button.sub-cta:hover {
    background: rgba(255, 255, 255, 0.25);
}

.feedback-card {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.feedback-content {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.feedback-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #eff6ff;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.feedback-text h4 {
    font-size: 0.95rem;
    color: #0f172a;
    margin-bottom: 0.2rem;
}

.feedback-text p {
    font-size: 0.82rem;
    color: #64748b;
    line-height: 1.4;
}

.feedback-btn {
    padding: 0.6rem 1rem;
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: #334155;
    font-size: 0.82rem;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
    transition: all 0.2s;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
}

.feedback-btn:hover {
    background: #e2e8f0;
    color: var(--primary-color);
}

@media (max-width: 680px) {
    .feedback-card {
        flex-direction: column;
        align-items: stretch;
    }
    .feedback-btn {
        justify-content: center;
    }
}

.series-footer {
    text-align: center;
    padding: 1rem 0 2rem 0;
    color: #64748b;
    font-size: 0.82rem;
}

/* Readouts, status lines and labels wrap instead of being cut off. */
.stat-label {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
}
