/* =====================================================================
   jdanacademy — "futuristic skeuomorphic" 1997 multimedia math tutor
   Rules of the house:
     * no smooth gradients: every ramp is an ordered-dithered bitmap (dither.js)
     * no blurred shadows or glows: hard pixel offsets only
     * no smooth motion: every animation / transition runs in steps (~6-8 fps)
   ===================================================================== */

:root {
  --gold: #ffcc66;
  --cyan: #66ffff;
  --phosphor: #ccffff;
  --amber: #ffaa33;
  --ok: #66ff66;
  --bevel: inset 1px 1px 0 rgba(255, 255, 255, 0.45), inset -1px -1px 0 rgba(0, 0, 0, 0.75), inset 2px 2px 0 rgba(255, 255, 255, 0.15), inset -2px -2px 0 rgba(0, 0, 0, 0.35);
  --drop: 4px 4px 0 rgba(0, 0, 0, 0.55);
  --rim: #ccccff #333344 #333344 #ccccff; /* outset metal rim: light top-left, dark bottom-right */
  --ring: 0 0 0 2px #cccccc, 0 0 0 3px #333333, 0 0 0 4px #ffffff, 0 0 0 5px #000000;
  --serif: 'Copperplate', 'Copperplate Gothic Bold', 'Optima', 'Palatino Linotype', Georgia, serif;
  --ui: 'Trebuchet MS', 'Verdana', 'Tahoma', sans-serif;
  --math: 'Cambria Math', 'STIX Two Math', 'Latin Modern Math', 'Times New Roman', Times, serif;
  --lcd: 'Courier New', 'Lucida Console', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: #000; font-family: var(--ui); color: #f2f2f2; overflow: hidden; user-select: none; }
button { font-family: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
#desktop { position: fixed; inset: 0; display: grid; place-items: center; }
#app { width: 1024px; height: 740px; display: flex; flex-direction: column; transform-origin: center center; image-rendering: pixelated; }
.viewport { position: relative; flex: 1; overflow: hidden; background: #000022; }
.backdrop { position: absolute; inset: 0; background-image: var(--dither); }

/* ---------------- screens: hard cut ---------------- */
.screen { position: absolute; inset: 0; z-index: 1; visibility: hidden; }
.screen.active { visibility: visible; animation: cut-in 0.3s steps(2, jump-start) both; }
@keyframes cut-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------------- stone slabs ---------------- */
/* Every .slab / button is carved by dither.js into var(--chisel): octagonal stone with
   flat lit bevels and a hard shadow. These rules only position content inside the carving. */
.slab { position: relative; }
.carved { background: var(--chisel) 0 0 / 100% 100% no-repeat !important; border: 0 !important; border-radius: 0 !important; box-shadow: none !important; }
button.carved:hover { filter: brightness(1.12); }
button.carved:active { background-image: var(--chisel-down) !important; transform: translate(3px, 3px); filter: none; }
.carved.on { background-image: var(--chisel-on) !important; }
button.carved:disabled { filter: grayscale(1) brightness(0.65); transform: none; background-image: var(--chisel) !important; cursor: default; }

.screw { position: absolute; width: 11px; height: 11px; border-radius: 50%; z-index: 3; background: var(--screw); box-shadow: 1px 1px 0 #000; }
.screw::after { content: ''; position: absolute; left: 2px; right: 2px; top: 5px; height: 1px; background: #222; transform: rotate(var(--r, 35deg)); box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5); }
.screw.tl { top: 7px; left: 7px; } .screw.tr { top: 7px; right: 7px; --r: -20deg; }
.screw.bl { bottom: 7px; left: 7px; --r: 80deg; } .screw.br { bottom: 7px; right: 7px; --r: 10deg; }

/* ---------------- logo: carved jade granite, extruded with hard steps ---------------- */
.logo {
  margin: 0;
  font: 700 58px/1 var(--serif); letter-spacing: 0.04em;
  color: transparent;
  background: var(--granite-jade); background-size: 256px 256px;
  -webkit-background-clip: text; background-clip: text;
  filter: drop-shadow(1px 1px 0 #006655) drop-shadow(1px 1px 0 #004433) drop-shadow(1px 1px 0 #003333)
          drop-shadow(1px 1px 0 #002222) drop-shadow(1px 1px 0 #001111) drop-shadow(-1px -1px 0 #99ffee) drop-shadow(4px 4px 0 rgba(0, 0, 0, 0.6));
}
.logo.small { font-size: 38px; }

.plate {
  display: inline-block; padding: 5px 22px 6px;
  font: 700 15px/1.1 var(--serif); letter-spacing: 0.14em; text-transform: uppercase;
  color: #332211; text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.6);
  padding: 6px 26px 9px 23px;
}

/* ---------------- LEDs & LCDs ---------------- */
.led { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--led-off-10); box-shadow: 0 0 0 1px #000; vertical-align: middle; }
.led.on { background: var(--led-on-10); }
.led.amber { background: var(--led-amber-10); }
.led.red { background: var(--led-red-10); }
.led.small { width: 7px; height: 7px; background: var(--led-off-7); }
.led.small.on { background: var(--led-on-7); }

.lcd {
  font: bold 14px/1.2 var(--lcd); color: #99ffcc; letter-spacing: 0.06em;
  background: repeating-linear-gradient(180deg, #002200 0 1px, #003311 1px 3px);
  border-radius: 3px; padding: 6px 10px;
  box-shadow: inset 2px 2px 0 #000, inset -1px -1px 0 #114422, 0 0 0 1px #000, 1px 1px 0 rgba(255, 255, 255, 0.2);
}
.lcd.small { font-size: 12px; padding: 4px 8px; }

/* ---------------- buttons ---------------- */
.btn-round {
  position: relative; width: 40px; height: 40px; border-radius: 50%; border: 0; padding: 0;
  font: bold 14px/1 var(--ui); color: #ffffff; text-shadow: 1px 1px 0 #000033;
  padding: 0 3px 3px 0; /* keep glyphs centred on the face, not the shadow */
}
.btn-round.small { width: 34px; height: 34px; font-size: 10px; }
.btn-play { width: 48px; height: 46px; }
.btn-big { width: 116px; height: 96px; padding: 0 4px 4px 0; font: 700 17px/1 var(--serif); letter-spacing: 0.08em; text-transform: uppercase; }

.btn-marble {
  border: 0; border-radius: 4px; padding: 9px 14px;
  font: 700 13px/1.1 var(--ui); color: #221a11; text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.6);
  padding-bottom: 12px; padding-right: 17px;
}

/* ---------------- home ---------------- */
.home-header { position: absolute; top: 16px; left: 0; right: 0; display: grid; justify-items: center; gap: 10px; }
.home-header .logo { font-size: 64px; }
.subject-grid { position: absolute; top: 150px; left: 42px; width: 940px; display: grid; grid-template-columns: repeat(3, 300px); gap: 20px; }
.subject { height: 150px; padding: 0; text-align: left; color: #fff; overflow: hidden; display: grid; grid-template-columns: 110px 1fr; align-items: center; }
.icon-well { margin-left: 16px; width: 84px; height: 84px; display: grid; place-items: center; }
.icon-well svg { width: 58px; height: 58px; }
.subject h2 { margin: 0 14px 6px 6px; font: 700 20px/1.1 var(--serif); letter-spacing: 0.04em; text-shadow: 2px 2px 0 #000; }
.subject p { margin: 0 14px 0 6px; font: italic 13px var(--ui); color: #ffdddd; text-shadow: 1px 1px 0 #000; }
.subject .badge { margin: 10px 0 0 6px; display: inline-block; padding: 3px 8px; border-radius: 2px; font: bold 10px/1 var(--ui); letter-spacing: 0.12em; text-transform: uppercase; color: #99ffcc; background: #002200; box-shadow: inset 1px 1px 0 #000, 1px 1px 0 rgba(255, 255, 255, 0.25); }
.subject.locked { filter: saturate(0.2) brightness(0.7); }
.subject.locked .badge { color: #ffcc66; background: #221100; }
.subject.locked::after { content: 'INSERT DISC 2'; position: absolute; right: -36px; top: 14px; transform: rotate(32deg); padding: 3px 40px; font: bold 10px/1 var(--ui); letter-spacing: 0.14em; color: #331a00; background: #ffcc33; box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6); }
.subject.shake { animation: shake 0.4s steps(4) both; }
@keyframes shake { 25% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 75% { transform: translateX(-4px); } }
.status-plaque { position: absolute; left: 362px; top: 490px; width: 620px; height: 150px; padding: 22px 30px; display: grid; gap: 10px; align-content: center; font: 14px var(--ui); color: #ddeeff; text-shadow: 1px 1px 0 #000; }
.sp-row { display: flex; gap: 10px; align-items: center; }
.sp-row.lcd { justify-self: start; text-shadow: none; }
.sp-tip { font-size: 13px; color: #ccddee; display: block; }
.sp-tip b { color: var(--gold); }

/* ---------------- lesson layout ---------------- */
.lesson-header { position: absolute; top: 8px; left: 16px; right: 16px; height: 78px; display: grid; grid-template-columns: 160px 1fr 160px; align-items: center; }
.lesson-titles { display: grid; justify-items: center; gap: 6px; }
.back-btn { justify-self: end; }
.tutor { display: flex; align-items: center; gap: 10px; }
.tutor-label { font: bold 10px var(--ui); letter-spacing: 0.25em; color: #99aadd; text-shadow: 1px 1px 0 #000; }
.orb { position: relative; width: 58px; height: 58px; border-radius: 50%; background: var(--well); background-size: 100% 100%; box-shadow: var(--ring), inset 2px 2px 0 #000; }
.orb-core { position: absolute; left: 14px; top: 14px; width: 30px; height: 30px; background: var(--orb-core); transform: scale(calc(0.7 + var(--lvl, 0) * 0.5)); }
.orb-ring { position: absolute; inset: 6px; border-radius: 50%; border: 1px dashed #66ffff; animation: spin 8s steps(16) infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.chapters { position: absolute; top: 96px; left: 16px; width: 160px; bottom: 16px; display: grid; grid-template-rows: repeat(6, 1fr); gap: 10px; }
.chapter { padding: 8px 10px 8px 8px; color: #fff; text-align: left; display: grid; grid-template-columns: 40px 1fr; grid-template-rows: auto auto; column-gap: 8px; align-items: center; }
.chapter .ch-num { grid-row: span 2; width: 40px; height: 40px; display: grid; place-items: center; }
.chapter .ch-num svg { width: 30px; height: 30px; }
.chapter .ch-title { font: 700 13px/1.15 Georgia, 'Palatino Linotype', serif; text-shadow: 1px 1px 0 #000, -1px 0 0 #000, 0 -1px 0 #000, 2px 2px 0 #000; }
.chapter .ch-meta { display: flex; align-items: center; gap: 6px; font: bold 10px var(--lcd); color: #ffdddd; text-shadow: 1px 1px 0 #000; }
.chapter.active { filter: brightness(1.25); }
.chapter.active::before { content: ''; position: absolute; left: -12px; top: 50%; margin-top: -9px; border-left: 9px solid #66ffff; border-top: 9px solid transparent; border-bottom: 9px solid transparent; filter: drop-shadow(2px 2px 0 #000); }

.player { position: absolute; top: 96px; left: 192px; width: 600px; bottom: 16px; display: grid; grid-template-rows: 420px 56px 1fr; gap: 12px; }
.bezel { padding: 20px 20px 22px; }
.bezel-badge { position: absolute; bottom: 4px; left: 0; right: 0; text-align: center; font: bold 9px/1 var(--ui); letter-spacing: 0.35em; color: #8899bb; text-shadow: 1px 1px 0 #000; }
.bezel-badge .led { vertical-align: 0; }
.screen-crt { position: relative; width: 100%; height: 100%; border-radius: 12px / 10px; overflow: hidden; background-color: #000011; background-image: var(--dither); box-shadow: inset 2px 2px 0 #000, 0 0 0 2px #111122, 0 0 0 3px #555566; }
.screen-crt::before { content: ''; position: absolute; inset: 0; background: linear-gradient(#113366 1px, transparent 1px) 0 0 / 28px 28px, linear-gradient(90deg, #113366 1px, transparent 1px) 0 0 / 28px 28px; opacity: 0.6; }
.crt-scan, .crt-glass { position: absolute; inset: 0; pointer-events: none; }
.crt-scan { background: repeating-linear-gradient(180deg, rgba(0, 0, 0, 0.35) 0 1px, transparent 1px 3px); }
.crt-glass { border-radius: inherit; background-image: var(--dither); }
.crt-osd { position: absolute; top: 12px; right: 16px; font: bold 13px var(--lcd); color: #66ff66; text-shadow: 1px 1px 0 #003300; letter-spacing: 0.1em; visibility: hidden; }
.crt-osd.show { visibility: visible; animation: blink 0.8s steps(1) infinite; }
@keyframes blink { 50% { visibility: hidden; } }
.big-play { position: absolute; left: 50%; top: 50%; width: 112px; height: 88px; margin: -44px -56px; border: 0; }
.big-play span { position: absolute; left: 44px; top: 22px; border-left: 34px solid #ffffff; border-top: 20px solid transparent; border-bottom: 20px solid transparent; filter: drop-shadow(2px 2px 0 #000033); }
.big-play.hidden { visibility: hidden; }

.transport { display: flex; align-items: center; gap: 14px; padding: 0 16px; }
.transport .btn-round { flex: none; font-size: 13px; }
.scrubber { position: relative; flex: 1; height: 30px; cursor: pointer; }
.groove { position: absolute; left: 0; right: 0; top: 11px; height: 8px; border-radius: 2px; background: #000; box-shadow: inset 1px 1px 0 #333, 1px 1px 0 rgba(255, 255, 255, 0.3); overflow: hidden; }
.fill { height: 100%; width: 0; background: #3399ff; box-shadow: inset 0 2px 0 #99ffff, inset 0 -2px 0 #0044aa; }
.ticks { position: absolute; inset: 0; }
.ticks i { position: absolute; top: 0; bottom: 0; width: 2px; background: #000; }
.knob { position: absolute; top: 3px; left: 0; width: 24px; height: 26px; margin-left: -12px; background: var(--knob); }
.time { flex: none; width: 118px; text-align: center; }

.captions { padding: 12px 16px; display: flex; align-items: center; }
.caption-inner { width: 100%; height: 100%; padding: 10px 14px; border-radius: 4px; background: #110505; box-shadow: inset 2px 2px 0 #000, 1px 1px 0 rgba(255, 255, 255, 0.25); font: 15px/1.4 var(--ui); color: #ffffcc; overflow: hidden; }
.caption-tag { display: inline-block; margin-right: 8px; padding: 1px 6px; border-radius: 2px; font: bold 10px var(--lcd); color: #000; background: var(--gold); vertical-align: 2px; }
.captions.off .caption-inner > span:last-child { visibility: hidden; }

/* ---------------- the video stage (all motion in steps) ---------------- */
.stage { position: absolute; left: 0; top: 0; width: 560px; height: 378px; transform: scale(var(--stage-scale, 1)); transform-origin: 0 0; }
.layer { position: absolute; inset: 0; display: grid; place-items: center; animation: cut-in 0.25s steps(2, jump-start) both; }
.layer.out { display: none; }

.title-card { text-align: center; padding: 0 40px; }
.title-card h2 {
  margin: 0; font: 700 40px/1.1 var(--serif); letter-spacing: 0.04em;
  color: transparent; background: var(--title-ink); background-size: 8px 44px;
  -webkit-background-clip: text; background-clip: text;
  filter: drop-shadow(2px 2px 0 #000066) drop-shadow(1px 1px 0 #000033);
  animation: title-zoom 1s steps(6) both;
}
.title-card p { margin: 16px 0 0; font: italic 17px var(--ui); color: #ffcc66; text-shadow: 2px 2px 0 #331a00; animation: appear 0.6s 0.5s steps(1) both; }
.title-card .rule { width: 70%; height: 2px; margin: 16px auto 0; background: repeating-linear-gradient(90deg, #66ffff 0 4px, transparent 4px 6px); animation: grow 0.9s 0.3s steps(6) both; }
.title-card .chap { font: bold 13px var(--lcd); letter-spacing: 0.3em; color: #66ff66; margin-bottom: 12px; }
@keyframes title-zoom { from { transform: scale(0.4); } to { transform: none; } }
@keyframes appear { from { visibility: hidden; } to { visibility: visible; } }
@keyframes grow { from { width: 0; } }

.eq-scene { display: grid; gap: 22px; justify-items: center; padding: 30px; }
.mline { font: 30px/1.3 var(--math); color: var(--phosphor); text-shadow: 2px 2px 0 #003366; white-space: nowrap; }
.mline.old { opacity: 0.5; transform: scale(0.88); }
.mline.enter { animation: wipe 0.9s steps(7) both; }
@keyframes wipe { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
.eq-scene.big .mline { font-size: 42px; }
.mline.boxed { padding: 16px 28px; border: 2px solid #ffcc66; outline: 2px solid #663300; outline-offset: 2px; color: #fff; animation: wipe 0.9s steps(7) both, frame-blink 1.2s 1s steps(1) infinite; }
@keyframes frame-blink { 50% { border-color: #ffffff; } }
.note-tag { position: absolute; top: 14px; left: 16px; padding: 4px 10px; font: 18px var(--math); color: #331a00; background: #ffdd66; transform: rotate(-3deg); box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.6); animation: appear 0.5s 0.5s steps(1) both; }
.note-tag .op { margin: 0 0.15em; }

/* math typesetting */
.mline i, .mi i, .math-label i { font-style: italic; }
.op { margin: 0 0.28em; font-style: normal; }
.gap { display: inline-block; width: 1em; }
.txt { font-family: var(--ui); font-style: normal; font-size: 0.7em; margin: 0 0.5em; opacity: 0.85; }
sup { font-size: 0.6em; vertical-align: 0.75em; line-height: 0; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 0.12em; font-size: 0.9em; }
.frac > .num { padding: 0 0.2em 0.08em; border-bottom: 0.06em solid currentColor; }
.frac > .den { padding: 0.08em 0.2em 0; }
.sqrt { display: inline-flex; align-items: stretch; vertical-align: middle; }
.sqrt .radix { width: 0.62em; flex: none; overflow: visible; }
.sqrt .radix path { fill: none; stroke: currentColor; stroke-width: 0.075em; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.sqrt .rad { border-top: 0.065em solid currentColor; padding: 0.08em 0.12em 0 0.08em; margin-top: 0.03em; }
.qoptions .op, .lab-readout .op { margin: 0 0.05em; }
.hl { color: #ffcc66; border-radius: 2px; background: #332200; box-shadow: 0 0 0 2px #996600; padding: 0 0.1em; animation: hl-blink 0.6s 0.4s steps(2) 2 both; }
@keyframes hl-blink { 0% { background: transparent; box-shadow: none; } }

/* graphs & area model */
.viz { width: 100%; height: 100%; }
.viz .grid line { stroke: #113355; stroke-width: 1; }
.viz .axis { stroke: #aaccdd; stroke-width: 2; }
.viz .tick { fill: #88aabb; font: 12px var(--lcd); }
.viz .curve { fill: none; stroke: #ffcc66; stroke-width: 4; stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.6s 0.2s steps(10) forwards; }
.viz.static .curve { animation: none; stroke-dashoffset: 0; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.viz .root { fill: #66ff66; stroke: #003300; stroke-width: 2; animation: appear 0.4s steps(1) both; }
.viz .ring { fill: none; stroke: #66ff66; stroke-width: 2; stroke-dasharray: 4 3; transform-box: fill-box; transform-origin: center; animation: ring 1.2s steps(4) infinite; }
.viz .root-label { fill: #ccffcc; font: italic 20px var(--math); paint-order: stroke; stroke: #000011; stroke-width: 4px; animation: appear 0.4s steps(1) both; }
.viz .none-label { fill: #ff9999; font: bold 16px var(--lcd); letter-spacing: 0.15em; animation: appear 0.5s 0.8s steps(1) both; }
@keyframes ring { from { transform: scale(0.8); } to { transform: scale(2.2); opacity: 0; } }
.math-label { position: absolute; top: 14px; left: 18px; padding: 6px 12px; border-radius: 2px; font: 22px var(--math); color: #fff; background: #000022; box-shadow: 0 0 0 1px #3366aa, 3px 3px 0 rgba(0, 0, 0, 0.6); }

.area .sq { fill: #003366; stroke: #66ffff; stroke-width: 2; }
.area .strip rect { fill: #663300; stroke: #ffcc66; stroke-width: 2; }
.area .corner rect { fill: #003300; stroke: #66ff66; stroke-width: 2; stroke-dasharray: 6 4; animation: march 0.5s steps(2) infinite; }
@keyframes march { to { stroke-dashoffset: -10; } }
.area text { font: italic 22px var(--math); fill: #ccffff; text-anchor: middle; dominant-baseline: middle; }
.area .lab-strip { fill: #ffdd99; font-size: 18px; }
.area .lab-corner { fill: #99ff99; font-size: 20px; }
.area g, .area text { transition: transform 1.1s steps(7, jump-end), opacity 0.3s steps(1, jump-end); transform-box: view-box; transform-origin: 0 0; }
.area .strip-a { transform: translate(380px, 50px); }
.area .strip-b { transform: translate(420px, 50px) rotate(0deg); }
.area .strip, .area .corner, .area .lab-strip, .area .lab-corner, .area .lab-full { opacity: 0; }
.area.s1 .strip, .area.s2 .strip, .area.s3 .strip { opacity: 1; }
.area.s1 .lab-full { opacity: 1; }
.area.s2 .strip-a, .area.s3 .strip-a { transform: translate(360px, 50px); }
.area.s2 .strip-b, .area.s3 .strip-b { transform: translate(160px, 290px) rotate(-90deg); }
.area.s2 .lab-strip, .area.s3 .lab-strip { opacity: 1; }
.area.s3 .corner, .area.s3 .lab-corner { opacity: 1; }
.area-caption { position: absolute; bottom: 18px; left: 0; right: 0; text-align: center; font: 24px var(--math); color: #fff; text-shadow: 2px 2px 0 #003366; }

/* ---------------- quiz ---------------- */
.quiz { position: absolute; top: 96px; right: 16px; width: 200px; bottom: 16px; padding: 22px 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.quiz-head { display: grid; gap: 8px; justify-items: center; }
.quiz-title { width: 100%; padding: 6px 4px; text-align: center; font: 700 13px/1.15 var(--serif); letter-spacing: 0.16em; color: #332211; padding: 7px 7px 10px 4px; text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.6); }
.quiz-leds { display: flex; gap: 8px; padding: 6px 10px; border-radius: 4px; background: #000; box-shadow: inset 1px 1px 0 #333, 1px 1px 0 rgba(255, 255, 255, 0.2); }
.quiz-leds .led.current { box-shadow: 0 0 0 1px #000, 0 0 0 3px #66ffff; animation: ring-blink 0.8s steps(1) infinite; }
@keyframes ring-blink { 50% { box-shadow: 0 0 0 1px #000; } }
.quiz-body { flex: 1; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.qscreen { padding: 10px; border-radius: 3px; min-height: 108px; font: 13.5px/1.4 var(--ui); color: #ffdd99; background: repeating-linear-gradient(180deg, #1a0d00 0 1px, #2a1800 1px 3px); box-shadow: inset 2px 2px 0 #000, 0 0 0 1px #000, 1px 1px 0 rgba(255, 255, 255, 0.2); }
.qscreen .qnum { display: block; margin-bottom: 4px; font: bold 10px var(--lcd); letter-spacing: 0.2em; color: var(--amber); }
.qscreen .mi { font: 16px var(--math); color: #ffffcc; white-space: nowrap; }
.qscreen .mi .op { margin: 0 0.15em; }
.qoptions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.qoptions .btn-marble { padding: 8px 7px 11px 4px; font: 20px var(--math); }
.qoptions .btn-marble.right { filter: sepia(1) saturate(3) hue-rotate(60deg) brightness(1.05); }
.qoptions .btn-marble.wrong { filter: sepia(1) saturate(4) hue-rotate(-35deg); animation: shake 0.35s steps(4) both; }
.qfeedback { min-height: 34px; font: bold 12px/1.35 var(--ui); text-align: center; padding: 0 4px; }
.qfeedback.ok { color: var(--ok); animation: blink 0.5s steps(1) 3; }
.qfeedback.bad { color: #ff9999; }
.qfeedback .hint { display: block; margin-top: 4px; font: italic 12px var(--ui); color: #ccddee; }
.qactions { margin-top: auto; display: flex; gap: 8px; }
.qactions .btn-marble { flex: 1; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.keypad .btn-marble { padding: 5px 3px 8px 0; font: bold 15px var(--lcd); }
.keypad .enter { grid-column: span 3; font: bold 12px var(--ui); letter-spacing: 0.15em; }
.qdisplay { font-size: 22px; text-align: right; min-height: 38px; }
.lab-graph { height: 120px; border-radius: 3px; background: #000011; box-shadow: inset 2px 2px 0 #000, 0 0 0 1px #000, 1px 1px 0 rgba(255, 255, 255, 0.2); overflow: hidden; }
.lab-graph svg { width: 100%; height: 100%; }
.lab-graph .curve { fill: none; stroke: #ffcc66; stroke-width: 2.5; }
.lab-graph .axis { stroke: #aaccdd; stroke-width: 1.5; }
.lab-graph .gridl { stroke: #113355; }
.lab-graph .root { fill: #66ff66; stroke: #003300; }
.slider { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; }
.slider::-webkit-slider-runnable-track { height: 8px; border-radius: 2px; background: #000; box-shadow: inset 1px 1px 0 #333, 1px 1px 0 rgba(255, 255, 255, 0.3); }
.slider::-moz-range-track { height: 8px; border-radius: 2px; background: #000; }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 24px; margin-top: -7px; background: var(--thumb); }
.slider::-moz-range-thumb { width: 22px; height: 24px; border-radius: 0; border: 0; background: var(--thumb); }
.lab-readout { display: flex; justify-content: space-between; }
.quiz-start, .quiz-end { flex: 1; display: grid; justify-items: center; align-content: center; gap: 14px; text-align: center; font: 13px/1.4 var(--ui); color: #ccddee; text-shadow: 1px 1px 0 #000; }
.quiz-end .score { font: bold 44px var(--lcd); color: #99ffcc; text-shadow: 3px 3px 0 #003311; }
.quiz-end .rank { font: 700 15px var(--serif); letter-spacing: 0.08em; color: var(--gold); }

/* ---------------- navbar (Mavis-style) ---------------- */
.navbar { height: 32px; flex: none; display: flex; align-items: center; justify-content: space-around; padding: 0 60px; background: #000044; box-shadow: inset 0 1px 0 #3333aa, inset 0 2px 0 #000; }
.navbar button { background: none; border: 0; padding: 4px 10px; font: 700 15px/1 var(--serif); letter-spacing: 0.1em; color: var(--gold); text-shadow: 2px 2px 0 #000; }
.navbar button:hover { color: #ffffff; }
.navbar i { color: var(--gold); font-style: normal; }

/* ---------------- dialogs (in-app panels) ---------------- */
.modal { position: absolute; inset: 0; z-index: 50; display: grid; place-items: center; background: repeating-conic-gradient(rgba(0, 0, 0, 0.75) 0 25%, transparent 0 50%) 0 0 / 2px 2px; }
.modal[hidden] { display: none; }
.dialog { width: 440px; padding: 26px 28px 22px; display: grid; justify-items: center; gap: 14px; font: 13px/1.5 var(--ui); color: #ddeeff; text-shadow: 1px 1px 0 #000; }
.dialog-body { width: 100%; display: grid; gap: 12px; }
.dialog-body label { display: grid; grid-template-columns: 110px 1fr 40px; align-items: center; gap: 8px; }
.dialog-body .val { font: bold 12px var(--lcd); color: #99ffcc; text-align: right; }
.dialog-body .row { display: flex; gap: 8px; justify-content: center; margin-top: 4px; }
.dialog-body .row .btn-marble { min-width: 96px; }

/* now playing + credits */
.now-playing { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 440px; }
.dialog .now-playing { max-width: none; }
.small-btn { padding: 4px 13px 7px 8px; font-size: 11px; }
.credits { max-height: 150px; overflow: auto; font-size: 11px; line-height: 1.35; color: #ccddee; }
.credits p { margin: 0 0 6px; }
.dialog { width: min(520px, 94vw); }

/* ======================================================================
   Phones: one scrolling column. Same carved stone, just stacked.
   (Keep this query in sync with MOBILE in app.js.)
   ====================================================================== */
@media (max-width: 760px), (max-height: 500px) {
  html, body { height: auto; overflow-x: hidden; overflow-y: auto; }
  #desktop { position: static; display: block; }
  #app { width: 100%; max-width: 560px; height: auto; min-height: 100vh; min-height: 100dvh; margin: 0 auto; transform: none !important; }
  .viewport { flex: 1; overflow: visible; }
  .backdrop { position: fixed; }
  .screen { position: relative; display: none; visibility: visible; }
  .screen.active { display: flex; flex-direction: column; gap: 12px; padding: 12px 10px 18px; }

  /* home */
  .home-header { position: static; gap: 8px; }
  .home-header .logo { font-size: min(11vw, 52px); }
  .subject-grid { position: static; width: auto; grid-template-columns: 1fr; gap: 10px; }
  .subject { height: 104px; grid-template-columns: 86px 1fr; }
  .icon-well { margin-left: 12px; width: 64px; height: 64px; }
  .icon-well svg { width: 44px; height: 44px; }
  .subject h2 { font-size: 17px; }
  .subject .badge { margin-top: 6px; }
  .status-plaque { position: relative; inset: auto; width: auto; height: auto; padding: 20px 22px; }
  .sp-row { flex-wrap: wrap; }
  .now-playing { max-width: calc(100vw - 150px); }

  /* lesson: header, player, chapters, quiz */
  .lesson-header { position: static; height: auto; grid-template-columns: 58px 1fr auto; gap: 8px; }
  .tutor-label { display: none; }
  .lesson-titles .logo.small { font-size: min(7.5vw, 34px); }
  .lesson-titles .plate { font-size: 11px; padding-left: 14px; padding-right: 17px; }
  .back-btn { font-size: 11px; padding: 7px 12px 10px 8px; }
  .player { position: static; width: auto; order: 1; grid-template-rows: auto 56px auto; gap: 10px; }
  .bezel { padding: 12px 12px 18px; }
  .screen-crt { height: auto; aspect-ratio: 560 / 378; }
  .big-play { transform: scale(0.75); }
  .transport { gap: 8px; padding: 0 12px; }
  .time { width: 70px; font-size: 11px; padding: 5px 4px; }
  #cc-btn { display: none; }
  .captions { min-height: 84px; }
  .chapters { position: static; width: auto; order: 2; grid-template-columns: 1fr 1fr; grid-template-rows: none; gap: 8px; }
  .chapter { min-height: 66px; }
  .chapter.active::before { display: none; }
  .chapter.active .ch-title { color: #66ffff; }
  .quiz { position: relative; inset: auto; width: auto; order: 3; min-height: 460px; }
  .qoptions .btn-marble { font-size: 22px; padding-top: 12px; padding-bottom: 15px; }
  .keypad .btn-marble { padding-top: 10px; padding-bottom: 13px; }
  .lab-graph { height: auto; aspect-ratio: 176 / 120; }

  /* nav pinned to the bottom of the screen */
  .navbar { position: sticky; bottom: 0; z-index: 20; height: 44px; padding: 0 6px; padding-bottom: env(safe-area-inset-bottom); }
  .navbar button { font-size: 13px; padding: 8px 6px; }
  .modal { position: fixed; }
}

/* screenshot mode (index.html?shot#…): jump every transition/animation to its end state */
.instant *, .instant *::before, .instant *::after { transition: none !important; animation-duration: 0s !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; }
.instant .big-play { display: none; }
