:root {
  --bg-0: #070a14;
  --bg-1: #121a30;
  --ink: #e8edff;
  --muted: #8a97bd;
  --move: #4df08a;
  --danger: #ff3b5c;
  --capture: #ffc24a;
  --panel: rgba(14, 19, 36, 0.82);
  --stroke: rgba(120, 160, 255, 0.18);
}

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

html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(120% 120% at 50% 0%, var(--bg-1) 0%, var(--bg-0) 60%);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#app { position: fixed; inset: 0; }

/* touch-action:none lets the canvas own all touch gestures (tap/drag/pinch).
   Without it, mobile browsers steal touches for scroll/zoom and fire pointercancel,
   which silently swallowed taps and made the board feel unresponsive on phones. */
canvas#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; }

.hud-top {
  position: absolute; top: 18px; left: 0; right: 0;
  display: flex; gap: 12px; justify-content: center;
}
/* The biome/weather badge (e.g. "🌳 Meadow ☀️") is redundant during play — the biome and
   weather are obvious from the board — so it's hidden everywhere. */
#biome-badge { display: none; }

.badge {
  pointer-events: none;
  background: var(--panel);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(10px);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--muted);
  display: flex; align-items: center; gap: 9px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.35);
}
.badge b { color: var(--ink); font-variant-numeric: tabular-nums; }

#turn-badge .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--move);
  box-shadow: 0 0 12px var(--move);
  animation: pulse 1.6s ease-in-out infinite;
}
#turn-badge.enemy .dot { background: var(--danger); box-shadow: 0 0 12px var(--danger); }
#turn-badge #turn-text { color: var(--ink); }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

.level-badge { gap: 6px; padding: 5px 8px; }
.lvl-btn {
  pointer-events: auto;
  font-family: inherit; font-size: 12px; line-height: 1;
  color: var(--muted); background: rgba(255,255,255,0.05);
  border: 1px solid var(--stroke); border-radius: 7px;
  width: 22px; height: 22px; cursor: pointer; padding: 0;
  transition: color .15s, border-color .15s, transform .1s;
}
.lvl-btn:hover { color: var(--ink); border-color: rgba(120,160,255,0.5); }
.lvl-btn:active { transform: scale(0.92); }
.level-badge b { color: var(--move); }

/* wave + foe-count badges */
#wave-badge b { color: #9b86ff; }
#foes-badge .foe-glyph { color: var(--danger); font-size: 12px; line-height: 1; }
#foes-badge b { color: var(--ink); }
#wave-badge.pulse { animation: wavePulse .6s ease; }
@keyframes wavePulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.14); border-color: rgba(122,92,255,0.85); box-shadow: 0 0 18px rgba(122,92,255,0.75); }
  100% { transform: scale(1); }
}

/* progress toward the portal — a thin bar just below the top badges */
#progress-dock {
  position: absolute; top: 54px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  width: min(360px, 56vw); pointer-events: none;
}
.prog-track {
  position: relative; width: 100%; height: 6px;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--stroke); border-radius: 999px;
}
.prog-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--move), #7CFFB2);
  border-radius: 999px; transition: width .4s ease;
  box-shadow: 0 0 10px rgba(124,255,178,0.6);
}
.prog-portal {
  position: absolute; right: -7px; top: 50%; transform: translateY(-50%);
  font-size: 13px; line-height: 1; filter: drop-shadow(0 0 6px rgba(124,255,178,0.75));
}
.prog-label {
  font-size: 11px; letter-spacing: 0.04em; color: var(--muted);
  text-shadow: 0 1px 4px rgba(0,0,0,0.55);
}
.prog-label b { color: var(--ink); font-variant-numeric: tabular-nums; }

.hud-warning {
  position: absolute; top: 92px; left: 50%; transform: translateX(-50%) translateY(-8px);
  background: rgba(255, 59, 92, 0.14);
  border: 1px solid rgba(255, 59, 92, 0.5);
  color: #ffd0d8;
  padding: 7px 18px; border-radius: 999px;
  font-size: 13px; letter-spacing: 0.05em; font-weight: 600;
  opacity: 0; transition: opacity .25s, transform .25s;
  text-shadow: 0 0 14px rgba(255, 59, 92, 0.6);
}
.hud-warning.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.hud-tip {
  position: absolute; top: 92px; left: 50%; transform: translateX(-50%) translateY(-8px);
  background: rgba(58, 160, 255, 0.16);
  border: 1px solid rgba(95, 190, 255, 0.55);
  color: #d6efff;
  padding: 7px 18px; border-radius: 999px;
  font-size: 13px; letter-spacing: 0.03em; font-weight: 600;
  opacity: 0; transition: opacity .25s, transform .25s;
  text-shadow: 0 0 14px rgba(95, 190, 255, 0.5);
  white-space: nowrap;
}
.hud-tip.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.hud-tip b { color: #fff; }
/* when both show, push the tip below the warning */
.hud-warning.show ~ .hud-tip.show { top: 128px; }

.hud-hint {
  position: absolute; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(10px);
  padding: 10px 20px; border-radius: 999px;
  font-size: 13px; color: var(--muted);
  transition: opacity .4s;
}
.hud-hint b { color: var(--ink); }

/* ---------- Top-right cluster: difficulty + sound ---------- */
.hud-tr {
  position: absolute; top: 14px; right: 18px;
  display: flex; align-items: flex-end; gap: 10px;
}
/* a labelled segmented control (label stacked above the buttons) */
.seg-group { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.seg-label {
  font-size: 9px; font-weight: 700; letter-spacing: 0.14em;
  color: var(--muted); text-transform: uppercase; pointer-events: none;
}
.ctrl-btn {
  pointer-events: auto;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--stroke);
  backdrop-filter: blur(10px);
  color: var(--ink); font-size: 18px; cursor: pointer;
  box-shadow: 0 8px 30px rgba(0,0,0,0.35);
  transition: transform .15s, color .2s, border-color .2s;
}
.ctrl-btn:hover { transform: translateY(-2px); border-color: rgba(120,160,255,0.4); }
.ctrl-btn.off { color: var(--muted); opacity: 0.7; }

/* difficulty segmented control */
.seg {
  pointer-events: auto;
  display: flex; background: var(--panel); border: 1px solid var(--stroke);
  border-radius: 999px; padding: 3px; backdrop-filter: blur(10px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.35);
}
.seg-btn {
  font-family: inherit; font-size: 11px; font-weight: 700; letter-spacing: 0.08em;
  color: var(--muted); background: none; border: none; cursor: pointer;
  padding: 6px 13px; border-radius: 999px; transition: color .2s, background .2s, box-shadow .2s;
}
.seg-btn.active {
  color: #06223a; background: linear-gradient(180deg, #6fe9ff, #34c4ff);
  box-shadow: 0 0 14px rgba(52,196,255,0.45);
}
.seg-btn.active[data-mode="hard"] {
  color: #2a0810; background: linear-gradient(180deg, #ff7a8c, #ff3b5c);
  box-shadow: 0 0 14px rgba(255,59,92,0.5);
}
.seg-btn.active[data-terrain] {
  color: #08240f; background: linear-gradient(180deg, #84f0a6, #34d27a);
  box-shadow: 0 0 14px rgba(52,210,122,0.45);
}
.seg-btn.active[data-help] {
  color: #06223a; background: linear-gradient(180deg, #6fe9ff, #34c4ff);
  box-shadow: 0 0 14px rgba(52,196,255,0.45);
}

/* ---------- Arcade scoreboard ---------- */
#scoreboard {
  position: absolute; top: 14px; left: 16px;
  font-family: "Courier New", ui-monospace, monospace;
  background: linear-gradient(180deg, rgba(10,14,28,0.9), rgba(8,11,22,0.86));
  border: 1px solid rgba(120,160,255,0.22);
  border-radius: 12px; padding: 10px 12px 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.45), inset 0 0 18px rgba(40,70,140,0.18);
  min-width: 168px;
}
.sb-total { display: flex; flex-direction: column; line-height: 1; margin-bottom: 8px; }
.sb-label { font-size: 10px; letter-spacing: 0.32em; color: #6f86c9; }
.sb-total-row { display: flex; align-items: center; gap: 9px; margin-top: 3px; }
.sb-total-val {
  font-size: 26px; font-weight: 700; letter-spacing: 0.06em;
  color: #ffe27a; text-shadow: 0 0 10px rgba(255,200,60,0.7), 0 0 2px rgba(255,200,60,0.9);
  transform-origin: left center;
}
.sb-coin {
  width: 20px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6c4, #ffd24a 45%, #e0a51e 80%, #a9760c);
  border: 1px solid #b9860f;
  box-shadow: 0 0 10px rgba(255,200,60,0.7), inset 0 -2px 3px rgba(150,90,0,0.5), inset 0 2px 2px rgba(255,255,255,0.5);
  position: relative; flex: 0 0 auto;
}
.sb-coin::after {
  content: "$"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: "Courier New", monospace; font-weight: 800; font-size: 12px; color: #9a6c0a;
}
.sb-total-val.punch { animation: scorePunch .42s cubic-bezier(.2,1.4,.3,1); }
@keyframes scorePunch {
  0% { transform: scale(1); } 35% { transform: scale(1.28); color: #fff; } 100% { transform: scale(1); }
}
/* big-money capture — a bigger flashing payout on the total */
.sb-total-val.jackpot { animation: scoreJackpot .8s cubic-bezier(.2,1.3,.3,1); }
@keyframes scoreJackpot {
  0%   { transform: scale(1); color: #ffe27a; }
  20%  { transform: scale(1.55); color: #fff; text-shadow: 0 0 22px #fff, 0 0 40px #ffd24a; }
  45%  { transform: scale(1.1); color: #fff3b0; }
  60%  { color: #fff; }
  100% { transform: scale(1); color: #ffe27a; }
}
/* coin flips on every capture */
.sb-coin.spin { animation: coinFlip .55s ease; }
@keyframes coinFlip {
  0% { transform: rotateY(0) scale(1); }
  50% { transform: rotateY(180deg) scale(1.25); }
  100% { transform: rotateY(360deg) scale(1); }
}
/* a quick gold sheen sweeps the scoreboard on a capture */
#scoreboard.win-flash { animation: boardFlash .5s ease; }
@keyframes boardFlash {
  0% { box-shadow: 0 8px 30px rgba(0,0,0,0.45), inset 0 0 18px rgba(40,70,140,0.18), inset 0 0 0 1px rgba(255,210,90,0); }
  35% { box-shadow: 0 8px 34px rgba(255,190,50,0.4), inset 0 0 26px rgba(255,200,80,0.35), inset 0 0 0 1px rgba(255,210,90,0.7); }
  100% { box-shadow: 0 8px 30px rgba(0,0,0,0.45), inset 0 0 18px rgba(40,70,140,0.18), inset 0 0 0 1px rgba(255,210,90,0); }
}
/* the four capture counts on one horizontal line: bigger icon + count, no name labels */
.sb-rows { display: flex; flex-direction: row; gap: 12px; border-top: 1px solid rgba(120,160,255,0.14); padding-top: 6px; }
.sb-row {
  display: flex; align-items: center; gap: 4px;
  font-size: 12px; color: #aebbe6;
  padding: 2px 2px; border-radius: 6px; transition: background .2s;
}
.sb-glyph { font-size: 19px; line-height: 1; }
.sb-glyph.pawn { color: #ffb340; } .sb-glyph.knight { color: #2fd6b6; }
.sb-glyph.bishop { color: #a86bff; } .sb-glyph.rook { color: #ff4d68; }
.sb-name { color: #7e8cb8; }
.sb-count { color: #fff; font-weight: 700; min-width: 24px; text-align: right; }
.sb-pts { color: #ffe27a; min-width: 34px; text-align: right; }
.sb-row.flash { background: rgba(255,226,122,0.18); animation: rowFlash .5s ease; }
@keyframes rowFlash { 0% { background: rgba(255,226,122,0.5); } 100% { background: rgba(255,226,122,0); } }

.sb-foot {
  display: flex; align-items: center; justify-content: flex-start; gap: 12px; flex-wrap: wrap;
  margin-top: 7px; padding-top: 6px; border-top: 1px solid rgba(120,160,255,0.14);
  font-size: 11px; letter-spacing: 0.06em; color: #7e8cb8;
}
.sb-moves b { color: #fff; font-variant-numeric: tabular-nums; }
.sb-best b { color: #ffd76a; font-variant-numeric: tabular-nums; }
.sb-mult {
  display: none;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-weight: 800; font-size: 11px; color: #08240f;
  background: linear-gradient(180deg, #84f0a6, #34d27a);
  border-radius: 6px; padding: 2px 7px;
  box-shadow: 0 0 10px rgba(52,210,122,0.45);
}
.sb-mult.show { display: inline-block; }

/* ---------- Floating +points payouts (casino style) ---------- */
#score-pop-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.score-pop {
  position: absolute; transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 6px;
  font-family: "Courier New", ui-monospace, monospace; font-weight: 800; font-size: 26px;
  color: var(--pop-col, #ffe27a);
  text-shadow: 0 0 10px currentColor, 0 2px 6px rgba(0,0,0,0.6);
  animation: scorePop 1.1s ease-out forwards;
  white-space: nowrap;
}
/* mini gold coin riding alongside the number */
.pop-coin {
  width: 0.8em; height: 0.8em; border-radius: 50%; flex: 0 0 auto;
  background: radial-gradient(circle at 35% 30%, #fff6c4, #ffd24a 45%, #e0a51e 80%, #a9760c);
  box-shadow: 0 0 8px rgba(255,200,60,0.8), inset 0 -1px 2px rgba(150,90,0,0.5);
}
/* bigger gains turn gold and grow */
.score-pop.big  { font-size: 36px; color: #ffe27a; }
.score-pop.huge {
  font-size: 50px; color: #fff3b0;
  text-shadow: 0 0 16px #ffd24a, 0 0 32px rgba(255,180,40,0.8), 0 2px 8px rgba(0,0,0,0.6);
  animation: scorePopHuge 1.4s cubic-bezier(.2,1.2,.3,1) forwards;
}
/* a sparkle ring for the jackpot pops */
.score-pop.huge::before {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 12px; height: 12px; transform: translate(-50%,-50%);
  border-radius: 50%; box-shadow: 0 0 0 0 rgba(255,220,120,0.85);
  animation: popSpark 0.7s ease-out forwards;
}
@keyframes scorePop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
  18% { opacity: 1; transform: translate(-50%, -90%) scale(1.25); }
  35% { transform: translate(-50%, -120%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -260%) scale(0.95); }
}
@keyframes scorePopHuge {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3) rotate(-6deg); }
  16% { opacity: 1; transform: translate(-50%, -95%) scale(1.5) rotate(3deg); }
  32% { transform: translate(-50%, -125%) scale(1.05) rotate(0deg); }
  100% { opacity: 0; transform: translate(-50%, -280%) scale(1); }
}
@keyframes popSpark {
  0% { box-shadow: 0 0 0 0 rgba(255,220,120,0.9); opacity: 1; }
  100% { box-shadow: 0 0 0 46px rgba(255,220,120,0); opacity: 0; }
}

/* ---------- Leap skill button ---------- */

/* ---------- Leap skill button ---------- */
#jump-dock {
  position: absolute; bottom: 70px; left: 50%; transform: translateX(-50%);
  pointer-events: none;
}
.jump-btn {
  pointer-events: auto;
  position: relative; overflow: hidden;
  font-family: inherit; font-size: 14px; font-weight: 800; letter-spacing: 0.14em;
  color: #cdd6ff;
  width: 168px; height: 46px; border-radius: 12px;
  background: rgba(16, 20, 38, 0.85);
  border: 1px solid rgba(122, 92, 255, 0.4);
  backdrop-filter: blur(10px);
  cursor: not-allowed;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  transition: transform .15s, box-shadow .25s, border-color .25s, color .2s;
}
.jump-fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0%;
  background: linear-gradient(90deg, rgba(122,92,255,0.55), rgba(160,120,255,0.75));
  transition: width .35s cubic-bezier(.2,.9,.25,1);
  z-index: 0;
}
.jump-content { position: relative; z-index: 1; display: flex; align-items: center; justify-content: center; gap: 8px; }
.jump-icon { font-size: 16px; filter: drop-shadow(0 0 6px rgba(160,120,255,0.8)); }

.jump-btn.ready {
  cursor: pointer; color: #fff;
  border-color: rgba(150, 120, 255, 0.95);
  box-shadow: 0 0 24px rgba(122,92,255,0.6), 0 8px 30px rgba(0,0,0,0.4);
  animation: jumpPulse 1.4s ease-in-out infinite;
}
.jump-btn.ready:hover { transform: translateY(-2px); }
.jump-btn.aiming {
  color: #fff; border-color: #b9a3ff;
  box-shadow: 0 0 32px rgba(150,120,255,0.85), 0 8px 30px rgba(0,0,0,0.4);
  animation: none;
}
@keyframes jumpPulse {
  0%,100% { box-shadow: 0 0 18px rgba(122,92,255,0.5), 0 8px 30px rgba(0,0,0,0.4); }
  50% { box-shadow: 0 0 34px rgba(150,120,255,0.85), 0 8px 30px rgba(0,0,0,0.4); }
}

/* ---------- Help action (bottom-left) ---------- */
#color-control {
  position: absolute; left: 18px; bottom: 22px;
  pointer-events: none; /* only the buttons inside are interactive */
  display: flex; flex-direction: column-reverse; align-items: flex-start; gap: 8px;
}
/* Reset View button (lives in the Settings → Camera row) */
#reset-view-btn { font-size: 12px; padding: 8px 12px; color: #d6efff; border-color: rgba(95,190,255,0.45); }
#reset-view-btn:hover { color: #fff; border-color: rgba(120,200,255,0.85); }

/* 8-bit music toggle (Settings) — dim when off, glowing purple when playing */
#music-btn:not(.off) {
  color: #d8ccff; border-color: rgba(143,116,255,0.7);
  box-shadow: 0 0 14px rgba(143,116,255,0.5);
}
.audio-ctrls { display: flex; gap: 10px; align-items: center; }
.song-name { font-size: 12px; color: var(--muted); max-width: 150px; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Per-instrument mixer (Settings) ---------- */
/* stack the label above its grid so the eight voice chips get a full-width row */
.set-row-col { flex-direction: column; align-items: stretch; }
.instr-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; width: 100%; margin-top: 2px;
}
.instr-btn {
  font-family: inherit; font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
  color: #d8ccff; cursor: pointer; padding: 7px 4px; border-radius: 9px;
  background: rgba(143,116,255,0.16); border: 1px solid rgba(143,116,255,0.5);
  box-shadow: 0 0 10px rgba(143,116,255,0.25);
  transition: color .18s, background .18s, box-shadow .18s, opacity .18s, transform .12s;
}
.instr-btn:hover { transform: translateY(-1px); border-color: rgba(170,150,255,0.85); }
/* muted voice reads dim and flat */
.instr-btn.off {
  color: var(--muted); background: rgba(255,255,255,0.04);
  border-color: rgba(255,255,255,0.12); box-shadow: none; opacity: 0.75;
}

/* ---------- Music volume slider (Settings) ---------- */
.vol-slider {
  -webkit-appearance: none; appearance: none;
  width: 160px; max-width: 55%; height: 6px; border-radius: 999px; cursor: pointer;
  background: linear-gradient(90deg, rgba(143,116,255,0.85), rgba(143,116,255,0.25));
  outline: none;
}
.vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: #d8ccff; border: 1px solid rgba(143,116,255,0.9);
  box-shadow: 0 0 10px rgba(143,116,255,0.6); transition: transform .12s;
}
.vol-slider::-webkit-slider-thumb:hover { transform: scale(1.15); }
.vol-slider::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: #d8ccff; border: 1px solid rgba(143,116,255,0.9);
  box-shadow: 0 0 10px rgba(143,116,255,0.6);
}

/* ---------- King color picker (in settings modal) ---------- */
#king-color {
  -webkit-appearance: none; appearance: none;
  width: 34px; height: 34px; border: none; border-radius: 9px;
  background: none; cursor: pointer; padding: 0;
}
#king-color::-webkit-color-swatch-wrapper { padding: 0; }
#king-color::-webkit-color-swatch { border: 1px solid var(--stroke); border-radius: 9px; }
#king-color::-moz-color-swatch { border: 1px solid var(--stroke); border-radius: 9px; }

.chip {
  pointer-events: auto;
  font-family: inherit; font-size: 10px; font-weight: 700; letter-spacing: 0.08em;
  color: var(--muted); background: rgba(255,255,255,0.04);
  border: 1px solid var(--stroke); border-radius: 8px;
  padding: 7px 9px; cursor: pointer; transition: color .2s, background .2s, border-color .2s, box-shadow .2s;
}
.chip:hover { color: var(--ink); border-color: rgba(120,160,255,0.4); }
.chip.active {
  color: #06223a; background: linear-gradient(180deg, #b9a3ff, #8f74ff);
  border-color: transparent; box-shadow: 0 0 14px rgba(143,116,255,0.5);
}
.chip.help {
  color: #06281f; background: linear-gradient(180deg, #6cf0a6, #36c47e);
  border-color: transparent; font-weight: 800; font-size: 13px; letter-spacing: 0.05em;
  padding: 9px 14px;
  box-shadow: 0 0 18px rgba(77,240,138,0.55), inset 0 1px 0 rgba(255,255,255,0.4);
  animation: helpPulse 2s ease-in-out infinite;
}
.chip.help:hover { color: #06281f; filter: brightness(1.08); transform: translateY(-1px); }
.chip.help:active { transform: translateY(0) scale(0.96); }
@keyframes helpPulse {
  0%,100% { box-shadow: 0 0 14px rgba(77,240,138,0.45), inset 0 1px 0 rgba(255,255,255,0.4); }
  50% { box-shadow: 0 0 26px rgba(77,240,138,0.8), inset 0 1px 0 rgba(255,255,255,0.4); }
}

/* ---------- FPS monitor ---------- */
#fps {
  position: absolute; right: 12px; bottom: 5px;
  font-family: "Courier New", ui-monospace, monospace; font-size: 10px;
  color: rgba(138,151,189,0.45); letter-spacing: 0.04em;
  pointer-events: none;
}
#fps.low { color: rgba(255,179,64,0.85); }  /* amber when running in reduced quality */

/* ---------- Legend ---------- */
#legend {
  position: absolute; right: 18px; bottom: 22px;
  background: var(--panel); border: 1px solid var(--stroke);
  backdrop-filter: blur(10px);
  border-radius: 14px; padding: 12px 14px;
  font-size: 12px; color: var(--muted);
  display: flex; flex-direction: column; gap: 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.35);
}
.legend-row { display: flex; align-items: center; gap: 9px; }
.swatch { width: 14px; height: 14px; border-radius: 4px; box-shadow: 0 0 10px currentColor; }
.sw-move { background: var(--move); color: var(--move); }
.sw-danger { background: var(--danger); color: var(--danger); }
.sw-capture { background: var(--capture); color: var(--capture); }

/* ---------- Settings / How-to-Play modals ---------- */
/* These sit ABOVE the opening menu (.overlay z-index:10). The compound selector also
   out-specifies the plain .overlay rule below, so the z-index isn't lost to the cascade. */
.overlay.settings-overlay, .overlay.howto-overlay { z-index: 60; }
.settings-overlay.show .settings-panel, .howto-overlay.show .settings-panel { transform: translateY(0) scale(1); }
.settings-panel {
  width: min(440px, 92vw); max-height: 86vh; overflow-y: auto;
  background: linear-gradient(180deg, rgba(22,30,55,0.96), rgba(12,17,33,0.97));
  border: 1px solid var(--stroke); border-radius: 20px;
  padding: 18px 22px 20px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.06);
  transform: translateY(12px) scale(0.98);
  transition: transform .4s cubic-bezier(.2,.9,.25,1);
  pointer-events: auto;
}
.settings-overlay.show .settings-panel { transform: translateY(0) scale(1); }
.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.settings-head h2 { font-size: 17px; letter-spacing: 0.06em; color: var(--ink); font-weight: 700; }
.modal-close {
  pointer-events: auto; width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255,255,255,0.05); border: 1px solid var(--stroke);
  color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer;
  transition: color .2s, border-color .2s;
}
.modal-close:hover { color: var(--ink); border-color: rgba(120,160,255,0.5); }
.set-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 2px; border-top: 1px solid rgba(255,255,255,0.07);
}
.set-row:first-of-type { border-top: none; }
.set-label { font-size: 13px; color: #c3cdf0; letter-spacing: 0.02em; }

/* ---------- Overlay / Modal ---------- */
.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(120% 120% at 50% 30%, rgba(8,12,24,0.55), rgba(4,6,14,0.92));
  backdrop-filter: blur(6px);
  /* visibility:hidden ALSO blocks the children — pointer-events:none on the parent
     alone does NOT, because the inner controls set pointer-events:auto and would
     keep intercepting taps/pinch across the screen while the modal is "hidden" */
  opacity: 0; pointer-events: none; visibility: hidden;
  transition: opacity .5s ease, visibility 0s linear .5s;
  z-index: 10;
}
.overlay.show { opacity: 1; pointer-events: auto; visibility: visible; transition: opacity .5s ease, visibility 0s; }

/* Pre-intro splash — sits above the menu so its click is the first audio gesture */
#splash { z-index: 30; background: radial-gradient(120% 120% at 50% 35%, rgba(10,16,32,0.82), rgba(3,5,12,0.97)); }
.splash-inner { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 22px; }
.splash-inner .title { font-size: 52px; }
.splash-hint { color: var(--muted); font-size: 13px; letter-spacing: 0.03em; }
.build-tag { color: var(--muted); opacity: 0.5; font-size: 11px; letter-spacing: 0.06em; margin-top: 6px; }
#build-corner { position: absolute; left: 8px; bottom: 6px; z-index: 40; color: var(--muted); opacity: 0.35; font-size: 10px; letter-spacing: 0.05em; pointer-events: none; }
#splash-btn { font-size: 18px; padding: 16px 38px; }

.panel {
  position: relative; /* anchors the corner Resume (×) button */
  width: min(520px, 90vw);
  background: linear-gradient(180deg, rgba(22,30,55,0.9), rgba(12,17,33,0.92));
  border: 1px solid var(--stroke);
  border-radius: 22px;
  padding: 38px 40px 34px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.06);
  transform: translateY(12px) scale(0.98);
  transition: transform .5s cubic-bezier(.2,.9,.25,1);
}
.overlay.show .panel { transform: translateY(0) scale(1); }

.title {
  font-size: 44px; letter-spacing: 0.16em; font-weight: 800;
  background: linear-gradient(180deg, #ffffff, #8fb4ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 40px rgba(110,150,255,0.35);
  margin-bottom: 12px;
}
.subtitle { color: var(--muted); font-size: 15px; line-height: 1.5; margin-bottom: 22px; }

.rules { list-style: none; text-align: left; margin: 0 auto 26px; max-width: 400px; }
.rules li {
  position: relative; padding: 7px 0 7px 22px;
  font-size: 14px; color: #c3cdf0; line-height: 1.45;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.rules li::before {
  content: ""; position: absolute; left: 2px; top: 14px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--move); box-shadow: 0 0 8px var(--move);
}
.rules b { color: #fff; }
.t-danger { color: var(--danger) !important; }
.t-jump { color: #b9a3ff !important; }

.btn {
  /* inherit pointer-events from .overlay so the centred button is only clickable
     while the overlay is actually shown (fixes "clicking the middle restarts") */
  font-family: inherit; font-size: 16px; font-weight: 700; letter-spacing: 0.14em;
  color: #06223a;
  background: linear-gradient(180deg, #6fe9ff, #34c4ff);
  border: none; border-radius: 12px;
  padding: 14px 44px; cursor: pointer;
  box-shadow: 0 10px 30px rgba(52,196,255,0.4), inset 0 1px 0 rgba(255,255,255,0.5);
  transition: transform .15s, box-shadow .2s, filter .2s;
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.08); box-shadow: 0 16px 40px rgba(52,196,255,0.55); }
.btn:active { transform: translateY(0); }
/* Loading state: hide the label and spin a ring, so a click gives instant feedback while
   the next map (etc.) loads. */
.btn.loading { color: transparent !important; pointer-events: none; position: relative; }
.btn.loading::after {
  content: ''; position: absolute; left: 50%; top: 50%; width: 20px; height: 20px; margin: -10px 0 0 -10px;
  border: 3px solid rgba(6,34,58,0.3); border-top-color: #06223a; border-radius: 50%;
  animation: btn-spin 0.7s linear infinite;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }

#loading {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px; letter-spacing: 0.1em;
  background: var(--bg-0); z-index: 20; transition: opacity .5s;
}
#loading.hide { opacity: 0; pointer-events: none; }

/* ---------- Mobile / small screens ---------- */
@media (max-width: 640px) {
  .title { font-size: 30px; }
  .subtitle { font-size: 13px; }
  .rules li { font-size: 12.5px; }

  /* Scoreboard: a small block top-left. Compact score + captures + moves/par, no BEST row. */
  #scoreboard { top: 8px; left: 8px; min-width: 0; padding: 6px 8px 5px; }
  .sb-total { margin-bottom: 5px; }
  .sb-total-val { font-size: 14px; }
  .sb-coin { width: 14px; height: 14px; }
  .sb-label { font-size: 8px; letter-spacing: 0.14em; }
  .sb-rows { gap: 7px; padding-top: 5px; }
  .sb-row { font-size: 10px; gap: 2px; }
  .sb-glyph { font-size: 14px; }
  .sb-foot { gap: 9px; font-size: 9px; margin-top: 5px; padding-top: 4px; }
  #par-delta { display: none; }                          /* par delta drops on mobile — keep it narrow */
  #scoreboard .sb-foot + .sb-foot { display: none; }     /* drop the BEST row on mobile */

  /* Top-right: account (icon only) + menu — sit clear of everything else. */
  .hud-tr { top: 8px; right: 8px; gap: 6px; }
  .ctrl-btn { width: 34px; height: 34px; font-size: 16px; }
  #auth-btn { right: 50px !important; top: 8px !important; width: 34px !important; height: 34px !important; padding: 0 !important; gap: 0 !important; justify-content: center; }
  #auth-btn .who { display: none; }                      /* just the 👤 icon on a phone */

  /* Level + turn on a SECOND row, right-aligned so they clear the scoreboard. Biome is
     visible on the board, so its badge is dropped here. */
  .hud-top { top: 48px; gap: 5px; flex-wrap: nowrap; padding: 0 8px 0 0; justify-content: flex-end; }
  #turn-badge, #foes-badge { display: none; } /* turn/foes read from the board — save room on a phone */
  .badge { font-size: 10px; padding: 3px 7px; gap: 4px; }
  .level-badge { padding: 3px 5px; }
  .level-badge b { display: inline-block; max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; } /* long map names don't blow up the badge */
  .lvl-btn { width: 18px; height: 18px; font-size: 11px; }

  /* progress on a row of its own, right-aligned + narrow so it clears the scoreboard */
  #progress-dock { top: 80px; right: 8px; left: auto; transform: none; width: 42vw; align-items: flex-end; }
  .prog-portal { font-size: 12px; }
  .prog-label { font-size: 10px; }

  #jump-dock { bottom: 84px; }
  .jump-btn { width: 150px; height: 44px; font-size: 12px; }

  #color-control { left: 10px; bottom: 14px; }
  .chip.help { font-size: 12px; padding: 8px 11px; }
  #reset-view-btn { font-size: 11px; padding: 7px 10px; }

  #legend { right: 10px; bottom: 14px; font-size: 10px; padding: 9px 11px; gap: 6px; }
  .legend-row { gap: 7px; }
  .swatch { width: 12px; height: 12px; }

  .hud-hint { display: none; }              /* too cramped next to the leap dock */
  .hud-tip { font-size: 11px; padding: 6px 12px; white-space: normal; max-width: 84vw; text-align: center; }

  .settings-panel { padding: 16px 16px 18px; }
  .set-row { padding: 12px 0; }
  .seg-btn { padding: 7px 11px; font-size: 11px; }
}

/* very small / narrow phones */
@media (max-width: 380px) {
  .jump-btn { width: 132px; }
  .sb-glyph { font-size: 14px; }
  .sb-row { font-size: 9px; }
  .badge { font-size: 9px; padding: 3px 6px; }
}
