:root {
    --bg: #0f172a;
    --card: rgba(30, 41, 59, 0.7);
    --primary: #38bdf8;
    --secondary: #f59e0b;
    --accent: #22c55e;
    --gravity: #f43f5e;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);
    --glow: rgba(56, 189, 248, 0.3);
    --success: #10b981;
    --error: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

#root {
    height: 100vh;
}

.app {
    display: flex;
    flex-direction: row;
    /* Controls on left */
    height: 100vh;
}

.center-stack {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ══════════════════════════════════════════
   MAIN SIMULATION ROW
   canvas-col | right-sidebar
══════════════════════════════════════════ */
.sim-row {
    flex: 1 1 0;
    display: flex;
    flex-direction: row;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

/* ── Left: Canvas Column ────────────────── */
.canvas-col {
    flex: 1 1 0;
    position: relative;
    min-width: 0;
    background: radial-gradient(ellipse at 50% 40%, #1e293b 0%, #0f172a 100%);
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Stage badge — fixed in canvas col */
.stage-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 20;
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid var(--primary);
    color: var(--primary);
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* HUD — fixed in canvas col, top-right */
.hud {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 20;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 10px 16px;
    display: flex;
    gap: 18px;
    width: auto;
    max-width: fit-content;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.stat {
    display: flex;
    flex-direction: column;
}

.stat .lbl {
    font-size: 9px;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: 0.5px;
    margin-bottom: 3px;
}

.stat .val {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--primary);
}

/* Feedback Toast — centered in canvas col */
.feedback-toast {
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(244, 63, 94, 0.1);
    border: 1px solid var(--gravity);
    border-radius: 10px;
    padding: 9px 20px;
    font-size: 12px;
    color: var(--gravity);
    z-index: 30;
    max-width: 420px;
    text-align: center;
    animation: fadeSlide 0.4s ease-out;
    pointer-events: none;
}

.feedback-toast.positive {
    background: rgba(56, 189, 248, 0.1);
    border-color: var(--primary);
    color: var(--primary);
}

.feedback-toast.success {
    background: rgba(16, 185, 129, 0.1);
    border-color: var(--success);
    color: var(--success);
}

/* ── Stage Overlay ────────────────────────── */
.stage-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(10, 15, 30, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

.stage-overlay-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 15px;
    animation: fadeSlideUp 0.4s ease;
}

.stage-overlay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.stage-overlay-header h2 {
    flex: 1;
    text-align: left;
    color: var(--primary);
    font-size: 1.4rem;
    margin: 0;
}

/* h2 inside stage-overlay-card (outside header) */
.stage-overlay-card>h2 {
    color: var(--primary);
    font-size: 1.4rem;
}

.stage-overlay-card h3 {
    color: var(--text);
    font-size: 1rem;
    font-weight: 400;
}

.lesson-content {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--muted);
    text-align: left;
    background: rgba(0, 0, 0, 0.2);
    padding: 15px;
    border-radius: 8px;
}

.predict-prompt {
    margin-top: 10px;
    padding: 12px;
    background: rgba(245, 158, 11, 0.1);
    border-left: 3px solid var(--secondary);
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--secondary);
    cursor: pointer;
    transition: background 0.2s;
}

.predict-prompt:hover {
    background: rgba(245, 158, 11, 0.2);
}

.start-stage-btn {
    margin-top: 10px;
    padding: 12px 24px;
    font-size: 1rem;
    align-self: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes fadeSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* ══════════════════════════════════════════
   EQUATION PANEL — full-width strip below sim-row
══════════════════════════════════════════ */
.eq-strip {
    flex-shrink: 0;
    height: 145px;
    background: #070d1a;
    border-top: 1px solid rgba(56, 189, 248, 0.2);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: stretch;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 0;
}

.eq-strip::-webkit-scrollbar {
    height: 4px;
}

.eq-strip::-webkit-scrollbar-thumb {
    background: rgba(56, 189, 248, 0.3);
    border-radius: 2px;
}

.eq-strip-title {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 120px;
    padding: 0 14px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--primary);
    font-weight: 700;
    border-right: 1px solid var(--border);
    text-align: center;
    line-height: 1.4;
    writing-mode: horizontal-tb;
}

.eq-cell {
    flex-shrink: 0;
    min-width: 210px;
    max-width: 250px;
    padding: 10px 16px;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 4px;
    transition: background 0.3s;
    overflow-y: auto;
}

.eq-cell::-webkit-scrollbar {
    width: 3px;
}

.eq-cell::-webkit-scrollbar-thumb {
    background: rgba(56, 189, 248, 0.3);
    border-radius: 2px;
}

.eq-cell.highlighted {
    background: rgba(56, 189, 248, 0.05);
    border-left: 2px solid var(--secondary);
}

.eq-cell .eq-desc {
    font-size: 9.5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    margin-bottom: 2px;
}

.eq-cell .eq-latex {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    color: #c8d6e8;
    margin-bottom: 4px;
}

.eq-cell .eq-steps {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.eq-step {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.67rem;
    color: var(--secondary);
    opacity: 0.7;
}

.eq-step.active {
    opacity: 1;
    color: var(--accent);
    font-weight: 700;
}

/* ── Left: Controls Panel ───────────────── */
.left-controls {
    width: 20%;
    min-width: 250px;
    flex-shrink: 0;
    background: #0a0f1e;
    border-right: 1px solid var(--border);
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow-y: auto;
}

.left-controls h2 {
    font-size: 1.1rem;
    color: var(--primary);
    margin-bottom: 10px;
    font-weight: 700;
}

.ctrl-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.home-btn {
    text-decoration: none;
    background: rgba(255, 255, 255, 0.05);
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 1rem;
    border: 1px solid var(--border);
    transition: 0.3s;
}

.home-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.nav-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.dots {
    display: flex;
    gap: 7px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition: 0.3s;
}

.dot.active {
    background: var(--primary);
    box-shadow: 0 0 8px var(--glow);
}

.btns {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn {
    padding: 8px 15px;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
    border: none;
    font-family: 'Outfit', sans-serif;
    font-size: 0.85rem;
    transition: 0.25s;
}

.btn.primary {
    background: var(--primary);
    color: #0f172a;
}

.btn.ghost {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    border: 1px solid var(--border);
}

.btn.danger {
    background: rgba(244, 63, 94, 0.12);
    color: var(--gravity);
    border: 1px solid rgba(244, 63, 94, 0.3);
}

.btn.quiz-btn {
    background: linear-gradient(135deg, #38bdf8, #0ea5e9);
    color: #0f172a;
    box-shadow: 0 4px 12px rgba(56, 189, 248, 0.2);
}

.ctrl-main {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
}

.sliders {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.slider-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.slider-label {
    display: flex;
    justify-content: space-between;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--muted);
}

.slider-label .v {
    color: var(--primary);
    font-family: 'JetBrains Mono', monospace;
}

input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 5px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    outline: none;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 8px var(--glow);
    transition: 0.2s;
}

input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.action-col {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* ══════════════════════════════════════════
   MODALS
══════════════════════════════════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: rgba(10, 15, 30, 0.92);
    backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-card {
    background: var(--card);
    width: 90%;
    max-width: 580px;
    max-height: 90vh;
    padding: 36px;
    border-radius: 26px;
    border: 1px solid var(--border);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.8);
    position: relative;
    overflow-y: auto;
}

.modal-badge {
    background: rgba(56, 189, 248, 0.1);
    color: var(--primary);
    display: inline-block;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 18px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 22px;
}

.modal-question {
    font-size: 1.1rem;
    text-align: center;
    margin-bottom: 22px;
    line-height: 1.5;
    color: var(--text);
}

.quiz-options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 14px;
}

.opt {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    padding: 13px;
    border-radius: 11px;
    cursor: pointer;
    text-align: center;
    font-size: 0.87rem;
    transition: 0.2s;
    color: var(--text);
}

.opt:hover:not(.correct):not(.wrong) {
    background: rgba(255, 255, 255, 0.07);
    border-color: var(--primary);
}

.opt.correct {
    background: rgba(16, 185, 129, 0.25) !important;
    border: 2px solid var(--success) !important;
    color: var(--success) !important;
    font-weight: 700 !important;
}

.opt.wrong {
    background: rgba(239, 68, 68, 0.25) !important;
    border: 2px solid var(--error) !important;
    color: var(--error) !important;
}

.opt.disabled {
    pointer-events: none;
}

.quiz-explanation {
    background: rgba(56, 189, 248, 0.07);
    border-left: 3px solid var(--primary);
    border-radius: 8px;
    padding: 11px 14px;
    font-size: 0.85rem;
    line-height: 1.55;
    margin-bottom: 12px;
    color: var(--text);
}

.modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
}

.score-display {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    color: var(--muted);
}

.step-tracker {
    font-size: 0.82rem;
    color: var(--muted);
}

.exit-btn {
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.85rem;
}

.exit-btn:hover {
    color: var(--error);
}

.quiz-progress-bar {
    position: absolute;
    top: 0;
    left: 0;
    height: 4px;
    background: var(--primary);
    transition: 0.5s ease;
}

.pred-feedback {
    margin-top: 16px;
}

.pred-result {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 10px;
}

.pred-result.correct {
    color: var(--success);
}

.pred-result.wrong {
    color: var(--error);
}

.success-card {
    text-align: center;
}

.confetti {
    font-size: 3.5rem;
    margin-bottom: 14px;
}

.mastery-pct {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
    margin: 10px 0;
}

.primary-action {
    background: var(--primary);
    color: #0f172a;
    border: none;
    padding: 11px 26px;
    border-radius: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.3s;
    font-family: 'Outfit', sans-serif;
    font-size: 0.92rem;
    margin-top: 1.5rem;
}

.primary-action:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

/* ── Animations ─────────────────────────── */
@keyframes fadeSlide {
    from {
        opacity: 0;
        transform: translate(-50%, -10px);
    }

    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

.hidden {
    display: none !important;
}

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    font-size: 1.3rem;
    color: var(--muted);
}

/* ── Mobile Responsiveness ──────────────── */
@media (max-width: 900px) {
    .left-controls {
        width: clamp(200px, 30vw, 280px);
        padding: 15px 12px;
    }

    .hud {
        top: 45px;
        /* Prevent overlap with stage badge */
        right: 12px;
        padding: 8px 12px;
        gap: 10px;
        max-width: 95%;
    }

    .stat .val {
        font-size: 0.8rem;
    }

    .stage-badge {
        top: 10px;
        left: 12px;
    }
}

@media (max-width: 600px) {
    .app {
        flex-direction: column;
    }

    .left-controls {
        width: 100%;
        max-height: 40vh;
        padding: 15px 20px;
        border-right: none;
        border-top: 1px solid var(--border);
        order: 2;
    }

    .sim-row {
        height: 60vh;
        order: 1;
        flex: none;
    }

    .stage-overlay {
        align-items: flex-start;
        padding: 40px 16px;
        overflow-y: auto;
    }

    .stage-overlay-card {
        max-height: none;
        margin: auto 0;
        width: 100%;
        border-radius: 12px;
        padding: 24px 20px;
    }

    .modal-card {
        max-height: 88vh;
        padding: 24px 18px;
        border-radius: 16px;
        width: 95%;
    }

    .hud {
        top: 8px;
        right: 8px;
        padding: 6px 10px;
        gap: 8px;
        flex-wrap: wrap;
        width: calc(100% - 16px);
        justify-content: center;
        background: rgba(0, 0, 0, 0.7);
    }

    .stat .val {
        font-size: 0.75rem;
    }

    .stage-badge {
        top: 55px;
    }
}

/* Zoom Controls */
.zoom-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 10px 0;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.zoom-label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--muted);
}

.zoom-btns {
    display: flex;
    gap: 8px;
}

.zoom-btns button {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.05);
    color: var(--primary);
    cursor: pointer;
    font-size: 16px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
}

.zoom-btns button:hover {
    background: rgba(56, 189, 248, 0.1);
    border-color: var(--primary);
    color: #fff;
}

/* ── Mobile Landscape Responsiveness ────── */
@media (max-height: 500px) and (orientation: landscape) {
    .left-controls {
        width: 260px;
        padding: 5px 10px;
        gap: 6px;
    }
    .left-controls h2 {
        font-size: 0.9rem;
        margin-bottom: 2px;
    }
    .slider-row {
        gap: 0px;
    }
    .slider-label {
        font-size: 10px;
    }
    .btn {
        padding: 4px 8px;
        font-size: 0.75rem;
    }
    .hud {
        top: 5px;
        right: 5px;
        padding: 4px 8px;
        gap: 8px;
    }
    .stat .val {
        font-size: 0.8rem;
    }
    .stage-badge {
        top: 5px;
        left: 5px;
        padding: 2px 8px;
    }
    .eq-strip {
        height: 90px;
    }
    .eq-strip-title {
        width: 30px;
        padding: 0 4px;
        writing-mode: vertical-rl;
        transform: rotate(180deg);
        font-size: 9px;
    }
    .eq-cell {
        min-width: 160px;
        padding: 4px 10px;
        gap: 2px;
    }
    .eq-cell .eq-desc {
        font-size: 8px;
    }
    .eq-cell .eq-latex {
        font-size: 0.65rem;
        margin-bottom: 2px;
    }
    .eq-step {
        font-size: 0.6rem;
    }
}