/*
 * pong — Glasses HUD theme. 8-bit-modern on pure #000.
 *
 * Lens rules:
 *   - Pure #000 background everywhere. Black = transparent on the lens.
 *   - Pure #fff foreground at 100% opacity for max photonic punch.
 *   - "Press Start 2P" for big-block 8-bit headers (brand, score, gameover).
 *   - "JetBrains Mono" for digits / codes (tabular nums, big and bright).
 *   - "Space Grotesk" for prose copy (subtitles, hints).
 *   - No SVGs. No external bitmaps. Spinner is CSS, digits are plain type.
 *   - 8 px safe margin (rubberbanding clips the edge).
 *   - 88 px minimum tap target on every .focusable.
 *   - Focus state = green/cyan outline + soft glow, plus an 8-bit caret arrow.
 */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&family=Press+Start+2P&family=Space+Grotesk:wght@400;500;600;700&display=swap');

:root {
  --bg: #000000;
  --fg: #ffffff;
  --dim: #6a6a78;
  --mute: #3a3a44;
  --accent: #00ff88;       /* CRT phosphor green */
  --accent-soft: rgba(0, 255, 136, 0.22);
  --accent-glow: rgba(0, 255, 136, 0.6);
  --cyan: #00d4ff;
  --cyan-soft: rgba(0, 212, 255, 0.18);
  --danger: #ff3355;
  --danger-glow: rgba(255, 51, 85, 0.55);
  --radius: 4px;
  --pixel: 'Press Start 2P', 'JetBrains Mono', monospace;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --sans: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html,
body {
  width: 600px;
  height: 600px;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-feature-settings: 'tnum' 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

#app {
  position: relative;
  width: 600px;
  height: 600px;
  padding: 8px;
}

/* Desktop: let html/body fill the viewport and center the 600×600 app
   inside. The glasses build stays fixed-size (data-device defaults to
   "glasses" if the inline script can't tag the document). */
html[data-device="desktop"],
html[data-device="desktop"] body {
  width: 100%;
  height: 100%;
}
html[data-device="desktop"] body {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Screens ---------- */

.screen {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  bottom: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 20px;
}

.screen.hidden {
  display: none;
}

.screen-title {
  font-family: var(--pixel);
  font-size: 26px;
  font-weight: 400;
  color: var(--fg);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-shadow: 0 0 12px var(--accent-glow);
}

.screen-subtitle {
  font-family: var(--sans);
  font-size: 24px;
  font-weight: 500;
  color: var(--fg);
  text-align: center;
  max-width: 540px;
  line-height: 1.35;
  letter-spacing: 0.01em;
}

/* ---------- Brand title (home) ---------- */

.brand-title {
  font-family: var(--pixel);
  font-size: 96px;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--fg);
  text-shadow:
    0 0 18px var(--accent-glow),
    4px 4px 0 rgba(0, 255, 136, 0.25);
  line-height: 1;
}

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

.brand-detail {
  font-family: var(--sans);
  font-size: 22px;
  font-weight: 500;
  color: var(--fg);
  text-align: center;
  max-width: 520px;
  line-height: 1.35;
  letter-spacing: 0.01em;
}

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

.focusable {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 88px;
  min-width: 200px;
  padding: 22px 32px;
  background: transparent;
  color: var(--fg);
  font-family: var(--pixel);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 3px solid var(--mute);
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  position: relative;
  transition:
    border-color 160ms steps(2),
    box-shadow 160ms steps(2),
    background 160ms steps(2),
    color 160ms steps(2),
    transform 160ms steps(2);
}

.focusable:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--fg);
  box-shadow:
    0 0 0 1px var(--accent) inset,
    0 0 24px var(--accent-glow);
}

/* 8-bit "caret" arrow that pops in next to the focused option */
.focusable::before {
  content: '';
  position: absolute;
  left: -18px;
  top: 50%;
  width: 0;
  height: 0;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-left: 14px solid var(--accent);
  transform: translateY(-50%) scaleX(0);
  transform-origin: right center;
  opacity: 0;
  transition: transform 120ms steps(2), opacity 120ms steps(2);
}

.focusable:focus::before {
  transform: translateY(-50%) scaleX(1);
  opacity: 1;
}

.focusable.primary {
  border-color: var(--accent);
  color: var(--accent);
}

.focusable.primary:focus {
  background: var(--accent-soft);
  color: var(--fg);
}

.focusable.danger {
  color: var(--danger);
  border-color: var(--mute);
}

.focusable.danger:focus {
  border-color: var(--danger);
  background: rgba(255, 51, 85, 0.14);
  color: var(--fg);
  box-shadow:
    0 0 0 1px var(--danger) inset,
    0 0 24px var(--danger-glow);
}

.focusable.danger:focus::before {
  border-left-color: var(--danger);
}

.focusable.small {
  min-height: 56px;
  min-width: 140px;
  padding: 12px 22px;
  font-size: 16px;
  color: var(--dim);
  border-color: var(--mute);
}

.focusable.small:focus {
  color: var(--fg);
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- Connecting — playful fragments ---------- */

#screen-connecting {
  gap: 40px;
}

.loader-bricks {
  display: flex;
  gap: 8px;
  height: 28px;
  align-items: flex-end;
}

.loader-bricks span {
  display: block;
  width: 14px;
  height: 14px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
  animation: brick-pulse 900ms steps(4) infinite;
}

.loader-bricks span:nth-child(2) { animation-delay: 150ms; }
.loader-bricks span:nth-child(3) { animation-delay: 300ms; }
.loader-bricks span:nth-child(4) { animation-delay: 450ms; }
.loader-bricks span:nth-child(5) { animation-delay: 600ms; }

@keyframes brick-pulse {
  0%, 100% { transform: translateY(0); opacity: 0.35; }
  25%      { transform: translateY(-14px); opacity: 1; }
  50%      { transform: translateY(0); opacity: 0.6; }
}

.fragment {
  font-family: var(--sans);
  font-size: 28px;
  font-weight: 600;
  color: var(--fg);
  text-align: center;
  max-width: 540px;
  line-height: 1.3;
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.01em;
}

.fragment .blinker {
  display: inline-block;
  width: 14px;
  height: 28px;
  background: var(--accent);
  margin-left: 8px;
  vertical-align: text-bottom;
  animation: blink 600ms steps(2) infinite;
  box-shadow: 0 0 8px var(--accent-glow);
}

@keyframes blink {
  0%, 50%   { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* legacy .spinner kept hidden so older markup doesn't 404 — current
   markup uses .loader-bricks instead */
.spinner { display: none; }

/* ---------- Waiting (room code) ---------- */

.pin-display {
  font-family: var(--mono);
  font-size: 168px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  text-align: center;
  text-shadow:
    0 0 24px var(--accent-glow),
    0 0 2px rgba(255, 255, 255, 0.7);
}

.pin-hint {
  font-family: var(--sans);
  font-size: 22px;
  font-weight: 500;
  color: var(--fg);
  text-align: center;
  line-height: 1.35;
  max-width: 540px;
  opacity: 0.85;
}

.pin-ttl {
  font-family: var(--mono);
  font-size: 18px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  min-height: 20px;
  letter-spacing: 0.04em;
}

/* ---------- Join (combo lock) ---------- */

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

.lock-body {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--bg);
  border-radius: var(--radius);
  border: 3px solid var(--mute);
  padding: 4px 8px;
  position: relative;
  transition: border-color 160ms steps(2), box-shadow 160ms steps(2);
}

.lock-body.lock-focused {
  border-color: var(--accent);
  box-shadow:
    0 0 0 1px var(--accent) inset,
    0 0 24px var(--accent-glow);
}

.selection-band {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 70px;
  background: var(--accent-soft);
  border-top: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  pointer-events: none;
  z-index: 1;
}

.combo-column {
  width: 92px;
  height: 220px;
  position: relative;
  overflow: hidden;
}

.combo-column.active .digit.current {
  color: var(--accent);
  text-shadow: 0 0 24px var(--accent-glow);
}

.combo-divider {
  width: 2px;
  height: 180px;
  background: var(--mute);
  flex-shrink: 0;
  margin: 0 2px;
}

.digit-window {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.digit-strip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  transition: transform 140ms steps(3);
}

.digit {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 92px;
  height: 44px;
  font-family: var(--mono);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  user-select: none;
  color: var(--fg);
  transition: color 140ms steps(3), opacity 140ms steps(3), font-size 140ms steps(3);
}

.digit.current {
  font-size: 56px;
  opacity: 1;
}
.digit.near {
  color: var(--dim);
  opacity: 0.55;
  font-size: 36px;
}
.digit.far {
  color: var(--dim);
  opacity: 0.18;
  font-size: 26px;
}

.column-indicator {
  display: flex;
  gap: 12px;
}

.column-indicator .dot {
  width: 12px;
  height: 12px;
  background: var(--mute);
  transition: background 160ms steps(2), box-shadow 160ms steps(2);
}

.column-indicator .dot.active {
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.lock-hint {
  font-family: var(--sans);
  font-size: 16px;
  font-weight: 500;
  color: var(--dim);
  letter-spacing: 0.02em;
  text-align: center;
}

.hint-arrows {
  color: var(--fg);
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 700;
}

.lock-body.shake {
  animation: shake 0.4s steps(8);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

/* ---------- Game ---------- */

.game-layout {
  justify-content: flex-start;
  gap: 10px;
  padding: 12px 16px;
}

.score-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 48px;
  font-family: var(--pixel);
  font-size: 88px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  padding: 4px 0 8px;
  letter-spacing: 0.02em;
}

.score-left {
  color: var(--accent);
  text-shadow: 0 0 18px var(--accent-glow);
}
.score-right {
  color: var(--fg);
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.4);
}
.score-sep {
  color: var(--dim);
  font-size: 56px;
}

/* Practice mode — single score at the top. */
.score-row.practice-score .score-sep,
.score-row.practice-score .score-right {
  display: none;
}
.score-row.practice-score .score-left {
  color: var(--accent);
  text-shadow: 0 0 24px var(--accent-glow);
}

.court-canvas {
  width: 552px;
  height: 368px;
  display: block;
  background: var(--bg);
  border: 2px solid var(--mute);
  border-radius: var(--radius);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.game-legend {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 552px;
  font-family: var(--mono);
  font-size: 16px;
  color: var(--dim);
  font-weight: 500;
}

.legend-side {
  font-family: var(--pixel);
  font-size: 16px;
  letter-spacing: 0.06em;
}

.legend-left {
  color: var(--accent);
}

.legend-right {
  color: var(--fg);
}

.legend-meta {
  font-variant-numeric: tabular-nums;
}

/* ---------- Practice exit prompt ---------- */

.practice-confirm {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.92);
  z-index: 10;
  padding: 24px;
}

.practice-confirm.hidden { display: none; }

.practice-confirm-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  padding: 36px 32px;
  border: 3px solid var(--accent);
  border-radius: var(--radius);
  background: var(--bg);
  box-shadow: 0 0 32px var(--accent-glow);
}

.practice-confirm-title {
  font-family: var(--pixel);
  font-size: 30px;
  color: var(--fg);
  letter-spacing: 0.06em;
  text-shadow: 0 0 12px var(--accent-glow);
  text-transform: uppercase;
  line-height: 1.1;
  text-align: center;
}

/* ---------- Game over ---------- */

.gameover-headline {
  font-family: var(--pixel);
  font-size: 64px;
  font-weight: 400;
  color: var(--accent);
  letter-spacing: 0.04em;
  text-shadow: 0 0 24px var(--accent-glow);
  text-transform: uppercase;
  text-align: center;
  line-height: 1.1;
}

.gameover-headline.lose {
  color: var(--danger);
  text-shadow: 0 0 24px var(--danger-glow);
}

/* ---------- Disconnected / Error ---------- */

.status-glyph {
  font-family: var(--pixel);
  font-size: 72px;
  line-height: 1;
  color: var(--accent);
  text-shadow: 0 0 18px var(--accent-glow);
}

.status-glyph.danger {
  color: var(--danger);
  text-shadow: 0 0 18px var(--danger-glow);
}

.status-message {
  font-family: var(--sans);
  font-size: 24px;
  font-weight: 500;
  color: var(--fg);
  text-align: center;
  max-width: 540px;
  line-height: 1.35;
}

/* ---------- Utility ---------- */

.hidden {
  display: none !important;
}

.row {
  display: flex;
  flex-direction: row;
  gap: 20px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

@media (prefers-reduced-motion: reduce) {
  .focusable,
  .digit,
  .digit-strip,
  .lock-body,
  .loader-bricks span,
  .fragment .blinker {
    transition: none;
    animation: none;
  }
}
