/* ==========================================================================
   Gimme Friction — 1980s arcade cabinet
   --------------------------------------------------------------------------
   1.  Tokens
   2.  Base, CRT & primitives
   3.  Start screen
   4.  HUD & field
   5.  Overlays & panels
   6.  Responsive & motion preferences

   One look only: a black CRT with neon phosphor colours. There is no light
   variant, because a cabinet screen is never light. Headings, numbers and
   buttons use Press Start 2P; running text uses VT323, which stays readable
   at paragraph length. Both fall back to the system monospace offline.

   The canvas reads its colours from the --field-* and --orb-* tokens.
   ========================================================================== */

/* ------------------------------------------------------------------ *
 * 1. Tokens                                                          *
 * ------------------------------------------------------------------ */

:root {
  --black:     #000000;
  --panel:     #07071a;
  --blue:      #2b2bd9;         /* cabinet chrome: borders and frames */
  --blue-dim:  #15157a;

  --text:      #e8e8ff;
  --text-dim:  #8a8ac8;

  --yellow:    #ffe600;
  --cyan:      #00e5ff;
  --magenta:   #ff2e88;
  --green:     #39ff14;

  /* Canvas palette. An orb's colour tracks its counter: cyan at three,
     yellow at two, magenta at one. */
  --field:      #05051a;
  --field-low:  #000008;       /* the turret's zone below the line */
  --field-grid: #10104a;
  --field-line: #ff2e88;
  --orb-3:      #00e5ff;
  --orb-2:      #ffe600;
  --orb-1:      #ff2e88;
  --orb-text:   #05051a;
  --shot:       #ffffff;
  --super:      #ff7a00;       /* the super shot: flies straight, pops all */
  --nuclear:    #ff1a1a;       /* the nuclear shot: bounces, pops all */
  --turret:     #1f8f0a;
  --turret-top: #39ff14;

  --font-pixel: "Press Start 2P", "Courier New", ui-monospace, monospace;
  --font-crt:   "VT323", "Courier New", ui-monospace, monospace;

  color-scheme: dark;
}

/* ------------------------------------------------------------------ *
 * 2. Base, CRT & primitives                                          *
 * ------------------------------------------------------------------ */

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

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-crt);
  font-size: 20px;
  color: var(--text);
  background: var(--black);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

/* CRT glass: scanlines plus a vignette, laid over everything and never
   taking a pointer event. */
body::after {
  content: '';
  position: fixed; inset: 0;
  z-index: 100;
  pointer-events: none;
  background:
    repeating-linear-gradient(180deg, rgba(0,0,0,0) 0 2px, rgba(0,0,0,.28) 2px 3px),
    radial-gradient(ellipse at center, rgba(0,0,0,0) 58%, rgba(0,0,0,.55) 100%);
  animation: flicker 6s steps(1) infinite;
}
@keyframes flicker {
  0%, 100% { opacity: 1; }
  47%      { opacity: .92; }
  48%      { opacity: 1; }
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

[hidden] { display: none !important; }

.app {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(10px, env(safe-area-inset-top)) 16px max(10px, env(safe-area-inset-bottom));
  overflow-y: auto;
}

.screen { width: 100%; max-width: 480px; }

/* Blinks like an attract-mode prompt: hard on/off, no fade. */
.blink { animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { visibility: hidden; } }

/* Buttons are pixel slabs with a hard offset shadow that the press eats. */
.btn {
  appearance: none;
  border: 3px solid var(--text);
  border-radius: 0;
  padding: 14px 22px;
  font-family: var(--font-pixel);
  font-size: .7rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 5px 5px 0 var(--blue);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn:active { transform: translate(5px, 5px); box-shadow: none; }
.btn:focus-visible { outline: 3px dashed var(--yellow); outline-offset: 5px; }

.btn--primary { background: var(--yellow); border-color: var(--yellow); color: var(--black); }
.btn--primary:hover { background: #fff27a; }

.btn--ghost { background: var(--black); color: var(--text); }
.btn--ghost:hover { background: var(--blue-dim); }

.btn--lg { padding: 18px 40px; font-size: .95rem; }

.icon-btn {
  appearance: none;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 3px solid var(--blue);
  border-radius: 0;
  background: var(--black);
  color: var(--cyan);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { border-color: var(--cyan); }
.icon-btn:active { transform: translate(2px, 2px); }
.icon-btn:focus-visible { outline: 3px dashed var(--yellow); outline-offset: 3px; }
.icon-btn svg {
  width: 20px; height: 20px;
  fill: currentColor; stroke: currentColor;
  shape-rendering: crispEdges;
}

#btn-sound .icon-sound-off { display: none; }
#btn-sound[aria-pressed="true"] .icon-sound-on { display: none; }
#btn-sound[aria-pressed="true"] .icon-sound-off { display: block; }
#btn-sound[aria-pressed="true"] { color: var(--magenta); }

kbd {
  display: inline-block;
  padding: 0 6px;
  border: 2px solid var(--text-dim);
  font: inherit;
  line-height: 1.1;
  color: var(--yellow);
}

/* ------------------------------------------------------------------ *
 * 3. Start screen                                                    *
 * ------------------------------------------------------------------ */

.start { text-align: center; padding: 16px 4px; }

.wordmark {
  margin: 0 0 18px;
  font-family: var(--font-pixel);
  font-weight: 400;
  line-height: 1.15;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.wordmark__top {
  font-size: clamp(1rem, 5vw, 1.35rem);
  letter-spacing: .5em;
  margin-right: -.5em;          /* balance the trailing letter-spacing */
  color: var(--cyan);
  text-shadow: 3px 3px 0 var(--blue);
}
/* Stacked hard shadows give the logo its extruded arcade-marquee depth. */
.wordmark__bottom {
  font-size: clamp(1.7rem, 9.2vw, 2.6rem);
  color: var(--yellow);
  text-shadow:
    3px 3px 0 var(--magenta),
    6px 6px 0 var(--blue),
    0 0 24px rgba(255,230,0,.35);
}

.start__tagline {
  margin: 0 auto 20px;
  font-size: 1.35rem;
  color: var(--magenta);
  letter-spacing: .06em;
  text-transform: uppercase;
}

.rules {
  list-style: none;
  margin: 0 auto 22px;
  padding: 14px 16px;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  border: 3px double var(--blue);
  background: var(--panel);
  font-size: 1.2rem;
  line-height: 1.15;
  color: var(--text);
}
.rules li { display: flex; gap: 12px; align-items: flex-start; }
.rules__dot {
  flex: 0 0 auto;
  width: 10px; height: 10px;
  margin-top: .3em;
}
.rules__dot--turret { background: var(--turret-top); }
.rules__dot--grow   { background: var(--orb-3); }
.rules__dot--hit    { background: var(--orb-2); }
.rules__dot--super  { background: var(--super); }
.rules__dot--nuclear { background: var(--nuclear); }
.rules__dot--line   {
  height: 3px; margin-top: .55em;
  background: repeating-linear-gradient(90deg, var(--field-line) 0 3px, transparent 3px 6px);
}

.start__best {
  display: inline-flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 22px;
  font-family: var(--font-pixel);
}
.start__best-label { font-size: .65rem; color: var(--magenta); }
.start__best-score { font-size: .9rem; color: var(--yellow); }

.start__actions { display: flex; flex-direction: column; align-items: center; gap: 16px; }

.press-start {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: .6rem;
  color: var(--cyan);
}

.credit {
  margin: 24px 0 4px;
  font-size: 1.05rem;
  color: var(--text-dim);
}

.back-link { margin: 0; font-size: 1.15rem; }
.back-link a { color: var(--cyan); text-decoration: none; }
.back-link a:hover { color: var(--yellow); }
.back-link a:hover::before { content: '> '; }

/* ------------------------------------------------------------------ *
 * 4. HUD & field                                                     *
 * ------------------------------------------------------------------ */

.screen--game { display: flex; flex-direction: column; align-items: center; gap: 10px; }

.hud {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.hud__stats { display: flex; align-items: flex-end; gap: 22px; }
.hud__tools { display: flex; gap: 8px; }

.stat { display: flex; flex-direction: column; gap: 6px; font-family: var(--font-pixel); }
.stat__label { font-size: .55rem; color: var(--magenta); text-transform: uppercase; }
.stat__value {
  font-size: 1rem; line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.stat__value--muted { color: var(--yellow); }

/* A pop flashes the score, in hard steps like a sprite palette swap. */
.stat--score.is-bumped .stat__value { animation: score-flash .5s steps(1); }
@keyframes score-flash {
  0%   { color: var(--yellow); }
  25%  { color: var(--cyan); }
  50%  { color: var(--yellow); }
  75%  { color: var(--cyan); }
}

.stage { display: grid; place-items: center; }

/* The canvas is a low-resolution buffer; CSS scales it up without
   smoothing, which is where the chunky pixels come from. */
.field {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 4px solid var(--blue);
  box-shadow: 0 0 0 4px var(--black), 0 0 0 8px var(--blue-dim), 0 0 40px rgba(43,43,217,.45);
  cursor: crosshair;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.field.is-shaking { animation: shake .4s steps(1); }
@keyframes shake {
  0%, 100% { transform: none; }
  20% { transform: translate(-6px, 2px); }
  40% { transform: translate(6px, -2px); }
  60% { transform: translate(-4px, 0); }
  80% { transform: translate(2px, 2px); }
}

.controls-hint {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text-dim);
  text-transform: uppercase;
}

/* ------------------------------------------------------------------ *
 * 5. Overlays & panels                                               *
 * ------------------------------------------------------------------ */

.overlay {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(0,0,0,.7);
  z-index: 50;
}

.panel {
  width: 100%;
  max-width: 380px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 26px 24px 24px;
  border: 4px solid var(--blue);
  outline: 4px solid var(--black);
  box-shadow: 0 0 0 8px var(--blue-dim), 0 0 60px rgba(43,43,217,.5);
  background: var(--panel);
  text-align: center;
  animation: panel-in .3s steps(3);
}
@keyframes panel-in {
  from { transform: scaleY(.05); }
  to   { transform: none; }
}

.panel__eyebrow {
  margin: 0 0 12px;
  font-size: 1.2rem;
  text-transform: uppercase;
  color: var(--magenta);
}
.panel__title {
  margin: 0 0 22px;
  font-family: var(--font-pixel);
  font-size: 1.3rem;
  font-weight: 400;
  line-height: 1.3;
  color: var(--yellow);
  text-transform: uppercase;
  text-shadow: 3px 3px 0 var(--magenta);
}
.panel__actions { display: flex; flex-direction: column; gap: 16px; margin-top: 24px; }

.result { margin-bottom: 20px; }
.result__score {
  font-family: var(--font-pixel);
  font-size: 2.2rem; line-height: 1;
  color: var(--cyan);
  text-shadow: 4px 4px 0 var(--blue);
}
.result__record {
  margin-top: 14px;
  font-family: var(--font-pixel);
  font-size: .55rem;
  color: var(--green);
  animation: blink .8s steps(1) infinite;
}

.result__grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 4px; margin: 0;
  padding: 12px 0;
  border-top: 2px dashed var(--blue);
  border-bottom: 2px dashed var(--blue);
}
.result__item { display: flex; flex-direction: column; gap: 8px; }
.result__item dt { font-size: 1rem; text-transform: uppercase; color: var(--text-dim); }
.result__item dd {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: .75rem;
  color: var(--text);
}

/* ------------------------------------------------------------------ *
 * 6. Responsive & motion preferences                                 *
 * ------------------------------------------------------------------ */

@media (max-height: 640px) {
  .controls-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
  body::after { animation: none; }
}
