/* game-player.css — full-screen game overlay.
 *
 * Sizing notes that matter on real phones:
 *  - 100dvh/dvw (not 100vh) so the overlay tracks the collapsing mobile URL bar
 *    and does not end up 60px taller than the visible area.
 *  - env(safe-area-inset-*) so the close button clears the notch / home bar on
 *    iOS, and the landscape notch on the right edge.
 *  - overscroll-behavior:contain stops a swipe from pulling the page behind the
 *    game (the classic iOS rubber-band that reveals the page under the overlay).
 *  - touch-action:none on the stage: a canvas game owns every gesture, and a
 *    browser pull-to-refresh mid-game is never what the player wanted.
 */

.tg {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: none;
  flex-direction: column;
  width: 100dvw;
  height: 100dvh;
  background: #000;
  overscroll-behavior: contain;
  -webkit-terscroll-behavior: contain;
}
.tg.on { display: flex; }

/* While a game is open the page behind must not scroll. */
html.tg-open, html.tg-open body {
  overflow: hidden !important;
  position: fixed;
  width: 100%;
  height: 100%;
}

/* ── top bar ─────────────────────────────────────────────────────────── */
.tg-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 8px calc(12px + env(safe-area-inset-left));
  background: linear-gradient(#1d2433, #141a26);
  color: #fff;
  min-height: 46px;
}
.tg-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.18);
  color: #fff;
  font: 700 14px/1 system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  padding: 8px 13px;
  border-radius: 999px;
  cursor: pointer;
  flex: 0 0 auto;
  -webkit-tap-highlight-color: transparent;
}
.tg-back:hover { background: rgba(255,255,255,.2); }
.tg-back:active { transform: scale(.96); }
.tg-back-ico { font-size: 13px; line-height: 1; }
.tg-title {
  flex: 1 1 auto;
  min-width: 0;
  font: 800 15px/1.2 system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tg-rotate {
  flex: 0 0 auto;
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.16);
  color: #fff; font-size: 16px;
  border-radius: 999px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tg-rotate:active { transform: scale(.94); }

/* ── stage ───────────────────────────────────────────────────────────── */
.tg-stage {
  flex: 1 1 auto;
  min-height: 0;                 /* without this a flex child refuses to shrink */
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
  padding-bottom: env(safe-area-inset-bottom);
  padding-right: env(safe-area-inset-right);
  padding-left: env(safe-area-inset-left);
  touch-action: none;
}
.tg-frame,
.tg-stage iframe {
  display: block;
  border: 0;
  background: #000;
  transform-origin: center center;
  max-width: 100%;
}

/* ── rotate hint ─────────────────────────────────────────────────────── */
.tg-hint {
  position: absolute;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: rgba(0,0,0,.78);
  border: 1px solid rgba(255,255,255,.2);
  color: #fff;
  font: 600 13px/1.35 system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  padding: 9px 15px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  max-width: 82vw;
  text-align: center;
  z-index: 2;
}
.tg-hint.on { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  .tg-hint { transition: none; }
  .tg-back:active, .tg-rotate:active { transform: none; }
}

/* Very short viewports (phone in landscape): shrink the bar so the game gets
   as much height as possible. */
@media (max-height: 430px) {
  .tg-bar { min-height: 38px; padding-top: calc(4px + env(safe-area-inset-top)); padding-bottom: 4px; }
  .tg-back { padding: 6px 11px; font-size: 13px; }
  .tg-title { font-size: 13px; }
}