*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* Light: sandstone halls by daylight */
  --bg: #efe5d0;
  --bg-warm: #e3d5b8;
  --ink: #33281e;
  --ink-light: #85775f;
  --ink-muted: #b3a385;
  --accent: #b5562f;
  --accent-hover: #984423;
  --filled: #5b7ab8;
  --mark: #d4c6a8;
  --grid-line: #9a8a6e;
  --grid-thick: #33281e;
  --cell-bg: #fbf5e8;
  /* Canvas: dungeon walls, stone floors, shelves */
  --wall: #cbb893;
  --wall-line: #b39f78;
  --alcove: #8a7556;
  --stone: #a8977a;
  --stone-dark: #8f7f64;
  --stone-top: #c4b391;
  --stone-line: #7d6e55;
  --stone-edge: #4a3e2e;
  --wood: #7a4f2c;
  --scroll: #f0e2bd;
  --shadow: rgba(40, 25, 10, 0.55);
  --vignette: 0.22;
  --radius: 6px;
  --max-w: 760px;
}

/* Dark: torchlit dungeon */
html.dark {
  --bg: #12100e;
  --bg-warm: #1d1915;
  --ink: #ecdfc4;
  --ink-light: #8f8169;
  --ink-muted: #574d3f;
  --accent: #e08a3c;
  --accent-hover: #c47230;
  --filled: #3a5a9e;
  --mark: #2e2821;
  --grid-line: #5c5244;
  --grid-thick: #8f826c;
  --cell-bg: #1f1b17;
  --wall: #2a241e;
  --wall-line: #1c1814;
  --alcove: #15110d;
  --stone: #4a4238;
  --stone-dark: #3b342c;
  --stone-top: #5f5547;
  --stone-line: #2c2620;
  --stone-edge: #14110e;
  --wood: #5a3a20;
  --scroll: #cdb98c;
  --shadow: rgba(0, 0, 0, 0.85);
  --vignette: 0.6;
}

html { background: var(--bg); overscroll-behavior-y: none; }

/* No double-tap zoom (iOS Safari ignores user-scalable, but honours this) */
html { touch-action: manipulation; }

body {
  font-family: 'DM Mono', monospace;
  touch-action: manipulation;
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  overscroll-behavior-y: none;
  /* Installed on iOS the status bar overlays the page (black-translucent) */
  padding-top: env(safe-area-inset-top, 0px);
}

/* ── Top bar: title + icons ── */
.top-bar {
  width: 100%;
  max-width: var(--max-w);
  padding: 0.75rem 1rem 0.25rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

h1 {
  font-family: 'Cinzel', 'Fraunces', serif;
  font-weight: 800;
  font-size: 1.4rem;
  letter-spacing: 0.02em;
  color: var(--ink);
}

h1 span { color: var(--accent); }
/* Logo from the poster lettering: the two words side by side, a touch tilted */
h1.logo { display: flex; align-items: center; gap: 0.25em; line-height: 0; margin: 0; }
h1.logo img { height: 1.35em; width: auto; filter: drop-shadow(1px 2px 0 rgba(0, 0, 0, 0.35)); }
h1.logo img:first-child { transform: rotate(-3deg); }
h1.logo img:last-child { transform: rotate(-2deg); }

.timer-info {
  font-size: 0.8rem;
  color: var(--ink-light);
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.icon-btn {
  border: none;
  background: none;
  padding: 0.2rem;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: var(--ink-light);
}
.icon-btn:hover { border: none; color: var(--ink); }
#pauseBtn { font-size: 0.7rem; letter-spacing: -0.15em; }

/* ── Spacer pushes content toward bottom on mobile ── */
.mobile-spacer { flex: 1 1 auto; }

/* ── Top controls (seed) ── */
.top-controls {
  width: 100%;
  max-width: var(--max-w);
  padding: 0.25rem 1rem 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.controls-row input[type="text"] {
  font-family: 'DM Mono', monospace;
  font-size: 0.85rem;
  padding: 0.45rem 0.65rem;
  border: 1.5px solid var(--grid-line);
  border-radius: var(--radius);
  background: var(--cell-bg);
  color: var(--ink);
  flex: 1;
  min-width: 0;
  outline: none;
  transition: border-color 0.15s;
}
.controls-row input[type="text"]:focus { border-color: var(--accent); }
.controls-row input[type="text"]::placeholder { color: var(--ink-muted); }

button {
  font-family: 'DM Mono', monospace;
  font-size: 0.85rem;
  padding: 0.45rem 0.65rem;
  border: 1.5px solid var(--grid-line);
  border-radius: var(--radius);
  background: var(--cell-bg);
  color: var(--ink);
  cursor: pointer;
  transition: all 0.15s;
}

button:hover { border-color: var(--accent); color: var(--accent); }
button:active { transform: scale(0.97); }
.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.hud-icon { display: none; }
.upgrade-btn {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-width: 1px;
  white-space: nowrap;
  color: var(--ink-light);
  background: none;
}
.upgrade-btn.ready { border-color: #d9a520; color: #d9a520; background: rgba(217, 165, 32, 0.12); }
.upgrade-btn.free { animation: pulse-glow 1.2s ease-in-out infinite; }
.upg-badge:not(:empty) { margin-left: 0.35rem; padding: 0 0.3rem; border-radius: 999px; background: #d9a520; color: #16161a; font-weight: 500; }
@keyframes pulse-glow { 50% { box-shadow: 0 0 0 3px rgba(217, 165, 32, 0.35); } }

/* ── Upgrade shop ── */
.modal-box.shop-box { max-width: min(460px, calc(100vw - 2rem)); text-align: left; }
.shop-sub { font-size: 0.8rem; color: var(--ink-light); margin-bottom: 0.6rem; }
.shop-list { display: flex; flex-direction: column; gap: 0.45rem; margin-bottom: 0.75rem; }
.shop-row { display: grid; grid-template-columns: 1.8rem 1fr auto; align-items: center; gap: 0.6rem; padding: 0.45rem 0.6rem; border: 1px solid var(--grid-line); border-radius: var(--radius); }
.shop-icon { font-size: 1.25rem; text-align: center; }
.shop-name { font-family: 'Cinzel', 'Fraunces', serif; font-weight: 800; font-size: 0.9rem; color: var(--ink); display: flex; gap: 0.5rem; align-items: baseline; }
.shop-pips { font-family: 'DM Mono', monospace; font-weight: 400; font-size: 0.7rem; color: #d9a520; letter-spacing: 0.1em; }
.shop-text { text-align: left; min-width: 0; }
.shop-desc { font-size: 0.72rem; color: var(--ink-light); line-height: 1.35; }
.shop-list[hidden], .wheel-box[hidden] { display: none; }
.wheel-box { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; margin-bottom: 0.75rem; }
.wheel-canvas { width: min(280px, 78vw); height: min(280px, 78vw); }
.wheel-side { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.6rem; }
.wheel-spin { min-width: 10rem; }
.wheel-spin:disabled { opacity: 0.5; cursor: default; }
.wheel-spin-quiz { border-color: #a46be0; color: #c9a0f0; }
.wheel-spin-quiz[hidden] { display: none; }
.wheel-result { min-height: 2.6em; font-size: 0.8rem; text-align: center; color: var(--ink); line-height: 1.35; }
.wheel-result b { color: var(--accent); font-weight: 500; }
.shop-buy { min-width: 4.6rem; font-size: 0.8rem; padding: 0.35rem 0.6rem; white-space: nowrap; }
.shop-buy:disabled { opacity: 0.5; cursor: default; }
.sound-wrap { position: relative; display: flex; }
.sound-panel {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: -0.5rem;
  z-index: 50;
  min-width: 15rem;
  padding: 0.6rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  border: 1px solid var(--grid-line);
  border-radius: var(--radius);
  background: var(--bg-warm);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  font-size: 0.75rem;
  color: var(--ink);
}
.sound-row { display: grid; grid-template-columns: 4.2rem 1fr 2.6rem; align-items: center; gap: 0.4rem; }
.sound-row output { text-align: right; color: var(--ink-light); font-variant-numeric: tabular-nums; }
.sound-row input[type="range"] { width: 100%; accent-color: var(--accent); }
.sound-check { display: flex; gap: 0.4rem; cursor: pointer; }
.sound-check input { accent-color: var(--accent); }
.icon-btn.muted { opacity: 0.4; text-decoration: line-through; }
/* ── Tutorial ── */
.modal-box.tut-box { position: relative; max-width: min(520px, calc(100vw - 2rem)); width: 100%; text-align: left; }
.tut-kicker { font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-light); margin-bottom: 0.5rem; }
.tut-canvas { display: block; width: 100%; height: 150px; border-radius: var(--radius); border: 1px solid var(--grid-line); margin-bottom: 0.75rem; }
.tut-title { text-align: left; margin-bottom: 0.4rem; }
.tut-text { font-size: 0.85rem; line-height: 1.5; color: var(--ink); min-height: 6.5em; text-align: left; }
.tut-text b { color: var(--accent); font-weight: 500; }
.tut-keys { display: inline-block; margin-top: 0.4rem; font-size: 0.75rem; color: var(--ink-light); }
.tut-dots { display: flex; justify-content: center; gap: 0.4rem; margin: 0.75rem 0 0.25rem; }
.tut-dot { width: 0.6rem; height: 0.6rem; padding: 0; border-radius: 50%; border: 1px solid var(--grid-line); background: none; }
.tut-dot.on { background: var(--accent); border-color: var(--accent); }
.tut-actions { justify-content: space-between; }
.tut-actions button:disabled { opacity: 0.4; cursor: default; }
.tut-close { position: absolute; top: 0.5rem; right: 0.6rem; border: none; background: none; font-size: 1.4rem; line-height: 1; padding: 0.2rem 0.4rem; color: var(--ink-light); }
.tut-start-btn {
  position: absolute;
  top: 0.6rem;
  left: calc(0.75rem + 8px);
  z-index: 2;
  font-family: 'Lilita One', 'Cinzel', sans-serif;
  font-size: 0.95rem;
  padding: 0.3rem 0.8rem;
  border: 2px solid #16161a;
  border-radius: 999px;
  background: #f4a414;
  color: #16161a;
  box-shadow: 0 3px 0 #16161a;
}
.tut-start-btn:hover { background: #ffb72e; color: #16161a; }
.tut-start-btn[hidden] { display: none; }
/* ── Install to home screen ── */
#installBtn[hidden] { display: none; }
.install-box { max-width: min(400px, calc(100vw - 2rem)); }
.install-steps { text-align: left; font-size: 0.85rem; line-height: 1.5; margin-bottom: 0.75rem; }
.install-steps ol { padding-left: 1.3rem; margin: 0.5rem 0 0; }
.install-steps li { margin: 0.25rem 0; }
.install-steps b { color: var(--accent); font-weight: 500; }
.ios-share { display: inline-block; border: 1.5px solid currentColor; border-top: none; padding: 0 0.2rem; font-size: 0.75rem; }
/* ── Wardrobe ── */
.modal-box.wardrobe-box { max-width: min(560px, calc(100vw - 1rem)); width: 100%; text-align: left; }
.wardrobe-sub { font-size: 0.78rem; color: var(--ink-light); }
.wardrobe-sub b { color: var(--accent); font-weight: 500; }
.wardrobe-body { display: flex; flex-direction: column; gap: 0.6rem; }
.wardrobe-canvas { width: 100%; height: 150px; border-radius: var(--radius); border: 1px solid var(--grid-line); flex: none; }
.wardrobe-head { font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-light); margin-top: 0.2rem; }
.wardrobe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(7.2rem, 1fr)); gap: 0.35rem; }
.wardrobe-item { display: grid; grid-template-columns: 1.6rem 1fr; grid-template-rows: auto auto; column-gap: 0.4rem; align-items: center; text-align: left; padding: 0.35rem 0.45rem; font-size: 0.75rem; }
.wardrobe-icon { grid-row: 1 / 3; width: 1.6rem; height: 1.6rem; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; border: 1px solid var(--grid-line); }
.wardrobe-name { font-weight: 500; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wardrobe-status { font-size: 0.65rem; color: var(--ink-light); }
.wardrobe-item.worn { border-color: var(--accent); background: rgba(224, 138, 60, 0.14); }
.wardrobe-item.worn .wardrobe-status { color: var(--accent); }
.wardrobe-item.picked { border-color: #d9a520; box-shadow: 0 0 0 2px rgba(217, 165, 32, 0.35); }
.wardrobe-item.picked .wardrobe-status { color: #d9a520; }
.wardrobe-item.locked { opacity: 0.7; }
.wardrobe-buy { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin-top: 0.5rem; padding: 0.4rem 0.55rem; border: 1px solid #d9a520; border-radius: var(--radius); background: rgba(217, 165, 32, 0.08); font-size: 0.8rem; }
.wardrobe-buy[hidden] { display: none; }
.wardrobe-buy button { font-size: 0.8rem; padding: 0.25rem 0.7rem; }
.wardrobe-buy button:disabled { opacity: 0.45; cursor: default; }
.buy-phones { border-color: #6a9e6a; color: #9ed09e; }
.code-form { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; margin-top: 0.5rem; }
.code-form input { width: 9rem; font: inherit; font-size: 16px; padding: 0.25rem 0.45rem; border: 1px solid var(--grid-line); border-radius: var(--radius); background: var(--bg-warm); color: var(--ink); text-transform: uppercase; }
.code-form button { font-size: 0.75rem; padding: 0.25rem 0.6rem; }
.code-msg { font-size: 0.72rem; color: var(--ink-light); }
@media (max-height: 520px) {
  .modal-box.wardrobe-box { max-width: min(720px, calc(100vw - 1rem)); padding: 0.75rem 1.25rem; gap: 0.4rem; }
  .wardrobe-box .modal-title { font-size: 1.15rem; }
  .wardrobe-body { flex-direction: row; align-items: flex-start; }
  .wardrobe-canvas { width: 170px; height: min(230px, calc(100dvh - 9rem)); }
  .wardrobe-lists { flex: 1; min-width: 0; }
}
/* Red blurred border that pulses in when the fortune wheel takes a heart (above the dialog) */
.hurt-vignette {
  position: fixed;
  inset: 0;
  z-index: 1001;
  pointer-events: none;
  opacity: 0;
  box-shadow: inset 0 0 70px 28px rgba(210, 25, 35, 0.85), inset 0 0 160px 60px rgba(160, 0, 20, 0.45);
}
.hurt-vignette.show { animation: hurt-vignette 1.1s ease-out; }
@keyframes hurt-vignette {
  0% { opacity: 0; }
  12% { opacity: 1; }
  30% { opacity: 0.55; }
  45% { opacity: 0.9; }
  100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .hurt-vignette.show { animation-duration: 0.6s; } }
/* ── Death by gambling: Skyrim-style loading screen ── */
.gamble-death {
  position: fixed;
  inset: 0;
  z-index: 1002;
  background: #000;
  color: #d9d4c7;
  display: none;
  opacity: 0;
}
.gamble-death.open { display: block; animation: gd-fade 2.4s ease-in forwards; }
@keyframes gd-fade { from { opacity: 0; } to { opacity: 1; } }
.gd-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.gd-tip {
  position: absolute;
  left: 50%;
  bottom: max(9vh, 4.5rem);
  transform: translateX(-50%);
  width: min(680px, calc(100vw - 2.5rem));
  text-align: center;
  opacity: 0;
  animation: gd-fade 1.6s ease-in 1.8s forwards;
}
.gd-tip-title { font-family: 'Cinzel', 'Fraunces', serif; font-weight: 600; font-size: 1.15rem; letter-spacing: 0.12em; text-transform: uppercase; color: #ece6d6; margin-bottom: 0.5rem; }
.gd-tip-text { font-family: 'Fraunces', serif; font-size: 1rem; line-height: 1.55; color: #bdb6a6; }
.gd-help { margin-top: 0.9rem; font-size: 0.75rem; color: #8d877a; }
.gd-help b { color: #bdb6a6; font-weight: 500; }
.gd-continue {
  position: absolute;
  right: max(1.25rem, env(safe-area-inset-right, 0px));
  bottom: max(1.25rem, env(safe-area-inset-bottom, 0px));
  background: none;
  border: 1px solid rgba(217, 212, 199, 0.35);
  color: #d9d4c7;
  font-family: 'Cinzel', serif;
  letter-spacing: 0.1em;
  opacity: 0;
  animation: gd-fade 1s ease-in 2.6s forwards;
}
.gd-continue:hover { border-color: #d9d4c7; color: #fff; background: rgba(255, 255, 255, 0.05); }
@media (max-height: 520px) {
  .gd-tip { bottom: 3.2rem; }
  .gd-tip-text { font-size: 0.85rem; }
}
.debug-panel {
  width: 100%;
  max-width: var(--max-w);
  padding: 0.35rem 1rem 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--ink-light);
}
.debug-panel button { font-size: 0.75rem; padding: 0.2rem 0.55rem; }
.debug-bosses { display: inline-flex; align-items: center; gap: 0.25rem; }
.debug-tag { color: #e04040; font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em; }
.toggle-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(224, 138, 60, 0.14); }
.btn-accent:hover { background: var(--accent-hover); color: #fff; border-color: var(--accent-hover); }

.seed-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  font-size: 0.7rem;
  color: var(--ink-muted);
}

.seed-display code {
  background: var(--bg-warm);
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  user-select: all;
}

/* ── HUD: hearts + pages/distance ── */
.hud {
  width: 100%;
  max-width: var(--max-w);
  padding: 0.5rem 1rem 0.35rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#heartsDisplay { font-size: 1.35rem; letter-spacing: 0.15em; color: var(--accent); }
.hud-left { display: flex; align-items: center; gap: 0.6rem; }
.hud-items { display: flex; align-items: center; gap: 0.45rem; font-size: 0.85rem; color: var(--ink); }
.potion-slot { display: inline-flex; align-items: center; gap: 0.15rem; font-weight: 500; color: #e05a7a; }
.potion-slot.empty { color: var(--ink-muted); opacity: 0.55; }
.potion-slot.empty svg { filter: grayscale(1); }
.heart-lost { color: var(--ink-muted); }

.hud-stats {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--ink-light);
}
.hud-stats b { color: var(--ink); font-weight: 500; font-size: 1rem; }

/* ── Game canvas ── */
.game-wrap {
  width: 100%;
  max-width: var(--max-w);
  padding: 0 0.75rem;
}

#game {
  display: block;
  width: 100%;
  border: 1.5px solid var(--grid-thick);
  border-radius: var(--radius);
  background: var(--bg);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}


/* ── Bottom controls: big jump button on touch screens ── */
.bottom-controls {
  width: 100%;
  max-width: var(--max-w);
  padding: 0.6rem 1rem 0.75rem;
  display: none;
  justify-content: center;
  gap: 0.6rem;
}

.jump-btn {
  flex: 1;
  width: 100%;
  max-width: 420px;
  height: 64px;
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--ink);
  color: var(--bg);
  border: none;
  border-radius: 32px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.jump-btn:hover { color: var(--bg); }
.jump-btn:active, .jump-btn.pressed { transform: scale(0.97); background: var(--accent); }
.throw-btn { background: var(--accent); color: #fff; }
.throw-btn:hover { color: #fff; }

@media (pointer: coarse) {
  .bottom-controls { display: flex; }
  /* Free space mostly above the game, some below: controls stay in thumb reach */
  .bottom-pad { flex: 0.5 1 auto; }
}

/* Safe-area padding for phones with gesture bars */
.bottom-pad {
  height: env(safe-area-inset-bottom, 0.5rem);
  min-height: 0.5rem;
}

/* ── Mobile ── */
@media (max-width: 420px) {
  h1 { font-size: 1.2rem; }
  .top-bar { padding: 0.5rem 0.75rem 0.15rem; }
  .game-wrap { padding: 0 0.5rem; }
}

/* ── Desktop: no spacer, content starts at top, bigger viewport ── */
@media (min-width: 700px) {
  :root { --max-w: 1200px; }
  .mobile-spacer { flex: 0 0 0; }
  .top-bar { padding: 1.5rem 1rem 0.5rem; }
  h1 { font-size: 1.6rem; }
}

#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 999;
}

@keyframes pop {
  0% { transform: scale(0.8); opacity: 0; }
  60% { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes game-shake {
  0%   { transform: translateX(0); }
  15%  { transform: translateX(-7px); }
  30%  { transform: translateX(7px); }
  50%  { transform: translateX(-5px); }
  70%  { transform: translateX(5px); }
  85%  { transform: translateX(-2px); }
  100% { transform: translateX(0); }
}
.game-wrap.shake { animation: game-shake 0.5s ease; }

@keyframes heart-pulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  100% { transform: scale(1); }
}
#heartsDisplay.pulse { animation: heart-pulse 0.4s ease; }

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-box {
  background: var(--bg);
  border: 1.5px solid var(--grid-thick);
  border-radius: var(--radius);
  padding: 1.75rem 2.25rem;
  text-align: center;
  display: flex; flex-direction: column; gap: 0.75rem;
  min-width: 230px;
  max-width: calc(100vw - 2rem);
  max-height: calc(100dvh - 1rem);
  overflow-y: auto;
  animation: pop 0.35s ease;
}
.modal-title {
  font-family: 'Cinzel', 'Fraunces', serif;
  font-size: 1.5rem; font-weight: 700;
  color: var(--accent);
}
.modal-stats { font-size: 0.9rem; line-height: 1.6; color: var(--ink); }
.modal-sub { font-size: 0.75rem; color: var(--ink-muted); }
.modal-actions { display: flex; gap: 0.5rem; justify-content: center; margin-top: 0.25rem; }

/* ── Quiz modal ── */
.quiz-box { max-width: min(560px, calc(100vw - 2rem)); text-align: left; padding: 1.5rem 1.75rem; }
.quiz-kicker {
  font-family: 'Cinzel', 'Fraunces', serif;
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  color: var(--accent);
}
.quiz-question { font-family: 'Fraunces', serif; font-size: 1.15rem; line-height: 1.4; color: var(--ink); }
.quiz-stakes { font-size: 0.72rem; color: var(--ink-light); }
.quiz-answers { display: flex; flex-direction: column; gap: 0.45rem; }
.quiz-answers button { text-align: left; line-height: 1.35; padding: 0.6rem 0.75rem; }
.quiz-answers button b { color: var(--ink-light); margin-right: 0.4rem; }
.quiz-answers button:disabled { cursor: default; transform: none; }
.quiz-answers button:disabled:hover { border-color: var(--grid-line); color: var(--ink); }
.quiz-answers button.right, .quiz-answers button.right:hover { border-color: #4f9a55; background: rgba(79, 154, 85, 0.18); }
.quiz-answers button.wrong, .quiz-answers button.wrong:hover { border-color: #d94040; background: rgba(217, 64, 64, 0.16); }
.quiz-feedback { font-size: 0.85rem; line-height: 1.5; color: var(--ink); min-height: 0; }
.quiz-feedback b.right { color: #4f9a55; }
.quiz-feedback b.wrong { color: #d94040; }
.quiz-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }
.quiz-skip { background: none; color: var(--ink-light); }

/* Phones in landscape: compact quiz, answers in two columns, button always reachable */
@media (max-height: 520px) {
  .quiz-box { max-width: min(760px, calc(100vw - 1rem)); padding: 0.75rem 1rem; gap: 0.4rem; }
  .quiz-kicker { font-size: 0.8rem; }
  .quiz-question { font-size: 0.95rem; line-height: 1.3; }
  .quiz-answers { display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem; }
  .quiz-answers button { padding: 0.4rem 0.55rem; font-size: 0.75rem; }
  .quiz-feedback { font-size: 0.75rem; line-height: 1.35; }
  .quiz-actions { position: sticky; bottom: 0; }
  .quiz-actions button { padding: 0.5rem 1.25rem; }
  /* Shop: tighter rows */
  .modal-box.shop-box { max-width: min(640px, calc(100vw - 1rem)); padding: 0.75rem 1.25rem; gap: 0.35rem; }
  .shop-box .modal-title { font-size: 1.15rem; }
  .shop-box .shop-sub { font-size: 0.72rem; margin-bottom: 0.2rem; }
  .shop-box .modal-actions button { padding: 0.4rem 1rem; }
  /* Fortune wheel: the wheel fills the left side at screen height, everything else stacks on the right */
  .wheel-mode .modal-box.shop-box {
    display: grid;
    grid-template-columns: auto minmax(12rem, 18rem);
    grid-template-rows: auto auto 1fr auto;
    column-gap: 1.25rem;
    align-items: center;
  }
  .wheel-mode .shop-box > :not(.wheel-box) { grid-column: 2; }
  .wheel-mode .wheel-box { display: contents; }
  .wheel-mode .wheel-canvas {
    grid-column: 1; grid-row: 1 / -1;
    width: min(280px, calc(100dvh - 2.5rem)); height: min(280px, calc(100dvh - 2.5rem));
  }
  .wheel-mode .wheel-side { grid-column: 2; grid-row: 3; }
  .wheel-mode .shop-box .modal-title { grid-row: 1; }
  .wheel-mode .shop-box .shop-sub { grid-row: 2; margin: 0; }
  .wheel-mode .shop-box .modal-actions { grid-row: 4; }
  .wheel-result { min-height: 0; }
  .shop-list { gap: 0.3rem; }
  .shop-row { padding: 0.3rem 0.5rem; }
}

/* ── Fullscreen button + layout ── */
.game-wrap { position: relative; }
.fs-btn {
  position: absolute;
  right: calc(0.75rem + 6px);
  bottom: 6px;
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  background: rgba(0, 0, 0, 0.45);
  color: #ecdfc4;
  border: 1px solid rgba(236, 223, 196, 0.35);
}
.fs-btn:hover { color: #fff; border-color: #fff; }

body.fs { height: 100dvh; min-height: 0; overflow: hidden; }
body.fs .top-bar, body.fs .top-controls, body.fs .mobile-spacer, body.fs .bottom-pad { display: none; }
body.fs .hud, body.fs .game-wrap, body.fs .bottom-controls { max-width: none; }
body.fs .hud { padding: 0.35rem 1rem 0.25rem; }
body.fs .game-wrap { flex: 1 1 0; min-height: 0; display: flex; align-items: center; padding-bottom: 0.25rem; }
body.fs .bottom-controls { padding: 0.35rem 1rem calc(0.35rem + env(safe-area-inset-bottom, 0px)); }
body.fs .jump-btn { height: 52px; }

/* ── Game over: small inline same-seed restart ── */
.go-seed { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.35rem; }
.go-seed code { background: var(--bg-warm); padding: 0.1rem 0.35rem; border-radius: 3px; user-select: all; }
.inline-btn {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-width: 1px;
  color: var(--ink-light);
  background: none;
}

/* Fullscreen: exit button sits in the HUD row, clear of the game */
body.fs .hud { padding-right: 3.25rem; }
body.fs .fs-btn { position: fixed; top: 4px; right: calc(8px + env(safe-area-inset-right, 0px)); z-index: 5; }

/* Phone held sideways in fullscreen: slim HUD, edge-to-edge game,
   round see-through thumb buttons over the bottom corners */
@media (orientation: landscape) and (max-height: 520px) {
  body.fs .hud { padding: 0.15rem 3.25rem 0.15rem calc(0.75rem + env(safe-area-inset-left, 0px)); }
  body.fs #heartsDisplay { font-size: 1rem; }
  body.fs .hud-stats { font-size: 0.7rem; }
  body.fs .hud-stats b { font-size: 0.85rem; }
  body.fs .fs-btn { width: 24px; height: 22px; top: 2px; font-size: 0.8rem; }
  body.fs .game-wrap { padding: 0 env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px); }
  body.fs #game { border: none; border-radius: 0; }
  body.fs .bottom-controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0 calc(1rem + env(safe-area-inset-right, 0px)) calc(0.75rem + env(safe-area-inset-bottom, 0px)) calc(1rem + env(safe-area-inset-left, 0px));
    justify-content: space-between;
    pointer-events: none;
    z-index: 4;
  }
  body.fs .jump-btn {
    pointer-events: auto;
    flex: 0 0 auto;
    width: 76px;
    height: 76px;
    padding: 0;
    border-radius: 50%;
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    opacity: 0.6;
  }
  body.fs .jump-btn.pressed { opacity: 0.85; }
  body.fs #jumpBtn { order: 2; margin-left: auto; }
  body.fs .throw-btn { order: 1; }
}

/* Seed field keeps a usable width; buttons wrap below it on narrow screens */
.controls-row input[type="text"] { flex: 1 1 160px; }
@media (max-width: 520px) {
  .controls-row input[type="text"] { flex-basis: 100%; }
  .controls-row button { flex: 1 1 auto; }
  /* Narrow HUD: tighter gaps, labels drop out, numbers stay */
  .hud { padding-left: 0.6rem; padding-right: 0.6rem; }
  .hud-left { gap: 0.4rem; }
  .hud-stats { gap: 0.55rem; white-space: nowrap; }
  .hud-stats .hud-label { display: none; }
  .hud-stats .hud-icon { display: inline; margin: 0 0.1rem; }
  .upgrade-btn { padding: 0.15rem 0.35rem; }
  .upg-label { display: none; }
}

/* ── Game over: highscore entry + board ── */
.hs-form { display: flex; flex-direction: column; gap: 0.4rem; }
.hs-kicker { font-family: 'Cinzel', 'Fraunces', serif; font-weight: 800; font-size: 0.95rem; color: var(--accent); }
.hs-row { display: flex; gap: 0.4rem; }
.hs-row input {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.45rem 0.6rem;
  border: 1.5px solid var(--grid-line);
  border-radius: var(--radius);
  background: var(--bg-warm);
  color: var(--ink);
  outline: none;
}
.hs-row input:focus { border-color: var(--accent); }
.hs-error { font-size: 0.75rem; color: #d94040; min-height: 0; }
.hs-error:empty { display: none; }
.hs-board { text-align: left; }
.hs-title { font-family: 'Cinzel', 'Fraunces', serif; font-weight: 700; font-size: 0.85rem; color: var(--ink-light); text-align: center; margin-bottom: 0.3rem; }
.hs-board ol { list-style: none; margin: 0; padding: 0; font-size: 0.8rem; }
.hs-board li {
  display: grid;
  grid-template-columns: 1.6rem 1fr auto;
  gap: 0.5rem;
  align-items: baseline;
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
}
.hs-board li:nth-child(odd) { background: var(--bg-warm); }
.hs-board li.me { outline: 1.5px solid var(--accent); }
.hs-board .hs-rank { color: var(--ink-muted); text-align: right; }
.hs-board .hs-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.hs-board .hs-stats { color: var(--ink-light); font-size: 0.72rem; white-space: nowrap; }
.hs-board .hs-stats b { color: var(--ink); font-size: 0.8rem; }
.hs-board .hs-hard { color: var(--accent); font-size: 0.65rem; margin-left: 0.3rem; }
.board-box { width: min(420px, calc(100vw - 2rem)); }
.hs-empty { font-size: 0.8rem; color: var(--ink-muted); text-align: center; }
.hs-empty:empty { display: none; }
.hs-offline { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.4rem; font-size: 0.8rem; color: var(--ink-light); }
