/* ============================================================
   Arithmetic Quest — theme
   Sister to Literature Quest, Eureka Quest & Philosophy Quest:
   the same scholarly dark DNA, tinted toward the deep ocean —
   Tally the octopus's home. Teal glass, gold Calculator Tokens,
   glowing numbers. Each world dives a little deeper (shallow
   aqua → trench indigo). Mobile-first.
   ============================================================ */
:root {
  --bg: #08161f;
  --bg-2: #0c2233;
  --panel: #10293a;
  --panel-2: #163a50;
  --line: #24506a;
  --ink: #e6f2f6;
  --ink-dim: #b7d3dd;
  --muted: #7fa3b0;
  --gold: #f2b23d;
  --gold-soft: #f8d187;
  --good: #6fce9f;
  --bad: #e07a68;
  --heart: #e0705f;
  --accent: #40c4d6;          /* per-world accent; JS swaps this */
  --accent-soft: #8fe9f2;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 10px 30px rgba(0,0,0,.4);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "Cascadia Code", "Roboto Mono", Menlo, Consolas, monospace;
  --maxw: 720px;
  --fs: 16px;
}
/* world accents — diving from the sunlit shallows down into the trench:
   1 Counting Cove (aqua), 2 Addition Lagoon (teal), 3 Multiplication Reef
   (sea green), 4 Division Depths (deep blue), 5 Fraction Trench (indigo) */
:root[data-world="2"] { --accent: #37c2b0; --accent-soft: #8fe6da; }
:root[data-world="3"] { --accent: #4fc98a; --accent-soft: #a6e9c6; }
:root[data-world="4"] { --accent: #5aa0e6; --accent-soft: #a9ccf4; }
:root[data-world="5"] { --accent: #8f8ff0; --accent-soft: #c4c4f8; }
:root[data-world="6"] { --accent: #b18cf0; --accent-soft: #d6c2f7; }

/* accessibility toggles */
:root[data-bigtext="1"] { --fs: 19px; }
:root[data-readable="1"] body,
:root[data-readable="1"] button,
:root[data-readable="1"] h1, :root[data-readable="1"] h2, :root[data-readable="1"] h3 {
  font-family: Verdana, "Comic Sans MS", Tahoma, sans-serif !important;
  letter-spacing: .3px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(1200px 800px at 50% -10%, #124156 0%, transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--fs);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
/* faint drifting bubbles / plankton grain */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: .05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
button { font-family: inherit; font-size: inherit; cursor: pointer; }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; letter-spacing: .1px; line-height: 1.18; }
[tabindex="-1"]:focus { outline: none; }
::selection { background: var(--gold); color: #201a08; }
.skip-link { position: absolute; left: -9999px; top: 0; background: var(--gold); color: #201a08; padding: 8px 14px; z-index: 99; border-radius: 0 0 8px 0; }
.skip-link:focus { left: 0; }
.seo-fallback { color: var(--ink-dim); }

/* ---- App bar ------------------------------------------------ */
.appbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: rgba(8,22,31,.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; background: none; border: 0; color: var(--ink); padding: 4px; }
.brand-glyph { display: inline-flex; line-height: 1; }
.brand-glyph svg { width: 26px; height: 26px; display: block; filter: drop-shadow(0 0 10px rgba(64,196,214,.5)); }
/* the Calculator-Token icon: the flat gold quadrant mark */
.token-ico { display: inline-flex; }
.token-ico svg { width: 16px; height: 16px; display: block; }
.brand-name { font-family: var(--serif); font-weight: 700; font-size: 17px; }
.appbar-stats { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--panel); border: 1px solid var(--line);
  padding: 4px 10px; border-radius: 999px; font-size: 14px; color: var(--ink-dim);
}
.chip b { color: var(--ink); }
.chip.hearts b { color: var(--heart); }
.chip.ink-chip b { color: var(--gold-soft); }
.icon-btn { background: var(--panel); border: 1px solid var(--line); color: var(--ink-dim); border-radius: 999px; width: 34px; height: 34px; display: grid; place-items: center; font-size: 16px; padding: 0; }
.icon-btn:hover { border-color: var(--gold); color: var(--ink); }
.level-chip { flex-direction: column; align-items: stretch; gap: 3px; padding: 4px 10px; }
.lvl { font-size: 12px; color: var(--gold-soft); font-weight: 700; text-align: center; }
.lvl-bar { width: 54px; height: 4px; background: #061019; border-radius: 3px; overflow: hidden; }
.lvl-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--gold-soft)); }

@media (max-width: 560px) {
  .brand-name { display: none; }
  .appbar { padding-left: 12px; padding-right: 12px; gap: 6px; }
  .appbar-stats { gap: 5px; flex-wrap: nowrap; }
  .chip { padding: 4px 8px; font-size: 12.5px; gap: 4px; }
  .icon-btn { width: 30px; height: 30px; font-size: 15px; }
  .level-chip { padding: 3px 8px; }
  .lvl-bar { width: 42px; }
  .lvl { font-size: 11px; }
}

/* ---- Layout ------------------------------------------------- */
.screen {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 18px 16px calc(40px + env(safe-area-inset-bottom));
  animation: fade .28s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---- Home --------------------------------------------------- */
.home-hero { text-align: center; padding: 14px 8px 6px; }
.home-title {
  font-size: clamp(30px, 8vw, 44px);
  margin: 6px 0 4px; color: var(--ink);
  letter-spacing: .2px; font-weight: 800;
}
.home-title::after {
  content: ""; display: block; width: 42px; height: 2px; margin: 13px auto 0;
  background: var(--gold); border-radius: 2px; opacity: .8;
}
.home-tag {
  color: var(--muted); margin: 0 auto 20px; max-width: 36ch;
  font-style: italic; font-family: var(--serif); font-size: 15.5px;
}
/* the four operations on a coordinate graph — front and center */
.home-book { display: flex; justify-content: center; margin: 6px 0 14px; }
.book-art {
  width: min(230px, 62%); height: auto;
  filter: drop-shadow(0 7px 18px rgba(0,0,0,.45));
  animation: bookbob 5s ease-in-out infinite;
}
@keyframes bookbob { 0%,100% { transform: translateY(0) rotate(-0.6deg); } 50% { transform: translateY(-4px) rotate(0.6deg); } }

.section-head { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.5px; margin: 26px 4px 12px; }

.continue-btn { margin: 14px 0 4px; }

/* Tally's Trial call-out on the home screen */
.trial-cta {
  position: relative; width: 100%; text-align: left; margin: 16px 0 4px;
  display: flex; gap: 14px; align-items: center;
  background: linear-gradient(135deg, rgba(64,196,214,.16), rgba(242,178,61,.12));
  border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 15px 16px; color: var(--ink);
  box-shadow: 0 0 22px rgba(64,196,214,.14);
  transition: transform .12s ease, box-shadow .12s ease;
}
.trial-cta:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.trial-cta-glyph { font-size: 34px; flex: none; filter: drop-shadow(0 2px 8px rgba(0,0,0,.4)); animation: bossbob 3.6s ease-in-out infinite; }
.trial-cta-body { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.trial-cta-title { font-family: var(--serif); font-size: 19px; color: var(--gold-soft); }
.trial-cta-sub { font-size: 13px; color: var(--ink-dim); }
.trial-cta-badge {
  font-size: 11px; font-weight: 700; color: var(--accent-soft);
  border: 1px solid var(--accent); border-radius: 999px; padding: 3px 10px; flex: none;
  background: rgba(64,196,214,.12);
}
.trial-cta-badge.done { color: var(--good); border-color: rgba(111,206,159,.5); background: rgba(111,206,159,.1); }

/* world cards on home */
.world-list { display: flex; flex-direction: column; gap: 12px; }
.world-card {
  position: relative; text-align: left; width: 100%;
  display: flex; gap: 14px; align-items: center;
  background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.035);
  padding: 16px; color: var(--ink);
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.world-card:not(:disabled):hover { transform: translateY(-2px); border-color: var(--gold); box-shadow: var(--shadow); }
.world-card:disabled { cursor: default; opacity: .55; }
.world-glyph { font-size: 32px; flex: none; filter: drop-shadow(0 2px 8px rgba(0,0,0,.4)); }
.world-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.world-name { font-family: var(--serif); font-size: 19px; }
.world-grade { font-size: 11px; color: var(--accent-soft); font-weight: 700; letter-spacing: .4px; text-transform: uppercase; }
.world-sub { font-size: 13px; color: var(--ink-dim); }
.world-progress { margin-top: 4px; }
.world-lock { margin-left: auto; font-size: 20px; color: var(--muted); flex: none; }
.world-soon { font-size: 11px; color: var(--muted); border: 1px dashed var(--line); border-radius: 999px; padding: 2px 9px; flex: none; }

.home-foot { text-align: center; margin-top: 26px; color: var(--muted); font-size: 13.5px; line-height: 1.7; }
.link-btn { background: none; border: 0; color: var(--gold-soft); text-decoration: underline; font-size: 13.5px; padding: 0; }
.home-foot a { color: var(--gold-soft); }

/* ---- Progress bar ------------------------------------------- */
.progress { position: relative; height: 17px; background: #061019; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-soft)); transition: width .5s ease; }
.progress.gold .progress-fill { background: linear-gradient(90deg, var(--gold), var(--gold-soft)); }
.progress-label {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 10.5px; line-height: 1; font-weight: 600; letter-spacing: .4px;
  color: var(--ink); text-shadow: 0 1px 2px rgba(0,0,0,.75);
}
.world-progress { display: block; }

/* ---- The Path ------------------------------------------------ */
.path-head { text-align: center; margin: 4px 0 6px; }
.path-title { font-size: clamp(26px, 7vw, 36px); margin: 4px 0 2px; }
.path-spirit { color: var(--muted); font-style: italic; font-family: var(--serif); font-size: 14.5px; max-width: 44ch; margin: 0 auto 8px; }
.path { position: relative; display: flex; flex-direction: column; align-items: center; gap: 0; padding: 18px 0 8px; }
.path::before {
  content: ""; position: absolute; top: 30px; bottom: 30px; left: 50%;
  width: 3px; transform: translateX(-50%);
  background: repeating-linear-gradient(180deg, var(--line) 0 10px, transparent 10px 20px);
}
.path-node {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: none; border: 0; color: var(--ink);
  padding: 12px 10px; width: min(340px, 88vw);
}
.path-node:nth-child(odd)  { transform: translateX(-11%); }
.path-node:nth-child(even) { transform: translateX(11%); }
.node-bubble {
  width: 74px; height: 74px; border-radius: 50%;
  display: grid; place-items: center; font-size: 32px;
  background: var(--panel); border: 3px solid var(--line);
  box-shadow: 0 6px 0 rgba(0,0,0,.35);
  transition: transform .12s ease, border-color .12s ease;
}
.path-node:not(:disabled):hover .node-bubble { transform: translateY(-3px); border-color: var(--accent); }
.path-node:not(:disabled):active .node-bubble { transform: translateY(0); }
.path-node.done .node-bubble { border-color: var(--accent); background: linear-gradient(160deg, var(--panel-2), var(--panel)); }
.path-node.gold .node-bubble { border-color: var(--gold); box-shadow: 0 6px 0 rgba(0,0,0,.35), 0 0 22px rgba(242,178,61,.35); }
.path-node.next .node-bubble { border-color: var(--accent); animation: pulse 1.8s ease infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 6px 0 rgba(0,0,0,.35), 0 0 0 0 rgba(64,196,214,.45); } 50% { box-shadow: 0 6px 0 rgba(0,0,0,.35), 0 0 0 12px rgba(64,196,214,0); } }
.path-node:disabled { cursor: default; }
.path-node:disabled .node-bubble { opacity: .45; filter: grayscale(.6); }
.node-label { font-family: var(--serif); font-size: 15.5px; text-align: center; max-width: 24ch; }
.path-node:disabled .node-label { color: var(--muted); }
.node-sub { font-size: 12px; color: var(--muted); }
.node-crowns { font-size: 12px; letter-spacing: 1px; color: var(--gold-soft); min-height: 15px; }
.node-boss .node-bubble { width: 92px; height: 92px; font-size: 44px; border-color: #7a4b3a; }
.node-boss.next .node-bubble { border-color: var(--bad); animation: pulse 1.8s ease infinite; }
.node-boss.done .node-bubble { border-color: var(--gold); }
.path-next-world { margin: 20px auto 0; text-align: center; color: var(--muted); font-size: 14px; }

/* ---- Lesson player chrome ------------------------------------ */
.game-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.qcount { font-size: 13px; color: var(--muted); text-align: center; flex: 1; font-weight: 600; }
.hearts-live { font-size: 15px; letter-spacing: 1px; white-space: nowrap; }
.ghost-btn {
  background: var(--panel); border: 1px solid var(--line); color: var(--ink-dim);
  padding: 8px 12px; border-radius: 999px; font-size: 13px; white-space: nowrap;
}
.ghost-btn:hover { color: var(--ink); border-color: var(--gold); }
.primary {
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  color: #241c05; border: 0; font-weight: 700; font-size: 16px;
  padding: 14px 20px; border-radius: 12px; width: 100%;
  box-shadow: 0 6px 18px rgba(242,178,61,.25);
  transition: transform .1s ease, filter .1s ease;
}
.primary:hover { filter: brightness(1.05); }
.primary:active { transform: scale(.98); }
.primary:disabled { filter: grayscale(.5) brightness(.7); cursor: default; transform: none; }
.danger-btn { background: rgba(215,106,99,.12); border: 1px solid var(--bad); color: #f0a9a4; padding: 12px 18px; border-radius: 12px; font-weight: 600; }

.qbar { height: 6px; background: #061019; border-radius: 3px; overflow: hidden; margin-bottom: 18px; }
.qbar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-soft)); transition: width .3s ease; }
.qprompt { font-size: clamp(19px, 5vw, 24px); line-height: 1.35; margin: 0 0 18px; font-family: var(--serif); }

/* teaching cards */
.teach-card {
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-left: 4px solid var(--gold);
  border-radius: var(--radius); padding: 18px 18px; margin-bottom: 14px;
  box-shadow: var(--shadow); animation: fade .25s ease;
}
.teach-card h3 { margin: 0 0 8px; color: var(--gold-soft); }
.teach-card p { margin: 0 0 10px; color: var(--ink); }
.teach-card p:last-child { margin-bottom: 0; }
.teach-card em { color: var(--accent-soft); font-style: italic; }
.teach-card strong { color: var(--gold-soft); }
.teach-ex { font-family: var(--mono); font-style: normal; background: rgba(0,0,0,.28); border-radius: 10px; padding: 10px 14px; margin: 8px 0; color: var(--accent-soft); font-size: 15px; }

/* ---- Exercise widgets ---------------------------------------- */
.options { display: flex; flex-direction: column; gap: 11px; }
.option {
  text-align: left; background: var(--panel); border: 1.5px solid var(--line);
  color: var(--ink); font-size: 16px; padding: 15px 16px; border-radius: 13px;
  transition: border-color .12s, background .12s, transform .08s;
}
.option:not(:disabled):hover { border-color: var(--accent); background: var(--panel-2); }
.option:not(:disabled):active { transform: scale(.99); }
.option:disabled { opacity: .95; cursor: default; }
.option.correct { border-color: var(--good); background: rgba(111,206,159,.16); color: #d7f5e6; }
.option.wrong { border-color: var(--bad); background: rgba(215,106,99,.15); color: #f6cecb; }
/* numeric multiple-choice: center the numbers, make them big and monospace */
.options.numeric { flex-direction: row; flex-wrap: wrap; justify-content: center; }
.options.numeric .option { flex: 1 1 40%; min-width: 120px; text-align: center; font-family: var(--mono); font-size: 22px; font-weight: 700; padding: 18px 12px; }

/* tap-the-word / tap-the-number */
.tapwords { display: flex; flex-wrap: wrap; gap: 8px 6px; font-family: var(--serif); font-size: 19px; line-height: 1.6; margin-bottom: 8px; justify-content: center; }
.tapword {
  background: none; border: 1.5px solid transparent; border-radius: 9px;
  color: var(--ink); padding: 3px 9px; font-family: var(--mono); font-size: 20px; font-weight: 700;
  transition: border-color .1s, background .1s;
}
.tapword:not(:disabled):hover { border-color: var(--accent); background: var(--panel-2); }
.tapword.correct { border-color: var(--good); background: rgba(111,206,159,.16); }
.tapword.wrong { border-color: var(--bad); background: rgba(215,106,99,.15); }
.tapword.reveal { border-color: var(--good); }

/* word/number bank builder */
.wb-answer {
  min-height: 58px; display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start;
  border-bottom: 2px solid var(--line); padding: 6px 2px 12px; margin-bottom: 18px;
  justify-content: center;
}
.wb-bank { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 18px; }
.tile {
  background: var(--panel); border: 1.5px solid var(--line); border-bottom-width: 3px;
  color: var(--ink); font-size: 18px; padding: 9px 15px; border-radius: 11px;
  font-family: var(--mono); font-weight: 700;
  transition: transform .08s, border-color .1s;
}
.tile:not(:disabled):hover { border-color: var(--accent); }
.tile:not(:disabled):active { transform: scale(.96); }
.tile.ghost { opacity: .25; pointer-events: none; }
.wb-answer .tile { background: var(--panel-2); }
.wb-answer.good .tile { border-color: var(--good); }
.wb-answer.bad .tile { border-color: var(--bad); }

/* match pairs */
.mp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.mp-col { display: flex; flex-direction: column; gap: 10px; }
.mp-item {
  text-align: center; background: var(--panel); border: 1.5px solid var(--line);
  color: var(--ink); font-size: 15.5px; padding: 12px 12px; border-radius: 12px;
  min-height: 52px; line-height: 1.35; display: grid; place-items: center;
  transition: border-color .1s, background .1s, opacity .3s;
}
.mp-item:not(:disabled):hover { border-color: var(--accent); }
.mp-item.active { border-color: var(--gold); background: var(--panel-2); box-shadow: 0 0 0 3px rgba(242,178,61,.18); }
.mp-item.done { opacity: .35; border-style: dashed; cursor: default; }
.mp-item.flash { border-color: var(--bad); background: rgba(215,106,99,.15); animation: shake .3s ease; }
@keyframes shake { 0%,100% { transform: none; } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* order-it */
.ord-pool, .ord-answer { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.ord-item {
  display: flex; align-items: center; gap: 10px; text-align: left;
  background: var(--panel); border: 1.5px solid var(--line);
  color: var(--ink); font-size: 16px; padding: 12px 14px; border-radius: 12px;
}
.ord-item:not(:disabled):hover { border-color: var(--accent); }
.ord-num {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--gold-soft);
}
.ord-item.ok { border-color: var(--good); background: rgba(111,206,159,.1); }
.ord-item.miss { border-color: var(--bad); background: rgba(215,106,99,.1); }
.ord-item.ghost { opacity: .25; pointer-events: none; }

/* feedback + explain */
.explain { margin-top: 18px; border-radius: 13px; padding: 14px 16px; border: 1px solid var(--line); animation: fade .25s ease; }
.explain.good { border-color: rgba(111,206,159,.5); background: rgba(111,206,159,.08); }
.explain.bad { border-color: rgba(215,106,99,.5); background: rgba(215,106,99,.08); }
.explain-head { font-weight: 700; font-family: var(--serif); margin-bottom: 4px; }
.explain.good .explain-head { color: var(--good); }
.explain.bad .explain-head { color: var(--bad); }
.explain-body { color: var(--ink-dim); font-size: 14.5px; }
.explain-body strong { color: var(--gold-soft); font-family: var(--mono); }
.next-btn { margin-top: 16px; }

/* ---- Results / end screens ----------------------------------- */
.result-card { text-align: center; background: linear-gradient(160deg, var(--panel-2), var(--panel)); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px 20px; box-shadow: var(--shadow); }
.result-emoji { font-size: 54px; }
.result-card h2 { font-size: 36px; margin: 6px 0 2px; color: var(--gold-soft); }
.result-verdict { color: var(--ink-dim); margin: 0 0 18px; }
.result-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 6px; display: flex; flex-direction: column; gap: 2px; }
.stat-num { font-family: var(--serif); font-size: 20px; color: var(--gold-soft); font-weight: 700; }
.stat-lbl { font-size: 11px; color: var(--muted); }
.record-badge { color: var(--gold-soft); font-weight: 700; margin-bottom: 16px; animation: pop .4s ease; }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.1); } 100% { transform: scale(1); opacity: 1; } }
.result-actions { display: flex; flex-direction: column; gap: 10px; }

/* ---- Boss battle ---------------------------------------------- */
.boss-head { text-align: center; margin-bottom: 10px; }
.boss-portrait { font-size: 64px; filter: drop-shadow(0 4px 14px rgba(0,0,0,.5)); animation: bossbob 3s ease-in-out infinite; display: inline-block; }
@keyframes bossbob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.boss-portrait.hit { animation: bosshit .4s ease; }
@keyframes bosshit { 0% { transform: scale(1); filter: brightness(2) drop-shadow(0 0 18px rgba(242,178,61,.8)); } 100% { transform: scale(1); } }
.boss-name { font-size: 24px; margin: 2px 0 8px; color: var(--gold-soft); }
.boss-hp { max-width: 300px; margin: 0 auto 4px; }
.boss-hp .progress-fill { background: linear-gradient(90deg, #b0503c, var(--bad)); }
.boss-taunt {
  font-family: var(--serif); font-style: italic; color: var(--ink-dim);
  background: rgba(0,0,0,.25); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; margin: 10px auto 14px; max-width: 46ch; min-height: 20px;
  animation: fade .3s ease;
}
.boss-intro-card { text-align: center; }
.boss-intro-card .boss-portrait { font-size: 84px; }

/* ---- Badges / toast / confetti -------------------------------- */
.badge-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 14px; }
.badge-pill { background: rgba(242,178,61,.1); border: 1px solid rgba(242,178,61,.35); color: var(--gold-soft); border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--gold); color: var(--ink);
  border-radius: 999px; padding: 10px 18px; font-size: 14.5px; z-index: 60;
  box-shadow: var(--shadow); animation: toastin .25s ease;
  max-width: 92vw; text-align: center;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }
.confetti { position: fixed; top: -12px; z-index: 70; font-size: 18px; pointer-events: none; animation: confall linear forwards; }
@keyframes confall { to { transform: translateY(105vh) rotate(540deg); opacity: .7; } }

/* ---- Settings / modal ----------------------------------------- */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50; display: grid; place-items: center; padding: 20px; animation: fade .2s ease; }
.modal { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 20px; max-width: 420px; width: 100%; max-height: 84dvh; overflow: auto; box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 14px; font-size: 22px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.setting-row:last-of-type { border-bottom: 0; }
.setting-lbl { font-size: 15px; }
.setting-sub { display: block; font-size: 12.5px; color: var(--muted); }
.tog { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; width: 52px; height: 30px; position: relative; flex: none; }
.tog::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--muted); transition: transform .15s ease, background .15s ease; }
.tog.on { border-color: var(--gold); }
.tog.on::after { transform: translateX(22px); background: var(--gold); }
.modal-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

/* ---- Onboarding ------------------------------------------------ */
.onboard-card { max-width: 460px; margin: 6vh auto 0; }
.ob-input {
  width: 100%; box-sizing: border-box;
  background: var(--bg-2); border: 1.5px solid var(--line); border-radius: 12px;
  color: var(--ink); font-family: inherit; font-size: 17px;
  padding: 13px 14px; margin-bottom: 16px; text-align: center;
}
.ob-input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(242,178,61,.15); }
.ob-input::placeholder { color: var(--muted); }
.ob-row { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; }
.ob-select {
  flex: 1; min-width: 0;
  background: var(--bg-2); border: 1.5px solid var(--line); border-radius: 12px;
  color: var(--ink); font-family: inherit; font-size: 15px; padding: 11px 8px;
}
.ob-select:focus { outline: none; border-color: var(--gold); }

/* recommended-world chip */
.world-card.rec { border-color: var(--gold); box-shadow: 0 0 18px rgba(242,178,61,.12), inset 0 1px 0 rgba(255,255,255,.035); }
.world-card.rec .world-name { padding-right: 74px; }
.rec-chip {
  position: absolute; top: 10px; right: 12px;
  font-size: 11px; color: var(--gold-soft); font-weight: 700;
  background: rgba(242,178,61,.12); border: 1px solid rgba(242,178,61,.35);
  padding: 2px 9px; border-radius: 999px;
}

/* ============================================================
   Tally the octopus — corner mascot (matches Scribbles/Discover:
   quiet mode, cheer bubbles, slide-up help drawer)
   ============================================================ */
.scrib {
  position: fixed; right: 12px; bottom: 92px; z-index: 55;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
  pointer-events: none;
}
.scrib > * { pointer-events: auto; }
.scrib-worm-btn {
  width: 64px; height: 64px; padding: 0; border: 0; background: none; cursor: pointer;
  filter: drop-shadow(0 0 9px rgba(64,196,214,.5)) drop-shadow(0 6px 12px rgba(0,0,0,.5));
  animation: scrib-bob 3.4s ease-in-out infinite;
}
.scrib.tucked { opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrib.quiet .scrib-worm-btn { pointer-events: none; cursor: default; opacity: .8; }
.scrib.compact { bottom: 150px; }
.scrib.compact .scrib-worm-btn { width: 46px; height: 46px; opacity: .88; }
.scrib.compact .scrib-worm-btn:hover { opacity: 1; }
.scrib.pop .scrib-worm-btn { animation: scrib-pop .5s ease; }
.scrib-worm { width: 100%; height: 100%; display: block; }
@keyframes scrib-bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes scrib-pop { 0% { transform: scale(1); } 35% { transform: scale(1.18) rotate(-4deg); } 70% { transform: scale(.95); } 100% { transform: scale(1); } }
.scrib-bubble {
  position: relative; max-width: min(240px, 66vw);
  background: var(--panel-2); border: 1px solid var(--gold);
  border-radius: 13px; padding: 9px 26px 9px 12px;
  color: var(--ink); font-size: 12.5px; line-height: 1.45;
  box-shadow: 0 12px 30px rgba(0,0,0,.45);
  opacity: 0; transform: translateY(8px) scale(.96); transform-origin: bottom right;
  transition: opacity .18s ease, transform .18s ease;
}
.scrib-bubble.show { opacity: 1; transform: translateY(0) scale(1); }
.scrib-bubble::after {
  content: ""; position: absolute; right: 22px; bottom: -8px;
  width: 14px; height: 14px; background: var(--panel-2);
  border-right: 1px solid var(--gold); border-bottom: 1px solid var(--gold);
  transform: rotate(45deg);
}
.scrib-btext { margin: 0; }
.scrib-x {
  position: absolute; top: 5px; right: 7px; width: 20px; height: 20px;
  border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 13px; line-height: 1;
}
.scrib-x:hover { color: var(--ink); }
.scrib-actions { display: flex; gap: 8px; margin-top: 11px; flex-wrap: wrap; }
.scrib-abtn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 6px 12px; border-radius: 8px; font-size: 13px; cursor: pointer;
}
.scrib-abtn.primary { background: var(--gold); border-color: var(--gold); color: #1c1710; font-weight: 700; }

/* Tally's help drawer (the slide-up chat) */
.scrib-veil { position: fixed; inset: 0; z-index: 58; background: rgba(4,12,18,.4); }
.scrib-drawer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 59;
  max-width: 720px; margin: 0 auto;
  background: var(--panel-2); border: 1px solid var(--line); border-bottom: 0;
  border-top: 2px solid var(--gold);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -16px 44px rgba(0,0,0,.55);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform .28s ease;
}
.scrib-drawer.open { transform: translateY(0); }
.scrib-d-head { display: flex; align-items: center; gap: 10px; }
.scrib-d-head .scrib-worm { width: 40px; height: 40px; flex: none; filter: drop-shadow(0 2px 5px rgba(0,0,0,.4)); }
.scrib-d-title { display: flex; flex-direction: column; line-height: 1.2; }
.scrib-d-title strong { font-family: var(--serif); font-size: 16.5px; }
.scrib-d-title span { font-size: 11.5px; color: var(--muted); }
.scrib-d-x {
  margin-left: auto; width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink-dim);
  font-size: 13px; cursor: pointer;
}
.scrib-d-x:hover { border-color: var(--gold); color: var(--ink); }
.scrib-greet { margin: 8px 0; color: var(--ink-dim); font-size: 13.5px; line-height: 1.5; font-style: italic; }
.scrib-msgs { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; max-height: 34vh; margin-bottom: 10px; overscroll-behavior: contain; }
.scrib-dmsg { padding: 8px 12px; border-radius: 12px; font-size: 13.5px; line-height: 1.5; max-width: 86%; white-space: pre-wrap; }
.scrib-dmsg.me { align-self: flex-end; background: rgba(242,178,61,.15); border: 1px solid rgba(242,178,61,.4); }
.scrib-dmsg.worm { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.scrib-dmsg.typing { color: var(--muted); letter-spacing: 2px; animation: scrib-bob 1s ease-in-out infinite; }
.scrib-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.scrib-chip { border: 1px solid var(--line); background: var(--panel); color: var(--ink-dim); padding: 6px 11px; border-radius: 999px; font-size: 12.5px; cursor: pointer; }
.scrib-chip:hover { border-color: var(--gold); color: var(--ink); }
.scrib-inrow { display: flex; gap: 8px; }
.scrib-in { flex: 1; min-width: 0; padding: 10px 13px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg-2); color: var(--ink); font-size: 14px; }
.scrib-in:focus { outline: none; border-color: var(--gold); }
.scrib-send2 { border: 0; border-radius: 12px; padding: 10px 18px; cursor: pointer; background: var(--gold); color: #1c1710; font-weight: 700; font-size: 14px; }
.scrib-send2:disabled { opacity: .55; cursor: default; }

/* ---- Chat with a Mathematician (Hall of Numbers) ---------------- */
.study-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 540px) { .study-grid { grid-template-columns: 1fr; } }
.scribe-card { align-items: flex-start; }
.scribe-teaches { font-size: 12px; color: var(--gold-soft); margin-top: 4px; }
.scribe-tools { display: flex; justify-content: center; margin-top: 10px; }
.scrib-quiz { font-size: 14px; padding: 9px 16px; }

/* hearts-empty screen */
.hearts-empty { text-align: center; }
.hearts-empty .result-emoji { animation: bossbob 2.4s ease-in-out infinite; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ==== Trophy Case (badge collection) ================================== */
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 14px 0 30px; }
.badge-card { background: var(--panel); border: 1px solid rgba(242,178,61,.35); border-radius: var(--radius-sm); padding: 12px 10px; text-align: center; display: flex; flex-direction: column; gap: 5px; align-items: center; }
.badge-card .badge-glyph { font-size: 28px; }
.badge-card .badge-name { font-weight: 700; color: var(--gold-soft); font-size: 14px; }
.badge-card .badge-how { font-size: 12px; color: var(--muted); line-height: 1.35; }
.badge-card.locked { border-color: var(--line); opacity: .62; filter: saturate(.4); }
.badge-card.locked .badge-name { color: var(--ink-dim); }

/* ==== the Game Room (minigames) =========================================== */
.mg-picks, .mg-pool { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.mg-pool { flex-direction: row; flex-wrap: wrap; }
.mg-card { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); color: var(--ink); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 15px; cursor: pointer; text-align: left; }
.mg-card:not(.checked):hover { border-color: var(--accent); background: var(--panel-2); }
.mg-card.picked { border-color: var(--accent); }
.mg-card.checked { cursor: default; }
.mg-card.checked.good { border-color: var(--good); background: rgba(111,206,159,.14); }
.mg-card.checked.bad { border-color: var(--bad); background: rgba(215,106,99,.12); }
.mg-slot { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; min-width: 22px; height: 22px; display: grid; place-items: center; font-size: 12px; font-weight: 800; color: var(--accent-soft); }
.mg-glyph { font-size: 20px; font-family: var(--mono); font-weight: 700; }
.mg-name { display: flex; flex-direction: column; line-height: 1.25; }
.mg-lived { color: var(--muted); font-size: 12px; }
.mg-truth { color: var(--ink-dim); font-size: 14px; margin: 8px 0; }
.mg-actions { margin: 14px 0 30px; }

/* Sort It! bins */
.sort-item { font-family: var(--mono); font-weight: 700; font-size: 30px; text-align: center; color: var(--ink); background: var(--panel); border: 1.5px solid var(--gold); border-radius: var(--radius); padding: 22px 18px; margin: 6px 0 18px; box-shadow: var(--shadow); }
.sort-bins { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sort-bin { text-align: center; min-height: 76px; display: grid; place-items: center; font-family: var(--serif); font-size: 16px; }
.sort-bin.correct { border-color: var(--good); background: rgba(111,206,159,.16); }
.sort-bin.wrong { border-color: var(--bad); background: rgba(215,106,99,.15); }
@media (max-width: 420px) { .sort-bins { grid-template-columns: 1fr; } }

/* ==== end-of-lesson review round ============================================ */
.review-intro { background: var(--panel); border: 1px solid rgba(64,196,214,.4); border-radius: var(--radius); padding: 18px; margin: 16px 0; text-align: center; }
.review-intro h3 { margin: 0 0 8px; color: var(--accent-soft); }
.review-intro p { color: var(--ink-dim); margin: 0 0 14px; line-height: 1.5; }
.review-tag { display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: .4px; color: var(--accent-soft); background: rgba(64,196,214,.12); border: 1px solid rgba(64,196,214,.4); border-radius: 999px; padding: 4px 12px; margin: 10px 0 2px; }
.result-verdict.review-line { color: var(--accent-soft); }

/* ==== Floating dock (Trophy Case + games left, Mathematicians right) ========= */
.dock-rail { position: fixed; left: 10px; top: 72px; z-index: 40; display: flex; flex-direction: column; gap: 11px; }
.dock-hidden .dock-rail, .dock-hidden .dock-study { display: none; }
.dock-btn, .dock-study {
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--panel-2); border: 1px solid var(--line);
  box-shadow: 0 6px 16px rgba(0,0,0,.45);
  cursor: pointer; display: grid; place-items: center;
  transition: transform .12s ease, border-color .12s ease;
}
.dock-btn { position: relative; }
.dock-rail .dock-btn:nth-child(even) { margin-left: 26px; }
.dock-study { position: fixed; right: 10px; top: 72px; z-index: 40; }
.dock-btn:hover, .dock-study:hover { transform: translateY(-2px); border-color: var(--accent); }
.dock-btn:active, .dock-study:active { transform: scale(.94); }
.dock-study { border-color: rgba(242,178,61,.5); }
.dock-study:hover { border-color: var(--gold); }
.dock-ico { font-size: 28px; line-height: 1; }
.dock-count { position: absolute; top: -4px; right: -5px; background: var(--gold); color: #201a08; font-size: 10px; font-weight: 800; line-height: 1; border-radius: 999px; padding: 3px 5px; min-width: 10px; text-align: center; }
.dock-label { position: absolute; left: 66px; top: 50%; transform: translateY(-50%) translateX(-4px); white-space: nowrap; background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 4px 9px; font-size: 12px; opacity: 0; pointer-events: none; transition: opacity .12s ease, transform .12s ease; box-shadow: 0 6px 16px rgba(0,0,0,.4); }
.dock-label.left { left: auto; right: 66px; transform: translateY(-50%) translateX(4px); }
.dock-btn:hover .dock-label, .dock-btn:focus-visible .dock-label,
.dock-study:hover .dock-label, .dock-study:focus-visible .dock-label { opacity: 1; transform: translateY(-50%) translateX(0); }
@media (max-width: 820px) {
  .dock-btn, .dock-study { width: 40px; height: 40px; }
  .dock-ico { font-size: 19px; }
  .dock-rail  { top: calc(env(safe-area-inset-top) + 80px); left: 6px; gap: 10px; }
  .dock-study { top: calc(env(safe-area-inset-top) + 80px); right: 6px; }
  .dock-rail .dock-btn:nth-child(even) { margin-left: 0; }
  .screen { padding-left: 52px; padding-right: 52px; }
  .dock-rail, .dock-study { transition: opacity .38s ease, transform .42s cubic-bezier(.2,.75,.25,1), visibility .42s; }
  .dock.dock-attop .dock-rail  { opacity: 0; visibility: hidden; pointer-events: none; transform: translateX(-72px); }
  .dock.dock-attop .dock-study { opacity: 0; visibility: hidden; pointer-events: none; transform: translateX(72px); }
}

/* ============================================================
   Tally's Trial — the daily timed race
   ============================================================ */
.trial-hero { text-align: center; }
.trial-hero .result-emoji { animation: bossbob 3s ease-in-out infinite; }
.trial-rules { text-align: left; max-width: 380px; margin: 4px auto 18px; color: var(--ink-dim); font-size: 14.5px; line-height: 1.6; }
.trial-rules li { margin-bottom: 6px; }
.trial-meta { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 14px; }
.trial-pill { font-size: 12.5px; color: var(--accent-soft); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; background: var(--panel); }
.trial-pill b { color: var(--gold-soft); }

/* race track */
.race { margin: 6px 0 16px; }
.race-lane { position: relative; height: 46px; margin: 8px 0; background: linear-gradient(180deg, rgba(64,196,214,.06), rgba(64,196,214,.02)); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.race-lane.tally { background: linear-gradient(180deg, rgba(242,178,61,.08), rgba(242,178,61,.02)); }
.race-flag { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 18px; opacity: .8; }
.race-runner { position: absolute; top: 50%; left: 0; transform: translate(0,-50%); font-size: 26px; transition: left .5s cubic-bezier(.3,.8,.4,1); filter: drop-shadow(0 2px 5px rgba(0,0,0,.5)); }
.race-label { position: absolute; left: 10px; top: 3px; font-size: 10px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }

/* the big timer + question */
.trial-timer { font-family: var(--mono); font-size: 20px; font-weight: 700; color: var(--accent-soft); text-align: center; }
.trial-timer.low { color: var(--bad); animation: pulse-num .6s ease-in-out infinite; }
@keyframes pulse-num { 0%,100% { opacity: 1; } 50% { opacity: .55; } }
.trial-timerbar { height: 8px; background: #061019; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; margin: 8px 0 16px; }
.trial-timerbar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-soft)); transition: width .25s linear; }
.trial-timerbar.low > span { background: linear-gradient(90deg, #b0503c, var(--bad)); }
.trial-eq {
  font-family: var(--mono); font-weight: 700; text-align: center;
  font-size: clamp(38px, 12vw, 60px); color: var(--ink);
  margin: 6px 0 4px; letter-spacing: 2px;
}
.trial-entry {
  font-family: var(--mono); font-weight: 700; text-align: center;
  font-size: clamp(30px, 9vw, 44px); min-height: 1.3em;
  color: var(--gold-soft); letter-spacing: 3px; margin-bottom: 10px;
  border-bottom: 3px solid var(--line); min-width: 120px; display: inline-block;
}
.trial-entry-wrap { text-align: center; }
.trial-entry.filled { border-color: var(--accent); }
.trial-progress { text-align: center; font-size: 13px; color: var(--muted); margin-bottom: 8px; }

/* number keypad */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 320px; margin: 6px auto 0; }
.key {
  background: var(--panel); border: 1.5px solid var(--line); border-bottom-width: 3px;
  color: var(--ink); font-family: var(--mono); font-weight: 700; font-size: 26px;
  padding: 16px 0; border-radius: 13px;
  transition: transform .06s, border-color .1s, background .1s;
}
.key:hover { border-color: var(--accent); background: var(--panel-2); }
.key:active { transform: scale(.95); }
.key.key-enter { background: linear-gradient(180deg, var(--gold-soft), var(--gold)); color: #241c05; border-color: var(--gold); font-size: 18px; }
.key.key-clear { color: var(--bad); font-size: 18px; }
.key.wide { grid-column: span 1; }
.trial-flash { text-align: center; font-family: var(--serif); font-size: 18px; min-height: 24px; margin: 6px 0; }
.trial-flash.good { color: var(--good); }
.trial-flash.bad { color: var(--bad); }
