/* ==========================================================================
   Underwater Arcade Games — Game shell, HUD and library controls
   Loaded only on pages that host a game or the game directory.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Game stage
   -------------------------------------------------------------------------- */
.game-stage {
  position: relative;
  width: 100%;
  background: #04121f;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-2);
  /* Reserved aspect ratio keeps CLS at zero while the canvas boots */
  aspect-ratio: 16 / 10;
  max-height: 78vh;
  touch-action: none; /* prevents scroll/zoom stealing touch input */
}

.game-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  /* Canvas is sized in device pixels by JS; CSS stretches it to the stage */
  background: linear-gradient(180deg, #0d3a5c 0%, #072338 55%, #03101d 100%);
  cursor: crosshair;
}

.game-stage.is-playing canvas { cursor: none; }
.game-stage.pointer-default canvas { cursor: default; }

/* --------------------------------------------------------------------------
   2. Overlays (start / pause / game over)
   -------------------------------------------------------------------------- */
.game-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  text-align: center;
  padding: var(--space-4) var(--space-3);
  background: rgba(3, 14, 26, .88);
  backdrop-filter: blur(3px);
  z-index: 3;
  overflow-y: auto;
}
.game-overlay[hidden] { display: none !important; }

.game-overlay h2 {
  margin: 0;
  font-size: clamp(1.4rem, 4vw, 2.1rem);
  color: #fff;
}
.game-overlay p {
  margin: 0;
  max-width: 48ch;
  color: var(--ink-muted);
  font-size: .95rem;
}
.game-overlay .overlay-score {
  font-family: var(--font-head);
  font-size: clamp(1.6rem, 6vw, 2.6rem);
  color: var(--glow);
  line-height: 1.1;
}
.game-overlay .overlay-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-1) var(--space-4);
  font-size: .87rem;
  color: var(--ink-muted);
}
.game-overlay .overlay-stats b { color: var(--ink); font-family: var(--font-head); }
.game-overlay .btn-row { justify-content: center; margin-top: var(--space-2); }

.overlay-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .4rem .9rem;
  font-size: .82rem;
  color: var(--ink-dim);
  max-width: 52ch;
}
.overlay-controls span { display: inline-flex; align-items: center; gap: .35rem; }

/* --------------------------------------------------------------------------
   3. HUD (drawn in DOM above the canvas, not inside it — stays crisp & readable)
   -------------------------------------------------------------------------- */
.game-hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem .9rem;
  padding: .55rem .8rem;
  background: linear-gradient(180deg, rgba(3, 14, 26, .85), rgba(3, 14, 26, 0));
  font-family: var(--font-head);
  font-size: .85rem;
  color: var(--ink);
  pointer-events: none;
  z-index: 2;
}
.hud-item {
  display: inline-flex;
  align-items: baseline;
  gap: .35rem;
  white-space: nowrap;
}
.hud-item .hud-label {
  font-family: var(--font-body);
  font-size: .68rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.hud-item .hud-value { color: #fff; font-variant-numeric: tabular-nums; }
.hud-item.is-alert .hud-value { color: var(--coral); }
.hud-spacer { margin-left: auto; }

/* Meter bars (oxygen, energy). Always paired with a numeric read-out so the
   state is never communicated by colour alone. */
.hud-meter {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}
.hud-meter .meter-track {
  width: 84px; height: 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .16);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .2);
}
.hud-meter .meter-fill {
  height: 100%;
  width: 100%;
  background: var(--glow);
  transform-origin: left center;
  transition: width .12s linear, background-color .2s ease;
}
.hud-meter.is-low .meter-fill { background: var(--coral); }

/* --------------------------------------------------------------------------
   4. Game toolbar (below the stage)
   -------------------------------------------------------------------------- */
.game-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
  padding: var(--space-2);
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
}
.game-toolbar .toolbar-scores {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem 1.1rem;
  font-size: .82rem;
  color: var(--ink-dim);
  margin-right: auto;
}
.game-toolbar .toolbar-scores b {
  color: var(--glow);
  font-family: var(--font-head);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   5. On-screen touch controls
   -------------------------------------------------------------------------- */
.touch-controls {
  display: none;
  gap: var(--space-2);
  margin-top: var(--space-2);
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
}
.touch-controls.is-visible { display: flex; }

.touch-pad {
  display: grid;
  grid-template-areas:
    ".    up    ."
    "left down right";
  gap: .4rem;
}
.touch-btn {
  width: 58px; height: 58px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--card-hi);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: 1.3rem;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.touch-btn:active, .touch-btn.is-down {
  background: var(--glow);
  color: #032027;
  border-color: var(--glow);
}
.touch-btn[data-dir="up"]    { grid-area: up; }
.touch-btn[data-dir="down"]  { grid-area: down; }
.touch-btn[data-dir="left"]  { grid-area: left; }
.touch-btn[data-dir="right"] { grid-area: right; }
.touch-btn.wide { width: auto; padding-inline: 1.4rem; }

/* --------------------------------------------------------------------------
   6. Orientation hint
   -------------------------------------------------------------------------- */
.rotate-hint {
  display: none;
  align-items: center;
  gap: .6rem;
  margin-top: var(--space-2);
  padding: .6rem .8rem;
  border: 1px solid var(--line);
  border-left: 3px solid var(--sand);
  border-radius: var(--radius-sm);
  background: rgba(255, 212, 138, .08);
  font-size: .85rem;
  color: var(--ink-muted);
}
@media (orientation: portrait) and (max-width: 820px) {
  .rotate-hint.is-enabled { display: flex; }
}

/* --------------------------------------------------------------------------
   7. Game page layout
   -------------------------------------------------------------------------- */
.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: var(--space-4);
  align-items: start;
}
.game-main { min-width: 0; }

.game-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.game-title-row h1 { margin: 0; font-size: var(--step-4); }
.game-title-row .badge { font-size: .72rem; }

.spec-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-2);
  margin: var(--space-3) 0;
}
.spec-grid div {
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: .7rem .85rem;
}
.spec-grid dt, .spec-grid .spec-label {
  font-size: .7rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: .2rem;
}
.spec-grid dd, .spec-grid .spec-value {
  margin: 0;
  font-family: var(--font-head);
  color: #fff;
  font-size: .95rem;
}

.controls-table td:first-child { width: 42%; }

.step-list { counter-reset: step; list-style: none; padding: 0; }
.step-list li {
  counter-increment: step;
  position: relative;
  padding-left: 2.6rem;
  margin-bottom: var(--space-3);
}
.step-list li::before {
  content: counter(step);
  position: absolute;
  left: 0; top: 0;
  width: 1.9rem; height: 1.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(53, 224, 208, .14);
  border: 1px solid rgba(53, 224, 208, .4);
  color: var(--glow);
  border-radius: 50%;
  font-family: var(--font-head);
  font-size: .9rem;
}

.feature-list { list-style: none; padding: 0; }
.feature-list li {
  position: relative;
  padding-left: 1.7rem;
  margin-bottom: .55rem;
}
.feature-list li::before {
  content: "";
  position: absolute;
  left: 0; top: .55em;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--glow);
  box-shadow: 0 0 0 3px rgba(53, 224, 208, .18);
}

/* --------------------------------------------------------------------------
   8. Library controls (filters / sort / search)
   -------------------------------------------------------------------------- */
.library-controls {
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-4);
  display: grid;
  gap: var(--space-3);
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}
.control-row > label {
  font-size: .74rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-dim);
  font-family: var(--font-head);
  margin-right: .2rem;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.chip {
  display: inline-block;
  padding: .38rem .85rem;
  min-height: 34px;
  border-radius: 999px;
  background: var(--midwater);
  border: 1px solid var(--line);
  color: var(--ink-muted);
  font-size: .84rem;
  font-family: var(--font-head);
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { border-color: var(--glow); color: #fff; }
.chip[aria-pressed="true"] {
  background: var(--glow);
  border-color: var(--glow);
  color: #032027;
}

.library-search {
  flex: 1;
  min-width: 190px;
}
.library-search input {
  width: 100%;
  background: var(--deep);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: .6rem .85rem;
  font: inherit;
  min-height: 44px;
}
.library-search input:focus { border-color: var(--glow); outline: none; box-shadow: var(--ring); }

.sort-select {
  background: var(--deep);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: .55rem .8rem;
  font: inherit;
  font-size: .9rem;
  min-height: 44px;
}
.sort-select:focus { border-color: var(--glow); outline: none; box-shadow: var(--ring); }

.result-count {
  font-size: .84rem;
  color: var(--ink-dim);
  margin-bottom: var(--space-2);
}
.result-count b { color: var(--ink); }

/* --------------------------------------------------------------------------
   9. Game of the day / random game strip
   -------------------------------------------------------------------------- */
.spotlight {
  display: grid;
  grid-template-columns: minmax(0, 320px) minmax(0, 1fr);
  gap: var(--space-4);
  align-items: center;
  background: linear-gradient(135deg, var(--card-hi) 0%, var(--card) 70%);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
}
.spotlight img { border-radius: var(--radius); width: 100%; }
.spotlight h3 { margin: .3rem 0 var(--space-2); font-size: var(--step-2); }
.spotlight p { color: var(--ink-muted); }

/* --------------------------------------------------------------------------
   10. Search results page
   -------------------------------------------------------------------------- */
.search-result {
  padding: var(--space-3);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--card);
  margin-bottom: var(--space-2);
}
.search-result h3 { margin: 0 0 .3rem; font-size: var(--step-1); }
.search-result h3 a { color: #fff; text-decoration: none; }
.search-result h3 a:hover { color: var(--glow-soft); }
.search-result p { margin: 0 0 .4rem; font-size: .9rem; color: var(--ink-muted); }
.search-result .result-type {
  display: inline-block;
  font-size: .68rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--glow);
  border: 1px solid rgba(53, 224, 208, .35);
  border-radius: 999px;
  padding: .15rem .55rem;
  margin-bottom: .45rem;
}
.search-result mark {
  background: rgba(255, 212, 138, .28);
  color: #fff;
  border-radius: 3px;
  padding: 0 .12em;
}
