/* ═══════════════════════════════════════════════════════════════════════════
   Pong — black and green, "classic arcade" rather than "modern dashboard".
   The court is the whole interface, so everything else stays small and quiet.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --font-display: 'Bebas Neue', 'DM Sans', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'DM Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --bg: #000000;
  --surface: #0b0b0b;
  --surface2: #131313;
  --surface3: #1c1c1c;
  --border: #232323;
  --border2: #2f2f2f;

  --text: #f5f5f5;
  --muted: #8a8a8a;

  --green: #1db954;
  --green-bright: #1ed760;
  --green-dim: #0f5c2a;
  --red: #e91429;

  /* The court and its pieces. Kept as variables so light mode can invert the
     court without touching a line of JavaScript — unlike the Tetris blocks,
     Pong draws in two colours only, so these CAN live in CSS. */
  --court-bg: #050505;
  --court-line: #1a3a25;
  --paddle: #1db954;
  --paddle-mine: #1ed760;
  --ball: #ffffff;
  --score: #1f4a2c;
}

html[data-theme='light'] {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface2: #f0f3f0;
  --surface3: #e6eae6;
  --border: #d8ded8;
  --border2: #c6cec6;

  --text: #101410;
  --muted: #5c665c;

  --court-bg: #eaf2ec;
  --court-line: #bcd6c4;
  --paddle: #12833c;
  --paddle-mine: #0d6b2f;
  --ball: #101410;
  --score: #b6cec0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 16px 40px;
}

/* ── Header ────────────────────────────────────────────────────────────── */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.home-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: .08em;
  color: var(--muted);
  text-decoration: none;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: color .15s, border-color .15s;
}
.home-btn svg { width: 14px; height: 14px; }
.home-btn:hover { color: var(--green); border-color: var(--green-dim); }

.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { color: var(--green); font-size: 20px; line-height: 1; }
.brand-text {
  font-family: var(--font-display);
  font-size: 24px;
  letter-spacing: 4px;
}

.header-right { display: flex; align-items: center; gap: 10px; }
.user-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { color: var(--green); border-color: var(--green-dim); }

/* ── Screens ───────────────────────────────────────────────────────────── */

.screen { display: none; }
.screen.active { display: block; }

.screen-title {
  font-family: var(--font-display);
  font-size: 34px;
  letter-spacing: 3px;
  margin: 26px 0 6px;
}
.screen-sub {
  max-width: 720px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.65;
  margin: 0 0 22px;
}

/* ── Menu ──────────────────────────────────────────────────────────────── */

.menu-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.mode-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
}
.mode-card:hover { border-color: var(--green-dim); }

.mode-icon { font-size: 26px; line-height: 1; }
.mode-name {
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 2px;
}
.mode-desc {
  flex: 1;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}
.mode-form { display: flex; flex-direction: column; gap: 10px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}

select,
.code-input {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 11px;
}
select:focus-visible,
.code-input:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }

.code-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  letter-spacing: .28em;
  text-align: center;
  text-transform: uppercase;
}
.join-row { display: flex; gap: 8px; }

.btn {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: 9px;
  padding: 10px 14px;
  cursor: pointer;
  transition: transform .08s, background .15s, border-color .15s;
}
.btn:hover { border-color: var(--green-dim); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }

.btn-primary {
  color: #04150a;
  background: var(--green);
  border-color: var(--green);
}
.btn-primary:hover { background: var(--green-bright); border-color: var(--green-bright); }

.btn-sm {
  font-size: 12px;
  padding: 7px 11px;
}

.record {
  margin-top: 22px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  line-height: 1.9;
}

/* ── Game ──────────────────────────────────────────────────────────────── */

.status-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 0 14px;
}
.status-mode {
  font-family: var(--font-display);
  font-size: 19px;
  letter-spacing: 2px;
  white-space: nowrap;
}
.status-note {
  flex: 1;
  min-width: 140px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}
.status-controls { display: flex; gap: 7px; }

.court-wrap {
  position: relative;
  display: flex;
  justify-content: center;
}

/*
  THE COURT CANVAS. Its size is owned by CSS and NOT by its width/height
  attributes.

  Why this matters, and why `aspect-ratio` is here: a <canvas> has no intrinsic
  ratio of its own. If you give it `height: auto` with no aspect-ratio, its
  layout height comes from its HEIGHT ATTRIBUTE — and app.js rewrites that
  attribute from the measured size every frame. That is a feedback loop, and it
  is exactly the bug that once made Tetris's preview boxes grow until they
  covered the screen. Declaring `aspect-ratio` makes the box size depend on the
  stylesheet alone, so the two can never chase each other.

  3 / 2 because the logical court is 1200x800.
*/
.court {
  display: block;
  height: min(56vh, 520px);
  width: auto;
  aspect-ratio: 3 / 2;
  background: var(--court-bg);
  border: 1px solid var(--border2);
  border-radius: 10px;
  cursor: none;
  touch-action: none; /* a drag on the court must move the paddle, not scroll */
}

@media (max-width: 900px) {
  .court {
    width: 100%;
    height: auto;
    aspect-ratio: 3 / 2;
  }
}

.serve-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 40px;
  letter-spacing: 4px;
  color: var(--green);
  pointer-events: none;
}

.hint {
  margin: 12px 0 0;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

.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;
}

/* ── Overlay ───────────────────────────────────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(0, 0, 0, .72);
  z-index: 40;
  padding: 20px;
}
.overlay.show { display: grid; }

.overlay-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 16px;
  padding: 26px 22px;
  text-align: center;
}
.overlay-icon { font-size: 38px; line-height: 1; }
.overlay-card h2 {
  font-family: var(--font-display);
  font-size: 30px;
  letter-spacing: 3px;
  margin: 10px 0 4px;
}
.overlay-card h2.win { color: var(--green); }
.overlay-card h2.lose { color: var(--red); }
.overlay-card p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  margin: 0 0 18px;
}
.overlay-actions { display: flex; gap: 9px; justify-content: center; flex-wrap: wrap; }

/* ── Settings dropdown ─────────────────────────────────────────────────── */

.settings-dropdown {
  position: fixed;
  top: 58px;
  right: max(16px, calc(50vw - 550px + 16px));
  display: none;
  flex-direction: column;
  min-width: 190px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 12px;
  overflow: hidden;
  z-index: 50;
}
.settings-dropdown.open { display: flex; }

.dropdown-item {
  font-size: 13px;
  padding: 11px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.dropdown-item:last-child { border-bottom: 0; }
.dropdown-item:hover { background: var(--surface2); color: var(--green); }

/* ── Toast ─────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 14px);
  max-width: calc(100vw - 32px);
  padding: 11px 16px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: var(--red); color: #ffd9dd; }

/* ── Courtesy ──────────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
