/* ==========================================================================
   ShootCute — HUD, crosshair and menu styling
   ========================================================================== */

:root {
  --ink: #1a1a2e;
  --paper: #ffffff;
  --pink: #ff4d6d;
  --pink-dark: #b3123a;
  --yellow: #ffd23f;
  --blue: #3a86ff;
  --green: #06d6a0;
  --overlay: rgba(26, 20, 60, 0.55);

  --crosshair: #ffffff;
  --crosshair-hit: #ffd23f;
  --hitmarker: #ff4d6d;

  --font: "Fredoka", "Baloo 2", "Arial Rounded MT Bold", "Varela Round", "Trebuchet MS", system-ui, sans-serif;
}

/* Fredoka (SIL Open Font License, assets/fonts/OFL.txt), bundled: no font loads from the internet.
   One variable file covers every weight the game uses (400-700). */
@font-face {
  font-family: "Fredoka";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("assets/fonts/fredoka-latin-wght.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Fredoka";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("assets/fonts/fredoka-latin-ext-wght.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #dff6ff;
  font-family: var(--font);
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
}

#game, #game canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hidden { display: none !important; }

/* --------------------------------------------------------------------------
   HUD
   -------------------------------------------------------------------------- */
#hud {
  --health-h: 46px;   /* the health bar's row along the top; the other boxes sit below it */
  position: fixed;
  top: calc(16px + var(--health-h) + 10px);
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 5;
}

.hud-box {
  min-width: 110px;
  padding: 8px 16px 10px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 4px 0 var(--ink);
  text-align: center;
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.hud-label {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.6;
}

.hud-value {
  font-size: 34px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.hud-sub { font-size: 12px; opacity: 0.6; margin-top: 2px; }

#hud-kills .hud-value { color: var(--pink); }
#hud-timer .hud-value { color: var(--blue); }

.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.hud-pill { flex-direction: row; gap: 6px; align-items: baseline; padding: 8px 16px; font-weight: 600; }
.hud-pill b { color: var(--pink); font-size: 22px; font-variant-numeric: tabular-nums; }
#hud-spawners.done b { color: var(--green); }

/* Health bar (Hard mode only): centered along the top, two thirds of the HUD's width */
#hud-health {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: calc((100vw - 32px) * 2 / 3);
  height: var(--health-h);
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
}
#hud.peaceful { top: 16px; }
#hud.peaceful #hud-health { display: none; }
#hud-health .hud-label { font-size: 15px; }
#hud-health .hud-sub { min-width: 2.2em; margin: 0; font-size: 18px; font-weight: 700; opacity: 0.8; text-align: right; font-variant-numeric: tabular-nums; }
.health-bar {
  flex: 1;
  height: 24px;
  background: #f3f0ff;
  border: 2px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
}
.health-fill {
  height: 100%;
  width: 100%;
  background: var(--green);
  border-radius: 999px;
  transition: width 0.15s ease-out, background-color 0.3s;
}
.health-fill.mid { background: var(--yellow); }
.health-fill.low { background: var(--pink); }

/* Boss health bar: just below the player's, shown only while a boss (Malaisey) is aware of you */
#hud-boss {
  position: fixed;
  top: calc(16px + var(--health-h) + 10px);
  left: 50%;
  transform: translateX(-50%);
  width: calc((100vw - 32px) * 0.42);
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding: 6px 16px;
  z-index: 5;
}
#hud-boss .hud-label { font-size: 13px; white-space: nowrap; }
.boss-bar { height: 16px; }
#hud-boss .health-fill { background: var(--pink); }

/* ---- Multi-kill badge (ui.showMultiKill): a big candy kill count + the tier's name ----------
   Upper centre, under the health and boss bars, well above the crosshair. Every timing, scale and
   color comes from CONFIG.combos.badge, set as the --mk-* properties on each show. A new multi-kill
   restarts every animation at once (no stacking). Only transform and opacity animate (plus the
   top tier's rainbow). Each face is three stacked copies of the text: a white outline with the
   colored shadow, the candy gradient, and a gloss on the upper part. */
#multikill {
  --mk-size: clamp(54px, min(13vh, 8.5vw), 116px);   /* the number's height; everything scales with it */
  --mk-a: #ffb3d1; --mk-b: #ffc9a3; --mk-c: #ff7aa8;  /* gradient top, bottom, shadow / accent */
  --mk-pop: 0.42s; --mk-hold: 0.93s; --mk-exit: 0.25s; --mk-text-delay: 0.08s;
  --mk-pop-scale: 1.3; --mk-tilt: 8deg; --mk-sparkle: 0.8s;
  position: fixed;
  left: 50%;
  top: max(124px, 15vh);          /* below the health bar and the boss bar */
  transform: translateX(-50%);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  z-index: 6;
}
#multikill.show { opacity: 1; }
#hud.hidden ~ #multikill { display: none; }

.mk-badge { display: flex; align-items: center; gap: calc(var(--mk-size) * 0.1); transform-origin: 35% 50%; }
.mk-numwrap { position: relative; isolation: isolate; font-size: var(--mk-size); line-height: 1; }
.mk-num { transform-origin: 50% 60%; }
.mk-words {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.12em;
  font-size: calc(var(--mk-size) * 0.5);
  transform-origin: 0 50%;
}
#multikill.long .mk-words { font-size: calc(var(--mk-size) * 0.4); }

.mk-face {
  --mk-stroke: 0.17em;            /* outline (half shows outside the letters) */
  display: inline-grid;
  font-family: var(--font);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: 0.01em;
}
.mk-face > span { position: relative; grid-area: 1 / 1; padding: 0 0.08em; }   /* positioned: the filtered outline layer then paints in DOM order, under the fill */
.mk-num-face { font-size: var(--mk-size); letter-spacing: -0.02em; }
.mk-name-face { --mk-stroke: 0.22em; }
.mk-out {
  color: #fff;
  -webkit-text-stroke: var(--mk-stroke) #fff;
  filter: drop-shadow(0 0.055em 0 var(--mk-c)) drop-shadow(0 0.1em 0.12em color-mix(in srgb, var(--mk-c) 55%, transparent));
}
.mk-fill {
  color: transparent;
  background: linear-gradient(180deg, var(--mk-a) 18%, var(--mk-b) 82%);
  -webkit-background-clip: text;
  background-clip: text;
}
.mk-gloss {
  color: transparent;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95) 8%, rgba(255, 255, 255, 0.5) 30%, rgba(255, 255, 255, 0) 47%);
  -webkit-background-clip: text;
  background-clip: text;
}
.mk-bonus {
  margin-left: 0.25em;
  padding: 0.05em 0.6em 0.1em;
  font-size: max(11px, 0.42em);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: var(--mk-c);
  border: 0.14em solid #fff;
  border-radius: 999px;
  box-shadow: 0 0.14em 0 color-mix(in srgb, var(--mk-c) 60%, var(--ink));
}
/* Top tier: the gradient shimmers through the rainbow. */
#multikill.rainbow .mk-fill {
  background: linear-gradient(100deg, #ff8fc0, #ffd86b, #a8f59a, #7fd8ff, #c9a0ff, #ff8fc0, #ffd86b, #a8f59a);
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
}

/* Splash: pooled particles (stars, hearts, sparkles, dots, confetti) fly out from behind the number. */
.mk-burst { position: absolute; left: 50%; top: 52%; width: 0; height: 0; z-index: -1; }
.mk-p {
  --a: 0deg; --d: 1em; --s: 1; --spin: 180deg; --delay: 0s; --c: #fff;
  position: absolute;
  left: -0.09em;
  top: -0.09em;
  width: 0.2em;
  height: 0.2em;
  background: var(--c);
  opacity: 0;
}
.mk-p.off { display: none; }   /* not used by this tier */
.mk-p-dot { border-radius: 50%; width: 0.15em; height: 0.15em; }
.mk-p-confetti { width: 0.09em; height: 0.26em; border-radius: 0.03em; }
.mk-p-star, .mk-p-heart, .mk-p-sparkle { -webkit-mask: var(--shape) center / contain no-repeat; mask: var(--shape) center / contain no-repeat; }
.mk-p-star { --shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 1.5l3.1 6.6 7.2.9-5.3 5 1.4 7.1L12 17.6 5.6 21.1 7 14l-5.3-5 7.2-.9z'/%3E%3C/svg%3E"); width: 0.34em; height: 0.34em; }
.mk-p-heart { --shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 21.4C5.4 16.2 1.5 12.6 1.5 8.1 1.5 4.9 4 2.6 7 2.6c2 0 3.8 1.1 5 2.8 1.2-1.7 3-2.8 5-2.8 3 0 5.5 2.3 5.5 5.5 0 4.5-3.9 8.1-10.5 13.3z'/%3E%3C/svg%3E"); width: 0.34em; height: 0.34em; }
.mk-p-sparkle { --shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 0c.8 6.4 4.6 10.6 12 12-7.4 1.4-11.2 5.6-12 12-.8-6.4-4.6-10.6-12-12 7.4-1.4 11.2-5.6 12-12z'/%3E%3C/svg%3E"); width: 0.32em; height: 0.32em; }

/* Animations (all restart when ui.js re-adds .show) */
#multikill.show .mk-badge { animation: mk-exit var(--mk-exit) ease-in calc(var(--mk-pop) + var(--mk-hold)) both; }
#multikill.show .mk-num { animation: mk-pop var(--mk-pop) linear both; }
#multikill.show .mk-num-face { animation: mk-squish calc(var(--mk-hold) / 2) ease-in-out var(--mk-pop) 2 alternate; }
#multikill.show .mk-words { animation: mk-words var(--mk-pop) linear var(--mk-text-delay) both; }
#multikill.show .mk-name-face { animation: mk-sway calc(var(--mk-hold) / 2) ease-in-out calc(var(--mk-pop) + var(--mk-text-delay)) 2 alternate; }
#multikill.show .mk-p { animation: mk-sparkle var(--mk-sparkle) cubic-bezier(0.15, 0.75, 0.3, 1) var(--delay) both; }
#multikill.show.rainbow .mk-fill { animation: mk-rainbow calc(var(--mk-pop) + var(--mk-hold) + var(--mk-exit)) linear both; }

@keyframes mk-pop {
  0%   { transform: scale(0) rotate(calc(var(--mk-tilt) * -1.5)); animation-timing-function: cubic-bezier(0.2, 0.8, 0.4, 1); }
  45%  { transform: scale(var(--mk-pop-scale)) rotate(var(--mk-tilt)); animation-timing-function: ease-in-out; }
  68%  { transform: scale(0.9) rotate(calc(var(--mk-tilt) * -0.5)); animation-timing-function: ease-in-out; }
  85%  { transform: scale(1.05) rotate(calc(var(--mk-tilt) * 0.15)); animation-timing-function: ease-in-out; }
  100% { transform: scale(1) rotate(calc(var(--mk-tilt) * -0.25)); }
}
@keyframes mk-words {
  0%   { opacity: 0; transform: translateX(-0.5em) scale(0.3); animation-timing-function: cubic-bezier(0.2, 0.8, 0.4, 1); }
  50%  { opacity: 1; transform: translateX(0.05em) scale(1.12); animation-timing-function: ease-in-out; }
  78%  { transform: scale(0.96); animation-timing-function: ease-in-out; }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes mk-squish {
  from { transform: scale(1.04, 0.96) rotate(-1.5deg); }
  to   { transform: scale(0.97, 1.03) rotate(1.5deg); }
}
@keyframes mk-sway {
  from { transform: rotate(-1deg) translateY(0.02em); }
  to   { transform: rotate(1deg) translateY(-0.02em); }
}
@keyframes mk-exit {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(0.55); }
}
@keyframes mk-sparkle {
  0%   { opacity: 1; transform: rotate(var(--a)) translateX(0.15em) scale(0) rotate(0deg); }
  25%  { opacity: 1; transform: rotate(var(--a)) translateX(calc(var(--d) * 0.65)) scale(var(--s)) rotate(calc(var(--spin) * 0.35)); }
  100% { opacity: 0; transform: rotate(var(--a)) translateX(var(--d)) scale(calc(var(--s) * 0.35)) rotate(var(--spin)); }
}
@keyframes mk-rainbow {
  from { background-position: 0% 50%; }
  to   { background-position: 100% 50%; }
}

/* Reduce motion (Settings): fade in, hold, fade out; no pop, wobble or splash. */
body.reduce-motion #multikill.show .mk-badge { animation: mk-fade calc(var(--mk-pop) + var(--mk-hold) + var(--mk-exit)) linear both; }
body.reduce-motion #multikill.show :is(.mk-num, .mk-num-face, .mk-words, .mk-name-face, .mk-fill) { animation: none; }
body.reduce-motion .mk-burst { display: none; }
@keyframes mk-fade {
  0%   { opacity: 0; }
  15%  { opacity: 1; }
  85%  { opacity: 1; }
  100% { opacity: 0; }
}

/* Kill count "pop" when it increases */
.hud-value.bump { animation: bump 0.25s ease-out; }
@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

/* ---- Weapon panel (bottom right) ---- */
#loadout {
  position: fixed;
  right: 16px;
  bottom: 16px;
  min-width: 170px;
  text-align: right;
  align-items: flex-end;
  pointer-events: none;
  z-index: 5;
}
.loadout-gun { font-size: 22px; font-weight: 700; }
.loadout-grenades { margin-top: 2px; display: flex; gap: 6px; align-items: center; }
#grenade-pips { letter-spacing: 2px; font-size: 18px; color: #f2b8cf; }
#grenade-pips b { color: var(--pink); font-weight: 700; }

/* ---- Interaction prompt: "Press E to …" ---- */
#prompt {
  position: fixed;
  left: 50%;
  top: calc(50% + 48px);
  transform: translateX(-50%);
  padding: 8px 18px;
  background: rgba(26, 26, 46, 0.82);
  color: var(--paper);
  border-radius: 999px;
  font-weight: 600;
  font-size: 17px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 6;
}
#prompt.info { background: rgba(179, 18, 58, 0.85); }

/* ---- Full-screen effects ---- */
#vignette, #shimmer, #fade {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
}
#vignette {
  background: radial-gradient(ellipse at center, transparent 45%, rgba(220, 0, 40, 0.75) 100%);
  z-index: 7;
}
#vignette.hit { animation: vignette-flash 0.35s ease-out; }
@keyframes vignette-flash { 0% { opacity: 1; } 100% { opacity: 0; } }

/* Respawn invulnerability: a pastel shimmer around the screen edges. */
#shimmer {
  background: radial-gradient(ellipse at center, transparent 55%, rgba(190, 160, 255, 0.55) 100%);
  z-index: 7;
}
#shimmer.on { animation: shimmer 0.35s ease-in-out infinite alternate; }
@keyframes shimmer { from { opacity: 0.2; } to { opacity: 0.9; } }

#fade { background: #000; z-index: 9; transition: opacity 0.6s ease; }
#fade.on { opacity: 1; }

#death {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(60, 0, 20, 0.55);
  color: var(--paper);
  text-shadow: 0 3px 0 var(--ink);
  pointer-events: none;
  z-index: 8;
  animation: death-in 0.4s ease-out;
}
.death-title { font-size: 56px; font-weight: 700; }
.death-sub { font-size: 20px; font-weight: 600; opacity: 0.85; }
@keyframes death-in { from { opacity: 0; transform: scale(1.1); } to { opacity: 1; transform: scale(1); } }

/* ---- Gun view tuner (?debug=1, key 6): the pause menu hides so the gun stays in view ---- */
#view-tuner {
  position: fixed;
  left: 16px;
  top: 90px;
  width: 300px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.78);
  color: #9ff;
  border-radius: 8px;
  font: 12px/1.5 ui-monospace, Consolas, monospace;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#view-tuner .vt-tabs { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
#view-tuner .vt-tabs button { flex: 1; }
#view-tuner .vt-tabs button.vt-tab-on { background: #2a5a5a; color: #fff; }
#view-tuner .vt-head { display: flex; gap: 6px; align-items: center; font-weight: 700; margin-bottom: 4px; }
#view-tuner .vt-head select { flex: 1; }
#view-tuner .vt-row { display: grid; grid-template-columns: 110px 1fr 46px; gap: 6px; align-items: center; }
#view-tuner .vt-row:has(button) { grid-template-columns: 1fr 1fr; }
#view-tuner .vt-hint { opacity: 0.8; margin: 2px 0; }
#view-tuner textarea { width: 100%; font: 11px ui-monospace, Consolas, monospace; resize: none; }
body.view-tuning #screen-paused { background: transparent; backdrop-filter: none; }
body.view-tuning #screen-paused > * { display: none; }

/* ---- Debug panel (?debug=1) ---- */
#debug-panel {
  position: fixed;
  left: 16px;
  bottom: 16px;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.7);
  color: #9ff;
  font: 11px/1.45 ui-monospace, Consolas, monospace;
  border-radius: 8px;
  white-space: pre;
  max-height: 42vh;
  overflow-y: auto;
  pointer-events: none;
  z-index: 6;
}
/* Damage events with kills (combo testing): newest at the bottom */
#debug-events {
  position: fixed;
  right: calc(env(safe-area-inset-right) + 16px);
  top: 38%;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  pointer-events: none;
  z-index: 8;
}
#debug-events div {
  padding: 2px 8px;
  background: rgba(0, 0, 0, 0.7);
  color: #9ff;
  font: 12px/1.4 ui-monospace, Consolas, monospace;
  border-radius: 6px;
  white-space: pre;
}
#debug-events div.combo { color: #ff0; }

/* ---- Toast: short messages like "Elevator locked" ---- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 18%;
  transform: translate(-50%, 8px);
  padding: 10px 20px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 4px 0 var(--ink);
  font-weight: 600;
  font-size: 18px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 12; /* above the menu screens too ("Logged out", "Account deleted") */
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* --------------------------------------------------------------------------
   Crosshair: a zero-size box at 50%/50%, so every child is positioned
   relative to the exact screen center (where the shooting ray goes).
   -------------------------------------------------------------------------- */
#crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 6;
  transition: transform 0.12s ease-out;
}

/* Brief "kick" outward on every shot (hit or miss) */
#crosshair.fire { transform: scale(1.4); transition: none; }

.ch {
  position: absolute;
  background: var(--crosshair);
  box-shadow: 0 0 0 1px rgba(26, 26, 46, 0.75);
  border-radius: 1px;
  transition: background 0.15s;
}
.ch-top    { width: 2px; height: 8px; left: -1px; top: -14px; }
.ch-bottom { width: 2px; height: 8px; left: -1px; top: 6px; }
.ch-left   { width: 8px; height: 2px; left: -14px; top: -1px; }
.ch-right  { width: 8px; height: 2px; left: 6px; top: -1px; }
.ch-dot    { width: 2px; height: 2px; left: -1px; top: -1px; }

/* Hit feedback: crosshair flashes yellow and a red "X" hitmarker appears */
#crosshair.hit .ch { background: var(--crosshair-hit); transition: none; }

.hitmarker { position: absolute; left: 0; top: 0; opacity: 0; }
#crosshair.hit .hitmarker { animation: hitmarker 0.3s ease-out forwards; }
.hm {
  position: absolute;
  width: 3px;
  height: 9px;
  background: var(--hitmarker);
  box-shadow: 0 0 0 1px rgba(26, 26, 46, 0.6);
  border-radius: 2px;
}
.hm-1 { left: 7px;   top: -17px; transform: rotate(45deg); }
.hm-2 { left: 7px;   top: 8px;   transform: rotate(-45deg); }
.hm-3 { left: -10px; top: 8px;   transform: rotate(45deg); }
.hm-4 { left: -10px; top: -17px; transform: rotate(-45deg); }
@keyframes hitmarker {
  0% { opacity: 1; transform: scale(0.7); }
  30% { opacity: 1; transform: scale(1.15); }
  100% { opacity: 0; transform: scale(1); }
}

/* --------------------------------------------------------------------------
   Menu screens
   -------------------------------------------------------------------------- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--overlay);
  backdrop-filter: blur(3px);
  z-index: 10;
}

.card {
  width: 100%;
  max-width: 460px;
  padding: 28px 32px 30px;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 28px;
  box-shadow: 0 8px 0 var(--ink);
  text-align: center;
  max-height: 100%;   /* the pause menu can be taller than a short window */
  overflow-y: auto;
}

h1, h2 { margin: 0 0 6px; line-height: 1.05; }
h1 { font-size: 46px; }
h2 { font-size: 38px; }
h1 .accent { color: var(--pink); }

.tagline { margin: 0 0 18px; opacity: 0.75; }
.eyebrow {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--pink);
}

/* ---- Mode picker (start screen) ---- */
.modes { border: 0; margin: 0 0 18px; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modes legend { margin-bottom: 8px; padding: 0; width: 100%; }
.mode {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  text-align: left;
  background: #f3f0ff;
  border: 3px solid transparent;
  border-radius: 16px;
  cursor: pointer;
}
.mode input { position: absolute; opacity: 0; pointer-events: none; }
.mode:has(input:checked) { border-color: var(--ink); background: #ffe8f0; box-shadow: 0 3px 0 var(--ink); }
.mode:has(input:focus-visible) { outline: 3px solid var(--blue); outline-offset: 2px; }
.mode-name { font-weight: 700; font-size: 18px; }
.mode-desc { font-size: 13px; opacity: 0.75; line-height: 1.3; }

.controls {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: grid;
  gap: 8px;
  text-align: left;
}
.controls li { display: flex; align-items: center; gap: 12px; }
/* Two columns on the start screen so Start stays on screen with the mode picker. */
#screen-start .controls { grid-template-columns: 1fr 1fr; column-gap: 14px; font-size: 14px; }
#screen-start .controls .keys { min-width: 96px; }
#screen-start .card { max-width: 540px; }
.controls .keys { display: inline-flex; gap: 4px; min-width: 150px; justify-content: flex-end; }

kbd {
  display: inline-block;
  min-width: 28px;
  padding: 3px 8px;
  font: 600 13px var(--font);
  text-align: center;
  background: #f3f0ff;
  border: 2px solid var(--ink);
  border-radius: 8px;
  box-shadow: 0 2px 0 var(--ink);
}

.slider {
  display: block;
  margin: 0 0 20px;
  font-size: 14px;
  font-weight: 600;
}
.slider output { color: var(--blue); }
.slider input { display: block; width: 100%; margin-top: 6px; accent-color: var(--blue); }

.btn {
  font: 700 22px var(--font);
  color: var(--paper);
  background: var(--pink);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 12px 44px;
  box-shadow: 0 5px 0 var(--ink);
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }

.btn:disabled { filter: grayscale(0.6) opacity(0.7); cursor: default; transform: none; }
.btn.sending { cursor: progress; }

.btn-secondary { background: var(--paper); color: var(--ink); }

.menu-buttons { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.menu-buttons .btn { width: 100%; max-width: 280px; padding-left: 0; padding-right: 0; }

/* ---- Pause menu stats ---- */
.section-title {
  margin: 0 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.6;
}
#screen-paused .stats { margin: 0 0 18px; }
#screen-paused .lock-hint { margin: -8px 0 18px; }
#screen-paused .menu-buttons { margin-bottom: 22px; }
#screen-paused .menu-buttons .btn { max-width: 300px; }
#screen-paused .menu-row { display: flex; gap: 10px; width: 100%; max-width: 300px; }
#screen-paused .menu-row .btn { flex: 1; padding-left: 0; padding-right: 0; }
.pause-keys { margin: 0; font-size: 13px; opacity: 0.6; }
.quit-question { margin: 0 0 4px; max-width: 300px; font-weight: 600; }

.lock-hint { margin: 14px 0 0; font-size: 14px; color: var(--pink-dark); font-weight: 600; }

.new-best { margin: 0 0 8px; font-weight: 700; color: var(--green); }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 8px;
  margin: 14px 0 22px;
}
.stats div {
  display: flex;
  flex-direction: column;
  padding: 8px 4px;
  background: #f3f0ff;
  border-radius: 12px;
  font-size: 22px;
  font-weight: 700;
}
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.6; }

/* --------------------------------------------------------------------------
   Loading screen (the bobbing creature is drawn on the game canvas behind it)
   -------------------------------------------------------------------------- */
.screen-loading {
  background: transparent;
  backdrop-filter: none;
  align-items: flex-end;
  padding-bottom: 16vh;
}
.loading-box { width: min(440px, 88vw); text-align: center; color: #f7e9f1; }
.loading-bar {
  height: 18px;
  padding: 3px;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid #f7c6dd;
  border-radius: 999px;
  overflow: hidden;
}
.loading-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff9fc6, #ffd6a5);
  transition: width 0.2s ease-out;
}
.loading-pct { margin: 10px 0 2px; font-weight: 700; font-size: 18px; letter-spacing: 0.04em; }
.loading-tip { margin: 0 0 14px; font-size: 15px; opacity: 0.8; min-height: 1.4em; }

/* Grenade counter bump when grenades are picked up */
#grenade-pips.bump { animation: bump 0.3s ease-out; display: inline-block; }

/* --------------------------------------------------------------------------
   Scores (Phase 4)
   -------------------------------------------------------------------------- */
.hud-score { font-size: 14px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.hud-score b { color: var(--pink); font-size: 16px; }
.score-debug {
  margin-top: 6px;
  padding: 6px 8px;
  background: #1a1a2e;
  color: #9ff;
  border-radius: 8px;
  font: 12px/1.45 ui-monospace, Consolas, monospace;
  text-align: left;
  white-space: pre;
}

.btn-small { font-size: 17px; padding: 9px 26px; box-shadow: 0 4px 0 var(--ink); }
.menu-row { flex-direction: row; flex-wrap: wrap; justify-content: center; }
.menu-row .btn { width: auto; max-width: none; padding: 9px 20px; }
#screen-start .menu-buttons .btn-small { width: auto; padding: 8px 28px; }

.final-score-label { margin-top: 10px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.6; }
.final-score {
  font-size: 60px;
  font-weight: 700;
  line-height: 1;
  color: var(--pink);
  margin: 2px 0 14px;
  font-variant-numeric: tabular-nums;
}

/* Score card: one line per part of the formula, counting up in turn. */
.breakdown { display: grid; gap: 6px; margin: 14px 0 6px; text-align: left; }
.breakdown-line {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 12px;
  padding: 8px 14px;
  background: #f3f0ff;
  border-radius: 12px;
  opacity: 0.25;
  transition: opacity 0.2s;
}
.breakdown-line.shown { opacity: 1; }
.breakdown-what { font-weight: 600; }
.breakdown-what small { font-weight: 400; opacity: 0.65; margin-left: 6px; }
.breakdown-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.breakdown-value.plus { color: var(--green); }
.breakdown-value.times { color: var(--blue); }
.breakdown-value.minus { color: var(--pink-dark); }

/* Run complete */
.card-wide { max-width: 560px; }
.level-table { width: 100%; border-collapse: collapse; margin: 0 0 8px; font-size: 14px; font-variant-numeric: tabular-nums; }
.level-table th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.6; padding: 4px; }
.level-table td { padding: 6px 4px; border-top: 2px solid #f3f0ff; }
.level-table td:first-child, .level-table th:first-child { text-align: left; }
.level-table .lt-score { font-weight: 700; color: var(--pink); }

.submit-form { margin: 4px 0 16px; text-align: left; }
.submit-form label { display: block; }
.submit-row { display: flex; gap: 8px; }
.submit-row input {
  flex: 1;
  min-width: 0;
  font: 600 18px var(--font);
  padding: 8px 14px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  outline: none;
}
.submit-row input:focus { border-color: var(--blue); }
.submit-msg { min-height: 1.3em; margin: 6px 0 0; font-weight: 600; font-size: 15px; }
.submit-msg.error { color: var(--pink-dark); }
.submit-msg.ok { color: #058a66; }

/* Leaderboard */
.card-board { max-width: 760px; display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.lb-test-note { margin: 0 0 6px; font-size: 13px; font-weight: 700; color: var(--pink-dark); }
.lb-tabs { display: flex; justify-content: center; gap: 8px; margin: 6px 0 4px; }
.lb-tab {
  font: 700 17px var(--font);
  padding: 7px 22px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  cursor: pointer;
}
.lb-tab.active { background: var(--ink); color: var(--paper); }
.lb-hint { margin: 2px 0 8px; font-size: 12px; opacity: 0.6; }
.lb-scroll {
  flex: 1;
  min-height: 160px;
  max-height: 58vh;
  overflow-y: auto;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: #fbfaff;
}
.lb-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.lb-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--paper);
  border-bottom: 2px solid var(--ink);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 6px 4px;
}
.lb-table th button {
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  background: none;
  border: 0;
  padding: 2px 4px;
  cursor: pointer;
  color: var(--ink);
  opacity: 0.7;
  border-radius: 6px;
}
.lb-table th button:hover { background: #f3f0ff; opacity: 1; }
.lb-table th button.active { opacity: 1; color: var(--pink); }
.lb-table td { padding: 6px 4px; border-bottom: 1px solid #ece8f8; text-align: center; white-space: nowrap; }
.lb-table .col-name { text-align: left; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
.lb-table td.col-score { font-weight: 700; }
.lb-table td.col-rank { opacity: 0.6; }
.lb-table tr.mine td { background: #fff1c9; }
.lb-table tr.mine td.col-name { font-weight: 700; }
.lb-table tr.just-added td { background: #ffd6ea; animation: just-added 1.2s ease-out 2; }
.lb-table tr.just-added td.col-name { font-weight: 700; }
@keyframes just-added { 0% { background: #ff9fcb; } 100% { background: #ffd6ea; } }
.lb-yours { margin: 0 0 6px; font-weight: 700; font-size: 16px; color: var(--pink-dark); }
.lb-status { margin: 10px 0; font-size: 13px; opacity: 0.65; }
.lb-pinned {
  margin: 8px 0 0;
  padding: 8px 14px;
  font: 700 15px var(--font);
  background: #fff1c9;
  border: 3px solid var(--ink);
  border-radius: 12px;
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
  text-align: left;
}

@media (max-width: 560px) {
  .lb-table .col-date { display: none; }
  .lb-table { font-size: 11px; }
  .lb-table td, .lb-table th { padding: 5px 1px; }
  .lb-table th { font-size: 10px; letter-spacing: 0; }
  .lb-table th button { padding: 2px 1px; }
  .lb-table .col-name { max-width: 68px; }
  .lb-scroll { overflow-x: auto; }
  .final-score { font-size: 46px; }
  .submit-row { flex-direction: column; }
}

@media (max-width: 480px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .modes { grid-template-columns: 1fr; }
  .card { padding: 22px 18px 24px; }
  .controls .keys { min-width: 120px; }
  #screen-start .controls { grid-template-columns: 1fr; }
  h1 { font-size: 36px; }
}

/* ==========================================================================
   Phones and tablets (Phase 6). `body.touch` is set while the touch controls are
   the active input; `body.touch-device` on any touch-first device.
   ========================================================================== */

/* No pinch / double-tap zoom, pull-to-refresh, text selection or long-press menus.
   Menus still scroll (cards and the leaderboard are their own scroll areas). */
html { overscroll-behavior: none; }
body { touch-action: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
.card, .lb-scroll { touch-action: pan-y; overscroll-behavior: contain; }
.screen {
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

body.touch .desktop-only { display: none !important; }
body:not(.touch) .touch-only { display: none !important; }
body:not(.touch-device) .touch-setting { display: none !important; }
.touch-intro { margin: 0 0 16px; font-size: 15px; opacity: 0.8; }

/* ---- On-screen controls (src/touch.js) ----------------------------------------- */
#touch-controls {
  --safe-x: max(env(safe-area-inset-left), env(safe-area-inset-right));
  --safe-b: env(safe-area-inset-bottom);
  position: fixed;
  inset: 0;
  z-index: 6;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.tc-cluster { position: absolute; inset: 0; pointer-events: none; }
body.lefty .tc-cluster { transform: scaleX(-1); }   /* mirror: buttons on the left */
.tc-btn {
  position: absolute;
  margin: 0;
  padding: var(--tc-pad);  /* invisible extra touch area around the visible button */
  border: 0;
  background: none;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.tc-face {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.26);
  border: 3px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 3px 0 rgba(26, 26, 46, 0.45);
  color: #fff;
  font: 700 15px var(--font);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
  transition: transform 0.06s, background-color 0.1s;
}
body.lefty .tc-cluster .tc-face { transform: scaleX(-1); }  /* keep the text readable */
.tc-btn.down .tc-face { transform: scale(0.92); background: rgba(255, 77, 109, 0.6); }
body.lefty .tc-cluster .tc-btn.down .tc-face { transform: scaleX(-1) scale(0.92); }

/* Fire under the right thumb, the others around it (all from the bottom-right corner). */
.tc-fire {
  --size: var(--tc-fire);
  right: calc(var(--tc-edge) + var(--safe-x) - var(--tc-pad));
  bottom: calc(var(--tc-edge) + var(--safe-b) - var(--tc-pad));
}
.tc-fire .tc-face { background: rgba(255, 77, 109, 0.42); font-size: 20px; }
.tc-action { --size: var(--tc-action); }
.tc-melee {
  right: calc(var(--tc-edge) + var(--safe-x) + var(--tc-fire) + 14px - var(--tc-pad));
  bottom: calc(var(--tc-edge) + var(--safe-b) - var(--tc-pad));
}
.tc-grenade {
  right: calc(var(--tc-edge) + var(--safe-x) + (var(--tc-fire) - var(--tc-action)) / 2 - var(--tc-pad));
  bottom: calc(var(--tc-edge) + var(--safe-b) + var(--tc-fire) + 14px - var(--tc-pad));
}
.tc-jump {
  right: calc(var(--tc-edge) + var(--safe-x) + var(--tc-fire) + 14px - var(--tc-pad));
  bottom: calc(var(--tc-edge) + var(--safe-b) + var(--tc-action) + 14px - var(--tc-pad));
}
.tc-grenade small { font-size: 10px; font-weight: 600; opacity: 0.9; }
.tc-grenade b { font-size: 22px; line-height: 1; }
.tc-grenade.empty .tc-face { opacity: 0.4; filter: grayscale(1); }
.tc-interact {
  right: calc(var(--tc-edge) + var(--safe-x) + var(--tc-fire) + var(--tc-action) + 28px - var(--tc-pad));
  bottom: calc(var(--tc-edge) + var(--safe-b) + (var(--tc-action) - var(--tc-interact)) / 2 - var(--tc-pad));
}
.tc-interact .tc-face {
  width: auto;
  min-width: 120px;
  height: var(--tc-interact);
  padding: 0 18px;
  border-radius: 999px;
  background: rgba(6, 214, 160, 0.6);
  font-size: 17px;
  white-space: nowrap;
}
.tc-pause {
  --size: var(--tc-pause);
  left: calc(env(safe-area-inset-left) + 6px - var(--tc-pad));
  top: calc(env(safe-area-inset-top) + 6px - var(--tc-pad));
}
.tc-pause .tc-face { border-radius: 14px; font-size: 18px; letter-spacing: 2px; background: rgba(26, 26, 46, 0.45); }

/* Floating joystick: the base sits where the thumb landed. */
.tc-stick {
  position: absolute;
  width: calc(2 * var(--tc-stick));
  height: calc(2 * var(--tc-stick));
  margin: calc(-1 * var(--tc-stick)) 0 0 calc(-1 * var(--tc-stick));
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 3px solid rgba(255, 255, 255, 0.5);
  pointer-events: none;
}
.tc-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  border: 3px solid #fff;
}

/* ---- Compact HUD: one strip along the top, clear of the thumbs ------------------ */
body.touch #hud {
  --health-h: 26px;
  top: calc(env(safe-area-inset-top) + 6px + var(--health-h) + 6px);
  left: calc(env(safe-area-inset-left) + 74px);   /* room for the pause button and its touch area */
  right: calc(env(safe-area-inset-right) + 8px);
  gap: 6px;
}
body.touch .hud-box { min-width: 0; padding: 3px 10px 4px; border-width: 2px; border-radius: 12px; box-shadow: 0 2px 0 var(--ink); }
body.touch .hud-label { font-size: 9px; }
body.touch .hud-value { font-size: 20px; }
body.touch .hud-sub { font-size: 9px; margin-top: 0; }
body.touch #hud.peaceful { top: calc(env(safe-area-inset-top) + 6px); }
body.touch #hud-health {
  top: calc(env(safe-area-inset-top) + 6px);
  width: calc((100vw - env(safe-area-inset-left) - env(safe-area-inset-right) - 16px) * 2 / 3);
  gap: 8px;
  padding: 0 10px;
}
body.touch #hud-health .hud-label { font-size: 10px; }
/* Boss bar: below the row under the health bar (time, weapon name, spawners, kills: it ends ~67px down),
   so it never covers the weapon name or the spawners pill. Compact like the other touch boxes. */
body.touch #hud-boss {
  top: calc(env(safe-area-inset-top) + 70px);
  gap: 6px;
  padding: 2px 10px 3px;
}
body.touch #hud-boss .hud-label { font-size: 10px; }
body.touch #multikill { --mk-size: clamp(34px, 11vmin, 60px); top: calc(env(safe-area-inset-top) + 70px); }   /* under the weapon name */
body.touch #hud:has(#hud-boss:not(.hidden)) ~ #multikill { top: calc(env(safe-area-inset-top) + 100px); }      /* and under the boss bar */
body.touch #hud-health .hud-sub { font-size: 12px; }
body.touch .health-bar { height: 14px; }
body.touch .hud-right { flex-direction: row; gap: 6px; align-items: flex-start; }
body.touch .hud-pill { padding: 4px 10px; font-size: 12px; }
body.touch .hud-pill b { font-size: 16px; }
body.touch .hud-score { font-size: 11px; margin-top: 0; }
body.touch .hud-score b { font-size: 12px; }
body.touch #loadout {
  top: calc(env(safe-area-inset-top) + 38px);   /* the middle of the row under the health bar */
  left: 50%;
  right: auto;
  bottom: auto;
  transform: translateX(-50%);
  min-width: 0;
  padding: 2px 12px;
}
body.touch #loadout .hud-label, body.touch .loadout-grenades { display: none; }  /* the count is on the Grenade button */
body.touch .loadout-gun { font-size: 14px; }
body.touch #toast { bottom: auto; top: 30%; font-size: 15px; }
body.touch #prompt { font-size: 14px; }
body.touch #debug-panel { display: none !important; }  /* the touch debug overlay replaces it */

/* ---- "Rotate your phone" ----------------------------------------------------------- */
#rotate { display: none; }
@media (orientation: portrait) {
  body.touch #rotate {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: #2a2033;
    color: #f7e9f1;
    text-align: center;
    touch-action: none;
  }
}
#rotate p { margin: 18px 0 0; font-size: 24px; font-weight: 700; }
#rotate small { font-size: 15px; opacity: 0.75; }
.rotate-icon {
  width: 46px;
  height: 76px;
  border: 4px solid #f7c6dd;
  border-radius: 10px;
  animation: rotate-hint 2.2s ease-in-out infinite;
}
@keyframes rotate-hint { 0%, 25% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }

/* ---- First-time controls help --------------------------------------------------------- */
#touch-help { position: fixed; inset: 0; z-index: 9; background: rgba(26, 20, 60, 0.55); touch-action: none; }
.th-label {
  position: absolute;
  padding: 6px 12px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 3px 0 var(--ink);
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  pointer-events: none;
}
.th-label small { display: block; max-width: 170px; white-space: normal; font-weight: 500; font-size: 11px; line-height: 1.25; opacity: 0.7; }
.th-label[data-side="left"] { transform: translate(-100%, -50%); }
.th-label[data-side="right"] { transform: translate(0, -50%); }
.th-label[data-side="center"] { transform: translate(-50%, -50%); text-align: center; border-style: dashed; }
.th-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.th-lines line { stroke: var(--paper); stroke-width: 2; stroke-dasharray: 4 4; }
.th-lines circle { fill: var(--paper); }
.th-tap {
  position: absolute;
  left: 25%;
  top: 34%;
  transform: translate(-50%, -50%);
  margin: 0;
  color: var(--paper);
  font-weight: 700;
  font-size: 20px;
  text-shadow: 0 2px 0 var(--ink);
  white-space: nowrap;
}

/* ---- Settings --------------------------------------------------------------------- */
.card-settings { max-width: 640px; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 22px; margin: 10px 0 16px; text-align: left; }
.settings-grid .slider { margin: 0; }
.toggle { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; font-size: 15px; cursor: pointer; }
.toggle input { flex: none; width: 22px; height: 22px; accent-color: var(--pink); }
.toggle small { display: block; font-weight: 400; font-size: 12px; opacity: 0.65; }
.segmented { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; border: 0; }
.segmented legend { margin-bottom: 6px; padding: 0; font-weight: 600; font-size: 14px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.segmented input:checked + span { background: var(--ink); color: var(--paper); }
.segmented input:focus-visible + span { outline: 3px solid var(--blue); outline-offset: 2px; }
.setting-note { flex-basis: 100%; min-height: 1.2em; margin: 2px 0 0; font-size: 12px; opacity: 0.7; }
/* Back stays on screen while the settings scroll. */
.card-settings .menu-buttons {
  position: sticky;
  bottom: -18px;
  margin: 0 -8px -18px;
  padding: 8px 0 14px;
  background: var(--paper);
  border-top: 2px solid #f3f0ff;
}
@media (max-width: 560px) { .settings-grid { grid-template-columns: 1fr; } }
@media (max-height: 520px) {
  .settings-grid { gap: 4px 22px; margin: 4px 0 8px; }
  .segmented span { padding: 0 11px; font-size: 13px; }
  .card-settings h2 { margin-bottom: 0; }
}

/* ---- Touch: every tap target at least 44 px; short landscape screens stay compact ----- */
body.touch .btn, body.touch .lb-tab, body.touch .lb-pinned, body.touch .submit-row input,
body.touch .segmented span { min-height: 44px; }
body.touch .lb-table th button { min-height: 44px; min-width: 44px; }
body.touch .slider input[type="range"] { height: 44px; margin-top: 0; }
@media (max-height: 520px) {
  .card { padding: 16px 22px 18px; border-radius: 22px; }
  h1 { font-size: 34px; }
  h2 { font-size: 28px; }
  .tagline { margin-bottom: 10px; }
  .modes { margin-bottom: 10px; }
  .final-score { font-size: 42px; }
  .menu-buttons { gap: 8px; }
  /* The pause menu fits a landscape phone without scrolling. */
  #screen-paused .menu-buttons { margin-bottom: 12px; }
  #screen-paused .card { padding-bottom: 12px; }
  #screen-paused .menu-buttons .btn:not(.btn-small) { padding-top: 8px; padding-bottom: 8px; }
  #screen-paused .section-title { margin-bottom: 4px; }
  #screen-paused .stats { margin-bottom: 0; }
  #screen-paused .stats div { padding: 4px; font-size: 18px; }
}

/* ---- Debug overlay on touch (?debug=1) ------------------------------------------------- */
#debug-touch { position: fixed; inset: 0; z-index: 8; pointer-events: none; }
.dbg-touch-info {
  position: absolute;
  right: calc(env(safe-area-inset-right) + 8px);
  top: calc(env(safe-area-inset-top) + 96px);
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.65);
  color: #9ff;
  border-radius: 6px;
  font: 11px/1.4 ui-monospace, Consolas, monospace;
  white-space: pre;
}
.dbg-ring { position: absolute; left: 50%; top: 50%; border: 1px dashed rgba(120, 255, 255, 0.75); border-radius: 50%; }
.dbg-ring.active { border-style: solid; border-color: #ff0; }
.dbg-touch-dot {
  position: absolute;
  left: -22px;
  top: -22px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #0ff;
  border-radius: 50%;
  color: #0ff;
  font: 9px ui-monospace, monospace;
}
/* A compact row along the top, out of the way of the thumbs. */
.dbg-cheats {
  position: absolute;
  left: calc(env(safe-area-inset-left) + 74px);
  top: calc(env(safe-area-inset-top) + 122px);
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  max-width: 46vw;
}
.dbg-cheats button {
  pointer-events: auto;
  padding: 3px 6px;
  background: rgba(0, 0, 0, 0.6);
  color: #9ff;
  border: 1px solid #355;
  border-radius: 4px;
  font: 10px ui-monospace, monospace;
  text-align: left;
}

/* ==========================================================================
   Accounts (Phase 7)
   ========================================================================== */
body:not(.signed-in) .when-signed-in, body.signed-in .when-signed-out { display: none !important; }
input, .code-box { -webkit-user-select: text; user-select: text; }
.btn-tiny { font-size: 15px; padding: 6px 16px; box-shadow: 0 3px 0 var(--ink); }
.menu-row .btn-tiny { padding: 6px 16px; }
.btn-danger { background: var(--pink-dark); color: var(--paper); }
.btn-secondary.btn-danger { background: var(--paper); color: var(--pink-dark); }

/* Start screen: who is signed in */
.account-line { margin-top: 14px; padding-top: 12px; border-top: 2px solid #f3f0ff; }
.account-who { margin: 0 0 8px; font-size: 15px; }
.account-line .menu-row { display: flex; gap: 8px; }

/* Run complete: the save box shows the buttons for its state */
.save-box { margin: 4px 0 16px; }
.save-box .submit-msg { margin: 0 0 8px; }
.save-actions { display: flex; gap: 8px; }
.save-actions > .btn { display: none; }
.save-box[data-state="signedOut"] .save-signed-out,
.save-box[data-state="saved"] .save-saved,
.save-box[data-state="error"] .save-error { display: inline-block; }
.save-box[data-state="saving"] .submit-msg::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 8px;
  border: 3px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -1px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Leaderboard: entries saved before accounts */
.guest-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 999px;
  background: #ece8f8;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: 1px;
  opacity: 0.8;
}

/* The account screen */
.card-account { max-width: 520px; text-align: left; }
.card-account h2 { text-align: center; }
.acct-reason { margin: 0 0 6px; padding: 8px 12px; background: #fff4d6; border-radius: 12px; font-weight: 600; font-size: 15px; text-align: center; }
.acct-note { margin: 0 0 10px; font-size: 14px; opacity: 0.75; text-align: center; }
.acct-warning { margin: 10px 0; padding: 10px 12px; background: #ffe3ea; border: 2px solid var(--pink-dark); border-radius: 12px; color: var(--pink-dark); font-weight: 700; font-size: 15px; }
.field { display: block; margin: 0 0 10px; font-weight: 600; font-size: 14px; }
.field small { font-weight: 400; opacity: 0.65; }
.field input {
  display: block;
  width: 100%;
  margin-top: 4px;
  font: 600 18px var(--font);
  padding: 8px 14px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  outline: none;
  background: var(--paper);
  color: var(--ink);
}
.field input:focus { border-color: var(--blue); }
.field input.pin { letter-spacing: 0.3em; font-variant-numeric: tabular-nums; }
.field input.code { text-transform: uppercase; letter-spacing: 0.08em; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.field-status { display: block; min-height: 1.2em; margin: 4px 0 0 4px; font-size: 13px; font-weight: 600; }
.field-status.ok { color: #058a66; }
.field-status.error { color: var(--pink-dark); }
.card-account .submit-msg { text-align: center; }
.code-row { display: flex; gap: 8px; align-items: center; }
.code-box {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  font: 700 22px ui-monospace, Consolas, monospace;
  letter-spacing: 0.06em;
  text-align: center;
  border: 3px dashed var(--ink);
  border-radius: 14px;
  background: #f3f0ff;
  color: var(--ink);
}
.acct-bests { display: grid; gap: 8px; margin: 6px 0 4px; }
.acct-best { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 10px; padding: 8px 14px; background: #f3f0ff; border-radius: 12px; }
.acct-best b { grid-column: 1; font-variant-numeric: tabular-nums; }
.acct-best .btn { grid-column: 2; grid-row: 1 / span 2; }
.acct-debug { display: block; margin: 0 auto 8px; font-size: 12px; }
/* Buttons stay on screen while a long panel scrolls (as in Settings). */
.card-account .acct-footer {
  position: sticky;
  bottom: -18px;
  margin: 8px -8px -18px;
  padding: 8px 0 14px;
  background: var(--paper);
  border-top: 2px solid #f3f0ff;
}
.card-account .acct-footer.menu-row { display: flex; gap: 8px; }
.card-account .acct-footer .menu-row { display: flex; gap: 8px; }
@media (max-width: 480px) { .field-pair { grid-template-columns: 1fr; } }
@media (max-height: 520px) {
  .card-account h2 { margin: 0 0 4px; }
  .field { margin-bottom: 6px; }
  .acct-note { margin-bottom: 6px; }
  .account-line { margin-top: 10px; padding-top: 8px; }
}

/* Touch: 44 px targets; 16 px+ text in fields so iOS doesn't zoom in */
body.touch .btn-tiny, body.touch .field input, body.touch .code-box { min-height: 44px; }
body.touch .field input { font-size: 18px; }
