/* Layout: each chapter is a live circuit running down the page in book order; the current reaches
   the first lab you have not finished. The hero is a toy from that chapter's bench. One dark world
   per chapter, by choice, so the page sets every colour itself and has no light theme. */
:root {
  color-scheme: dark;
  --display: 'Lalezar', 'Baloo Bhaijaan 2', Tahoma, sans-serif;
  --body: 'Baloo Bhaijaan 2', Tahoma, sans-serif;
  /* Chapter 1, «ليلة النحاس»: copper objects under a violet night, charge glows yellow. */
  --sky-top: #3c2470;
  --sky-bot: #170e35;
  --surface: #29195a;
  --surface-2: #36226f;
  --wire: #7b67b8;
  --glow: #ffd24a;
  --hot: #ff8a3d;
  --cool: #8fd3ff;
  --ink: #fff5e1;
  --muted: #cbbbe9;
  --btn-ink: #2b1606;
  --r-pad: 42px;
  background: var(--sky-bot);
}
.app[data-chapter="2"] {
  /* Chapter 2, «حقل الفيروز»: deep teal field, aqua flux, red north pole. */
  --sky-top: #0f4b4f; --sky-bot: #062229; --surface: #0b383c; --surface-2: #11484b;
  --wire: #3f8e89; --glow: #62f5d6; --hot: #ff5d5d; --cool: #f4f7f6;
  --ink: #effffa; --muted: #a6d5cb; --btn-ink: #03211c;
}
.app[data-chapter="3"] {
  /* Chapter 3, «استوديو الليل»: navy scope room, cyan trace, pink second wave. */
  --sky-top: #1c2d6c; --sky-bot: #0a1235; --surface: #152257; --surface-2: #1d2e6f;
  --wire: #4b5ea9; --glow: #67e3ff; --hot: #ff6fb1; --cool: #ffd24a;
  --ink: #f2f5ff; --muted: #b6c0e8; --btn-ink: #061a35;
}
/* Part 2, the same colours as the labs (engine/chapter-theme.js, studio-premium.css). */
.app[data-chapter="4"] {
  /* Chapter 4, radio night: plum sky, pink waves. */
  --sky-top: #4a1d4f; --sky-bot: #1a0a22; --surface: #3a1640; --surface-2: #4b1f52;
  --wire: #9a5aa3; --glow: #ff9de2; --hot: #ffb347; --cool: #8fd3ff;
  --ink: #fff1fb; --muted: #e2b9d6; --btn-ink: #2b0a24;
}
.app[data-chapter="5"] {
  /* Chapter 5, darkroom: wine sky, laser-red fringes. */
  --sky-top: #3d1520; --sky-bot: #14070c; --surface: #2f1018; --surface-2: #3e1621;
  --wire: #9c4a58; --glow: #ff6b6b; --hot: #ffd166; --cool: #9be7ff;
  --ink: #fff1f1; --muted: #e6b3b8; --btn-ink: #2a0508;
}
.app[data-chapter="6"] {
  /* Chapter 6, photons: indigo sky, violet light. */
  --sky-top: #26185a; --sky-bot: #0c0722; --surface: #1d1347; --surface-2: #281b5c;
  --wire: #6f5bc0; --glow: #b99aff; --hot: #7cf5ff; --cool: #ffd24a;
  --ink: #f4f0ff; --muted: #c5b8ec; --btn-ink: #150a3a;
}
.app[data-chapter="7"] {
  /* Chapter 7, circuit board: deep green, signal green. */
  --sky-top: #0f3d2a; --sky-bot: #051a12; --surface: #0c2f21; --surface-2: #123d2b;
  --wire: #3f8a63; --glow: #7dff9b; --hot: #ffd23f; --cool: #9be7ff;
  --ink: #effff3; --muted: #a8d8b5; --btn-ink: #03200e;
}
.app[data-chapter="8"] {
  /* Chapter 8, spectra: slate sky, gold orbits. */
  --sky-top: #2d2a4a; --sky-bot: #0e0d1d; --surface: #23213d; --surface-2: #2e2b4f;
  --wire: #6c6798; --glow: #ffe27a; --hot: #ff7ad9; --cool: #8fd3ff;
  --ink: #fffbea; --muted: #cfc9a6; --btn-ink: #2a2104;
}
.app[data-chapter="9"] {
  /* Chapter 9, nuclei: olive sky, acid-yellow glow. */
  --sky-top: #2f3612; --sky-bot: #101405; --surface: #252b0e; --surface-2: #313914;
  --wire: #7d8a3c; --glow: #d4ff3d; --hot: #ff8a3d; --cool: #9be7ff;
  --ink: #fbffe8; --muted: #c9d49c; --btn-ink: #1c2402;
}

@font-face { font-family: 'Baloo Bhaijaan 2'; font-weight: 500; font-display: swap; src: url(assets/fonts/zYXwKUwuEqdVGqM8tPDdAA_Y-_bMKo1EhQd2tWxo8TyjSqP4.ttf) format('truetype'); }
@font-face { font-family: 'Baloo Bhaijaan 2'; font-weight: 600; font-display: swap; src: url(assets/fonts/zYXwKUwuEqdVGqM8tPDdAA_Y-_bMKo1EhQd2tWxo8TxPTaP4.ttf) format('truetype'); }
@font-face { font-family: 'Baloo Bhaijaan 2'; font-weight: 700; font-display: swap; src: url(assets/fonts/zYXwKUwuEqdVGqM8tPDdAA_Y-_bMKo1EhQd2tWxo8Tx2TaP4.ttf) format('truetype'); }
@font-face { font-family: 'Baloo Bhaijaan 2'; font-weight: 800; font-display: swap; src: url(assets/fonts/zYXwKUwuEqdVGqM8tPDdAA_Y-_bMKo1EhQd2tWxo8TwRTaP4.ttf) format('truetype'); }
@font-face { font-family: 'Lalezar'; font-weight: 400; font-display: swap; src: url(assets/fonts/zrfl0HLVx-HwTP82UaA.ttf) format('truetype'); }

* { box-sizing: border-box; }
:root { scrollbar-gutter: stable; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--sky-bot); color: var(--ink); }
/* Baloo draws a Latin f like the Persian digit four: the frequency f gets a serif italic face (as in the engine) */
.ups { font-family: Georgia, 'Times New Roman', serif; font-style: italic; font-weight: 700; padding-inline: .5px .08em; line-height: 1; }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
img { max-width: 100%; }
:focus-visible { outline: 3px solid var(--glow); outline-offset: 4px; border-radius: 12px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.app {
  position: relative;
  min-height: 100vh;
  font: 500 17px/1.6 var(--body);
  color: var(--ink);
  background: var(--sky-bot);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 0 140px;
  transition: background-color .7s ease;
}

/* ── Sky: one fixed layer per chapter, cross-faded with opacity only ───────────── */
.sky { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.sky i { position: absolute; inset: 0; opacity: 0; transition: opacity .8s ease; }
.app[data-chapter="1"] .sky-1, .app[data-chapter="2"] .sky-2, .app[data-chapter="3"] .sky-3,
.app[data-chapter="4"] .sky-4, .app[data-chapter="5"] .sky-5, .app[data-chapter="6"] .sky-6,
.app[data-chapter="7"] .sky-7, .app[data-chapter="8"] .sky-8, .app[data-chapter="9"] .sky-9 { opacity: 1; }
.sky-1 {
  background:
    radial-gradient(70% 42% at 50% 14%, rgba(255, 158, 84, .26), transparent 72%),
    radial-gradient(circle, rgba(255, 236, 200, .085) 1.1px, transparent 1.7px) 0 0 / 22px 22px,
    linear-gradient(180deg, #3c2470 0%, #251651 48%, #170e35 100%);
}
.sky-2 {
  background:
    radial-gradient(70% 42% at 50% 14%, rgba(98, 245, 214, .17), transparent 72%),
    repeating-radial-gradient(ellipse 120% 55% at 50% -6%, transparent 0 38px, rgba(98, 245, 214, .07) 39px 40px),
    linear-gradient(180deg, #0f4b4f 0%, #0a3238 50%, #062229 100%);
}
.sky-3 {
  background:
    radial-gradient(70% 42% at 50% 14%, rgba(103, 227, 255, .2), transparent 72%),
    linear-gradient(rgba(103, 227, 255, .065) 1px, transparent 1px) 0 0 / 36px 36px,
    linear-gradient(90deg, rgba(103, 227, 255, .065) 1px, transparent 1px) 0 0 / 36px 36px,
    linear-gradient(180deg, #1c2d6c 0%, #121f52 50%, #0a1235 100%);
}
/* part 2: radio arcs (4), interference fringes (5), photons (6), board grid (7), orbits (8), nuclei (9) */
.sky-4 {
  background:
    radial-gradient(70% 42% at 50% 14%, rgba(255, 157, 226, .18), transparent 72%),
    repeating-radial-gradient(circle at 50% -4%, transparent 0 32px, rgba(255, 157, 226, .075) 33px 34px),
    linear-gradient(180deg, #4a1d4f 0%, #2e1236 48%, #1a0a22 100%);
}
.sky-5 {
  background:
    radial-gradient(70% 42% at 50% 14%, rgba(255, 107, 107, .18), transparent 72%),
    repeating-linear-gradient(90deg, transparent 0 26px, rgba(255, 107, 107, .06) 30px 34px, transparent 38px 60px),
    linear-gradient(180deg, #3d1520 0%, #270d16 48%, #14070c 100%);
}
.sky-6 {
  background:
    radial-gradient(70% 42% at 50% 14%, rgba(185, 154, 255, .2), transparent 72%),
    radial-gradient(circle, rgba(220, 205, 255, .09) 1.1px, transparent 1.7px) 0 0 / 22px 22px,
    linear-gradient(180deg, #26185a 0%, #180f3d 48%, #0c0722 100%);
}
.sky-7 {
  background:
    radial-gradient(70% 42% at 50% 14%, rgba(125, 255, 155, .15), transparent 72%),
    linear-gradient(rgba(125, 255, 155, .06) 1px, transparent 1px) 0 0 / 36px 36px,
    linear-gradient(90deg, rgba(125, 255, 155, .06) 1px, transparent 1px) 0 0 / 36px 36px,
    linear-gradient(180deg, #0f3d2a 0%, #0a2a1d 50%, #051a12 100%);
}
.sky-8 {
  background:
    radial-gradient(70% 42% at 50% 14%, rgba(255, 226, 122, .17), transparent 72%),
    repeating-radial-gradient(ellipse 120% 55% at 50% -6%, transparent 0 38px, rgba(255, 226, 122, .065) 39px 40px),
    linear-gradient(180deg, #2d2a4a 0%, #1c1a33 50%, #0e0d1d 100%);
}
.sky-9 {
  background:
    radial-gradient(70% 42% at 50% 14%, rgba(212, 255, 61, .14), transparent 72%),
    radial-gradient(circle, rgba(232, 255, 170, .08) 1.2px, transparent 1.8px) 0 0 / 26px 26px,
    linear-gradient(180deg, #2f3612 0%, #1f240b 50%, #101405 100%);
}

.top, .shell, .foot { position: relative; z-index: 1; }

/* ── Top bar ─────────────────────────────────────────────────────────────────── */
.top {
  max-width: 1120px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-block: 14px 4px;
}
.brand { font: 400 33px/1 var(--display); color: var(--ink); text-decoration: none; padding-block: 4px; }
.meter {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 84%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--glow) 22%, transparent);
  font: 700 14px/1 var(--body); color: var(--ink); white-space: nowrap;
}
.bolt { width: 18px; height: 18px; fill: var(--glow); }
.meter-bar { width: 42px; height: 8px; border-radius: 4px; overflow: hidden; background: color-mix(in srgb, var(--glow) 20%, transparent); }
.meter-bar i { display: block; height: 100%; background: var(--glow); border-radius: 4px; transform-origin: right center; transform: scaleX(var(--p, 0)); transition: transform .7s cubic-bezier(.2, .8, .2, 1); }

/* ── Chapter switch ──────────────────────────────────────────────────────────── */
/* the book comes in two parts (chapters 1-3 and 4-9); the switch shows one part's worlds */
.parts { display: flex; gap: 6px; margin-top: 12px; padding: 4px; border-radius: 99px; background: color-mix(in srgb, var(--surface) 60%, transparent); }
.parts button { flex: 1; min-height: 44px; border: 0; border-radius: 99px; background: transparent; color: var(--muted); font: 700 15px/1 var(--body); transition: background-color .3s, color .3s; }
.parts [aria-pressed="true"] { background: var(--glow); color: var(--btn-ink); }
.parts button:focus-visible, .worlds button:focus-visible { outline: 3px solid var(--glow); outline-offset: 2px; }
.worlds { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.worlds button {
  display: flex; align-items: center; justify-content: center; gap: 5px;
  min-height: 54px; padding: 6px 4px; border: 0; border-radius: 18px;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  color: var(--muted); font: 400 16px/1.1 var(--display); white-space: nowrap;
  transition: background-color .3s, color .3s, transform .15s;
}
.worlds button:active { transform: scale(.96); }
.worlds img { width: 26px; height: 28px; object-fit: contain; flex: none; }
.worlds [aria-pressed="true"] { background: var(--surface-2); color: var(--ink); box-shadow: inset 0 0 0 2px var(--glow), 0 8px 18px rgba(0, 0, 0, .25); }

/* ── Hero: the chapter's word, and a toy you can poke ───────────────────────── */
.hero { position: relative; display: grid; justify-items: center; text-align: center; padding-top: 10px; touch-action: pan-y; }
.giant {
  position: relative; z-index: 0; margin: 0 0 -.66em;
  font: 400 clamp(84px, 27vw, 148px)/1.05 var(--display);
  white-space: nowrap; color: transparent;
  background: linear-gradient(180deg, color-mix(in srgb, var(--glow) 44%, transparent) 8%, color-mix(in srgb, var(--glow) 3%, transparent) 78%);
  -webkit-background-clip: text; background-clip: text;
}
.toy {
  position: relative; z-index: 1;
  width: min(60vw, 248px); aspect-ratio: 1; max-width: 100%;
  padding: 0; border: 0; background: none; border-radius: 50%;
}
.toy-spot {
  position: absolute; inset: -6% -14% -2%; z-index: -1; border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--glow) 24%, transparent), transparent 75%);
}
.toy-spot::after {
  content: ""; position: absolute; left: 24%; right: 24%; bottom: 7%; height: 11%; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, .42), transparent);
}
.toy-bounce, .toy-body { position: absolute; inset: 0; display: block; }
.toy-body img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 16px 14px rgba(0, 0, 0, .32)); -webkit-user-drag: none; user-select: none; }
.field { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.field path:not(.chev) { fill: none; stroke-width: .9; stroke-linecap: round; stroke-dasharray: 2.4 3.2; opacity: .75; }
.field .chev { stroke: none; opacity: .9; }
.field.flow path:not(.chev) { animation: march 1.1s linear infinite; }
@keyframes march { to { stroke-dashoffset: -11.2; } }

.fx { position: absolute; inset: 0; pointer-events: none; }
.q {
  position: absolute; width: 24px; height: 24px; margin: -12px 0 0 -12px; border-radius: 50%;
  animation: pop .32s cubic-bezier(.3, 1.6, .5, 1) both;
}
.q::before, .q::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 12px; height: 3px; margin: -1.5px 0 0 -6px;
  border-radius: 2px; background: currentColor;
}
.q.plus::after { transform: rotate(90deg); }
.q.minus::after { display: none; }
.q.plus { background: var(--hot); color: #2b0d00; box-shadow: 0 0 14px color-mix(in srgb, var(--hot) 70%, transparent); }
.q.minus { background: var(--cool); color: #04263a; box-shadow: 0 0 14px color-mix(in srgb, var(--cool) 70%, transparent); }
@keyframes pop { from { transform: scale(0); } }
.flash {
  position: absolute; width: 70%; aspect-ratio: 1; margin: -35% 0 0 -35%; border-radius: 50%;
  background: radial-gradient(closest-side, #fff, color-mix(in srgb, var(--glow) 80%, transparent) 30%, transparent 72%);
  opacity: 0;
}
.pole {
  position: absolute; left: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%;
  display: grid; place-items: center; font: 800 17px/1 var(--body);
  box-shadow: 0 4px 10px rgba(0, 0, 0, .3); transition: opacity .2s;
}
.pole.n { background: var(--hot); color: #fff; }
.pole.s { background: #f4f7f6; color: #0b3236; }
.scope {
  position: absolute; left: 15.5%; top: 28.5%; width: 64%; height: 35%;
  border-radius: 10% / 16%; overflow: hidden;
}
.scope svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.scope .grid { stroke: rgba(103, 227, 255, .16); stroke-width: 1; vector-effect: non-scaling-stroke; }
.scope .trace { fill: none; stroke: var(--glow); stroke-width: 2.6; vector-effect: non-scaling-stroke; stroke-linecap: round; }
.scope .trace.i { stroke: var(--hot); stroke-width: 2; opacity: .85; }

.hint {
  min-height: 1.6em; margin: 4px 0 0; padding: 0 12px;
  font: 700 15px/1.6 var(--body); color: var(--glow); text-wrap: balance;
}
.pips { display: flex; gap: 7px; margin-top: 6px; height: 10px; }
.pips i { width: 10px; height: 10px; border-radius: 50%; background: color-mix(in srgb, var(--hot) 22%, transparent); transition: background-color .2s, transform .2s; }
.pips i.on { background: var(--hot); transform: scale(1.15); }
.app:not([data-chapter="1"]) .pips { visibility: hidden; height: 0; margin: 0; }
.book { margin: 14px 0 0; font: 700 14px/1.4 var(--body); color: var(--muted); }
.lede { margin: 2px 0 0; max-width: 30ch; font: 500 18px/1.6 var(--body); color: var(--ink); text-wrap: balance; }

/* ── The circuit map ─────────────────────────────────────────────────────────── */
.map { position: relative; margin-top: 26px; }
.board { position: relative; width: 100%; max-width: 560px; margin: 0 auto; }
.wire { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.w-base { fill: none; stroke: var(--wire); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; opacity: .75; }
.w-glow { fill: none; stroke: var(--glow); stroke-width: 15; stroke-linecap: round; stroke-linejoin: round; opacity: .17; }
.w-core { fill: none; stroke: var(--glow); stroke-width: 3.6; stroke-linecap: round; stroke-linejoin: round; }
.w-vias circle { fill: var(--sky-bot); stroke: var(--wire); stroke-width: 2.5; }
.w-head { opacity: 0; }
.nodes { list-style: none; margin: 0; padding: 0; }

.node {
  position: absolute; display: flex; align-items: center; gap: 12px;
  height: calc(var(--r-pad) * 2); padding: 0; border: 0; background: none; text-align: start;
}
.node.left { flex-direction: row-reverse; text-align: end; }
.pad {
  position: relative; isolation: isolate; flex: none; width: calc(var(--r-pad) * 2); height: calc(var(--r-pad) * 2); border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, var(--surface-2), var(--surface) 72%);
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--wire) 80%, transparent), 0 10px 20px rgba(0, 0, 0, .28);
  transition: box-shadow .45s ease, transform .2s;
}
.pad::before {
  content: ""; position: absolute; inset: -20px; z-index: -1; border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--glow) 34%, transparent), transparent);
  opacity: 0; transition: opacity .5s ease;
}
.pad img {
  position: absolute; left: 7%; top: -12%; width: 86%; height: 100%; object-fit: contain;
  filter: drop-shadow(0 6px 5px rgba(0, 0, 0, .35)); -webkit-user-drag: none; user-select: none;
}
.node:active .pad { transform: scale(.94); }
.node.is-on .pad { box-shadow: inset 0 0 0 3px var(--glow), 0 0 0 5px color-mix(in srgb, var(--glow) 15%, transparent), 0 10px 22px rgba(0, 0, 0, .3); }
.node.is-on .pad::before { opacity: 1; }
.node.is-off .pad img { opacity: .78; filter: saturate(.55) drop-shadow(0 6px 5px rgba(0, 0, 0, .35)); }
.node.is-next .pad::after {
  content: ""; position: absolute; inset: -7px; border-radius: 50%;
  border: 3px solid var(--glow); animation: ring 1.9s ease-out infinite;
}
@keyframes ring { from { transform: scale(.96); opacity: .95; } to { transform: scale(1.38); opacity: 0; } }

.badge {
  position: absolute; top: -5px; right: -5px; min-width: 30px; height: 30px; padding: 0 7px; border-radius: 15px;
  display: grid; place-items: center; background: var(--hot); color: #fff;
  font: 400 18px/1 var(--display); box-shadow: 0 0 0 3px var(--sky-bot);
}
.node.left .badge { right: auto; left: -5px; }
.badge svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.badge.lab { background: var(--surface-2); color: var(--glow); box-shadow: 0 0 0 3px var(--sky-bot), inset 0 0 0 2px var(--glow); }
.badge.src { background: var(--glow); color: var(--btn-ink); }
.badge.q { background: var(--glow); color: var(--btn-ink); font: 400 20px/1 var(--display); }
.badge.src svg { fill: currentColor; stroke: none; }
.tick {
  position: absolute; bottom: -3px; left: -3px; width: 28px; height: 28px; border-radius: 50%;
  display: none; place-items: center; background: var(--glow); box-shadow: 0 0 0 3px var(--sky-bot);
}
.node.left .tick { left: auto; right: -3px; }
.tick svg { width: 16px; height: 16px; fill: none; stroke: var(--btn-ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.node.is-done .tick { display: grid; }

.lbl { display: grid; gap: 1px; min-width: 0; max-width: var(--lw, 200px); }
.lbl b { font: 400 19px/1.28 var(--display); color: var(--ink); text-wrap: balance; }
.lbl span { font: 600 13px/1.35 var(--body); color: var(--muted); }
.lbl .done-note { color: var(--glow); }
.node.is-off:not(.is-done) .lbl b { color: color-mix(in srgb, var(--ink) 80%, transparent); }

.lamp-imgs { position: absolute; inset: 0; }
.lamp-imgs img + img { opacity: 0; transition: opacity .6s ease; }
.node.lit .lamp-imgs img + img { opacity: 1; }
.node.lit .pad::before { inset: -46px; opacity: 1; background: radial-gradient(closest-side, rgba(255, 214, 102, .6), transparent); }

.mascot {
  position: absolute; top: 0; left: 0; z-index: 3; width: 58px; height: 72px; padding: 0; border: 0; background: none;
  transform: translate(var(--mx, -999px), var(--my, 0));
}
.mascot img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 8px 6px rgba(0, 0, 0, .35)); transform: scaleX(var(--flip, 1)); }
.bubble {
  position: absolute; z-index: 4; top: 0; left: 0; width: max-content; max-width: 230px; margin: 0;
  padding: 10px 14px; border-radius: 16px; background: #fffaf0; color: #2a1d3f;
  font: 600 15px/1.5 var(--body); box-shadow: 0 10px 24px rgba(0, 0, 0, .3);
  animation: pop .25s cubic-bezier(.3, 1.4, .5, 1) both;
}

.burst { position: absolute; z-index: 5; width: 0; height: 0; pointer-events: none; }
.burst i { position: absolute; width: 8px; height: 8px; margin: -4px; border-radius: 50%; background: var(--glow); box-shadow: 0 0 10px var(--glow); }
.burst i:nth-child(3n) { background: #fff; }
.burst i:nth-child(4n) { background: var(--hot); box-shadow: 0 0 10px var(--hot); }

/* ── Footer ──────────────────────────────────────────────────────────────────── */
.foot { max-width: 560px; margin: 26px auto 0; display: grid; gap: 6px; font: 500 14px/1.6 var(--body); color: var(--muted); text-align: center; }
.foot p { margin: 0; }
.app[data-mode="live"] .proto-only { display: none; }
.link { padding: 0; border: 0; background: none; color: var(--glow); font: 700 14px var(--body); text-decoration: underline; text-underline-offset: 4px; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 2px 22px 0; border: 0; border-radius: 17px;
  background: var(--glow); color: var(--btn-ink); text-decoration: none; white-space: nowrap;
  font: 400 21px/1 var(--display);
  box-shadow: 0 5px 0 color-mix(in srgb, var(--glow) 48%, #000), 0 12px 22px rgba(0, 0, 0, .3);
  transition: transform .1s ease, box-shadow .1s ease;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 color-mix(in srgb, var(--glow) 48%, #000), 0 5px 10px rgba(0, 0, 0, .3); }
.btn.wide { display: flex; width: 100%; min-height: 58px; font-size: 23px; }

/* ── Dock ────────────────────────────────────────────────────────────────────── */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  padding-right: max(12px, env(safe-area-inset-right, 0px));
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  pointer-events: none; transform: translateY(140%); transition: transform .55s cubic-bezier(.2, .9, .25, 1);
}
.dock::before {
  content: ""; position: absolute; inset: -46px 0 0; z-index: -1;
  background: linear-gradient(to top, var(--sky-bot) 42%, color-mix(in srgb, var(--sky-bot) 0%, transparent));
}
.dock.show { transform: none; }
.dock-in {
  pointer-events: auto; max-width: 540px; margin: 0 auto; padding: 8px 8px 8px 8px;
  display: flex; align-items: center; gap: 10px; border-radius: 24px;
  background: var(--surface-2); box-shadow: 0 14px 30px rgba(0, 0, 0, .42), inset 0 1px 0 rgba(255, 255, 255, .08);
}
.dock-in img { width: 48px; height: 48px; object-fit: contain; flex: none; margin-inline-start: 2px; }
.dock-text { flex: 1; min-width: 0; margin: 0; display: grid; line-height: 1.25; }
.dock-text span { font: 700 12px/1.3 var(--body); color: var(--glow); }
.dock-text strong { font: 400 18px/1.3 var(--display); font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dock .btn { min-height: 50px; padding-inline: 20px; }

/* ── Sheet ───────────────────────────────────────────────────────────────────── */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; display: grid; align-items: end; justify-items: center; }
.scrim { position: absolute; inset: 0; background: rgba(4, 2, 14, .58); opacity: 0; transition: opacity .32s ease; }
.sheet-wrap.open .scrim { opacity: 1; }
.sheet {
  position: relative; width: min(100%, 540px); max-height: 92%; overflow-y: auto; overscroll-behavior: contain;
  border-radius: 30px 30px 0 0;
  background: linear-gradient(180deg, var(--surface-2), var(--surface) 62%);
  box-shadow: 0 -18px 40px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .1);
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
  padding-block: 4px calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateY(105%); transition: transform .4s cubic-bezier(.2, .9, .25, 1);
  text-align: center;
}
.sheet-wrap.open .sheet { transform: none; }
.grab { display: grid; place-items: center; height: 26px; touch-action: none; cursor: grab; }
.grab i { width: 44px; height: 5px; border-radius: 3px; background: color-mix(in srgb, var(--ink) 30%, transparent); }
.s-stage { position: relative; height: 176px; display: grid; place-items: center; touch-action: none; }
.s-glow { position: absolute; width: 220px; height: 220px; border-radius: 50%; background: radial-gradient(closest-side, color-mix(in srgb, var(--glow) 30%, transparent), transparent); }
.s-stage img { position: relative; height: 160px; width: auto; max-width: 80%; object-fit: contain; filter: drop-shadow(0 16px 14px rgba(0, 0, 0, .4)); }
.s-tags { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.tag { padding: 3px 12px 2px; border-radius: 999px; font: 700 14px/1.5 var(--body); background: color-mix(in srgb, var(--glow) 15%, transparent); color: var(--glow); }
.tag.done { background: var(--glow); color: var(--btn-ink); }
.sheet h3 { margin: 10px 0 4px; font: 400 30px/1.25 var(--display); text-wrap: balance; outline: none; }
.sheet p { margin: 0 auto 20px; max-width: 32ch; font: 500 17px/1.65 var(--body); color: var(--muted); text-wrap: balance; }
.s-nav { display: flex; justify-content: space-between; margin-top: 12px; }
.s-nav button {
  display: inline-flex; align-items: center; gap: 4px; min-height: 48px; padding: 0 12px;
  border: 0; border-radius: 14px; background: none; color: var(--muted); font: 700 15px var(--body);
}
.s-nav button:disabled { opacity: .3; cursor: default; }
.s-nav svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* ── Toast ───────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; z-index: 60; left: 50%; top: calc(12px + env(safe-area-inset-top, 0px));
  width: max-content; max-width: min(92vw, 420px); margin: 0; padding: 12px 18px;
  border-radius: 18px; background: #fffaf0; color: #24183a; text-align: center;
  font: 600 15px/1.55 var(--body); box-shadow: 0 14px 30px rgba(0, 0, 0, .35);
  opacity: 0; transform: translate(-50%, -24px); pointer-events: none;
  transition: opacity .25s ease, transform .35s cubic-bezier(.2, .9, .25, 1);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── Wide screens: the toy stays put on the right, the circuit scrolls beside it ─ */
@media (min-width: 960px) {
  :root { --r-pad: 46px; }
  .shell { max-width: 1120px; margin: 0 auto; display: grid; grid-template-columns: 400px minmax(0, 600px); gap: 56px; justify-content: center; align-items: start; }
  .side { position: sticky; top: 16px; }
  .map { margin-top: 18px; }
  .board { max-width: 600px; }
  .giant { font-size: 130px; }
  .toy { width: 270px; }
  .foot { max-width: 1120px; }
}
@media (max-height: 720px) and (max-width: 959px) {
  .toy { width: min(52vw, 196px); }
  .map { margin-top: 14px; }
}
@media (max-width: 370px) {
  :root { --r-pad: 38px; }
  .worlds button { font-size: 14px; gap: 3px; }
  .worlds img { width: 20px; height: 24px; }
  .lbl b { font-size: 17px; }
  .dock-in img { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* the level pill (engine/cheer.js) sits between the brand and the lab meter; on phones only its ring and streak show */
.top .h-pill { margin-inline-start: auto; }
@media (max-width: 440px) { .top .h-pill .xp { display: none; } .top .h-pill { padding-inline-end: 6px; } .top { gap: 8px; } }
