/* ===========================================================================
   Snake Pit — slither.io battle royale · Mr. Mac's Review Arcade
   Editorial dark · Neon cyan/violet/gold pit · Continuous arena
   =========================================================================== */

:root {
  color-scheme: dark;
  --void:           #04060f;
  --cabinet-dark:   #0a0d1c;
  --cabinet-mid:    #101830;
  --panel:          rgba(8, 14, 28, .88);
  --panel-strong:   rgba(6, 10, 22, .96);
  --line:           rgba(255,255,255,.12);
  --text:           #f0f5ff;
  --muted:          #8aa0c8;
  --gold:           #f5c451;
  --brass:          #c8922a;
  --brass-light:    #f0d068;
  --bronze:         #a96e3d;
  --emerald:        #4dd49b;
  --emerald-deep:   #1f8d68;
  --chrome:         #d0d8ee;
  --cyan:           #5de0f0;
  --cyan-deep:      #2ba0b6;
  --green:          #6dc18f;
  --rose:           #f07bb8;
  --violet:         #a991ff;
  --violet-deep:    #6c4fc8;
  --crim:           #d04848;
  --steel:          #a0a8b8;
  --danger:         #f04860;
  --orange:         #ff8838;

  --hud-accent:     var(--cyan);

  --shadow-deep:   0 32px 96px rgba(0,0,0,.72), 0 8px 24px rgba(0,0,0,.48);
  --shadow-panel:  0 20px 60px rgba(0,0,0,.55);
  --glow-violet:   0 0 28px rgba(169,145,255,.4);
  --glow-cyan:     0 0 28px rgba(93,224,240,.4);
  --glow-gold:     0 0 28px rgba(245,196,81,.4);
  --glow-emerald:  0 0 28px rgba(77,212,155,.4);
  --glow-rose:     0 0 28px rgba(240,123,184,.4);

  --ease: cubic-bezier(.2,.8,.2,1);
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  width: 100%; height: 100%;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  position: fixed; inset: 0; margin: 0;
  background: var(--void);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, select { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: wait; opacity: .55; }

.mono {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}

kbd {
  font-family: 'JetBrains Mono', monospace;
  font-size: .82em;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.04);
  color: var(--chrome);
}

/* Shell + canvas
   Note: page-marquee strip is relative-positioned ABOVE this shell (~22px mobile,
   ~28px desktop). Subtracting it keeps the canvas bottom inside the viewport so
   the joystick/boost row isn't clipped off-screen. */
.snakepit-shell {
  position: relative;
  width: 100vw;
  height: calc(100dvh - 28px);
  max-height: calc(100dvh - 28px);
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(ellipse 100% 70% at 50% 30%, var(--cabinet-mid) 0%, transparent 70%),
    radial-gradient(ellipse 100% 80% at 50% 100%, var(--cabinet-dark) 0%, var(--void) 80%),
    var(--void);
}
@media (max-width: 540px) {
  .snakepit-shell {
    height: calc(100dvh - 18px);
    max-height: calc(100dvh - 18px);
  }
}

#snakepitCanvas {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

/* Subtle scanline overlay */
.scanline-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(255,255,255,.012) 0px,
      rgba(255,255,255,.012) 1px,
      transparent 1px,
      transparent 3px
    );
  mix-blend-mode: overlay;
  opacity: .6;
}
@media (prefers-reduced-motion: reduce) {
  .scanline-overlay { display: none; }
}

/* Top HUD */
.top-hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  background: linear-gradient(180deg, rgba(2,4,12,.92) 0%, rgba(2,4,12,.7) 60%, transparent 100%);
  pointer-events: auto;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  flex: 0 1 auto;
}
.brand-core {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  box-shadow: 0 0 14px var(--cyan);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-title {
  font-family: 'Fraunces', serif;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.01em;
}
.brand-prefix { color: var(--text); }
.brand-suffix {
  color: var(--cyan);
  font-style: italic;
  font-weight: 900;
  text-shadow: 0 0 18px rgba(93,224,240,.55);
  margin-left: 2px;
}
.brand-sub {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: uppercase;
}

.hud-stats {
  display: flex;
  gap: 8px;
  flex: 1 1 auto;
  justify-content: center;
}
.stat-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 12px;
  border-radius: 8px;
  background: rgba(4,8,18,.55);
  border: 1px solid var(--line);
  min-width: 64px;
}
.stat-value {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}
.stat-label {
  font-size: 9px;
  color: var(--muted);
  letter-spacing: .12em;
  text-transform: uppercase;
  margin-top: 2px;
}
.stat-cell.is-warning .stat-value { color: var(--gold); }
.stat-cell.is-danger .stat-value { color: var(--danger); animation: timerPulse .35s ease-in-out infinite alternate; }
.stat-cell.is-boost .stat-value { color: var(--cyan); text-shadow: 0 0 8px rgba(93,224,240,.6); }
@keyframes timerPulse {
  from { text-shadow: 0 0 6px rgba(240,72,96,.2); }
  to   { text-shadow: 0 0 14px rgba(240,72,96,.7); }
}
@media (prefers-reduced-motion: reduce) {
  .stat-cell.is-danger .stat-value { animation: none; }
}

.hud-controls { display: flex; gap: 6px; }
.hud-btn {
  font-size: 12px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: rgba(4,8,18,.6);
  color: var(--chrome);
  letter-spacing: .04em;
  text-transform: uppercase;
  transition: background .2s, border-color .2s, color .2s;
}
.hud-btn:hover { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.25); color: var(--text); }
.hud-btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.glass-pill { border-radius: 999px; }

/* Goal ribbon */
.wave-ribbon {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(4,8,18,.7);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  font-size: 12px;
  pointer-events: none;
  transition: border-color .6s var(--ease), color .6s var(--ease);
  max-width: calc(100vw - 32px);
  white-space: nowrap;
  overflow: hidden;
}
.wave-kicker {
  color: var(--muted);
  letter-spacing: .12em;
  text-transform: uppercase;
  font-size: 10px;
  flex: 0 0 auto;
}
.wave-name {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 16px;
  color: var(--cyan);
  transition: color .6s var(--ease), text-shadow .6s var(--ease);
  flex: 0 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.wave-meta {
  font-family: 'JetBrains Mono', monospace;
  color: var(--muted);
  font-size: 11px;
  margin-left: 4px;
  flex: 0 0 auto;
}

/* Touch joystick + boost — only on small screens */
/* Anchored at bottom with pointer-events only on the hit areas, so the translucent
   tray background doesn't block canvas clicks. The canvas z-index is 0 and the
   controls sit at z-index 28, but pointer-events:none on the container means only
   the actual stick/button elements capture input. */
.touch-controls {
  position: absolute;
  bottom: 0;
  left: 0; right: 0;
  z-index: 28;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 22px 14px;
  /* translucent strip so the play area above is still visible */
  background: linear-gradient(0deg, rgba(2,4,12,.72) 0%, transparent 100%);
  pointer-events: none; /* tray bg passthrough — only children capture */
}
/* re-enable pointer events on the interactive children */
.tc-stick, .tc-boost { pointer-events: auto; }
.tc-stick {
  position: relative;
  width: 130px; height: 130px;
  pointer-events: auto;
  touch-action: none;
}
.tc-stick-base {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(4,8,18,.7);
  border: 2px solid rgba(93,224,240,.4);
  box-shadow: 0 0 20px rgba(93,224,240,.25), inset 0 0 30px rgba(0,0,0,.4);
}
.tc-stick-knob {
  position: absolute;
  top: 50%; left: 50%;
  width: 50px; height: 50px;
  margin: -25px 0 0 -25px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--cyan) 0%, var(--cyan-deep) 70%, var(--violet-deep) 100%);
  border: 2px solid rgba(255,255,255,.4);
  box-shadow: 0 4px 14px rgba(0,0,0,.6), 0 0 14px rgba(93,224,240,.45);
  transition: top .04s linear, left .04s linear;
  pointer-events: none;
}
.tc-boost {
  width: 100px; height: 100px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: radial-gradient(circle at 30% 30%, var(--gold) 0%, var(--brass) 70%, rgba(0,0,0,.4) 100%);
  color: #1a1208;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: .08em;
  box-shadow: 0 0 18px rgba(245,196,81,.4), 0 4px 12px rgba(0,0,0,.5);
  transition: transform .12s, box-shadow .15s;
}
.tc-boost:active {
  transform: translateY(2px) scale(0.95);
  box-shadow: 0 0 28px rgba(245,196,81,.7), 0 2px 6px rgba(0,0,0,.6);
}
.tc-boost.is-active {
  background: radial-gradient(circle at 30% 30%, #ffe488 0%, var(--gold) 70%, var(--brass) 100%);
  box-shadow: 0 0 36px rgba(245,196,81,.8);
}
@media (max-width: 720px), (pointer: coarse) {
  .touch-controls { display: flex; }
}

/* Combo callout overlay */
.popup-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  pointer-events: none;
}
.popup-text {
  position: absolute;
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 900;
  font-size: 28px;
  color: var(--cyan);
  text-shadow: 0 2px 8px rgba(0,0,0,.7), 0 0 14px rgba(93,224,240,.5);
  letter-spacing: -.01em;
  animation: popupFloat 1.1s var(--ease) forwards;
  pointer-events: none;
  transform: translate(-50%, -50%);
}
.popup-text.is-tetris {
  font-size: 36px;
  color: var(--gold);
  text-shadow: 0 2px 8px rgba(0,0,0,.7), 0 0 18px rgba(245,196,81,.55);
}
.popup-text.is-bonus { color: var(--violet); text-shadow: 0 2px 8px rgba(0,0,0,.7), 0 0 14px rgba(169,145,255,.5); }
.popup-text.is-legend {
  font-size: 32px;
  color: var(--rose);
  text-shadow: 0 2px 8px rgba(0,0,0,.7), 0 0 18px rgba(240,123,184,.5);
}
.popup-text.is-score {
  font-family: 'JetBrains Mono', monospace;
  font-style: normal;
  font-weight: 800;
  font-size: 18px;
  color: var(--gold);
}
.popup-text.is-warn {
  color: var(--danger);
  text-shadow: 0 2px 8px rgba(0,0,0,.7), 0 0 14px rgba(240,72,96,.5);
}
.popup-text.is-kill {
  font-size: 30px;
  color: var(--orange);
  text-shadow: 0 2px 8px rgba(0,0,0,.7), 0 0 18px rgba(255,136,56,.65);
}
@keyframes popupFloat {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(.7); }
  18%  { opacity: 1; transform: translate(-50%, -56%) scale(1.12); }
  100% { opacity: 0; transform: translate(-50%, -100%) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .popup-text { animation-duration: .35s; }
}

/* Modal screens — shared */
/* z-index hierarchy: setup/end/pause at 8000, question (scholar) at 9500 */
.setup-screen, .pause-screen, .end-screen {
  position: absolute;
  inset: 0;
  z-index: 8000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(ellipse 80% 60% at 50% 50%, rgba(6,12,28,.9) 0%, rgba(2,4,12,.96) 80%);
  backdrop-filter: blur(6px);
}
/* pause sits above setup/end but below scholar question */
.pause-screen { z-index: 8200; }
/* scholar question always on top (below toasts at 9999) */
.question-screen {
  position: absolute;
  inset: 0;
  z-index: 9500;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(ellipse 80% 60% at 50% 50%, rgba(6,12,28,.92) 0%, rgba(2,4,12,.97) 80%);
  backdrop-filter: blur(8px);
}
.setup-screen.show, .pause-screen.show, .end-screen.show, .question-screen.show {
  display: flex;
  animation: modalIn .35s var(--ease);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.98); }
  to   { opacity: 1; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .setup-screen.show, .pause-screen.show, .end-screen.show, .question-screen.show { animation: none; }
}

.setup-card {
  width: 100%;
  max-width: 640px;
  /* prevent card overflow on small screens */
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 28px 32px 32px;
  border-radius: 18px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-deep);
  position: relative;
}
.setup-card.compact { max-width: 480px; padding: 24px 28px; }

.marquee-art {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 110px;
  pointer-events: none;
  overflow: hidden;
}
.marquee-glow {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 50% 80% at 50% 100%, var(--cyan) 0%, transparent 70%);
  opacity: .26;
}
.marquee-spark {
  position: absolute;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 18px var(--cyan), inset 0 0 6px rgba(255,255,255,0.4);
  animation: sparkFloat 6s ease-in-out infinite;
}
.spark-a { top: 18%; left: 22%; animation-delay: 0s; background: var(--cyan); box-shadow: 0 0 18px var(--cyan), inset 0 0 6px rgba(255,255,255,.4); }
.spark-b { top: 32%; left: 70%; animation-delay: 1.4s; background: var(--violet); box-shadow: 0 0 18px var(--violet), inset 0 0 6px rgba(255,255,255,.4); }
.spark-c { top: 24%; left: 50%; animation-delay: 2.8s; background: var(--gold); box-shadow: 0 0 18px var(--gold), inset 0 0 6px rgba(255,255,255,.4); }
@keyframes sparkFloat {
  0%, 100% { transform: translateY(0); opacity: .8; }
  50%      { transform: translateY(-12px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .marquee-spark { animation: none; }
}
.marquee-inner-border {
  position: absolute;
  inset: 8px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.08);
}

.setup-kicker {
  position: relative;
  z-index: 2;
  font-size: 11px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 6px;
  font-weight: 700;
}
.kicker-pause-glyph {
  display: inline-block;
  margin-right: 4px;
  letter-spacing: -2px;
}

.setup-card h1 {
  position: relative;
  z-index: 2;
  font-family: 'Fraunces', serif;
  font-weight: 900;
  font-size: 42px;
  letter-spacing: -.02em;
  margin: 0 0 8px;
  line-height: 1;
}
.setup-card h1 .title-prefix { color: var(--text); }
.setup-card h1 .title-suffix {
  color: var(--cyan);
  font-style: italic;
  text-shadow: 0 0 22px rgba(93,224,240,.6);
  margin-left: 4px;
}
.setup-card h2 {
  font-family: 'Fraunces', serif;
  font-weight: 800;
  font-size: 28px;
  margin: 0 0 8px;
  line-height: 1.1;
  font-style: italic;
}

.ship-badges-row {
  position: relative;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 12px;
  align-items: center;
}
.ship-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  padding: 4px 8px;
  border-radius: 5px;
  background: rgba(0,0,0,.4);
  border: 1px solid var(--cyan);
  color: var(--cyan);
  box-shadow: 0 0 10px rgba(93,224,240,.25);
}
.ship-badge.badge-gold     { border-color: var(--gold);    color: var(--gold);    box-shadow: 0 0 10px rgba(245,196,81,.25); }
.ship-badge.badge-rose     { border-color: var(--rose);    color: var(--rose);    box-shadow: 0 0 10px rgba(240,123,184,.30); }
.ship-badge.badge-violet   { border-color: var(--violet);  color: var(--violet);  box-shadow: 0 0 10px rgba(169,145,255,.25); }
.ship-badge.badge-cyan     { border-color: var(--cyan);    color: var(--cyan);    box-shadow: 0 0 10px rgba(93,224,240,.25); }
.ship-badge.badge-emerald  { border-color: var(--emerald); color: var(--emerald); box-shadow: 0 0 10px rgba(77,212,155,.25); }
.ship-badge.badge-bronze   { border-color: var(--bronze);  color: var(--bronze);  box-shadow: 0 0 10px rgba(169,110,61,.25); }

.ship-campaign-label {
  margin-left: 6px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .08em;
}

.setup-sub {
  position: relative;
  z-index: 2;
  color: var(--muted);
  margin: 0 0 18px;
  line-height: 1.5;
  font-size: 14px;
  max-width: 60ch;
}
.setup-sub em { color: var(--gold); font-style: italic; }

.setup-actions {
  position: relative;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.btn {
  font-size: 14px;
  font-weight: 600;
  padding: 11px 20px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.05);
  color: var(--text);
  letter-spacing: .04em;
  transition: background .2s, border-color .2s, transform .15s;
}
.btn:hover { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.25); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.btn.primary {
  background: linear-gradient(180deg, var(--gold) 0%, var(--brass) 100%);
  border-color: var(--gold);
  color: #1a1208;
  font-weight: 800;
  box-shadow: var(--glow-gold);
}
.btn.primary:hover {
  background: linear-gradient(180deg, var(--brass-light) 0%, var(--gold) 100%);
}
.brass-btn .btn-coin { margin-right: 4px; }

.key-hints {
  position: relative;
  z-index: 2;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .04em;
}
.key-hints kbd { margin: 0 1px; }

/* Question modal styling */
.question-card {
  width: 100%;
  max-width: 560px;
  padding: 24px 28px;
  border-radius: 18px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-deep);
}
.question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.question-meta {
  font-size: 11px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 700;
}
.question-close {
  font-size: 11px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.06);
  color: var(--muted);
  letter-spacing: .08em;
  text-transform: uppercase;
}
.question-close:hover { color: var(--text); border-color: rgba(255,255,255,.25); }

.question-card h2 {
  font-family: 'Fraunces', serif;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.3;
  margin: 0 0 16px;
  font-style: italic;
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.choice-btn {
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.04);
  color: var(--text);
  font-size: 14px;
  text-align: left;
  line-height: 1.4;
  transition: background .2s, border-color .2s, transform .12s;
}
.choice-btn:hover {
  background: rgba(255,255,255,.08);
  border-color: var(--gold);
}
.choice-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.choice-btn .choice-letter {
  display: inline-block;
  margin-right: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 800;
  color: var(--gold);
}
.choice-btn.is-correct {
  background: rgba(77,212,155,.18);
  border-color: var(--emerald);
}
.choice-btn.is-wrong {
  background: rgba(240,72,96,.18);
  border-color: var(--danger);
}

.explanation {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  min-height: 1.55em;
}
.explanation.is-correct { color: var(--emerald); }
.explanation.is-wrong { color: var(--danger); }

@media (max-width: 540px) {
  .choice-grid { grid-template-columns: 1fr; }
  .setup-card h1 { font-size: 32px; }
  .top-hud { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .hud-stats { order: 3; flex-basis: 100%; justify-content: space-around; flex-wrap: nowrap; gap: 4px; }
  .stat-cell { min-width: 0; padding: 3px 6px; flex: 1 1 0; }
  .stat-value { font-size: 14px; }
  .stat-label { font-size: 8px; letter-spacing: .08em; }
  /* Hide "best" lifetime stat during mobile play — visible on end-screen recap */
  .stat-cell:has(#hudBest) { display: none; }
  .wave-ribbon { top: 96px; font-size: 11px; padding: 5px 12px; }
  .wave-name { font-size: 14px; }
  .wave-meta { font-size: 10px; }
  .tc-stick { width: 100px; height: 100px; }
  .tc-stick-knob { width: 40px; height: 40px; margin: -20px 0 0 -20px; }
  .tc-boost { width: 80px; height: 80px; font-size: 13px; }
}

/* < 480px — extra-small phones */
@media (max-width: 479px) {
  /* HUD: shrink stats further so they don't wrap awkwardly */
  .stat-cell { min-width: 44px; padding: 2px 5px; }
  .stat-value { font-size: 13px; }
  .stat-label { font-size: 8px; }
  /* Brand title compacts */
  .brand-title { font-size: 17px; }
  /* Setup card padding tighter */
  .setup-card { padding: 18px 16px 20px; }
  .setup-card h1 { font-size: 28px; }
  /* Setup action buttons wrap cleanly */
  .setup-actions { flex-wrap: wrap; }
  /* Key hints smaller */
  .key-hints { font-size: 11px; }
  /* Touch controls smaller */
  .tc-stick { width: 88px; height: 88px; }
  .tc-stick-knob { width: 34px; height: 34px; margin: -17px 0 0 -17px; }
  .tc-boost { width: 70px; height: 70px; font-size: 12px; }
}

/* End screen grid */
.end-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0 8px;
}
.end-cell {
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
}
.end-cell-label {
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}
.end-cell-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 22px;
  font-weight: 800;
  color: var(--gold);
}

/* Resume / leaderboard panels */
.resume-card, .leaderboard-panel {
  position: relative;
  z-index: 2;
  margin: 12px 0 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
  font-size: 13px;
}
.resume-card-title, .leaderboard-title {
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.resume-card-meta {
  font-family: 'JetBrains Mono', monospace;
  color: var(--chrome);
  margin-bottom: 8px;
  font-size: 12px;
}
.resume-actions { display: flex; gap: 8px; }
.leaderboard-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--chrome);
}
.leaderboard-row .lb-rank { color: var(--gold); font-weight: 800; min-width: 24px; }
.leaderboard-row .lb-name { flex: 1; padding: 0 8px; color: var(--text); }
.leaderboard-row .lb-score { color: var(--gold); }

/* Achievement recap — end-of-run */
.end-recap {
  margin: 0 0 16px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(245, 196, 81, 0.09), rgba(245, 196, 81, 0.04));
  border: 1px solid rgba(245, 196, 81, 0.3);
  border-radius: 12px;
  text-align: left;
}
.end-recap-title {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 700;
  color: #f5c451;
  font-family: "Fraunces", serif;
}
.end-recap-list {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 6px;
}
.end-recap-item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.03);
  border-left: 3px solid rgba(180, 180, 180, 0.4);
  border-radius: 8px;
  font-size: 13px;
}
.end-recap-item[data-tier="bronze"] { border-left-color: #cd7f32; }
.end-recap-item[data-tier="silver"] { border-left-color: #c0c0c0; }
.end-recap-item[data-tier="gold"] { border-left-color: #f5c451; }
.end-recap-item[data-tier="legendary"] { border-left-color: #ff7cc8; box-shadow: 0 0 12px rgba(255, 124, 200, 0.2); }
.end-recap-icon { font-size: 18px; }
.end-recap-name { font-weight: 600; color: var(--paper, #fff); }
@media (prefers-reduced-motion: reduce) {
  .end-recap-item { box-shadow: none !important; }
}


/* ── Back to Arcade link (UX walkthrough rec #10) ─────────────────────── */
.setup-back-link {
  position: absolute;
  top: 16px;
  left: 16px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(245, 196, 81, 0.12);
  border: 1px solid rgba(245, 196, 81, 0.35);
  border-radius: 999px;
  color: #f5c451;
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  letter-spacing: 0.04em;
  transition: all 0.2s;
  z-index: 10;
}
.setup-back-link:hover, .setup-back-link:focus-visible {
  background: rgba(245, 196, 81, 0.22);
  transform: translateX(-2px);
  outline: 2px solid #f5c451;
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  .setup-back-link { transition: none; }
  .setup-back-link:hover { transform: none; }
}
@media (max-width: 480px) {
  .setup-back-link { top: 8px; left: 8px; padding: 4px 10px; font-size: 11px; }
}

/* ── Pause achievement-progress widget ─────────────────────────────────── */
.pause-progress {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: rgba(245,196,81,.08);
  border: 1px solid rgba(245,196,81,.30);
  border-radius: 12px;
  margin: 0 0 12px;
}
.pause-progress-icon { font-size: 22px; flex-shrink: 0; }
.pause-progress-text { flex: 1; min-width: 0; }
.pause-progress-title { font-weight: 700; font-size: 13px; color: #f5c451; }
.pause-progress-meta { font-size: 11.5px; color: var(--muted, #9aa3bb); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pause-progress-bar { width: 80px; height: 6px; background: rgba(0,0,0,.3); border-radius: 4px; overflow: hidden; flex-shrink: 0; }
.pause-progress-fill { height: 100%; background: #f5c451; transition: width 240ms ease; }
@media (prefers-reduced-motion: reduce) { .pause-progress-fill { transition: none; } }

/* ===========================================================================
   Mobile HUD visibility fix — May 10 2026
   User report: "snake top menu is not visible on mobile"
   Root cause: HUD wrapped to multi-row on small screens, but the controls
   row could get pushed off-screen when brand+stats overflowed. Pin the
   exit/pause controls to the top-right with a higher z-index so they are
   ALWAYS reachable, and tighten layout below 540px.
   =========================================================================== */
@media (max-width: 540px) {
  /* Force the HUD to be solid (not gradient-to-transparent) on mobile so
     it never visually disappears against dark game content. */
  .top-hud {
    background: rgba(2, 4, 12, 0.94) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }
  /* Brand: never let it eat the controls row */
  .brand { flex: 0 1 auto; min-width: 0; max-width: 50%; }
  .brand-title { font-size: 16px; }
  .brand-sub { display: none; }
  /* Controls: pin to row 1 so Exit + Pause are always visible */
  .hud-controls { order: 2; flex: 0 0 auto; gap: 4px; }
  .hud-btn { padding: 8px 10px; font-size: 11px; min-height: 38px; }
}
@media (max-width: 380px) {
  .brand-title { font-size: 14px; }
  .hud-btn { padding: 6px 8px; font-size: 10px; }
}


/* ─── BUILD-OUT (May 2026): live leaderboard, difficulty, banner ─── */

/* Top-right live leaderboard panel. Compact 5-row list. */
.hud-leader {
  position: absolute;
  top: 110px;
  right: max(10px, env(safe-area-inset-right, 10px));
  z-index: 30;
  min-width: 180px;
  max-width: 220px;
  padding: 10px 10px 8px;
  background: rgba(4, 8, 18, 0.66);
  border: 1px solid rgba(245, 196, 81, 0.20);
  border-radius: 12px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  pointer-events: none;  /* don't intercept canvas drags */
}
.hud-leader .lb-title {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .14em;
  color: rgba(245, 196, 81, .85);
  text-transform: uppercase;
  margin: 0 0 6px;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}
.hud-leader .lb-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.hud-leader .lb-row {
  display: grid;
  grid-template-columns: 14px 10px 1fr auto;
  gap: 6px;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #d8dceb;
  padding: 3px 0;
  border-radius: 4px;
  transition: background 200ms;
}
.hud-leader .lb-row.is-player {
  background: rgba(93, 224, 240, 0.13);
  color: #bef5fb;
}
.hud-leader .lb-row.is-boss {
  background: rgba(255, 160, 60, 0.16);
  color: #ffd060;
  border-left: 2px solid #ff8040;
  padding-left: 4px;
}
.hud-leader .lb-rank {
  font-size: 10px;
  color: rgba(255,255,255,.4);
}
.hud-leader .lb-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  box-shadow: 0 0 6px currentColor;
}
.hud-leader .lb-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: .04em;
}
.hud-leader .lb-len {
  font-variant-numeric: tabular-nums;
  color: rgba(255,255,255,.62);
  font-size: 10.5px;
}
.hud-leader .lb-row.is-player .lb-name,
.hud-leader .lb-row.is-player .lb-len { color: #bef5fb; }
.hud-leader .lb-row.is-boss .lb-name,
.hud-leader .lb-row.is-boss .lb-len { color: #ffd060; }

@media (max-width: 720px) {
  .hud-leader {
    top: 132px;
    min-width: 0;
    max-width: 140px;
    padding: 6px 8px 5px;
  }
  .hud-leader .lb-row { font-size: 10px; padding: 2px 0; }
  .hud-leader .lb-title { font-size: 8px; margin: 0 0 4px; }
}

/* Difficulty selector on setup screen — 4-pill row */
.sp-diff-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 12px 0 16px;
}
@media (min-width: 540px) {
  .sp-diff-row { grid-template-columns: repeat(4, 1fr); }
}
.sp-diff-btn {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 10px 8px !important;
  text-align: center;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
}
.sp-diff-btn .sp-diff-name {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .04em;
  color: #d8dceb;
}
.sp-diff-btn .sp-diff-meta {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .06em;
  color: rgba(255,255,255,.48);
  text-transform: uppercase;
}
.sp-diff-btn.is-selected {
  background: rgba(245, 196, 81, 0.18) !important;
  border-color: #f5c451 !important;
  box-shadow: 0 0 14px rgba(245, 196, 81, .25);
}
.sp-diff-btn.is-selected .sp-diff-name { color: #fff0a0; }

/* Centered banner — boss arrival, frenzy, etc. */
.snake-pit-banner {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%) scale(.9);
  opacity: 0;
  z-index: 60;
  padding: 14px 24px;
  background: rgba(4, 8, 18, .82);
  border: 2px solid #5de0f0;
  border-radius: 14px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  text-align: center;
  pointer-events: none;
  animation: spbanner 240ms cubic-bezier(.34, 1.56, .64, 1) forwards;
  max-width: 90vw;
}
.snake-pit-banner strong {
  display: block;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: .12em;
  text-shadow: 0 0 12px currentColor;
}
.snake-pit-banner .banner-sub {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .10em;
  color: rgba(255,255,255,.65);
  text-transform: uppercase;
}
.snake-pit-banner.is-big strong { font-size: 22px; }
.snake-pit-banner.is-out { animation: spbannerOut 380ms ease-in forwards; }
@keyframes spbanner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.7); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes spbannerOut {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -65%) scale(.92); }
}
@media (prefers-reduced-motion: reduce) {
  .snake-pit-banner { animation: none; opacity: 1; transform: translate(-50%, -50%); }
}

/* ─── Combo pill: small corner notice, NOT a centered banner ───
   Lives under the wave-ribbon, left side. Slides in from the left and
   fades quickly so it never obscures the playfield. */
.snake-pit-combo-pill {
  position: absolute;
  top: 100px;
  left: max(14px, env(safe-area-inset-left, 14px));
  z-index: 35;
  display: inline-flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 12px;
  background: rgba(4, 8, 18, 0.78);
  border: 1.5px solid currentColor;
  border-radius: 8px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  pointer-events: none;
  opacity: 0;
  transform: translateX(-12px);
  animation: spComboPillIn 200ms cubic-bezier(.34, 1.56, .64, 1) forwards;
}
.snake-pit-combo-pill strong {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .14em;
  text-shadow: 0 0 8px currentColor;
}
.snake-pit-combo-pill .cp-sub {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .10em;
  color: rgba(255,255,255,.55);
  text-transform: uppercase;
}
.snake-pit-combo-pill.is-out {
  animation: spComboPillOut 380ms ease-in forwards;
}
@keyframes spComboPillIn {
  0% { opacity: 0; transform: translateX(-12px); }
  100% { opacity: 1; transform: translateX(0); }
}
@keyframes spComboPillOut {
  0% { opacity: 1; transform: translateX(0); }
  100% { opacity: 0; transform: translateX(-12px); }
}
@media (prefers-reduced-motion: reduce) {
  .snake-pit-combo-pill { animation: none; opacity: 1; transform: none; }
  .snake-pit-combo-pill.is-out { animation: none; opacity: 0; }
}
@media (max-width: 720px) {
  .snake-pit-combo-pill { top: 84px; padding: 4px 9px; }
  .snake-pit-combo-pill strong { font-size: 11px; }
  .snake-pit-combo-pill .cp-sub { font-size: 8.5px; }
}
