/* ==========================================================================
   Boxing Arcade — game.css
   The shared player shell: stage, HUD, meters, overlays, touch controls.
   Loaded only on game pages.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Page layout: stage + side rail
   -------------------------------------------------------------------------- */

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: var(--sp-5);
  align-items: start;
  margin-bottom: var(--sp-6);
}

.game-rail {
  position: sticky;
  top: calc(var(--header-h) + var(--sp-3));
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

/* --------------------------------------------------------------------------
   2. Shell & stage
   -------------------------------------------------------------------------- */

.game-shell {
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  background: var(--c-surface);
  overflow: hidden;
  box-shadow: var(--sh-2);
}

/* Per-game accent, set by the game's own stylesheet via --game-accent. */
.game-shell { --accent: var(--game-accent, var(--c-accent)); }

.game-topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0.55rem var(--sp-3);
  background: var(--c-bg-alt);
  border-bottom: 1px solid var(--c-border);
}

.game-topbar__title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--fs-sm);
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.01em;
  min-width: 0;
}
.game-topbar__title .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  box-shadow: 0 0 8px var(--accent);
}
.game-topbar__title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-topbar__tools {
  margin-left: auto;
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.game-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  background: var(--c-surface-2);
  color: var(--c-muted);
  cursor: pointer;
  transition: all var(--t-fast);
}
.game-btn:hover { color: #fff; background: var(--c-surface-3); }
.game-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
.game-btn svg { width: 16px; height: 16px; pointer-events: none; }
.game-btn--wide { width: auto; padding-inline: 0.7rem; gap: 0.35rem; font-size: var(--fs-xs); font-weight: 700; }

/* --------------------------------------------------------------------------
   3. HUD
   -------------------------------------------------------------------------- */

.game-hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-4);
  padding: 0.5rem var(--sp-3);
  background: var(--c-bg-alt);
  border-bottom: 1px solid var(--c-border);
  font-size: var(--fs-xs);
}

.hud-stat {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  min-width: 0;
}
.hud-stat__label {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 800;
  color: var(--c-muted-2);
}
.hud-stat__value {
  font-family: var(--font-mono);
  font-size: var(--fs-base);
  font-weight: 700;
  color: #fff;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.hud-stat--best .hud-stat__value { color: var(--c-gold); }
.hud-stat--combo .hud-stat__value { color: var(--accent); }
.hud-stat[hidden] { display: none !important; }

/* Meters: health (red), stamina (mint), combo charge (gold) */
.hud-meter {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex: 1 1 130px;
  min-width: 110px;
  max-width: 220px;
}
.hud-meter[hidden] { display: none !important; }
.hud-meter__label {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 800;
  color: var(--c-muted-2);
  flex-shrink: 0;
}
.hud-meter__track {
  position: relative;
  flex: 1;
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--c-surface-3);
  overflow: hidden;
}
.hud-meter__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  border-radius: inherit;
  background: var(--c-accent);
  transition: width 140ms linear, background 200ms ease;
}
.hud-meter--stamina .hud-meter__fill { background: var(--c-mint); }
.hud-meter--combo   .hud-meter__fill { background: var(--c-gold); }
.hud-meter--health  .hud-meter__fill[data-low="true"] { background: var(--c-hard); }
.hud-meter--health  .hud-meter__fill[data-critical="true"] { background: var(--c-accent); }

/* Opponent health sits on its own row so it never crowds player stats. */
.hud-meter--opponent .hud-meter__fill { background: var(--c-violet); }

/* --------------------------------------------------------------------------
   4. Canvas
   -------------------------------------------------------------------------- */

.game-stage {
  position: relative;
  background:
    radial-gradient(120% 100% at 50% 0%, #161c2b, #0a0c12 70%);
  padding: 0;
  display: grid;
  place-items: center;
}

.game-canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: min(66vh, 620px);
  margin-inline: auto;
}

.game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;           /* gestures belong to the game, not the browser */
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  background: #0a0c12;
  cursor: crosshair;
}
.game-canvas:focus-visible { outline: 3px solid var(--c-gold); outline-offset: -3px; }

/* Portrait-friendly games declare a taller box. */
.game-canvas-wrap[data-ratio="4:3"]  { aspect-ratio: 4 / 3; }
.game-canvas-wrap[data-ratio="3:2"]  { aspect-ratio: 3 / 2; }
.game-canvas-wrap[data-ratio="1:1"]  { aspect-ratio: 1 / 1; max-width: 620px; }
.game-canvas-wrap[data-ratio="9:16"] { aspect-ratio: 9 / 16; max-width: 400px; }

/* --------------------------------------------------------------------------
   5. Overlays (real DOM — readable by screen readers and search engines)
   -------------------------------------------------------------------------- */

.game-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-4);
  text-align: center;
  background: rgba(8, 10, 16, 0.88);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.game-overlay[hidden] { display: none !important; }

.game-overlay__kicker {
  font-size: var(--fs-xs);
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}
.game-overlay__title {
  margin: 0;
  font-size: clamp(1.4rem, 4.5vw, 2.2rem);
  font-weight: 900;
  letter-spacing: -0.03em;
  color: #fff;
}
.game-overlay__text {
  margin: 0;
  max-width: 44ch;
  font-size: var(--fs-sm);
  color: var(--c-muted);
}
.game-overlay__stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sp-4);
  margin: var(--sp-1) 0;
}
.game-overlay__stats div { min-width: 72px; }
.game-overlay__stats b {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--fs-lg);
  color: #fff;
  font-variant-numeric: tabular-nums;
}
.game-overlay__stats span {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--c-muted-2);
  font-weight: 700;
}
.game-overlay__stats .is-record b { color: var(--c-gold); }

.game-overlay__actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); justify-content: center; }

/* Countdown numerals */
.game-countdown {
  font-family: var(--font-mono);
  font-size: clamp(3rem, 14vw, 6rem);
  font-weight: 900;
  color: #fff;
  line-height: 1;
  text-shadow: 0 0 34px var(--accent);
}

/* --------------------------------------------------------------------------
   6. Touch controls
   Shown on coarse pointers, or whenever the player turns them on.
   -------------------------------------------------------------------------- */

.touch-controls {
  display: none;
  gap: var(--sp-3);
  align-items: flex-end;
  justify-content: space-between;
  padding: var(--sp-3);
  background: var(--c-bg-alt);
  border-top: 1px solid var(--c-border);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.touch-controls[data-active="true"] { display: flex; }

@media (pointer: coarse) {
  .touch-controls:not([data-active="false"]) { display: flex; }
}

.touch-pad {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  gap: 4px;
  flex-shrink: 0;
}
.touch-pad .tbtn:nth-child(1) { grid-area: 1 / 2; }
.touch-pad .tbtn:nth-child(2) { grid-area: 2 / 1; }
.touch-pad .tbtn:nth-child(3) { grid-area: 2 / 3; }
.touch-pad .tbtn:nth-child(4) { grid-area: 3 / 2; }

.touch-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  align-items: center;
  flex: 1;
}

.tbtn {
  display: grid;
  place-items: center;
  min-width: 56px;
  min-height: 46px;
  padding: 0 0.6rem;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface-2);
  color: var(--c-text);
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  transition: background var(--t-fast), transform var(--t-fast);
}
.tbtn svg { width: 20px; height: 20px; pointer-events: none; }
.tbtn[data-pressed="true"] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  transform: scale(0.95);
}
.tbtn--primary {
  min-width: 78px;
  min-height: 56px;
  background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #000));
  color: #fff;
  border-color: transparent;
  font-size: 0.78rem;
}
.tbtn--wide { min-width: 96px; }

/* Full-width tap surface for one-button games. */
.touch-tap-zone {
  flex: 1;
  min-height: 58px;
  border: 1px dashed var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface-2);
  color: var(--c-muted);
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: 700;
  cursor: pointer;
  touch-action: none;
}
.touch-tap-zone[data-pressed="true"] { background: var(--accent); color: #fff; }

/* --------------------------------------------------------------------------
   7. Rail blocks: controls, scores, quick facts
   -------------------------------------------------------------------------- */

.rail-block {
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  background: var(--c-surface);
  padding: var(--sp-4);
}
.rail-block h2, .rail-block h3 {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--c-muted-2);
  margin: 0 0 var(--sp-3);
}

.control-list { list-style: none; margin: 0; padding: 0; font-size: var(--fs-sm); }
.control-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--c-border-soft);
  margin: 0;
}
.control-list li:last-child { border-bottom: 0; }
.control-list .keys { display: flex; gap: 3px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.control-list .action { color: var(--c-muted); }

.score-list { list-style: none; margin: 0; padding: 0; font-size: var(--fs-sm); }
.score-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--c-border-soft);
  margin: 0;
}
.score-list li:last-child { border-bottom: 0; }
.score-list .label { color: var(--c-muted); }
.score-list .value {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--c-gold);
  font-variant-numeric: tabular-nums;
}
.score-list .value[data-empty="true"] { color: var(--c-muted-2); }

.share-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.share-row .btn { flex: 1; }

/* --------------------------------------------------------------------------
   8. Fullscreen
   -------------------------------------------------------------------------- */

.game-shell:fullscreen {
  border: 0;
  border-radius: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #0a0c12;
}
.game-shell:fullscreen .game-stage { flex: 1; }
.game-shell:fullscreen .game-canvas-wrap {
  width: 100%;
  height: 100%;
  max-height: none;
  aspect-ratio: auto;
}
.game-shell:-webkit-full-screen .game-canvas-wrap { height: 100%; max-height: none; }

/* --------------------------------------------------------------------------
   9. Game page content sections
   -------------------------------------------------------------------------- */

.game-intro { margin-bottom: var(--sp-5); }
.game-intro p { color: var(--c-text-soft); font-size: var(--fs-md); max-width: 72ch; }

.game-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: var(--sp-2);
  margin-bottom: var(--sp-5);
}
.game-fact {
  padding: var(--sp-3);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface);
}
.game-fact span {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  font-weight: 800;
  color: var(--c-muted-2);
  margin-bottom: 2px;
}
.game-fact b { color: #fff; font-size: var(--fs-sm); }

.mechanic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--sp-3);
}
.mechanic {
  padding: var(--sp-4);
  border: 1px solid var(--c-border);
  border-left: 3px solid var(--accent, var(--c-accent));
  border-radius: var(--r-md);
  background: var(--c-surface);
}
.mechanic h3 { margin: 0 0 var(--sp-1); font-size: var(--fs-base); color: #fff; }
.mechanic p { margin: 0; font-size: var(--fs-sm); color: var(--c-muted); }

.tip-list { counter-reset: tip; list-style: none; padding: 0; margin: 0; }
.tip-list li {
  position: relative;
  counter-increment: tip;
  padding: 0 0 var(--sp-3) 2.6rem;
  margin: 0;
  color: var(--c-text-soft);
}
.tip-list li::before {
  content: counter(tip);
  position: absolute;
  left: 0;
  top: 0;
  width: 1.85rem;
  height: 1.85rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  color: var(--c-gold);
  font-size: var(--fs-xs);
  font-weight: 800;
}

/* Small-screen refinements live in responsive.css. */
@media (prefers-reduced-motion: reduce) {
  .hud-meter__fill { transition: none; }
}
