/* Design tokens ---------------------------------------------------------- */
:root {
  --ink: #1f2348;
  --ink-soft: #4b5082;
  --paper: #fff9ef;
  --card: #ffffff;
  --line: #e9e1d2;
  --coral: #ff6b57;
  --coral-dark: #e2503d;
  --sun: #ffc93c;
  --mint: #2ec4a0;
  --mint-dark: #0e7a62;
  --sky: #59b7ff;
  --plum: #6a48d6;
  --coral-text: #c93f2c; /* WCAG AA on white/paper */
  --btn-coral: #c93f2c; --btn-coral-dark: #9e2f20;
  --btn-mint: #0e7a62; --btn-mint-dark: #095644;
  --rose: #ff8fb1;
  --bad: #b8262c;
  --good: #0e7a62;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 6px 0 rgba(31, 35, 72, 0.08), 0 12px 28px rgba(31, 35, 72, 0.08);
  --shadow-press: 0 2px 0 rgba(31, 35, 72, 0.12);
  --font: ui-rounded, system-ui, sans-serif;
  --mono: ui-monospace, monospace;
  --box0: #ece6da; --box1: #ffb3a7; --box2: #ffd38a; --box3: #c9ec9b; --box4: #7fd9b9; --box5: #2ec4a0;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--ink); background: var(--paper);
  background-image: radial-gradient(circle at 12% 8%, #ffe9c7 0, transparent 32%),
    radial-gradient(circle at 92% 18%, #e2f6ef 0, transparent 30%);
  background-attachment: fixed; line-height: 1.5; font-size: 17px;
}
body.large-text { font-size: 20px; }
a { color: var(--plum); }
img, svg { max-width: 100%; }
:focus-visible { outline: 3px solid var(--sky); outline-offset: 3px; border-radius: 6px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header ------------------------------------------------------------------ */
.site-header {
  position: sticky; top: 0; z-index: 20; backdrop-filter: blur(10px);
  background: rgba(255, 249, 239, 0.86); border-bottom: 1px solid var(--line);
}
.site-header .inner { max-width: 1120px; margin: 0 auto; display: flex; align-items: center; gap: 16px; padding: 10px 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.25rem; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.wordmark { font-weight: 900; font-size: 1.4rem; letter-spacing: -0.02em; color: var(--ink); }
.wordmark span { color: var(--ink-soft); font-weight: 700; }
.test-badge { font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--ink); background: var(--sun); border-radius: 999px; padding: 3px 9px; }
.test-line { margin: 0; text-align: center; font-size: .82rem; font-weight: 700; color: var(--ink); background: #fff2c9; padding: 5px 16px; border-top: 1px solid var(--line); }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 800; }
.skip-link:focus { top: 10px; }
.site-footer p { margin: 6px 0; }
.feedback-link { font-weight: 800; }
.licence-wrap { overflow-x: auto; max-width: 100%; }
.licence-table { width: 100%; border-collapse: collapse; }
.licence-table td { overflow-wrap: anywhere; }
@media (max-width: 560px) { .licence-table, .licence-table tbody, .licence-table tr, .licence-table td { display: block; } .licence-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); } .licence-table tr { border-bottom: 1px solid var(--line); padding: 6px 0; } .licence-table td { border: 0; padding: 3px 4px; } }
.licence-table th, .licence-table td { text-align: left; vertical-align: top; padding: 8px 10px; border-bottom: 1px solid var(--line); }
ul.facts li { margin-bottom: 8px; }
.brand small { display: block; font-size: 0.62rem; font-weight: 700; color: var(--coral-text); letter-spacing: 0.08em; text-transform: uppercase; margin-top: -4px; }
.nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.nav a { padding: 8px 14px; border-radius: 999px; text-decoration: none; color: var(--ink-soft); font-weight: 700; font-size: 0.95rem; }
.nav a:hover { background: #fff; color: var(--ink); }
.nav a[aria-current="page"] { background: var(--ink); color: #fff; }
.icon-btn { border: 0; background: #fff; border-radius: 999px; width: 42px; height: 42px; display: grid; place-items: center; cursor: pointer; box-shadow: var(--shadow-press); font-size: 1.2rem; }

main { max-width: 1120px; margin: 0 auto; padding: 24px 20px 64px; }
footer.site-footer { text-align: center; color: var(--ink-soft); font-size: 0.85rem; padding: 24px 20px 40px; }

/* Typography -------------------------------------------------------------- */
h1, h2, h3 { line-height: 1.15; letter-spacing: -0.015em; margin: 0 0 0.4em; }
h1 { font-size: clamp(2rem, 4.4vw, 3.2rem); font-weight: 900; }
h2 { font-size: clamp(1.4rem, 2.6vw, 1.9rem); font-weight: 850; }
h3, h2.h3 { font-size: 1.2rem; font-weight: 800; }
/* Until the shared header is in place, keep the page invisible so nothing jumps (CLS). Fallback reveal after 1.5 s. */
body.pending > main { visibility: hidden; animation: reveal 0s 1.5s forwards; }
@keyframes reveal { to { visibility: visible; } }
.lead { font-size: 1.15rem; color: var(--ink-soft); max-width: 60ch; }
.eyebrow { font-weight: 800; color: var(--coral-text); text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.8rem; }

/* Buttons ----------------------------------------------------------------- */
.btn {
  --bg: var(--btn-coral); --bg-dark: var(--btn-coral-dark);
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  border: 0; border-radius: 999px; padding: 14px 26px; font: inherit; font-weight: 800; font-size: 1.05rem;
  background: var(--bg); color: #fff; cursor: pointer; text-decoration: none;
  box-shadow: 0 5px 0 var(--bg-dark); transform: translateY(0); transition: transform .08s, box-shadow .08s;
}
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--bg-dark); }
.btn.mint { --bg: var(--btn-mint); --bg-dark: var(--btn-mint-dark); }
.btn.ink { --bg: var(--ink); --bg-dark: #0d1030; }
.btn.plum { --bg: var(--plum); --bg-dark: #4f32ad; }
.btn.ghost { background: #fff; color: var(--ink); box-shadow: 0 5px 0 var(--line); }
.btn.small { padding: 9px 16px; font-size: 0.95rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

/* Cards / layout ---------------------------------------------------------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.section { margin-top: 44px; }
.pill { display: inline-block; padding: 4px 12px; border-radius: 999px; background: #fff3dc; color: #8a5208; font-weight: 800; font-size: 0.8rem; }
.muted { color: var(--ink-soft); }

/* Hero -------------------------------------------------------------------- */
.hero { display: grid; grid-template-columns: 1.3fr 1fr; gap: 28px; align-items: center; }
.hero .mascot-wrap { position: relative; display: grid; place-items: center; }
.hero .mascot-wrap .bubble { position: absolute; top: 10%; left: 0; background: #fff; border-radius: 18px; padding: 10px 16px; font-weight: 800; box-shadow: var(--shadow); transform: rotate(-4deg); }
.hero .mascot-wrap svg { width: min(340px, 90%); filter: drop-shadow(0 18px 18px rgba(31,35,72,.12)); }
@media (max-width: 760px) { .hero { grid-template-columns: 1fr; } .hero .mascot-wrap { order: -1; } .hero .mascot-wrap svg { width: 200px; } }

/* Table picker ------------------------------------------------------------ */
.picker { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-width: 52px; height: 52px; border-radius: 16px; border: 2px solid var(--line); background: #fff; font: inherit;
  font-weight: 900; font-size: 1.15rem; color: var(--ink); cursor: pointer; transition: transform .1s;
}
.chip:hover { transform: translateY(-2px); }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); box-shadow: 0 4px 0 #0d1030; }
.chip.all { padding: 0 14px; font-size: .95rem; }

/* Table cards ------------------------------------------------------------- */
.table-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px; }
.table-card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 18px 10px 14px;
  border-radius: var(--radius); background: #fff; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); transition: transform .12s;
}
.table-card:hover { transform: translateY(-4px) rotate(-1deg); }
.table-card .num { font-size: 2.3rem; font-weight: 900; line-height: 1; }
.table-card .label { font-weight: 700; color: var(--ink-soft); font-size: .9rem; }
.ring { width: 64px; height: 64px; }
.table-card .ring-wrap { position: relative; display: grid; place-items: center; }
.table-card .ring-wrap .num { position: absolute; font-size: 1.6rem; }

/* Game cards -------------------------------------------------------------- */
.game-card { display: flex; flex-direction: column; overflow: hidden; padding: 0; text-decoration: none; color: var(--ink); transition: transform .12s; }
.game-card:hover { transform: translateY(-4px); }
.game-card .art { height: 150px; display: block; }
.game-card .body { padding: 16px 18px 20px; }
.game-card .body p { margin: 4px 0 0; color: var(--ink-soft); font-size: .95rem; }

/* Heatmap ----------------------------------------------------------------- */
.heatmap { display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 3px; max-width: 620px; font-size: .78rem; }
.heatmap .h { display: grid; place-items: center; font-weight: 900; color: var(--ink-soft); aspect-ratio: 1; }
.heatmap .c { aspect-ratio: 1; border-radius: 6px; display: grid; place-items: center; font-weight: 700; color: var(--ink); background: var(--box0); border: 0; font: inherit; font-size: .72rem; cursor: default; }
.heatmap .c[data-box="1"] { background: var(--box1); } .heatmap .c[data-box="2"] { background: var(--box2); }
.heatmap .c[data-box="3"] { background: var(--box3); } .heatmap .c[data-box="4"] { background: var(--box4); }
.heatmap .c[data-box="5"] { background: var(--box5); color: var(--ink); }
.heatmap .c.hl { outline: 3px solid var(--ink); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .85rem; color: var(--ink-soft); margin-top: 10px; }
.legend span::before { content: ""; display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: 6px; background: var(--c); }

/* Practice ---------------------------------------------------------------- */
.practice { max-width: 760px; margin: 0 auto; }
.stage { position: relative; text-align: center; padding: 28px 24px 30px; overflow: hidden; }
.stage .meta { display: flex; justify-content: space-between; font-weight: 800; color: var(--ink-soft); }
.progressbar { height: 12px; background: #f1ebdf; border-radius: 999px; overflow: hidden; margin: 12px 0 8px; }
.progressbar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--mint), var(--sky)); border-radius: 999px; transition: width .3s; }
.question { font-size: clamp(3rem, 10vw, 5.4rem); font-weight: 900; letter-spacing: -0.02em; margin: 18px 0 6px; font-variant-numeric: tabular-nums; }
.question .ans { display: inline-block; min-width: 2.2ch; padding: 0 .2em; border-bottom: 6px solid var(--line); color: var(--plum); }
.feedback { min-height: 3.2em; font-weight: 800; font-size: 1.1rem; }
.feedback.good { color: var(--good); } .feedback.bad { color: var(--bad); }
.feedback .hint { display: block; font-weight: 600; color: var(--ink-soft); font-size: 1rem; margin-top: 2px; }
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 340px; margin: 10px auto 0; }
.numpad button {
  height: 64px; border: 0; border-radius: 16px; background: #fff; font: inherit; font-weight: 900; font-size: 1.6rem; color: var(--ink);
  box-shadow: 0 5px 0 var(--line), 0 0 0 2px var(--line) inset; cursor: pointer;
}
.numpad button:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--line), 0 0 0 2px var(--line) inset; }
.numpad .ok { background: var(--mint); color: #fff; box-shadow: 0 5px 0 var(--mint-dark); }
.numpad .back { background: #fff3dc; }
.choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; max-width: 420px; margin: 14px auto 0; }
.choices button { height: 78px; border-radius: 18px; border: 0; font: inherit; font-weight: 900; font-size: 2rem; color: #fff; cursor: pointer; box-shadow: 0 6px 0 rgba(0,0,0,.18); }
.choices button:nth-child(1) { background: var(--sky); } .choices button:nth-child(2) { background: var(--plum); }
.choices button:nth-child(3) { background: var(--coral); } .choices button:nth-child(4) { background: var(--mint); }
.choices button.wrong { opacity: .35; } .choices button.right { outline: 5px solid var(--ink); }
.toggle-group { display: inline-flex; flex-wrap: wrap; background: #f1ebdf; border-radius: 22px; padding: 4px; max-width: 100%; }
.toggle-group button { border: 0; background: transparent; font: inherit; font-weight: 800; padding: 8px 16px; border-radius: 999px; cursor: pointer; color: var(--ink-soft); }
.toggle-group button[aria-pressed="true"] { background: #fff; color: var(--ink); box-shadow: var(--shadow-press); }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.pop { animation: pop .35s; }
@keyframes pop { 50% { transform: scale(1.12); } }

/* Results ----------------------------------------------------------------- */
.results { text-align: center; }
.stars { font-size: 3.2rem; letter-spacing: .1em; }
.stars .off { filter: grayscale(1); opacity: .25; }
.mistake-list { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.mistake-list li { background: #ffeceb; color: var(--bad); padding: 6px 12px; border-radius: 12px; font-weight: 800; }
.stat-row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin: 16px 0; }
.stat { background: #fff8ea; border-radius: 16px; padding: 12px 18px; min-width: 120px; }
.stat b { display: block; font-size: 1.8rem; }

/* Table page -------------------------------------------------------------- */
.steps { display: flex; gap: 8px; flex-wrap: wrap; margin: 18px 0; }
.steps button {
  display: flex; align-items: center; gap: 8px; border: 2px solid var(--line); background: #fff; font: inherit; font-weight: 800;
  padding: 10px 16px; border-radius: 999px; cursor: pointer; color: var(--ink-soft);
}
.steps button .n { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: #f1ebdf; color: var(--ink); font-size: .85rem; }
.steps button[aria-selected="true"] { border-color: var(--ink); color: var(--ink); }
.steps button[aria-selected="true"] .n { background: var(--ink); color: #fff; }
.steps button.done .n { background: var(--mint); color: #fff; }
.facts-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.fact-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: #fff8ea; border-radius: 14px; padding: 10px 14px; font-weight: 800; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.fact-row input { width: 76px; height: 46px; border-radius: 12px; border: 2px solid var(--line); font: inherit; font-weight: 900; text-align: center; font-size: 1.25rem; color: var(--ink); background: #fff; }
.fact-row input.ok { border-color: var(--mint); background: #e6faf3; }
.fact-row input.no { border-color: var(--bad); background: #ffeceb; }
.fact-row .dots { display: grid; gap: 2px; }
.fact-row .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--coral); display: block; }
.fact-row.look { cursor: pointer; transition: background .15s; }
.fact-row.look:hover, .fact-row.look.active { background: #ffe3cc; }
.dot-stage { min-height: 140px; display: grid; place-items: center; margin-top: 16px; }
.dot-stage .grid-dots { display: grid; gap: 6px; }
.dot-stage .grid-dots i { width: 16px; height: 16px; border-radius: 50%; background: var(--coral); display: block; animation: pop .3s backwards; }
.dot-stage .grid-dots i:nth-child(odd) { background: var(--plum); }

/* Drag-to-match ------------------------------------------------------------ */
.match { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.slots, .tiles { display: grid; gap: 10px; align-content: start; }
.slot { display: flex; align-items: center; justify-content: space-between; background: #fff8ea; border-radius: 14px; padding: 8px 10px 8px 16px; font-weight: 800; font-size: 1.2rem; }
.slot .drop { font: inherit; font-size: 1.2rem; color: var(--ink); background: #fff; cursor: pointer; width: 76px; height: 48px; border-radius: 12px; border: 3px dashed var(--line); display: grid; place-items: center; font-weight: 900; }
.slot .drop.filled { border-style: solid; border-color: var(--sky); background: #eaf6ff; }
.slot .drop.ok { border-color: var(--mint); background: #e6faf3; }
.slot .drop.no { border-color: var(--bad); background: #ffeceb; }
.slot .drop.over { border-color: var(--plum); background: #f1ecff; }
.tiles { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
.tile { height: 54px; border-radius: 14px; border: 0; background: var(--sun); color: var(--ink); font: inherit; font-weight: 900; font-size: 1.3rem; cursor: grab; box-shadow: 0 4px 0 #d9a21a; touch-action: none; user-select: none; }
.tile.selected { outline: 4px solid var(--plum); }
.tile.used { visibility: hidden; }
.tile.dragging { position: fixed; z-index: 100; pointer-events: none; transform: rotate(-4deg) scale(1.08); cursor: grabbing; }

/* Game shell -------------------------------------------------------------- */
.game-shell { max-width: 980px; margin: 0 auto; }
.game-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.game-top h1 { font-size: 1.8rem; margin: 0; }
.game-top .spacer { flex: 1; }
.hud { display: flex; gap: 10px; flex-wrap: wrap; }
.hud .badge { background: #fff; border-radius: 999px; padding: 6px 14px; font-weight: 900; box-shadow: var(--shadow-press); }
.canvas-wrap { position: relative; border-radius: 24px; overflow: hidden; box-shadow: var(--shadow); background: #bfe7ff; }
.canvas-wrap canvas { display: block; width: 100%; height: auto; touch-action: none; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(31, 35, 72, .45); backdrop-filter: blur(3px); }
.overlay .card { max-width: 440px; text-align: center; }
.overlay[hidden] { display: none; }
.lane-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.qbanner { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); background: #fff; border-radius: 999px; padding: 8px 26px; font-weight: 900; font-size: 1.8rem; box-shadow: var(--shadow); white-space: nowrap; }

/* Memory ------------------------------------------------------------------ */
.memory-board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; max-width: 640px; margin: 0 auto; }
.mcard { display: block; aspect-ratio: 6 / 5; border: 0; padding: 0; background: transparent; cursor: pointer; font: inherit; }
.mcard .inner { display: block; position: relative; width: 100%; height: 100%; }
/* 2D "flip": the back squeezes to zero width, then the front grows back (no 3D layers needed). */
.mcard .face { position: absolute; inset: 0; border-radius: 16px; display: grid; place-items: center; font-weight: 900; box-shadow: var(--shadow); overflow: hidden; transition: transform .16s ease-in; }
.mcard .back { background: var(--ink); transform: scaleX(1); transition-delay: .16s; }
.mcard .back svg { width: 100%; height: 100%; display: block; }
.mcard .front { transform: scaleX(0); transition-delay: 0s; background: #fff; font-size: clamp(1.2rem, 3.6vw, 2rem); color: var(--ink); }
.mcard.open .back, .mcard.matched .back { transform: scaleX(0); transition-delay: 0s; }
.mcard.open .front, .mcard.matched .front { transform: scaleX(1); transition-delay: .16s; transition-timing-function: ease-out; }
.mcard .front.answer { background: #fff3dc; color: var(--coral-dark); font-size: clamp(1.6rem, 5vw, 2.6rem); }
.mcard.matched .front { background: #e6faf3; color: var(--mint-dark); }
.mcard:hover .back { filter: brightness(1.15); }
.players { display: flex; gap: 12px; justify-content: center; margin: 12px 0 18px; }
.player { padding: 8px 18px; border-radius: 999px; background: #fff; font-weight: 900; box-shadow: var(--shadow-press); opacity: .55; }
.player.active { opacity: 1; outline: 3px solid var(--coral); }

/* Forms / misc ------------------------------------------------------------ */
textarea, input[type="text"] { width: 100%; font: inherit; border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #fff; color: var(--ink); }
textarea { min-height: 90px; font-family: var(--mono); font-size: .8rem; }
.tip { background: #f1ecff; border-radius: var(--radius); padding: 16px 20px; display: flex; gap: 14px; align-items: flex-start; }
.tip svg { flex: 0 0 56px; height: 56px; }
.big-timer { font-size: 2rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.confetti, .celebrate-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 200; }
.celebrate-calm { position: fixed; z-index: 200; pointer-events: none; transform: translate(-50%, -50%); font-size: 1.6rem; opacity: 0;
  filter: drop-shadow(0 0 10px rgba(255, 201, 60, .9)); animation: calm-glow .75s ease-in-out forwards; }
.celebrate-calm.big { font-size: 3.4rem; animation-duration: 1.3s; }
@keyframes calm-glow { 0% { opacity: 0; } 35% { opacity: 1; } 100% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; transition-duration: .001s !important; }
  /* The calm celebration only fades (no movement), so it keeps its timing. */
  .celebrate-calm { animation-duration: .75s !important; }
  .celebrate-calm.big { animation-duration: 1.3s !important; }
}
@media (max-width: 640px) {
  .nav a { padding: 6px 10px; font-size: .85rem; }
  .match { grid-template-columns: 1fr; }
  .site-header .inner { flex-wrap: wrap; }
}

/* ===================== v0.2 ============================================= */
/* Lexend (SIL OFL 1.1, bundled in fonts/) – readability option. */
@font-face { font-family: "Lexend"; src: url("../fonts/Lexend-Regular.woff2") format("woff2"); font-weight: 400 600; font-display: swap; }
@font-face { font-family: "Lexend"; src: url("../fonts/Lexend-Bold.woff2") format("woff2"); font-weight: 700 900; font-display: swap; }
body.font-lexend { --font: "Lexend", system-ui, sans-serif; letter-spacing: .01em; word-spacing: .06em; }
body.font-lexend, body.font-lexend button, body.font-lexend input, body.font-lexend select, body.font-lexend textarea { font-family: var(--font); }
.lexend-sample { font-family: "Lexend", system-ui, sans-serif; }
body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
body.reduce-motion .celebrate-calm { animation-duration: .75s !important; }
body.reduce-motion .celebrate-calm.big { animation-duration: 1.3s !important; }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

/* Header chip + icon buttons */
.profile-chip { display: inline-flex; align-items: center; gap: 6px; background: #fff; border-radius: 999px; padding: 3px 12px 3px 3px; text-decoration: none; color: var(--ink); font-weight: 800; box-shadow: var(--shadow-press); max-width: 160px; }
.profile-chip .chip-art { width: 34px; height: 34px; border-radius: 50%; background: #f1ecff; overflow: hidden; display: grid; place-items: center; flex: 0 0 34px; }
.profile-chip .chip-art svg { width: 34px; height: 34px; }
.profile-chip .chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
a.icon-btn { text-decoration: none; display: inline-grid; place-items: center; }

/* Toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 10px; z-index: 60; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 16px; box-shadow: var(--shadow); display: flex; gap: 12px; align-items: center; font-weight: 600; animation: toast-in .3s ease-out; }
.toast a { color: var(--sun); }
.toast-art { width: 52px; flex: 0 0 52px; }
@keyframes toast-in { from { transform: translateY(20px); opacity: 0; } }

/* Home hero mascot */
.hero-mascot { display: block; text-align: center; transition: transform .2s; }
.hero-mascot:hover { transform: rotate(-3deg) scale(1.03); }
.hero .mascot-wrap .dress { margin-top: 6px; }

/* Profiles */
.profile-card { display: flex; gap: 18px; align-items: center; border: 3px solid transparent; }
.profile-card.active { border-color: var(--mint); }
.profile-card h3 { margin: 0; }
.profile-card p { margin: 2px 0 10px; }
.pc-art { width: 96px; height: 96px; flex: 0 0 96px; border-radius: 50%; background: radial-gradient(circle at 50% 40%, #fff, #efe7ff); display: grid; place-items: center; overflow: hidden; }
.pc-art svg { width: 96px; height: 96px; }
.add-profile input[type=text] { max-width: 320px; }
.kind-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.kind-pick { border: 3px solid var(--line); background: #fff; border-radius: 18px; padding: 8px 12px 6px; cursor: pointer; display: grid; justify-items: center; gap: 2px; font: inherit; font-weight: 800; color: var(--ink); width: 118px; }
.kind-pick svg { width: 92px; height: 92px; }
.kind-pick[aria-pressed="true"] { border-color: var(--plum); background: #f6f2ff; box-shadow: 0 4px 0 #d9cdfb; }

/* Mascot studio */
.mascot-studio { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 20px; align-items: start; }
.studio-preview { text-align: center; position: sticky; top: 84px; background: radial-gradient(circle at 50% 35%, #fff 0, #fff 40%, #f1ecff 100%); }
.studio-preview h2 { margin: 6px 0 0; }
.preview-art svg { width: 100%; max-width: 280px; filter: drop-shadow(0 16px 14px rgba(31,35,72,.14)); }
@media (max-width: 760px) { .mascot-studio { grid-template-columns: 1fr; } .studio-preview { position: static; } }
.acc-slot h3 { margin: 14px 0 6px; font-size: 1rem; color: var(--ink-soft); }
.acc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.acc { position: relative; border: 3px solid var(--line); background: #fff; border-radius: 16px; padding: 6px 6px 8px; cursor: pointer; font: inherit; color: var(--ink); display: grid; justify-items: center; gap: 2px; }
.acc .acc-art svg { width: 84px; height: 84px; }
.acc .acc-name { font-weight: 800; font-size: .88rem; }
.acc.on { border-color: var(--mint); background: #eafaf5; box-shadow: 0 4px 0 #bfeedd; }
.acc.on::after { content: "✓"; position: absolute; top: 4px; right: 8px; color: var(--mint-dark); font-weight: 900; }
.acc.locked { cursor: not-allowed; background: #f7f5f0; }
.acc.locked .acc-art { filter: grayscale(1) opacity(.45); }
.acc-lock { font-size: .72rem; line-height: 1.2; color: var(--ink-soft); text-align: center; }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* Settings + worksheets */
.settings-head { display: flex; gap: 20px; align-items: center; }
.set-art { width: 110px; flex: 0 0 110px; }
.settings fieldset { border: 0; margin: 0; }
.settings legend { font-weight: 900; font-size: 1.15rem; padding: 0; margin-bottom: 8px; float: left; width: 100%; }
.radio { display: flex; align-items: center; gap: 10px; padding: 7px 0; font-weight: 600; cursor: pointer; }
.radio input { width: 20px; height: 20px; accent-color: var(--plum); }
.switch { display: inline-flex; align-items: center; gap: 12px; font-weight: 700; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch .slider { width: 52px; height: 30px; background: #d8d2c6; border-radius: 999px; position: relative; transition: background .2s; }
.switch .slider::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 2px 4px rgba(0,0,0,.2); }
.switch input:checked + .slider { background: var(--mint); }
.switch input:checked + .slider::after { transform: translateX(22px); }
.switch input:focus-visible + .slider { outline: 3px solid var(--sky); outline-offset: 2px; }
input[type=range] { width: 100%; accent-color: var(--plum); height: 28px; }
.pill.ok { background: #e3f8f1; color: var(--mint-dark); }
.pill.ok:empty { display: none; }
kbd { background: #fff; border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 6px; padding: 0 6px; font-family: var(--mono); font-size: .85em; }
.kid-privacy ul { padding-left: 1.2em; font-size: 1.05rem; }
.kid-privacy li { margin: 6px 0; }

/* Pause */
.pause-btn { order: 5; }
.game-top .pause-btn { margin-left: 4px; }

/* 3D games */
.g3d-wrap { background: #1f2348; aspect-ratio: 16 / 9; min-height: 360px; }
.g3d-wrap canvas { width: 100% !important; height: 100% !important; }
.g3d-banner { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); background: rgba(255,255,255,.94); color: var(--ink); padding: 8px 22px; border-radius: 16px; font-weight: 900; font-size: 1.6rem; box-shadow: 0 6px 0 rgba(0,0,0,.18); pointer-events: none; white-space: nowrap; z-index: 2; }
.g3d-banner:empty { display: none; }
.g3d-banner small { display: block; font-size: .8rem; font-weight: 700; color: var(--ink-soft); text-align: center; }
.g3d-side { position: absolute; top: 14px; right: 14px; display: grid; gap: 8px; z-index: 2; max-width: 240px; }
.g3d-side:empty { display: none; }
.g3d-side .panel { background: rgba(255,255,255,.94); border-radius: 14px; padding: 8px 12px; font-weight: 700; font-size: .9rem; box-shadow: 0 4px 0 rgba(0,0,0,.15); }
.g3d-side .panel h4 { margin: 0 0 4px; font-size: .95rem; }
.g3d-side button { font: inherit; }
.g3d-float { position: absolute; transform: translate(-50%, -100%); font-weight: 900; font-size: 1.4rem; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.35); pointer-events: none; animation: float-up 0.9s ease-out forwards; z-index: 3; }
@keyframes float-up { to { transform: translate(-50%, -220%); opacity: 0; } }
.touch-pad { position: absolute; inset: auto 12px 12px 12px; display: none; justify-content: space-between; align-items: end; pointer-events: none; z-index: 2; }
.touch-pad button { pointer-events: auto; border: 0; border-radius: 16px; background: rgba(255,255,255,.75); font-size: 1.3rem; font-weight: 900; color: var(--ink); width: 56px; height: 56px; touch-action: none; user-select: none; -webkit-user-select: none; }
.touch-pad .dpad { display: grid; grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(2, 56px); gap: 6px; }
.touch-pad .dpad [data-k=up] { grid-column: 2; }
.touch-pad .dpad [data-k=left] { grid-column: 1; grid-row: 2; }
.touch-pad .dpad [data-k=down] { grid-column: 2; grid-row: 2; }
.touch-pad .dpad [data-k=right] { grid-column: 3; grid-row: 2; }
.touch-pad .jump { width: 92px; height: 92px; border-radius: 50%; background: rgba(255,201,60,.9); }
@media (pointer: coarse) { .touch-pad { display: flex; } }
.g3d-help { margin-top: 10px; }
.build-menu { display: grid; gap: 6px; }
.build-menu button { display: flex; justify-content: space-between; gap: 10px; border: 0; background: #f4f0ff; border-radius: 10px; padding: 6px 10px; font-weight: 800; cursor: pointer; color: var(--ink); }
.build-menu button[disabled] { opacity: .45; cursor: not-allowed; }
.board-list { margin: 6px 0 0; padding-left: 1.4em; text-align: left; }
.upgrades { display: grid; gap: 8px; margin: 12px 0; text-align: left; }
.upgrades .up { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #f6f2ff; border-radius: 12px; padding: 8px 12px; }
.g3d-wrap .overlay { z-index: 4; }
.g3d-wrap .overlay .card { max-height: calc(100% - 24px); overflow: auto; }
.settings legend + * { clear: both; }
.profile-card .pc-body { flex: 1; min-width: 0; }
.profile-card .btn-row { gap: 8px; }
.profile-card .btn.small { padding: 7px 12px; font-size: .85rem; }

/* ---- v0.3: transfer, 100-question test ---- */
.label-strong { font-weight: 800; display: inline-block; margin-bottom: 4px; }
.small-print { font-size: .85rem; }
.transfer { display: grid; grid-template-columns: 1fr auto; gap: 18px; align-items: start; }
.transfer textarea { width: 100%; min-height: 96px; font-family: var(--mono); font-size: .8rem; border: 2px solid var(--line); border-radius: var(--radius-sm); padding: 10px; word-break: break-all; }
.qr { display: inline-block; width: max-content; max-width: 100%; box-sizing: border-box; background: #fff; padding: 6px; border-radius: var(--radius-sm); border: 2px solid var(--line); }
.qr svg { display: block; max-width: 100%; height: auto; }
#scanBox video { width: 100%; max-width: 320px; border-radius: var(--radius-sm); display: block; margin: 10px 0; }
@media (max-width: 640px) { .transfer { grid-template-columns: 1fr; } }
.table-score { margin: 14px auto; border-collapse: collapse; min-width: 260px; }
.table-score caption { font-weight: 800; margin-bottom: 6px; }
.table-score th, .table-score td { padding: 4px 10px; text-align: left; }
.minibar { width: 120px; height: 10px; border-radius: 6px; background: var(--box0); overflow: hidden; }
.minibar i { display: block; height: 100%; background: var(--mint-dark); }
.g3d-view { position: absolute; top: 14px; left: 14px; z-index: 2; background: rgba(255,255,255,.92); }
.g3d-view[aria-pressed="true"] { background: var(--sun); }

/* ---- v0.4: adventure games (Talbergets tempel, Lyktvakten) ---- */
.adv-wrap { touch-action: none; user-select: none; -webkit-user-select: none; }
.adv-wrap .touch-pad { display: none !important; }
.adv-stick-zone { position: absolute; left: 0; bottom: 0; width: 45%; height: 70%; z-index: 2; touch-action: none; }
.adv-stick { position: absolute; width: 124px; height: 124px; margin: -62px 0 0 -62px; border-radius: 50%; background: rgba(255,255,255,.22); border: 3px solid rgba(255,255,255,.7); box-shadow: 0 4px 0 rgba(0,0,0,.18); pointer-events: none; }
.adv-stick i { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; border-radius: 50%; background: rgba(255,255,255,.92); box-shadow: 0 4px 0 rgba(0,0,0,.2); transform: translate(-50%,-50%); }
.adv-btns { position: absolute; right: 14px; bottom: 14px; z-index: 3; display: grid; grid-template-columns: auto auto; grid-template-areas: "focus item" "lamp action"; gap: 10px; align-items: end; justify-items: end; }
.adv-btn { position: relative; border: 0; border-radius: 22px; background: rgba(255,255,255,.93); color: var(--ink); font: inherit; font-weight: 900; display: grid; place-items: center; gap: 0; width: 76px; height: 76px; padding: 4px; box-shadow: 0 5px 0 rgba(0,0,0,.25); cursor: pointer; touch-action: none; }
.adv-btn .ic { font-size: 1.7rem; line-height: 1; }
.adv-btn .lb { font-size: .72rem; line-height: 1.1; }
.adv-btn kbd { position: absolute; top: -6px; right: -6px; font-size: .62rem; padding: 1px 5px; border-radius: 6px; background: var(--ink); color: #fff; box-shadow: none; }
.adv-btn.down { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.adv-btn[disabled] { opacity: .45; }
.adv-btn[hidden] { display: none; }
.adv-btn.glow { animation: adv-glow 1s ease-in-out infinite alternate; }
@keyframes adv-glow { from { box-shadow: 0 5px 0 rgba(0,0,0,.25), 0 0 0 0 rgba(255,201,60,.0); } to { box-shadow: 0 5px 0 rgba(0,0,0,.25), 0 0 0 8px rgba(255,201,60,.55); } }
.adv-action { grid-area: action; width: 104px; height: 104px; border-radius: 50%; background: #ffc93c; }
.adv-action .ic { font-size: 2.3rem; }
.adv-action .lb { font-size: .85rem; }
.adv-focus { grid-area: focus; background: #e9e2ff; }
.adv-item { grid-area: item; background: #c9f4e6; }
.adv-lamp { grid-area: lamp; background: #fff1c2; }
.adv-ring { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 3; display: grid; gap: 8px; justify-items: center; pointer-events: auto; }
.adv-ring[hidden] { display: none; }
.adv-ring .q { background: #1f2348; color: #fff; font-weight: 900; font-size: 1.7rem; padding: 6px 22px; border-radius: 16px; box-shadow: 0 5px 0 rgba(0,0,0,.25); text-align: center; }
.adv-ring .q small { display: block; font-size: .75rem; font-weight: 700; opacity: .85; }
.adv-ring .opts { display: flex; gap: 10px; }
.adv-ring .opt { position: relative; min-width: 76px; height: 70px; border: 0; border-radius: 18px; font: inherit; font-size: 1.7rem; font-weight: 900; color: var(--ink); background: #fff; box-shadow: 0 6px 0 #c9bfe9; cursor: pointer; touch-action: none; }
.adv-ring .opt:nth-child(1) { background: #ffe1db; box-shadow: 0 6px 0 #f2a597; }
.adv-ring .opt:nth-child(2) { background: #dff1ff; box-shadow: 0 6px 0 #98c9ef; }
.adv-ring .opt:nth-child(3) { background: #fff3c9; box-shadow: 0 6px 0 #ecd279; }
.adv-ring .opt:nth-child(4) { background: #d8f7ec; box-shadow: 0 6px 0 #8fdcc1; }
.adv-ring .opt kbd { position: absolute; top: 4px; left: 6px; font-size: .6rem; padding: 0 4px; border-radius: 5px; background: rgba(31,35,72,.75); color: #fff; box-shadow: none; }
.adv-explain { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%) scale(1); z-index: 4; background: #fff; border-radius: 20px; padding: 14px 20px; display: grid; gap: 6px; justify-items: center; box-shadow: 0 8px 0 rgba(0,0,0,.2); transition: opacity .35s, transform .35s; pointer-events: none; max-width: 80%; }
.adv-explain.out { opacity: 0; transform: translate(-50%, -50%) scale(.92); }
.adv-explain .dots { display: grid; gap: 4px; }
.adv-explain .dots i { width: 12px; height: 12px; border-radius: 3px; background: var(--mint, #2ec4a0); display: block; }
.adv-explain b { font-size: 1.6rem; }
.adv-explain span { font-size: .85rem; color: var(--ink-soft); }
.adv-title { position: absolute; left: 50%; top: 28%; transform: translate(-50%, -50%); z-index: 3; text-align: center; color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.35); pointer-events: none; transition: opacity .45s; }
.adv-title b { display: block; font-size: 2.4rem; font-weight: 900; letter-spacing: .02em; }
.adv-title span { font-size: 1rem; font-weight: 800; }
.adv-title.out { opacity: 0; }
.adv-hud { position: absolute; top: 12px; left: 12px; z-index: 2; display: flex; gap: 8px; flex-wrap: wrap; max-width: 56%; pointer-events: none; }
.adv-hud .chip { background: rgba(255,255,255,.93); border-radius: 14px; padding: 5px 11px; font-weight: 900; font-size: 1rem; box-shadow: 0 4px 0 rgba(0,0,0,.18); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.adv-hud .hearts i { display: inline-block; width: 16px; height: 14px; background: #ff5b6e; clip-path: polygon(0 25%, 25% 0, 50% 20%, 75% 0, 100% 25%, 100% 50%, 50% 100%, 0 50%); }
.adv-hud .hearts i.off { background: #d8d3e8; }
.adv-hud .meter { width: 90px; height: 12px; border-radius: 7px; background: #e8e3f5; overflow: hidden; }
.adv-hud .meter b { display: block; height: 100%; background: linear-gradient(90deg, #ff9f1c, #ffc93c); border-radius: 7px; transition: width .25s; }
.adv-hud .meter.lamp b { background: linear-gradient(90deg, #ffd65a, #fff1a8); }
.adv-hud .night { background: #2b2f63; color: #fff; }
.adv-map { position: absolute; top: 12px; right: 12px; z-index: 2; width: 132px; height: 132px; border-radius: 18px; background: rgba(31,35,72,.82); box-shadow: 0 4px 0 rgba(0,0,0,.2); cursor: pointer; }
.adv-map canvas { width: 100%; height: 100%; display: block; border-radius: 18px; }
.adv-sign { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 2; background: rgba(255,255,255,.95); border-radius: 16px; padding: 6px 18px; font-weight: 900; font-size: 1.2rem; text-align: center; box-shadow: 0 5px 0 rgba(0,0,0,.18); pointer-events: none; max-width: 46%; }
.adv-sign:empty { display: none; }
.adv-sign small { display: block; font-size: .78rem; font-weight: 700; color: var(--ink-soft); }
.adv-fade { position: absolute; inset: 0; z-index: 3; background: #1f2348; opacity: 0; pointer-events: none; transition: opacity .35s; }
.adv-fade.on { opacity: 1; }
.adv-bench { display: grid; gap: 8px; text-align: left; }
.adv-bench .rec { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; background: #f6f2ff; border-radius: 14px; padding: 8px 12px; }
.adv-bench .rec small { color: var(--ink-soft); }
.adv-bench .grid-art { display: inline-grid; gap: 2px; margin-top: 4px; }
.adv-bench .grid-art i { width: 8px; height: 8px; background: #c98f4a; border-radius: 2px; display: block; }
@media (max-width: 760px) {
  .adv-btn { width: 62px; height: 62px; border-radius: 18px; }
  .adv-action { width: 86px; height: 86px; }
  .adv-ring .opt { min-width: 60px; height: 58px; font-size: 1.35rem; }
  .adv-ring .q { font-size: 1.3rem; }
  .adv-map { width: 96px; height: 96px; }
  .adv-sign { font-size: .95rem; max-width: 60%; }
  .adv-hud .chip { font-size: .85rem; }
}
.adv-sign:not(.on) { display: none; }
.adv-hud .gems { gap: 4px; }
.adv-hud .gem { display: inline-block; width: 14px; height: 14px; transform: rotate(45deg); border-radius: 3px; box-shadow: inset 0 0 0 2px rgba(31,35,72,.25); }
.adv-hud .chip.hint { display: block; font-size: .85rem; font-weight: 800; white-space: normal; max-width: 340px; background: #1f2348; color: #fff; }
.adv-hud .key.red { filter: hue-rotate(-40deg) saturate(2); }
.adv-hud .key.blue { filter: hue-rotate(170deg) saturate(1.6); }
.adv-shell .g3d-help { margin-top: 8px; }
@media (max-width: 700px) { .adv-map { width: 96px; height: 96px; } .adv-hud .chip.hint { max-width: 220px; font-size: .75rem; } .adv-sign { max-width: 70%; font-size: 1rem; } }
/* Shared adventure style: chunky pop-ups */
.adv-pop { position: absolute; z-index: 4; transform: translate(-50%, -50%); font-weight: 900; font-size: 1.9rem; color: #ffe08a; -webkit-text-stroke: 2px #1f2348; paint-order: stroke fill; text-shadow: 0 4px 0 rgba(31,35,72,.55); pointer-events: none; animation: adv-pop 1.05s ease-out forwards; white-space: nowrap; }
.adv-pop.info { color: #fff; font-size: 1.4rem; }
.adv-pop.soft { color: #c9f4e6; font-size: 1.3rem; }
@keyframes adv-pop { 0% { opacity: 0; transform: translate(-50%, -20%) scale(.6); } 18% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); } 30% { transform: translate(-50%, -70%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -190%) scale(1); } }
@media (prefers-reduced-motion: reduce) { .adv-pop { animation-duration: .01s; animation-delay: .8s; } }
.adv-panel { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; background: rgba(31,35,72,.45); }
.adv-panel[hidden] { display: none; }
.adv-panel .adv-bench { background: #fff; border-radius: 24px; padding: 16px 18px; box-shadow: 0 8px 0 rgba(0,0,0,.25); width: min(560px, 92%); max-height: 92%; overflow: auto; }
.adv-panel h3 { margin: 0 0 4px; } .adv-panel h3 small { font-weight: 700; color: var(--ink-soft); }
.adv-bench .rec { border: 0; font: inherit; color: var(--ink); cursor: pointer; text-align: left; grid-template-columns: 1fr auto auto; box-shadow: 0 4px 0 #d9d0f5; }
.adv-bench .rec:hover, .adv-bench .rec:focus-visible { background: #ece5ff; }
.adv-bench .arr { display: grid; gap: 2px; }
.adv-bench .arr i { width: 10px; height: 4px; border-radius: 2px; background: #b07a48; display: block; }
.adv-bench .rc { font-weight: 900; font-size: .85rem; white-space: nowrap; }
.adv-hud .moons i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: rgba(255,255,255,.35); margin-left: 2px; }
.adv-hud .chip:not(.night) .moons i { background: #e2dcf2; }
.adv-hud .moons i.on { background: #ffe08a; }
.adv-hud .meter.xp b { background: linear-gradient(90deg, #8e6cf0, #ff8fb1); }
.adv-hud .meter { width: 64px; }
/* Tassrusch: number pad + stage progress */
.adv-pad { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 4; background: rgba(255,255,255,.97); border-radius: 24px; padding: 10px 12px 12px; box-shadow: 0 8px 0 rgba(0,0,0,.25); display: grid; gap: 8px; justify-items: center; width: min(320px, 92%); }
.adv-pad[hidden] { display: none; }
.adv-pad .q { background: #1f2348; color: #fff; font-weight: 900; font-size: 1.8rem; padding: 4px 20px; border-radius: 14px; text-align: center; }
.adv-pad .q small { display: block; font-size: .72rem; font-weight: 700; opacity: .85; }
.adv-pad .val { min-width: 120px; min-height: 44px; font-size: 2rem; font-weight: 900; text-align: center; border-radius: 12px; background: #f6f2ff; box-shadow: inset 0 3px 0 rgba(0,0,0,.08); padding: 0 12px; }
.adv-pad .keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; width: 100%; }
.adv-pad .keys button { height: 48px; border: 0; border-radius: 14px; font: inherit; font-size: 1.4rem; font-weight: 900; background: #fff3c9; color: var(--ink); box-shadow: 0 4px 0 #ecd279; cursor: pointer; touch-action: none; }
.adv-pad .keys button:active { transform: translateY(3px); box-shadow: 0 1px 0 #ecd279; }
.adv-pad .keys .ok { background: #2ec4a0; color: #fff; box-shadow: 0 4px 0 #1f8f74; }
.adv-progress { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); width: min(340px, 40%); height: 14px; z-index: 2; border-radius: 8px; background: rgba(255,255,255,.85); box-shadow: 0 4px 0 rgba(0,0,0,.18); }
.adv-progress[hidden] { display: none; }
.adv-progress b { position: absolute; top: -5px; width: 22px; height: 22px; margin-left: -11px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.adv-progress .me { background: #ff6b57; z-index: 1; }
.adv-progress .ghost { background: #8e6cf0; opacity: .75; }
.adv-progress .ghost[hidden] { display: none; }
.adv-hud .chip.boost { background: #ffc93c; animation: adv-glow .5s ease-in-out infinite alternate; }
.adv-hud .chip.paw .meter b { background: linear-gradient(90deg, #ff6b57, #ffc93c); }

/* ---------------------------------------------------------- Dog Watcher --- */
.dw-sub { font-size: .9rem; font-weight: 800; color: var(--ink-soft); margin-left: 6px; }
/* Dog Watcher 3D: soft pastel HUD on top of the scene */
.g3d-wrap.dw3d { background: #cfeeff; aspect-ratio: 16 / 10; min-height: 420px; }
.adv-drop { grid-area: drop; background: #ffd9e4; }
.adv-call { grid-area: call; background: #d7f0ff; }
.dw3d .adv-btns { grid-template-areas: "call drop" "call action"; align-items: end; }
.dw3d .adv-call { align-self: end; }
.dw-hud { position: absolute; inset: 10px 10px auto 10px; z-index: 2; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; pointer-events: none; }
.dw-hud > * { pointer-events: auto; }
.dw-left { display: grid; gap: 6px; max-width: 46%; }
.dw-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.dw-hud .chip { height: auto; min-width: 0; min-height: 34px; display: inline-flex; align-items: center; gap: 4px; background: rgba(255,255,255,.94); box-shadow: 0 3px 0 rgba(31,35,72,.14); font-weight: 900; border: 0; font: inherit; font-weight: 900; padding: 5px 11px; border-radius: 999px; color: var(--ink); }
.dw-hud button.chip { cursor: pointer; }
.dw-walk { background: #fff1c2 !important; }
.dw-tasks { list-style: none; margin: 0; padding: 8px 10px; background: rgba(255,255,255,.93); border-radius: 16px; box-shadow: 0 3px 0 rgba(31,35,72,.12); display: grid; gap: 4px; font-size: .85rem; font-weight: 800; }
.dw-tasks[hidden] { display: none; }
.dw-tasks li { display: flex; gap: 6px; align-items: center; }
.dw-tasks li.done { color: #2a8f6f; }
.dw-tasks small { color: var(--ink-soft); font-weight: 800; }
.dw-dogcards { display: grid; gap: 6px; width: 172px; }
.dw-card { background: rgba(255,255,255,.94); border-radius: 16px; padding: 5px 8px 6px; box-shadow: 0 3px 0 rgba(31,35,72,.12); border-left: 6px solid var(--c); }
.dw-call { all: unset; display: flex; gap: 6px; align-items: center; width: 100%; cursor: pointer; font-weight: 900; font-size: .9rem; box-sizing: border-box; border-radius: 10px; }
.dw-call:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }
.dw-call .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dw-bars { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px; margin-top: 3px; }
.dw-bar { display: flex; align-items: center; gap: 3px; font-size: .7rem; }
.dw-bar .m { flex: 1; height: 7px; border-radius: 99px; background: #eee6da; overflow: hidden; }
.dw-bar .m i { display: block; height: 100%; width: 0; border-radius: 99px; background: var(--mint); transition: width .5s ease; }
.dw-bar .m i.low { background: var(--sun); }
.dw3d .adv-sign { top: auto; bottom: 14px; max-width: 54%; }
.dw-hold { position: absolute; left: 50%; top: 42%; z-index: 3; width: 64px; height: 64px; margin: -32px 0 0 -32px; border-radius: 50%; background: conic-gradient(#ffc93c var(--p, 0%), rgba(255,255,255,.7) 0); box-shadow: 0 4px 0 rgba(31,35,72,.2); pointer-events: none; }
.dw-hold i { position: absolute; inset: 9px; border-radius: 50%; background: #fff; }
.dw-hold i::after { content: '✋'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.4rem; }
.dw-hold[hidden] { display: none; }
.dw-ask { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; background: rgba(31,35,72,.3); padding: 12px; }
.dw-ask[hidden] { display: none; }
.dw-ask-card { background: #fff; border-radius: 26px; padding: 16px 18px; width: min(420px, 94%); max-height: 94%; overflow: auto; text-align: center; box-shadow: 0 8px 0 rgba(31,35,72,.22); }
.dw-story { margin: 0 0 4px; font-weight: 700; }
.dw-q { font-size: 2.3rem; font-weight: 900; margin: 4px 0 10px; }
.dw-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dw-opts .opt { font: inherit; font-size: 1.5rem; font-weight: 900; min-height: 58px; border: 0; border-radius: 18px; background: #f3eeff; color: var(--ink); box-shadow: 0 4px 0 #d9d0f5; cursor: pointer; position: relative; }
.dw-opts .opt:hover, .dw-opts .opt:focus-visible { background: #e6ddff; outline: 3px solid var(--sky); outline-offset: 1px; }
.dw-opts .opt kbd { position: absolute; top: 4px; left: 6px; font-size: .62rem; }
.dw-later { margin-top: 10px; }
.dw-explain { background: #fff6d8; border-radius: 14px; padding: 8px 10px; margin-bottom: 10px; }
.dw-explain p { margin: 0 0 6px; }
.dw-dots { display: grid; gap: 4px; justify-content: center; }
.dw-dots i { width: 13px; height: 13px; border-radius: 50%; background: var(--plum); opacity: .8; }
.dw-evening { position: absolute; left: 12px; bottom: 12px; z-index: 3; display: none; }
.dw3d.playing .dw-evening { display: inline-flex; }
.dw-shop .dw-who { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.dw-shop .rec { cursor: default; }
.dw-owned { font-weight: 800; color: #2a8f6f; font-size: .85rem; }
.dw-names { text-align: left; }
.dw-name-field { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.dw-swatch { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--c); flex: none; }
.dw-breed { font-size: .8rem; font-weight: 800; color: var(--ink-soft); width: 92px; flex: none; }
.dw-name-field input { flex: 1; font: inherit; font-weight: 800; padding: 10px 12px; border-radius: 12px; border: 2px solid var(--line); min-width: 0; }
.dw-name-field input:focus-visible { outline: 3px solid var(--sky); outline-offset: 1px; }
@media (max-width: 760px) {
  .g3d-wrap.dw3d { aspect-ratio: auto; width: 100%; min-height: 440px; height: min(140vw, 76vh); }
  .dw-left { max-width: 52%; }
  .dw-dogcards { width: 118px; gap: 3px; }
  .dw-card { padding: 3px 6px 4px; border-left-width: 4px; }
  .dw-call { font-size: .8rem; }
  .dw-bar { font-size: .6rem; }
  .dw-tasks { font-size: .75rem; padding: 6px 8px; }
  .dw3d .adv-sign { top: auto; bottom: 112px; max-width: 92%; font-size: .85rem; padding: 5px 12px; }
  .dw-hud { inset: 6px 6px auto 6px; }
  .dw-chips { gap: 4px; }
  .dw-hud .chip { font-size: .74rem; padding: 2px 8px; height: auto; min-width: 0; min-height: 26px; border-width: 0; display: inline-flex; align-items: center; gap: 3px; }
  .dw-left { max-width: 58%; }
  .dw-q { font-size: 2rem; }
  .dw-evening { left: auto; right: 12px; bottom: auto; top: 50%; display: none !important; }
}
@media (max-width: 480px) {
  .dw-dogcards { width: 106px; }
  .dw-card { padding: 2px 5px 3px; border-radius: 12px; }
  .dw-call { font-size: .74rem; gap: 3px; }
  .dw-bars { gap: 1px 5px; margin-top: 1px; }
  .dw-bar { font-size: .52rem; gap: 2px; }
  .dw-bar .m { height: 5px; }
  .dw-hud .chip { font-size: .7rem; padding: 1px 7px; min-height: 24px; }
  .dw-hud { inset: 5px 5px auto 5px; }
}
/* Rain: a soft blue-grey veil over the scene; with reduced motion it also carries calm, still drops instead of falling streaks. */
.dw3d::after { content: ''; position: absolute; inset: 0; z-index: 1; pointer-events: none; opacity: 0; transition: opacity 1.2s ease; border-radius: inherit;
  background: linear-gradient(180deg, rgba(84,104,150,.30) 0%, rgba(110,130,170,.12) 60%, rgba(110,130,170,.06) 100%); }
.dw3d.dw-rain::after { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .dw3d::after { transition: none; background: radial-gradient(circle at 20% 30%, rgba(255,255,255,.55) 0 2px, transparent 3px) 0 0 / 46px 58px, radial-gradient(circle at 70% 60%, rgba(255,255,255,.45) 0 2px, transparent 3px) 0 0 / 38px 50px, linear-gradient(180deg, rgba(84,104,150,.32), rgba(110,130,170,.1)); }
}
body.reduce-motion .dw3d::after { transition: none; background: radial-gradient(circle at 20% 30%, rgba(255,255,255,.55) 0 2px, transparent 3px) 0 0 / 46px 58px, radial-gradient(circle at 70% 60%, rgba(255,255,255,.45) 0 2px, transparent 3px) 0 0 / 38px 50px, linear-gradient(180deg, rgba(84,104,150,.32), rgba(110,130,170,.1)); }
/* On small phones the wrapped site header would cover a third of a 3D game while you play: let it scroll away. */
@media (max-width: 760px) { body:has(.adv-shell) .site-header { position: static; } }

/* ===================== v0.4.1: phones first ============================== */
.icon-btn { width: 44px; height: 44px; }
@media (max-width: 640px), (max-height: 500px) {
  .site-header { position: static; backdrop-filter: none; }
  .site-header .inner { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; align-items: center; gap: 4px 6px;
    padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 4px max(10px, env(safe-area-inset-left)); }
  .site-header .brand { grid-area: 1 / 1; min-height: 44px; min-width: 0; gap: 6px; }
  .site-header .wordmark { font-size: 1.2rem; }
  .site-header .profile-chip { grid-area: 1 / 2; min-height: 44px; padding: 4px; max-width: none; }
  .site-header .profile-chip .chip-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .site-header .profile-chip .chip-art { width: 36px; height: 36px; flex-basis: 36px; }
  .site-header a.icon-btn { grid-area: 1 / 3; }
  .site-header #soundToggle { grid-area: 1 / 4; }
  .site-header .nav { grid-area: 2 / 1 / 3 / 5; margin: 0 -4px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 2px; overscroll-behavior-x: contain; }
  .site-header .nav::-webkit-scrollbar { display: none; }
  .site-header .nav a { flex: 0 0 auto; min-height: 44px; display: inline-flex; align-items: center; padding: 0 10px; font-size: .9rem; }
  .test-line { font-size: .72rem; padding: 3px 12px; line-height: 1.3; }
  main { padding: 16px max(14px, env(safe-area-inset-right)) 48px max(14px, env(safe-area-inset-left)); }
  .btn.small { min-height: 44px; }
  .site-footer a { display: inline-block; padding: 10px 2px; }
}

/* Game pages on phones: the stage fills the screen below a slim top bar. */
@media (max-width: 760px), (max-height: 500px) {
  main:has(> .game-shell) { padding: 6px max(6px, env(safe-area-inset-right)) 24px max(6px, env(safe-area-inset-left)); }
  .game-top { flex-wrap: nowrap; gap: 6px; margin-bottom: 6px; min-height: 48px; }
  .game-top h1 { font-size: 1.1rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .game-top .dw-sub { display: none; }
  .game-top .btn.small { padding: 6px 12px; white-space: nowrap; }
  .game-top .spacer { flex: 1 1 0; min-width: 0; }
  .game-top .hud { flex-wrap: nowrap; gap: 4px; }
  .game-top .hud .badge { padding: 4px 9px; font-size: .85rem; white-space: nowrap; }
  .g3d-wrap, .g3d-wrap.dw3d { aspect-ratio: auto; min-height: 0; width: 100%; height: calc(100svh - 62px); border-radius: 16px; }
  .canvas-wrap { touch-action: none; overscroll-behavior: contain; }
  .canvas-wrap .overlay .card { padding: 16px 14px 0; max-width: min(440px, calc(100% - 16px)); max-height: calc(100% - 16px); overflow: auto; }
  .canvas-wrap .overlay .card .gs-go { position: sticky; bottom: 0; margin: 12px -14px 0; padding: 10px 14px 14px; background: linear-gradient(rgba(255,255,255,0), #fff 30%); }
  .canvas-wrap .overlay .card .btn-row { padding-bottom: 14px; }
  .g3d-help { font-size: .85rem; }
  .canvas-wrap:has(> canvas):not(.g3d-wrap) { display: flex; align-items: center; justify-content: center; }
  .canvas-wrap:has(> canvas):not(.g3d-wrap) > canvas { width: auto; height: auto; max-width: 100%; max-height: calc(100svh - 62px); }
  .canvas-wrap .overlay { overscroll-behavior: contain; }
  /* While playing, the game takes over the whole screen (safe areas respected). */
  body.game-play { overflow: hidden; overscroll-behavior: none; }
  body.game-play .game-shell { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; background: var(--paper);
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  body.game-play .game-shell .game-top { padding: 4px 8px 2px; margin: 0; }
  body.game-play .game-shell > .canvas-wrap { flex: 1 1 auto; height: auto; min-height: 0; border-radius: 0; box-shadow: none; }
  body.game-play .game-shell > .canvas-wrap:not(.g3d-wrap) > canvas { max-height: 100%; }
  body.game-play .game-shell > :not(.game-top):not(.canvas-wrap) { display: none; }
  body.game-play .site-header, body.game-play .site-footer, body.game-play .skip-link { visibility: hidden; }
  .adv-btn, .adv-ring .opt, .dw-opts .opt, .touch-pad button { touch-action: manipulation; }
  .adv-btns { right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom)); }
}
/* Landscape phones: the top bar is tighter still. */
@media (max-height: 500px) and (orientation: landscape) {
  .g3d-wrap, .g3d-wrap.dw3d { height: calc(100svh - 54px); }
  .game-top { min-height: 44px; margin-bottom: 4px; }
  .adv-btn { width: 56px; height: 56px; border-radius: 16px; }
  .adv-action { width: 80px; height: 80px; }
  .adv-map { width: 80px; height: 80px; }
}
.toggle-group button { min-height: 44px; }
@media (max-width: 640px), (max-height: 500px) {
  /* Practice / quick test setup: one column, start button stays reachable at the bottom edge. */
  .practice #setup:not([hidden]) { display: block !important; padding: 18px 16px 0; }
  .practice #setup #setupArt { display: none; }
  .practice #setup h1 { font-size: 1.6rem !important; }
  .practice #setup #go { width: 100%; }
  .practice #setup #go, .practice #setup .toggle-group { max-width: 100%; }
  .practice #setup > div:last-child > div:last-child, .practice #setup > div:last-child:has(> #go) { position: sticky; bottom: 0; z-index: 2; margin: 12px -16px 0; padding: 10px 16px max(14px, env(safe-area-inset-bottom)); background: linear-gradient(rgba(255,255,255,0), #fff 28%); border-radius: 0 0 var(--radius) var(--radius); }
  .practice .toggle-group { display: flex; }
  .practice .toggle-group button { flex: 1 1 auto; }
  .picker .chip { min-width: 48px; height: 48px; }
  .site-footer a { padding: 12px 2px; }
  input[type=checkbox], input[type=radio] { width: 22px; height: 22px; }
  label:has(> input[type=checkbox]), label:has(> input[type=radio]) { min-height: 44px; display: inline-flex; align-items: center; gap: 8px; }
  select, input[type=text], input[type=number], input:not([type]) { min-height: 44px; font-size: 16px; }
  input[type=range] { height: 44px; }
  /* Game start / end cards: smaller mascot so the buttons fit. */
  .canvas-wrap .overlay .card > div[style*="width"]:first-child { width: 72px !important; }
  .canvas-wrap .overlay .card h2 { font-size: 1.3rem; }
  .canvas-wrap .overlay .card p { margin: 6px 0; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .canvas-wrap .overlay .card > div[style*="width"]:first-child { display: none; }
}
@media (max-width: 760px), (max-height: 500px) {
  .canvas-wrap .overlay { place-items: start center; padding-top: 8px; }
  .canvas-wrap .overlay .card { max-height: min(calc(100% - 16px), calc(100svh - 76px)); }
  select { min-width: 64px; }
}
/* Dog Watcher: the dog toggle only matters on small stages. */
.dw-dogsbtn { display: none !important; }
.dw-dogcards.mini { width: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.dw-dogcards.mini .dw-card { width: 44px; height: 44px; padding: 0; border-left: 0; border-radius: 50%; box-shadow: 0 0 0 3px var(--c), 0 3px 0 rgba(31,35,72,.18); position: relative; }
.dw-dogcards.mini .dw-call { width: 44px; height: 44px; justify-content: center; border-radius: 50%; }
.dw-dogcards.mini .dw-call .mood { font-size: 1.35rem; }
.dw-dogcards.mini .dw-call .nm { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.dw-dogcards.mini .dw-bars { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.dw-dogcards.mini .dw-card::after { content: attr(data-ini); position: absolute; left: -4px; bottom: -4px; width: 18px; height: 18px; border-radius: 50%; background: var(--c); color: #fff; font-size: .62rem; font-weight: 900; display: grid; place-items: center; pointer-events: none; }
.dw-dogcards.mini .dw-card.low::before { content: '!'; position: absolute; right: -4px; top: -4px; width: 18px; height: 18px; border-radius: 50%; background: #ffc93c; color: var(--ink); font-size: .7rem; font-weight: 900; display: grid; place-items: center; z-index: 1; pointer-events: none; }
@media (max-width: 760px), (max-height: 500px) {
  .dw-dogsbtn { display: inline-flex !important; }
  .dw-hud button.chip { position: relative; }
  .dw-hud button.chip::after { content: ''; position: absolute; top: -10px; bottom: -10px; left: -3px; right: -3px; }
  .g3d-wrap.dw3d .dw-evening { display: inline-flex !important; position: absolute; left: max(8px, env(safe-area-inset-left)); bottom: max(8px, env(safe-area-inset-bottom)); top: auto; right: auto; min-height: 44px; padding: 4px 12px; font-size: .8rem; z-index: 3; }
  .g3d-wrap.dw3d:not(.playing) .dw-evening { display: none !important; }
  .dw3d .adv-sign { bottom: max(120px, calc(env(safe-area-inset-bottom) + 112px)); }
}
@media (max-width: 760px), (max-height: 500px) {
  /* Slim play bar: back, scores (scroll if many), pause. */
  body.game-play .game-top h1, body.game-play .game-top .spacer { display: none; }
  body.game-play .game-top .hud { flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; justify-content: flex-start; }
  body.game-play .game-top .hud::-webkit-scrollbar { display: none; }
  .game-top .pause-btn, .game-top > a.btn { flex: 0 0 auto; }
  body.game-play .game-shell > .canvas-wrap[style*="min-height"] { min-height: 0 !important; overflow: auto; }
  /* Compact in-game HUD. */
  .adv-hud { top: 8px; left: 8px; gap: 4px; max-width: 58%; }
  .adv-hud .chip { font-size: .74rem; padding: 3px 8px; border-radius: 11px; gap: 4px; box-shadow: 0 2px 0 rgba(0,0,0,.16); }
  .adv-hud .chip.hint { max-width: 100%; font-size: .72rem; }
  .adv-hud .hearts i { width: 12px; height: 11px; }
  .adv-hud .meter { width: 56px; height: 9px; }
  .adv-map { width: 84px; height: 84px; top: 8px; right: 8px; border-radius: 14px; }
  .g3d-side { top: 8px; right: 8px; max-width: 46%; gap: 4px; }
  .g3d-side .panel { font-size: .74rem; padding: 5px 8px; border-radius: 11px; }
  .g3d-side .panel h4 { font-size: .8rem; }
  .build-menu button { padding: 4px 8px; min-height: 44px; align-items: center; }
  .g3d-view { top: 8px; left: 8px; }
  .g3d-banner { font-size: 1.15rem; padding: 5px 14px; top: 8px; }
  .touch-pad { inset: auto max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
}
/* Canvas (2D) games switch to a portrait board on upright phones (MTGameShell.fitCanvas). */
@media (max-width: 760px), (max-height: 500px) {
  .g3d-side { max-height: calc(100% - 150px); overflow-y: auto; overscroll-behavior: contain; }
  .g3d-wrap:has(.g3d-view) .g3d-banner { top: 56px; }
  .g3d-banner small { font-size: .7rem; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .g3d-side { max-width: 32%; max-height: calc(100% - 110px); }
  .g3d-wrap:has(.g3d-view) .g3d-banner { top: 8px; }
  .adv-hud { max-width: 50%; }
  .touch-pad .dpad { grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(2, 48px); }
  .touch-pad button { width: 48px; height: 48px; }
  .touch-pad .jump { width: 76px; height: 76px; }
}
@media (max-width: 760px), (max-height: 500px) {
  .dw-hud button.chip { min-width: 44px; justify-content: center; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .adv-hud { gap: 3px; }
  .adv-hud .chip { font-size: .68rem; padding: 2px 7px; }
  .adv-hud .meter { width: 44px; height: 8px; }
  .adv-hud .chip.hint { font-size: .68rem; padding: 3px 8px; max-width: 300px; }
}
/* Phones: compact adventure HUD (essentials first, ＋ unfolds the rest). */
.adv-hud .hud-more { display: none; }
@media (max-width: 760px), (max-height: 500px) {
  .adv-hud .hud-more { display: inline-flex; pointer-events: auto; border: 0; font: inherit; font-weight: 900; color: var(--ink); cursor: pointer; min-width: 30px; justify-content: center; position: relative; }
  .adv-hud .hud-more::after { content: ''; position: absolute; top: -12px; bottom: -12px; left: -8px; right: -8px; }
  .adv-hud:not(.open) .chip.extra { display: none; }
  .adv-hud .chip .moons { display: none; }
  .adv-hud .chip small { font-size: .62rem; }
  .adv-hud .chip.hint.old { display: none; }
}
/* Island side panel: the toggle reads as a heading on desktop; on phones the list folds behind it. */
.side-toggle { all: unset; cursor: default; font: inherit; font-weight: 800; }
.side-toggle span { display: none; }
@media (max-width: 760px), (max-height: 500px) {
  .side-toggle { cursor: pointer; display: flex; justify-content: space-between; gap: 6px; min-height: 44px; align-items: center; width: 100%; box-sizing: border-box; }
  .side-toggle span { display: inline; }
  .g3d-side .panel:not(.open) .build-menu { display: none; }
  .g3d-side .panel h4:has(.side-toggle) { margin: -5px 0; }
  .g3d-side .build-menu button.locked { display: none; }
  .g3d-side .side-info h4 { display: inline; font-size: .74rem; margin-right: 4px; }
  .g3d-side .side-income { font-size: .7rem; }
  .g3d-side .side-tip { font-size: .7rem; }
}
/* Par-jakten on phones: taller cards fill the portrait board, bigger numbers. */
@media (max-width: 760px) and (orientation: portrait) {
  .memory-board { gap: 8px; }
  .mcard { aspect-ratio: 4 / 5; }
  .mcard .front { font-size: 1.15rem; }
  .mcard .front.answer { font-size: 1.7rem; }
  .canvas-wrap:has(> .memory-board) { padding: 10px !important; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .memory-board { grid-template-columns: repeat(8, 1fr) !important; max-width: none; gap: 6px; }
  .mcard { aspect-ratio: 4 / 5; }
  .canvas-wrap:has(> .memory-board) { padding: 8px !important; }
  .players { margin: 4px 0 8px; }
}
/* Tabeller: on phones the multiplication chart keeps 44 px cells and scrolls sideways inside its card, with the header row and column pinned. */
@media (max-width: 640px), (max-height: 500px) {
  #chart.heatmap { grid-template-columns: repeat(14, 44px); gap: 3px; max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; padding-bottom: 6px; font-size: .9rem; scroll-snap-type: x proximity; }
  #chart.heatmap .h, #chart.heatmap .c { aspect-ratio: auto; height: 44px; font-size: .85rem; }
  #chart.heatmap > :nth-child(14n+1) { position: sticky; left: 0; z-index: 1; background: var(--card); box-shadow: 4px 0 6px -4px rgba(31,35,72,.25); }
  #chart.heatmap > :nth-child(-n+14) { position: sticky; top: 0; }
}

/* ===================== v0.4.2: desktop fit + Helskärm ===================== */
.game-top .fs-btn { order: 6; white-space: nowrap; }
.game-shell.is-full { display: flex; flex-direction: column; width: 100%; height: 100%; max-width: none; margin: 0; background: var(--paper);
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
body.game-max { overflow: hidden; }
body.game-max .game-shell { position: fixed; inset: 0; z-index: 70; }
.game-shell.is-full .game-top { margin-bottom: 6px; flex-wrap: nowrap; }
.game-shell.is-full > .canvas-wrap { flex: 1 1 auto; min-height: 0 !important; height: auto !important; max-height: none; aspect-ratio: auto !important; width: 100%; }
.game-shell.is-full > .canvas-wrap:has(> canvas):not(.g3d-wrap) { display: flex; align-items: center; justify-content: center; }
.game-shell.is-full > .canvas-wrap:has(> canvas):not(.g3d-wrap) > canvas { width: auto; height: auto; max-width: 100%; max-height: 100%; }
.game-shell.is-full > .canvas-wrap[style*="min-height"] { overflow: auto; }
.game-shell.is-full > :not(.game-top):not(.canvas-wrap) { display: none; }
/* Desktop without fullscreen: the bar, HUD, stage and start card fit the window (no page scroll needed). */
@media (min-width: 761px) and (min-height: 501px) {
  .g3d-wrap, .g3d-wrap.dw3d { aspect-ratio: auto; min-height: 340px; height: min(calc(100vh - 210px), 760px); }
  .canvas-wrap:has(> canvas):not(.g3d-wrap) { display: flex; align-items: center; justify-content: center; }
  .canvas-wrap:has(> canvas):not(.g3d-wrap) > canvas { width: auto; height: auto; max-width: 100%; max-height: calc(100vh - 210px); }
  .canvas-wrap[style*="min-height"] { min-height: min(640px, calc(100vh - 210px)) !important; }
  .game-shell:not(.is-full) .canvas-wrap .overlay .card { max-height: calc(100% - 20px); }
}
@media (min-width: 761px) and (min-height: 501px) {
  .canvas-wrap .overlay .card { max-width: min(760px, calc(100% - 32px)); overflow: auto; }
  /* Cards with an extra panel (dog names, tower upgrades) put it in a second column. */
  .canvas-wrap .overlay .card:has(> .dw-names, > #shop) { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .85fr); column-gap: 22px; max-width: min(1000px, calc(100% - 32px)); align-content: start; }
  .canvas-wrap .overlay .card:has(> .dw-names, > #shop) > :not(.dw-names):not(#shop) { grid-column: 1; }
  .canvas-wrap .overlay .card > .dw-names, .canvas-wrap .overlay .card > #shop { grid-column: 2; grid-row: 1 / span 9; align-self: center; margin-top: 0; text-align: left; }
  .canvas-wrap .overlay .card #gsPicker { flex-wrap: wrap; justify-content: center; gap: 6px; }
  .canvas-wrap .overlay .card #gsPicker .chip { min-width: 44px; height: 44px; padding: 0 8px; }
  .canvas-wrap .overlay .card > p.muted { max-width: 560px; margin-left: auto; margin-right: auto; }
}
@media (min-width: 761px) and (max-height: 860px) {
  .canvas-wrap .overlay .card { padding: 14px 20px; }
  .canvas-wrap .overlay .card > div[style*="width"]:first-child { width: 64px !important; }
  .canvas-wrap .overlay .card h2 { font-size: 1.4rem; margin-bottom: 4px; }
  .canvas-wrap .overlay .card p { margin: 6px 0; }
  .canvas-wrap .overlay .card .gs-go { margin-top: 12px !important; }
  .game-top { margin-bottom: 8px; }
  .game-top h1 { font-size: 1.5rem; }
}
@media (max-width: 640px), (max-height: 500px) {
  .game-top .fs-btn { font-size: 0; min-width: 44px; padding: 0 10px; }
  .game-top .fs-btn span { font-size: 1.15rem; }
}
@media (min-width: 761px) and (max-height: 920px) {
  .canvas-wrap .overlay .card > div[style*="width"]:first-child { display: none; }
  .canvas-wrap .overlay .card .toggle-group button, .canvas-wrap .overlay .card #gsPicker button { min-height: 40px; }
  .canvas-wrap .overlay .card p[style*="margin:14px"] { margin: 8px 0 4px !important; }
  .canvas-wrap .overlay .card .gs-go { margin-top: 8px !important; }
  .canvas-wrap .overlay .card h2 { margin-top: 0; }
}
@media (min-width: 761px) and (min-height: 921px) {
  .canvas-wrap .overlay .card > div[style*="width"]:first-child { width: 72px !important; }
}

/* ===================== Ritstudion ===================== */
.rit-wrap { display: grid; gap: 8px; padding: 8px; background: linear-gradient(160deg, #fff3dc, #efe7ff); justify-content: center; align-content: center; justify-items: center; align-items: center;
  height: min(calc(100vh - 210px), 760px); min-height: 420px; aspect-ratio: auto; touch-action: none; }
.rit-wrap.tall { grid-template-columns: auto; grid-template-areas: "board" "tools" "pal"; }
.rit-wrap.wide { grid-template-columns: auto auto auto; grid-template-areas: "tools board pal"; }
.rit-board { grid-area: board; position: relative; width: 480px; height: 480px; border-radius: 14px; overflow: hidden; background: #fff; box-shadow: 0 3px 0 rgba(31,35,72,.12), 0 0 0 3px #1f2348 inset; }
.rit-board canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.rit-board #ritLive { cursor: crosshair; }
.rit-board #ritLive.marker { opacity: .55; }
.rit-board.reveal { animation: ritReveal 1.3s ease-out; }
@keyframes ritReveal { 0% { transform: scale(1); } 30% { transform: scale(1.04) rotate(-1deg); } 60% { transform: scale(.99) rotate(.6deg); } 100% { transform: none; } }
.rit-tip { position: absolute; left: 8px; right: 8px; bottom: 8px; margin: 0; padding: 6px 10px; border-radius: 12px; background: rgba(255,255,255,.94); box-shadow: 0 2px 8px rgba(31,35,72,.15); font-size: .92rem; pointer-events: none; text-align: center; }
.rit-tools { grid-area: tools; display: flex; flex-direction: column; gap: 6px; max-width: 100%; }
.rit-row { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.rit-wrap.wide .rit-tools { max-height: 100%; }
.rit-wrap.wide .rit-row { display: grid; grid-template-columns: repeat(2, 46px); overflow: visible; }
.rit-wrap.tall .rit-tools { width: 100%; align-items: center; }
.rit-btn { position: relative; width: 46px; height: 46px; min-width: 46px; border-radius: 12px; border: 2px solid #e6dcc8; background: #fff; font-size: 1.35rem; display: grid; place-items: center; cursor: pointer; touch-action: manipulation; }
.rit-btn[aria-pressed="true"] { border-color: #1f2348; background: #ffe6b8; box-shadow: 0 2px 0 #1f2348; }
.rit-btn:disabled { opacity: .4; cursor: default; }
.rit-btn.size i { display: block; border-radius: 50%; background: #1f2348; }
.rit-btn.asleep span, .rit-sw.asleep { filter: grayscale(.85); opacity: .55; }
.zz { position: absolute; right: -4px; top: -6px; width: 20px; height: 20px; border-radius: 50%; background: #1f2348; color: #fff; font-size: .75rem; display: grid; place-items: center; filter: none; opacity: 1; }
.rit-palette { grid-area: pal; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 4px 2px; max-width: 100%; }
.rit-wrap.wide .rit-palette { display: grid; grid-template-columns: repeat(3, 44px); overflow-y: auto; max-height: 100%; align-content: center; }
.rit-sw { position: relative; width: 44px; height: 44px; min-width: 44px; border-radius: 50%; border: 3px solid #fff; background: var(--c); box-shadow: 0 0 0 2px #1f2348; cursor: pointer; touch-action: manipulation; }
.rit-sw.asleep { opacity: 1; filter: none; background: repeating-linear-gradient(45deg, var(--c) 0 6px, #fff 6px 10px); }
.rit-sw.asleep .zz { right: -6px; top: -6px; }
.rit-sw[aria-pressed="true"] { box-shadow: 0 0 0 3px #1f2348, 0 0 0 6px #ffcf3a; transform: scale(1.06); }
.rit-sw.num { border-radius: 12px; width: 52px; min-width: 52px; }
.rit-sw.num b { display: inline-block; padding: 1px 5px; border-radius: 8px; background: rgba(255,255,255,.92); color: #1f2348; font-size: .95rem; font-weight: 900; }
.rit-wrap.wide .rit-palette:has(.num) { grid-template-columns: repeat(2, 52px); }
.rit-sw.rainbow { background: conic-gradient(#e8434f, #ffcf3a, #3cb55a, #2f7de1, #8a5cf0, #e8434f); }
.woke { animation: ritWake .9s ease-out; }
@keyframes ritWake { 0% { transform: scale(1); } 35% { transform: scale(1.35) rotate(8deg); } 70% { transform: scale(.95); } 100% { transform: scale(1); } }
body.reduce-motion .woke, body.reduce-motion .rit-board.reveal { animation: none; }
.rit-sheet { z-index: 6; }
.rit-sheet .card { max-width: min(560px, calc(100% - 16px)); max-height: calc(100% - 16px); overflow: auto; }
.rit-pics { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 10px; margin: 10px 0; }
.rit-pic, .rit-gal { display: grid; gap: 4px; justify-items: center; padding: 6px; border: 2px solid #e6dcc8; border-radius: 14px; background: #fff; font-weight: 800; cursor: pointer; }
.rit-pic img, .rit-gal img { width: 100%; height: auto; aspect-ratio: 1; border-radius: 8px; }
.rit-pic .blank { width: 100%; aspect-ratio: 1; border-radius: 8px; border: 2px dashed #c9bda5; }
.rit-pic:focus-visible, .rit-pic:hover { border-color: #1f2348; }
.rit-gal .btn-row { gap: 4px; flex-wrap: nowrap; }
.rit-gal .btn.small { min-width: 44px; padding: 0 8px; }
.rit-stickers { display: grid; grid-template-columns: repeat(4, 64px); gap: 8px; justify-content: center; margin: 10px 0; }
.rit-st { width: 64px; height: 64px; border-radius: 14px; border: 2px solid #e6dcc8; background: #fff; display: grid; place-items: center; cursor: pointer; }
.rit-st[aria-pressed="true"] { border-color: #1f2348; background: #ffe6b8; }
.rit-menu { display: grid; gap: 8px; margin: 10px 0; }
.rit-ask-head { display: flex; align-items: center; justify-content: center; gap: 10px; }
.rit-ask-head .big { font-size: 2rem; }
.rit-dot { width: 40px; height: 40px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 3px #1f2348; display: inline-block; }
.rit-q { font-size: 2rem; margin: 10px 0; }
.rit-choices { display: grid; grid-template-columns: repeat(4, minmax(56px, 1fr)); gap: 8px; }
.rit-choices .btn { font-size: 1.3rem; min-height: 52px; }
.rit-choices .btn.right { background: #b9f0d4; border-color: #2ec4a0; }
@media (max-width: 640px), (max-height: 500px) {
  body.game-play .rit-wrap { height: calc(100svh - 62px); min-height: 0; padding: 6px; gap: 6px; }
  .rit-wrap { height: auto; min-height: 0; }
  .rit-btn { width: 44px; height: 44px; min-width: 44px; font-size: 1.2rem; }
  .rit-wrap.wide .rit-row { grid-template-columns: repeat(2, 44px); gap: 4px; }
  .rit-wrap.wide .rit-palette { grid-template-columns: repeat(3, 44px); gap: 4px; }
  .rit-q { font-size: 1.6rem; }
  .rit-choices { grid-template-columns: repeat(2, 1fr); }
  .rit-stickers { grid-template-columns: repeat(4, 56px); }
  .rit-st { width: 56px; height: 56px; }
}
.game-shell.is-full > .rit-wrap { height: auto !important; }

/* v0.5.1 static content (first HTML response; the page scripts enhance it) */
.fact-list { list-style: none; padding: 0; margin: 10px 0 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px 14px; font-variant-numeric: tabular-nums; font-size: 1.1rem; }
.fact-list li { padding: 4px 10px; border-radius: 10px; background: var(--paper-2, #fff3dc); }
.seo-text p, .seo-text li { max-width: 72ch; }
.mt-static { border-collapse: collapse; font-variant-numeric: tabular-nums; width: 100%; max-width: 760px; }
.mt-static caption { text-align: left; font-weight: 700; margin-bottom: 6px; }
.mt-static th, .mt-static td { border: 1px solid #e6dcc8; padding: 4px; text-align: center; }
.mt-static th { background: #fff3dc; }
#chart:has(.mt-static) { overflow-x: auto; }
/* "Multiplikationstabellen" is one long word: shrink headings on narrow phones instead of overflowing. */
h1 { overflow-wrap: break-word; }
@media (max-width: 520px) { main h1 { font-size: min(2rem, 6.4vw); } }
/* Soft-art HUD: the same round pastel chips and cards as Dog Watcher in every 3D game. */
.g3d-wrap { background: #cfeeff; }
.adv-hud .chip, .g3d-view { border-radius: 999px; box-shadow: 0 3px 0 rgba(31,35,72,.14); }
.adv-hud .chip.hint { border-radius: 16px; background: rgba(255,255,255,.95); color: var(--ink); border-left: 6px solid #9a7cf2; }
.adv-hud .night { background: #3b3f78; }
.adv-sign, .g3d-banner { border-radius: 999px; box-shadow: 0 4px 0 rgba(31,35,72,.14); }
.g3d-side .panel { border-radius: 16px; box-shadow: 0 3px 0 rgba(31,35,72,.12); }
.adv-map { border-radius: 24px; background: rgba(59,63,120,.78); border: 3px solid rgba(255,255,255,.9); box-shadow: 0 3px 0 rgba(31,35,72,.18); }
.adv-ring .q, .adv-pad .q { background: #3b3f78; border-radius: 999px; box-shadow: 0 4px 0 rgba(31,35,72,.22); }
.adv-fade { background: #3b3f78; }
