/* ==========================================================================
   Ping Pong Arcade — Game page + canvas shell
   ========================================================================== */

/* --------------------------------------------------------------------------
   Page layout
   -------------------------------------------------------------------------- */
.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: var(--sp-6);
  align-items: start;
}

.game-aside {
  position: sticky;
  top: calc(var(--header-h) + var(--sp-4));
  display: grid;
  gap: var(--sp-4);
}

.game-hero-copy { margin-bottom: var(--sp-4); }
.game-hero-copy h1 { margin-bottom: var(--sp-2); }
.game-hero-copy .game-tagline {
  color: var(--text-muted);
  font-size: var(--fs-md);
  margin-bottom: var(--sp-3);
  max-width: 68ch;
}

/* --------------------------------------------------------------------------
   Stage
   -------------------------------------------------------------------------- */
.game-stage {
  position: relative;
  background: #060b16;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

/*
 * The playfield is a top-down table: 100 world units wide by 140 long, so the
 * canvas is portrait to match. Without that, the table renders as a narrow
 * strip with large empty margins. The width is additionally capped against the
 * viewport height so the whole game still fits on screen on a laptop.
 */
.game-stage__canvas-wrap {
  position: relative;
  width: 100%;
  max-width: min(100%, calc(70vh * 5 / 7));
  margin-inline: auto;
  aspect-ratio: 5 / 7;
  background: #060b16;
  touch-action: none;
}

#game-canvas,
.game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  cursor: crosshair;
}
.game-canvas:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }

/* HUD strip above the canvas */
.game-stage__hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-sm);
}
.hud-stat {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 62px;
}
.hud-stat__label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--text-dim);
  font-weight: 700;
}
.hud-stat__value {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.hud-stat--accent .hud-stat__value { color: var(--accent); }
.hud-stat--rally .hud-stat__value { color: var(--accent-2); }
.hud-stat--combo .hud-stat__value { color: var(--warn); }
.hud-stat.is-hidden { display: none; }

.hud-spacer { margin-left: auto; }

/* Overlays (loading / ready / paused / game over) */
.game-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: var(--sp-5) var(--sp-4);
  overflow-y: auto;
  overscroll-behavior: contain;
  text-align: center;
  background: color-mix(in srgb, #040810 82%, transparent);
  backdrop-filter: blur(4px);
  color: #eef2fa;
}
.game-overlay[hidden] { display: none; }
.game-overlay__inner { max-width: 420px; width: 100%; }
.game-overlay h2 {
  font-size: clamp(1.4rem, 4vw, 2rem);
  margin-bottom: var(--sp-2);
  color: #fff;
}
.game-overlay p { color: #c3cee3; margin-bottom: var(--sp-4); }
.game-overlay .btn { margin: var(--sp-1); }
.game-overlay__scores {
  display: flex;
  justify-content: center;
  gap: var(--sp-5);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}
.game-overlay__scores div { min-width: 84px; }
.game-overlay__scores span {
  display: block;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: #8b99b5;
  font-weight: 700;
}
.game-overlay__scores strong {
  font-family: var(--font-display);
  font-size: 1.7rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.game-overlay__controls {
  margin-top: var(--sp-4);
  padding-top: var(--sp-4);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-size: var(--fs-xs);
  color: #9fadc7;
}
.game-overlay__controls kbd {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.18);
  color: #eef2fa;
}

/* Loading spinner */
.game-spinner {
  width: 42px; height: 42px;
  margin: 0 auto var(--sp-4);
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  animation: ppa-spin 0.85s linear infinite;
}
@keyframes ppa-spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------------
   Control bar below the canvas
   -------------------------------------------------------------------------- */
.game-controls-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  align-items: center;
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.game-controls-bar .spacer { margin-left: auto; }

.mode-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  overflow: hidden;
  background: var(--surface-2);
}
.mode-switch button {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-weight: 700;
  font-size: var(--fs-xs);
  padding: 0.5rem 0.95rem;
  min-height: 38px;
  cursor: pointer;
}
.mode-switch button[aria-pressed="true"] { background: var(--accent-2); color: var(--accent-2-ink); }
.mode-switch button:not(:last-child) { border-right: 1px solid var(--border); }

/* --------------------------------------------------------------------------
   Touch controls
   -------------------------------------------------------------------------- */
.touch-controls {
  display: none;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4) var(--sp-4);
  background: var(--surface);
  border-top: 1px solid var(--border);
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  user-select: none;
  -webkit-user-select: none;
}
.touch-controls[data-layout="pad"] { grid-template-columns: 1fr 1fr 1.2fr; }
.touch-controls[data-layout="single"] { grid-template-columns: 1fr; }
.touch-controls[data-layout="versus"] { grid-template-columns: repeat(4, 1fr); }

.touch-btn {
  display: grid;
  place-items: center;
  gap: 2px;
  min-height: 62px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--t-fast), transform var(--t-fast);
}
.touch-btn:active,
.touch-btn.is-active { background: var(--accent); color: var(--accent-ink); transform: scale(0.97); }
.touch-btn--primary { background: color-mix(in srgb, var(--accent) 22%, var(--surface-2)); border-color: var(--accent); }
.touch-btn--p2 { background: color-mix(in srgb, var(--accent-2) 18%, var(--surface-2)); border-color: var(--accent-2); }
.touch-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.touch-hint, .keyboard-hint {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  padding: var(--sp-2) var(--sp-4);
  background: var(--surface);
}

/* --------------------------------------------------------------------------
   Aside widgets
   -------------------------------------------------------------------------- */
.scorebox {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
}
.scorebox h2, .scorebox h3 {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--text-dim);
  margin-bottom: var(--sp-3);
}
.scorebox dl { margin: 0; display: grid; gap: var(--sp-2); }
.scorebox dl div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-3);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--border-soft);
}
.scorebox dl div:last-child { border-bottom: 0; padding-bottom: 0; }
.scorebox dt { color: var(--text-muted); font-size: var(--fs-sm); }
.scorebox dd {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.meta-list { list-style: none; margin: 0; padding: 0; font-size: var(--fs-sm); }
.meta-list li {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--border-soft);
}
.meta-list li:last-child { border-bottom: 0; }
.meta-list dt, .meta-list .k { color: var(--text-dim); }
.meta-list .v { font-weight: 600; color: var(--text); text-align: right; }

/* --------------------------------------------------------------------------
   Game content body (below the stage)
   -------------------------------------------------------------------------- */
.game-content {
  margin-top: var(--sp-6);
  max-width: 75ch;
}
.game-content h2 {
  font-size: var(--fs-xl);
  margin-top: var(--sp-6);
  padding-top: var(--sp-5);
  border-top: 1px solid var(--border-soft);
}
.game-content h2:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.game-content h3 { font-size: var(--fs-md); margin-top: var(--sp-5); }
.game-content p, .game-content li { color: var(--text-muted); }
.game-content strong { color: var(--text); }

.controls-table td:first-child { width: 42%; }
.controls-table kbd + kbd { margin-left: 4px; }

.tips-list { counter-reset: tip; list-style: none; padding: 0; }
.tips-list li {
  counter-increment: tip;
  position: relative;
  padding-left: 2.6rem;
  margin-bottom: var(--sp-4);
  color: var(--text-muted);
}
.tips-list li::before {
  content: counter(tip);
  position: absolute;
  left: 0; top: 0;
  width: 1.85rem; height: 1.85rem;
  border-radius: 50%;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
  font-weight: 800;
  font-size: var(--fs-xs);
  font-family: var(--font-display);
}
.tips-list li strong { color: var(--text); }

/* Share row */
.share-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

/* Fullscreen adaptation */
.game-stage:fullscreen { border-radius: 0; display: flex; flex-direction: column; }
.game-stage:fullscreen .game-stage__canvas-wrap { flex: 1 1 auto; aspect-ratio: auto; }
