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

html, body {
  height: 100%;
  background: #000000;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#stage {
  position: relative;
  width: 540px;
  height: 960px;
  /* near-black fallback so the frame reads dark before the canvas paints */
  background: radial-gradient(120% 90% at 50% 42%, #08040f 0%, #04020a 55%, #000000 100%);
  border: 1px solid #1a0a2a;
  border-radius: 12px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.75), inset 0 0 70px rgba(0,0,0,0.45),
              0 0 40px rgba(150, 60, 220, 0.10);
  overflow: hidden;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  /* CSS-filter fallback path for desaturation when the composer SatPass is
     unavailable. game.js sets --canvas-sat (1 = full color, 0 = grayscale). */
  filter: saturate(var(--canvas-sat, 1));
}

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

#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 70px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 12px 16px 0;
  background: linear-gradient(180deg, rgba(8,4,18,0.78), rgba(8,4,18,0));
}
.t-title {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 6px;
  opacity: 0.96;
  text-shadow: 0 0 18px rgba(180,120,255,0.55);
}
.t-sub {
  font-size: 10px;
  letter-spacing: 4px;
  opacity: 0.6;
  margin-top: 4px;
}

/* ---------- Per-snake standings ---------- */
#standings {
  position: absolute;
  top: 80px; left: 12px;
  width: 184px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.snake-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 8px;
  background: rgba(8,10,22,0.55);
  border: 1px solid rgba(255,255,255,0.10);
  /* smoothly animate position when standings reorder */
  transition: transform 0.35s cubic-bezier(.2,.8,.3,1), opacity 0.4s ease, filter 0.4s ease;
}
.snake-row.dead { opacity: 0.30; filter: grayscale(0.85); }
.snake-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: 0 0 10px currentColor;
}
.snake-name {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 2px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.snake-len {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
  transition: transform 0.12s ease;
}
.snake-len.bump { transform: scale(1.45); }
.snake-row.dead .snake-len::after { content: " ✕"; font-size: 11px; opacity: 0.8; }

/* ---------- Arena-shrink meter ---------- */
#shrink-readout {
  position: absolute;
  top: 56px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border-radius: 20px;
  background: rgba(16,8,28,0.55);
  border: 1px solid rgba(255,120,180,0.30);
}
.shrink-label {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 3px;
  color: #ffc2dd;
}
.shrink-track {
  width: 150px; height: 5px;
  border-radius: 3px;
  background: rgba(255,255,255,0.16);
  overflow: hidden;
}
.shrink-prog {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, #ff7a3c, #ff2e6e);
  box-shadow: 0 0 12px rgba(255,46,110,0.85);
  transition: width 0.2s linear;
}
.shrink-time {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 12px;
  font-weight: 800;
  color: #ffd9ec;
  min-width: 34px;
  text-align: right;
}
#shrink-readout.urgent { animation: shrinkPulse 0.6s ease-in-out infinite; }
@keyframes shrinkPulse {
  0%,100% { box-shadow: 0 0 0 rgba(255,46,110,0); }
  50% { box-shadow: 0 0 22px rgba(255,46,110,0.7); border-color: rgba(255,90,150,0.9); }
}

/* =====================================================================
   WIN-FX LAYER — the overhauled victory presentation. All transitions are
   triggered by toggling inline styles / classes from game.js so each
   variation can choreograph its own slide-in, scale, smash, shake, bars,
   vignette and desaturation. The layer itself never eats pointer events.
   ===================================================================== */
#winfx {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  overflow: hidden;
}
#winfx.hidden { display: none !important; }

/* ---- cinematic letterbox bars (hidden off-frame by default) ---- */
.letterbox {
  position: absolute;
  left: 0; right: 0;
  height: 90px;
  background: #000;
  transition: transform 0.45s cubic-bezier(.2,.85,.25,1);
  will-change: transform;
}
#lb-top { top: 0; transform: translateY(-100%); }
#lb-bot { bottom: 0; transform: translateY(100%); }
#winfx.bars #lb-top { transform: translateY(0); }
#winfx.bars #lb-bot { transform: translateY(0); }

/* ---- full-frame white impact flash (smash landing) ---- */
#fx-flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  mix-blend-mode: screen;
}

/* ---- vignette punch-in ---- */
#fx-vignette {
  position: absolute;
  inset: 0;
  opacity: 0;
  background: radial-gradient(120% 95% at 50% 50%,
              rgba(0,0,0,0) 38%, rgba(0,0,0,0.55) 78%, rgba(0,0,0,0.9) 100%);
  transition: opacity 0.5s ease;
}

/* ---- expanding shockwave ring (drawn as a scaling bordered circle) ---- */
#fx-shockwave {
  position: absolute;
  top: 46%; left: 50%;
  width: 40px; height: 40px;
  margin: -20px 0 0 -20px;
  border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.9);
  box-shadow: 0 0 30px rgba(255,255,255,0.6), inset 0 0 24px rgba(255,255,255,0.5);
  opacity: 0;
  transform: scale(0.2);
  will-change: transform, opacity;
}

/* ---- the side-sliding ITALIC winner banner ---- */
#win-banner {
  position: absolute;
  top: 44%; left: 50%;
  text-align: center;
  font-style: italic;                 /* spec: text set in italics */
  /* default rest transform; game.js overrides transform per-variation */
  transform: translate(-50%, -50%);
  will-change: transform, opacity, filter;
}
.wb-sub {
  font-size: 13px;
  letter-spacing: 6px;
  font-weight: 700;
  font-style: italic;
  opacity: 0.9;
}
.wb-name {
  font-size: 70px;
  font-weight: 900;
  font-style: italic;
  letter-spacing: 2px;
  line-height: 1;
  margin: 6px 0;
  color: #fff;
  text-shadow: 0 0 30px currentColor, 0 4px 18px rgba(0,0,0,0.6);
  white-space: nowrap;
}
/* serif variant (V3) */
#win-banner.serif .wb-name { font-family: Georgia, "Times New Roman", serif; }
/* neon variant (V4) */
#win-banner.neon .wb-name {
  text-shadow: 0 0 8px #fff, 0 0 22px currentColor, 0 0 44px currentColor, 0 0 70px currentColor;
}
/* motion-blur streak variant (V4 entry) */
#win-banner.streak .wb-name { filter: blur(0px); }
.wb-tag {
  font-size: 26px;
  font-weight: 900;
  font-style: italic;
  letter-spacing: 14px;
  opacity: 0.95;
}

/* =====================================================================
   EXPANDED-ENDING OVERLAYS — each is hidden (opacity:0) at rest and driven
   imperatively from game.js. All sit inside #winfx (pointer-events:none).
   ===================================================================== */

/* ---- Shatter-Freeze: glass-crack overlay snaps in on the smash. The crack
        pattern is a set of radial conic/linear gradient slivers; it pops to
        full opacity instantly then slowly fades. ---- */
#fx-crack {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  background:
    repeating-conic-gradient(from 0deg at 50% 46%,
      rgba(255,255,255,0) 0deg, rgba(255,255,255,0) 11deg,
      rgba(255,255,255,0.85) 11.4deg, rgba(255,255,255,0) 11.8deg 23deg),
    radial-gradient(closest-side at 50% 46%,
      rgba(255,255,255,0.0) 0%, rgba(255,255,255,0.0) 6%,
      rgba(255,255,255,0.55) 6.5%, rgba(255,255,255,0) 7.5%,
      rgba(255,255,255,0) 22%, rgba(255,255,255,0.4) 22.5%, rgba(255,255,255,0) 23.5%);
  mix-blend-mode: screen;
  filter: drop-shadow(0 0 2px rgba(180,220,255,0.9));
}

/* ---- Comic halftone dot overlay (Comic K.O.) ---- */
#fx-halftone {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  background-image: radial-gradient(rgba(0,0,0,0.55) 1.4px, rgba(0,0,0,0) 1.6px);
  background-size: 7px 7px;
  mix-blend-mode: multiply;
}

/* ---- VHS / glitch scanlines (Glitch-Dissolve & Replay-Rewind) ---- */
#fx-scanlines {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg, rgba(0,0,0,0.0) 0px, rgba(0,0,0,0.0) 2px,
    rgba(0,0,0,0.35) 2px, rgba(0,0,0,0.35) 3px);
  mix-blend-mode: multiply;
}
#fx-scanlines.flicker { animation: scanFlicker 0.12s steps(2) infinite; }
@keyframes scanFlicker {
  0% { opacity: 0.55; transform: translateY(0); }
  50% { opacity: 0.30; transform: translateY(-1px); }
  100% { opacity: 0.55; transform: translateY(1px); }
}

/* ---- Spotlight Cut: dim to near-black except a soft cone on the winner. ---- */
#fx-spotlight {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  background: radial-gradient(38% 30% at 50% 52%,
    rgba(0,0,0,0) 0%, rgba(0,0,0,0) 42%,
    rgba(0,0,0,0.82) 72%, rgba(0,0,0,0.97) 100%);
  transition: opacity 0.6s ease;
}

/* ---- Speed-Lines Dash: anime lines converging toward center. ---- */
#fx-speedlines {
  position: absolute;
  inset: -20%;
  opacity: 0;
  pointer-events: none;
  background: repeating-conic-gradient(from 0deg at 50% 50%,
    rgba(255,255,255,0) 0deg, rgba(255,255,255,0) 1.4deg,
    rgba(255,255,255,0.5) 1.6deg, rgba(255,255,255,0) 1.9deg 3.4deg);
  -webkit-mask-image: radial-gradient(closest-side at 50% 50%,
    rgba(0,0,0,0) 32%, rgba(0,0,0,1) 70%);
  mask-image: radial-gradient(closest-side at 50% 50%,
    rgba(0,0,0,0) 32%, rgba(0,0,0,1) 70%);
  mix-blend-mode: screen;
}
#fx-speedlines.spin { animation: speedSpin 1.2s linear; }
@keyframes speedSpin { from { transform: rotate(0deg); } to { transform: rotate(7deg); } }

/* ---- Comic starburst behind the name (Comic K.O.) ---- */
#fx-comic {
  position: absolute;
  top: 44%; left: 50%;
  width: 320px; height: 320px;
  margin: -160px 0 0 -160px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-style: italic;
  font-size: 56px;
  letter-spacing: 2px;
  color: #fff200;
  -webkit-text-stroke: 3px #1a0a00;
  text-shadow: 0 6px 0 rgba(0,0,0,0.55);
  background: #ff2e54;
  clip-path: polygon(50% 0%, 61% 18%, 82% 8%, 78% 31%, 100% 35%, 82% 50%,
    100% 66%, 78% 70%, 82% 92%, 61% 82%, 50% 100%, 39% 82%, 18% 92%, 22% 70%,
    0% 66%, 18% 50%, 0% 35%, 22% 31%, 18% 8%, 39% 18%);
  opacity: 0;
  transform: scale(0.2) rotate(-12deg);
  will-change: transform, opacity;
}

/* ---- Circular wax-seal / WINNER stamp (Stamp Seal) ---- */
#fx-stamp {
  position: absolute;
  top: 44%; left: 50%;
  width: 180px; height: 180px;
  margin: -90px 0 0 -90px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 6px double rgba(255,255,255,0.92);
  font-weight: 900;
  font-style: italic;
  font-size: 30px;
  letter-spacing: 5px;
  color: rgba(255,255,255,0.95);
  text-shadow: 0 2px 6px rgba(0,0,0,0.7);
  box-shadow: 0 0 26px rgba(255,255,255,0.35), inset 0 0 20px rgba(255,255,255,0.18);
  background: radial-gradient(closest-side, rgba(0,0,0,0.18), rgba(0,0,0,0.0));
  opacity: 0;
  transform: scale(2.6) rotate(-16deg);
  will-change: transform, opacity;
}

/* ---- variation id tag, lower-left, unobtrusive ---- */
#winfx-tag {
  position: absolute;
  left: 12px; bottom: 30px;
  font-family: "SF Mono", Menlo, monospace;
  font-size: 10px;
  letter-spacing: 2px;
  font-weight: 700;
  color: rgba(255,255,255,0.5);
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  padding: 3px 7px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 6px;
  background: rgba(0,0,0,0.35);
}

/* ---------- Watermark / ticker ---------- */
#watermark {
  position: absolute;
  bottom: 30px; right: 14px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  color: rgba(255,255,255,0.55);
  text-shadow: 0 1px 3px rgba(0,0,0,0.7);
}
.ticker {
  position: absolute;
  left: 0; right: 0;
  bottom: 8px;
  text-align: center;
  font-family: "SF Mono", "Menlo", "Courier New", monospace;
  font-size: 11px;
  letter-spacing: 2px;
  opacity: 0.6;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

#boot-error {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  font-size: 14px;
  line-height: 1.6;
  color: #ff8a8a;
  background: rgba(8,10,20,0.95);
}

/* CRITICAL: an ID selector (#boot-error{display:flex}) would otherwise outrank
   a plain .hidden{display:none}, leaving the full-screen dark overlay visible
   on top of the WebGL canvas. !important keeps it hidden unless we explicitly
   un-hide it on an actual context-creation failure. */
.hidden { display: none !important; }

#stage.shaking { animation: quake 0.3s linear infinite; }
@keyframes quake {
  0%,100% { transform: translate(0,0); }
  25% { transform: translate(-3px, 2px); }
  50% { transform: translate(3px, -2px); }
  75% { transform: translate(-2px, -2px); }
}
