/* ============================================================
   SWARM v0.0.1 — prototype styles
   ============================================================ */

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

/* --ui-scale is recomputed by resize() for every viewport; --safe keeps a
   readable gap from every screen edge (and honours device safe areas). */
:root {
  --ui-scale: 1;
  --safe: max(12px, env(safe-area-inset-top, 0px));
  --safe-x: max(14px, env(safe-area-inset-left, 0px));
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #07090d;
  overscroll-behavior: none;
}

/* Fullscreen canvas. touch-action:none lets us own swipe gestures. */
#game {
  display: block;
  width: 100vw;
  height: 100vh;
  touch-action: none;
  cursor: default;
  touch-action: none;      /* no pinch-zoom / double-tap zoom on the arena */
}

/* ---------- HUD (display only: Mass + FPS) ---------- */
#hud {
  position: fixed;
  top: var(--safe);
  left: var(--safe-x);
  max-width: 42vw;
  font-family: "Courier New", ui-monospace, monospace;
  color: #a8f7bd;
  text-shadow: 0 0 8px rgba(57, 255, 106, 0.55);
  letter-spacing: 1.5px;
  user-select: none;
  pointer-events: none;
}

#mass {
  font-size: max(15px, calc(22px * var(--ui-scale)));
  font-weight: bold;
}

#debug {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.5;
  opacity: 0.55;
  white-space: pre;
}

/* AI inspector (F4) — separate column so it never fights the main HUD */
#aidebug {
  position: fixed;
  top: var(--safe);
  right: var(--safe-x);
  max-width: 44vw;
  max-height: 46vh;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.5;
  opacity: 0.6;
  color: #ffc9bd;
  text-shadow: 0 0 8px rgba(255, 120, 90, 0.45);
  white-space: pre;
  text-align: right;
}

/* ---------- Leaderboard ---------- */
#leaderboard {
  position: fixed;
  top: var(--safe);
  right: var(--safe-x);
  min-width: min(210px, 40vw);
  max-width: 44vw;
  max-height: 46vh;
  overflow: hidden;
  font-family: "Courier New", ui-monospace, monospace;
  font-size: max(10px, calc(13px * var(--ui-scale)));
  line-height: 1.6;
  color: #cfe9d8;
  user-select: none;
  pointer-events: none;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.8);
}
#leaderboard .lb-title {
  font-size: 11px;
  letter-spacing: 3px;
  opacity: 0.5;
  margin-bottom: 4px;
}
#leaderboard .row { display: flex; justify-content: space-between; gap: 14px; opacity: 0.82; }
#leaderboard .row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#leaderboard .row.me { color: #8affaa; opacity: 1; font-weight: bold; text-shadow: 0 0 9px rgba(57,255,106,0.6); }
#leaderboard .row.top .nm { color: #ffd86e; }

/* F4 inspector sits bottom-right, clear of the radar dish above it */
#aidebug {
  position: fixed;
  top: auto;
  bottom: calc(var(--safe) + 200px * var(--ui-scale));
  right: var(--safe-x);
  font-size: max(9px, calc(12px * var(--ui-scale)));
}

/* ---------- Spectate bar ---------- */
#spectatebar {
  position: fixed;
  bottom: var(--safe);
  left: 50%;
  transform: translateX(-50%);
  max-width: 92vw;
  padding: 9px 18px;
  border: 1px solid rgba(140, 220, 255, 0.35);
  border-radius: 999px;
  background: rgba(6, 14, 20, 0.72);
  color: #bfe6ff;
  font-family: "Courier New", ui-monospace, monospace;
  font-size: 12px;
  letter-spacing: 2px;
  display: flex;
  align-items: center;
  gap: 14px;
  z-index: 20;
}

/* ---------- Menus ---------- */
#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  background: radial-gradient(circle at 50% 45%, rgba(6,20,12,0.72) 0%, rgba(2,6,4,0.93) 70%);
  backdrop-filter: blur(3px);
  z-index: 30;
}
#panel {
  width: min(92vw, calc(380px * var(--ui-scale)));
  max-height: 96vh;          /* never taller than the viewport... */
  overflow-y: auto;          /* ...and scroll vertically only if it has to */
  overscroll-behavior: contain;
  padding: calc(30px * var(--ui-scale)) calc(28px * var(--ui-scale)) calc(22px * var(--ui-scale));
  border: 1px solid rgba(57, 255, 106, 0.22);
  border-radius: 14px;
  background: rgba(4, 12, 8, 0.9);
  box-shadow: 0 0 60px rgba(57, 255, 106, 0.09);
  font-family: "Courier New", ui-monospace, monospace;
  color: #a8f7bd;
  text-align: center;
}
#panel h1 {
  margin: 0;
  text-shadow: 0 0 22px rgba(57, 255, 106, 0.55);
}
#panel h2 { margin: 0 0 18px; font-size: max(15px, calc(20px * var(--ui-scale))); letter-spacing: 6px; opacity: 0.85; }
#subtitle {
  margin: 2px 0 0;
  font-size: max(10px, calc(13px * var(--ui-scale)));
  letter-spacing: calc(9px * var(--ui-scale));
  font-weight: normal;
  opacity: 0.6;
}
#panel h1 { font-size: max(24px, calc(34px * var(--ui-scale))); letter-spacing: calc(7px * var(--ui-scale)); }
#tagline { margin: 6px 0 26px; font-size: 11px; letter-spacing: 3px; opacity: 0.45; }
#panel label { display: block; font-size: 10px; letter-spacing: 3px; opacity: 0.5; margin-bottom: 7px; }
#nameinput {
  width: 100%;
  padding: max(8px, calc(11px * var(--ui-scale))) 13px;
  margin-bottom: 16px;
  border: 1px solid rgba(57, 255, 106, 0.28);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.45);
  color: #d9ffe6;
  font-family: inherit;
  font-size: 15px;
  letter-spacing: 2px;
  text-align: center;
  outline: none;
  box-sizing: border-box;
  font-size: max(13px, calc(15px * var(--ui-scale)));
}
#nameinput:focus { border-color: rgba(57, 255, 106, 0.7); box-shadow: 0 0 16px rgba(57,255,106,0.18); }
#panel button {
  display: block;
  width: 100%;
  margin: max(6px, calc(8px * var(--ui-scale))) 0;
  padding: max(9px, calc(12px * var(--ui-scale)));
  border: 1px solid rgba(57, 255, 106, 0.28);
  border-radius: 8px;
  background: transparent;
  color: #a8f7bd;
  font-family: inherit;
  font-size: max(11px, calc(13px * var(--ui-scale)));
  letter-spacing: 4px;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s, transform 0.08s;
}
#panel button:hover { background: rgba(57, 255, 106, 0.1); border-color: rgba(57, 255, 106, 0.6); }
#panel button:active { transform: translateY(1px); }
#panel button.primary {
  background: rgba(57, 255, 106, 0.14);
  border-color: rgba(57, 255, 106, 0.65);
  color: #e6ffef;
}
button.mini {
  padding: 4px 12px;
  border: 1px solid rgba(140, 220, 255, 0.45);
  border-radius: 999px;
  background: transparent;
  color: #bfe6ff;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 2px;
  cursor: pointer;
}
button.mini:hover { background: rgba(140, 220, 255, 0.14); }
.hint { margin: 20px 0 0; font-size: 10px; letter-spacing: 2px; opacity: 0.32; }
.hidden { display: none !important; }

/* ---------- Play-screen pickers (color + starting core) ---------- */
.picker {
  display: flex;
  flex-wrap: wrap;
  gap: max(6px, calc(7px * var(--ui-scale, 1)));
  justify-content: center;
  margin-bottom: 18px;
}

/* Color swatches — a compact GRID of true circles.
   CRITICAL: these MUST be scoped under #colorpicker. The swatches are
   <button> elements, so the generic `#panel button` rule (ID specificity
   1,0,1) would otherwise outrank a plain `.swatch` class (0,1,0) and force
   them to full-width rounded rectangles — exactly the stacked-bars bug.
   A descendant selector that includes the #colorpicker id (1,1,0) outranks
   `#panel button`, so the circle wins. */
#colorpicker {
  display: grid;
  grid-template-columns: repeat(4, auto);   /* 4 columns; wraps into rows */
  justify-content: center;
  align-items: center;
  gap: max(11px, calc(15px * var(--ui-scale, 1)));
  margin-bottom: 20px;
}
#colorpicker .swatch {
  --sw: max(26px, calc(34px * var(--ui-scale, 1)));
  width: var(--sw);
  height: var(--sw);
  min-width: 0;               /* cancel any inherited button min-width */
  padding: 0;                 /* cancel #panel button padding */
  margin: 0;                  /* cancel #panel button margin */
  box-sizing: border-box;     /* the border stays inside the circle */
  aspect-ratio: 1 / 1;        /* always a perfect circle */
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.20);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.35);
  transition: transform 0.1s, box-shadow 0.14s, border-color 0.12s;
}
#colorpicker .swatch:hover {
  transform: scale(1.12);
  border-color: rgba(255, 255, 255, 0.5);
}
#colorpicker .swatch.sel {
  border-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(4, 12, 8, 0.9), 0 0 18px rgba(255, 255, 255, 0.65);
  transform: scale(1.18);
}
.coreopt {
  flex: 1;
  min-width: 84px;
  padding: 9px 4px !important;
  margin: 0 !important;
  font-size: 11px !important;
  letter-spacing: 2px !important;
}
.coreopt.sel { background: rgba(57, 255, 106, 0.16); border-color: rgba(57, 255, 106, 0.75); color: #eaffef; }
.coreopt .cdesc { display: block; margin-top: 3px; font-size: 9px; letter-spacing: 1px; opacity: 0.5; }

/* ---------- Kill counter ---------- */
#kills {
  font-size: max(11px, calc(13px * var(--ui-scale)));
  letter-spacing: 2px;
  opacity: 0.75;
  margin-top: 2px;
}

/* ---------- Kill feed (top-left, newest first) ---------- */
#killfeed {
  margin-top: 10px;
  min-height: 96px;
  max-width: 42vw;
  font-size: max(10px, calc(12px * var(--ui-scale)));
  line-height: 1.6;
  letter-spacing: 1px;
}
#killfeed .kf-k, #killfeed .kf-v { overflow: hidden; text-overflow: ellipsis; }
#killfeed .kf {
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  transition: opacity 0.18s linear;
}
#killfeed .kf-k { color: #cfeadd; }
#killfeed .kf-i { font-size: 13px; filter: saturate(1.2); }
#killfeed .kf-v { color: #ff9d8a; text-decoration: line-through; opacity: 0.9; }

/* ---------- Death pause card ---------- */
#deathcard {
  position: fixed;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 92vw;
  padding: calc(22px * var(--ui-scale)) min(38px, 7vw);
  border: 1px solid rgba(255, 120, 90, 0.35);
  border-radius: 12px;
  background: rgba(10, 4, 4, 0.78);
  box-shadow: 0 0 50px rgba(255, 80, 60, 0.13);
  font-family: "Courier New", ui-monospace, monospace;
  text-align: center;
  color: #ffd9d1;
  user-select: none;
  pointer-events: none;
  z-index: 25;
}
#deathcard .dc-l { font-size: 10px; letter-spacing: 5px; opacity: 0.55; }
#deathcard .dc-n {
  font-size: max(18px, calc(26px * var(--ui-scale)));
  letter-spacing: 3px;
  overflow-wrap: anywhere;
  margin: 8px 0 4px;
  color: #fff2ee;
  text-shadow: 0 0 18px rgba(255, 120, 90, 0.5);
}
#deathcard .dc-c { font-size: 12px; letter-spacing: 3px; opacity: 0.72; }
#deathcard .dc-t { margin-top: 14px; font-size: 10px; letter-spacing: 3px; opacity: 0.4; }

/* ---------- Combat feedback ---------- */
#multikill {
  position: fixed;
  top: 26%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 96vw;
  text-align: center;
  font-family: "Courier New", ui-monospace, monospace;
  /* min() against a vw term keeps "TRIPLE KILL" on one line on any width */
  font-size: min(calc(40px * var(--ui-scale)), 9vw);
  font-weight: bold;
  letter-spacing: min(calc(10px * var(--ui-scale)), 2.2vw);
  color: #fff0c2;
  text-shadow: 0 0 26px rgba(255, 190, 60, 0.85), 0 0 60px rgba(255, 140, 40, 0.5);
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
  z-index: 26;
}
#energytoast {
  position: fixed;
  top: 34%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 92vw;
  text-align: center;
  font-family: "Courier New", ui-monospace, monospace;
  font-size: max(12px, calc(15px * var(--ui-scale)));
  letter-spacing: 4px;
  color: #ffe9a8;
  text-shadow: 0 0 14px rgba(255, 214, 64, 0.75);
  pointer-events: none;
  user-select: none;
  z-index: 26;
}

/* ============================================================
   START SCREEN (v0.2.0) — the artwork IS the menu
   ============================================================ */
#startscreen {
  position: fixed;
  inset: 0;
  z-index: 28;                 /* above canvas/HUD, below pause overlay (30) */
  overflow: hidden;
  background: #05060a;
  user-select: none;
}
#startscreen.hidden { display: none !important; }

/* Blurred, enlarged copy fills the letterbox/pillarbox gaps on odd ratios */
#ss-blur {
  position: absolute;
  inset: -4%;
  background: center / cover no-repeat var(--menu-art, none);
  filter: blur(34px) brightness(0.5) saturate(1.1);
  transform: scale(1.12);
  opacity: 0.9;
}

/* The contained image rect — position + size are computed in JS (px) */
#ss-scene { position: absolute; inset: 0; }
#ss-frame {
  position: absolute;
  transform-origin: 51.5% 35%;  /* CRT screen centre; JS keeps this in sync */
  will-change: transform, filter;
}
#ss-art {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 2px;
}

/* ---- Cosmetic overlays (never capture input) ---- */
#ss-fx { position: absolute; inset: 0; pointer-events: none; overflow: hidden; border-radius: 2px; }
#ss-scanlines {
  position: absolute; inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0px,
    rgba(0,0,0,0) 2px,
    rgba(0,0,0,0.16) 3px,
    rgba(0,0,0,0) 4px);
  mix-blend-mode: multiply;
  opacity: 0.55;
}
#ss-flicker {
  position: absolute; inset: 0;
  background: rgba(120, 180, 255, 0.03);
  animation: ss-flicker 5.5s steps(60) infinite;
}
@keyframes ss-flicker {
  0%,100% { opacity: 0.20; }
  47% { opacity: 0.10; }
  48% { opacity: 0.45; }
  49% { opacity: 0.12; }
  72% { opacity: 0.28; }
  73% { opacity: 0.08; }
}
/* Soft neon pulse hugging the television screen area */
#ss-glow {
  position: absolute;
  left: 24%; top: 8%; width: 55%; height: 56%;
  border-radius: 12px;
  box-shadow: 0 0 60px 12px rgba(120, 60, 220, 0.0);
  animation: ss-glow 4.2s ease-in-out infinite;
}
@keyframes ss-glow {
  0%,100% { box-shadow: 0 0 55px 8px rgba(150, 70, 230, 0.10); }
  50% { box-shadow: 0 0 80px 20px rgba(190, 90, 255, 0.22); }
}
#ss-dust { position: absolute; inset: 0; width: 100%; height: 100%; }

/* ---- Functional hotspots (positioned in % of the frame, so they follow it) ---- */
#ss-hotspots { position: absolute; inset: 0; }
.hotspot {
  position: absolute;
  margin: 0; padding: 0;
  background: transparent;
  border: 2px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: box-shadow 0.16s ease, border-color 0.16s ease, background 0.16s ease;
  outline: none;
}
.hotspot:hover,
.hotspot:focus-visible,
.hotspot.focus {
  border-color: rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 0 22px rgba(120, 200, 255, 0.55), inset 0 0 18px rgba(120, 200, 255, 0.25);
  animation: hs-pulse 1.6s ease-in-out infinite;
}
@keyframes hs-pulse {
  0%,100% { box-shadow: 0 0 18px rgba(120, 200, 255, 0.4), inset 0 0 14px rgba(120, 200, 255, 0.2); }
  50% { box-shadow: 0 0 30px rgba(160, 220, 255, 0.7), inset 0 0 22px rgba(160, 220, 255, 0.35); }
}

#ss-version {
  position: absolute;
  font-family: "Courier New", ui-monospace, monospace;
  color: #9fb6cf;
  letter-spacing: 1px;
  text-align: right;
  background: rgba(6, 10, 16, 0.72);
  border-radius: 3px;
  display: flex; align-items: center; justify-content: flex-end;
  padding-right: 2%;
  text-shadow: 0 0 6px rgba(0,0,0,0.9);
}

/* Fade-to-black used by the Play transition */
#ss-black {
  position: absolute; inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  z-index: 5;
}

/* ---- Menu panels layered over the dimmed start screen ---- */
#menupanel {
  position: fixed;
  inset: 0;
  z-index: 29;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  background: rgba(2, 5, 8, 0.72);
  backdrop-filter: blur(4px);
}
#menupanel.hidden { display: none !important; }
.mpanel {
  width: min(92vw, calc(400px * var(--ui-scale, 1)));
  max-height: 94vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: calc(26px * var(--ui-scale, 1)) calc(26px * var(--ui-scale, 1)) calc(20px * var(--ui-scale, 1));
  border: 1px solid rgba(57, 255, 106, 0.22);
  border-radius: 14px;
  background: rgba(4, 12, 8, 0.94);
  box-shadow: 0 0 60px rgba(57, 255, 106, 0.10);
  font-family: "Courier New", ui-monospace, monospace;
  color: #a8f7bd;
  text-align: center;
}
.mpanel.hidden { display: none !important; }
.mpanel h2 { margin: 0 0 18px; font-size: max(16px, calc(22px * var(--ui-scale, 1))); letter-spacing: 6px; }
.mpanel label { display: block; font-size: 10px; letter-spacing: 3px; opacity: 0.55; margin-bottom: 6px; }
.mp-actions { display: flex; gap: 10px; margin-top: 16px; }
.mp-actions button { flex: 1; }
.setrow { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; margin-bottom: 12px; text-align: left; }
.setrow label { margin: 0; }
.setrow input[type="range"] { grid-column: 1 / 2; width: 100%; accent-color: #39ff6a; cursor: pointer; }
.setrow .setval { grid-column: 2 / 3; grid-row: 1 / 3; font-size: 12px; opacity: 0.8; min-width: 40px; text-align: right; }
.lb-soon { font-size: max(18px, calc(26px * var(--ui-scale, 1))); letter-spacing: 6px; color: #ffd86e; margin: 18px 0 8px; text-shadow: 0 0 18px rgba(255, 200, 90, 0.5); }
.lb-sub { font-size: 12px; opacity: 0.6; letter-spacing: 1px; margin-bottom: 6px; }

/* ---- Play transition: input lock hides pointer on the hotspots ---- */
#startscreen.transitioning .hotspot { pointer-events: none; }

/* ---- Reduced motion: kill all ambient animation, keep it readable ---- */
@media (prefers-reduced-motion: reduce) {
  #ss-flicker, #ss-glow, .hotspot { animation: none !important; }
  #ss-flicker { opacity: 0.14; }
}
