/* Themes. [data-theme] also works on shop swatches.
   "line" separates static content. Anything you can press gets an ink border. */
:root, [data-theme="daylight"] {
  --bg: #f6f0e1; --surface: #fffcf4; --soft: #ede4cd; --text: #24201a; --muted: #655c4d; --line: #d9cdb0;
  --primary: #2b53ad; --on-primary: #ffffff; --accent: #f2b233;
  --good: #1d6b42; --good-bg: #dcecd6; --bad: #a3301c; --bad-bg: #f7dcd2;
}
[data-theme="midnight"] {
  --bg: #17181c; --surface: #212329; --soft: #2f3139; --text: #f1ede2; --muted: #ada796; --line: #3e414b;
  --primary: #9db9ff; --on-primary: #121624; --accent: #f2b233;
  --good: #86d9a5; --good-bg: #1b3629; --bad: #ffa08d; --bad-bg: #47251f;
}
[data-theme="sakura"] {
  --bg: #f9eaec; --surface: #fff9f8; --soft: #f3d8dd; --text: #3d1f28; --muted: #77505b; --line: #e8c2ca;
  --primary: #9d2f57; --on-primary: #ffffff; --accent: #f4a259;
  --good: #1d6b42; --good-bg: #ddecd9; --bad: #9c2a1c; --bad-bg: #fbd9d0;
}
[data-theme="ocean"] {
  --bg: #e5eeee; --surface: #fbfefd; --soft: #d3e3e3; --text: #102d34; --muted: #466368; --line: #b7ced0;
  --primary: #0f5c68; --on-primary: #ffffff; --accent: #f08a3c;
  --good: #1d6b42; --good-bg: #d9eeda; --bad: #a3301c; --bad-bg: #f8dcd5;
}
[data-theme="arcade"] {
  --bg: #1c1130; --surface: #281a44; --soft: #38265c; --text: #fbf5ff; --muted: #c1abe0; --line: #4c3578;
  --primary: #5ee0c6; --on-primary: #10231f; --accent: #ffd84a;
  --good: #93efab; --good-bg: #143a34; --bad: #ff9dba; --bad-bg: #4d1638;
}

[data-theme="forest"] {
  --bg: #e9efe0; --surface: #fbfdf6; --soft: #dae5cb; --text: #1f2d1c; --muted: #4f5e46; --line: #c0d1ae;
  --primary: #2f6a3b; --on-primary: #ffffff; --accent: #e0a92e;
  --good: #1d6b42; --good-bg: #d3ebd1; --bad: #a3301c; --bad-bg: #f7dcd2;
}
[data-theme="chalk"] {
  --bg: #22332c; --surface: #2b3f37; --soft: #375046; --text: #f3f6ec; --muted: #bccdbe; --line: #4b6658;
  --primary: #ffe08a; --on-primary: #26240f; --accent: #f4a6b8;
  --good: #b0ecb2; --good-bg: #22503a; --bad: #ffbcab; --bad-bg: #57322d;
}

* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font: 16px/1.5 "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  padding-bottom: 92px;
}
h1, h2, h3, .prompt, .big-number, .stat b { font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif; }
h1 { font-size: 1.8rem; line-height: 1.2; margin: 0; }
h2 { font-size: 1.2rem; margin: 0 0 8px; }
h3 { font-size: 1.05rem; margin: 0; }
p { margin: 4px 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
.hidden { display: none; }
.muted { color: var(--muted); }
.good-text { color: var(--good); font-weight: 600; }
.center { text-align: center; justify-content: center; }
.grow { flex: 1; min-width: 0; }
.icon, .mascot { display: inline-flex; flex: none; line-height: 0; }
.tagline { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- frame ---------- */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--surface); border-bottom: 2px solid var(--text);
}
.brand { display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 0; }
.wordmark { display: inline-flex; line-height: 0; }
.stats { display: flex; gap: 4px; }
.top-stat { display: flex; align-items: center; gap: 5px; background: none; border: 0; border-radius: 8px; padding: 4px 8px; }
.top-stat:hover { background: var(--soft); }
.level { display: flex; flex-direction: column; gap: 2px; font-size: .85rem; line-height: 1.2; }
.level .bar { height: 5px; width: 56px; }

main { max-width: 640px; margin: 0 auto; padding: 20px 16px; }
nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; justify-content: center;
  padding: 6px 4px; background: var(--surface); border-top: 2px solid var(--text);
}
nav button { flex: 1; max-width: 130px; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; background: none; border: 2px solid transparent; border-radius: 10px; padding: 5px 2px; font-size: .78rem; color: var(--muted); }
nav button.on { background: var(--soft); border-color: var(--text); color: var(--text); font-weight: 600; }

body.focus { padding-bottom: 24px; }
body.focus nav, body.focus .top { display: none; }

@media (min-width: 900px) {
  body { padding-bottom: 24px; }
  nav { top: 62px; right: auto; width: 190px; flex-direction: column; justify-content: flex-start; gap: 4px; padding: 16px 10px; border-top: 0; border-right: 2px solid var(--line); }
  nav button { flex: none; max-width: none; flex-direction: row; gap: 10px; padding: 8px 10px; font-size: 1rem; }
  body:not(.focus) main { margin-left: max(210px, calc(50% - 320px)); }
}
@media (max-width: 430px) {
  .brand .wordmark { display: none; }
  .top { padding: 8px 10px; }
  .top-stat { padding: 4px 5px; }
}

/* ---------- building blocks ---------- */
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack.tight { gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; margin-top: 12px; }
.row.wrap { flex-wrap: wrap; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card { background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px; padding: 16px; }
.notice { border: 2px solid var(--accent); }

.btn {
  border: 2px solid var(--text); border-radius: 10px; background: var(--surface); box-shadow: 0 3px 0 var(--text);
  padding: 8px 18px; font-weight: 600; margin-bottom: 3px;
}
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--text); }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.accent { background: var(--accent); color: #2a1c00; }
.btn.plain { background: none; border-color: transparent; box-shadow: none; text-decoration: underline; text-underline-offset: 3px; }
.btn.small { padding: 3px 12px; font-size: .9rem; }
.btn.big { padding: 12px 18px; font-size: 1.1rem; width: 100%; }
.btn.cant, .btn:disabled { opacity: .55; }
.back-link { display: inline-flex; align-self: flex-start; align-items: center; gap: 6px; background: none; border: 0; padding: 4px 0; font-weight: 600; }
.back-link:hover { text-decoration: underline; }

.bar { height: 9px; background: var(--soft); border-radius: 6px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--primary); transition: width .25s; }
.bar.tall { height: 14px; border: 2px solid var(--text); }
.bar.timer span { background: var(--accent); transition: width .1s linear; }
.bar.money span { background: var(--good); }

.hero { display: flex; gap: 16px; align-items: center; }

.list { border: 2px solid var(--text); border-radius: 12px; overflow: hidden; background: var(--surface); }
.link-row { display: flex; width: 100%; align-items: center; gap: 14px; padding: 12px 14px; background: none; border: 0; text-align: left; }
.link-row + .link-row { border-top: 1.5px solid var(--line); }
.link-row:hover:not(:disabled) { background: var(--soft); }
.link-row:disabled { opacity: .45; }
.link-row b, .link-row small { display: block; }
.link-row small { color: var(--muted); }

.deck-switch { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.deck-switch button { display: flex; align-items: center; gap: 8px; text-align: left; padding: 8px 10px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface); line-height: 1.25; overflow-wrap: anywhere; }
.deck-switch button.on { border: 2px solid var(--text); background: var(--soft); font-weight: 600; }

.week { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; }
.weekday { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px 0; font-size: .8rem; border-radius: 8px; }
.weekday i { width: 14px; height: 14px; margin: 5px 0; border-radius: 50%; border: 2px solid var(--line); }
.weekday.now { background: var(--soft); font-weight: 700; }
.quest { display: flex; align-items: center; gap: 14px; padding: 10px 0; border-top: 1px solid var(--line); }
.quest .bar { margin-top: 4px; }

.item-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.item { display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 8px; text-align: center; }
.item.equipped { border: 2px solid var(--good); }
.wardrobe { position: sticky; top: 60px; z-index: 3; display: flex; align-items: center; gap: 18px; padding: 8px 16px; border: 2px solid var(--text); color: var(--text); }
.wardrobe-stage { width: 172px; flex: none; line-height: 0; }
.wardrobe-stage .mascot { display: block; }
.wardrobe-stage svg { width: 100%; height: auto; }
.wardrobe-info { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.wardrobe-info > * { max-width: 100%; }
.wardrobe-info .bar { width: 190px; }
.wardrobe-info h2 { margin: 0; }
.try { background: none; border: 2px dashed transparent; border-radius: 10px; padding: 2px; line-height: 0; }
.try:hover { border-color: var(--line); background: var(--soft); }
.swatch { display: flex; gap: 4px; padding: 14px; border-radius: 10px; background: var(--bg); border: 2px solid var(--text); }
.swatch i { width: 18px; height: 44px; border-radius: 4px; background: var(--primary); }
.swatch i:nth-child(2) { background: var(--accent); }
.swatch i:nth-child(3) { background: var(--text); }
.pieces { display: flex; gap: 6px; align-items: center; height: 76px; }

.tabs { display: flex; flex-wrap: wrap; gap: 4px 16px; border-bottom: 1.5px solid var(--line); }
.tabs button { background: none; border: 0; border-bottom: 4px solid transparent; padding: 6px 0; color: var(--muted); }
.tabs button.on { border-color: var(--text); color: var(--text); font-weight: 600; }

.stat-grid { display: flex; flex-wrap: wrap; gap: 1.5px; background: var(--line); border: 1.5px solid var(--line); border-radius: 12px; overflow: hidden; }
.stat { flex: 1 1 30%; display: flex; flex-direction: column; text-align: center; padding: 10px; background: var(--surface); }
.stat b { font-size: 1.4rem; }
.stat span { color: var(--muted); font-size: .85rem; }

.path { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 8px 0; }
.node-wrap { display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; max-width: 180px; }
.node-wrap.shift1 { transform: translateX(50px); }
.node-wrap.shift3 { transform: translateX(-50px); }
.node { width: 68px; height: 62px; display: grid; place-items: center; border-radius: 50%; border: 2px solid var(--text); box-shadow: 0 5px 0 var(--text); margin-bottom: 7px; background: var(--surface); }
.node.done { background: var(--good-bg); }
.node.next { background: var(--accent); color: #2a1c00; }
.node:disabled { border-color: var(--line); box-shadow: 0 5px 0 var(--line); background: var(--soft); opacity: .8; }

.card-row { display: grid; grid-template-columns: 1fr 1.5fr 96px; gap: 10px; align-items: baseline; padding: 8px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.card-row small { text-align: right; }
.level-new { color: var(--muted); }
.level-learning { color: var(--bad); }
.level-familiar { color: var(--text); }
.level-mastered { color: var(--good); font-weight: 700; }

label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
label.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 400; }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; accent-color: var(--primary); flex: none; }
input[type=text], input[type=email], input[type=password], select, textarea { width: 100%; padding: 10px 12px; border-radius: 10px; border: 2px solid var(--text); background: var(--surface); font-weight: 400; }
textarea { resize: vertical; }
.icon-picker { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.icon-picker button { padding: 6px; border: 2px solid transparent; border-radius: 10px; background: none; line-height: 0; }
.icon-picker button.on { border-color: var(--text); background: var(--soft); }

.chart { display: flex; align-items: flex-end; gap: 4px; height: 150px; margin-bottom: 8px; }
.chart .col { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; font-size: .72rem; }
.chart .col span { width: 100%; min-height: 6px; border-radius: 4px 4px 0 0; background: var(--soft); border: 2px solid var(--text); border-bottom: 0; }
.chart .col span.met { background: var(--primary); }
.chart .col span.none { min-height: 2px; height: 2px; border: 0; background: var(--line); }
.deck-line { display: grid; grid-template-columns: 1.4fr 1fr auto; gap: 10px; align-items: center; padding: 6px 0; }
.badge-grid { display: grid; gap: 16px 8px; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.badge { display: flex; flex-direction: column; align-items: center; text-align: center; line-height: 1.3; }
.badge:not(.on) .icon { filter: grayscale(1); opacity: .4; }
.badge:not(.on) b, .badge small { color: var(--muted); }

/* ---------- playing ---------- */
.play { max-width: 600px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.play.wide { max-width: 780px; }
.play-top { display: flex; align-items: center; gap: 14px; }
.play-top .back-link { align-self: center; }
.hearts { display: inline-flex; gap: 2px; }
.stage { min-height: 250px; }
.question { display: flex; flex-direction: column; gap: 10px; }
.ask-label { color: var(--muted); font-size: .9rem; }
.prompt { font-size: 1.6rem; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.intro { text-align: center; padding: 32px 16px; border: 2px solid var(--text); }
.options { display: grid; gap: 10px; }
.options.tiles { grid-template-columns: 1fr 1fr; }
.option {
  display: flex; flex-direction: row; align-items: center; gap: 12px; text-align: left; width: 100%; font-weight: 400;
  padding: 11px 14px; border-radius: 10px; border: 2px solid var(--text); box-shadow: 0 3px 0 var(--text); margin-bottom: 3px; background: var(--surface); overflow-wrap: anywhere;
}
label.option { cursor: pointer; }
.option-text { flex: 1; min-width: 0; }
button.option:hover:not(:disabled) { background: var(--soft); }
.option .key { min-width: 24px; height: 24px; border-radius: 6px; background: var(--soft); display: grid; place-items: center; font-size: .8rem; font-weight: 700; }
.tiles .option { min-height: 84px; color: #fff; font-weight: 600; }
.tiles .o0 { background: #6a4391; }
.tiles .o1 { background: #1d6b70; }
.tiles .o2 { background: #2f4f8c; }
.tiles .o3 { background: #98395a; }
.tiles button.option:hover:not(:disabled) { filter: brightness(1.14); }
.tiles .o0:hover:not(:disabled) { background: #6a4391; }
.tiles .o1:hover:not(:disabled) { background: #1d6b70; }
.tiles .o2:hover:not(:disabled) { background: #2f4f8c; }
.tiles .o3:hover:not(:disabled) { background: #98395a; }
.letter { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: #fffaf0; color: #24201a; border: 2px solid #24201a; font-weight: 700; }
.option.right, .tiles .option.right { background: var(--good-bg); border-color: var(--good); box-shadow: 0 3px 0 var(--good); color: var(--good); font-weight: 700; }
.option.wrong, .tiles .option.wrong { background: var(--bad-bg); border-color: var(--bad); box-shadow: 0 3px 0 var(--bad); color: var(--bad); }
.option.dim { opacity: .4; }
.answer-input.right { border-color: var(--good); background: var(--good-bg); }
.answer-input.wrong { border-color: var(--bad); background: var(--bad-bg); }

.feedback { display: flex; align-items: center; justify-content: flex-end; gap: 12px; min-height: 66px; padding: 10px 14px; border-radius: 10px; }
.feedback.good { background: var(--good-bg); color: var(--good); }
.feedback.bad { background: var(--bad-bg); color: var(--bad); }
.feedback small { display: block; }
.feedback .btn { color: var(--on-primary); }

.question .prompt { font-size: 1.4rem; }
.intro hr { border: 0; border-top: 1.5px solid var(--line); margin: 14px 40px; }
.intro-def { font-size: 1.25rem; }

/* Flashcards: an index card on a pile. The answer side is a different color and gets stamped. */
.pile { position: relative; perspective: 1300px; margin: 14px 0 4px; }
.under { position: absolute; inset: 0; border: 2px solid var(--text); border-radius: 16px; background: var(--surface); }
.under.one { transform: translateY(7px) rotate(1.2deg); }
.under.two { transform: translateY(13px) rotate(-1.6deg); background: var(--soft); }
.flashcard { position: relative; z-index: 1; cursor: pointer; touch-action: pan-y; user-select: none; -webkit-user-select: none; border-radius: 16px; }
.flipper { display: grid; transform-style: preserve-3d; }
.flashcard.flipped .flipper { transform: rotateY(180deg); }
.face {
  grid-area: 1 / 1; min-height: 290px; display: flex; flex-direction: column; justify-content: space-between; align-items: center; gap: 14px;
  padding: 18px 22px; text-align: center; border: 2px solid var(--text); border-radius: 16px; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden;
}
.face.front { background: var(--surface) repeating-linear-gradient(transparent 0 35px, var(--line) 35px 36px); }
.face.back { transform: rotateY(180deg); position: relative; background: var(--primary); color: var(--on-primary); }
.face.back::after { content: ""; position: absolute; inset: 9px; border: 2px dashed currentColor; border-radius: 10px; opacity: .45; pointer-events: none; }
.face .prompt { font-size: 1.75rem; }
.side-tab { align-self: flex-start; font-weight: 700; padding: 2px 12px; border: 2px solid var(--text); border-radius: 6px; background: var(--accent); color: #2a1c00; }
.face.back .side-tab { background: var(--surface); color: var(--text); }
.hint { font-size: .9rem; color: var(--muted); background: var(--surface); padding: 0 8px; border-radius: 4px; }
.face.back .hint { background: none; color: inherit; opacity: .85; }
.stamp { position: absolute; top: 18px; right: 20px; padding: 2px 14px; border: 4px solid var(--accent); border-radius: 8px; color: var(--accent); font: 800 1.3rem/1.4 "Avenir Next", system-ui, sans-serif; letter-spacing: .12em; text-transform: uppercase; transform: rotate(10deg); }
.flashcard.landed .stamp { animation: slam .34s cubic-bezier(.2, .9, .3, 1.5) both; }
@keyframes slam { from { transform: rotate(-8deg) scale(2.8); opacity: 0; } to { transform: rotate(10deg) scale(1); opacity: 1; } }
.ink { position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; border: 2px solid var(--text); border-radius: 50% 50% 46% 54%; background: var(--accent); pointer-events: none; }
.ink1 { width: 13px; height: 13px; background: var(--primary); }
.ink2 { width: 16px; height: 16px; background: var(--surface); }
.verdict { position: absolute; z-index: 2; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(-9deg); padding: 4px 20px; border: 4px solid; border-radius: 10px; font-weight: 800; font-size: 1.8rem; white-space: nowrap; background: var(--surface); opacity: 0; pointer-events: none; }
.verdict.show { opacity: 1; }
.verdict.yes { color: var(--good); }
.verdict.no { color: var(--bad); }
.sides { display: grid; grid-template-columns: 1fr 1fr; margin-top: 8px; border: 2px solid var(--text); border-radius: 10px; overflow: hidden; text-align: center; font-size: .9rem; color: var(--muted); }
.sides span { padding: 5px; transition: background .2s; }
.sides span.on { background: var(--text); color: var(--bg); font-weight: 700; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.match-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.tile { min-height: 92px; padding: 8px; border-radius: 10px; border: 2px solid var(--text); box-shadow: 0 3px 0 var(--text); background: var(--surface); overflow-wrap: anywhere; line-height: 1.3; }
.tile.picked { background: var(--accent); color: #2a1c00; font-weight: 600; }
.tile.wrong { border-color: var(--bad); background: var(--bad-bg); }
.tile.gone { visibility: hidden; }

.big-number { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.seconds { min-width: 36px; text-align: right; font-variant-numeric: tabular-nums; }
.rivals { display: flex; gap: 24px; flex-wrap: wrap; }
.rivals > div { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.board .rank { display: grid; grid-template-columns: 20px 36px 1fr auto 56px; gap: 8px; align-items: center; padding: 4px 6px; border-radius: 8px; }
.board .rank > b:last-child { text-align: right; }
.board .rank.you, .racer.you { background: var(--soft); }
.hud-side { display: flex; flex-direction: column; align-items: flex-end; font-size: .85rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rush { display: grid; grid-template-columns: 1fr 270px; gap: 18px; align-items: start; }
.rush .option { padding: 8px 12px; }
.flash { min-height: 48px; margin-top: 6px; padding: 10px 12px; border-radius: 10px; font-weight: 600; }
.flash.good { background: var(--good-bg); color: var(--good); }
.flash.bad { background: var(--bad-bg); color: var(--bad); }
.shop-grid { display: grid; gap: 8px; }
.buy { display: flex; flex-direction: column; text-align: left; padding: 6px 10px; border-radius: 10px; border: 2px solid var(--text); box-shadow: 0 3px 0 var(--text); margin-bottom: 3px; background: var(--surface); line-height: 1.3; }
.buy b { display: flex; align-items: center; gap: 4px; font-size: .9rem; }
.buy small { color: var(--muted); }
.buy:disabled { border-color: var(--line); box-shadow: 0 3px 0 var(--line); }
.buy.on { border-color: var(--good); background: var(--good-bg); }
.racers { padding: 8px; }
.racer { display: grid; grid-template-columns: 30px 52px 1fr 56px; gap: 6px; align-items: center; padding: 3px; border-radius: 8px; font-size: .85rem; }
.racer > span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.racer small { text-align: right; }

/* ---------- Reef Climb ---------- */
.climb { gap: 10px; }
.climb-stage { position: relative; align-self: center; width: min(100%, 400px, max(280px, calc((100vh - 250px) * .769))); }
.climb-canvas { display: block; width: 100%; height: auto; border: 2px solid var(--text); border-radius: 12px; }
.climb-panel { position: absolute; inset: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 14px; background: var(--surface); border: 2px solid var(--text); border-radius: 12px; }
.climb-panel.hidden { display: none; }
.climb-panel .btn.big { flex: none; position: sticky; bottom: 0; margin-top: auto; }
.climb-panel .btn.big:disabled { opacity: 1; background: var(--soft); color: var(--muted); border-color: var(--line); box-shadow: 0 3px 0 var(--line); }
.climb-panel .option { padding: 7px 12px; }
.pads { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 10px; width: min(100%, 400px); align-self: center; }
.pad { padding: 12px 0; touch-action: none; user-select: none; -webkit-user-select: none; }

/* ---------- Tide Pool ---------- */
.pool { position: relative; height: 250px; overflow: hidden; border: 2px solid var(--text); border-radius: 12px; background: #cfe8ee; }
.pool-water { position: absolute; left: 0; right: 0; bottom: 0; height: 45%; background: #4f9bb8; border-top: 3px solid #24201a; }
.pool-pier { position: absolute; left: 0; bottom: 30%; width: 38%; height: 30px; background: #b98a5c; border: 3px solid #24201a; border-left: 0; border-radius: 0 6px 6px 0; }
.pool-mascot { position: absolute; left: 6%; bottom: calc(30% + 14px); }
.pool-line { position: absolute; left: calc(6% + 99px); width: calc(64% - 88px); top: 108px; height: 31px; line-height: 0; }
.bobber { position: absolute; left: 70%; bottom: 40%; width: 22px; height: 22px; border-radius: 50%; border: 3px solid #24201a; background: linear-gradient(#e8674a 50%, #fffaf0 50%); animation: bob 1.4s ease-in-out infinite; }
.bobber.hidden { display: none; }
.bobber.bite { animation: bite .22s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(5px); } }
@keyframes bite { 50% { transform: translateY(20px) scale(.85); } }
.creatures { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.creature { display: flex; flex-direction: column; align-items: center; line-height: 1.25; }
.creature small { color: var(--muted); }
.creature:not(.on) .icon { filter: grayscale(1); opacity: .3; }

/* ---------- Jot ---------- */
.mascot svg { overflow: visible; }
.jot-bob { animation: jot-bob 2.4s ease-in-out infinite; }
.jot-blink { animation: jot-blink 3.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.jot-hop { animation: jot-hop 1.15s ease-in-out infinite; transform-origin: 120px 227px; }
.jot-wave { animation: jot-wave .7s ease-in-out infinite; transform-origin: 120px 126px; }
.jot-breathe { animation: jot-breathe 2.6s ease-in-out infinite; transform-origin: 120px 234px; }
.jot-twinkle { animation: jot-twinkle .9s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.jot-pop { animation: jot-pop 1.15s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.jot-rise { animation: jot-rise 1.8s ease-in-out infinite; }
@keyframes jot-bob { 50% { transform: translateY(-7px); } }
@keyframes jot-blink { 0%, 90%, 100% { transform: scaleY(1); } 94% { transform: scaleY(.08); } }
@keyframes jot-hop { 0%, 100% { transform: translateY(0) scale(1, 1); } 16% { transform: translateY(2px) scale(1.07, .9); } 46% { transform: translateY(-30px) scale(.94, 1.08); } 70% { transform: translateY(0) scale(1.06, .92); } 84% { transform: translateY(-3px) scale(.98, 1.02); } }
@keyframes jot-wave { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
@keyframes jot-breathe { 50% { transform: scale(1.012, .985); } }
@keyframes jot-twinkle { 0%, 100% { transform: scale(.8) rotate(-8deg); } 50% { transform: scale(1.15) rotate(8deg); } }
@keyframes jot-pop { 0%, 15%, 100% { transform: scale(.3); opacity: 0; } 50% { transform: scale(1.15); opacity: 1; } 80% { transform: scale(1); opacity: 1; } }
@keyframes jot-rise { 0% { transform: translateY(6px); opacity: 0; } 40% { opacity: 1; } 100% { transform: translateY(-14px); opacity: 0; } }
.react { flex: none; align-self: flex-end; line-height: 0; margin: -22px 0 -6px; }
.homes { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 12px 4px; text-align: center; }
.home .mascot svg { width: 100%; max-width: 112px; height: auto; }
.home { display: flex; flex-direction: column; align-items: center; line-height: 1.3; }
.home small { color: var(--muted); }
.home.locked .mascot { filter: grayscale(1); opacity: .5; }
.home.now b { background: var(--accent); color: #2a1c00; padding: 0 8px; border-radius: 6px; }

/* ---------- results, dialogs, effects ---------- */
.results { max-width: 600px; margin: 0 auto; }
.rewards { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 24px; font-weight: 700; font-size: 1.1rem; }
.news { padding: 5px 0; }
.missed { padding: 8px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.missed > div { display: flex; justify-content: space-between; gap: 12px; }
.missed > div > * { min-width: 0; }
.missed small { color: var(--bad); }

.veil { position: fixed; inset: 0; z-index: 20; background: rgba(20, 16, 10, .6); display: grid; place-items: center; padding: 16px; }
.dialog { max-width: 400px; width: 100%; border: 2px solid var(--text); }
#toasts { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; gap: 6px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; text-align: center; }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 25; }
.confetti i { position: absolute; top: -30px; line-height: 0; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

/* Subject library and uploads */
.lib-row { display: flex; align-items: center; gap: 8px; padding-right: 12px; }
.lib-row + .lib-row { border-top: 1.5px solid var(--line); }
.lib-row .link-row { flex: 1; min-width: 0; gap: 10px; padding-right: 4px; }
/* The button beside each deck already shows what the row does. */
.lib-row .link-row > :last-child { display: none; }
@media (max-width: 340px) { .lib-row .link-row > :first-child { display: none; } }
.lib-row.added { background: var(--soft); }
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 22px 16px; border: 2px dashed var(--text); border-radius: 12px; background: var(--surface); }
.dropzone.over { background: var(--soft); border-style: solid; }
.status { font-weight: 600; }
.status:empty { display: none; }
.source { max-height: 220px; overflow: auto; margin-top: 8px; padding: 12px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface); font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; }

@media (max-width: 719px) {
  .rush { grid-template-columns: 1fr; }
  .rush .stage { min-height: 0; }
  .shop-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .buy { padding: 5px 6px; font-size: .82rem; }
  .buy b { font-size: .82rem; }
  .match-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
}
@media (max-width: 520px) {
  .climb-panel > p { display: none; }
  .climb-panel .question .prompt { font-size: 1.15rem; }
  .wardrobe { gap: 10px; padding: 10px; }
  .wardrobe-stage { width: 118px; }
  .wardrobe-info .bar { width: 100%; }
  .options.tiles { grid-template-columns: 1fr; }
  .tiles .option { min-height: 56px; }
  .card-row { grid-template-columns: 1fr 1fr; }
  .card-row small { grid-column: 2; }
  .deck-line { grid-template-columns: 1fr 70px auto; }
  /* The button drops to its own line so Jot and the answer have room. */
  .feedback { flex-wrap: wrap; }
  .feedback .grow { flex: 1 1 0; min-width: 0; }
  .feedback .btn { flex: 1 1 100%; }
}
/* Keyboard hints are useless on touch screens. */
@media (pointer: coarse) { .keys, .option .key { display: none; } }
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- front door and account ---------- */
body.door { padding-bottom: 24px; }
body.door .top, body.door nav { display: none; }
body.door:not(.focus) main { max-width: 900px; margin: 0 auto; }
.gate-layout { display: grid; gap: 16px; max-width: 440px; margin: 0 auto; }
.gate-hello { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
@media (max-width: 899px) {
  .gate-hello .mascot svg { width: 104px; height: auto; }
  .gate-hello p { display: none; }
}
.gate-card { border: 2px solid var(--text); }
.field { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 0 4px; }
.field small { grid-column: 1 / -1; margin-top: 4px; }
.form-error { color: var(--bad); font-weight: 600; margin: 0; }
.form-error:empty { display: none; }
label.check input { align-self: flex-start; margin-top: 3px; }
.guest { display: flex; flex-direction: column; align-items: center; border-top: 1.5px solid var(--line); padding-top: 10px; }
.legal-links { display: flex; justify-content: center; gap: 18px; margin: 0; }
a { color: var(--primary); text-underline-offset: 3px; }
.held { display: grid; grid-template-columns: fit-content(38%) minmax(0, 1fr); gap: 6px 14px; margin: 0; }
.held dt { color: var(--muted); }
.held dd { margin: 0; overflow-wrap: anywhere; }
.cookie-note {
  position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 15; max-width: 620px; margin: 0 auto; display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; background: var(--surface); border: 2px solid var(--text); border-radius: 12px; font-size: .9rem;
}
.cookie-note p { flex: 1; margin: 0; }
body:not(.door):not(.focus) .cookie-note { bottom: calc(86px + env(safe-area-inset-bottom)); }
body.focus .cookie-note { display: none; }

@media (min-width: 900px) {
  .gate-layout { max-width: none; grid-template-columns: 1fr 420px; align-items: center; column-gap: 48px; padding-top: 40px; }
  .gate-hello p { max-width: 320px; font-size: 1.1rem; }
  .gate-layout .legal-links { grid-column: 1 / -1; }
  body:not(.door):not(.focus) .cookie-note { bottom: 12px; }
}

/* Policy pages */
body.doc { padding-bottom: 32px; }
body.doc h1 { margin: 12px 0 4px; }
body.doc h2 { margin: 22px 0 6px; }
body.doc li { margin: 3px 0; }

/* ---------- phones: thumbs, notches and no hover ---------- */
button { touch-action: manipulation; }
.pad, .climb-panel .pad { touch-action: none; }
body { padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
nav { padding-bottom: calc(6px + env(safe-area-inset-bottom)); padding-left: max(4px, env(safe-area-inset-left)); padding-right: max(4px, env(safe-area-inset-right)); }
.touch { display: none; }
@media (pointer: coarse) {
  .touch { display: block; }
  .btn { min-height: 44px; }
  .btn.small { min-height: 40px; }
  .top-stat, .brand { min-height: 44px; min-width: 44px; justify-content: center; }
  .legal-links a { display: inline-block; padding: 10px 6px; }
  .back-link, .tabs button { min-height: 40px; }
  input[type=text], input[type=email], input[type=password], select { min-height: 46px; }
  input[type=checkbox], input[type=radio] { width: 22px; height: 22px; }
}

/* ---------- desktop: use the width, drop the on-screen game pad ---------- */
.home-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@media (min-width: 900px) {
  body { padding-bottom: 24px; }
  nav { padding: 16px 10px; }
}
@media (min-width: 1100px) {
  body[data-route="home"]:not(.focus) main,
  body[data-route="progress"]:not(.focus) main,
  body[data-route="shop"]:not(.focus) main { max-width: 980px; margin-left: max(210px, calc(50% - 490px)); }
  .stack.home-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; }
  .home-grid > .hero { grid-column: 1 / -1; }
}
@media (hover: hover) and (pointer: fine) {
  .pads { display: none; }
}
body.door { padding-bottom: 24px; }
body.focus { padding-bottom: 24px; }
body.doc { padding-bottom: 32px; }
