/* ============================================================
   Chronology Quest — theme
   Sister to Literature Quest's storybook forest and Philosophy
   Quest's ink & marble: same scholarly dark-parchment DNA,
   tinted toward sandstone, bronze, and hourglass gold.
   The two halves of the timeline re-accent the UI:
   World History = bronze, American History = federal blue.
   Mobile-first.
   ============================================================ */
:root {
  --bg: #171310;
  --bg-2: #1e1914;
  --panel: #251e17;
  --panel-2: #2e261c;
  --line: #43382a;
  --ink: #ece5d8;
  --ink-dim: #c6bda4;
  --muted: #98917a;
  --gold: #d7b24a;
  --gold-soft: #ead18a;
  --good: #8fb562;
  --bad: #d5765f;
  --heart: #e0705f;
  --accent: #cfa457;          /* per-side accent; JS swaps this */
  --accent-soft: #e8cd97;
  --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;
}
/* American History side: federal blue accent */
:root[data-side="amer"] { --accent: #8fb0d1; --accent-soft: #c2d6ea; }

/* 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%, #322718 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(23,19,16,.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-size: 22px; line-height: 1;
  filter: drop-shadow(0 0 12px rgba(215,178,74,.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.token-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: #0f0b08; 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; } }

/* ---- Progress bar ------------------------------------------- */
.progress { position: relative; height: 17px; background: #100c08; 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);
}

/* ============================================================
   The Timeline — the vertical living map.
   World History climbs UP from the hub; American History digs DOWN.
   ============================================================ */
.tl { position: relative; padding: 8px 0 20px; }
.tl::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: 50%;
  width: 3px; transform: translateX(-50%);
  background: repeating-linear-gradient(180deg, var(--line) 0 10px, transparent 10px 20px);
}
.tl-cap {
  position: relative; z-index: 1; text-align: center;
  color: var(--muted); font-style: italic; font-family: var(--serif);
  font-size: 13.5px; padding: 10px 0 16px; max-width: 40ch; margin: 0 auto;
}
.tl-year {
  position: relative; z-index: 1; display: block; width: fit-content;
  margin: 2px auto; padding: 3px 12px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px;
  color: var(--muted); font-size: 11.5px; font-weight: 700; letter-spacing: 1px;
}
.tl-row { position: relative; z-index: 1; display: flex; padding: 10px 0; }
.tl-row.left  { justify-content: flex-start; }
.tl-row.right { justify-content: flex-end; }
.tl-row .world-card { width: min(430px, 86%); }
.tl-side-head {
  position: relative; z-index: 1; text-align: center;
  font-size: 13px; letter-spacing: 2.5px; text-transform: uppercase;
  color: var(--accent-soft); font-weight: 800; padding: 14px 0 4px;
  text-shadow: 0 1px 4px rgba(0,0,0,.6);
}
.tl-side-head small { display: block; letter-spacing: .4px; text-transform: none; color: var(--muted); font-weight: 500; margin-top: 2px; }

/* the hub — "you are here", between the two halves */
.tl-hero {
  position: relative; z-index: 2; text-align: center;
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
  border: 1px solid var(--gold); border-radius: var(--radius);
  box-shadow: var(--shadow), 0 0 34px rgba(215,178,74,.12);
  padding: 20px 16px; margin: 14px auto; width: min(470px, 96%);
}
.tl-hero h1 { font-size: clamp(27px, 7vw, 38px); margin: 2px 0 4px; }
.tl-hero h1::after {
  content: ""; display: block; width: 42px; height: 2px; margin: 11px auto 0;
  background: var(--gold); border-radius: 2px; opacity: .8;
}
.tl-tag { color: var(--muted); margin: 0 auto 12px; max-width: 38ch; font-style: italic; font-family: var(--serif); font-size: 15px; }
.tl-dirs { display: flex; justify-content: center; gap: 10px; margin: 10px 0 4px; flex-wrap: wrap; }
.tl-dir {
  background: var(--panel); border: 1px solid var(--line); color: var(--ink-dim);
  border-radius: 999px; padding: 7px 14px; font-size: 13px;
}
.tl-dir:hover { border-color: var(--accent); color: var(--ink); }
.continue-btn { margin: 12px 0 2px; }

/* wordless hourglass art in the hub (no stat read-outs — those live in the app bar) */
.home-hour { display: flex; justify-content: center; margin: 4px 0 10px; }
.hour-art {
  width: min(120px, 34%); height: auto;
  filter: drop-shadow(0 7px 16px rgba(0,0,0,.4));
  animation: hourbob 5s ease-in-out infinite;
}
@keyframes hourbob { 0%,100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-4px) rotate(1deg); } }

/* Top 30 banner cards on the timeline */
.tl-top30 {
  position: relative; z-index: 1;
  width: min(430px, 86%); margin: 4px auto;
  display: flex; gap: 12px; align-items: center; text-align: left;
  background: linear-gradient(160deg, rgba(215,178,74,.14), var(--panel));
  border: 1px dashed rgba(215,178,74,.55); border-radius: var(--radius);
  color: var(--ink); padding: 13px 15px;
  transition: transform .12s ease, border-color .12s ease;
}
.tl-top30:hover { transform: translateY(-2px); border-style: solid; border-color: var(--gold); }
.t30-glyph { font-size: 30px; flex: none; }
.t30-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.t30-name { font-family: var(--serif); font-size: 17px; color: var(--gold-soft); }
.t30-sub { font-size: 12.5px; color: var(--ink-dim); }
.t30-count { font-size: 12px; color: var(--gold-soft); font-weight: 700; }

/* era cards (shared with rosters etc.) */
.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: 18px; }
.world-sub { font-size: 13px; color: var(--ink-dim); }
.world-span { font-size: 11.5px; color: var(--muted); letter-spacing: .6px; font-weight: 700; }
.world-progress { margin-top: 4px; display: block; }
.world-soon { font-size: 11px; color: var(--muted); border: 1px dashed var(--line); border-radius: 999px; padding: 2px 9px; flex: none; }
.world-card.rec { border-color: var(--gold); box-shadow: 0 0 18px rgba(215,178,74,.12), inset 0 1px 0 rgba(255,255,255,.035); }
.rec-chip {
  position: absolute; top: 10px; right: 12px;
  font-size: 11px; color: var(--gold-soft); font-weight: 700;
  background: rgba(215,178,74,.12); border: 1px solid rgba(215,178,74,.35);
  padding: 2px 9px; border-radius: 999px;
}

.home-foot { position: relative; z-index: 1; 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); }
.section-head { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.5px; margin: 26px 4px 12px; }

/* ---- The era path (inside one era) ---------------------------- */
.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-span { color: var(--gold-soft); font-size: 12px; letter-spacing: 1.5px; font-weight: 700; }
.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(215,178,74,.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(207,164,87,.45); } 50% { box-shadow: 0 6px 0 rgba(0,0,0,.35), 0 0 0 12px rgba(207,164,87,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(215,178,74,.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: #100c08; 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 — primary sources sit in the scroll box */
.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); }
.teach-src { display: block; font-size: 12px; color: var(--muted); font-style: normal; margin-top: 6px; letter-spacing: .3px; }

/* ---- 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 (kept for engine parity with the sister quests) */
.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(215,178,74,.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 (era guardians) ------------------------------- */
.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(215,178,74,.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; }

/* ---- Toast / confetti ------------------------------------------ */
.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(215,178,74,.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); }

/* ---- Top 30 ------------------------------------------------------ */
.t30-hub { text-align: center; }
.t30-clock {
  font-family: var(--serif); font-size: clamp(24px, 6vw, 34px); font-weight: 700;
  color: var(--gold-soft); letter-spacing: 1px; margin: 6px 0 2px;
}
.t30-clock-sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.t30-live {
  display: inline-block; font-size: 12px; font-weight: 800; letter-spacing: 1.5px;
  color: #1c1710; background: linear-gradient(90deg, var(--gold-soft), var(--gold));
  border-radius: 999px; padding: 4px 14px; margin-bottom: 10px;
  animation: pulse 1.8s ease infinite;
}
.t30-list { text-align: left; margin: 14px 0; display: flex; flex-direction: column; gap: 6px; max-height: 46dvh; overflow-y: auto; padding-right: 4px; }
.t30-row {
  display: flex; gap: 10px; align-items: baseline;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; font-size: 14px;
}
.t30-row b { color: var(--gold-soft); font-family: var(--serif); min-width: 74px; text-align: right; flex: none; }

/* flashcards */
.flash-stage { perspective: 1200px; margin: 14px auto; width: min(430px, 96%); }
.flash-card {
  position: relative; width: 100%; min-height: 210px; cursor: pointer;
  transform-style: preserve-3d; transition: transform .45s ease;
  border: 0; background: none; padding: 0; display: block;
}
.flash-card.flipped { transform: rotateY(180deg); }
.flash-face {
  position: absolute; inset: 0; backface-visibility: hidden;
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 8px;
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
  border: 1px solid var(--gold); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; text-align: center;
}
.flash-face.back { transform: rotateY(180deg); }
.flash-year { font-family: var(--serif); font-size: 44px; font-weight: 800; color: var(--gold-soft); }
.flash-event { font-family: var(--serif); font-size: 21px; line-height: 1.4; color: var(--ink); }
.flash-hint { font-size: 12px; color: var(--muted); }
.flash-nav { display: flex; gap: 10px; justify-content: center; align-items: center; margin: 10px 0; }
.flash-count { color: var(--muted); font-size: 13.5px; min-width: 70px; }

/* ---- Reflect the Turtle (corner mascot, matches his siblings) ---- */
.refl {
  position: fixed; right: 12px; bottom: 92px; z-index: 55;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
  pointer-events: none;
}
.refl > * { pointer-events: auto; }
.refl-btn {
  width: 62px; height: 62px; padding: 0; border: 0; background: none; cursor: pointer;
  filter: drop-shadow(0 0 9px rgba(207,164,87,.45)) drop-shadow(0 6px 12px rgba(0,0,0,.5));
  animation: refl-bob 4.2s ease-in-out infinite;
}
.refl.tucked { opacity: 0; pointer-events: none; transition: opacity .2s; }
.refl.quiet .refl-btn { pointer-events: none; cursor: default; opacity: .8; }
.refl.compact { bottom: 150px; }
.refl.compact .refl-btn { width: 46px; height: 46px; opacity: .88; }
.refl.compact .refl-btn:hover { opacity: 1; }
.refl.pop .refl-btn { animation: refl-pop .5s ease; }
.refl-turtle { width: 100%; height: 100%; display: block; }
@keyframes refl-bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes refl-pop { 0% { transform: scale(1); } 35% { transform: scale(1.18) rotate(-4deg); } 70% { transform: scale(.95); } 100% { transform: scale(1); } }
.refl-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;
}
.refl-bubble.show { opacity: 1; transform: translateY(0) scale(1); }
.refl-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);
}
.refl-btext { margin: 0; }
.refl-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;
}
.refl-x:hover { color: var(--ink); }
.refl-actions { display: flex; gap: 8px; margin-top: 11px; flex-wrap: wrap; }
.refl-abtn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 6px 12px; border-radius: 8px; font-size: 13px; cursor: pointer;
}
.refl-abtn.primary { background: var(--gold); border-color: var(--gold); color: #1c1710; font-weight: 700; }

/* Reflect's help drawer (the slide-up chat) */
.refl-veil { position: fixed; inset: 0; z-index: 58; background: rgba(8,10,5,.35); }
.refl-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;
}
.refl-drawer.open { transform: translateY(0); }
.refl-d-head { display: flex; align-items: center; gap: 10px; }
.refl-d-head .refl-turtle { width: 38px; height: 38px; flex: none; filter: drop-shadow(0 2px 5px rgba(0,0,0,.4)); }
.refl-d-title { display: flex; flex-direction: column; line-height: 1.2; }
.refl-d-title strong { font-family: var(--serif); font-size: 16.5px; }
.refl-d-title span { font-size: 11.5px; color: var(--muted); }
.refl-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;
}
.refl-d-x:hover { border-color: var(--gold); color: var(--ink); }
.refl-greet { margin: 8px 0; color: var(--ink-dim); font-size: 13.5px; line-height: 1.5; font-style: italic; }
.refl-msgs {
  display: flex; flex-direction: column; gap: 8px;
  overflow-y: auto; max-height: 34vh; margin-bottom: 10px;
  overscroll-behavior: contain;
}
.refl-dmsg {
  padding: 8px 12px; border-radius: 12px; font-size: 13.5px; line-height: 1.5; max-width: 86%;
  white-space: pre-wrap;
}
.refl-dmsg.me { align-self: flex-end; background: rgba(215,178,74,.15); border: 1px solid rgba(215,178,74,.4); }
.refl-dmsg.turtle { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.refl-dmsg.typing { color: var(--muted); letter-spacing: 2px; animation: refl-bob 1s ease-in-out infinite; }
.refl-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.refl-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;
}
.refl-chip:hover { border-color: var(--gold); color: var(--ink); }
.refl-inrow { display: flex; gap: 8px; }
.refl-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;
}
.refl-in:focus { outline: none; border-color: var(--gold); }
.refl-send {
  border: 0; border-radius: 12px; padding: 10px 18px; cursor: pointer;
  background: var(--gold); color: #1c1710; font-weight: 700; font-size: 14px;
}
.refl-send:disabled { opacity: .55; cursor: default; }

/* ---- Remember with a Recorder (figure chat) --------------------- */
.study-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 540px) { .study-grid { grid-template-columns: 1fr; } }
.figure-card { align-items: flex-start; }
.figure-teaches { font-size: 12px; color: var(--gold-soft); margin-top: 4px; }
.rec-hero { text-align: center; margin-bottom: 10px; }
.rec-face { font-size: 52px; display: inline-block; animation: bossbob 2.6s ease-in-out infinite; }
.rec-face.big { font-size: 64px; }
.rec-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;
}
.rec-msg { display: flex; gap: 8px; align-items: flex-end; max-width: 88%; }
.rec-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.rec-mini { font-size: 20px; flex: none; }
.rec-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;
}
.rec-msg.user .rec-text { background: var(--panel-2); border-color: var(--accent); border-radius: 14px 14px 4px 14px; }
.rec-text.dim { color: var(--muted); font-style: italic; }
.rec-composer { display: flex; gap: 8px; align-items: flex-end; }
.rec-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;
}
.rec-input:focus { outline: none; border-color: var(--gold); }
.rec-send { width: auto; padding: 12px 20px; }

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

/* ==== Scrapbook (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(215,178,74,.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 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;
}

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

/* ==== Floating dock (Scrapbook + minigames left, Recorder 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; }
.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(215,178,74,.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: 560px) {
  .dock-btn, .dock-study { width: 50px; height: 50px; }
  .dock-ico { font-size: 24px; }
  .dock-rail .dock-btn:nth-child(even) { margin-left: 20px; }
}

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