/* =============================================================================
   PlayLab — "Soft Lab"
   Pillowy, optimistic light chrome on a soft lavender-cream base, wrapped around
   a dark, focused game arena. Light cards reason; the dark stage is where you
   plot. Buttons are chunky and pressable; the cyan curve is the thing you win.
   ============================================================================= */

:root {
  /* — Surfaces / ink (light chrome) — */
  --bg:        #F1EEFA;
  --bg-tint:   #E8E3F8;
  --surface:   #FFFFFF;
  --surface-2: #F4F1FC;
  --surface-3: #EAE5F8;
  --line:      #E4DEF4;
  --ink:       #211C3D;
  --ink-dim:   #5E5880;
  --ink-faint: #918BAE;

  /* — Brand / accents — */
  --primary:    #6C5CE7;
  --primary-2:  #8B7BFF;
  --primary-d:  #5A49D6;
  --primary-ink:#FFFFFF;
  --accent:     #FF7A59;
  --accent-2:   #FF9D7E;
  --accent-d:   #ED6643;

  /* — Status / game — */
  --success:   #34E2A8;
  --success-d: #0F8F66;
  --warn:      #FFB020;
  --danger:    #FF5C7A;
  --danger-d:  #D63357;
  --gold:      #FFD34D;
  --silver:    #C6CFDD;
  --bronze:    #E0985A;

  /* — Arena / canvas palette (dark stage) — */
  --arena-bg:   #131124;
  --arena-bg-2: #1C1A38;
  --arena-ink:  #B9B5DE;
  --cyan:       #37E1FF;
  --cyan-core:  #EAFCFF;
  --mint:       #34E2A8;

  /* — Radii — */
  --r-xs: 8px;  --r-sm: 12px; --r-md: 16px;
  --r-lg: 22px; --r-xl: 30px; --r-2xl: 40px; --r-pill: 999px;

  /* — Type — */
  --display:'Fredoka', system-ui, sans-serif;
  --ui:'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --mono:'JetBrains Mono', ui-monospace, monospace;

  /* — Elevation: soft-3D / pillowy — */
  --sh-1: 0 1px 2px rgba(33,18,82,.05), 0 3px 8px rgba(60,40,120,.06);
  --sh-2: 0 2px 4px rgba(33,18,82,.05), 0 10px 26px rgba(60,40,120,.10);
  --sh-3: 0 4px 8px rgba(33,18,82,.06), 0 22px 50px rgba(60,40,120,.16);
  --hi:   inset 0 1px 0 rgba(255,255,255,.75);
  --hi-soft: inset 0 1px 0 rgba(255,255,255,.5);
  --glow-primary: 0 8px 22px rgba(108,92,231,.42);
  --glow-coral:   0 8px 22px rgba(255,122,89,.40);

  /* — Motion — */
  --pop:   cubic-bezier(.34,1.56,.64,1);
  --out:   cubic-bezier(.16,1,.3,1);
  --press: cubic-bezier(.2,.8,.2,1);

  /* — Legacy aliases (referenced by inline SVG/JS) — */
  --curve: var(--cyan);
  --data:  var(--danger);
  --good:  var(--success);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  color: var(--ink);
  font-family: var(--ui);
  font-size: 16px;
  line-height: 1.5;
  background:
    radial-gradient(1200px 700px at 12% -8%, #FBEFF0 0%, rgba(251,239,240,0) 55%),
    radial-gradient(1100px 800px at 100% 0%, #E7E0FB 0%, rgba(231,224,251,0) 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
h1, h2, h3, h4 { font-family: var(--display); font-weight: 600; letter-spacing: -.01em; line-height: 1.05; }
button { font-family: inherit; cursor: pointer; }
::selection { background: rgba(108,92,231,.22); }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 6px; }

#app, #landing, .modal, .toast { position: relative; z-index: 2; }

/* shared icon system */
.ico { width: 18px; height: 18px; stroke: currentColor; stroke-width: 1.9;
  fill: none; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; display: block; }

/* =============================================================================
   LANDING — the emotional opener
   ============================================================================= */
#landing {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center;
  padding: clamp(28px, 6vw, 84px);
  overflow: hidden;
  background: linear-gradient(170deg, #FBFAFE 0%, #F3EFFC 58%, #EFE9FB 100%);
  transition: opacity .55s var(--out), visibility .55s;
}
#landing.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

/* soft brand glows */
#landing::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(540px 420px at 88% 8%, rgba(255,122,89,.16), transparent 60%),
    radial-gradient(620px 520px at 8% 96%, rgba(108,92,231,.18), transparent 60%);
}

/* the plotted phenomenon behind the words (faint) */
.lab-plot {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; opacity: 0;
  -webkit-mask-image: linear-gradient(105deg, transparent 0%, #000 30%, #000 80%, transparent 100%);
          mask-image: linear-gradient(105deg, transparent 0%, #000 30%, #000 80%, transparent 100%);
  animation: plot-fade 1s ease .15s forwards;
}
@keyframes plot-fade { to { opacity: .28; } }
.plot-curve {
  fill: none; stroke: var(--primary); stroke-width: 2.6;
  filter: drop-shadow(0 0 10px rgba(108,92,231,.4));
  stroke-dasharray: 3000; stroke-dashoffset: 3000;
  animation: draw-curve 2.4s var(--out) .2s forwards;
}
@keyframes draw-curve { to { stroke-dashoffset: 0; } }
.plot-pt { opacity: 0; transform-box: fill-box; transform-origin: center; }
.plot-pt circle.ring { fill: none; stroke: var(--accent); stroke-width: 2; }
.plot-pt line { stroke: var(--accent); stroke-width: 1.4; opacity: .7; }
.plot-pt.show { animation: pt-pop .5s var(--pop) forwards; }
@keyframes pt-pop { from { opacity: 0; transform: scale(.3); } to { opacity: .9; transform: scale(1); } }

.landing-inner {
  position: relative; z-index: 2; max-width: 760px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 18px;
}
.landing-inner > * { opacity: 0; animation: rise .7s var(--out) forwards; }
.landing-brand   { animation-delay: .05s; }
.landing-eyebrow { animation-delay: .15s; }
.landing-headline{ animation-delay: .22s; }
.landing-sub     { animation-delay: .55s; }
.landing-src     { animation-delay: .62s; }
.landing-feats   { animation-delay: .70s; }
.landing-cta     { animation-delay: .92s; }
@keyframes rise { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }

.landing-brand { display: flex; align-items: center; gap: 13px; }
.landing-brand .mark, .brand .mark { filter: drop-shadow(0 6px 16px rgba(108,92,231,.4)); }
.landing-brand .mark { width: 48px; height: 48px; }
.brand-name { font-family: var(--display); font-size: 24px; font-weight: 600; letter-spacing: -.01em; line-height: 1; color: var(--ink); }
.brand-sub  { font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--primary); margin-top: 4px; }

.landing-eyebrow {
  font-family: var(--mono); font-size: 12px; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: var(--primary);
}
.landing-headline {
  align-self: stretch; max-width: 100%;
  font-family: var(--display);
  font-size: clamp(38px, 6.4vw, 76px);
  font-weight: 600; line-height: 1.02; letter-spacing: -.02em;
  color: var(--ink); text-wrap: balance;
}
.landing-headline .stat-num {
  font-family: var(--mono); font-weight: 700;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
  color: var(--accent-d);
}
.landing-headline .stat-unit { color: var(--accent-d); }
.landing-headline .rest { display: block; color: var(--ink); }

.landing-sub {
  font-size: clamp(16px, 1.8vw, 20px); color: var(--ink-dim);
  line-height: 1.5; max-width: 54ch; font-weight: 500;
}
.landing-sub b  { color: var(--ink); font-weight: 700; }
.landing-sub em { font-style: normal; color: var(--primary); font-weight: 700; }
.landing-src { font-size: 12.5px; color: var(--ink-faint); font-weight: 600; }

.landing-feats { display: flex; gap: 14px; margin: 8px 0; flex-wrap: wrap; }
.feat {
  display: flex; align-items: flex-start; gap: 12px; flex: 1 1 200px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 15px 16px;
  box-shadow: var(--sh-1), var(--hi);
}
.feat-ico {
  width: 42px; height: 42px; border-radius: 13px;
  display: grid; place-items: center; flex: 0 0 auto;
  background: #ECE8FD; color: var(--primary); box-shadow: var(--hi);
}
.feat-ico.is-data { color: var(--accent-d); background: #FFEDE6; }
.feat-ico.is-good { color: var(--success-d); background: #E6FBF3; }
.feat-ico .fx { font-family: var(--mono); font-size: 15px; font-weight: 700; color: var(--ink); letter-spacing: -.02em; }
.feat-ico .ico { width: 21px; height: 21px; }
.feat b { display: block; font-size: 14px; font-weight: 800; color: var(--ink); }
.feat small { display: block; font-size: 12.5px; color: var(--ink-dim); margin-top: 3px; line-height: 1.4; }

.landing-cta { display: flex; align-items: center; gap: 18px; margin-top: 10px; flex-wrap: wrap; }
.landing-note { font-size: 12.5px; color: var(--ink-faint); font-weight: 600; }

/* the primary call — a chunky pillowy button */
.btn-cta {
  display: inline-flex; align-items: center; gap: 10px; border: none;
  font-family: var(--ui); font-size: 17px; font-weight: 800; color: var(--primary-ink); letter-spacing: .01em;
  height: 58px; padding: 0 30px; border-radius: var(--r-pill);
  background: linear-gradient(180deg, var(--primary-2), var(--primary));
  box-shadow: var(--glow-primary), var(--hi-soft), 0 7px 0 0 var(--primary-d);
  transition: transform .12s var(--press), box-shadow .12s var(--press), filter .2s;
}
.btn-cta .ico { width: 20px; height: 20px; transition: transform .25s var(--pop); }
.btn-cta:hover { filter: brightness(1.04); transform: translateY(-1px); }
.btn-cta:hover .ico { transform: translateX(4px); }
.btn-cta:active { transform: translateY(5px); box-shadow: var(--glow-primary), var(--hi-soft), 0 2px 0 0 var(--primary-d); }

/* =============================================================================
   APP SHELL
   ============================================================================= */
#app {
  display: flex; flex-direction: column; height: 100vh; height: 100dvh;
  padding: clamp(12px, 1.6vw, 20px);
  gap: clamp(12px, 1.6vw, 18px);
  animation: app-in .6s var(--out) both;
}
@keyframes app-in { from { opacity: 0; } to { opacity: 1; } }

/* ---- topbar: a pillowy white card ---- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 18px; flex: 0 0 auto; flex-wrap: wrap;
  background: linear-gradient(180deg, #FFFFFF, #F7F4FE);
  border: 1px solid var(--line); border-radius: var(--r-xl);
  box-shadow: var(--sh-2), var(--hi);
  animation: drop-in .55s var(--out) .05s both;
}
@keyframes drop-in { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; transform: none; } }
.brand { display: flex; align-items: center; gap: 11px; flex: 0 0 auto; }
.brand .mark { width: 40px; height: 40px; }
.brand .brand-name { font-size: 23px; }

/* ---- generate bar ---- */
.genbar { display: flex; gap: 8px; align-items: center; flex: 1 1 300px; min-width: 240px; }
.gen-field {
  display: flex; align-items: center; gap: 10px; flex: 1 1 auto; min-width: 0;
  height: 46px; background: var(--surface-2); border: 1.5px solid var(--line);
  border-radius: var(--r-pill); padding: 0 16px;
  box-shadow: inset 0 2px 5px rgba(33,18,82,.05);
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.gen-field .ico { color: var(--primary); width: 17px; height: 17px; }
.gen-field:focus-within {
  border-color: var(--primary); background: #fff;
  box-shadow: inset 0 2px 5px rgba(33,18,82,.04), 0 0 0 4px rgba(108,92,231,.16);
}
.gen-input {
  flex: 1 1 auto; min-width: 0; background: transparent; border: none; outline: none;
  font-family: var(--ui); font-size: 14px; font-weight: 500; color: var(--ink);
}
.gen-input::placeholder { color: var(--ink-faint); font-weight: 500; }

/* coral primary action */
.btn-gen {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; border: none;
  height: 46px; padding: 0 20px;
  font-family: var(--ui); font-size: 14px; font-weight: 800; color: var(--primary-ink); letter-spacing: .01em;
  border-radius: var(--r-pill);
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  box-shadow: var(--glow-coral), var(--hi-soft), 0 6px 0 0 var(--accent-d);
  transition: transform .12s var(--press), box-shadow .12s var(--press), filter .2s, opacity .2s;
}
.btn-gen .spark { width: 17px; height: 17px; color: #fff; }
.btn-gen:hover { filter: brightness(1.04); transform: translateY(-1px); }
.btn-gen:active { transform: translateY(4px); box-shadow: var(--glow-coral), var(--hi-soft), 0 2px 0 0 var(--accent-d); }
.btn-gen:disabled { opacity: .6; cursor: wait; }
.btn-gen:disabled .spark { animation: spark-spin 1s linear infinite; }
@keyframes spark-spin { to { transform: rotate(360deg); } }

/* ---- icon buttons (mute, homework) ---- */
.icon-btn {
  width: 46px; height: 46px; flex: 0 0 auto;
  display: grid; place-items: center; color: var(--primary);
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--r-pill);
  box-shadow: var(--sh-1), var(--hi);
  transition: color .15s, border-color .15s, transform .12s var(--press);
}
.icon-btn:hover { border-color: var(--primary); transform: translateY(-1px); }
.icon-btn:active { transform: translateY(2px); }
#muteBtn .ico-off { display: none; }
#muteBtn[data-muted="1"] { color: var(--ink-faint); }
#muteBtn[data-muted="1"] .ico-on { display: none; }
#muteBtn[data-muted="1"] .ico-off { display: block; }

/* ---- demos / level chips ---- */
.levels-wrap { display: flex; align-items: center; gap: 9px; flex: 1 1 100%; flex-wrap: wrap; }
.levels-label { font-size: 11px; font-weight: 800; letter-spacing: .16em;
  text-transform: uppercase; color: var(--ink-faint); }
.levels { display: flex; gap: 8px; flex-wrap: wrap; }
.level-chip {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px;
  font-family: var(--ui); font-size: 12.5px; font-weight: 700; color: var(--ink-dim);
  border: 1.5px solid var(--line); border-radius: var(--r-pill); background: var(--surface);
  box-shadow: var(--sh-1);
  transition: color .16s, border-color .2s, transform .12s var(--press), background .2s;
}
.level-chip:hover { color: var(--ink); transform: translateY(-1px); }
.level-chip.active {
  color: var(--primary); border-color: var(--primary); background: #F3F0FE;
  box-shadow: var(--sh-1), 0 0 0 3px rgba(108,92,231,.14);
}
.level-chip .diff { font-family: var(--mono); font-size: 10px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink-faint); }
.level-chip.active .diff { color: var(--primary-d); }
.level-chip .dot { width: 8px; height: 8px; border-radius: 50%; box-shadow: 0 0 0 3px rgba(0,0,0,.03); }
.level-chip .dot.easy   { background: var(--success); }
.level-chip .dot.medium { background: var(--warn); }
.level-chip .dot.hard   { background: var(--danger); }
/* generated-level chip shimmers */
#genChip {
  color: #fff; border-color: transparent;
  background: linear-gradient(110deg, var(--primary), var(--primary-2) 60%, var(--accent));
  background-size: 200% 100%; box-shadow: var(--sh-2);
  animation: shimmer 4.5s linear infinite;
}
@keyframes shimmer { to { background-position: 200% 0; } }

/* =============================================================================
   STAGE — arena + panel
   ============================================================================= */
.stage {
  flex: 1 1 auto; display: grid; grid-template-columns: 1.5fr minmax(340px, .95fr);
  gap: clamp(12px, 1.6vw, 18px); min-height: 0;
}

.arena-wrap {
  position: relative; border-radius: var(--r-xl); overflow: hidden;
  background: var(--arena-bg);
  box-shadow: var(--sh-3), inset 0 0 0 1px rgba(255,255,255,.04);
  animation: arena-in .6s var(--out) .12s both;
}
@keyframes arena-in { from { opacity: 0; transform: scale(.985); } to { opacity: 1; transform: none; } }
canvas#game { display: block; width: 100%; height: 100%; }

/* a figure label floating over the arena (decorative) */
.arena-fig {
  position: absolute; top: 14px; right: 16px; z-index: 3; pointer-events: none;
  font-family: var(--mono); font-size: 11px; font-weight: 700; letter-spacing: .06em;
  color: var(--arena-ink);
  background: rgba(40,36,72,.55); border: 1px solid rgba(255,255,255,.1);
  padding: 5px 9px; border-radius: var(--r-pill);
}

/* ---- overlay messages (sit on the dark arena) ---- */
.overlay {
  position: absolute; inset: 0; z-index: 4;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none; text-align: center;
}
.overlay:not(:empty) { background: rgba(19,17,36,.32); }
.overlay .big {
  position: relative;
  font-family: var(--display); font-size: clamp(38px, 6.5vw, 72px); font-weight: 700;
  letter-spacing: -.01em; line-height: 1; color: #fff;
  transform: translateY(10px) scale(.92); opacity: 0;
  animation: stamp .5s var(--pop) forwards;
}
.overlay .big.win  { color: #EAFFF6; text-shadow: 0 0 40px rgba(52,226,168,.55); }
.overlay .big.lose { color: #FFE7EC; text-shadow: 0 0 34px rgba(255,92,122,.45); }
.overlay .big.win::after {
  content: ""; position: absolute; inset: -10% -20%;
  background: linear-gradient(105deg, transparent 38%, rgba(255,255,255,.55) 50%, transparent 62%);
  transform: translateX(-120%); animation: sweep 1.1s var(--out) .3s 1;
  pointer-events: none; mix-blend-mode: screen;
}
@keyframes sweep { to { transform: translateX(120%); } }
.overlay .sub {
  display: block; font-family: var(--ui); font-size: 15px; font-weight: 600; color: #C9C6E8;
  margin-top: 12px;
}
@keyframes stamp { to { transform: translateY(0) scale(1); opacity: 1; } }
/* overlay action buttons (Go harder, etc.) — interactive on the dark stage */
.ov-actions { display: flex; gap: 10px; margin-top: 18px; justify-content: center; pointer-events: auto; }
.ov-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 46px; padding: 0 22px; border: none; border-radius: var(--r-pill);
  font-family: var(--ui); font-weight: 800; font-size: 14px; color: #fff;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  box-shadow: var(--glow-coral), var(--hi-soft), 0 5px 0 0 var(--accent-d);
  transition: transform .12s var(--press), box-shadow .12s var(--press), filter .2s;
}
.ov-btn .ico { width: 17px; height: 17px; }
.ov-btn:hover { filter: brightness(1.04); transform: translateY(-1px); }
.ov-btn:active { transform: translateY(3px); box-shadow: var(--glow-coral), var(--hi-soft), 0 2px 0 0 var(--accent-d); }

/* ---- proof theater: the AI build log ---- */
.overlay .proof {
  min-width: 380px; max-width: 86%;
  background: rgba(19,17,36,.94);
  border: 1px solid rgba(255,255,255,.1); border-radius: var(--r-md);
  padding: 18px 20px; pointer-events: none;
  font-family: var(--mono); text-align: left;
  box-shadow: var(--sh-3);
}
.proof-head { font-size: 12.5px; font-weight: 700; color: var(--cyan-core); letter-spacing: .3px; margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px; }
.proof-head::before {
  content: ""; width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto;
  background: var(--cyan); box-shadow: 0 0 10px var(--cyan); animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: .3; } }
.proof-lines { max-height: 190px; overflow: hidden; display: flex; flex-direction: column; gap: 3px; }
.proof-line { font-size: 12.5px; line-height: 1.6; color: var(--arena-ink); padding-left: 20px; position: relative;
  animation: proof-in .26s var(--out) both; }
@keyframes proof-in { from { opacity: 0; transform: translateY(5px); } }
.proof-line::before { content: "›"; position: absolute; left: 4px; color: var(--cyan); }
.proof-line.ok   { color: var(--mint); }
.proof-line.ok::before   { content: "✓"; color: var(--mint); }
.proof-line.fail { color: var(--danger); }
.proof-line.fail::before { content: "✗"; color: var(--danger); }
.proof-caret { width: 8px; height: 15px; margin: 7px 0 0 20px; background: var(--cyan); opacity: .85;
  animation: blink 1s steps(1) infinite; }

/* ---- "no law here" suggestions ---- */
.overlay .suggest { pointer-events: auto; display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: 76%; }
.overlay .suggest .title { font-family: var(--display); font-size: 26px; font-weight: 700; color: #fff; }
.overlay .suggest .sub { font-size: 14px; color: var(--arena-ink); line-height: 1.5; }
.overlay .suggest .chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.overlay .suggest .chips button {
  font-family: var(--ui); font-size: 13px; font-weight: 700; color: var(--cyan-core);
  background: rgba(255,255,255,.06); border: 1.5px solid rgba(255,255,255,.16); border-radius: var(--r-pill);
  padding: 9px 15px; transition: transform .15s var(--press), background .2s, border-color .2s;
}
.overlay .suggest .chips button:hover { background: rgba(55,225,255,.16); border-color: var(--cyan); transform: translateY(-1px); }

.overlay .loader { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.overlay .spinner { width: 46px; height: 46px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.12); border-top-color: var(--cyan); animation: spark-spin .8s linear infinite; }
.overlay .loader-text { font-size: 16px; font-weight: 600; color: #fff; }

/* =============================================================================
   PANEL — the white card where you reason
   ============================================================================= */
.panel {
  position: relative;
  background: linear-gradient(180deg, #FFFFFF, #FAF8FE);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-2), var(--hi);
  padding: 22px;
  display: flex; flex-direction: column; gap: 15px;
  overflow-y: auto;
  animation: panel-in .6s var(--out) .18s both;
}
@keyframes panel-in { from { opacity: 0; transform: translateX(22px); } to { opacity: 1; transform: none; } }

.panel-head { display: flex; flex-direction: column; gap: 8px; }
.panel-head .subject-chip + .source-chip { margin-top: 0; }
.subject-chip {
  display: inline-flex; align-items: center; gap: 6px; align-self: flex-start;
  font-size: 11px; font-weight: 800; letter-spacing: .12em;
  text-transform: uppercase; color: var(--primary-d);
  padding: 6px 11px; border-radius: var(--r-pill); background: #ECE8FD;
}
.source-chip {
  display: inline-flex; align-items: center; gap: 5px; vertical-align: middle;
  font-size: 11px; font-weight: 800; letter-spacing: .08em;
  text-transform: uppercase; color: #fff;
  padding: 6px 11px; border-radius: var(--r-pill);
  background: linear-gradient(110deg, var(--primary), var(--accent)); background-size: 200% 100%;
  margin-left: 7px; animation: shimmer 4.5s linear infinite;
}
.source-chip .spark { width: 13px; height: 13px; }

.panel-head h1, .level-title {
  font-family: var(--display); font-size: 30px; font-weight: 600; line-height: 1.04; letter-spacing: -.01em;
  color: var(--ink);
}
.concept { font-size: 13.5px; color: var(--ink-dim); line-height: 1.55; }

/* ---- AI explainer: tap to reveal how the graph works ---- */
.explain { display: flex; flex-direction: column; }
.explain[hidden] { display: none; }
.explain-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 12px 15px; border: 1.5px solid #E0D8FB; border-radius: var(--r-md);
  background: linear-gradient(180deg, #F6F3FF, #EFEAFD);
  color: var(--primary-d); font-family: var(--ui); font-size: 14px; font-weight: 800;
  box-shadow: var(--sh-1), var(--hi);
  transition: transform .12s var(--press), border-color .2s, background .2s;
}
.explain-btn .spark { width: 17px; height: 17px; color: var(--primary); }
.explain-btn .explain-label { flex: 1 1 auto; text-align: left; }
.explain-btn .chev { width: 18px; height: 18px; color: var(--primary); transition: transform .3s var(--out); }
.explain-btn:hover { transform: translateY(-1px); border-color: var(--primary); }
.explain-btn:active { transform: translateY(1px); }
.explain-btn.open { background: linear-gradient(180deg, #EFEAFD, #E9E2FB); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.explain-btn.open .chev { transform: rotate(180deg); }

.explain-box {
  display: grid; grid-template-rows: 0fr; opacity: 0;
  transition: grid-template-rows .4s var(--out), opacity .3s;
}
.explain-box.open { grid-template-rows: 1fr; opacity: 1; }
.explain-inner { overflow: hidden; }
.explain-inner > :first-child { margin-top: 9px; }
.ex-sec {
  font-size: 13.5px; color: var(--ink-dim); line-height: 1.55; padding: 10px 14px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); margin-bottom: 7px;
}
.ex-sec:last-child { margin-bottom: 0; }
.ex-k { display: block; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
  color: var(--primary-d); margin-bottom: 3px; }
.ex-sec b { color: var(--ink); font-weight: 700; }
.ex-sec code { font-family: var(--mono); font-size: 13px; color: var(--accent-d);
  background: #FFEDE6; padding: 1px 6px; border-radius: 6px; }
.ex-params { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0 0 7px; padding: 0; }
.ex-params li { font-size: 12.5px; color: var(--ink-dim); background: #F1EDFD;
  border: 1px solid var(--line); padding: 5px 10px; border-radius: var(--r-pill); }
.ex-params b { font-family: var(--mono); color: var(--primary); }

/* ---- "your fit" formula readout ---- */
.formula {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  font-family: var(--mono); font-size: 18px; font-weight: 500; font-variant-numeric: tabular-nums;
  color: var(--ink); background: var(--surface-2);
  border: 1.5px solid var(--line); border-radius: var(--r-md);
  padding: 15px 16px 13px; word-break: break-word;
  box-shadow: inset 0 2px 5px rgba(33,18,82,.04);
}
.formula::before {
  content: "your fit"; position: absolute; top: -8px; left: 13px;
  font-family: var(--ui); font-size: 10px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-faint); background: #fff; padding: 0 6px;
}
.formula .lhs { color: var(--primary); font-weight: 600; }

/* ---- sliders ---- */
.controls { display: flex; flex-direction: column; gap: 14px; }
.slider-field { display: flex; flex-direction: column; gap: 8px; }
.slider-field .slider-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.slider-field .s-label { font-size: 14px; font-weight: 700; color: var(--ink); }
.slider-field .s-value {
  font-family: var(--mono); font-size: 15px; font-weight: 700; color: var(--primary);
  font-variant-numeric: tabular-nums; min-width: 46px; text-align: center;
  padding: 2px 9px; border-radius: var(--r-pill); background: #F1EDFD;
}
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 14px; border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--primary) var(--fill,50%), var(--surface-3) var(--fill,50%));
  box-shadow: inset 0 2px 4px rgba(33,18,82,.10); outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 28px; height: 28px; border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #fff, #EFEBFE 60%);
  border: none; box-shadow: 0 3px 8px rgba(60,40,120,.32), inset 0 0 0 5px var(--primary);
  transition: transform .12s var(--press);
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.12); }
input[type="range"]::-moz-range-thumb {
  width: 28px; height: 28px; border: none; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgba(60,40,120,.32), inset 0 0 0 5px var(--primary);
}
input[type="range"]:disabled { opacity: .5; cursor: not-allowed; }

/* ---- expression input + palette (dark editor) ---- */
.expr-field { display: flex; flex-direction: column; gap: 10px; }
.expr-input {
  width: 100%; min-height: 52px;
  font-family: var(--mono); font-size: 18px; font-weight: 500; color: var(--cyan-core);
  background: #0F0E1F; border: 1.5px solid var(--line); border-radius: var(--r-md);
  padding: 13px 16px; outline: none; caret-color: var(--cyan);
  box-shadow: inset 0 2px 6px rgba(0,0,0,.35);
  transition: border-color .18s, box-shadow .18s;
}
.expr-input::placeholder { color: #6B6890; }
.expr-input:focus { border-color: var(--cyan); box-shadow: inset 0 2px 6px rgba(0,0,0,.35), 0 0 0 4px rgba(55,225,255,.18); }
.expr-input.shake { animation: shakeX .36s; border-color: var(--danger); box-shadow: inset 0 2px 6px rgba(0,0,0,.35), 0 0 0 4px rgba(255,92,122,.2); }
@keyframes shakeX {
  0%,100% { transform: translateX(0); } 20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(4px); }
}
.palette { display: grid; grid-template-columns: repeat(6, 1fr); gap: 7px; }
.palette button {
  height: 44px; border-radius: var(--r-sm); border: 1.5px solid var(--line);
  background: linear-gradient(180deg, #fff, #F6F3FD); color: var(--ink);
  font-family: var(--mono); font-size: 15px; font-weight: 700;
  box-shadow: var(--sh-1), var(--hi);
  transition: transform .12s var(--press), border-color .2s, color .2s;
}
.palette button:hover { transform: translateY(-1px); border-color: var(--primary); color: var(--primary); }
.palette button:active { transform: translateY(2px); box-shadow: var(--sh-1); }

/* ---- hint + error ---- */
.hint-btn {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 16px; border-radius: var(--r-pill);
  font-family: var(--ui); font-size: 14px; font-weight: 700; color: #8A6300;
  background: #FFF8E6; border: 1.5px dashed #E6C766;
  transition: transform .12s var(--press), background .2s, border-color .2s, color .2s;
}
.hint-btn .ico { width: 16px; height: 16px; }
.hint-btn:hover { transform: translateY(-1px); background: #FFF2CE; }
.hint-btn:disabled { opacity: .5; cursor: default; transform: none; }
.hint-btn.answer { color: var(--success-d); background: #E6FBF3; border-color: #7FE0BE; }
.hint:empty { display: none; }
.hint {
  font-size: 13.5px; color: #7A5800; line-height: 1.45;
  background: #FFF8E6; border: 1px solid #F1DFA6; border-radius: var(--r-md);
  padding: 11px 14px;
}
.error {
  font-size: 13.5px; color: var(--danger-d); font-weight: 700;
  background: #FFE1E8; border: 1px solid #FBC4D1; border-radius: var(--r-md);
  padding: 10px 13px; animation: rise .25s var(--out);
}

/* ---- "Hear the law" toggle (shown on wave levels) ---- */
.hear-btn {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 8px;
  height: 42px; padding: 0 16px; border-radius: var(--r-pill);
  font-family: var(--ui); font-size: 13.5px; font-weight: 800; color: #0E7FB0;
  background: #ECF7FF; border: 1.5px solid #BFE3FB; box-shadow: var(--sh-1);
  transition: transform .12s var(--press), background .2s, border-color .2s, color .2s, box-shadow .2s;
}
.hear-btn[hidden] { display: none; }
.hear-btn .ico { width: 17px; height: 17px; }
.hear-btn:hover { transform: translateY(-1px); }
.hear-btn.on {
  color: #fff; border-color: transparent;
  background: linear-gradient(180deg, #4FC3F7, #2BA8E0);
  box-shadow: 0 6px 18px rgba(43,168,224,.42), var(--hi-soft);
}
.hear-btn.on .ico { animation: hear-pulse 1.1s ease-in-out infinite; }
@keyframes hear-pulse { 0%,100% { transform: scale(1); opacity: .9; } 50% { transform: scale(1.18); opacity: 1; } }

/* ---- status: pips + medals ---- */
.statusrow { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 2px; }
.statusrow .lbl, .pips .lbl, .medals .lbl {
  font-size: 11px; font-weight: 800; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-faint);
}
.pips, .medals { display: flex; align-items: center; gap: 8px; }
.pip-row, .medal-row { display: flex; align-items: center; gap: 7px; }
.pip {
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--surface-3); box-shadow: inset 0 0 0 2px var(--line);
  transition: all .3s var(--pop);
}
.pip.live  { background: var(--primary); box-shadow: var(--glow-primary); }
.pip.spent { background: #fff; box-shadow: inset 0 0 0 2px var(--danger); position: relative; animation: burn .4s var(--pop); }
.pip.spent::after { content: ""; position: absolute; inset: 4px; border-radius: 50%; background: var(--danger); }
@keyframes burn { 0% { transform: scale(1.4); } 60% { transform: scale(.85); } 100% { transform: scale(1); } }

.medal {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--mono); font-size: 12px; font-weight: 800;
  background: var(--surface-2); box-shadow: inset 0 0 0 2px var(--line);
  filter: grayscale(1) opacity(.5);
  transition: filter .35s var(--pop), transform .35s var(--pop); position: relative; overflow: hidden;
}
.medal.gold   { background: radial-gradient(circle at 38% 32%, #FFF1B8, var(--gold)); color: #7A5800; }
.medal.silver { background: radial-gradient(circle at 38% 32%, #fff, var(--silver)); color: #5C6677; }
.medal.bronze { background: radial-gradient(circle at 38% 32%, #F6C99A, var(--bronze)); color: #6A3F18; }
.medal.earned { filter: none; transform: scale(1.06); box-shadow: 0 3px 8px rgba(255,179,32,.4), var(--hi); }
.medal.earned::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 40%, rgba(255,255,255,.8) 50%, transparent 60%);
  transform: translateX(-120%); animation: sweep 1s var(--out) .2s 1;
}

/* ---- the high-stakes PLOT button ---- */
.fire-btn {
  position: relative; border: none; width: 100%;
  padding: 14px 18px; border-radius: var(--r-lg);
  background: linear-gradient(180deg, var(--primary-2), var(--primary));
  color: #fff;
  box-shadow: var(--glow-primary), var(--hi-soft), 0 6px 0 0 var(--primary-d);
  transition: transform .12s var(--press), box-shadow .12s var(--press), filter .2s;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.fire-btn .fire-label { font-family: var(--display); font-size: 20px; font-weight: 700; line-height: 1.1; letter-spacing: .08em; }
.fire-btn .fire-sub { font-family: var(--mono); font-size: 10px; font-weight: 500; line-height: 1.2; opacity: .85; letter-spacing: .04em; }
.fire-btn:hover { filter: brightness(1.04); transform: translateY(-1px); }
.fire-btn:active { transform: translateY(4px); box-shadow: var(--glow-primary), var(--hi-soft), 0 2px 0 0 var(--primary-d); }
.fire-btn:disabled {
  cursor: not-allowed; filter: grayscale(.45) brightness(.96);
  background: linear-gradient(180deg, #CFC8EE, #BBB2E4);
  box-shadow: var(--sh-1), 0 4px 0 0 #A79DD6; opacity: .85; transform: none;
}

.reset-btn, .share-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--ui); font-size: 13.5px; font-weight: 700;
  height: 44px; border-radius: var(--r-pill); transition: all .16s var(--press);
}
.reset-btn .ico, .share-btn .ico { width: 16px; height: 16px; }
.reset-btn { border: none; background: none; color: var(--ink-faint); text-decoration: underline; text-underline-offset: 3px; }
.reset-btn:hover { color: var(--ink-dim); }
.share-btn {
  color: var(--primary); background: var(--surface);
  box-shadow: var(--sh-1), inset 0 0 0 1.5px var(--line); font-weight: 800;
}
.share-btn:hover { transform: translateY(-1px); }
.share-btn:active { transform: translateY(2px); }

/* ---- versus ---- */
.vs {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 12.5px; color: var(--ink-dim); font-weight: 600;
  border-top: 1px solid var(--line); padding-top: 14px; margin-top: auto;
}
.vs-you { color: var(--success-d); font-weight: 800; }
.vs-cpu { color: var(--accent-d); font-weight: 800; }

/* =============================================================================
   MODAL + TOAST
   ============================================================================= */
.modal {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: rgba(33,28,61,.62);
  animation: fade .22s ease;
}
.modal[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: min(560px, 100%);
  background: linear-gradient(180deg, #FFFFFF, #FAF8FE);
  border: 1px solid var(--line); border-radius: var(--r-xl);
  box-shadow: var(--sh-3), var(--hi); padding: 26px;
  display: flex; flex-direction: column; gap: 13px;
  animation: modal-pop .38s var(--pop) both;
}
@keyframes modal-pop { from { opacity: 0; transform: translateY(16px) scale(.96); } to { opacity: 1; transform: none; } }
.modal-card h3 { font-family: var(--display); font-size: 22px; font-weight: 600; display: flex; align-items: center; gap: 9px; color: var(--ink); }
.modal-card h3 .ico { width: 20px; height: 20px; color: var(--primary); }
.modal-card p { font-size: 14px; color: var(--ink-dim); line-height: 1.55; }
.modal-card textarea {
  min-height: 120px; resize: vertical; font-family: var(--ui); font-size: 14px; color: var(--ink);
  background: var(--surface-2); border: 1.5px solid var(--line); border-radius: var(--r-md);
  padding: 13px 14px; outline: none; line-height: 1.55;
  box-shadow: inset 0 2px 5px rgba(33,18,82,.04);
}
.modal-card textarea:focus { border-color: var(--primary); box-shadow: inset 0 2px 5px rgba(33,18,82,.04), 0 0 0 4px rgba(108,92,231,.16); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* ---- homework modal: clearer 3-step framing + examples ---- */
.modal-lead { font-size: 14px; color: var(--ink-dim); line-height: 1.55; }
.modal-lead b { color: var(--ink); }
.hw-steps {
  display: flex; gap: 8px; list-style: none; margin: 0; padding: 0; flex-wrap: wrap;
}
.hw-steps li {
  display: flex; align-items: center; gap: 7px; flex: 1 1 0; min-width: 140px;
  font-size: 12.5px; font-weight: 700; color: var(--ink-dim);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 9px 11px;
}
.hw-num {
  display: grid; place-items: center; width: 20px; height: 20px; flex: none;
  font-family: var(--mono); font-size: 12px; font-weight: 800; color: #fff;
  background: linear-gradient(180deg, var(--primary), var(--primary-d)); border-radius: 50%;
}
.hw-examples { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.hw-ex-label { font-size: 12.5px; color: var(--ink-dim); font-weight: 600; }
.hw-examples button {
  font-family: var(--ui); font-size: 12.5px; font-weight: 700; color: var(--primary);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-pill);
  padding: 5px 12px; transition: transform .12s var(--press), background .15s;
}
.hw-examples button:hover { transform: translateY(-1px); background: var(--surface-2); }
.hw-examples button:active { transform: translateY(1px); }
.primary-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 46px; padding: 0 22px;
  font-family: var(--ui); font-weight: 800; color: #fff; border: none; border-radius: var(--r-pill);
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  box-shadow: var(--glow-coral), var(--hi-soft), 0 6px 0 0 var(--accent-d);
  transition: transform .12s var(--press), box-shadow .12s var(--press), filter .2s;
}
.primary-btn:hover { filter: brightness(1.04); transform: translateY(-1px); }
.primary-btn:active { transform: translateY(4px); box-shadow: var(--glow-coral), var(--hi-soft), 0 2px 0 0 var(--accent-d); }
.ghost-btn {
  height: 46px; padding: 0 20px;
  font-family: var(--ui); font-weight: 700; color: var(--primary); background: var(--surface);
  border: none; border-radius: var(--r-pill); box-shadow: var(--sh-1), inset 0 0 0 1.5px var(--line);
  transition: transform .12s var(--press);
}
.ghost-btn:hover { transform: translateY(-1px); }
.ghost-btn:active { transform: translateY(2px); }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(24px);
  z-index: 95; padding: 13px 20px; border-radius: var(--r-pill);
  background: #fff; border: 1px solid var(--line);
  color: var(--ink); font-size: 13.5px; font-weight: 700; box-shadow: var(--sh-3);
  opacity: 0; transition: opacity .26s, transform .3s var(--pop);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* =============================================================================
   RESPONSIVE
   ============================================================================= */
@media (max-width: 960px) {
  html, body { overflow-y: auto; overflow-x: hidden; }
  #app { height: auto; min-height: 100dvh; }
  .genbar { order: 3; flex-basis: 100%; }
  .stage { grid-template-columns: 1fr; }
  .arena-wrap { min-height: 56vh; }
  .panel { overflow: visible; }
}
@media (max-width: 560px) {
  .topbar { padding: 12px 14px; }
  .panel { padding: 18px; }
  .panel-head h1, .level-title { font-size: 25px; }
  #landing { padding: 24px; }
  .landing-headline { font-size: clamp(30px, 9vw, 52px); letter-spacing: -.01em; }
  .landing-inner { gap: 16px; }
  .palette { grid-template-columns: repeat(4, 1fr); }
}

/* =============================================================================
   REDUCED MOTION
   ============================================================================= */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .plot-curve { stroke-dashoffset: 0; }
  .lab-plot { opacity: .28; }
  .landing-inner > * { opacity: 1; }
}
