/* ============================================================
   NEON RALLY — cohesive neon-arcade theme
   ============================================================ */

:root {
  --bg0: #05050c;
  --bg1: #0c0618;
  --ink: #e8f6ff;
  --dim: #8b93b8;
  --cyan: #3df5ff;
  --magenta: #ff3df5;
  --lime: #b6ff3d;
  --gold: #ffe14d;
  --danger: #ff4d6b;
  --panel: rgba(9, 7, 22, 0.86);
  --line: rgba(61, 245, 255, 0.32);
  --line-strong: rgba(61, 245, 255, 0.7);
  --font-display: "Orbitron", "Segoe UI", system-ui, sans-serif;
  --font-body: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg0);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

body {
  position: fixed;
  inset: 0;
}

canvas#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  touch-action: none;
  cursor: none;
}
body.menu-open canvas#game { cursor: default; }

/* CRT vignette + scanlines (pure CSS, GPU cheap) */
#vignette {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.55) 100%);
}
#scanlines {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.14;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.05) 0 1px,
    transparent 1px 3px
  );
}

/* ---------------- HUD ---------------- */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) 0 calc(12px + var(--safe-l));
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
}
#hud.hidden {
  opacity: 0;
  transform: translateY(-8px);
  visibility: hidden;
}
.hud-cell { display: flex; flex-direction: column; min-width: 90px; }
.hud-rally { align-items: center; }
.hud-right {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-width: 0;
  pointer-events: auto;
}
.hud-label {
  font-family: var(--font-body);
  font-size: clamp(9px, 1.6vw, 11px);
  letter-spacing: 0.28em;
  color: var(--dim);
}
.hud-value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(22px, 5vw, 34px);
  line-height: 1.05;
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(61, 245, 255, 0.65);
  font-variant-numeric: tabular-nums;
}
.hud-value.rally {
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255, 225, 77, 0.55);
}
.hud-value.bump { animation: bump 0.28s cubic-bezier(0.2, 2.4, 0.4, 1); }
@keyframes bump {
  0% { transform: scale(1); }
  35% { transform: scale(1.28); }
  100% { transform: scale(1); }
}

.lives { display: flex; gap: 6px; height: 18px; align-items: center; }
.lives .pip {
  width: 13px; height: 13px;
  background: var(--magenta);
  transform: rotate(45deg);
  border-radius: 3px;
  box-shadow: 0 0 10px rgba(255, 61, 245, 0.8);
  transition: transform 0.2s ease, opacity 0.2s ease, background 0.2s ease;
}
.lives .pip.lost {
  background: transparent;
  box-shadow: none;
  outline: 1px solid rgba(255, 61, 245, 0.35);
  opacity: 0.45;
}
.lives .pip.pop { animation: bump 0.3s cubic-bezier(0.2, 2.2, 0.4, 1); }

.icon-btn {
  appearance: none;
  border: 1px solid rgba(61, 245, 255, 0.35);
  background: rgba(9, 7, 22, 0.72);
  color: var(--cyan);
  width: 40px; height: 40px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.icon-btn:hover { box-shadow: 0 0 14px rgba(61, 245, 255, 0.35); background: rgba(15, 12, 34, 0.9); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn .ic-off { display: none; }
.icon-btn.muted { color: var(--dim); border-color: rgba(139, 147, 184, 0.35); }
.icon-btn.muted .ic-on { display: none; }
.icon-btn.muted .ic-off { display: block; }

/* ---------------- Overlays ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
  background: rgba(4, 3, 12, 0.55);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  opacity: 1;
  visibility: visible;
  transition: opacity 0.24s ease, visibility 0.24s;
  overflow: hidden auto;
  touch-action: pan-y;
}
.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.panel {
  width: min(520px, 100%);
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  scrollbar-width: thin;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: clamp(20px, 4.5vh, 36px) clamp(18px, 5vw, 36px);
  text-align: center;
  box-shadow:
    0 0 0 1px rgba(255, 61, 245, 0.06),
    0 0 44px rgba(61, 245, 255, 0.12),
    0 24px 70px rgba(0, 0, 0, 0.6);
  animation: panelIn 0.34s cubic-bezier(0.16, 1.2, 0.3, 1);
  touch-action: pan-y;
}
.overlay.hidden .panel { animation: none; }
@keyframes panelIn {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
.panel.narrow { width: min(420px, 100%); }

.kicker {
  font-size: clamp(10px, 2vw, 12px);
  letter-spacing: 0.42em;
  color: var(--magenta);
  text-shadow: 0 0 10px rgba(255, 61, 245, 0.6);
  margin-bottom: 10px;
}
.kicker.danger { color: var(--danger); text-shadow: 0 0 10px rgba(255, 77, 107, 0.6); }

.title {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(40px, 11vw, 76px);
  line-height: 0.98;
  letter-spacing: 0.02em;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-bottom: 10px;
}
.title .t-neon {
  color: #fff;
  text-shadow:
    0 0 8px rgba(255, 255, 255, 0.8),
    0 0 28px rgba(61, 245, 255, 0.75),
    0 0 60px rgba(61, 245, 255, 0.45);
  animation: flicker 4.5s infinite;
}
.title .t-rally {
  color: var(--magenta);
  text-shadow:
    0 0 10px rgba(255, 61, 245, 0.9),
    0 0 34px rgba(255, 61, 245, 0.6),
    0 0 70px rgba(255, 61, 245, 0.35);
}
@keyframes flicker {
  0%, 91%, 94%, 100% { opacity: 1; }
  92%, 95% { opacity: 0.55; }
}

.h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(22px, 6vw, 32px);
  letter-spacing: 0.06em;
  margin-bottom: 18px;
  text-shadow: 0 0 18px rgba(61, 245, 255, 0.45);
}

.tag {
  color: var(--dim);
  font-size: clamp(13px, 2.6vw, 15px);
  margin-bottom: 20px;
}

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid rgba(61, 245, 255, 0.45);
  background: rgba(61, 245, 255, 0.07);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(13px, 2.8vw, 15px);
  letter-spacing: 0.22em;
  padding: 15px 30px;
  min-height: 50px;
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, box-shadow 0.18s ease, background 0.18s ease, border-color 0.18s ease;
  position: relative;
}
.btn:hover {
  background: rgba(61, 245, 255, 0.14);
  box-shadow: 0 0 22px rgba(61, 245, 255, 0.35);
}
.btn:active { transform: scale(0.96); }
.btn.primary {
  background: linear-gradient(180deg, rgba(61, 245, 255, 0.24), rgba(61, 245, 255, 0.1));
  border-color: var(--line-strong);
  color: #eafdff;
  text-shadow: 0 0 12px rgba(61, 245, 255, 0.8);
  box-shadow: 0 0 26px rgba(61, 245, 255, 0.28), inset 0 0 18px rgba(61, 245, 255, 0.12);
}
.btn.primary:hover {
  box-shadow: 0 0 40px rgba(61, 245, 255, 0.5), inset 0 0 22px rgba(61, 245, 255, 0.2);
  transform: translateY(-1px);
}
.btn.ghost {
  background: transparent;
  border-color: rgba(139, 147, 184, 0.4);
  color: var(--dim);
  letter-spacing: 0.18em;
}
.btn.ghost:hover { color: var(--ink); border-color: rgba(139, 147, 184, 0.8); box-shadow: none; }
.btn.tiny { min-height: 36px; padding: 9px 16px; font-size: 11px; opacity: 0.75; }
.btn-col { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.btn-col .btn { width: 100%; }

#btnPlay {
  width: min(300px, 100%);
  font-size: clamp(16px, 3.6vw, 19px);
  padding: 17px 30px;
  animation: breathe 2.4s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 20px rgba(61, 245, 255, 0.25), inset 0 0 14px rgba(61, 245, 255, 0.1); }
  50% { box-shadow: 0 0 44px rgba(61, 245, 255, 0.55), inset 0 0 20px rgba(61, 245, 255, 0.2); }
}

.kbd, .hint .key {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 6px;
  border: 1px solid rgba(61, 245, 255, 0.4);
  background: rgba(61, 245, 255, 0.08);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  color: var(--cyan);
  vertical-align: middle;
}
.hint .key.wide { padding: 0 9px; }

.hints { margin-top: 18px; display: flex; flex-direction: column; gap: 9px; }
.hint {
  font-size: clamp(11px, 2.3vw, 13px);
  color: var(--dim);
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
  align-items: center;
}
.hint em { font-style: normal; opacity: 0.7; }

.mini-board {
  margin-top: 16px;
  border-top: 1px dashed rgba(139, 147, 184, 0.3);
  padding-top: 12px;
}
.mini-board .mb-title {
  font-size: 10px;
  letter-spacing: 0.36em;
  color: var(--magenta);
  margin-bottom: 8px;
}
.mini-board ul { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.mini-board li {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-display);
  font-size: clamp(12px, 2.5vw, 14px);
  color: var(--dim);
  padding: 0 6px;
}
.mini-board li b { color: var(--gold); font-weight: 700; text-shadow: 0 0 8px rgba(255, 225, 77, 0.5); }
.mini-board li span:first-child { letter-spacing: 0.2em; color: var(--ink); }
.mini-board .empty { color: var(--dim); font-size: 12px; justify-content: center; letter-spacing: 0.1em; }

/* Final score / stats */
.final-score { display: flex; flex-direction: column; gap: 2px; margin: 4px 0 16px; }
.final-score span:last-child {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(44px, 12vw, 64px);
  color: var(--cyan);
  text-shadow: 0 0 24px rgba(61, 245, 255, 0.7);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.stat {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(139, 147, 184, 0.22);
  border-radius: 10px;
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.stat span {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(17px, 4vw, 22px);
  color: var(--ink);
}
.stat label { font-size: 9px; letter-spacing: 0.22em; color: var(--dim); }

.name-entry { margin: 6px 0 4px; animation: panelIn 0.3s ease; }
.new-high {
  font-family: var(--font-display);
  font-size: clamp(11px, 2.4vw, 13px);
  color: var(--gold);
  letter-spacing: 0.12em;
  text-shadow: 0 0 12px rgba(255, 225, 77, 0.6);
  margin-bottom: 10px;
}
.name-input {
  width: 148px;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 34px;
  letter-spacing: 0.35em;
  text-indent: 0.35em;
  color: var(--gold);
  background: rgba(255, 225, 77, 0.06);
  border: 1px solid rgba(255, 225, 77, 0.5);
  border-radius: 12px;
  padding: 10px 6px;
  outline: none;
  text-transform: uppercase;
  caret-color: var(--gold);
  box-shadow: 0 0 22px rgba(255, 225, 77, 0.18);
}
.name-input:focus { box-shadow: 0 0 30px rgba(255, 225, 77, 0.4); }
.name-input::placeholder { color: rgba(255, 225, 77, 0.28); }

/* Score table */
.score-list {
  list-style: none;
  counter-reset: rank;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 4px 0 6px;
}
.score-list li {
  counter-increment: rank;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(139, 147, 184, 0.18);
  font-family: var(--font-display);
  transition: box-shadow 0.3s ease;
}
.score-list li::before {
  content: counter(rank, decimal-leading-zero);
  color: var(--dim);
  font-size: 13px;
  width: 26px;
}
.score-list li .nm {
  flex: 1;
  text-align: left;
  letter-spacing: 0.24em;
  color: var(--ink);
  font-weight: 700;
}
.score-list li .sc {
  color: var(--gold);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 10px rgba(255, 225, 77, 0.45);
}
.score-list li:first-child {
  border-color: rgba(255, 225, 77, 0.55);
  background: rgba(255, 225, 77, 0.07);
  box-shadow: 0 0 18px rgba(255, 225, 77, 0.18);
}
.score-list li:first-child::before { content: "👑"; width: auto; }
.score-list li.fresh {
  border-color: var(--line-strong);
  box-shadow: 0 0 22px rgba(61, 245, 255, 0.35);
  animation: freshGlow 1.4s ease infinite alternate;
}
@keyframes freshGlow {
  from { box-shadow: 0 0 10px rgba(61, 245, 255, 0.25); }
  to { box-shadow: 0 0 28px rgba(61, 245, 255, 0.55); }
}
.score-list .empty-row {
  justify-content: center;
  color: var(--dim);
  font-size: 12px;
  letter-spacing: 0.18em;
  border-style: dashed;
}
.score-list .empty-row::before { content: ""; width: 0; }

.foot {
  margin-top: 16px;
  font-size: 12px;
  color: var(--dim);
}

#nameEntry.hidden { display: none; }
#hud.hidden { visibility: hidden; }

/* ---------------- Responsive ---------------- */
@media (max-height: 640px) {
  .panel { padding: 16px 18px; border-radius: 14px; }
  .title { font-size: clamp(30px, 9vh, 48px); flex-direction: row; gap: 12px; }
  .tag { margin-bottom: 12px; }
  .hints { margin-top: 12px; }
  .mini-board { margin-top: 10px; padding-top: 8px; }
  #btnPlay { padding: 13px 26px; }
  .btn { min-height: 44px; padding: 12px 22px; }
}
@media (max-width: 380px) {
  .stats { gap: 5px; }
  .hint .key { min-width: 20px; height: 20px; font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .title .t-neon { animation: none; }
  #btnPlay { animation: none; }
  .score-list li.fresh { animation: none; }
  .panel { animation: none; }
}
