/* ═══════════════════════════════════════════════════════════════
   Sky Defender player page — the framed "canvas" around the game.
   Colours come from the shared theme tokens (themes.css).
   ═══════════════════════════════════════════════════════════════ */
.sd-page {
  width: min(100%, 1100px);
  margin: 0 auto;
  padding: 7rem 1.5rem 4rem;
}

.sd-head { text-align: center; margin-bottom: 1.75rem; }
.sd-title {
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0.6rem 0 0.4rem;
}
.sd-sub { max-width: 620px; margin: 0 auto; color: var(--text-muted); }

/* ── Player frame ────────────────────────────────────────────── */
.sd-player {
  display: flex;
  flex-direction: column;
  background: var(--bg-card, var(--bg));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 20px);
  overflow: hidden;
  box-shadow: 0 24px 60px -24px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--border-soft, transparent);
}

.sd-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.9rem;
  background: var(--bg-glass, var(--bg));
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
}
.sd-bar--top      { border-bottom: 1px solid var(--border); }
.sd-bar--controls { border-top: 1px solid var(--border); flex-wrap: wrap; }

.sd-dots { display: flex; gap: 6px; }
.sd-dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--text-faint); opacity: 0.7; }
.sd-bar-title { flex: 1; text-align: center; }
.sd-status { display: inline-flex; align-items: center; gap: 0.4rem; }
.sd-status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); }
.sd-status[data-state="loading"] .sd-status-dot { background: #f5a623; animation: sdPulse 1s infinite; }
.sd-status[data-state="live"]    .sd-status-dot { background: #3ecf8e; }
@keyframes sdPulse { 50% { opacity: 0.25; } }

/* ── Stage (16:9, letterboxed, game fills it) ───────────────── */
.sd-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: radial-gradient(ellipse at 50% 30%, #1a2332 0%, #0d1b2a 70%);
  overflow: hidden;
}
.sd-stage iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #87ceeb;
}

/* ── Control buttons ─────────────────────────────────────────── */
.sd-spacer { flex: 1; }
.sd-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.82rem;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.sd-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.sd-btn:hover:not(:disabled) { background: var(--border-soft); border-color: var(--accent); color: var(--accent); }
.sd-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sd-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.sd-btn--primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.sd-btn--primary:hover:not(:disabled) { background: var(--accent); color: var(--bg); filter: brightness(1.1); }

/* icon swaps */
.sd-btn .ic-off, .sd-btn .ic-exit { display: none; }
.sd-btn[aria-pressed="true"] .ic-on  { display: none; }
.sd-btn[aria-pressed="true"] .ic-off { display: block; }
.sd-player.is-fullscreen .sd-btn .ic-enter { display: none; }
.sd-player.is-fullscreen .sd-btn .ic-exit  { display: block; }

/* ── Fullscreen: ONLY the game stage goes fullscreen ─────────────
   No title bar, no control bar, no frame — the game fills the screen.
   (The player frame used to be the fullscreen element, so its bars and
   border came along and ate into the game.) */
.sd-stage:fullscreen,
.sd-stage:-webkit-full-screen,
.sd-stage.is-pseudo-fs {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  border-radius: 0;
  background: #000;
}
/* iPhone Safari has no Fullscreen API for non-video elements: fall back to a fixed layer */
.sd-stage.is-pseudo-fs { position: fixed; inset: 0; z-index: 2000; }

/* small floating exit button (visible only in fullscreen) */
.sd-fs-exit {
  display: none;
  position: absolute;
  z-index: 5;
  top: calc(10px + env(safe-area-inset-top, 0px));
  right: calc(10px + env(safe-area-inset-right, 0px));
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  opacity: 0.55;
  cursor: pointer;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.2s ease;
}
.sd-fs-exit svg { width: 18px; height: 18px; }
.sd-fs-exit:hover, .sd-fs-exit:focus-visible { opacity: 1; }
/* no on-screen exit button in real fullscreen (Esc / swipe / back exits);
   only the iPhone fallback layer keeps one, since it has no other way out */
.sd-stage.is-pseudo-fs .sd-fs-exit { display: flex; }

/* ── Info cards ──────────────────────────────────────────────── */
.sd-info {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}
.sd-card {
  padding: 1.1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card, transparent);
}
.sd-card h2 { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.6rem; color: var(--accent); }
.sd-card ul { display: grid; gap: 0.4rem; font-size: 0.85rem; color: var(--text-muted); }
.sd-card b { color: var(--text); font-weight: 500; }
.sd-keys { font-size: 0.85rem; color: var(--text-muted); }
.sd-note { margin-top: 0.6rem; font-size: 0.78rem; color: var(--text-faint, var(--text-muted)); }
.sd-note a:hover { color: var(--accent); }
kbd {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.1rem 0.45rem;
  margin: 0 0.15rem 0 0.4rem;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--text);
}

@media (max-width: 640px) {
  .sd-page { padding: 6rem 0.75rem 3rem; }
  .sd-bar-title { display: none; }
  .sd-status { margin-left: auto; }
  .sd-btn-label { display: none; }
  .sd-btn { padding: 0.55rem 0.7rem; }
  /* phones: let the stage be taller than 16:9 */
  .sd-stage { aspect-ratio: 4 / 3; }
}

.sd-status[data-state="ready"] .sd-status-dot { background: #3ecf8e; }

/* "Built with" tags */
.sd-card .project-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.sd-card .tag {
  padding: 0.2rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════════
   Mobile responsiveness — everything below only applies to phones /
   small touch screens. Desktop layout (>640px, mouse) is unchanged.
   ═══════════════════════════════════════════════════════════════ */

/* "rotate your phone" hint — hidden everywhere except portrait touch screens */
.sd-rotate-hint { display: none; }

/* real fullscreen / iPhone pseudo-fullscreen: use the *dynamic* viewport so the
   browser's collapsing address bar never crops the game or its controls */
.sd-stage.is-pseudo-fs {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  box-sizing: border-box;
}

/* phone in portrait: game is built for landscape, so nudge the player */
@media (max-width: 640px) and (orientation: portrait) and (pointer: coarse) {
  .sd-rotate-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.55rem 0.9rem;
    border-top: 1px solid var(--border);
    background: var(--bg-glass, var(--bg));
    font-family: var(--font-mono);
    font-size: 0.72rem;
    line-height: 1.35;
    text-align: center;
    color: var(--text-muted);
  }
  .sd-rotate-hint svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--accent); }
  .sd-player.is-fullscreen .sd-rotate-hint { display: none; }
}

/* phone in landscape: use the whole screen height for the game instead of a
   small 16:9 box sitting under a big heading */
@media (orientation: landscape) and (max-height: 520px) and (pointer: coarse) {
  .sd-page { padding: 4.75rem max(0.75rem, env(safe-area-inset-right, 0px)) 2rem max(0.75rem, env(safe-area-inset-left, 0px)); }
  .sd-head { display: none; }
  .sd-bar { padding: 0.4rem 0.75rem; }
  .sd-stage {
    aspect-ratio: auto;
    height: calc(100vh - 11rem);
    height: calc(100dvh - 11rem);
    min-height: 200px;
  }
  .sd-stage:fullscreen,
  .sd-stage:-webkit-full-screen,
  .sd-stage.is-pseudo-fs { height: 100vh; height: 100dvh; }
  .sd-btn { padding: 0.4rem 0.7rem; }
}

/* very narrow phones: keep the control bar on one row */
@media (max-width: 380px) {
  .sd-bar--controls { gap: 0.4rem; padding: 0.5rem 0.6rem; }
  .sd-btn { padding: 0.5rem 0.6rem; }
}
