/* ==========================================================================
   Physics Arcade — game stage, HUD, overlays and touch controls
   Loaded only on individual game pages.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Page layout for a game page
   -------------------------------------------------------------------------- */

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

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

.aside-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4);
}
.aside-box h3 {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted-2);
  margin-bottom: var(--sp-3);
}
.aside-box ul { list-style: none; margin: 0; padding: 0; }
.aside-box li { margin-bottom: .5rem; font-size: var(--fs-sm); }
.aside-box li:last-child { margin-bottom: 0; }

.mini-game {
  display: flex;
  gap: var(--sp-3);
  align-items: center;
  padding: .45rem 0;
}
.mini-game img {
  width: 56px; height: 40px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: var(--surface-2);
}
.mini-game .mini-meta { min-width: 0; }
.mini-game strong { display: block; font-size: var(--fs-sm); color: var(--text-strong); font-weight: 650; }
.mini-game span { font-size: var(--fs-xs); color: var(--muted-2); }
.mini-game a { color: inherit; }

/* --------------------------------------------------------------------------
   2. The stage — canvas never gets covered by anything
   -------------------------------------------------------------------------- */

.game-stage {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.game-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  background: var(--bg-deep);
  touch-action: none;             /* the canvas handles its own gestures */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

.game-frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.game-frame:fullscreen,
.game-frame:-webkit-full-screen {
  aspect-ratio: auto;
  width: 100vw;
  height: 100vh;
  border-radius: 0;
}

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

.game-hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.hud-row { display: flex; flex-wrap: wrap; gap: var(--sp-4); align-items: center; }

.hud-stat { min-width: 60px; }
.hud-stat span {
  display: block;
  font-size: .62rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted-2);
  font-weight: 800;
}
.hud-stat strong {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.1rem;
  color: var(--text-strong);
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
}
.hud-stat.is-alert strong { color: var(--danger); }
.hud-stat.is-good strong  { color: var(--success); }

.hud-controls { display: flex; gap: var(--sp-2); }

.hud-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
}
.hud-btn:hover { color: var(--text-strong); border-color: var(--accent); }
.hud-btn svg { width: 17px; height: 17px; pointer-events: none; }
.hud-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

/* --------------------------------------------------------------------------
   4. Overlays — ready / paused / game over / victory / error
   -------------------------------------------------------------------------- */

.game-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--sp-3);
  padding: var(--sp-5);
  background: linear-gradient(180deg, rgba(7,10,18,.86), rgba(7,10,18,.95));
  backdrop-filter: blur(3px);
  z-index: 5;
  color: #e8ecf7;
}
.game-overlay[hidden] { display: none; }

.game-overlay h2 {
  font-size: clamp(1.4rem, 5vw, 2.1rem);
  margin: 0;
  color: #fff;
}
.game-overlay h2.win  { color: var(--success); }
.game-overlay h2.lose { color: var(--danger); }

.game-overlay p { margin: 0; color: #9aa6c4; max-width: 46ch; font-size: var(--fs-sm); }

.overlay-scores {
  display: flex;
  gap: var(--sp-5);
  margin: var(--sp-2) 0;
  flex-wrap: wrap;
  justify-content: center;
}
.overlay-score span {
  display: block;
  font-size: .62rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #6e7b9c;
  font-weight: 800;
}
.overlay-score strong {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.7rem;
  color: #22d3ee;
  font-variant-numeric: tabular-nums;
}
.overlay-score.best strong { color: #fbbf24; }

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  justify-content: center;
  margin-top: var(--sp-2);
}

.overlay-hint {
  font-size: var(--fs-xs);
  color: #6e7b9c;
}
.overlay-hint kbd {
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.18);
  color: #e8ecf7;
}

.new-best {
  display: inline-block;
  padding: .22em .7em;
  border-radius: 999px;
  background: #fbbf24;
  color: #2a1c00;
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

/* Countdown */
.countdown-num {
  font-size: clamp(3rem, 14vw, 6rem);
  font-weight: 800;
  line-height: 1;
  color: #22d3ee;
  font-family: var(--font-mono);
}

/* Loading */
.game-loading {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  align-items: center;
  color: #9aa6c4;
  font-size: var(--fs-sm);
}
.spinner {
  width: 34px; height: 34px;
  border: 3px solid rgba(154,166,196,.25);
  border-top-color: #22d3ee;
  border-radius: 50%;
  animation: pa-spin .8s linear infinite;
}
@keyframes pa-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; border-top-color: #22d3ee; }
}

/* --------------------------------------------------------------------------
   5. Touch controls — rendered outside the canvas, never over it
   -------------------------------------------------------------------------- */

.touch-controls {
  display: none;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  align-items: center;
  justify-content: space-between;
}
.touch-controls.active { display: flex; }

.touch-cluster { display: flex; gap: var(--sp-2); }

.touch-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  height: 56px;
  padding: 0 var(--sp-3);
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 800;
  font-size: var(--fs-sm);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.touch-btn:active, .touch-btn.pressed {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}
.touch-btn svg { width: 22px; height: 22px; pointer-events: none; }
.touch-btn.wide { min-width: 96px; }

/* --------------------------------------------------------------------------
   6. Controls documentation block (outside the canvas — accessibility)
   -------------------------------------------------------------------------- */

.controls-panel {
  padding: var(--sp-4);
  background: var(--surface-2);
  border-top: 1px solid var(--border);
}
.controls-panel h2 {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted-2);
  margin-bottom: var(--sp-3);
}
.controls-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: var(--sp-2) var(--sp-4);
  list-style: none;
  margin: 0;
  padding: 0;
}
.controls-list li {
  display: flex;
  gap: var(--sp-3);
  align-items: baseline;
  font-size: var(--fs-sm);
  color: var(--muted);
  margin: 0;
}
.controls-list .key { flex-shrink: 0; min-width: 84px; }

/* --------------------------------------------------------------------------
   7. Game page content blocks
   -------------------------------------------------------------------------- */

.game-content { margin-top: var(--sp-6); }
.game-content h2 { margin-top: var(--sp-6); }
.game-content h2:first-child { margin-top: 0; }
.game-content h3 { margin-top: var(--sp-5); font-size: var(--fs-md); }

.mech-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}
.mech-card {
  padding: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-3);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.mech-card h3 { font-size: var(--fs-base); margin: 0 0 var(--sp-2); }
.mech-card p { font-size: var(--fs-sm); color: var(--muted); margin: 0; }

.spec-table td:first-child { color: var(--muted); width: 38%; font-weight: 600; }

.feature-list {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px,1fr));
  gap: var(--sp-2);
}
.feature-list li {
  display: flex;
  gap: var(--sp-2);
  align-items: flex-start;
  font-size: var(--fs-sm);
  color: var(--muted);
  padding: .5rem .75rem;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  margin: 0;
}
.feature-list li::before { content: "▸"; color: var(--accent); font-weight: 800; }

.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-3);
  font-size: var(--fs-sm);
  color: var(--muted);
}
.tips-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: 8px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--accent);
  font-weight: 800;
  font-size: .8rem;
}
.tips-list li strong { color: var(--text-strong); }

.share-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
  padding: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: var(--sp-5) 0;
}
.share-row p { margin: 0; margin-right: auto; font-size: var(--fs-sm); color: var(--muted); }

/* Local score board */
.score-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px,1fr));
  gap: var(--sp-2);
}
.score-cell {
  padding: var(--sp-3);
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  text-align: center;
}
.score-cell strong {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.15rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.score-cell span { font-size: .62rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted-2); font-weight: 800; }

/* --------------------------------------------------------------------------
   8. Mobile game stage
   -------------------------------------------------------------------------- */

@media (max-width: 768px) {
  .game-frame { aspect-ratio: 4 / 3; }
  .game-hud { padding: var(--sp-2) var(--sp-3); gap: var(--sp-2); }
  .hud-row { gap: var(--sp-3); }
  .hud-stat strong { font-size: .95rem; }
  .hud-btn { width: 34px; height: 34px; }
  .hud-btn svg { width: 15px; height: 15px; }
}

@media (max-width: 560px) {
  .game-frame { aspect-ratio: 1 / 1; }
  .controls-list { grid-template-columns: 1fr; }
  .touch-btn { min-width: 52px; height: 52px; }
}
