/* RALLY — Level 57. Classic Pong, clean minimal arcade. */

@font-face { font-family: "Press Start 2P"; font-style: normal; font-weight: 400; font-display: swap; src: url("/press-start-2p.woff2") format("woff2"); }
@font-face { font-family: "Press Start 2P Fallback"; src: local("Courier New"); size-adjust: 166.64%; ascent-override: 60%; descent-override: 0%; line-gap-override: 0%; }

:root {
  --bg: #0a0a12;
  --surface: #12121d;
  --surface-2: #1a1a2a;
  --line: #28283c;
  --text: #e9e9f2;
  --dim: #9aa0b5;
  --cyan: #45f0ff;
  --magenta: #ff3d8b;
  --gold: #ffc857;
  --green: #41ff8b;
  --red: #ff5560;
  --pixel: "Press Start 2P", "Press Start 2P Fallback", "Courier New", monospace;
  --body: -apple-system, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --glow-cyan: 0 0 14px rgba(69, 240, 255, 0.35);
  --space-gutter: clamp(16px, 4vw, 48px);
}

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(69, 240, 255, 0.05), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
::selection { background: rgba(69, 240, 255, 0.3); }
[hidden] { display: none !important; }

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

.skip-link {
  position: absolute;
  left: 12px; top: -48px;
  z-index: 200;
  background: var(--cyan);
  color: #05050d;
  padding: 10px 16px;
  border-radius: 6px;
  font-family: var(--mono);
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.2s var(--ease-out);
}
.skip-link:focus-visible { transform: translateY(60px); }

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(69, 240, 255, 0.15);
}
a { color: var(--cyan); }

/* ---------- header chrome ---------- */

.site-header {
  padding: 26px var(--space-gutter) 10px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.lab-link {
  align-self: flex-start;
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--dim);
  text-decoration: none;
  padding: 6px 2px;
  transition: color 0.15s, text-shadow 0.15s;
}
.lab-link:hover { color: var(--cyan); text-shadow: var(--glow-cyan); }
.level {
  margin: 0;
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--gold);
}
.wordmark {
  margin: 6px 0 4px;
  font-family: var(--pixel);
  font-size: clamp(22px, 4.5vw, 34px);
  letter-spacing: 3px;
  color: var(--text);
  text-shadow: 0 0 16px rgba(69, 240, 255, 0.55), 3px 3px 0 var(--magenta);
}
.tagline {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--dim);
}
.cursor { color: var(--cyan); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- layout ---------- */

main {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px var(--space-gutter) 72px;
}
.game-shell { display: grid; gap: 14px; }

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
}

/* ---------- controls ---------- */

.control-panel { display: flex; flex-direction: column; gap: 12px; }
.mode-row { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; }
.mode-tabs, .control-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.btn, .chip {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.12s var(--ease-out), border-color 0.12s, box-shadow 0.12s, color 0.12s, background 0.12s;
}
.btn {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 10px 14px;
}
.btn:hover:not(:disabled), .chip:hover:not(:disabled) {
  border-color: var(--cyan);
  box-shadow: 0 0 12px rgba(69, 240, 255, 0.22);
  transform: translateY(-1px);
}
.btn:active, .chip:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary { background: var(--cyan); border-color: var(--cyan); color: #05050d; }
.btn-primary:hover:not(:disabled) { box-shadow: 0 0 18px rgba(69, 240, 255, 0.5); }

.chip {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--dim);
  font-family: var(--mono);
  font-size: 12px;
  padding: 8px 12px;
}
.chip.is-active {
  border-color: var(--cyan);
  color: var(--cyan);
  background: rgba(69, 240, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(69, 240, 255, 0.35);
}

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

.hud {
  display: grid;
  grid-template-columns: 1fr minmax(0, 1.4fr) 1fr;
  gap: 10px;
  align-items: stretch;
}
.hud-card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-content: center;
}
.score-card { align-items: center; text-align: center; }
.score-card span {
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--dim);
}
.score-card strong {
  font-family: var(--pixel);
  font-size: clamp(26px, 7vw, 40px);
  line-height: 1;
  color: var(--text);
}
.score-left { border-top: 3px solid var(--cyan); }
.score-left strong { color: var(--cyan); text-shadow: 0 0 16px rgba(69, 240, 255, 0.4); }
.score-right { border-top: 3px solid var(--magenta); }
.score-right strong { color: var(--magenta); text-shadow: 0 0 16px rgba(255, 61, 139, 0.4); }

.meta-card { align-items: center; text-align: center; gap: 8px; }
.first-to {
  font-family: var(--pixel);
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--gold);
  text-shadow: 0 0 10px rgba(255, 200, 87, 0.3);
}
.rally-line {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--dim);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: center;
  justify-content: center;
}
.rally-line b { color: var(--text); font-weight: 700; }
.rally-line .sep { color: var(--line); }

/* ---------- stage ---------- */

.stage-panel {
  position: relative;
  background: linear-gradient(180deg, var(--surface), rgba(18, 18, 29, 0.3));
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  overflow: hidden;
}
#gameCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 8 / 5;
  max-height: 64vh;
  min-height: 280px;
  border-radius: 8px;
  background: var(--bg);
  touch-action: none;
  cursor: crosshair;
  image-rendering: pixelated;
}

.overlay-panel {
  position: absolute;
  inset: 10px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  text-align: center;
  border-radius: 8px;
  background: rgba(10, 10, 18, 0.82);
  backdrop-filter: blur(2px);
  pointer-events: none;
  padding: 18px;
}
.overlay-kicker {
  margin: 0;
  font-family: var(--pixel);
  font-size: clamp(13px, 3vw, 18px);
  color: var(--gold);
  text-shadow: 0 0 14px rgba(255, 200, 87, 0.35);
}
.overlay-hint {
  margin: 0;
  max-width: 30ch;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.5px;
  line-height: 1.6;
}

.score-panel { pointer-events: auto; gap: 14px; }
.score-panel h2 {
  margin: 0;
  font-family: var(--pixel);
  font-size: clamp(15px, 4vw, 22px);
  color: var(--green);
  text-shadow: 0 0 14px rgba(65, 255, 139, 0.45);
}
.win-score {
  margin: 0;
  font-family: var(--pixel);
  font-size: clamp(13px, 3vw, 16px);
  letter-spacing: 2px;
  color: var(--text);
}
.win-best {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--dim);
}

/* ---------- on-screen touch controls ---------- */

.touch-controls {
  display: none;
  gap: 12px;
}
.touch-side {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}
.touch-controls[data-mode="cpu"] .touch-right { display: none; }
.touch-controls[data-mode="cpu"] .touch-left { flex: 1; }
.touch-label {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 1px;
  color: var(--dim);
}
.touch-left .touch-label { color: var(--cyan); }
.touch-right .touch-label { color: var(--magenta); }
.dpad { display: flex; gap: 10px; width: 100%; }
.pad-btn {
  flex: 1;
  min-height: 56px;
  font-size: 20px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  cursor: pointer;
  touch-action: none;
  transition: background 0.1s, border-color 0.1s, transform 0.08s;
}
.pad-btn:hover { border-color: var(--cyan); }
.pad-btn:active { background: rgba(69, 240, 255, 0.16); border-color: var(--cyan); transform: scale(0.97); }

/* show touch controls on coarse pointers (phones/tablets) */
@media (pointer: coarse) {
  .touch-controls { display: flex; }
  .btn, .chip { min-height: 44px; padding: 11px 14px; }
  #gameCanvas { cursor: default; }
}

/* ---------- notes / footer ---------- */

.privacy-note {
  margin: 0 auto;
  max-width: 620px;
  text-align: center;
  color: var(--dim);
  font-size: 12.5px;
}

.toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--red);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.22s var(--ease-out) both;
}
.toast-info { border-left-color: var(--cyan); }
.toast-success { border-left-color: var(--green); }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity 0.25s, transform 0.25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

.site-footer {
  border-top: 1px solid var(--line);
  padding: 22px var(--space-gutter);
  text-align: center;
  color: var(--dim);
  font-size: 13px;
}
.site-footer a { color: var(--cyan); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; text-shadow: var(--glow-cyan); }

/* ---------- responsive ---------- */

@media (max-width: 560px) {
  .wordmark { letter-spacing: 1px; }
  .control-panel { gap: 10px; }
  .mode-row { gap: 8px; }
  .control-actions { width: 100%; }
  .control-actions .btn { flex: 1; }
  .hud { grid-template-columns: 1fr 1fr; }
  .meta-card { grid-column: 1 / -1; order: -1; }
  .score-card strong { font-size: clamp(28px, 12vw, 40px); }
}

@media (max-width: 360px) {
  main { padding-left: 12px; padding-right: 12px; }
  .rally-line { font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .cursor { animation: none; }
  .overlay-panel { backdrop-filter: none; }
}
