/* ==========================================================================
   Beat The Arcade — theme.css
   Design tokens, reset, typography and the CRT / glitch effect layers.
   Everything visual is driven from the custom properties below, so the whole
   palette can be retuned from this one file.
   ========================================================================== */

:root {
  /* --- surfaces ---------------------------------------------------------- */
  --bg: #05060a;
  --bg-2: #080a12;
  --surface: #0d1020;
  --surface-2: #141832;
  --surface-3: #1b2040;
  --line: #232a4a;
  --line-bright: #35407a;

  /* --- ink --------------------------------------------------------------- */
  --ink: #e9edff;
  --ink-dim: #98a2c8;
  --ink-mute: #626c93;

  /* --- neon -------------------------------------------------------------- */
  --cyan: #00f0ff;
  --magenta: #ff2bd6;
  --lime: #b6ff2b;
  --amber: #ffb020;
  --red: #ff3b5c;
  --violet: #8b5cff;

  /* per-game accent, overridden on each game page */
  --accent: var(--cyan);
  --accent-2: var(--magenta);
  --accent-rgb: 0, 240, 255;
  --accent-2-rgb: 255, 43, 214;

  /* --- type -------------------------------------------------------------- */
  --font-display: "Orbitron", "Arial Black", impact, system-ui, sans-serif;
  --font-ui: "Chakra Petch", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Share Tech Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* --- shape / rhythm ---------------------------------------------------- */
  --r-xs: 3px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-pill: 999px;
  --pad: clamp(14px, 2.2vw, 26px);
  --gap: clamp(12px, 1.8vw, 22px);
  --maxw: 1120px;

  /* --- motion ------------------------------------------------------------ */
  --dur: 180ms;
  --dur-slow: 420ms;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in: cubic-bezier(0.5, 0, 0.75, 0);

  /* --- glow -------------------------------------------------------------- */
  --glow: 0 0 6px rgba(var(--accent-rgb), 0.7), 0 0 22px rgba(var(--accent-rgb), 0.32);
  --glow-soft: 0 0 14px rgba(var(--accent-rgb), 0.18);
  --glow-2: 0 0 6px rgba(var(--accent-2-rgb), 0.65), 0 0 22px rgba(var(--accent-2-rgb), 0.3);
  --shadow: 0 12px 34px rgba(0, 0, 0, 0.55);

  --header-h: 62px;
}

/* ==========================================================================
   reset
   ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body,
h1,
h2,
h3,
h4,
p,
figure,
blockquote,
dl,
dd,
ul,
ol {
  margin: 0;
}

ul,
ol {
  padding: 0;
  list-style: none;
}

html,
body {
  min-height: 100%;
}

body {
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: clamp(15px, 0.55vw + 14px, 17px);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* animated backdrop: faint perspective grid + drifting nebula */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(60vw 60vw at 12% -10%, rgba(var(--accent-2-rgb), 0.16), transparent 62%),
    radial-gradient(55vw 55vw at 92% 8%, rgba(var(--accent-rgb), 0.14), transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 60%, #04050a 100%);
}

body::after {
  content: "";
  position: fixed;
  inset: -10% -10% -40% -10%;
  z-index: -1;
  background-image:
    linear-gradient(to right, rgba(var(--accent-rgb), 0.12) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(var(--accent-rgb), 0.12) 1px, transparent 1px);
  background-size: 58px 58px;
  transform: perspective(420px) rotateX(58deg);
  transform-origin: 50% 100%;
  mask-image: linear-gradient(to top, #000 0%, transparent 72%);
  -webkit-mask-image: linear-gradient(to top, #000 0%, transparent 72%);
  animation: grid-drift 24s linear infinite;
  opacity: 0.7;
  pointer-events: none;
}

img,
picture,
svg,
canvas {
  display: block;
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: 0;
}

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

a:hover {
  text-decoration: underline;
}

/* ==========================================================================
   typography helpers
   ========================================================================== */

h1,
h2,
h3,
.display {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.05;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(2rem, 6vw, 4.2rem);
}

h2 {
  font-size: clamp(1.3rem, 2.6vw, 1.9rem);
}

h3 {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--accent);
}

.dim {
  color: var(--ink-dim);
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   glow + glitch
   ========================================================================== */

.glow {
  color: var(--ink);
  text-shadow: var(--glow);
}

.glitch {
  position: relative;
  color: var(--ink);
  text-shadow:
    0 0 4px rgba(var(--accent-rgb), 0.55),
    0 0 26px rgba(var(--accent-rgb), 0.3);
}

.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  pointer-events: none;
  clip-path: inset(0 0 0 0);
  opacity: 0.85;
}

.glitch::before {
  color: var(--magenta);
  transform: translate(-2px, 1px);
  animation: glitch-a 5.5s steps(1, end) infinite;
}

.glitch::after {
  color: var(--cyan);
  transform: translate(2px, -1px);
  animation: glitch-b 4.2s steps(1, end) infinite;
}

/* ==========================================================================
   CRT overlay: scanlines, vignette, flicker
   ========================================================================== */

.crt {
  position: relative;
}

.crt__scan {
  position: fixed;
  inset: 0;
  z-index: 9000;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0 2px,
    rgba(0, 0, 0, 0.26) 2px 4px
  );
  opacity: 0.42;
  mix-blend-mode: multiply;
}

.crt__vig {
  position: fixed;
  inset: 0;
  z-index: 9001;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.55) 100%),
    linear-gradient(to bottom, rgba(var(--accent-rgb), 0.05), transparent 22%);
  animation: crt-flicker 5.2s steps(1, end) infinite;
}

/* ==========================================================================
   buttons
   ========================================================================== */

.btn {
  --btn-accent: var(--accent);
  --btn-rgb: var(--accent-rgb);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  min-height: 44px;
  padding: 0.6em 1.25em;
  border: 1px solid rgba(var(--btn-rgb), 0.55);
  border-radius: var(--r-sm);
  background: linear-gradient(180deg, rgba(var(--btn-rgb), 0.14), rgba(var(--btn-rgb), 0.04));
  color: var(--ink);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.86rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
    background-color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.btn:hover {
  border-color: var(--btn-accent);
  background: linear-gradient(180deg, rgba(var(--btn-rgb), 0.26), rgba(var(--btn-rgb), 0.08));
  box-shadow: 0 0 6px rgba(var(--btn-rgb), 0.6), 0 0 22px rgba(var(--btn-rgb), 0.28);
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn--solid {
  background: var(--btn-accent);
  border-color: var(--btn-accent);
  color: #04060c;
  font-weight: 700;
}

.btn--solid:hover {
  background: #fff;
  border-color: #fff;
  box-shadow: 0 0 8px rgba(var(--btn-rgb), 0.9), 0 0 34px rgba(var(--btn-rgb), 0.5);
}

.btn--ghost {
  background: transparent;
  border-color: var(--line-bright);
  color: var(--ink-dim);
}

.btn--ghost:hover {
  color: var(--ink);
  border-color: var(--accent);
  box-shadow: none;
}

.btn--icon {
  min-height: 40px;
  width: 40px;
  padding: 0;
  border-radius: var(--r-sm);
  font-size: 1rem;
  letter-spacing: 0;
}

.btn--lg {
  min-height: 52px;
  padding: 0.8em 1.8em;
  font-size: 0.95rem;
}

/* Applied to the "New Round"/"New Match" control once play has stopped: it is
   the only way forward, so it is lit up until the player uses it. */
.btn--invite {
  border-color: var(--accent);
  color: var(--ink);
  animation: pulse-glow 1.6s ease-in-out infinite;
}

.btn[aria-pressed="true"],
.btn.is-on {
  border-color: var(--accent);
  color: var(--ink);
  box-shadow: inset 0 0 14px rgba(var(--accent-rgb), 0.24);
}

/* ==========================================================================
   focus visibility (neon ring, keyboard only)
   ========================================================================== */

:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(var(--accent-rgb), 0.2);
}

/* ==========================================================================
   surfaces
   ========================================================================== */

.panel {
  position: relative;
  background: linear-gradient(180deg, rgba(20, 24, 50, 0.9), rgba(10, 12, 24, 0.92));
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}

/* corner ticks — cheap way to look "edgy" without images */
.ticks::before,
.ticks::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border: 2px solid var(--accent);
  pointer-events: none;
  opacity: 0.8;
}

.ticks::before {
  top: -1px;
  left: -1px;
  border-right: 0;
  border-bottom: 0;
}

.ticks::after {
  right: -1px;
  bottom: -1px;
  border-left: 0;
  border-top: 0;
}

.hr {
  height: 1px;
  border: 0;
  background: linear-gradient(90deg, transparent, var(--line-bright), transparent);
}

/* ==========================================================================
   keyframes
   ========================================================================== */

@keyframes grid-drift {
  from {
    background-position: 0 0, 0 0;
  }
  to {
    background-position: 0 116px, 0 116px;
  }
}

@keyframes crt-flicker {
  0%,
  96%,
  100% {
    opacity: 1;
  }
  96.5% {
    opacity: 0.86;
  }
  97% {
    opacity: 1;
  }
  97.6% {
    opacity: 0.9;
  }
}

@keyframes glitch-a {
  0%,
  86%,
  100% {
    clip-path: inset(0 0 100% 0);
  }
  87% {
    clip-path: inset(8% 0 62% 0);
  }
  90% {
    clip-path: inset(52% 0 18% 0);
  }
  93% {
    clip-path: inset(22% 0 44% 0);
  }
}

@keyframes glitch-b {
  0%,
  88%,
  100% {
    clip-path: inset(100% 0 0 0);
  }
  89% {
    clip-path: inset(60% 0 12% 0);
  }
  92% {
    clip-path: inset(14% 0 66% 0);
  }
  95% {
    clip-path: inset(38% 0 30% 0);
  }
}

@keyframes pulse-glow {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.5);
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes sweep {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(-50%);
  }
}

@keyframes shake {
  0% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(-4px, 2px);
  }
  50% {
    transform: translate(3px, -3px);
  }
  75% {
    transform: translate(-2px, -1px);
  }
  100% {
    transform: translate(0, 0);
  }
}

/* Win flourish for the tic tac toe line. Deliberately glow-and-brightness only:
   it used to scale the winning cells to 1.12, which made those squares visibly
   change size and pull the rest of the grid out of alignment for the duration. */
@keyframes pop {
  0% {
    filter: brightness(1);
  }
  40% {
    filter: brightness(1.6);
  }
  100% {
    filter: brightness(1);
  }
}

@keyframes flash-out {
  0% {
    box-shadow: inset 0 0 0 2px var(--accent), inset 0 0 60px rgba(var(--accent-rgb), 0.5);
  }
  100% {
    box-shadow: inset 0 0 0 2px transparent, inset 0 0 60px transparent;
  }
}

/* ==========================================================================
   reduced motion — kill flicker, scanline drift, glitch and marquee
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }

  body::after {
    animation: none;
    opacity: 0.35;
  }

  .crt__vig {
    animation: none;
  }

  .crt__scan {
    opacity: 0.22;
  }

  .glitch::before,
  .glitch::after {
    display: none;
  }
}
