/* Self-hosted fonts (SIL Open Font License) — no third-party requests. */
@font-face { font-family: 'Pixelify Sans'; src: url(../fonts/pixelify-sans-latin.woff2) format('woff2'); font-weight: 400 700; font-display: swap; }
@font-face { font-family: 'Atkinson Hyperlegible'; src: url(../fonts/atkinson-400-latin.woff2) format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Atkinson Hyperlegible'; src: url(../fonts/atkinson-700-latin.woff2) format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Press Start 2P'; src: url(../fonts/press-start-2p-latin.woff2) format('woff2'); font-weight: 400; font-display: swap; }

:root {
  --u: 3px;                /* one art pixel, set by main.js */
  --ink: #1a1c2c;
  --cream: #fff4d6;
  --cream-d: #f0dcae;
  --gold: #f2c93a;
  --gold-d: #c99a1a;
  --purple: #3b2f7a;
  --purple-l: #5b4aa0;
  --green: #45a84b;
  --red: #d8433a;
  --sky: #8fd0f7;
  --text: #2a2238;
  --fs: clamp(14px, calc(var(--u) * 5.4), 26px);
  --fs-sm: clamp(12px, calc(var(--u) * 4.4), 20px);
  --fs-lg: clamp(16px, calc(var(--u) * 7), 34px);
  --pix: 'Press Start 2P', ui-monospace, monospace;
  --body: 'Atkinson Hyperlegible', 'Trebuchet MS', system-ui, sans-serif; /* clear 5/S, b/d for early readers */
  --chunky: 'Pixelify Sans', 'Atkinson Hyperlegible', system-ui, sans-serif;
  --bevel: 0 0 0 2px var(--ink), inset 0 -3px 0 rgba(0,0,0,.18), inset 0 2px 0 rgba(255,255,255,.55);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0d0b1e; color: var(--text); overflow: hidden; overscroll-behavior: none; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font-family: var(--body); font-size: var(--fs);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  position: fixed; inset: 0; height: 100dvh;
}
canvas, img { -webkit-touch-callout: none; -webkit-user-drag: none; }
#app { position: fixed; inset: 0; height: 100dvh; display: grid; place-items: center; background:
  radial-gradient(ellipse at 50% 40%, #2a2358 0%, #0d0b1e 70%);
  /* keep the stage clear of notches, rounded corners and the home bar (read back by fit() in main.js) */
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); }
#stage { position: relative; overflow: hidden; background: #000; box-shadow: 0 0 60px rgba(120,90,255,.25); }
#screen, .pixel { image-rendering: pixelated; image-rendering: crisp-edges; }
#screen { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

/* ---------------------------------------------------------------- CRT glow */
#crt { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .3s; }
body.crt #crt { opacity: 1;
  background:
    repeating-linear-gradient(to bottom, rgba(0,0,0,.12) 0, rgba(0,0,0,.12) 1px, transparent 1px, transparent calc(var(--u) * 1)),
    radial-gradient(ellipse at center, transparent 62%, rgba(10,6,30,.38) 100%);
  mix-blend-mode: multiply; }

/* ---------------------------------------------------------------- loading */
#loading { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: calc(var(--u) * 3); text-align: center; background: radial-gradient(ellipse at 50% 45%, #2a2358 0%, #12102b 75%);
  color: var(--cream); font-family: var(--pix); font-size: calc(var(--u) * 3.6); transition: opacity .45s; z-index: 50; }
body[data-title="outback"] #loading { background: radial-gradient(ellipse at 50% 45%, #5a2412 0%, #1b0a05 75%); }
body.ready #loading { opacity: 0; pointer-events: none; }
.ld-name { font-size: calc(var(--u) * 8); color: var(--gold); text-shadow: calc(var(--u)*.7) calc(var(--u)*.7) 0 var(--ink); letter-spacing: .06em; }
#ld-hero { width: calc(var(--u) * 20); height: calc(var(--u) * 22); image-rendering: pixelated; }
.ld-bar { width: calc(var(--u) * 120); height: calc(var(--u) * 5); background: var(--ink); padding: calc(var(--u) * .8);
  box-shadow: 0 0 0 calc(var(--u) * .8) var(--cream-d); }
.ld-bar i { display: block; height: 100%; width: 4%; transition: width .35s steps(6);
  background: repeating-linear-gradient(90deg, var(--gold) 0 calc(var(--u) * 4), var(--gold-d) calc(var(--u) * 4) calc(var(--u) * 5)); }
.ld-msg { margin: 0; min-height: 1.2em; }
.ld-tip { margin: 0; max-width: 70%; font-family: var(--body); font-size: var(--fs-sm); color: rgba(255,244,214,.75); min-height: 2.6em; }
.spinner { width: 28px; height: 28px; margin: 0 auto; background: var(--gold); box-shadow: 0 0 0 4px var(--ink);
  animation: spin 1s steps(8) infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- title menu */
#menu { position: absolute; inset: 0; display: none; flex-direction: column; align-items: flex-start; justify-content: center;
  padding-left: calc(var(--u) * 18); gap: calc(var(--u) * 7); z-index: 10; }
#menu.show { display: flex; animation: fadeIn .6s ease-out both; }
.logo { text-align: left; font-family: var(--pix); color: var(--gold); line-height: 1;
  text-shadow: calc(var(--u)*.8) calc(var(--u)*.8) 0 var(--ink), calc(var(--u)*-.5) calc(var(--u)*-.5) 0 #fff6b0; }
.logo-top { font-size: calc(var(--u) * 9); color: #fff; letter-spacing: .1em; }
.logo-main { font-size: calc(var(--u) * 17); margin-top: calc(var(--u) * 2); position: relative; animation: logoFloat 4s ease-in-out infinite; }
.logo-ii { font-size: .75em; color: #ff8fc4; margin-left: .25em; display: inline-block; transform: rotate(-8deg); }
.logo-sub { font-family: var(--chunky); font-weight: 700; color: #ffe6b3; font-size: calc(var(--u) * 7); margin-top: calc(var(--u) * 3);
  text-shadow: 2px 2px 0 var(--ink); letter-spacing: .04em; }
@keyframes logoFloat { 50% { transform: translateY(calc(var(--u) * -1.5)); } }
.menu-items { display: flex; flex-direction: column; gap: calc(var(--u) * 2.2); align-items: stretch; min-width: calc(var(--u) * 100); }
.menu-foot { position: absolute; bottom: calc(var(--u) * 3); left: 0; right: 0; text-align: center; color: rgba(255,244,214,.6); font-size: var(--fs-sm); }
body:not([data-mode="title"]) #menu { display: none; }

/* ---------------------------------------------------------------- buttons */
.btn { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: var(--cream); color: var(--ink); border: 0; border-radius: 6px; padding: .45em 1.1em; min-height: 44px;
  font-family: var(--chunky); font-weight: 700; font-size: var(--fs); box-shadow: var(--bevel), 0 4px 0 var(--ink);
  transition: transform .08s, filter .15s; }
.btn small { font-weight: 400; font-size: .7em; opacity: .75; }
.btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.btn:active { transform: translateY(3px); box-shadow: var(--bevel), 0 1px 0 var(--ink); }
.btn.primary { background: var(--gold); }
.btn.big { font-size: var(--fs-lg); }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 12px; }

/* ---------------------------------------------------------------- HUD */
#hud { position: absolute; left: 0; right: 0; top: 0; display: none; justify-content: space-between; align-items: flex-start;
  padding: calc(var(--u) * 2.5); gap: 8px; z-index: 5; pointer-events: none; }
body[data-mode="play"] #hud, body[data-mode="castle"] #hud, body[data-mode="lair"] #hud { display: flex; }
.hud-left, .hud-right { display: flex; gap: calc(var(--u) * 1.6); align-items: center; pointer-events: auto; }
.hud-left { flex: 0 1 auto; min-width: 0; }
.hud-right { flex: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: rgba(26,28,44,.78); color: var(--cream); border: 0;
  border-radius: 8px; padding: 4px 10px; min-height: 36px; font-weight: 700; font-size: var(--fs-sm);
  box-shadow: 0 0 0 2px rgba(255,244,214,.25); backdrop-filter: blur(2px); font-family: var(--chunky); white-space: nowrap; }
#coin-count, #clue-count { font-family: var(--body); }
.btn-hud { min-width: 40px; justify-content: center; font-size: var(--fs); }
.btn-hud:hover { background: rgba(59,47,122,.95); }
#hud-level { display: block; min-width: 0; flex: 0 1 auto; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 28px;
  font-family: var(--pix); font-size: clamp(8px, calc(var(--u) * 3.2), 14px); letter-spacing: .02em; }
#hud-key { display: none; background: rgba(242,201,58,.9); }
#hud-key.show { display: inline-flex; animation: pop .4s cubic-bezier(.3,1.8,.5,1); }
#coin-count { min-width: 1.2em; text-align: right; }
.bump { animation: bump .35s ease-out; }
@keyframes bump { 40% { transform: scale(1.25); } }
@keyframes pop { from { transform: scale(0); } }
body[data-mode="lair"] #btn-clues, body[data-mode="lair"] #btn-map, body[data-mode="lair"] #btn-castle,
body[data-mode="castle"] #btn-clues, body[data-mode="castle"] #btn-map, body[data-mode="castle"] #hud-level { display: none; }
body[data-mode="ending"] #hud { display: none; }

#castlebar { position: absolute; left: 0; right: 0; bottom: calc(var(--u) * 3); display: none; justify-content: center; align-items: center;
  gap: 16px; z-index: 5; }
body[data-mode="castle"] #castlebar, body[data-mode="ending"] #castlebar { display: flex; }
.castle-title { font-family: var(--pix); color: var(--gold); font-size: clamp(10px, calc(var(--u) * 4.5), 20px); text-shadow: 2px 2px 0 var(--ink); }

/* ---------------------------------------------------------------- hover label, banner, toasts */
#label { position: absolute; left: calc(var(--x) * 100%); top: calc(var(--y) * 100%); transform: translate(-50%, calc(-100% - 14px));
  background: var(--ink); color: var(--cream); padding: 3px 8px; border-radius: 4px; font-size: var(--fs-sm); white-space: nowrap;
  pointer-events: none; opacity: 0; transition: opacity .12s; z-index: 6; }
#label.show { opacity: 1; }
#banner { position: absolute; left: 0; right: 0; top: 30%; text-align: center; pointer-events: none; z-index: 7; opacity: 0; }
#banner.show { animation: banner 2.6s ease-in-out both; }
.b-title { font-family: var(--pix); color: #fff; font-size: calc(var(--u) * 6); text-shadow: 3px 3px 0 var(--ink); }
.b-sub { font-family: var(--pix); color: var(--gold); font-size: calc(var(--u) * 11); margin-top: calc(var(--u) * 3);
  text-shadow: calc(var(--u)*.8) calc(var(--u)*.8) 0 var(--ink); }
@keyframes banner { 0% { opacity: 0; transform: scale(.85); } 15%, 75% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-10px); } }
#toasts { position: absolute; left: 50%; bottom: calc(var(--u) * 4); transform: translateX(-50%); display: flex; flex-direction: column;
  align-items: center; gap: 6px; z-index: 8; pointer-events: none; width: 90%; }
.toast { background: rgba(26,28,44,.9); color: var(--cream); padding: 8px 16px; border-radius: 10px; font-size: var(--fs);
  box-shadow: 0 0 0 2px var(--gold); text-align: center; opacity: 0; transform: translateY(10px); transition: .25s; max-width: 100%; }
.toast.in { opacity: 1; transform: none; }
.toast b { color: var(--gold); }

/* ---------------------------------------------------------------- dialogs */
#overlay { position: absolute; inset: 0; z-index: 20; pointer-events: none; }
.scrim { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(13,11,30,.45); pointer-events: auto;
  opacity: 0; transition: opacity .18s; padding: 3%; }
.scrim.in { opacity: 1; }
.scrim.out { opacity: 0; }
.dialog { position: relative; display: flex; gap: 16px; background: var(--cream); color: var(--text); border-radius: 12px;
  padding: 18px 22px; max-width: 88%; max-height: 94%; overflow: auto;
  box-shadow: 0 0 0 3px var(--ink), 0 0 0 7px var(--gold), 0 0 0 10px var(--ink), 0 14px 0 6px rgba(0,0,0,.35);
  transform: scale(.9) translateY(10px); transition: transform .22s cubic-bezier(.3,1.5,.5,1); }
.scrim.in .dialog { transform: none; }
.dialog h2 { font-family: var(--pix); font-size: clamp(11px, calc(var(--u) * 4.4), 20px); margin: 0 0 10px; color: var(--purple); line-height: 1.4; }
.dialog-main { flex: 1; min-width: 0; position: relative; }
.portrait { flex: none; width: clamp(64px, calc(var(--u) * 28), 128px); align-self: flex-start; }
.portrait canvas { width: 100%; height: auto; display: block; filter: drop-shadow(3px 3px 0 rgba(0,0,0,.2)); }
.msg-body { font-size: var(--fs); line-height: 1.45; padding-right: 34px; }
.msg-body b, .cluebook b { color: var(--purple); }
b.clr { color: var(--clr) !important; -webkit-text-stroke: .6px var(--ink); paint-order: stroke fill; letter-spacing: .04em; }
.speak { position: absolute; top: -6px; right: -6px; background: none; border: 0; font-size: var(--fs-lg); line-height: 1; padding: 4px; border-radius: 6px; }
.speak:hover { background: rgba(0,0,0,.06); }
.speak.sm { position: static; font-size: var(--fs); margin-left: 6px; vertical-align: middle; }
.message .btn-row { justify-content: flex-end; }

/* question card */
.question { min-width: min(88%, 620px); }
.q-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; padding-right: 36px; }
.badge { font-family: var(--pix); font-size: clamp(8px, calc(var(--u) * 2.8), 12px); background: var(--purple); color: #fff; padding: 5px 8px; border-radius: 4px; }
.subj-math .badge { background: #2d7fd8; }
.subj-reading .badge { background: #d8433a; }
.subj-thinking .badge { background: #2f9e44; }
.q-title { font-size: var(--fs-sm); opacity: .75; }
.q-intro { margin: 4px 0; font-size: var(--fs-sm); opacity: .8; }
.q-prompt { font-size: var(--fs-lg); font-weight: 700; margin: 6px 0 10px; line-height: 1.3; }
.visual { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px; margin: 8px 0 14px; padding: 10px;
  background: #fffaf0; border-radius: 10px; box-shadow: inset 0 0 0 2px var(--cream-d); }
.visual canvas { width: clamp(28px, calc(var(--u) * 12), 56px); height: auto; image-rendering: pixelated; }
.v-picture canvas { width: clamp(64px, calc(var(--u) * 26), 120px); }
.visual .group { display: grid; gap: 4px; justify-content: center; }
.visual .op { font-size: var(--fs-lg); font-weight: 700; }
.v-text { font-family: var(--body); font-weight: 700; font-size: clamp(22px, calc(var(--u) * 11), 48px); letter-spacing: .06em; color: var(--purple); }
.v-text.long { font-size: var(--fs-lg); letter-spacing: 0; line-height: 1.4; text-align: center; color: var(--text); }
.seq { display: inline-grid; place-items: center; min-width: clamp(34px, calc(var(--u) * 14), 64px); min-height: clamp(34px, calc(var(--u) * 14), 64px);
  background: #fff; border-radius: 8px; box-shadow: 0 0 0 2px var(--cream-d); font-weight: 700; font-size: var(--fs-lg); }
.seq.blank { background: var(--gold); box-shadow: 0 0 0 2px var(--ink); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.choices { display: grid; gap: 10px; grid-template-columns: repeat(var(--cols, 3), 1fr); }
.choices.n2 { --cols: 2; } .choices.n4 { --cols: 2; }
.choice { position: relative; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 56px; padding: 10px 14px 10px 30px;
  background: #fff; border: 0; border-radius: 10px; font-family: var(--body); font-size: var(--fs-lg); font-weight: 700; color: var(--ink);
  box-shadow: 0 0 0 3px var(--ink), 0 5px 0 var(--ink); transition: transform .08s, background .15s; }
.choice canvas { width: clamp(32px, calc(var(--u) * 13), 64px); height: auto; image-rendering: pixelated; }
.choice:hover:not(:disabled) { background: #fff7d6; transform: translateY(-2px); }
.choice:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 0 0 3px var(--ink), 0 1px 0 var(--ink); }
.choice .num { position: absolute; left: 8px; top: 6px; font-family: var(--pix); font-size: 9px; opacity: .45; }
.choice.right { background: #8fe08a; animation: pop .35s; }
.choice.wrong { background: #f3b0a8; opacity: .6; animation: wobble .35s; }
.choice.reveal { background: #bfe6ff; box-shadow: 0 0 0 3px var(--ink), 0 0 0 7px #3a6fd8; }
@keyframes wobble { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.hint { min-height: 1.6em; margin-top: 12px; font-size: var(--fs); }
.hint .good { color: #2f8a36; font-size: var(--fs-lg); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* panels */
.panel { flex-direction: column; min-width: min(88%, 440px); }
.panel.wide { min-width: min(92%, 720px); }
.close { position: absolute; top: 8px; right: 10px; background: var(--ink); color: #fff; border: 0; border-radius: 50%; width: 36px; height: 36px; font-size: 16px; z-index: 2; }
.setup { display: flex; flex-direction: column; gap: 14px; align-items: stretch; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 700; font-size: var(--fs-sm); color: var(--purple); }
input[type="text"] { font: inherit; font-size: var(--fs-lg); padding: 8px 12px; border: 0; border-radius: 8px; background: #fff;
  box-shadow: inset 0 0 0 3px var(--ink); color: var(--ink); user-select: text; -webkit-user-select: text; }
.avatars { display: flex; gap: 12px; flex-wrap: wrap; }
.avatar { background: #fff; border: 0; border-radius: 10px; padding: 6px 10px; box-shadow: 0 0 0 3px var(--cream-d); }
.avatar.on { background: #fff4b0; box-shadow: 0 0 0 3px var(--ink), 0 0 0 6px var(--gold); }
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg-btn { flex: 1; display: flex; flex-direction: column; align-items: center; background: #fff; border: 0; border-radius: 8px; padding: 8px 10px;
  box-shadow: 0 0 0 3px var(--cream-d); font-weight: 700; min-height: 44px; }
.seg-btn small { font-weight: 400; font-size: .75em; opacity: .7; }
.seg-btn.on { background: var(--gold); box-shadow: 0 0 0 3px var(--ink); }
.seg-btn.check.on::before { content: '✓ '; }
.warn { color: var(--red); font-size: var(--fs-sm); margin: 0; }
.options { display: flex; flex-direction: column; gap: 12px; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.opt input[type="range"] { width: 45%; accent-color: var(--purple); }
.opt input[type="checkbox"] { width: 26px; height: 26px; accent-color: var(--purple); }
.opt select { font: inherit; padding: 6px; border-radius: 6px; }
.how { display: flex; flex-direction: column; gap: 12px; }
.step { display: flex; gap: 16px; align-items: center; }
.step > canvas { flex: none; width: 72px !important; height: auto !important; }
.step h3 { margin: 0; font-size: var(--fs); color: var(--purple); }
.step p { margin: 2px 0 0; font-size: var(--fs-sm); line-height: 1.4; }
.keys h3 { font-size: var(--fs); margin: 6px 0; color: var(--purple); }
.keys p { font-size: var(--fs-sm); line-height: 2; margin: 0; }
kbd { background: #fff; box-shadow: 0 0 0 2px var(--ink), 0 2px 0 2px var(--ink); border-radius: 4px; padding: 0 6px; margin: 0 3px; font-family: var(--body); }
.credits p { line-height: 1.5; font-size: var(--fs-sm); max-width: 560px; }
.dim { opacity: .7; font-size: var(--fs-sm); }
.cluebook .clues { padding-left: 1.4em; margin: 0 0 10px; display: flex; flex-direction: column; gap: 10px; }
.cluebook li { font-size: var(--fs); line-height: 1.4; }
.cluebook li.missing { opacity: .45; font-style: italic; }
.map { display: flex; flex-direction: column; align-items: center; }
.map-canvas { width: min(100%, 560px); height: auto; border-radius: 8px; box-shadow: 0 0 0 3px var(--ink); }
.map-legend { font-size: var(--fs-sm); display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 4px 20px; width: 100%; margin: 12px 0 0; }
.map-legend .done { color: #2f8a36; }
.map-legend .here { font-weight: 700; color: var(--purple); }
.ending { text-align: center; }
.ending h2 { font-size: clamp(14px, calc(var(--u) * 6), 26px); }
.rank { font-family: var(--pix); color: var(--gold-d); font-size: clamp(11px, calc(var(--u) * 4.4), 20px); margin: 14px 0; line-height: 1.6; }
.rank small { display: block; font-family: var(--chunky); color: var(--text); font-size: var(--fs-sm); }
.stats { list-style: none; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; text-align: left; font-size: var(--fs-sm); }
.stats b { color: var(--purple); font-size: var(--fs-lg); }

/* ---------------------------------------------------------------- misc */
@keyframes fadeIn { from { opacity: 0; } }
/* Portrait phones get the "turn sideways" card (js/main.js sets body.rotate-needed); if they choose to play upright anyway: */
@media (orientation: portrait) and (max-width: 600px) {
  body.portrait-ok #app { place-items: start center; padding-top: max(12vh, env(safe-area-inset-top)); }
  body.portrait-ok #overlay { position: fixed; inset: 0; }
  body.portrait-ok #hud-level { display: none; }
  body.portrait-ok #hud { padding: 6px; }
  body.portrait-ok .hud-right { flex: 1 1 auto; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
  body.portrait-ok .chip { padding: 4px 7px; }
  body.portrait-ok #toasts { position: fixed; bottom: 28vh; }
  body.portrait-ok .question, body.portrait-ok .panel { max-width: 98%; }
  body.portrait-ok .dialog { flex-direction: column; align-items: center; }
  body.portrait-ok .portrait { width: 72px; }
}
body.reduced-motion *, body.reduced-motion *::before { animation-duration: .01s !important; transition-duration: .01s !important; }
@media (prefers-reduced-motion: reduce) { .logo-main, .seq.blank { animation: none; } }
.noscript { color: #fff; text-align: center; font-family: sans-serif; }

body:not([data-mode="ending"]) #castlebar .only-ending, body[data-mode="ending"] #castlebar .only-castle { display: none; }

/* ---------------------------------------------------------------- v2: exploration UI */
#mg-overlay { position: absolute; inset: 0; pointer-events: none; z-index: 4; font-family: var(--body); color: var(--text); }
#mg-quit { position: absolute; top: calc(var(--u) * 2.5); right: calc(var(--u) * 2.5); z-index: 6; display: none; pointer-events: auto; }
body[data-mode="minigame"] #mg-quit { display: inline-flex; }
body[data-mode="minigame"] #hud { display: none; }
.chip.voice { display: none; font-family: var(--body); font-size: var(--fs-sm); }
.chip.voice.show { display: block; min-width: 0; flex: 0 3 auto; overflow: hidden; text-overflow: ellipsis; line-height: 28px; animation: pulse 1.6s infinite; }
@media (pointer: coarse) { .chip.voice.show { line-height: 32px; } }
.portrait.talking canvas { animation: talk .28s ease-in-out infinite alternate; }
@keyframes talk { from { transform: translateY(0) scale(1); } to { transform: translateY(-3%) scale(1.04, .97); } }
.avatar { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.av-name { font-size: var(--fs-sm); font-family: var(--chunky); }
.opt.col { flex-direction: column; align-items: stretch; gap: 2px; }
.opt.col .opt { width: 100%; }
.narr-status { text-align: right; min-height: 1.2em; }
.tip { background: #fff; border-radius: 8px; padding: 8px 12px; font-size: var(--fs-sm); box-shadow: 0 0 0 2px var(--cream-d); }

.pack-row { display: flex; gap: 18px; align-items: flex-start; }
.pack-items { display: flex; flex-direction: column; gap: 10px; flex: 1; }
.item, .shop-item { display: flex; gap: 12px; align-items: center; background: #fff; border-radius: 10px; padding: 8px 12px; box-shadow: 0 0 0 2px var(--cream-d); }
.item p, .shop-item p { margin: 2px 0 0; font-size: var(--fs-sm); line-height: 1.3; }
.item canvas, .shop-item canvas { flex: none; }
.hats { display: flex; gap: 10px; flex-wrap: wrap; }
.hat { background: #fff; border: 0; border-radius: 10px; padding: 6px; min-width: 64px; min-height: 64px; box-shadow: 0 0 0 3px var(--cream-d); display: grid; place-items: center; }
.hat.on { background: #fff4b0; box-shadow: 0 0 0 3px var(--ink), 0 0 0 6px var(--gold); }
.nohat { font-size: var(--fs-sm); font-weight: 700; }
.pack h3 { margin: 14px 0 8px; color: var(--purple); font-size: var(--fs); }

.shop-head { display: flex; gap: 14px; align-items: center; }
.shop-head canvas { width: clamp(64px, calc(var(--u) * 26), 110px); height: auto; image-rendering: pixelated; }
.shop-head p { margin: 4px 0 0; font-style: italic; font-size: var(--fs-sm); }
.coins-line { display: flex; align-items: center; gap: 6px; font-weight: 700; margin: 10px 0; }
.shop-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.si-text { flex: 1; min-width: 0; }
.shop-item .btn { min-width: 70px; }
.price { display: inline-flex; align-items: center; gap: 2px; }

.room-row { display: flex; align-items: flex-start; gap: 6px; flex-wrap: wrap; justify-content: center; }
.room-col { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.room-card { min-width: 110px; max-width: 150px; background: #efe3c2; border-radius: 10px; padding: 8px 10px; text-align: center; box-shadow: 0 0 0 2px #c9a86a; }
.room-card.seen { background: #fff; box-shadow: 0 0 0 2px var(--ink); }
.room-card.here { background: #fff4b0; box-shadow: 0 0 0 3px var(--ink), 0 0 0 6px var(--gold); }
.rc-name { font-weight: 700; font-size: var(--fs-sm); }
.rc-icons { min-height: 1.3em; font-size: var(--fs-sm); }
.rc-here { font-size: .75em; color: var(--purple); font-weight: 700; }
.rc-arrow, .rc-down { font-weight: 700; color: #8a5a2a; align-self: center; }
.rc-arrow { margin-top: 16px; }
.map details { width: 100%; margin-top: 8px; }
.map summary { cursor: pointer; font-weight: 700; color: var(--purple); }

/* ================================================================ phones & tablets */

/* Touch: roomier HUD targets, no sticky hover states, no hover labels. */
@media (pointer: coarse) {
  .chip { min-height: 40px; padding: 4px 9px; }
  .btn-hud { min-width: 42px; }
  #hud-level { line-height: 32px; }
  #mg-quit { min-width: 44px; min-height: 44px; }
  .close { width: 42px; height: 42px; font-size: 18px; }
  .mg-legend { display: none !important; }
}
@media (hover: none) {
  #label { display: none; }
  .btn:hover { filter: none; transform: none; }
  .btn-hud:hover { background: rgba(26,28,44,.78); }
  .choice:hover:not(:disabled) { background: #fff; transform: none; }
  .speak:hover { background: none; }
}

/* Short landscape screens (phones ≈ 360–430px tall): compact dialogs that use the full screen width. */
@media (max-height: 480px) {
  .chip { gap: 4px; }
  #hud { padding: calc(var(--u) * 2); }
  .hud-right { gap: 5px; }
  #overlay { position: fixed; inset: 0; }
  .scrim { padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); }
  .dialog { padding: 10px 14px; gap: 12px; max-width: 100%; max-height: 100%; border-radius: 10px;
    box-shadow: 0 0 0 2px var(--ink), 0 0 0 5px var(--gold), 0 0 0 7px var(--ink), 0 8px 0 4px rgba(0,0,0,.35);
    overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .dialog h2 { margin-bottom: 6px; font-size: 13px; }
  .portrait { width: 64px; }
  .msg-body { font-size: 16px; line-height: 1.35; }
  .btn { min-height: 48px; padding: .35em 1em; font-size: 16px; }
  .btn-row { margin-top: 8px; gap: 10px; }
  .speak { top: -4px; right: -4px; font-size: 22px; min-width: 40px; min-height: 40px; }

  /* question card: portrait left, prompt + choices right, all choices in one row where they fit */
  .question { min-width: min(100%, 600px); align-items: flex-start; }
  .question .portrait { width: 56px; }
  .q-head { margin-bottom: 2px; gap: 8px; }
  .q-title, .q-intro { font-size: 14px; }
  .q-intro { margin: 2px 0; }
  .q-prompt { font-size: 17px; margin: 2px 0 6px; }
  .visual { margin: 4px 0 8px; padding: 5px 8px; gap: 8px; }
  .visual canvas { width: 30px; }
  .v-picture canvas { width: 60px; }
  .v-text { font-size: 28px; }
  .v-text.long { font-size: 17px; line-height: 1.3; }
  .seq { min-width: 40px; min-height: 40px; font-size: 17px; }
  .choices { gap: 8px; }
  .choices.n4 { --cols: 4; }
  .choice { min-height: 52px; padding: 6px 10px 6px 24px; font-size: 17px; box-shadow: 0 0 0 3px var(--ink), 0 4px 0 var(--ink); }
  .choice canvas { width: 36px; }
  .choice .num { left: 6px; top: 4px; }
  .hint { margin-top: 6px; min-height: 1.3em; font-size: 15px; }
  .hint .good { font-size: 17px; }

  /* panels scroll inside; the close button stays pinned top-right while they do */
  .panel { min-width: min(100%, 440px); }
  .panel.wide { min-width: min(100%, 720px); }
  .panel > .close { position: sticky; top: 0; align-self: flex-end; flex: none; margin: -4px -8px -38px 0;
    box-shadow: 0 0 0 3px var(--cream); }
  .options { gap: 6px; }
  .panel > .options, .panel > .setup { margin-right: 40px; } /* right-hand controls never slide under the pinned ✕ */
  .opt { gap: 12px; min-height: 40px; }
  .opt input[type="checkbox"] { width: 28px; height: 28px; }
  .opt select { min-height: 40px; }
  .setup { gap: 8px; }
  .step > canvas { width: 52px !important; }
  .how { gap: 8px; }
  .shop-head canvas { width: 56px; }
  .shop-head h2 { margin-bottom: 2px; }
  .coins-line { margin: 6px 0; }
  .shop-list { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
  .item, .shop-item { padding: 6px 10px; }
  .shop-item .btn { min-width: 64px; }
  .map-canvas { width: min(100%, 460px); }
  .stats { gap: 2px 14px; }
  .rank { margin: 8px 0; }
  #banner { top: 26%; }
  .b-sub { font-size: calc(var(--u) * 10); }
}
@media (max-height: 400px) {
  .question .portrait { width: 48px; }
  .dialog h2 { font-size: 12px; }
}

/* ---------------------------------------------------------------- "turn your phone sideways" */
#rotate { display: none; }
body.rotate-needed #rotate { position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; text-align: center; color: var(--cream);
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  background: radial-gradient(ellipse at 50% 38%, #3b2f7a 0%, #1d1b4a 55%, #0d0b1e 100%); animation: fadeIn .3s ease-out both; }
body.rotate-needed #app, body.rotate-needed #touch { visibility: hidden; }
.rot-phone { position: relative; width: 64px; height: 112px; margin-bottom: 18px; background: var(--purple-l); border: 4px solid var(--ink);
  clip-path: polygon(4px 0, calc(100% - 4px) 0, calc(100% - 4px) 4px, 100% 4px, 100% calc(100% - 4px), calc(100% - 4px) calc(100% - 4px),
    calc(100% - 4px) 100%, 4px 100%, 4px calc(100% - 4px), 0 calc(100% - 4px), 0 4px, 4px 4px);
  animation: rotPhone 3.2s steps(1, end) infinite; }
.rot-phone::after { content: ''; position: absolute; left: 50%; bottom: 4px; width: 8px; height: 4px; margin-left: -4px; background: var(--ink); }
.rot-screen { position: absolute; left: 4px; right: 4px; top: 8px; bottom: 14px; overflow: hidden; background: #8fd0f7; }
/* the picture is drawn landscape and turned a quarter, so it only looks right once the phone is sideways */
.rot-screen > .rot-land { position: absolute; left: 50%; top: 50%; width: 82px; height: 48px; transform: translate(-50%, -50%) rotate(90deg);
  background: linear-gradient(#8fd0f7 0 70%, #45a84b 70% 100%); }
.rot-land::before { content: ''; position: absolute; left: 30%; width: 44%; bottom: 30%; height: 52%; background: #5b4aa0;
  clip-path: polygon(40% 0, 60% 0, 60% 25%, 70% 25%, 70% 50%, 85% 50%, 85% 75%, 100% 75%, 100% 100%, 0 100%, 0 75%, 15% 75%, 15% 50%, 30% 50%, 30% 25%, 40% 25%); }
.rot-hero { position: absolute; left: 16%; bottom: 22%; width: 6px; height: 10px; background: linear-gradient(var(--gold) 0 30%, #f4c89a 30% 50%, var(--red) 50% 100%);
  animation: rotHop .8s steps(2, end) infinite; }
@keyframes rotPhone {
  0% { transform: rotate(0deg); } 30% { transform: rotate(-30deg); } 36% { transform: rotate(-60deg); }
  42%, 88% { transform: rotate(-90deg); } 94% { transform: rotate(-45deg); }
}
@keyframes rotHop { 50% { transform: translateY(-4px); } }
.rot-title { margin: 0; font-family: var(--pix); font-size: 15px; line-height: 1.6; color: var(--gold); text-shadow: 3px 3px 0 var(--ink); }
.rot-sub { margin: 0; max-width: 300px; font-size: 17px; line-height: 1.45; }
.rot-skip { margin-top: 18px; min-height: 44px; padding: 8px 16px; background: none; border: 0; color: rgba(255,244,214,.7);
  font-size: 15px; text-decoration: underline; text-underline-offset: 3px; }
@media (prefers-reduced-motion: reduce) { .rot-phone { animation: none; transform: rotate(-90deg); } .rot-hero { animation: none; } }

/* ---------------------------------------------------------------- on-screen touch controls (js/touch.js) */
.touch-controls { --tc-pad: clamp(108px, 30vh, 156px); --tc-btn: clamp(52px, 15vh, 72px);
  --tc-bg: rgba(26,28,44,.42); --tc-line: rgba(255,244,214,.8); --tc-on: rgba(242,201,58,.92);
  --tc-notch: polygon(3px 0, calc(100% - 3px) 0, calc(100% - 3px) 3px, 100% 3px, 100% calc(100% - 3px), calc(100% - 3px) calc(100% - 3px),
    calc(100% - 3px) 100%, 3px 100%, 3px calc(100% - 3px), 0 calc(100% - 3px), 0 3px, 3px 3px);
  --tc-arrow: polygon(42.9% 0, 57.1% 0, 57.1% 25%, 71.4% 25%, 71.4% 50%, 85.7% 50%, 85.7% 75%, 100% 75%, 100% 100%,
    0 100%, 0 75%, 14.3% 75%, 14.3% 50%, 28.6% 50%, 28.6% 25%, 42.9% 25%);
  position: fixed; inset: auto 0 0 0; z-index: 30; display: none; justify-content: space-between; align-items: flex-end; pointer-events: none;
  padding: 0 calc(env(safe-area-inset-right, 0px) + 8px) calc(env(safe-area-inset-bottom, 0px) + 8px) calc(env(safe-area-inset-left, 0px) + 8px);
  transition: opacity .25s;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
body.touch[data-mode="play"]:not(.touch-off) .touch-controls { display: flex; }
body:has(#overlay .scrim) .touch-controls { display: none !important; }
/* keep toasts between the D-pad and the buttons (measured against the letterbox the stage leaves at the sides) */
body.touch[data-mode="play"]:not(.touch-off) #toasts {
  width: calc(100% - 2 * max(8px, clamp(108px, 30vh, 156px) + 16px + env(safe-area-inset-left, 0px) - (100vw - var(--u) * 384) / 2)); }
body.touch-ghost .touch-controls { opacity: .28; }
body.touch-ghost .touch-controls * { pointer-events: none !important; }
body.touch-ghost[data-mode="play"] #toasts { width: 90%; }
.tc-dpad { position: relative; width: var(--tc-pad); height: var(--tc-pad); display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  pointer-events: none; touch-action: none; }
.tc-dpad > * { pointer-events: auto; }
.tc-btn, .mg-touch .tp { position: relative; display: grid; place-items: center; background: var(--tc-bg, rgba(26,28,44,.52));
  box-shadow: inset 0 0 0 3px var(--tc-line, rgba(255,244,214,.85)), inset 0 -5px 0 3px rgba(0,0,0,.28);
  clip-path: var(--tc-notch); color: var(--cream); transition: transform .06s, background .1s; }
.tc-arrow::before, .mg-touch :is(.tp-left, .tp-right, .tp-up, .tp-down)::before, .tc-jump-ico {
  content: ''; width: 42%; aspect-ratio: 7 / 4; background: var(--cream); clip-path: var(--tc-arrow); filter: drop-shadow(0 2px 0 var(--ink)); }
/* the D-pad reads as one cross: each arm is outlined on its three outer sides only, with pixel-notched outer corners */
.tc-arrow { --L: var(--tc-line); }
.tc-up { grid-area: 1 / 2; clip-path: polygon(3px 0, calc(100% - 3px) 0, calc(100% - 3px) 3px, 100% 3px, 100% 100%, 0 100%, 0 3px, 3px 3px);
  box-shadow: inset 3px 0 0 var(--L), inset -3px 0 0 var(--L), inset 0 3px 0 var(--L); }
.tc-down { grid-area: 3 / 2; clip-path: polygon(0 0, 100% 0, 100% calc(100% - 3px), calc(100% - 3px) calc(100% - 3px), calc(100% - 3px) 100%, 3px 100%, 3px calc(100% - 3px), 0 calc(100% - 3px));
  box-shadow: inset 3px 0 0 var(--L), inset -3px 0 0 var(--L), inset 0 -3px 0 var(--L), inset 0 -8px 0 rgba(0,0,0,.2); }
.tc-left { grid-area: 2 / 1; clip-path: polygon(3px 0, 100% 0, 100% 100%, 3px 100%, 3px calc(100% - 3px), 0 calc(100% - 3px), 0 3px, 3px 3px);
  box-shadow: inset 0 3px 0 var(--L), inset 0 -3px 0 var(--L), inset 3px 0 0 var(--L), inset 0 -8px 0 rgba(0,0,0,.2); }
.tc-right { grid-area: 2 / 3; clip-path: polygon(0 0, calc(100% - 3px) 0, calc(100% - 3px) 3px, 100% 3px, 100% calc(100% - 3px), calc(100% - 3px) calc(100% - 3px), calc(100% - 3px) 100%, 0 100%);
  box-shadow: inset 0 3px 0 var(--L), inset 0 -3px 0 var(--L), inset -3px 0 0 var(--L), inset 0 -8px 0 rgba(0,0,0,.2); }
.tc-left::before { transform: rotate(-90deg); }
.tc-right::before { transform: rotate(90deg); }
.tc-down::before { transform: rotate(180deg); }
.tc-hub { grid-area: 2 / 2; position: relative;
  background: linear-gradient(var(--tc-line) 0 0) 0 0 / 3px 3px no-repeat, linear-gradient(var(--tc-line) 0 0) 100% 0 / 3px 3px no-repeat,
    linear-gradient(var(--tc-line) 0 0) 0 100% / 3px 3px no-repeat, linear-gradient(var(--tc-line) 0 0) 100% 100% / 3px 3px no-repeat, var(--tc-bg); }
.tc-hub::after { content: ''; position: absolute; left: 50%; top: 50%; width: 22%; height: 22%; transform: translate(-50%, -50%);
  background: rgba(255,244,214,.3); clip-path: var(--tc-notch); }
.tc-arrow.on { --L: var(--ink); }
.tc-btn.on, .mg-touch .tp.on { background: var(--tc-on, rgba(242,201,58,.92)); }
.tc-round.on, .mg-touch .tp.on { transform: translateY(2px); box-shadow: inset 0 0 0 3px var(--ink), inset 0 4px 0 3px rgba(0,0,0,.18); }
.tc-btn.on::before, .tc-btn.on .tc-jump-ico, .mg-touch .tp.on::before { background: var(--ink); filter: none; }
.tc-acts { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; }
.tc-round { width: var(--tc-btn); height: var(--tc-btn); padding: 0; border: 0; pointer-events: auto; touch-action: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.tc-jump { width: calc(var(--tc-btn) * 1.1); height: calc(var(--tc-btn) * 1.1); }
.tc-round b { font-family: var(--pix); font-weight: 400; font-size: calc(var(--tc-btn) * .3); line-height: 1; text-shadow: 0 2px 0 var(--ink); }
.tc-round small { font-family: var(--chunky); font-weight: 700; font-size: 13px; line-height: 1; letter-spacing: .04em; opacity: .9; }
.tc-jump-ico { display: block; width: 44%; }
.tc-btn.on b, .tc-btn.on small { color: var(--ink); text-shadow: none; }
@media (prefers-reduced-motion: reduce) { .tc-btn, .mg-touch .tp { transition: none; } }

/* ---------------------------------------------------------------- mini-game key legend & touch pad (js/minigames/controls.js) */
.mg-legend { position: absolute; left: 50%; bottom: calc(var(--u) * 2); transform: translateX(-50%); z-index: 3; display: flex; gap: calc(var(--u) * 3.5);
  white-space: nowrap; padding: calc(var(--u) * 1) calc(var(--u) * 3.2); border-radius: 8px; background: rgba(26,28,44,.72); color: var(--cream);
  font-family: var(--chunky); font-size: var(--fs-sm); box-shadow: 0 0 0 2px rgba(255,244,214,.25); pointer-events: none; }
.mg-legend span { display: inline-flex; align-items: center; gap: 2px; }
.mg-legend kbd { color: var(--ink); font-size: .9em; }
.mg-touch { --tc-bg: rgba(26,28,44,.52); --tc-line: rgba(255,244,214,.85); --tc-on: rgba(242,201,58,.92);
  --tc-notch: polygon(3px 0, calc(100% - 3px) 0, calc(100% - 3px) 3px, 100% 3px, 100% calc(100% - 3px), calc(100% - 3px) calc(100% - 3px),
    calc(100% - 3px) 100%, 3px 100%, 3px calc(100% - 3px), 0 calc(100% - 3px), 0 3px, 3px 3px);
  --tc-arrow: polygon(42.9% 0, 57.1% 0, 57.1% 25%, 71.4% 25%, 71.4% 50%, 85.7% 50%, 85.7% 75%, 100% 75%, 100% 100%,
    0 100%, 0 75%, 14.3% 75%, 14.3% 50%, 28.6% 50%, 28.6% 25%, 42.9% 25%);
  --tp: max(50px, calc(var(--u) * 17));
  position: absolute; left: 0; right: 0; bottom: calc(var(--u) * 3); z-index: 3; display: flex; justify-content: space-between; align-items: flex-end;
  padding: 0 calc(var(--u) * 3); pointer-events: none; touch-action: none; user-select: none; -webkit-user-select: none; }
.mg-touch .tp { width: var(--tp); height: var(--tp); padding: 0; border: 0; pointer-events: auto; touch-action: none;
  font-family: var(--chunky); font-weight: 700; font-size: max(15px, calc(var(--u) * 5)); }
.mg-touch :is(.tp-left, .tp-right, .tp-up, .tp-down) { font-size: 0; }
.mg-touch .tp-left::before { transform: rotate(-90deg); }
.mg-touch .tp-right::before { transform: rotate(90deg); }
.mg-touch .tp-down::before { transform: rotate(180deg); }
.tp-dpad { display: flex; gap: 6px; align-items: flex-end; }
.tp-dpad:has(.tp-up), .tp-dpad:has(.tp-down) { display: grid; gap: 0; grid-template: repeat(3, var(--tp)) / repeat(3, var(--tp)); }
.tp-dpad:has(.tp-up) .tp-up, .tp-dpad:has(.tp-down) .tp-up { grid-area: 1 / 2; }
.tp-dpad:has(.tp-up) .tp-left, .tp-dpad:has(.tp-down) .tp-left { grid-area: 2 / 1; }
.tp-dpad:has(.tp-up) .tp-right, .tp-dpad:has(.tp-down) .tp-right { grid-area: 2 / 3; }
.tp-dpad:has(.tp-up) .tp-down, .tp-dpad:has(.tp-down) .tp-down { grid-area: 3 / 2; }
.tp-acts { display: flex; gap: 10px; align-items: flex-end; }
.mg-touch .tp-jump { margin-bottom: calc(var(--tp) * .45); }
.mg-touch .tp-act, .mg-touch .tp-jump { width: calc(var(--tp) * 1.2); height: calc(var(--tp) * 1.2); text-shadow: 0 2px 0 var(--ink); }
.mg-touch .tp.on { color: var(--ink); text-shadow: none; }
@media (max-height: 480px) { .mg-touch { --tp: max(50px, calc(var(--u) * 15)); } }
/* mini-games: toasts sit above the key legend, or between the touch pads */
body[data-mode="minigame"] #toasts { bottom: calc(var(--u) * 14); }
body.touch[data-mode="minigame"] #toasts { bottom: calc(var(--u) * 4); width: calc(100% - 6 * max(50px, var(--u) * 15) - var(--u) * 6 - 24px); }

/* ---------------------------------------------------------------- Detective Board (pinboard) */
.board { --cork: #b7844f; display: flex; flex-direction: column; gap: 14px; padding: 16px; border-radius: 8px; color: var(--ink);
  background:
    radial-gradient(circle at 20% 30%, rgba(90,50,20,.35) 0 1px, transparent 1.5px) 0 0 / 9px 11px,
    radial-gradient(circle at 70% 60%, rgba(255,230,180,.28) 0 1px, transparent 1.5px) 0 0 / 13px 7px,
    radial-gradient(circle at 40% 80%, rgba(70,40,15,.3) 0 1.2px, transparent 1.8px) 3px 2px / 17px 15px,
    linear-gradient(135deg, #c39159, #a97440 60%, #b88550);
  box-shadow: inset 0 0 0 6px #7a4f28, inset 0 0 0 8px #5a3818, inset 0 0 24px 8px rgba(60,30,10,.45), 0 0 0 3px var(--ink); }
.board h2 { margin: 0 44px 0 0; display: inline-block; align-self: flex-start; background: var(--cream); padding: 6px 12px; transform: rotate(-1.5deg);
  box-shadow: 0 3px 0 rgba(0,0,0,.25); }
.board-clues { display: flex; flex-wrap: wrap; gap: 10px 14px; margin: 0; padding: 0; list-style: none; }
.board-clues > * { position: relative; flex: 1 1 200px; max-width: 360px; padding: 12px 12px 10px; font-size: var(--fs-sm); line-height: 1.35;
  background: #fffbe6 repeating-linear-gradient(transparent 0 calc(1.35em - 1px), rgba(80,120,200,.25) calc(1.35em - 1px) 1.35em) 0 22px / 100% calc(100% - 22px) no-repeat;
  box-shadow: 0 0 0 1px rgba(0,0,0,.15), 2px 4px 0 rgba(0,0,0,.25); transform: rotate(-.8deg); }
.board-clues > *:nth-child(even) { transform: rotate(.9deg); background-color: #fff3c4; }
.board-clues > *::before, .card::before { content: ''; position: absolute; left: 50%; top: -5px; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%; z-index: 2;
  background: radial-gradient(circle at 35% 35%, #ff9d8f 0 2px, var(--red) 3px, #8e211b 6px); box-shadow: 1px 2px 0 rgba(0,0,0,.35); }
.board-rooms { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.board-room { padding: 8px 10px 10px; background: rgba(255,244,214,.18); border: 2px dashed rgba(255,244,214,.45); border-radius: 6px; }
.board-room h3 { margin: 0 0 8px; font-family: var(--chunky); font-size: var(--fs-sm); color: var(--cream); text-shadow: 1px 2px 0 rgba(0,0,0,.5); }
.board-room .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 12px 10px; }
.card { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 4px; min-height: 48px; min-width: 48px;
  padding: 10px 6px 6px; border: 0; border-radius: 2px; background: #fffdf4; color: var(--ink); font-family: var(--body);
  box-shadow: 0 0 0 1px rgba(0,0,0,.18), 2px 4px 0 rgba(0,0,0,.28); transform: rotate(-1.2deg); transition: transform .12s, box-shadow .12s; }
.card:nth-child(3n+2) { transform: rotate(1.4deg); }
.card:nth-child(3n) { transform: rotate(-.4deg); }
.card canvas { width: 100%; max-width: 64px; height: auto; image-rendering: pixelated; }
.card-label { font-size: 14px; font-weight: 700; line-height: 1.15; text-align: center; overflow-wrap: anywhere; }
.card:hover { transform: rotate(0) translateY(-2px); }
.card:focus-visible { outline: 4px solid #fff; outline-offset: 3px; box-shadow: 0 0 0 1px rgba(0,0,0,.18), 0 0 0 10px var(--purple), 2px 4px 0 10px rgba(0,0,0,.28); z-index: 3; }
.card.selected { background: #fff4b0; transform: rotate(0) scale(1.06); z-index: 2; box-shadow: 0 0 0 3px var(--ink), 0 0 0 6px var(--gold), 3px 6px 0 4px rgba(0,0,0,.3); }
.card.maybe { background: #fff1a8; }
.card.maybe::after { content: '?'; position: absolute; right: -6px; top: -6px; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%;
  font-family: var(--pix); font-size: 11px; background: var(--gold); box-shadow: 0 0 0 2px var(--ink); z-index: 2; }
.card.crossed { background: #e9e2cf; }
.card.crossed canvas, .card.crossed .card-label { opacity: .45; filter: grayscale(.7); }
.card.crossed::after { content: ''; position: absolute; inset: 4px; z-index: 2; pointer-events: none;
  background:
    linear-gradient(45deg, transparent calc(50% - 4px), var(--red) calc(50% - 4px) calc(50% + 4px), transparent calc(50% + 4px)),
    linear-gradient(-45deg, transparent calc(50% - 4px), var(--red) calc(50% - 4px) calc(50% + 4px), transparent calc(50% + 4px));
  filter: drop-shadow(1px 1px 0 #7a1a14); }
.board-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; align-items: center; }
.board-actions .btn { min-height: 48px; }
@media (hover: none) { .card:hover { transform: rotate(-1.2deg); } }
@media (max-height: 480px) {
  .board { padding: 10px; gap: 10px; }
  .board-rooms { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
  .board-room .cards { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 10px 8px; }
  .card canvas { max-width: 44px; }
  .board-clues > * { padding: 10px 10px 8px; }
}
@media (prefers-reduced-motion: reduce) { .card { transition: none; } }

/* ---------------------------------------------------------------- save slots */
.slot-list { display: flex; flex-direction: column; gap: 10px; }
.slot-wrap { display: flex; gap: 8px; align-items: stretch; }
.slot { flex: 1; display: flex; gap: 14px; align-items: center; text-align: left; background: #fff; border: 0; border-radius: 12px;
  padding: 10px 14px; min-height: 72px; box-shadow: 0 0 0 3px var(--ink), 0 5px 0 var(--ink); font-family: var(--body); color: var(--ink); }
.slot:hover:not(:disabled) { background: #fff7d6; transform: translateY(-1px); }
.slot:focus-visible { outline: 3px solid var(--purple); outline-offset: 3px; }
.slot.empty { justify-content: space-between; background: #f6ecd2; box-shadow: 0 0 0 3px var(--cream-d); }
.slot.empty:disabled { opacity: .55; cursor: default; }
.slot-num { font-family: var(--pix); font-size: clamp(8px, calc(var(--u) * 2.8), 12px); color: var(--purple); }
.slot-empty { font-weight: 700; font-size: var(--fs); color: #8a6a3a; }
.slot-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.slot-name { font-weight: 700; font-size: var(--fs-lg); line-height: 1.1; }
.slot-place { font-size: var(--fs-sm); color: var(--purple); font-weight: 700; }
.slot-treasures { display: flex; gap: 4px; margin: 2px 0; }
.slot-treasures canvas { background: #f6ecd2; border-radius: 6px; }
.slot-treasures canvas.missing { opacity: .5; }
.slot-meta { font-size: .8em; opacity: .75; }
.slot-del { flex: none; width: 52px; border: 0; border-radius: 12px; background: #f3d6d0; font-size: 20px; box-shadow: 0 0 0 3px var(--ink); }
.slot-del:hover { background: #f3b0a8; }
@media (max-height: 480px) { .slot { min-height: 56px; padding: 6px 10px; } .slot-treasures { display: none; } }

/* ---------------------------------------------------------------- one clear highlight in dialogs
   The focused button IS the highlighted one (hover moves focus), so it gets the strongest look;
   the gold "default" button only looks special until something else is highlighted. */
.scrim .btn:focus, .scrim .choice:focus, .scrim .slot:focus, .scrim .seg-btn:focus, .scrim .card:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--ink), 0 0 0 7px #7b5cff, 0 6px 0 3px var(--ink) !important;
  transform: translateY(-2px);
}
.scrim .choice:focus { background: #fff4b0; }
.scrim .btn { position: relative; }
.scrim .btn:focus { padding-left: 1.7em; }
.scrim .btn:focus::before { content: '▶'; position: absolute; left: .55em; top: 50%; transform: translateY(-50%); font-size: .7em; }
.scrim .btn-row:focus-within .btn.primary:not(:focus) { background: var(--cream); }

/* Link back to the Treasure collection hub (title screen footer). */
.menu-foot .all-games { color: var(--cream); text-decoration: none; border-bottom: 1px dotted rgba(255,244,214,.5); }
.menu-foot .all-games:hover, .menu-foot .all-games:focus-visible { color: var(--gold); outline: none; }

/* ---------------------------------------------------------------- painting easel (js/paint.js) */
.easel { --easel-size: clamp(200px, calc(var(--u) * 116), 460px); --sw: clamp(34px, calc(var(--u) * 12.5), 46px);
  display: flex; flex-direction: column; gap: 10px; }
.easel h2 { margin: 0 44px 0 0; }
.easel-body { display: flex; gap: 16px; align-items: flex-start; justify-content: center; }
.easel-tools { display: grid; grid-template-columns: 1fr; gap: 9px; }
.easel-tool, .easel-stamp { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 4px 6px;
  background: #fff; color: var(--ink); border: 0; border-radius: 10px; box-shadow: 0 0 0 3px var(--ink), 0 4px 0 var(--ink);
  transition: transform .08s, background .12s; }
.easel-tool { min-width: clamp(58px, calc(var(--u) * 21), 80px); min-height: 52px; font-family: var(--chunky); font-weight: 700; font-size: var(--fs-sm); line-height: 1; }
.easel-ico canvas { display: block; width: clamp(28px, calc(var(--u) * 10), 40px); height: auto; }
.easel-tool:active:not(:disabled), .easel-stamp:active { transform: translateY(3px); box-shadow: 0 0 0 3px var(--ink), 0 1px 0 var(--ink); }
.easel-tool.on, .easel-stamp.on { background: var(--gold); }
.easel-tool:disabled { opacity: .45; cursor: default; }
/* the canvas sits on a little wooden easel board */
.easel-stand { flex: none; padding: 8px; border-radius: 6px; background: linear-gradient(#b0753f, #8a5a2a);
  box-shadow: 0 0 0 3px var(--ink), inset 0 2px 0 rgba(255,255,255,.3), inset 0 -3px 0 rgba(0,0,0,.25), 0 6px 0 rgba(0,0,0,.25); }
.easel-canvas { display: block; width: var(--easel-size); height: var(--easel-size); background: var(--cream);
  box-shadow: 0 0 0 3px var(--ink); touch-action: none; cursor: crosshair; }
.easel-side { display: flex; flex-direction: column; gap: 12px; }
.easel-palette { display: grid; grid-template-columns: repeat(4, var(--sw)); gap: 7px; }
.easel-swatch { width: var(--sw); height: var(--sw); padding: 0; border: 0; border-radius: 8px; background: var(--c);
  box-shadow: 0 0 0 3px var(--ink), inset 0 -4px 0 rgba(0,0,0,.18); transition: transform .08s; }
.easel-swatch.on { transform: scale(1.08); box-shadow: 0 0 0 3px var(--ink), 0 0 0 6px var(--gold), 0 0 0 8px var(--ink), inset 0 0 0 3px #fff; }
.easel-stamps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.easel-stamp { min-height: 46px; padding: 4px; }
.easel-stamp canvas { display: block; width: auto; height: clamp(26px, calc(var(--u) * 9), 36px); }
.easel-actions { margin-top: auto; justify-content: stretch; flex-wrap: nowrap; gap: 10px; }
.easel-actions .btn { flex: 1; padding: .45em .7em; white-space: nowrap; }
.easel-keys { margin: 0; text-align: center; font-size: 14px; line-height: 1.9; }
.easel-keys kbd { margin: 0 1px; }
.scrim .easel-tool:focus, .scrim .easel-stamp:focus, .scrim .easel-swatch:focus { outline: none; z-index: 1;
  box-shadow: 0 0 0 3px var(--ink), 0 0 0 7px #7b5cff, 0 6px 0 3px var(--ink); }
.scrim .easel-swatch:focus { box-shadow: 0 0 0 3px var(--ink), 0 0 0 7px #7b5cff, inset 0 0 0 3px #fff; }
.scrim .easel-canvas:focus { outline: none; }
.easel-stand:focus-within { box-shadow: 0 0 0 3px var(--ink), 0 0 0 7px #7b5cff, inset 0 2px 0 rgba(255,255,255,.3), inset 0 -3px 0 rgba(0,0,0,.25); }
@media (hover: hover) { .easel-tool:hover:not(:disabled), .easel-stamp:hover { background: #fff7d6; } .easel-tool.on:hover, .easel-stamp.on:hover { background: var(--gold); } }
@media (pointer: coarse) { .easel-keys { display: none; } }
@media (max-height: 480px) {
  .easel { --easel-size: min(calc(100dvh - 92px), 300px); --sw: 32px; gap: 6px; }
  .easel h2 { margin-bottom: 0; }
  .easel-body { gap: 12px; }
  .easel-tools { gap: 7px; }
  .easel-tool { min-width: 54px; min-height: 44px; }
  .easel-lbl { font-size: 12px; }
  .easel-ico canvas { width: 26px; }
  .easel-stand { padding: 5px; }
  .easel-side { gap: 9px; }
  .easel-palette { gap: 6px; }
  .easel-stamp { min-height: 40px; }
  .easel-stamp canvas { height: 24px; }
  .easel-keys { display: none; }
}
@media (prefers-reduced-motion: reduce) { .easel-tool, .easel-stamp, .easel-swatch { transition: none; } }

/* Bonus games cabinet panel */
.bonus .bonus-icon { font-size: calc(var(--u) * 10); width: calc(var(--u) * 14); text-align: center; }
.bonus .shop-item.locked .bonus-icon { filter: grayscale(.6); opacity: .8; }

/* Dev jump screen (?dev or ` on the title screen) */
.dev-btn { position: absolute; left: calc(var(--u) * 2); bottom: calc(var(--u) * 2); z-index: 60; }
.dev h3 { margin: calc(var(--u) * 3) 0 calc(var(--u) * 1); font-size: var(--fs-sm); }
.dev-row { display: flex; flex-wrap: wrap; gap: calc(var(--u) * 1.2); align-items: center; }
.dev-row .btn { min-height: 0; padding: .3em .7em; font-size: var(--fs-sm); }
.dev-sec { border-top: 2px dashed var(--cream-d); margin-top: calc(var(--u) * 2); }
