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

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --border: #2a2a2a;
  --accent: #4ade80;
  --accent-dim: #16a34a;
  --yellow: #facc15;
  --orange: #fb923c;
  --red: #f87171;
  --text: #f5f5f5;
  --text-dim: #888;
  --needle: #ffffff;
  --track-h: 64px;
  --needle-w: 4px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 0 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#game-title { font-weight: 700; color: var(--text); }

/* Screens */
.screen { display: none; flex: 1; flex-direction: column; padding: 32px 0; }
.screen.active { display: flex; }

/* Home */
.hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
}

.hero h1 { font-size: 2rem; font-weight: 800; }
.hero p { color: var(--text-dim); font-size: 1rem; max-width: 260px; line-height: 1.5; }

.hero-needle-demo {
  width: 100%;
  max-width: 300px;
  margin-bottom: 8px;
}

/* Track */
.track {
  position: relative;
  width: 100%;
  height: var(--track-h);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  /* Zones: black | red | yellow | green | yellow | red | black
     Must match JS constants: GREEN=±4%, YELLOW=±9%, RED=±15% from center (50%) */
  background: linear-gradient(to right,
    #111 0% 35%,
    #7f1d1d 35% 41%,
    #78350f 41% 46%,
    #14532d 46% 54%,
    #78350f 54% 59%,
    #7f1d1d 59% 65%,
    #111 65% 100%
  );
}

/* Demo track on home screen keeps a simple single zone */
.hero-needle-demo .track {
  background: var(--surface);
}
.zone {
  position: absolute;
  top: 0;
  height: 100%;
  width: 20%;
  left: 40%;
  background: rgba(74, 222, 128, 0.2);
  border-left: 2px solid #4ade80;
  border-right: 2px solid #4ade80;
}

.needle {
  position: absolute;
  top: 0;
  height: 100%;
  width: var(--needle-w);
  background: var(--needle);
  border-radius: 2px;
  left: 0%;
  will-change: left;
  box-shadow: 0 0 10px rgba(255,255,255,0.9);
}

/* Buttons */
.btn-primary, .btn-secondary {
  display: block;
  width: 100%;
  padding: 18px;
  border: none;
  border-radius: 14px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: transform 80ms, opacity 80ms;
}
.btn-primary:active, .btn-secondary:active { transform: scale(0.97); opacity: 0.85; }

.btn-primary {
  background: var(--accent);
  color: #000;
  margin-bottom: 12px;
}
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

#already-played { text-align: center; margin-top: 8px; }
#already-played p { color: var(--text-dim); font-size: 0.9rem; margin-bottom: 12px; }

/* Game screen */
#screen-game { justify-content: center; gap: 32px; touch-action: none; }

.round-indicators {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition: background 200ms;
}
.dot.hit   { background: var(--accent); }
.dot.close { background: var(--yellow); }
.dot.nice  { background: var(--orange); }
.dot.miss  { background: var(--red); }
.dot.active { background: var(--text-dim); }

.round-label {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.track-container {
  position: relative;
  cursor: pointer;
  user-select: none;
}

.tap-hint {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* Tap feedback */
.tap-feedback {
  position: absolute;
  top: -36px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.4rem;
  font-weight: 800;
  animation: feedbackPop 600ms ease-out forwards;
}
.tap-feedback.perfect { color: var(--accent); }
.tap-feedback.great   { color: var(--yellow); }
.tap-feedback.nice    { color: var(--orange); }
.tap-feedback.miss    { color: var(--red); }

@keyframes feedbackPop {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  60%  { opacity: 1; transform: translateX(-50%) translateY(-12px) scale(1.1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-24px) scale(0.9); }
}

/* Result screen */
#screen-result { gap: 24px; }

.result-header { text-align: center; }
.result-title { font-size: 0.85rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 8px; }
.result-score-big { font-size: 4rem; font-weight: 900; line-height: 1; }
.score-max { font-size: 1.4rem; color: var(--text-dim); font-weight: 400; }
.percentile { margin-top: 8px; color: var(--accent); font-size: 1rem; font-weight: 600; }

.result-grid {
  display: flex;
  gap: 8px;
  justify-content: center;
  font-size: 2rem;
}

.result-share-text {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  font-family: monospace;
  font-size: 0.9rem;
  white-space: pre;
  color: var(--text-dim);
  line-height: 1.6;
}

.result-buttons { display: flex; flex-direction: column; gap: 12px; }

.share-confirm {
  text-align: center;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
}

/* Replay / Ad */
.replay-section { margin-top: 4px; }

.btn-watch-ad {
  display: block;
  width: 100%;
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 150ms, color 150ms;
}
.btn-watch-ad:hover, .btn-watch-ad:active { border-color: var(--accent); color: var(--accent); }

.ad-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.ad-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 24px;
  width: min(320px, 90vw);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ad-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.ad-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

.btn-close-ad {
  background: var(--border);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ad-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px 0 8px;
}

.ad-logo { font-size: 3rem; }
.ad-headline { font-size: 1.3rem; font-weight: 700; }
.ad-sub { color: var(--text-dim); font-size: 0.9rem; text-align: center; line-height: 1.5; }

.hidden { display: none !important; }

/* ── Home / game grid ────────────────────── */
.home-sub { color: var(--text-dim); font-size: 0.8rem; text-align: center; padding: 8px 0 12px; }

#screen-home { overflow-y: auto; }

.game-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding-bottom: 16px;
}

.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 10px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
  transition: border-color 80ms;
}
.game-card:active { opacity: 0.8; }
.game-card.played { border-color: var(--accent-dim); background: rgba(74,222,128,0.05); }

.game-card-emoji { font-size: 1.8rem; line-height: 1; }
.game-card-name  { font-size: 0.72rem; color: var(--text-dim); text-align: center; line-height: 1.3; }
.game-card-score { font-size: 0.85rem; font-weight: 700; color: var(--accent); margin-top: 2px; }

.btn-home {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 8px 0;
  text-align: center;
  width: 100%;
}

/* ── Game shell ───────────────────────────── */
.game-status { display: flex; flex-direction: column; align-items: center; gap: 8px; }
#game-content { flex: 1; display: flex; flex-direction: column; justify-content: center; width: 100%; }
.game-hint-area { min-height: 48px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.game-hint { color: var(--text-dim); font-size: 0.8rem; text-align: center; }

/* ── Reaction ─────────────────────────────── */
.reaction-area {
  border-radius: 16px;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 100ms;
  cursor: pointer;
}
.reaction-wait  { background: var(--surface); border: 1px solid var(--border); }
.reaction-go    { background: #16a34a; }
.reaction-early { background: #b91c1c; }
.reaction-text  { font-size: 2.2rem; font-weight: 900; pointer-events: none; }

/* ── Aim ──────────────────────────────────── */
.aim-area { position: relative; height: 260px; width: 100%; }
.aim-circle {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle, #60a5fa 0%, #2563eb 60%, #1d4ed8 100%);
  cursor: pointer;
  transition: transform 80ms, opacity 200ms;
  box-shadow: 0 0 20px rgba(59,130,246,0.4);
}
.aim-circle.aim-hit  { transform: scale(1.15) !important; opacity: 0; }
.aim-circle.aim-miss { opacity: 0.3; }

/* ── Count ────────────────────────────────── */
.count-dots { position: relative; height: 180px; width: 100%; }
.count-dot {
  position: absolute;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  transform: translate(-50%, -50%);
}
.count-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.count-btn {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 700;
  cursor: pointer;
}
.count-btn.correct { background: var(--accent-dim); border-color: var(--accent); color: #fff; }
.count-btn.wrong   { background: #7f1d1d; border-color: var(--red); }

/* ── Hold ─────────────────────────────────── */
.hold-area { display: flex; flex-direction: column; align-items: center; gap: 24px; }
.hold-btn {
  width: 130px; height: 130px;
  border-radius: 50%;
  border: 3px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: none;
  transition: border-color 100ms, background 100ms, color 100ms;
}
.hold-btn.active { background: var(--accent); border-color: var(--accent); color: #000; }
.hold-track-wrap { position: relative; width: 100%; height: 8px; }
.hold-track { width: 100%; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.hold-fill  { height: 100%; width: 0%; background: var(--accent); border-radius: 4px; }
.hold-marker {
  position: absolute;
  left: 50%;
  top: -5px;
  width: 3px; height: 18px;
  background: #fff;
  border-radius: 2px;
  transform: translateX(-50%);
}
#hold-label { color: var(--text-dim); font-size: 0.85rem; }

/* ── Memory ───────────────────────────────── */
.memory-pads { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.memory-pad {
  aspect-ratio: 1;
  border-radius: 16px;
  border: none;
  opacity: 0.45;
  cursor: pointer;
  transition: opacity 100ms, transform 80ms;
  touch-action: none;
}
.memory-pad.lit    { opacity: 1; transform: scale(1.04); }
.memory-pad:disabled { cursor: default; }
.memory-status { text-align: center; font-size: 1rem; color: var(--text-dim); margin-top: 8px; }

/* ── Stroop ───────────────────────────────── */
.stroop-word { font-size: 3rem; font-weight: 900; text-align: center; letter-spacing: 0.05em; padding: 16px 0; }
.stroop-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stroop-btn {
  height: 60px;
  border-radius: 12px;
  border: 3px solid transparent;
  cursor: pointer;
  transition: border-color 100ms, opacity 100ms;
  touch-action: none;
}
.stroop-btn.correct { border-color: #fff; }
.stroop-btn.wrong   { opacity: 0.25; }

/* ── Speed ────────────────────────────────── */
.speed-area { display: flex; flex-direction: column; align-items: center; gap: 16px; width: 100%; }
.speed-count { font-size: 6rem; font-weight: 900; line-height: 1; }
.speed-bar-wrap { width: 100%; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.speed-bar { height: 100%; width: 100%; background: var(--accent); border-radius: 4px; }
.speed-label { color: var(--text-dim); font-size: 1rem; font-weight: 600; }

/* ── Anti-tap ─────────────────────────────── */
.anti-area {
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.anti-circle {
  width: 110px; height: 110px;
  border-radius: 50%;
  transition: transform 100ms, opacity 200ms;
  box-shadow: 0 0 24px rgba(0,0,0,0.4);
}
.anti-circle.anti-correct { transform: scale(1.12); }
.anti-circle.anti-wrong   { opacity: 0.2; }

/* ── Double ───────────────────────────────── */
.double-tracks { display: flex; flex-direction: column; gap: 16px; width: 100%; }
