/* ============================================================
   Eureka Quest — theme
   Sister to Literature Quest & Philosophy Quest: the same
   scholarly dark DNA, tinted toward a midnight laboratory —
   deep indigo glass, amber sparks, glowing instruments.
   Each world re-accents the UI (lab cyan → frontier blue).
   Mobile-first.
   ============================================================ */
:root {
  --bg: #0e0d1f;
  --bg-2: #151430;
  --panel: #1a1938;
  --panel-2: #232150;
  --line: #34325e;
  --ink: #e9e8f4;
  --ink-dim: #bfbedb;
  --muted: #8f8fb1;
  --gold: #f2b23d;
  --gold-soft: #f8d187;
  --good: #82c07a;
  --bad: #e07a68;
  --heart: #e0705f;
  --accent: #67d4e0;          /* per-world accent; JS swaps this */
  --accent-soft: #a9ecf2;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --maxw: 720px;
  --fs: 16px;
}
/* world accents: 1 Methods (lab cyan), 2 Biology (leaf), 3 Zoology (savanna),
   4 Chemistry (mint), 5 Physics (frontier blue) */
:root[data-world="2"] { --accent: #8ac97a; --accent-soft: #bde5ae; }
:root[data-world="3"] { --accent: #e0a35c; --accent-soft: #f0cd9e; }
:root[data-world="4"] { --accent: #6fd6a8; --accent-soft: #aceccd; }
:root[data-world="5"] { --accent: #7aa8f0; --accent-soft: #b0ccf8; }

/* 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%, #22204e 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;
}
/* fine paper 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(14,13,31,.84);
  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 {
  font-family: var(--serif); font-size: 25px; line-height: 1;
  color: var(--gold); text-shadow: 0 0 18px rgba(242,178,61,.5);
}
.brand-name { font-family: var(--serif); font-weight: 700; font-size: 17px; }
@media (max-width: 420px) { .brand-name { display: none; } }
.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(--accent-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: #0a091a; border-radius: 3px; overflow: hidden; }
.lvl-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--gold-soft)); }

/* ---- 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;
}
/* wordless bubbling flask where stat read-outs would otherwise repeat */
.home-book { display: flex; justify-content: center; margin: 6px 0 14px; }
.book-art {
  width: min(210px, 58%); height: auto;
  filter: drop-shadow(0 7px 16px rgba(0,0,0,.4));
  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; }

/* 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-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: #0a091a; 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(103,212,224,.45); } 50% { box-shadow: 0 6px 0 rgba(0,0,0,.35), 0 0 0 12px rgba(103,212,224,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: #0a091a; 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(--serif); font-style: italic; background: rgba(0,0,0,.22); border-radius: 10px; padding: 10px 14px; margin: 8px 0; color: var(--ink-dim); }

/* ---- 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(107,191,115,.16); color: #d7f5db; }
.option.wrong { border-color: var(--bad); background: rgba(215,106,99,.15); color: #f6cecb; }

/* tap-the-word */
.tapwords { display: flex; flex-wrap: wrap; gap: 8px 6px; font-family: var(--serif); font-size: 19px; line-height: 1.6; margin-bottom: 8px; }
.tapword {
  background: none; border: 1.5px solid transparent; border-radius: 9px;
  color: var(--ink); padding: 3px 7px; font-family: inherit; font-size: inherit;
  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(107,191,115,.16); }
.tapword.wrong { border-color: var(--bad); background: rgba(215,106,99,.15); }
.tapword.reveal { border-color: var(--good); }

/* punctuation placement */
.punct-mark-badge {
  display: inline-grid; place-items: center; min-width: 46px; height: 46px; padding: 0 12px;
  border-radius: 12px; background: var(--panel-2); border: 1.5px solid var(--gold);
  color: var(--gold-soft); font-size: 26px; font-family: var(--serif); font-weight: 700;
  margin: 0 auto 14px;
}
.punct-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px; font-family: var(--serif); font-size: 20px; line-height: 1.9; margin-bottom: 8px; }
.punct-seg { padding: 2px 1px; }
.punct-slot {
  display: inline-grid; place-items: center;
  width: 30px; height: 34px; margin: 0 3px; vertical-align: baseline;
  background: var(--panel); border: 1.5px dashed var(--muted); border-radius: 8px;
  color: var(--muted); font-size: 18px; font-family: inherit;
  transition: border-color .1s, background .1s;
}
.punct-slot:not(:disabled):hover { border-color: var(--accent); background: var(--panel-2); }
.punct-slot.correct { border-style: solid; border-color: var(--good); background: rgba(107,191,115,.16); color: var(--good); font-weight: 700; }
.punct-slot.wrong { border-style: solid; border-color: var(--bad); background: rgba(215,106,99,.15); color: var(--bad); }
.punct-slot.reveal { border-style: solid; border-color: var(--good); color: var(--good); font-weight: 700; }

/* word bank */
.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;
}
.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: 16.5px; padding: 9px 14px; border-radius: 11px;
  font-family: var(--serif);
  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: left; background: var(--panel); border: 1.5px solid var(--line);
  color: var(--ink); font-size: 14.5px; padding: 12px 12px; border-radius: 12px;
  min-height: 52px; line-height: 1.35;
  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: 15.5px; 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(107,191,115,.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(107,191,115,.5); background: rgba(107,191,115,.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; }
.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;
}

/* ---- Scribbles ------------------------------------------------- */
.scrib-modal { text-align: center; }
.scrib-face { font-size: 52px; display: inline-block; animation: bossbob 2.6s ease-in-out infinite; }
.scrib-face.big { font-size: 64px; }
.scrib-name { color: var(--gold-soft); margin: 6px 0 12px; }
.scrib-line { color: var(--ink-dim); font-size: 15px; margin: 0 0 12px; text-align: left; }
.scrib-line strong { color: var(--gold-soft); }
.scrib-line em { color: var(--accent-soft); }
button.chip.hearts { cursor: pointer; }
button.chip.hearts:hover { border-color: var(--heart); }
.scrib-card { border-style: dashed; }
.scrib-card:hover { border-style: solid; }

.scrib-hero { text-align: center; margin-bottom: 10px; }
.scrib-log {
  display: flex; flex-direction: column; gap: 10px;
  min-height: 200px; max-height: 55dvh; overflow-y: auto;
  background: rgba(0,0,0,.18); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.scrib-msg { display: flex; gap: 8px; align-items: flex-end; max-width: 88%; }
.scrib-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.scrib-mini { font-size: 20px; flex: none; }
.scrib-text {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px 14px 14px 4px; padding: 9px 13px; font-size: 15px; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word;
}
.scrib-msg.user .scrib-text { background: var(--panel-2); border-color: var(--accent); border-radius: 14px 14px 4px 14px; }
.scrib-text.dim { color: var(--muted); font-style: italic; }
.scrib-composer { display: flex; gap: 8px; align-items: flex-end; }
.scrib-input {
  flex: 1; resize: none; min-height: 46px; max-height: 120px;
  background: var(--bg-2); border: 1.5px solid var(--line); border-radius: 12px;
  color: var(--ink); font-family: inherit; font-size: 15px; padding: 12px 13px;
}
.scrib-input:focus { outline: none; border-color: var(--gold); }
.scrib-send { width: auto; padding: 12px 20px; }

/* ---- Discover the mascot (matches Scribbles/Ponder/Scout: corner rat,
       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: 60px; height: 60px; padding: 0; border: 0; background: none; cursor: pointer;
  filter: drop-shadow(0 0 9px rgba(103,212,224,.45)) 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; }
/* Quiet mode (a question is on screen): the worm can't be tapped — no drawer,
   no misclicks near the answers — but his brief cheer bubbles still show. */
.scrib.quiet .scrib-worm-btn { pointer-events: none; cursor: default; opacity: .8; }
/* Lesson screens: smaller, translucent, tucked above the Continue bar. */
.scrib.compact { bottom: 150px; }
.scrib.compact .scrib-worm-btn { width: 44px; height: 44px; 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; }

/* Scribbles' help drawer (the slide-up chat) */
.scrib-veil { position: fixed; inset: 0; z-index: 58; background: rgba(8,10,5,.35); }
.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: 38px; height: 38px; 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; }

/* ---- Study with a Scribe ---------------------------------------- */
.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; }
}

/* ==== Scribbles' Scrapbook (badge collection) ================================== */
.scrap-btn { position: relative; font-size: 18px; }
.scrap-count {
  position: absolute; top: -4px; right: -6px;
  background: var(--gold); color: #201a08;
  font-size: 10px; font-weight: 800; line-height: 1;
  border-radius: 999px; padding: 3px 5px; min-width: 10px;
}
.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); }
button.badge-pill.badge-more { cursor: pointer; background: rgba(103,212,224,.12); border-color: var(--accent); color: var(--accent-soft); }

/* ==== 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(107,191,115,.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; }
.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; }
.mg-quote {
  font-family: var(--serif); font-size: 20px; line-height: 1.5; color: var(--ink);
  background: var(--panel); border-left: 3px solid var(--gold);
  border-radius: var(--radius-sm); padding: 16px 18px; margin: 14px 0;
}

/* Sort It! */
.sort-item {
  font-family: var(--serif); font-size: 24px; 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; }
@media (max-width: 420px) { .sort-bins { grid-template-columns: 1fr; } }

/* ==== end-of-lesson review round ============================================ */
.review-intro {
  background: var(--panel); border: 1px solid rgba(103,212,224,.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(103,212,224,.12);
  border: 1px solid rgba(103,212,224,.4); border-radius: 999px;
  padding: 4px 12px; margin: 10px 0 2px;
}
.result-verdict.review-line { color: var(--accent-soft); }

/* ==== Floating dock (Scrapbook + minigames left, Study 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; }
/* the left rail is staggered — every other icon steps to the right */
.dock-rail .dock-btn:nth-child(even) { margin-left: 26px; }
/* Study stays fixed top-right (its own fixed box is the label's positioning context) */
.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;
}
/* hover/focus flyout label */
.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: 560px) {
  .dock-btn, .dock-study { width: 50px; height: 50px; }
  .dock-ico { font-size: 24px; }
  .dock-rail .dock-btn:nth-child(even) { margin-left: 20px; }
}

/* ==== Poem Builder ============================================================ */
.poem-note { color: var(--muted); font-weight: 400; }
.poem-lines { margin: 8px 0 4px; }
.poem-line {
  font-family: var(--serif); font-size: 17px; line-height: 1.6; color: var(--ink-dim);
}
.poem-final {
  font-family: var(--serif); font-size: 19px; line-height: 1.7; color: var(--ink);
  background: var(--panel); border-left: 3px solid var(--gold);
  border-radius: var(--radius-sm); padding: 16px 18px; margin: 12px 0; text-align: left;
}
