/*  Time & Distance Lab — Styles  */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=Space+Grotesk:wght@400;500;600;700&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Outfit', sans-serif; background: #0a0e1a; color: #e2e8f0; overflow: hidden; }

/* ── OVERLAY ────────────────────────────────────────── */
#phet-stage {
    position: absolute; top: 0; left: 0;
    width: 1280px; height: 720px;
    background: #0a0e1a;
    display: flex; flex-direction: column;
    overflow: hidden; transform-origin: 0 0;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.4);
    touch-action: none;
}

.td-overlay {
    position: absolute; inset: 0; z-index: 1000;
    background: rgba(5,10,21,0.88);
    backdrop-filter: blur(8px);
    display: flex; align-items: center; justify-content: center; padding: 16px;
    animation: fadeIn .3s ease;
}
.td-overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.td-modal {
    background: linear-gradient(140deg,#0d1526,#0f1f3d);
    border: 1px solid rgba(99,179,237,.2);
    border-radius: 22px;
    max-width: 680px; width: 100%; max-height: 90vh;
    position: relative;
    box-shadow: 0 30px 80px rgba(0,0,0,.6);
    animation: popIn .4s cubic-bezier(.175,.885,.32,1.275);
}
@keyframes popIn { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.td-modal-scroll { overflow-y: auto; padding: 32px; max-height: 90vh; }
.td-modal-scroll::-webkit-scrollbar { width: 4px; }
.td-modal-scroll::-webkit-scrollbar-thumb { background: rgba(99,102,241,.4); border-radius: 4px; }

.td-close {
    position: absolute; top: 14px; right: 14px;
    background: rgba(239,68,68,.15); border: 1px solid rgba(239,68,68,.3);
    color: #f87171; width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
    display: flex; align-items: center; justify-content: center; transition: all .2s;
}
.td-close:hover { background: rgba(239,68,68,.3); transform: rotate(90deg); }

.td-hero { font-size: 3.5rem; text-align: center; animation: floatY 3s ease-in-out infinite; }
@keyframes floatY { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }

.td-modal h2 {
    text-align: center; font-size: 1.6rem; font-weight: 800; margin: 8px 0 4px;
    background: linear-gradient(135deg,#60a5fa,#a78bfa);
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.td-subtitle { text-align: center; color: #64748b; margin-bottom: 20px; }

/* Formula Triangle */
.fmla-triangle {
    background: rgba(15,23,42,.7);
    border: 1px solid rgba(99,179,237,.15);
    border-radius: 16px; padding: 20px; margin-bottom: 18px; text-align: center;
}
.ft-top, .ft-bot { display: flex; justify-content: center; align-items: center; gap: 10px; }
.ft-top { margin-bottom: 6px; }
.ft-box {
    display: flex; flex-direction: column; align-items: center;
    padding: 10px 18px; border-radius: 12px; font-size: 1.5rem; font-weight: 800;
    font-family: 'Space Grotesk', sans-serif; min-width: 70px;
}
.ft-box span { font-size: 0.65rem; font-weight: 500; text-transform: uppercase; letter-spacing: .5px; margin-top: 2px; }
.ft-d { background: rgba(99,102,241,.25); color: #a5b4fc; border: 2px solid rgba(99,102,241,.4); }
.ft-s { background: rgba(16,185,129,.2);  color: #6ee7b7; border: 2px solid rgba(16,185,129,.4); }
.ft-t { background: rgba(245,158,11,.2);  color: #fcd34d; border: 2px solid rgba(245,158,11,.4); }
.ft-x { font-size: 1.4rem; color: #475569; font-weight: 700; }
.ft-rules { margin-top: 12px; display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.ft-rules span {
    font-family: 'Space Grotesk', monospace; font-size: 0.8rem; font-weight: 600;
    background: rgba(30,41,59,.8); padding: 4px 12px; border-radius: 8px; color: #7dd3fc;
    border: 1px solid rgba(99,179,237,.2);
}

.th-sec { background: rgba(30,41,59,.4); border-radius: 12px; padding: 14px; margin-bottom: 12px; border: 1px solid rgba(99,179,237,.08); }
.th-sec h3 { font-size: .95rem; color: #7dd3fc; margin-bottom: 8px; }
.th-sec p  { font-size: .85rem; color: #94a3b8; line-height: 1.6; margin-bottom: 6px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { font-size: .75rem; background: rgba(99,102,241,.15); border: 1px solid rgba(99,102,241,.3); color: #a5b4fc; padding: 4px 10px; border-radius: 20px; }

.mini-svg { width: 100%; max-width: 210px; display: block; margin: 8px auto 0; }

.th-tip { border-left: 3px solid #f59e0b !important; }
.th-tip h3 { color: #fcd34d !important; }
.th-tip ul { padding-left: 18px; }
.th-tip li { font-size: .83rem; color: #94a3b8; line-height: 1.8; }

.td-start-btn {
    display: block; width: 100%; margin-top: 18px; padding: 14px;
    background: linear-gradient(135deg,#6366f1,#8b5cf6); color: #fff; border: none;
    border-radius: 12px; font-family: 'Outfit', sans-serif; font-size: 1rem; font-weight: 700;
    cursor: pointer; transition: all .3s; box-shadow: 0 8px 30px rgba(99,102,241,.4);
    display: flex; align-items: center; justify-content: center; gap: 8px;
}
.td-start-btn:hover { transform: translateY(-3px); box-shadow: 0 14px 40px rgba(99,102,241,.6); }

/* ── APP LAYOUT ─────────────────────────────────────── */
#td-app { display: flex; flex-direction: column; height: 100%; width: 100%; overflow: hidden; }

/* NAV — override global index.css fixed nav */
#td-nav {
    position: relative !important;
    top: auto !important;
    display: flex; justify-content: space-between; align-items: center;
    padding: 0 22px; height: 62px;
    background: rgba(10,14,26,.98) !important;
    border-bottom: 1px solid rgba(99,179,237,.12);
    flex-shrink: 0; z-index: 50;
    width: 100% !important;
    backdrop-filter: none;
}
.nav-brand { display: flex; align-items: center; gap: 10px; font-family: 'Space Grotesk', sans-serif; }
.brand-link { text-decoration: none; color: inherit; display: flex; align-items: center; gap: 8px; font-size: 1.1rem; font-weight: 700; }
.brand-thin { font-weight: 300; }
.nav-sep { color: rgba(148,163,184,.35); }
.nav-chapter { font-size: .78rem; color: #64748b; font-weight: 500; text-transform: uppercase; letter-spacing: .5px; }
.nav-current  { font-size: .82rem; color: #60a5fa; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.nav-actions  { display: flex; gap: 10px; align-items: center; }
.nav-btn {
    display: flex; align-items: center; gap: 6px; padding: 7px 15px;
    border-radius: 8px; font-family: 'Outfit', sans-serif; font-size: .82rem; font-weight: 600;
    cursor: pointer; border: none; transition: all .2s; text-decoration: none;
}
.td-theory-btn { background: linear-gradient(135deg,#6366f1,#8b5cf6); color: #fff; box-shadow: 0 4px 15px rgba(99,102,241,.3); }
.td-theory-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(99,102,241,.5); }
.td-exit-btn { background: rgba(30,41,59,.8); color: #94a3b8; border: 1px solid rgba(148,163,184,.2); }
.td-exit-btn:hover { background: rgba(51,65,85,.8); color: #e2e8f0; }

/* MAIN LAYOUT */
.td-layout { display: flex; flex: 1; overflow: hidden; min-height: 0; }

/* SIM AREA */
.sim-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: #050a15; min-width: 0; min-height: 0; }

/* MODE TABS */
.mode-tabs { display: flex; gap: 6px; padding: 8px 14px 0; flex-shrink: 0; background: #050a15; border-bottom: 1px solid rgba(99,179,237,.1); }
.mode-tab {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 18px; border-radius: 8px 8px 0 0;
    font-family: 'Outfit', sans-serif; font-size: .82rem; font-weight: 600;
    cursor: pointer; border: 1px solid rgba(99,179,237,.1); border-bottom: none;
    background: rgba(15,23,42,.6); color: #64748b; transition: all .2s;
}
.mode-tab:hover  { background: rgba(30,41,59,.8); color: #94a3b8; }
.mode-tab.active { background: rgba(99,102,241,.2); color: #a5b4fc; border-color: rgba(99,102,241,.4); }

/* CANVAS WRAP */
.canvas-wrap { flex: 1; position: relative; overflow: hidden; min-height: 0; }
#mainCanvas { width: 100%; height: 100%; display: block; }

/* HUD BAR */
.hud-bar {
    position: absolute; top: 0; left: 0; right: 0;
    display: flex; gap: 8px; padding: 8px 14px;
    background: linear-gradient(180deg, rgba(5,10,21,.9) 0%, transparent 100%);
    pointer-events: none;
}
.hud-item { display: flex; align-items: center; gap: 6px; background: rgba(15,23,42,.8); border: 1px solid rgba(99,179,237,.15); border-radius: 18px; padding: 4px 12px; }
.hud-lbl { font-size: .72rem; color: #64748b; }
.hud-val { font-size: .82rem; font-weight: 700; color: #7dd3fc; font-family: 'Space Grotesk', monospace; }

/* WINNER OVERLAY */
.winner-overlay {
    position: absolute; inset: 0; background: rgba(5,10,21,.85);
    display: flex; align-items: center; justify-content: center; z-index: 30;
    backdrop-filter: blur(6px);
}
.winner-overlay.hidden { display: none; }
.winner-card {
    background: linear-gradient(135deg,#0d1526,#1a2a4a);
    border: 2px solid #f59e0b; border-radius: 20px; padding: 30px 40px;
    text-align: center; animation: popIn .4s cubic-bezier(.175,.885,.32,1.275);
}
.w-trophy { font-size: 3rem; animation: floatY 2s ease-in-out infinite; }
.w-title  { font-size: 1.5rem; font-weight: 800; color: #f59e0b; margin: 8px 0; }
.w-stats  { color: #94a3b8; font-size: .85rem; font-family: 'Space Grotesk', monospace; line-height: 1.8; }
.w-close-btn { margin-top: 14px; padding: 9px 24px; background: linear-gradient(135deg,#6366f1,#8b5cf6); color: #fff; border: none; border-radius: 10px; font-family: 'Outfit', sans-serif; font-weight: 600; cursor: pointer; transition: all .2s; }
.w-close-btn:hover { transform: translateY(-2px); }

/* RULER */
.ruler-section { flex-shrink: 0; padding: 8px 14px; background: rgba(10,14,26,.9); border-top: 1px solid rgba(99,179,237,.08); }
.ruler-header { display: flex; justify-content: space-between; font-size: .75rem; color: #64748b; margin-bottom: 6px; font-weight: 600; }
.ruler-right { color: #7dd3fc; font-family: 'Space Grotesk', monospace; }
.ruler-bar-wrap { display: flex; align-items: center; gap: 8px; }
.ruler-flag { font-size: 1rem; }
.ruler-track { flex: 1; height: 20px; background: rgba(30,41,59,.8); border-radius: 10px; border: 1px solid rgba(99,179,237,.15); position: relative; overflow: hidden; }
.ruler-fill-a { position: absolute; left: 0; top: 0; height: 100%; background: linear-gradient(90deg,#6366f1,#8b5cf6); border-radius: 10px; width: 0%; transition: width .05s linear; }
.ruler-fill-b { position: absolute; left: 0; top: 0; height: 100%; background: rgba(245,158,11,.4); border-radius: 10px; width: 0%; transition: width .05s linear; }
.ruler-fill-b.hidden { display: none; }
.ruler-pin {
    position: absolute; top: -18px; transform: translateX(-50%);
    display: flex; flex-direction: column; align-items: center; font-size: .6rem; font-weight: 700;
    pointer-events: none; transition: left .05s linear;
}
.ruler-pin i { font-size: .75rem; }
.pin-a { color: #818cf8; }
.pin-b { color: #fbbf24; }
.ruler-pin.hidden { display: none; }

/* ACTION BAR */
.action-bar {
    flex-shrink: 0; display: flex; justify-content: space-between; align-items: center;
    padding: 10px 14px; background: rgba(10,14,26,.95); border-top: 1px solid rgba(99,179,237,.08);
    flex-wrap: wrap; gap: 8px;
}
.action-left  { display: flex; gap: 8px; }
.action-right { display: flex; align-items: center; gap: 6px; }
.act-btn {
    display: flex; align-items: center; gap: 6px; padding: 8px 16px;
    border-radius: 9px; font-family: 'Outfit', sans-serif; font-size: .82rem; font-weight: 600;
    cursor: pointer; border: none; transition: all .2s;
}
.btn-start { background: linear-gradient(135deg,#10b981,#059669); color: #fff; box-shadow: 0 4px 15px rgba(16,185,129,.3); }
.btn-start:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(16,185,129,.5); }
.btn-pause { background: rgba(245,158,11,.15); color: #fcd34d; border: 1px solid rgba(245,158,11,.3); }
.btn-pause:hover:not(:disabled) { background: rgba(245,158,11,.3); transform: translateY(-2px); }
.btn-pause:disabled { opacity: .4; cursor: not-allowed; }
.btn-step  { background: rgba(99,102,241,.15); color: #a5b4fc; border: 1px solid rgba(99,102,241,.3); }
.btn-step:hover  { background: rgba(99,102,241,.3); transform: translateY(-2px); }
.btn-reset { background: rgba(239,68,68,.12); color: #f87171; border: 1px solid rgba(239,68,68,.3); }
.btn-reset:hover { background: rgba(239,68,68,.25); transform: translateY(-2px); }

.sm-label { font-size: .75rem; color: #64748b; font-weight: 600; }
.sm-btn { padding: 5px 11px; border-radius: 7px; font-size: .78rem; font-weight: 600; cursor: pointer; border: 1px solid rgba(99,179,237,.15); background: rgba(15,23,42,.8); color: #64748b; transition: all .2s; font-family: 'Outfit', sans-serif; }
.sm-btn:hover  { border-color: rgba(99,102,241,.4); color: #a5b4fc; }
.sm-btn.active { background: rgba(99,102,241,.25); border-color: #6366f1; color: #a5b4fc; }

/* SIDEBAR */
.td-sidebar { width: 290px; background: #0d1526; border-left: 1px solid rgba(99,179,237,.1); display: flex; flex-direction: column; gap: 8px; overflow-y: auto; padding: 10px; flex-shrink: 0; }
.td-sidebar::-webkit-scrollbar { width: 4px; }
.td-sidebar::-webkit-scrollbar-thumb { background: rgba(99,102,241,.25); border-radius: 4px; }

.td-card { background: rgba(15,23,42,.8); border: 1px solid rgba(99,179,237,.1); border-radius: 13px; padding: 12px; flex-shrink: 0; }
.td-card.hidden { display: none; }

.td-card-hdr { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; color: #64748b; margin-bottom: 10px; display: flex; align-items: center; gap: 6px; padding-bottom: 7px; border-bottom: 1px solid rgba(99,179,237,.07); }
.td-card-hdr i { color: #60a5fa; }

/* VEHICLE PICKER */
.vehicle-picker { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.veh-btn {
    width: 38px; height: 38px; border-radius: 8px; font-size: 1.2rem;
    border: 2px solid rgba(99,179,237,.15); background: rgba(30,41,59,.6);
    cursor: pointer; transition: all .2s; display: flex; align-items: center; justify-content: center;
}
.veh-btn:hover { border-color: rgba(99,102,241,.5); transform: scale(1.1); }
.veh-btn.active { border-color: #6366f1; background: rgba(99,102,241,.25); box-shadow: 0 0 10px rgba(99,102,241,.3); }

/* CONTROLS */
.ctrl-row { margin-bottom: 4px; }
.ctrl-row label { display: flex; justify-content: space-between; font-size: .82rem; color: #94a3b8; margin-bottom: 6px; }
.val-pill { background: rgba(99,102,241,.2); color: #a5b4fc; padding: 2px 8px; border-radius: 6px; font-family: 'Space Grotesk', monospace; font-size: .78rem; font-weight: 600; }
input[type=range] { width: 100%; height: 4px; background: rgba(99,179,237,.15); border-radius: 4px; outline: none; -webkit-appearance: none; appearance: none; cursor: pointer; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; background: linear-gradient(135deg,#6366f1,#8b5cf6); border-radius: 50%; cursor: pointer; border: 2px solid #0d1526; box-shadow: 0 0 8px rgba(99,102,241,.5); }

/* SCENARIOS */
.scenario-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.scene-btn { text-align: left; padding: 7px 10px; border-radius: 8px; font-family: 'Outfit', sans-serif; font-size: .78rem; font-weight: 600; cursor: pointer; border: 1px solid rgba(99,179,237,.15); background: rgba(30,41,59,.6); color: #94a3b8; transition: all .2s; }
.scene-btn:hover { background: rgba(99,102,241,.2); border-color: rgba(99,102,241,.4); color: #c7d2fe; transform: translateY(-1px); }

/* FORMULA BOXES */
.fmla-card { background: rgba(10,14,30,.9) !important; border-color: rgba(99,102,241,.25) !important; }
.fmla-boxes { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.fmla-eq { font-size: 1.3rem; color: #475569; font-weight: 700; flex-shrink: 0; }
.fmla-box { flex: 1; border-radius: 10px; padding: 8px; text-align: center; }
.fmla-d { background: rgba(99,102,241,.15); border: 1px solid rgba(99,102,241,.3); }
.fmla-s { background: rgba(16,185,129,.12); border: 1px solid rgba(16,185,129,.3); }
.fmla-t { background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.3); }
.fb-label { font-size: .62rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: #64748b; margin-bottom: 3px; }
.fb-val { font-size: .95rem; font-weight: 800; font-family: 'Space Grotesk', monospace; }
.fmla-d .fb-val { color: #a5b4fc; }
.fmla-s .fb-val { color: #6ee7b7; }
.fmla-t .fb-val { color: #fcd34d; }
.fb-sub { font-size: .6rem; color: #475569; margin-top: 2px; }
.fmla-insight { font-size: .78rem; color: #f59e0b; text-align: center; padding: 7px; background: rgba(245,158,11,.08); border-radius: 8px; border: 1px solid rgba(245,158,11,.2); min-height: 34px; display: flex; align-items: center; justify-content: center; }

/* GRAPH CANVAS */
#graphCanvas { width: 100%; border-radius: 8px; background: rgba(5,10,21,.8); border: 1px solid rgba(99,179,237,.1); }
.graph-legend { display: flex; gap: 10px; margin-top: 6px; }
.gl-item { display: flex; align-items: center; gap: 5px; font-size: .72rem; color: #94a3b8; }
.gl-dot { width: 10px; height: 10px; border-radius: 50%; }

/* CHALLENGE CARD */
.chall-type-row { display: flex; gap: 4px; margin-bottom: 10px; flex-wrap: wrap; }
.chall-type { flex: 1; padding: 5px; border-radius: 7px; font-family: 'Outfit', sans-serif; font-size: .72rem; font-weight: 600; cursor: pointer; border: 1px solid rgba(99,179,237,.15); background: rgba(30,41,59,.6); color: #64748b; transition: all .2s; white-space: nowrap; }
.chall-type.active { background: rgba(99,102,241,.25); border-color: #6366f1; color: #a5b4fc; }
.chall-question { font-size: .85rem; color: #e2e8f0; margin-bottom: 10px; line-height: 1.5; background: rgba(30,41,59,.6); padding: 10px; border-radius: 8px; min-height: 50px; }
.chall-input-row { display: flex; gap: 6px; margin-bottom: 8px; }
#chall-ans { flex: 1; background: rgba(30,41,59,.8); border: 1px solid rgba(99,179,237,.2); border-radius: 8px; padding: 7px 10px; color: #e2e8f0; font-family: 'Space Grotesk', monospace; font-size: .9rem; outline: none; }
#chall-ans:focus { border-color: #6366f1; }
.chall-btn { padding: 7px 14px; background: linear-gradient(135deg,#6366f1,#8b5cf6); color: #fff; border: none; border-radius: 8px; font-family: 'Outfit', sans-serif; font-weight: 600; font-size: .8rem; cursor: pointer; transition: all .2s; }
.chall-btn:hover { transform: translateY(-1px); }
.chall-result { padding: 8px; border-radius: 8px; font-size: .82rem; font-weight: 600; text-align: center; }
.chall-result.correct { background: rgba(16,185,129,.15); border: 1px solid rgba(16,185,129,.3); color: #6ee7b7; }
.chall-result.wrong   { background: rgba(239,68,68,.12);  border: 1px solid rgba(239,68,68,.3);  color: #f87171; }
.chall-result.close   { background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.3); color: #fcd34d; }
.chall-result.hidden  { display: none; }
.chall-new-btn { width: 100%; margin-top: 8px; padding: 7px; border-radius: 8px; font-family: 'Outfit', sans-serif; font-size: .78rem; font-weight: 600; cursor: pointer; background: rgba(30,41,59,.8); border: 1px solid rgba(99,179,237,.15); color: #64748b; transition: all .2s; display: flex; align-items: center; justify-content: center; gap: 6px; }
.chall-new-btn:hover { background: rgba(51,65,85,.8); color: #94a3b8; }

/* RESPONSIVE */
/* RULER TICKS */
.ruler-ticks { position: absolute; inset: 0; pointer-events: none; }
.ruler-tick {
    position: absolute; top: 0; height: 100%; border-left: 1px solid rgba(255,255,255,0.15);
    font-size: .58rem; color: rgba(255,255,255,.4); padding-top: 22px; padding-left: 2px;
    white-space: nowrap; font-family: 'Space Grotesk', monospace;
}

/* Media Queries Removed for Scaled #phet-stage Environment */
