/* =========================================================================
   Bounce Arena — all UI chrome. The play field itself is canvas-rendered;
   everything here is menus, HUD, overlays.

   The palette lives in custom properties so the colorblind toggle is a
   variable swap (body.colorblind), not a rewrite. Arena accents are set
   from JS on #stage via --arena-accent.
   ========================================================================= */

:root {
  --bg: #0A0A0F;
  --p1: #00F0FF;          /* electric cyan  — Player 1 */
  --p2: #FF2E88;          /* magenta        — Player 2 */
  --ball: #FFB800;        /* amber          — ball + power-ups */
  --ink: #E8ECF4;
  --ink-dim: #8A93A6;
  --panel-bg: rgba(16, 18, 28, 0.72);
  --panel-border: rgba(160, 200, 255, 0.18);
  --arena-accent: #00F0FF;
  --focus: #FFB800;
}

/* Deuteranopia/protanopia-safe swap: cyan vs orange, white ball. */
body.colorblind {
  --p1: #35C4FF;
  --p2: #FF9E1B;
  --ball: #FFFFFF;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

/* ------------------------------------------------------------------ stage */

#stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Canvas is sized from JS to a letterboxed 16:9 rect; overlays share it. */
#game {
  position: absolute;
  background: var(--bg);
  box-shadow: 0 0 60px rgba(0, 240, 255, 0.06);
}

/* --------------------------------------------------------------- screens */

.screen {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}
.screen.active { display: flex; }

/* Pause / confirm / game-over sit on a dimmer so play state stays visible. */
.overlay-screen { background: rgba(6, 7, 12, 0.62); backdrop-filter: blur(3px); }

.panel {
  background: var(--panel-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: 0 0 40px rgba(0, 240, 255, 0.10), inset 0 0 30px rgba(0, 0, 0, 0.35);
  padding: clamp(18px, 4vmin, 40px);
  width: min(440px, 94vw);
  max-height: 92vh;
  text-align: center;
}
.panel-wide { width: min(640px, 94vw); }
.panel-scroll { overflow-y: auto; text-align: left; }
.panel-scroll h2 { text-align: center; }

/* ---------------------------------------------------------------- type */

h2 {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: clamp(18px, 3.4vmin, 26px);
  margin-bottom: 18px;
  color: var(--ink);
  text-shadow: 0 0 18px rgba(0, 240, 255, 0.35);
}
h3 {
  font-size: 14px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--arena-accent);
  margin: 18px 0 6px;
}
p { color: var(--ink-dim); font-size: 14px; line-height: 1.55; }

.game-title {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-size: clamp(30px, 7vmin, 54px);
  letter-spacing: 0.10em;
  color: var(--p1);
  text-shadow: 0 0 24px var(--p1);
  line-height: 1.05;
}
.game-title span { display: block; color: var(--p2); text-shadow: 0 0 24px var(--p2); }
.tagline {
  margin: 6px 0 22px;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--ball);
}

/* --------------------------------------------------------------- buttons */

.menu-buttons { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }

.btn {
  font: inherit;
  font-size: 15px;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px 18px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s, transform 0.15s;
}
.btn:hover { border-color: var(--p1); box-shadow: 0 0 16px rgba(0, 240, 255, 0.25); }
.btn:active { transform: scale(0.98); }
.btn:focus-visible, .seg button:focus-visible, input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.btn-primary {
  border-color: var(--p1);
  color: var(--p1);
  background: rgba(0, 240, 255, 0.08);
  box-shadow: 0 0 18px rgba(0, 240, 255, 0.18);
}
.btn-ghost { border-color: transparent; color: var(--ink-dim); }
.btn-ghost:hover { color: var(--ink); box-shadow: none; border-color: var(--panel-border); }
.btn[disabled] { opacity: 0.35; cursor: not-allowed; box-shadow: none; }
.btn[disabled]:hover { border-color: var(--panel-border); }

.diff-btn small { display: block; font-size: 11px; color: var(--ink-dim); margin-top: 2px; letter-spacing: 0.03em; }

.row-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }

/* ------------------------------------------------------------- option UI */

.opt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0;
  text-align: left;
  flex-wrap: wrap;
}
.opt-label { font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-dim); }
.opt-row.disabled { opacity: 0.35; pointer-events: none; }

.seg { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.seg button {
  font: inherit;
  font-size: 13px;
  color: var(--ink-dim);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  transition: all 0.18s;
}
.seg button[aria-pressed="true"] {
  color: var(--bg);
  background: var(--p1);
  border-color: var(--p1);
  box-shadow: 0 0 14px rgba(0, 240, 255, 0.45);
  font-weight: 600;
}
.seg button[disabled] { opacity: 0.35; cursor: not-allowed; }

input[type="range"] { accent-color: var(--p1); width: 180px; }
input[type="text"] {
  font: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 10px 12px;
}

/* --------------------------------------------------------------- legend */

.legend { list-style: none; text-align: left; }
.legend li { font-size: 13px; color: var(--ink-dim); padding: 4px 0; line-height: 1.5; }
.legend b { color: var(--ink); }
.legend .pu-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 8px; background: var(--ball); box-shadow: 0 0 8px var(--ball);
  vertical-align: 1px;
}
kbd {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--panel-border);
  border-radius: 5px;
  padding: 1px 6px;
}
.key-hint { font-size: 11px; letter-spacing: 0.14em; color: var(--ink-dim); }
.key-hint-block, .touch-hint-block { margin-bottom: 6px; }

/* Hide keyboard hints on touch-primary devices, touch hints on pointer ones */
body.touch .key-hint, body.touch .key-hint-block { display: none; }
body:not(.touch) .touch-hint-block { display: none; }

/* ------------------------------------------------------------------ HUD */

#hud {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 2.2% 6% 0;
}
#hud.hidden { display: none; }

.hud-side { display: flex; flex-direction: column; align-items: center; gap: 6px; }

.hud-score {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: clamp(26px, 6vmin, 52px);
  font-weight: 700;
  line-height: 1;
}
.hud-left  .hud-score { color: var(--p1); text-shadow: 0 0 16px var(--p1); }
.hud-right .hud-score { color: var(--p2); text-shadow: 0 0 16px var(--p2); }

.hud-score.pop { animation: score-pop 0.4s ease; }
@keyframes score-pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.5); }
  100% { transform: scale(1); }
}

.hud-effects { display: flex; gap: 5px; min-height: 26px; }
.fx-icon {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; line-height: 1;
  /* --p is set from JS each frame: conic remaining-time ring */
  background:
    radial-gradient(circle, rgba(10,10,15,0.9) 58%, transparent 59%),
    conic-gradient(var(--ball) calc(var(--p, 1) * 360deg), rgba(255,255,255,0.12) 0deg);
}

.hud-center { position: absolute; left: 0; right: 0; top: 4%; text-align: center; pointer-events: none; }

.hud-banner {
  display: inline-block;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: clamp(13px, 2.6vmin, 20px);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--ball);
  text-shadow: 0 0 18px var(--ball);
  border: 1px solid rgba(255, 184, 0, 0.4);
  border-radius: 8px;
  padding: 6px 18px;
  background: rgba(10, 10, 15, 0.55);
  animation: banner-pulse 1.1s ease-in-out infinite;
}
@keyframes banner-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.55; } }

.hud-count {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: clamp(40px, 12vmin, 96px);
  font-weight: 700;
  color: var(--ink);
  text-shadow: 0 0 30px var(--p1);
  margin-top: 14vh;
}

/* -------------------------------------------------------------- game over */

.go-score {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: clamp(26px, 6vmin, 44px);
  color: var(--ball);
  text-shadow: 0 0 20px var(--ball);
  margin: 6px 0 14px;
}
.go-stats { list-style: none; display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; margin-bottom: 8px; }
.go-stats li { font-size: 12px; color: var(--ink-dim); letter-spacing: 0.06em; }
.go-stats b { display: block; font-size: 18px; color: var(--ink); font-family: ui-monospace, Menlo, monospace; }
.go-highscore { color: var(--ball); font-size: 14px; letter-spacing: 0.1em; margin: 8px 0; }
.go-submit { display: flex; gap: 8px; justify-content: center; margin: 10px 0; flex-wrap: wrap; }
.go-board { list-style-position: inside; max-height: 160px; overflow-y: auto; font-size: 13px; color: var(--ink-dim); margin-top: 8px; }
.go-board li { padding: 2px 0; }
.go-board b { color: var(--ink); }

/* ------------------------------------------------------------ pause extra */

.pause-diffs { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.pause-diffs.hidden { display: none; }

/* ------------------------------------------------------------- CRT layer */

.crt { position: absolute; z-index: 8; pointer-events: none; }
.crt::before {
  /* scanlines */
  content: "";
  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.22) 3px, rgba(0, 0, 0, 0.22) 4px
  );
  mix-blend-mode: multiply;
}
.crt::after {
  /* vignette + faint chromatic fringe */
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, transparent 58%, rgba(0, 0, 10, 0.5) 100%);
  box-shadow: inset 2px 0 2px rgba(255, 0, 60, 0.06), inset -2px 0 2px rgba(0, 120, 255, 0.06);
}
.crt.flicker { animation: crt-flicker 0.12s infinite; }
@keyframes crt-flicker { 0%,100% { opacity: 1; } 50% { opacity: 0.92; } }

.hidden { display: none !important; }

/* ------------------------------------------------------------- responsive */

@media (max-width: 560px), (max-height: 480px) {
  .panel { padding: 14px 16px; }
  .opt-row { flex-direction: column; align-items: flex-start; gap: 6px; }
  .seg { justify-content: flex-start; }
  .menu-buttons { gap: 7px; }
  .btn { padding: 9px 14px; font-size: 14px; }
  h2 { margin-bottom: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .hud-banner { animation: none; }
  .hud-score.pop { animation: none; }
  .crt.flicker { animation: none; }
  .btn, .seg button { transition: none; }
}
