/* Snap! Reaction Arena — neon arcade theme */

:root {
  --bg:       #0a0519;
  --bg-2:     #150a2c;
  --bg-3:     #1f1043;
  --line:     #2d1a55;
  --text:     #f3f1ff;
  --muted:    #8a82b8;
  --accent:   #ff3ec8;
  --accent-2: #50f5eb;
  --accent-3: #b06bff;
  --good:     #4af58a;
  --bad:      #ff4d6d;
  --warn:     #ffb13b;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: radial-gradient(1200px 800px at 50% -20%, #2a124e 0%, var(--bg) 60%) fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { color: var(--accent); }

button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- Splash ---------- */
.splash {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg);
  display: grid; place-items: center;
  transition: opacity 320ms ease, visibility 320ms ease;
}
.splash.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-bolt {
  width: 80px; height: 80px;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  clip-path: polygon(54% 14%, 34% 54%, 48% 54%, 40% 88%, 70% 46%, 54% 46%, 64% 14%);
  filter: drop-shadow(0 0 20px var(--accent));
  animation: pulse 1.6s ease-in-out infinite;
}
.splash-name {
  margin-top: 18px;
  font-size: 28px; font-weight: 800; letter-spacing: 6px;
  color: var(--accent-2);
  text-shadow: 0 0 14px rgba(80,245,235,0.6);
}
@keyframes pulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 14px var(--accent)); }
  50%      { transform: scale(1.08); filter: drop-shadow(0 0 28px var(--accent)); }
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px;
  padding: calc(10px + var(--safe-top)) 14px 10px 14px;
  background: linear-gradient(180deg, rgba(10,5,25,0.92), rgba(10,5,25,0.70) 90%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 900; letter-spacing: 3px; font-size: 18px;
  color: var(--text);
}
.brand-bolt {
  display: inline-block; transform: translateY(1px);
  color: var(--accent);
  text-shadow: 0 0 10px rgba(255,62,200,0.8);
}
.brand-name { color: var(--accent-2); text-shadow: 0 0 8px rgba(80,245,235,0.5); }
.topnav { display: flex; gap: 4px; margin-left: 8px; flex: 1; }
.topnav a {
  padding: 8px 10px; border-radius: 8px; color: var(--muted);
  font-size: 14px; font-weight: 600;
}
.topnav a.active, .topnav a:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.iconbtn {
  width: 38px; height: 38px; border-radius: 50%;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  font-size: 18px; line-height: 1;
}
.iconbtn:hover { background: rgba(255,255,255,0.12); }

/* ---------- Layout ---------- */
.app {
  max-width: 760px; margin: 0 auto;
  padding: 16px 14px calc(20px + var(--safe-bot)) 14px;
}
h1, h2, h3 { font-weight: 800; letter-spacing: 0.5px; margin: 0 0 10px; }
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; color: var(--accent-2); }
p { margin: 0 0 12px; color: #d8d3ee; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  color: #fff; font-weight: 800; letter-spacing: 1px;
  text-transform: uppercase; font-size: 14px;
  border: 0; box-shadow: 0 0 18px rgba(255,62,200,0.45), inset 0 0 0 1px rgba(255,255,255,0.15);
  transition: transform 80ms ease, box-shadow 200ms ease, filter 200ms ease;
}
.btn:hover { filter: brightness(1.1); box-shadow: 0 0 24px rgba(255,62,200,0.7), inset 0 0 0 1px rgba(255,255,255,0.2); }
.btn:active { transform: translateY(1px); }
.btn.ghost {
  background: transparent; color: var(--accent-2);
  border: 1px solid var(--accent-2);
  box-shadow: 0 0 12px rgba(80,245,235,0.25), inset 0 0 0 1px rgba(80,245,235,0.15);
}
.btn.ghost:hover { color: var(--text); border-color: var(--text); }
.btn.lg { padding: 16px 26px; font-size: 16px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

/* ---------- Inputs ---------- */
.input {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
  color: var(--text); font-size: 16px;
}
.input:focus { outline: 0; border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(80,245,235,0.18); }

/* ---------- Cards / grid ---------- */
.game-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.game-card {
  background: linear-gradient(160deg, var(--bg-2), var(--bg-3));
  border: 1px solid var(--line);
  border-radius: 14px; padding: 14px;
  cursor: pointer; position: relative; overflow: hidden;
  transition: transform 120ms ease, border-color 200ms ease, box-shadow 200ms ease;
}
.game-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-2);
  box-shadow: 0 8px 26px rgba(80,245,235,0.18);
}
.game-card .gc-title {
  font-weight: 800; font-size: 17px; letter-spacing: 0.5px; color: var(--text);
  margin-bottom: 4px;
}
.game-card .gc-blurb { color: var(--muted); font-size: 13px; min-height: 32px; }
.game-card .gc-best {
  margin-top: 10px; font-size: 12px; color: var(--accent-2);
  display: flex; justify-content: space-between; gap: 8px;
}
.game-card .gc-tag {
  position: absolute; top: 10px; right: 10px;
  font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase;
  padding: 3px 7px; border-radius: 999px;
  background: rgba(176,107,255,0.16); color: var(--accent-3);
  border: 1px solid rgba(176,107,255,0.4);
}
.game-card .gc-actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin-top: 12px;
}
.game-card .gc-actions .btn { padding: 9px 12px; font-size: 12px; }
.game-card .gc-actions .gc-lb { color: var(--accent-2); }

/* ---------- Game stage ---------- */
.stage {
  margin-top: 8px;
  background: linear-gradient(160deg, var(--bg-2), var(--bg-3));
  border: 1px solid var(--line); border-radius: 16px;
  padding: 18px;
}
.stage h2 { color: var(--accent); text-shadow: 0 0 8px rgba(255,62,200,0.5); }
.stage .desc { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.play-area {
  position: relative; min-height: 360px;
  background: rgba(0,0,0,0.35);
  border-radius: 12px;
  display: grid; place-items: center;
  overflow: hidden;
  touch-action: manipulation;
  isolation: isolate;
  transition: background 220ms ease;
}
/* A slow neon "breathing" gradient that lives beneath the message during
   idle/wait states. Adds tactile motion without distracting from the cue. */
.play-area::before {
  content: ''; position: absolute; inset: -10%; z-index: 0;
  background:
    radial-gradient(circle at 20% 30%, rgba(255,62,200,0.18), transparent 55%),
    radial-gradient(circle at 80% 70%, rgba(80,245,235,0.18), transparent 55%);
  filter: blur(20px);
  pointer-events: none;
  animation: drift 7s ease-in-out infinite;
  opacity: 1;
  transition: opacity 240ms ease;
}
/* Drop the breathing layer when the screen needs absolute focus
   (e.g., the moment Red Light flips, or a TAP! prompt). */
.play-area.solid::before { opacity: 0; }
@keyframes drift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(2%, -3%) scale(1.05); }
}

.play-area > * { position: relative; z-index: 1; }

.play-msg { font-size: 20px; font-weight: 700; text-align: center; padding: 20px; }
.play-msg .big {
  font-size: 44px; display: block; margin: 6px 0;
  letter-spacing: 1px;
  text-shadow: 0 0 24px rgba(255,255,255,0.18);
}
/* Strong, instant change on phase flips so red-light / "TAP!" feel tactile. */
.play-area.flash-go,
.play-area.flash-stop,
.play-area.flash-hit {
  animation: snap-in 180ms ease;
}
@keyframes snap-in {
  0%   { filter: brightness(1.4); }
  100% { filter: brightness(1); }
}

.flash-go      { background: #1a4a2a !important; }
.flash-stop    { background: #5a1a1a !important; }
.flash-neutral { background: #1a1730 !important; }
.flash-hit     { background: #1a3550 !important; }
.flash-stop .play-msg .big { color: #ffe4e8; text-shadow: 0 0 28px rgba(255,77,109,0.9); }
.flash-go   .play-msg .big { color: #d8ffe6; text-shadow: 0 0 28px rgba(74,245,138,0.7); }

/* Tap ripple — a fading ring spawned by JS at the touch position. */
.tap-ripple {
  position: absolute; width: 8px; height: 8px; border-radius: 50%;
  background: rgba(255,255,255,0.18);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.5);
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: ripple 520ms ease-out forwards;
  z-index: 2;
}
@keyframes ripple {
  0%   { width: 8px;   height: 8px;   opacity: 0.85; }
  100% { width: 280px; height: 280px; opacity: 0;    }
}

/* ---------- Result screen ---------- */
.stage.result { text-align: center; padding-top: 22px; padding-bottom: 22px; }
.stage.result h2 { color: var(--accent-2); text-shadow: 0 0 8px rgba(80,245,235,0.4); }
.result-score {
  display: inline-flex; align-items: baseline; gap: 10px;
  margin: 8px 0 6px;
}
.result-num {
  font-size: 88px; font-weight: 900; letter-spacing: 1px;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  text-shadow: 0 0 30px rgba(255,62,200,0.35);
  animation: pop-in 220ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
  font-variant-numeric: tabular-nums;
}
.result-unit {
  font-size: 22px; font-weight: 700; letter-spacing: 2px;
  color: var(--muted); text-transform: uppercase;
}
.result-detail {
  color: var(--muted); font-size: 14px; margin-bottom: 14px;
}
.stage.result .lb-stats { grid-template-columns: repeat(3, 1fr); margin: 6px 0 14px; }
.stage.result .input { margin-top: 4px; max-width: 360px; margin-inline: auto; }
.stage.result .btn-row { justify-content: center; margin-top: 14px; }
.result-lb-link {
  display: inline-block; margin-top: 14px;
  font-size: 14px; font-weight: 600; letter-spacing: 0.5px;
  color: var(--accent-2);
}
.result-lb-link:hover { color: var(--accent); }

@keyframes pop-in {
  0%   { transform: scale(0.6); opacity: 0; }
  60%  { transform: scale(1.05); opacity: 1; }
  100% { transform: scale(1); }
}

@media (max-width: 480px) {
  .result-num { font-size: 64px; }
  .result-unit { font-size: 18px; }
  .stage.result .lb-stats { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .stage.result .lb-stat { padding: 8px 6px; }
  .stage.result .lb-stat .v { font-size: 16px; }
}

/* ---------- Whack-9 grid ---------- */
.w9-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  width: min(360px, 90%);
}
.w9-cell {
  aspect-ratio: 1/1;
  border-radius: 50%;
  background: #251447;
  border: 2px solid #3d2570;
  transition: background 60ms ease, transform 60ms ease, box-shadow 60ms ease;
}
.w9-cell.lit {
  background: var(--accent);
  border-color: #ff8fe1;
  box-shadow: 0 0 26px var(--accent), inset 0 0 12px rgba(255,255,255,0.4);
  transform: scale(1.05);
}

/* ---------- Aim trainer ---------- */
.aim-area { width: 100%; height: 420px; position: relative; }
.aim-target {
  position: absolute; width: 56px; height: 56px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0%, var(--accent-2) 35%, #1d8f8a 100%);
  box-shadow: 0 0 24px var(--accent-2);
  transform: translate(-50%, -50%);
  cursor: pointer;
  animation: aim-in 120ms ease;
}
@keyframes aim-in { from { transform: translate(-50%, -50%) scale(0.4); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }

/* ---------- Stroop ---------- */
.stroop-word {
  font-size: 56px; font-weight: 900; letter-spacing: 2px;
  text-align: center; padding: 20px;
}
.stroop-choices {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
  margin-top: 14px; width: 100%; max-width: 340px;
}
.stroop-choice {
  padding: 14px; border-radius: 10px; border: 2px solid currentColor;
  background: rgba(255,255,255,0.05); font-weight: 800;
  font-size: 16px; letter-spacing: 1px; text-transform: uppercase;
}

/* ---------- Choice reaction ---------- */
.choice-arrow {
  font-size: 120px; line-height: 1; font-weight: 900;
  color: var(--accent-2); text-shadow: 0 0 30px rgba(80,245,235,0.7);
}
.choice-pad {
  display: grid; grid-template-areas: ". up ." "left . right" ". down .";
  gap: 10px; margin-top: 16px;
}
.choice-pad button {
  width: 60px; height: 60px; border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.06);
  font-size: 28px; color: var(--text);
}
.choice-pad button:active { background: rgba(80,245,235,0.18); }
.cp-up { grid-area: up; } .cp-down { grid-area: down; }
.cp-left { grid-area: left; } .cp-right { grid-area: right; }

/* ---------- Go/No-Go ---------- */
.gng-stim {
  width: 180px; height: 180px;
  border-radius: 50%;
  display: grid; place-items: center;
  animation: stim-in 140ms ease;
}
@keyframes stim-in {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ---------- Sequence ---------- */
.seq-pad {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
  width: min(360px, 90%);
}
.seq-tile {
  aspect-ratio: 1/1; border-radius: 14px;
  border: 2px solid var(--line);
  opacity: 0.6; transition: opacity 80ms ease, transform 80ms ease, box-shadow 100ms ease;
}
.seq-tile.lit { opacity: 1; transform: scale(1.04); }
.seq-tile[data-c="0"] { background: #b32a86; box-shadow: 0 0 0 var(--line); }
.seq-tile[data-c="1"] { background: #2aa2b3; }
.seq-tile[data-c="2"] { background: #b3a02a; }
.seq-tile[data-c="3"] { background: #5a2ab3; }
.seq-tile.lit[data-c="0"] { box-shadow: 0 0 30px #ff3ec8; }
.seq-tile.lit[data-c="1"] { box-shadow: 0 0 30px #50f5eb; }
.seq-tile.lit[data-c="2"] { box-shadow: 0 0 30px #ffe14d; }
.seq-tile.lit[data-c="3"] { box-shadow: 0 0 30px #b06bff; }

/* ---------- Audio reaction ---------- */
.audio-eye { font-size: 64px; }

/* ---------- Leaderboard ---------- */
.lb-tabs {
  display: inline-flex; gap: 4px; padding: 4px;
  background: rgba(255,255,255,0.04); border-radius: 999px; margin-bottom: 12px;
}
.lb-tabs button {
  padding: 8px 14px; border: 0; background: transparent; color: var(--muted);
  border-radius: 999px; font-weight: 700; font-size: 13px; letter-spacing: 1px;
  text-transform: uppercase;
}
.lb-tabs button.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  color: #fff;
}
.lb-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px;
}
.lb-stat {
  background: rgba(255,255,255,0.04); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px; text-align: center;
}
.lb-stat .v { font-size: 20px; font-weight: 800; color: var(--accent-2); }
.lb-stat .k { font-size: 10px; color: var(--muted); letter-spacing: 1.2px; text-transform: uppercase; }
.lb-table {
  width: 100%; max-width: 640px; margin: 0 auto;
  border-collapse: collapse; font-size: 14px;
  text-align: center;
}
.lb-table th, .lb-table td {
  padding: 8px 10px; border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.lb-table th {
  color: var(--muted); font-weight: 600;
  font-size: 11px; letter-spacing: 1.2px; text-transform: uppercase;
}
.lb-table tbody tr:hover { background: rgba(255,255,255,0.04); }
.lb-table .rank {
  width: 44px; color: var(--accent-3); font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.lb-table .col-name { text-align: left; font-weight: 600; }
.lb-table .score {
  font-variant-numeric: tabular-nums;
  color: var(--accent-2); font-weight: 700;
}
.lb-table .col-date,
.lb-table .col-time {
  color: var(--muted); font-variant-numeric: tabular-nums;
  white-space: nowrap; font-size: 12px;
}
.lb-empty { color: var(--muted); padding: 24px; text-align: center; }

@media (max-width: 480px) {
  .lb-table th, .lb-table td { padding: 6px 4px; font-size: 13px; }
  .lb-table .rank { width: 28px; }
  .lb-table .col-date,
  .lb-table .col-time { font-size: 11px; }
}

/* ---------- Toast / banner ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-bot));
  transform: translateX(-50%);
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--accent-2);
  border-radius: 999px; padding: 10px 18px;
  font-size: 14px; font-weight: 600;
  box-shadow: 0 0 24px rgba(80,245,235,0.35);
  z-index: 100;
  animation: toast-in 200ms ease;
}
@keyframes toast-in { from { transform: translate(-50%, 14px); opacity: 0; } to { transform: translateX(-50%); opacity: 1; } }

/* ---------- Help ---------- */
.help-section { margin-bottom: 22px; }
.help-section h3 { color: var(--accent); margin-bottom: 6px; }
.kbd {
  display: inline-block; padding: 1px 6px; border-radius: 4px;
  background: rgba(255,255,255,0.08); border: 1px solid var(--line);
  font-family: ui-monospace, monospace; font-size: 12px;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .topnav a { padding: 6px 8px; }
  h1 { font-size: 22px; }
  .lb-stats { grid-template-columns: repeat(2, 1fr); }
  .stroop-word { font-size: 44px; }
  .choice-arrow { font-size: 96px; }
}

/* ---------- Misc ---------- */
.muted { color: var(--muted); }
.center { text-align: center; }
.spacer { height: 14px; }
hr.div { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.kv { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.05); font-size: 14px; }
.kv .v { color: var(--accent-2); font-weight: 700; }
