/* ==========================================================================
   Tap or Don't Tap — DOM-only Go/No-Go reaction game
   Full-bleed color flashes via the fixed #signal-surface; the HUD and all
   layout live above it, so a flash can never shift layout.
   ========================================================================== */

:root {
  --bg: #0b0e14;
  --card: #151a24;
  --card-border: #232b3a;
  --text: #e8ecf4;
  --muted: #8b94a7;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --blue: #3b82f6;
  --primary: #6366f1;
  --primary-dark: #4f46e5;
}

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

html,
body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#game-root {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* ---------- states ---------- */

.state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
}

.state[hidden] {
  display: none;
}

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

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  font-size: 1.05rem;
  font-weight: 700;
  z-index: 30;
  pointer-events: none;
  text-shadow: 0 1px 3px rgb(0 0 0 / 0.55);
}

#hud-score {
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
}

#hud[hidden] {
  display: none;
}

/* ---------- rule-flip banner ---------- */

#swap-banner {
  position: absolute;
  top: calc(48px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: #f59e0b;
  color: #1c1917;
  font-weight: 800;
  font-size: 0.85rem;
  padding: 6px 14px;
  border-radius: 999px;
  z-index: 30;
  white-space: nowrap;
}

#swap-banner[hidden] {
  display: none;
}

/* ---------- menu / gameover card ---------- */

.menu-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 28px 22px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 18px 50px rgb(0 0 0 / 0.5);
}

.menu-card h1 {
  font-size: 1.7rem;
  line-height: 1.25;
  margin-bottom: 10px;
}

.tagline {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 16px;
}

.tagline .green {
  color: var(--green);
}

.tagline .red {
  color: var(--red);
}

.best-line {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 14px;
}

.best-line b {
  color: var(--text);
}

#sparkline {
  width: 100%;
  height: 40px;
  margin-bottom: 14px;
}

#sparkline[hidden] {
  display: none;
}

#sparkline polyline {
  fill: none;
  stroke: var(--primary);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hint {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 14px;
}

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

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 12px;
}

button:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

.btn-primary {
  display: block;
  width: 100%;
  background: var(--primary);
  color: #fff;
  font-size: 1.15rem;
  font-weight: 700;
  padding: 14px;
  transition:
    transform 0.12s ease,
    background 0.12s ease;
}

.btn-primary:active {
  transform: scale(0.97);
  background: var(--primary-dark);
}

.btn-secondary {
  display: block;
  width: 100%;
  background: #2a3245;
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 700;
  padding: 12px;
}

.btn-secondary:active {
  transform: scale(0.97);
}

.btn-ghost {
  display: block;
  width: 100%;
  background: none;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 10px;
  margin-top: 6px;
}

.btn-ghost:hover {
  color: var(--text);
}

.btn-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 4px;
}

.back-link {
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
}

.back-link:hover {
  color: var(--text);
}

/* ---------- waiting ---------- */

#state-waiting {
  background: #05070b;
}

.wait-text {
  color: #2a3245;
  font-size: 1rem;
  letter-spacing: 0.08em;
}

/* ---------- signal ---------- */

#state-signal {
  padding: 0;
}

#signal-surface {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #05070b;
}

#signal-surface.flash-green {
  background: var(--green);
}

#signal-surface.flash-red {
  background: var(--red);
}

#signal-surface.flash-yellow {
  background: var(--yellow);
}

#signal-surface.flash-blue {
  background: var(--blue);
}

#signal-word {
  font-size: clamp(3rem, 18vw, 7rem);
  font-weight: 900;
  color: rgb(255 255 255 / 0.92);
  letter-spacing: 0.05em;
  text-shadow: 0 3px 18px rgb(0 0 0 / 0.35);
}

/* White fails contrast on the bright flashes — the Stroop word switches to
   dark ink on green (the only flash that ever shows a word besides red). */
#signal-surface.flash-green #signal-word {
  color: #052e16;
  text-shadow: none;
}

#signal-word[hidden] {
  display: none;
}

/* Colorblind-safe redundant cue (suggestion 01): a shape layered on the
   flash, always matching the actual color — never the Stroop word.
   Grayscale QA note: ✓ / ✕ / △ stay distinct by silhouette alone, so no
   hue check is needed; dark ink reads on all four bright flashes. */
#signal-shape {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 0;
}

/* The author display:flex would defeat the UA [hidden] rule — restate it. */
#signal-shape[hidden] {
  display: none;
}

#signal-shape svg {
  width: 46vmin;
  height: 46vmin;
  fill: rgb(0 0 0 / 0.22);
  stroke: none;
}

#shape-cross path,
#shape-triangle {
  fill: none;
  stroke: rgb(0 0 0 / 0.28);
  stroke-width: 14;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#shape-check .cut {
  fill: none;
  stroke: rgb(255 255 255 / 0.75);
  stroke-width: 12;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#signal-shape svg[hidden] {
  display: none;
}

#signal-surface.has-word #signal-shape {
  opacity: 0.35;
}

#signal-word {
  position: relative;
  z-index: 1;
}

/* ---------- tutorial toast ---------- */

#tut-toast {
  position: absolute;
  bottom: calc(64px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 8px 16px;
  border-radius: 999px;
  z-index: 35;
  white-space: nowrap;
  cursor: pointer;
  animation: feedback-pop 0.18s ease-out;
}

#tut-toast[hidden] {
  display: none;
}

/* ---------- feedback overlay ---------- */

#feedback {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgb(5 7 11 / 0.88);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 14px 26px;
  font-size: 1.5rem;
  font-weight: 800;
  z-index: 40;
  white-space: nowrap;
  animation: feedback-pop 0.18s ease-out;
}

#feedback[hidden] {
  display: none;
}

#feedback.good {
  color: var(--green);
}

#feedback.bad {
  color: var(--red);
}

@keyframes feedback-pop {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

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

.go-score {
  font-size: 3rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.go-stats {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 8px 0 14px;
}

.go-stats b {
  color: var(--text);
}

.go-badge {
  display: inline-block;
  /* Darkened ends so white text clears WCAG AA on the whole gradient. */
  background: linear-gradient(135deg, #4f46e5, #7e22ce);
  color: #fff;
  font-weight: 800;
  font-size: 0.9rem;
  padding: 7px 16px;
  border-radius: 999px;
  margin-bottom: 14px;
}

.go-badge[hidden] {
  display: none;
}

.go-record {
  color: var(--yellow);
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 14px;
}

.go-record[hidden] {
  display: none;
}

.share-note {
  color: var(--green);
  font-size: 0.85rem;
  margin-top: 8px;
}

.share-note[hidden] {
  display: none;
}

/* ---------- pause overlay ---------- */

#pause-overlay {
  position: fixed;
  inset: 0;
  background: rgb(5 7 11 / 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

#pause-overlay[hidden] {
  display: none;
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  #feedback {
    animation: none;
  }

  .btn-primary,
  .btn-secondary {
    transition: none;
  }
}
