﻿/* Game stage: iframe frame, loading state, overlays and toolbar. Mobile-first. */

.g-stage {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.g-stage__hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  min-height: var(--touch-target-min);
}

.g-stage__hud-item {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.g-stage__hud-item strong {
  color: var(--color-text);
  font-size: var(--font-size-md);
  letter-spacing: 0;
  text-transform: none;
}

.g-stage__frame-wrap {
  position: relative;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 4 / 5;
  margin-inline: auto;
  overflow: hidden;
  overscroll-behavior: contain;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-stage-bg);
  box-shadow: var(--shadow-md);
}

.g-stage__frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--color-stage-bg);
}

/* Loading ---------------------------------------------------------------- */

.g-stage__loader {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-5);
  color: var(--color-stage-loader-text);
  background:
    radial-gradient(420px 260px at 50% 38%, var(--color-stage-glow), transparent 70%),
    var(--color-stage-loader-bg);
  text-align: center;
}

.g-stage:not([data-state="loading"]) .g-stage__loader {
  display: none;
}

.g-stage__loader-text {
  margin: 0;
  font-size: var(--font-size-md);
  letter-spacing: 0.02em;
}

.g-spinner {
  width: 38px;
  height: 38px;
  border: 3px solid var(--color-stage-track);
  border-top-color: var(--color-brand-500);
  border-radius: 50%;
  animation: g-spin 800ms linear infinite;
}

@keyframes g-spin {
  to {
    transform: rotate(1turn);
  }
}

/* Overlays --------------------------------------------------------------- */

.g-stage__overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: var(--space-2);
  background: var(--color-overlay-bg);
  backdrop-filter: blur(7px);
}

.g-stage__overlay[hidden] {
  display: none;
}

.g-overlay-card {
  width: min(100%, 390px);
  max-height: 80vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-4);
  border: 1px solid var(--color-overlay-border);
  border-radius: var(--radius-lg);
  color: var(--color-text);
  background: var(--color-surface);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.g-overlay-card__title {
  margin-bottom: var(--space-2);
  font-size: var(--font-size-xl);
  line-height: var(--line-height-tight);
  letter-spacing: -0.02em;
}

.g-overlay-card__text {
  margin-bottom: var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--font-size-md);
}

.g-overlay-card__score {
  margin: var(--space-4) 0 var(--space-1);
  color: var(--color-brand-600);
  font-size: clamp(2rem, 7vw, 3rem);
  font-weight: var(--font-weight-bold);
  line-height: 1;
  letter-spacing: -0.04em;
}

.g-overlay-card__best {
  margin-bottom: var(--space-5);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

.g-overlay-card__actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.g-overlay-card__actions .g-btn {
  width: 100%;
  min-height: 48px;
}

/* Toolbar ---------------------------------------------------------------- */

.g-stage__toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding-bottom: var(--safe-bottom);
}

/* Fullscreen ------------------------------------------------------------- */

.g-stage__frame-wrap:fullscreen {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
}

.g-stage__frame-wrap:fullscreen .g-stage__frame {
  width: 100%;
  height: 100%;
}

/* iOS fallback: hide the shell and let the stage fill the viewport. */
body.is-fullscreen .g-shell__header,
body.is-fullscreen .g-shell__footer,
body.is-fullscreen .g-shell__side,
body.is-fullscreen .g-ad-slot {
  display: none;
}

body.is-fullscreen .g-shell__main {
  display: block;
  max-width: none;
  padding: 0;
}

body.is-fullscreen .g-shell__stage {
  min-height: 100vh;
  min-height: 100dvh;
}

body.is-fullscreen .g-stage {
  min-height: 100vh;
  min-height: 100dvh;
  justify-content: center;
}

body.is-fullscreen .g-stage__hud,
body.is-fullscreen .g-game-head,
body.is-fullscreen .g-game-info {
  display: none;
}

body.is-fullscreen .g-stage__frame-wrap {
  width: 100vw;
  height: calc(100vh - var(--header-height));
  height: calc(100dvh - var(--header-height));
  max-width: none;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
}

body.is-fullscreen .g-stage__toolbar {
  padding-bottom: calc(var(--space-3) + var(--safe-bottom));
}

/* Larger screens: restore the 16:9 presentation. */

@media (min-width: 768px) {
  .g-stage__frame-wrap {
    max-width: var(--stage-max-width);
    aspect-ratio: 16 / 9;
    border-radius: var(--radius-lg);
  }

  .g-overlay-card {
    padding: var(--space-5);
  }

  .g-overlay-card__actions {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  .g-overlay-card__actions .g-btn {
    flex: 1 1 130px;
    width: auto;
  }
}

/* Mobile landscape: favour the stage height. */
@media (max-width: 896px) and (orientation: landscape) {
  .g-stage__frame-wrap {
    aspect-ratio: 16 / 9;
    max-width: 100%;
    max-height: calc(100vh - var(--header-height) - var(--space-6));
    max-height: calc(100dvh - var(--header-height) - var(--space-6));
  }
}
