/* Brickhollow UI. Kid-first: big readable text (Lexend), chunky brick
 * buttons with studs, high contrast, every control keyboard/pad reachable.
 * Theme tokens mirror THEME in main.js. */

@font-face { font-family: "Lexend"; src: url("fonts/lexend-400.woff2") format("woff2"); font-weight: 400; font-display: block; }
@font-face { font-family: "Lexend"; src: url("fonts/lexend-500.woff2") format("woff2"); font-weight: 500; font-display: block; }
@font-face { font-family: "Lexend"; src: url("fonts/lexend-600.woff2") format("woff2"); font-weight: 600; font-display: block; }
@font-face { font-family: "Lexend"; src: url("fonts/lexend-700.woff2") format("woff2"); font-weight: 700; font-display: block; }
@font-face { font-family: "Lexend"; src: url("fonts/lexend-800.woff2") format("woff2"); font-weight: 800; font-display: block; }
@font-face { font-family: "Cinzel Decorative"; src: url("fonts/cinzel-decorative-900.woff2") format("woff2"); font-weight: 900; font-display: block; }
@font-face { font-family: "Cinzel"; src: url("fonts/cinzel-500.woff2") format("woff2"); font-weight: 500; font-display: block; }

:root {
  --bg: #0f1a2c;
  --surface: rgba(18, 30, 52, 0.9);
  --surface2: rgba(30, 46, 76, 0.95);
  --edge: #3a5584;
  --ink: #fbf7ea;
  --muted: #b9c6db;
  --accent: #ffd23f;
  --reward: #ffd23f;
  --danger: #ff5d5d;
  --good: #57d977;
  --blue: #4aa8ff;
  --parch: #f8eed3;
  --parch-ink: #3a2a18;
  --font-ui: "Lexend", system-ui, sans-serif;
  --font-title: "Cinzel Decorative", "Cinzel", serif;
  --text-s: 0.95rem;
  --text-m: 1.15rem;
  --text-l: 1.6rem;
  --text-xl: 2.6rem;
  --space: 0.5rem;
  --radius: 14px;
  --read-scale: 1;
}
html.large-text { --read-scale: 1.18; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font-family: var(--font-ui); }
button { font-family: inherit; }
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; }
.hidden { display: none !important; }

#vignette { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.28) 100%); }
#flash { position: fixed; inset: 0; pointer-events: none; opacity: 0; background: #fff; }
#vignette.hurt { background: radial-gradient(ellipse at center, transparent 45%, rgba(220,30,30,0.45) 100%); }

a.back { position: fixed; left: 12px; bottom: 10px; color: var(--muted); font-size: 0.85rem; text-decoration: none; z-index: 60; opacity: 0.8; }
a.back:hover, a.back:focus-visible { color: var(--accent); opacity: 1; }
a.back.ingame { bottom: auto; top: auto; left: auto; right: 12px; bottom: 8px; }

:focus-visible { outline: 4px solid var(--accent); outline-offset: 3px; }

.kbd {
  display: inline-flex; align-items: center; justify-content: center; min-width: 1.7em; height: 1.7em;
  padding: 0 0.4em; border-radius: 6px; background: #f5f0e0; color: #2a2a2a; font-weight: 700;
  font-size: 0.85em; box-shadow: inset 0 -3px 0 rgba(0,0,0,0.25); margin-right: 0.35em;
}

/* ---------------------------------------------------------- brick buttons */
.bbtn {
  --c: #2f6fd0;
  position: relative; border: 0; cursor: pointer; color: #fff; font-weight: 700; font-size: 1.25rem;
  padding: 0.75em 1.3em 0.7em; min-height: 52px; border-radius: 10px; background: var(--c);
  box-shadow: inset 0 -7px 0 rgba(0,0,0,0.22), inset 0 3px 0 rgba(255,255,255,0.25), 0 5px 0 rgba(0,0,0,0.35);
  text-shadow: 0 2px 0 rgba(0,0,0,0.25); transition: transform 0.08s, filter 0.12s;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4em;
}
.bbtn::before {
  content: ""; position: absolute; top: -7px; left: 16%; right: 16%; height: 8px; border-radius: 5px 5px 0 0;
  background: radial-gradient(ellipse 9px 7px at 25% 100%, var(--c) 96%, transparent 100%),
              radial-gradient(ellipse 9px 7px at 75% 100%, var(--c) 96%, transparent 100%);
  filter: brightness(1.12);
}
.bbtn:hover, .bbtn:focus-visible { filter: brightness(1.12); transform: translateY(-2px); }
.bbtn:active { transform: translateY(3px); box-shadow: inset 0 -3px 0 rgba(0,0,0,0.22), 0 2px 0 rgba(0,0,0,0.35); }
.bbtn svg { width: 1.2em; height: 1.2em; fill: currentColor; }
.bbtn.gold { --c: #e8a818; color: #3a2400; text-shadow: 0 1px 0 rgba(255,255,255,0.4); }
.bbtn.green { --c: #2f9e44; }
.bbtn.blue { --c: #2f6fd0; }
.bbtn.purple { --c: #7a4bb0; }
.bbtn.red { --c: #c8342a; }
.bbtn.tan { --c: #c9a46a; color: #3a2400; text-shadow: none; }
.bbtn.small { font-size: 0.95rem; min-height: 40px; padding: 0.45em 0.9em; }
.bbtn.big { font-size: 1.5rem; padding: 0.8em 1.8em; }
.bbtn:disabled { filter: grayscale(0.8) brightness(0.8); cursor: default; transform: none; }

.icon-btn {
  width: 48px; height: 48px; border-radius: 12px; border: 0; cursor: pointer;
  background: #2f6fd0; color: #fff; display: inline-flex; align-items: center; justify-content: center;
  box-shadow: inset 0 -5px 0 rgba(0,0,0,0.22), 0 3px 0 rgba(0,0,0,0.3); flex: none;
}
.icon-btn svg { width: 28px; height: 28px; fill: currentColor; }
.icon-btn.speaking { background: #e8a818; color: #3a2400; animation: pulse 0.9s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }

/* ---------------------------------------------------------- screens */
.screen { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; z-index: 40; }
.screen.show { display: flex; }
.screen.dim { background: rgba(8, 14, 26, 0.55); backdrop-filter: blur(3px); }
.panel {
  background: var(--surface); border: 3px solid var(--edge); border-radius: 20px; padding: 1.4rem 1.8rem;
  box-shadow: 0 18px 50px rgba(0,0,0,0.45); max-height: 92vh; overflow: auto; max-width: min(94vw, 980px);
}
.panel h2 { font-family: var(--font-title); font-size: 2rem; margin: 0 0 1rem; text-align: center; color: var(--accent); letter-spacing: 0.02em; }
.menu { display: flex; flex-direction: column; gap: 1.1rem; align-items: stretch; min-width: 300px; margin: 1.2rem auto 0; }
.row-btns { display: flex; justify-content: center; gap: 1rem; margin-top: 1.2rem; }
.hint { color: var(--muted); font-size: var(--text-s); text-align: center; }

#loading { background: radial-gradient(ellipse at 50% 40%, #24406e, #0f1a2c 70%); flex-direction: column; gap: 1.2rem; z-index: 80; }
.loadbar { width: 360px; height: 18px; border-radius: 9px; background: #0b1322; border: 2px solid var(--edge); overflow: hidden; }
.loadbar i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, #e8a818, #ffe27a); transition: width 0.2s; }
#loadtext { color: var(--muted); font-size: 1.1rem; }

.logo {
  font-family: var(--font-title); font-weight: 900; font-size: clamp(3rem, 9vw, 6.4rem); line-height: 1;
  background: linear-gradient(180deg, #fff6c4 0%, #ffd23f 45%, #d98a10 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 0 #6b3a06) drop-shadow(0 10px 18px rgba(0,0,0,0.5)); text-align: center; letter-spacing: 0.02em;
}
.logo.small { font-size: 3rem; }
.subtitle { font-family: "Cinzel", serif; font-size: clamp(1.1rem, 2.4vw, 1.7rem); text-align: center; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,0.7); margin-top: 0.5rem; letter-spacing: 0.08em; }
#title { background: linear-gradient(180deg, rgba(10,20,40,0.15), rgba(10,20,40,0.55)); }
.title-wrap { display: flex; flex-direction: column; align-items: center; }
#title .menu { min-width: 320px; }
#title .hint { margin-top: 1.4rem; text-shadow: 0 1px 4px #000; color: #e8eef8; }

/* ---------------------------------------------------------- creator */
#creator { justify-content: flex-start; padding-left: 4vw; }
.creator-panel { width: min(520px, 90vw); }
.field { display: flex; flex-direction: column; gap: 0.4rem; font-weight: 600; font-size: 1.1rem; margin-bottom: 1rem; }
.field input { font: 700 1.6rem var(--font-ui); padding: 0.4em 0.6em; border-radius: 10px; border: 3px solid var(--edge); background: #0b1322; color: var(--ink); }
.field input:focus { border-color: var(--accent); outline: none; }
.opt-rows { display: flex; flex-direction: column; gap: 0.9rem; }
.opt-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.opt-row > span { font-weight: 600; font-size: 1.05rem; }
.swatches { display: flex; gap: 0.45rem; flex-wrap: wrap; justify-content: flex-end; }
.swatch { width: 42px; height: 42px; border-radius: 9px; border: 3px solid transparent; cursor: pointer; box-shadow: inset 0 -5px 0 rgba(0,0,0,0.2); position: relative; }
.swatch.on { border-color: #fff; transform: scale(1.1); }
.swatch.on::after { content: ""; position: absolute; inset: 9px; border-radius: 50%; background: rgba(255,255,255,0.7); }
.seg { display: flex; gap: 0.35rem; }
.seg button { font: 600 1rem var(--font-ui); padding: 0.55em 0.8em; border-radius: 9px; border: 2px solid var(--edge); background: #0b1322; color: var(--ink); cursor: pointer; min-height: 44px; }
.seg button.on { background: var(--accent); color: #2a1a00; border-color: var(--accent); }

/* ---------------------------------------------------------- HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.hud-tl { position: absolute; left: 18px; top: 16px; display: flex; flex-direction: column; gap: 10px; }
.hearts { display: flex; gap: 4px; }
.hearts svg { width: 38px; height: 38px; fill: #e8312f; filter: drop-shadow(0 2px 0 #6a0c0c) drop-shadow(0 3px 4px rgba(0,0,0,0.4)); }
.hearts svg.empty { fill: #2b1e28; filter: drop-shadow(0 2px 0 #000); opacity: 0.8; }
.hearts svg.pop { animation: heartpop 0.35s; }
@keyframes heartpop { 50% { transform: scale(1.35); } }
.counters { display: flex; gap: 12px; }
.counter { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border-radius: 999px; padding: 5px 14px 5px 8px; font-weight: 700; font-size: 1.35rem; font-variant-numeric: tabular-nums; border: 2px solid var(--edge); }
.counter svg { width: 30px; height: 30px; }
.counter.studs svg { fill: #cfd6e0; color: #cfd6e0; }
.counter.gold svg { fill: #ffc21a; }
.counter small { color: var(--muted); font-size: 0.9rem; font-weight: 600; }
.counter.bump { animation: bump 0.3s; }
@keyframes bump { 40% { transform: scale(1.18); } }
.tracker { background: var(--surface); border-radius: 12px; border-left: 5px solid var(--accent); padding: 10px 14px; max-width: 360px; font-size: calc(1.05rem * var(--read-scale)); }
.tracker .qtitle { display: flex; align-items: center; gap: 8px; color: var(--accent); font-weight: 700; font-size: calc(1.12rem * var(--read-scale)); }
.tracker .qtitle svg { width: 20px; height: 20px; fill: var(--accent); flex: none; }
.tracker ul { margin: 6px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 3px; }
.tracker li { display: flex; gap: 8px; align-items: center; }
.tracker li::before { content: ""; width: 14px; height: 14px; border: 2px solid var(--muted); border-radius: 3px; flex: none; }
.tracker li.done { color: var(--muted); text-decoration: line-through; }
.tracker li.done::before { background: var(--good); border-color: var(--good); }
.tracker .dist { color: var(--muted); font-size: 0.85rem; margin-left: auto; font-variant-numeric: tabular-nums; }

.hud-tr { position: absolute; right: 18px; top: 16px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.minimap { position: relative; width: 200px; height: 200px; border-radius: 50%; overflow: hidden; border: 5px solid #e9d9a6; box-shadow: 0 0 0 3px #6b4a1a, 0 6px 18px rgba(0,0,0,0.45); background: #1d6fc0; }
.minimap canvas { width: 100%; height: 100%; display: block; }
.north { position: absolute; top: 3px; left: 50%; transform: translateX(-50%); background: #1b1b1b; color: #fff; font-weight: 800; font-size: 0.8rem; border-radius: 5px; padding: 1px 6px; }
.region-name { background: var(--surface); border-radius: 999px; padding: 4px 14px; font-weight: 600; font-size: 1rem; border: 2px solid var(--edge); }

.controls-hint { position: absolute; left: 18px; bottom: 34px; background: var(--surface); border-radius: 12px; padding: 10px 14px; display: flex; flex-direction: column; gap: 6px; font-size: 1rem; transition: opacity 0.5s; }
.controls-hint.fade { opacity: 0; }
.prompt { position: absolute; left: 50%; bottom: 17%; transform: translateX(-50%); background: var(--surface); border: 3px solid var(--accent); border-radius: 999px; padding: 10px 22px 10px 12px; font-size: calc(1.3rem * var(--read-scale)); font-weight: 600; display: flex; align-items: center; animation: promptin 0.2s; }
@keyframes promptin { from { transform: translate(-50%, 10px); opacity: 0; } }

.bossbar { position: absolute; left: 50%; top: 18px; transform: translateX(-50%); width: min(560px, 60vw); text-align: center; font-family: var(--font-title); font-size: 1.3rem; text-shadow: 0 2px 4px #000; }
.bossbar .bar { height: 18px; margin-top: 6px; border-radius: 9px; background: #1a0f26; border: 3px solid #d8c07a; overflow: hidden; }
.bossbar .bar i { display: block; height: 100%; background: linear-gradient(90deg, #9a4dff, #e05cff); transition: width 0.25s; }
.riftbar { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; background: var(--surface); padding: 8px 16px; border-radius: 999px; font-weight: 700; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.riftbar .xp { width: 280px; height: 14px; border-radius: 7px; background: #0b1322; overflow: hidden; }
.riftbar .xp i { display: block; height: 100%; background: linear-gradient(90deg, #4aa8ff, #9ef3ff); }

/* toasts + banners */
#toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 50; pointer-events: none; }
.toast { background: var(--surface2); border: 2px solid var(--edge); border-radius: 999px; padding: 10px 20px; font-weight: 600; font-size: calc(1.15rem * var(--read-scale)); animation: toastin 0.25s; display: flex; align-items: center; gap: 8px; }
.toast svg { width: 24px; height: 24px; fill: var(--accent); }
.toast.out { animation: toastout 0.3s forwards; }
@keyframes toastin { from { transform: translateY(-14px); opacity: 0; } }
@keyframes toastout { to { transform: translateY(-14px); opacity: 0; } }
.banner { position: fixed; left: 50%; top: 30%; transform: translate(-50%, -50%); text-align: center; z-index: 45; pointer-events: none; animation: bannerin 0.5s cubic-bezier(.2,1.6,.4,1); }
.banner-icon svg { width: 110px; height: 110px; fill: #ffc21a; filter: drop-shadow(0 6px 0 #7a4a00) drop-shadow(0 0 30px rgba(255,210,63,0.8)); animation: spinY 1.6s ease-in-out infinite; }
.banner-title { font-family: var(--font-title); font-size: clamp(2.2rem, 6vw, 4rem); color: #ffe27a; text-shadow: 0 4px 0 #6b3a06, 0 8px 20px rgba(0,0,0,0.6); }
.banner-sub { font-size: calc(1.4rem * var(--read-scale)); font-weight: 600; text-shadow: 0 2px 6px #000; margin-top: 6px; }
@keyframes bannerin { from { transform: translate(-50%, -50%) scale(0.3); opacity: 0; } }
@keyframes spinY { 50% { transform: scaleX(-1); } }
.banner.out { animation: toastout 0.4s forwards; }
.region-banner { position: fixed; left: 50%; top: 22%; transform: translateX(-50%); font-family: var(--font-title); font-size: clamp(2rem, 5vw, 3.4rem); color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,0.5), 0 0 24px rgba(0,0,0,0.6); pointer-events: none; z-index: 30; animation: regionin 3.2s forwards; white-space: nowrap; }
.region-banner small { display: block; font-family: var(--font-ui); font-size: 1.1rem; text-align: center; letter-spacing: 0.3em; opacity: 0.85; }
@keyframes regionin { 0% { opacity: 0; letter-spacing: 0.3em; } 15%, 75% { opacity: 1; letter-spacing: 0.05em; } 100% { opacity: 0; } }

/* ---------------------------------------------------------- readable text */
.readable { font-size: calc(1.35rem * var(--read-scale)); line-height: 1.55; letter-spacing: 0.01em; }
.readable .w { cursor: pointer; border-radius: 5px; padding: 0 1px; transition: background 0.1s; }
.readable .w:hover { background: rgba(255, 210, 63, 0.25); }
.readable .w.hl { background: #ffd23f; color: #2a1a00; }
.readable .w.target { font-weight: 800; text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: 4px; }

/* ---------------------------------------------------------- dialogue */
.dialog {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); width: min(900px, 94vw); z-index: 20;
  display: flex; gap: 16px; align-items: stretch; background: var(--surface); border: 3px solid var(--edge); border-radius: 18px;
  padding: 14px; box-shadow: 0 12px 40px rgba(0,0,0,0.45); animation: promptin 0.2s;
}
.portrait { width: 128px; height: 128px; border-radius: 14px; background: radial-gradient(circle at 50% 35%, #5b7fb8, #22365c); flex: none; overflow: hidden; border: 3px solid #e9d9a6; }
.portrait canvas { width: 100%; height: 100%; }
.dialog-body { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.nameplate { color: var(--accent); font-weight: 800; font-size: 1.25rem; }
.dialog .readable { min-height: 3.2em; }
.dialog-foot { display: flex; align-items: center; gap: 12px; margin-top: auto; }
.dialog-foot .next { margin-left: auto; color: var(--muted); font: 600 1rem var(--font-ui); animation: nudge 1.2s infinite; background: none; border: 0; cursor: pointer; padding: 8px 10px; }
html.touch .dialog-foot .next { background: #e8a818; color: #3a2400; border-radius: 12px; padding: 10px 22px; font-size: 1.15rem; box-shadow: inset 0 -5px 0 rgba(0,0,0,0.2), 0 3px 0 rgba(0,0,0,0.3); min-height: 48px; }
@keyframes nudge { 50% { transform: translateX(4px); } }
.choices-inline { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------------------------------------------------------- quiz card */
.quiz { position: fixed; inset: 0; z-index: 46; display: flex; align-items: center; justify-content: center; background: rgba(8, 14, 26, 0.35); }
.card {
  width: min(760px, 94vw); max-height: 94vh; overflow: auto; background: var(--parch); color: var(--parch-ink);
  border-radius: 22px; border: 5px solid #8a5a2a; box-shadow: 0 0 0 4px #e9c77a, 0 20px 60px rgba(0,0,0,0.55);
  padding: 18px 24px 20px; animation: cardin 0.35s cubic-bezier(.2,1.4,.4,1); position: relative;
}
@keyframes cardin { from { transform: scale(0.7) rotate(-2deg); opacity: 0; } }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.card-tag { font-family: "Cinzel", serif; font-weight: 500; font-size: 1.15rem; letter-spacing: 0.08em; text-transform: uppercase; color: #8a5a2a; }
.card .story { color: #4a3620; text-align: center; }
.card .passage { background: #fff8e6; border-radius: 12px; padding: 12px 16px; border: 2px dashed #d7b98a; margin: 6px 0 10px; text-align: left; }
.card .passage:empty, .card .story:empty { display: none; }
.prompt-big { font-size: calc(2.1rem * var(--read-scale)); font-weight: 700; text-align: center; margin: 8px 0 12px; line-height: 1.3; }
.prompt-big.math { font-size: 3.2rem; letter-spacing: 0.03em; font-variant-numeric: tabular-nums; }
.visual { display: block; margin: 0 auto 10px; max-width: 100%; background: #fff8e6; border-radius: 12px; border: 2px solid #e2c89a; }
.answers { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 18px; margin-top: 12px; }
.answers.four { grid-template-columns: repeat(4, 1fr); }
.answers .bbtn { font-size: calc(1.55rem * var(--read-scale)); min-height: 70px; --c: #25497e; padding: 0.5em 0.6em; }
.answers .bbtn.long { font-size: calc(1.15rem * var(--read-scale)); }
.answers .bbtn .num { position: absolute; left: 8px; top: 6px; font-size: 0.75rem; opacity: 0.7; font-weight: 600; }
.answers .bbtn.right { --c: #2f9e44; animation: pop 0.4s; }
.answers .bbtn.wrong { --c: #b8453a; animation: shake 0.4s; opacity: 0.75; }
.answers .bbtn.right::after, .answers .bbtn.wrong::after { content: ""; width: 26px; height: 26px; margin-left: 6px; background: currentColor; flex: none;
  -webkit-mask: var(--m) center/contain no-repeat; mask: var(--m) center/contain no-repeat; }
.answers .bbtn.right::after { --m: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M4 12.5l5 5L20 6.5' fill='none' stroke='black' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'/></svg>"); }
.answers .bbtn.wrong::after { --m: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M6 6l12 12M18 6L6 18' fill='none' stroke='black' stroke-width='3.4' stroke-linecap='round'/></svg>"); }
@keyframes pop { 50% { transform: scale(1.12); } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.quiz-foot { display: flex; align-items: center; gap: 14px; margin-top: 16px; min-height: 48px; }
.feedback { font-size: calc(1.2rem * var(--read-scale)); font-weight: 600; flex: 1; }
.feedback.good { color: #1d7a34; }
.feedback.try { color: #9a3a1a; }
.card .icon-btn { background: #8a5a2a; }

/* word bricks */
.wb-build { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 18px 0 10px; }
.wb-slot { min-width: 150px; padding: 16px 24px; border-radius: 10px; font-size: 2rem; font-weight: 800; text-align: center; background: #2f9e44; color: #fff; box-shadow: inset 0 -7px 0 rgba(0,0,0,0.22), 0 5px 0 rgba(0,0,0,0.3); }
.wb-slot:not(.given) { background: #fff8e6; color: #8a5a2a; border: 3px dashed #c9a46a; box-shadow: none; }
.wb-slot.filled { background: #e8a818; color: #3a2400; border: 0; animation: pop 0.4s; }
.wb-plus { font-size: 2.4rem; font-weight: 800; color: #8a5a2a; }
.answers.bricks .bbtn { --c: #c8342a; }
.answers.bricks .bbtn:nth-child(2) { --c: #2f6fd0; }
.answers.bricks .bbtn:nth-child(3) { --c: #7a4bb0; }
.answers.bricks .bbtn:nth-child(4) { --c: #2f9e44; }

/* ---------------------------------------------------------- menus */
.pause-panel { min-width: 380px; }
.pause-stats { display: flex; justify-content: center; gap: 1.2rem; margin-top: 1.2rem; color: var(--muted); font-weight: 600; flex-wrap: wrap; }
.settings-body, .parents-body { display: flex; flex-direction: column; gap: 0.9rem; min-width: min(640px, 86vw); }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; font-size: 1.1rem; font-weight: 500; min-height: 44px; }
.set-row input[type=range] { width: 240px; accent-color: var(--accent); height: 28px; }
.set-row .val { width: 3.2em; text-align: right; font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 700; }
.toggle { width: 64px; height: 36px; border-radius: 18px; border: 0; background: #33415a; position: relative; cursor: pointer; flex: none; }
.toggle::after { content: ""; position: absolute; top: 4px; left: 4px; width: 28px; height: 28px; border-radius: 50%; background: #cfd6e0; transition: left 0.15s; }
.toggle.on { background: var(--good); }
.toggle.on::after { left: 32px; background: #fff; }
.set-head { font-family: "Cinzel", serif; color: var(--accent); font-size: 1.15rem; margin-top: 0.6rem; border-bottom: 2px solid var(--edge); padding-bottom: 4px; }
.skill-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px 16px; }
.skill { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,0.04); border-radius: 10px; padding: 6px 10px; }
.skill .name { flex: 1; font-size: 0.98rem; }
.skill .lvl { font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.skill .acc { width: 64px; height: 8px; border-radius: 4px; background: #0b1322; overflow: hidden; }
.skill .acc i { display: block; height: 100%; background: var(--good); }
.parent-note { color: var(--muted); font-size: 0.95rem; line-height: 1.5; }
.stat-cards { display: flex; gap: 12px; flex-wrap: wrap; }
.stat-card { flex: 1; min-width: 140px; background: rgba(255,255,255,0.05); border-radius: 12px; padding: 10px 14px; }
.stat-card b { display: block; font-size: 1.8rem; color: var(--accent); font-variant-numeric: tabular-nums; }

.journal-body { min-width: min(620px, 86vw); display: flex; flex-direction: column; gap: 10px; }
.jq { background: rgba(255,255,255,0.05); border-radius: 12px; padding: 10px 14px; }
.jq h3 { margin: 0 0 4px; font-size: 1.15rem; color: var(--accent); }
.jq.done h3 { color: var(--good); }
.jq p { margin: 0; color: var(--muted); }
.jgroup { font-family: "Cinzel", serif; color: var(--muted); margin-top: 6px; }

.map-panel { display: flex; flex-direction: column; align-items: center; }
#bigmap { width: min(640px, 70vh); height: min(640px, 70vh); border-radius: 16px; border: 5px solid #e9d9a6; background: #1d6fc0; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; margin-top: 10px; color: var(--muted); font-weight: 600; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }

.shop-studs { text-align: center; font-size: 1.4rem; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px; }
.shop-studs svg { width: 32px; height: 32px; fill: #cfd6e0; }
.shop-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; min-width: min(760px, 86vw); }
.shop-item { background: rgba(255,255,255,0.05); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 6px; border: 2px solid transparent; }
.shop-item h3 { margin: 0; font-size: 1.15rem; }
.shop-item p { margin: 0; color: var(--muted); font-size: 0.98rem; flex: 1; }
.shop-item .buy { align-self: flex-start; }
.shop-item.owned { border-color: var(--good); }
.shop-item .price { display: inline-flex; align-items: center; gap: 4px; }

.ending-stats { display: flex; gap: 14px; margin: 24px 0 8px; flex-wrap: wrap; justify-content: center; }
#ending { background: radial-gradient(ellipse at center, rgba(40,20,70,0.25), rgba(8,14,26,0.7)); }

html.rm *, html.rm *::before, html.rm *::after { animation-duration: 0.001s !important; animation-iteration-count: 1 !important; transition-duration: 0.001s !important; }

@media (max-width: 1100px) {
  .minimap { width: 150px; height: 150px; }
  .hearts svg { width: 30px; height: 30px; }
  .tracker { max-width: 290px; }
}

/* ---------------------------------------------------------- touch (iOS) */
html, body { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
input { -webkit-user-select: text; user-select: text; }
#touch { position: fixed; inset: 0; z-index: 12; pointer-events: none; }
#touch .tzone { position: absolute; top: 0; bottom: 0; pointer-events: auto; touch-action: none; }
#touch .tleft { left: 0; width: 45%; }
#touch .tright { right: 0; width: 55%; }
#touch .stick { position: fixed; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; background: rgba(255,255,255,0.12); border: 3px solid rgba(255,255,255,0.45); pointer-events: none; }
#touch .knob { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; border-radius: 50%; background: rgba(255,255,255,0.8); box-shadow: 0 3px 10px rgba(0,0,0,0.35); transform: translate(-50%, -50%); }
#touch .tbtn { position: fixed; pointer-events: auto; touch-action: none; border: 0; border-radius: 50%; color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: inset 0 -6px 0 rgba(0,0,0,0.25), 0 4px 0 rgba(0,0,0,0.3); font: 700 0.8rem var(--font-ui); opacity: 0.88; }
#touch .tbtn svg { width: 46%; height: 46%; fill: currentColor; }
#touch .tbtn.down { transform: translateY(3px) scale(0.95); opacity: 1; }
#touch .jump { width: 92px; height: 92px; right: calc(28px + env(safe-area-inset-right)); bottom: calc(30px + env(safe-area-inset-bottom)); background: #2f9e44; }
#touch .sword { width: 84px; height: 84px; right: calc(134px + env(safe-area-inset-right)); bottom: calc(22px + env(safe-area-inset-bottom)); background: #c8342a; }
#touch .use { width: 72px; height: 72px; right: calc(48px + env(safe-area-inset-right)); bottom: calc(140px + env(safe-area-inset-bottom)); background: #2f6fd0; }
#touch .use span { font-size: 0.72rem; margin-top: -4px; }
#touch .use.ready { background: #e8a818; color: #3a2400; animation: pulse 0.9s infinite; opacity: 1; }
#touch .mini { width: 52px; height: 52px; background: rgba(18,30,52,0.85); border: 2px solid var(--edge); box-shadow: none; }
#touch .pausebtn { top: calc(12px + env(safe-area-inset-top)); left: calc(50% + 6px); }
#touch .mapbtn { top: calc(12px + env(safe-area-inset-top)); left: calc(50% - 58px); }
#touch .viewbtn { top: calc(12px + env(safe-area-inset-top)); left: calc(50% + 70px); }
html.fp #touch .viewbtn { background: #e8a818; color: #3a2400; }
/* first person: a small aiming dot */
#crosshair { position: fixed; left: 50%; top: 50%; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px rgba(0,0,0,0.45); pointer-events: none; z-index: 5; display: none; }
html.fp #crosshair { display: block; }

html.touch .controls-hint { display: none; }
html.touch #prompt { pointer-events: auto; cursor: pointer; bottom: calc(40% + env(safe-area-inset-bottom)); }
html.touch .kbd.keyonly, html.touch .answers .bbtn .num { display: none; }
html.touch a.back.ingame { display: none; }
.next .t { display: none; }
html.touch .next .k { display: none; }
html.touch .next .t { display: inline; }

/* notch / home indicator */
.hud-tl { left: calc(18px + env(safe-area-inset-left)); top: calc(16px + env(safe-area-inset-top)); }
.hud-tr { right: calc(18px + env(safe-area-inset-right)); top: calc(16px + env(safe-area-inset-top)); }

/* small landscape screens (phones) */
@media (max-height: 520px) {
  :root { --text-xl: 2rem; }
  .hearts svg { width: 24px; height: 24px; }
  .counter { font-size: 1rem; padding: 3px 10px 3px 6px; }
  .counter svg { width: 22px; height: 22px; }
  .tracker { max-width: 250px; padding: 6px 10px; font-size: 0.85rem; }
  .tracker .qtitle { font-size: 0.92rem; }
  .minimap { width: 118px; height: 118px; border-width: 4px; }
  .region-name { font-size: 0.8rem; padding: 2px 10px; }
  #touch .pausebtn, #touch .mapbtn { width: 46px; height: 46px; }
  #touch .mapbtn { left: calc(50% - 56px); }
  #touch .viewbtn { width: 46px; height: 46px; left: calc(50% + 62px); }
  #touch .jump { width: 78px; height: 78px; }
  #touch .sword { width: 70px; height: 70px; right: calc(118px + env(safe-area-inset-right)); }
  #touch .use { width: 62px; height: 62px; bottom: calc(118px + env(safe-area-inset-bottom)); }
  .dialog { bottom: calc(8px + env(safe-area-inset-bottom)); padding: 8px; gap: 10px; width: min(760px, 92vw); }
  .portrait { width: 76px; height: 76px; }
  .dialog .readable { font-size: calc(1.05rem * var(--read-scale)); min-height: 2.6em; }
  .nameplate { font-size: 1rem; }
  .icon-btn { width: 40px; height: 40px; }
  .card { padding: 8px 14px 10px; border-width: 4px; max-height: 96vh; }
  .card-tag { font-size: 0.85rem; }
  .card-head { margin-bottom: 0; }
  .card .icon-btn { width: 36px; height: 36px; }
  .visual { max-height: 26vh; width: auto; }
  .quiz-foot { min-height: 40px; }
  .quiz-foot .bbtn.small { min-height: 36px; padding: 0.3em 0.7em; }
  .feedback { font-size: calc(0.95rem * var(--read-scale)); }
  .creator-panel { max-height: 96vh; }
  .creator-panel h2 { display: none; }
  .creator-panel .row-btns { position: sticky; bottom: -0.8rem; background: var(--surface2); margin: 0.6rem -1.1rem -0.8rem; padding: 0.6rem; border-radius: 0 0 18px 18px; }
  .field { margin-bottom: 0.5rem; font-size: 0.95rem; }
  .readable { font-size: calc(1.05rem * var(--read-scale)); line-height: 1.45; }
  .prompt-big { font-size: calc(1.4rem * var(--read-scale)); margin: 4px 0 6px; }
  .prompt-big.math { font-size: 2.2rem; }
  .answers { gap: 10px 12px; margin-top: 6px; }
  .answers .bbtn { min-height: 52px; font-size: calc(1.2rem * var(--read-scale)); }
  .quiz-foot { margin-top: 8px; }
  .panel { padding: 0.8rem 1.1rem; }
  .panel h2 { font-size: 1.4rem; margin-bottom: 0.5rem; }
  .menu { gap: 0.7rem; }
  .bbtn { font-size: 1.05rem; min-height: 44px; padding: 0.5em 1em; }
  .logo { font-size: clamp(2.4rem, 8vw, 4rem); }
  .banner-icon svg { width: 70px; height: 70px; }
  .creator-panel { width: min(460px, 60vw); }
  .field input { font-size: 1.2rem; }
  .swatch { width: 34px; height: 34px; }
  .opt-rows { gap: 0.5rem; }
  #bigmap { width: min(480px, 64vh); height: min(480px, 64vh); }
}

/* phones held upright: ask to turn sideways */
#rotate { position: fixed; inset: 0; z-index: 90; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(ellipse at 50% 40%, #24406e, #0f1a2c 70%); text-align: center; padding: 24px; font-size: 1.3rem; font-weight: 600; }
#rotate svg { width: 96px; height: 96px; fill: var(--accent); animation: turn 2.4s ease-in-out infinite; }
@keyframes turn { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) and (max-width: 640px) { html.touch #rotate { display: flex; } }
