/*
 * Game shell: layout of /game/:slug (and the admin preview) around the game iframe.
 *
 * The portal owns the layout; the game only gets the iframe viewport and adapts to it.
 * Modes:
 *   normal  - site header/footer, toolbar + iframe (+ desktop ad rail), content below;
 *   theater - body.game-theater: compact toolbar + iframe + ads fill the browser viewport,
 *             header/footer/content are hidden with CSS (kept in the DOM).
 * Theater is NOT browser fullscreen: the ad slots stay next to the game.
 * The iframe is never moved or re-created, only its wrapper size changes.
 *
 * Breakpoints:
 *   >= 1100px wide          GAME | AD RAIL (game-desktop-rail)
 *   <  1100px wide          GAME / AD BANNER below (game-mobile-bottom)
 *   landscape, <= 500px tall compact toolbar, iframe as tall as the viewport allows
 */

:root {
  --vh-stable: 100vh;   /* normal mode: does not change while the mobile URL bar hides */
  --vh-dynamic: 100vh;  /* theater: follows the visible viewport (game-shell.js sets px if dvh is missing) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}
@supports (height: 100svh) {
  :root {
    --vh-stable: 100svh;
    --vh-dynamic: 100dvh;
  }
}

.page-game {
  --rail-w: 300px;
  --ad-bottom-h: 100px;
  --toolbar-h: 52px;
  --toolbar-total: var(--toolbar-h);
  --game-top: 172px;    /* header + category nav + breadcrumbs above the toolbar (normal mode) */
  --game-bottom: 16px;
  --game-min-h: 320px;
  --game-max-h: 1200px;
  --game-reserve: 0px;  /* room kept below the game for the bottom ad (theater) */
  --game-h: clamp(var(--game-min-h),
                  calc(var(--vh-stable) - var(--game-top) - var(--toolbar-total) - var(--game-bottom)),
                  var(--game-max-h));
}

.page-game .container { max-width: 1432px; }

/* ---------- layout ---------- */

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px 16px;
  margin-top: 8px;
}

.game-main,
.game-ad-rail,
.game-ad-bottom { min-width: 0; }

/* ---------- toolbar ---------- */

.game-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  height: var(--toolbar-total);
}

.game-toolbar h1 {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 24px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.game-toolbar-home {
  display: none; /* theater only: the breadcrumbs are hidden there */
  flex: none;
  padding: 6px 4px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.game-toolbar-home:hover { color: var(--accent); }

.game-toolbar-actions {
  display: flex;
  flex: none;
  gap: 8px;
}

.game-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.game-btn:hover { border-color: var(--accent); color: var(--accent); }
.game-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.game-btn-icon { font-size: 16px; line-height: 1; }

.game-btn:focus-visible,
.game-toolbar-home:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.game-btn[aria-pressed="true"]:focus-visible { outline-color: #1c2030; }

/* ---------- iframe ---------- */

.game-frame-wrapper {
  position: relative;
  width: 100%;
  height: var(--game-h);
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}

.game-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

/* ---------- display ad slots (placeholders, not real ads) ---------- */

.game-ad-rail { display: none; }

.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 2px dashed #9aa3b8;
  border-radius: var(--radius);
  background: repeating-linear-gradient(-45deg, #eef0f5 0 12px, #e5e8f0 12px 24px);
  color: #596179;
  font: 12px/1.4 ui-monospace, Consolas, "Courier New", monospace;
  text-align: center;
}

.ad-placeholder {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(244, 245, 248, 0.9);
}
.ad-placeholder-tag { font-weight: 700; letter-spacing: 0.12em; }

.ad-slot--rail {
  width: 100%;
  height: 100%;
  max-height: 600px;
}

.ad-slot--banner {
  width: 100%;
  max-width: 728px;
  height: var(--ad-bottom-h);
  margin: 0 auto;
}

/* ---------- content below the game ---------- */

.game-content { min-width: 0; }
.game-short { margin: 16px 0 0; color: var(--muted); }
.game-info .text-block { max-width: 80ch; }

/* ---------- wide: GAME | AD RAIL ---------- */

@media (min-width: 1100px) {
  .game-layout { grid-template-columns: minmax(0, 1fr) var(--rail-w); }
  .game-ad-rail {
    display: block;
    padding-top: var(--toolbar-total); /* rail starts level with the iframe */
  }
  .game-ad-bottom { display: none; }
}

/* ---------- phones ---------- */

@media (max-width: 699px) {
  .page-game {
    --toolbar-h: 48px;
    --game-bottom: 12px;
    --game-min-h: 260px;
  }
  .game-toolbar h1 { font-size: 20px; }
  .game-btn { padding: 0 12px; }
}

@media (pointer: coarse) {
  .game-btn { height: 44px; }
}

/* Phone in landscape: very little height, the game gets all of it. */
@media (orientation: landscape) and (max-height: 500px) {
  .page-game {
    --toolbar-h: 44px;
    --game-top: 0px;     /* the iframe fits the viewport once the toolbar is scrolled to the top */
    --game-bottom: 6px;
    --game-min-h: 200px;
  }
  .game-layout { margin-top: 4px; }
  .game-toolbar h1 { font-size: 18px; }
  .game-btn { height: 36px; padding: 0 12px; }
}

/* ==================== theater mode ==================== */

body.game-theater .site-header,
body.game-theater .site-footer,
body.game-theater .breadcrumbs,
body.game-theater .preview-banner,
body.game-theater .game-content { display: none; }

body.game-theater {
  --toolbar-h: 48px;
  --toolbar-total: calc(var(--toolbar-h) + var(--safe-top));
  --theater-pad: max(8px, var(--safe-bottom));
  --game-h: max(180px, calc(var(--vh-dynamic) - var(--toolbar-total) - var(--game-reserve) - var(--theater-pad)));
}

body.game-theater main.container {
  max-width: none;
  padding-top: 0;
  padding-bottom: 0;
  padding-left: max(8px, var(--safe-left));
  padding-right: max(8px, var(--safe-right));
}

body.game-theater .game-layout {
  gap: 8px 12px;
  margin-top: 0;
  padding-bottom: var(--theater-pad);
}

body.game-theater .game-toolbar { padding-top: var(--safe-top); }
body.game-theater .game-toolbar h1 { font-size: 18px; }
body.game-theater .game-toolbar-home { display: inline-block; }

/* Single column with enough height: keep the bottom banner on screen next to the game. */
@media (max-width: 1099px) and (min-height: 600px) {
  body.game-theater { --game-reserve: calc(var(--ad-bottom-h) + 8px); }
}

/* Theater on a landscape phone: compact bar, banner may stay below the fold. */
@media (orientation: landscape) and (max-height: 500px) {
  body.game-theater { --toolbar-h: 40px; }
  body.game-theater .game-toolbar h1 { font-size: 16px; }
  body.game-theater .game-btn { height: 34px; }
}

@media (max-width: 420px) {
  .game-toolbar-home-text { display: none; }
}
