/* ============================================================
   Flappy Plane — Skyline Run
   Layout: fixed ad rails top/bottom, game frame fills the middle.
   ============================================================ */

:root {
  --bg: #060912;
  --bg-soft: #0b1020;
  --ink: #f5f1e6;
  --muted: #98a3c0;
  --muted-2: #6f7a98;
  --amber: #ffc857;
  --amber-2: #f0a53a;
  --red: #ff5a5f;
  --green: #5fe0a4;
  --panel: rgba(12, 18, 34, 0.86);
  --panel-line: rgba(255, 255, 255, 0.12);
  --rail-h: clamp(52px, 8.3vh, 68px);
  --side-w: 110px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --radius: 22px;
  --font: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(1200px 700px at 50% -10%, #1a1c3d 0%, transparent 60%),
    radial-gradient(900px 500px at 50% 110%, #1b1430 0%, transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

button { font: inherit; }

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
}

kbd {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.07);
  font-family: inherit;
  font-size: 0.72em;
  font-weight: 700;
  letter-spacing: 0.04em;
}

/* ------------------------------------------------------------
   Ad rails — always visible, never covered by the game
   ------------------------------------------------------------ */

.ad-rail {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 60;
  height: var(--rail-h);
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #05070f, #090d1a);
  isolation: isolate;
}

.ad-rail--top {
  top: 0;
  height: calc(var(--rail-h) + var(--safe-top));
  padding-top: var(--safe-top);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.ad-rail--bottom {
  bottom: 0;
  height: calc(var(--rail-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35);
}

.ad-rail__label {
  position: absolute;
  left: 4px;
  top: 50%;
  transform: translateY(-50%) rotate(180deg);
  writing-mode: vertical-rl;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.24);
  pointer-events: none;
  user-select: none;
}

.ad-slot {
  width: min(728px, calc(100% - 30px));
  height: calc(100% - 10px);
  min-height: 48px;
  max-height: 90px;
  border-radius: 8px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.015) 1px, transparent 1px) 0 0 / 34px 100%,
    rgba(255, 255, 255, 0.015);
}

/* Keep the rail present but quiet when no creative fills it. */
.ad-slot[data-aa-ad-status="empty"],
.ad-slot[data-aa-ad-status="error"],
.ad-slot[data-aa-ad-status="closed"],
.ad-slot[data-aa-ad-status="limit"] {
  background: rgba(255, 255, 255, 0.018);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.025);
}

/* ------------------------------------------------------------
   Stage + frame
   ------------------------------------------------------------ */

.stage {
  position: fixed;
  top: calc(var(--rail-h) + var(--safe-top));
  right: 0;
  bottom: calc(var(--rail-h) + var(--safe-bottom));
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 10px 18px;
}

.game-frame {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: 960px;
  height: 600px;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 8 / 5;
  border-radius: 24px;
  background: #0b1020;
  border: 1px solid rgba(255, 255, 255, 0.11);
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.62),
    0 0 0 1px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  container-type: size;
  container-name: frame;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.game-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 40%, transparent 55%, rgba(3, 6, 16, 0.42) 100%),
    linear-gradient(180deg, rgba(4, 7, 16, 0.28), transparent 18% 82%, rgba(4, 7, 16, 0.35));
}

/* ------------------------------------------------------------
   HUD
   ------------------------------------------------------------ */

.hud {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 5;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.game-frame[data-state="playing"] .hud,
.game-frame[data-state="paused"] .hud,
.game-frame[data-state="dying"] .hud,
.game-frame[data-state="over"] .hud {
  opacity: 1;
}

.hud__score {
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translateX(-50%);
  font-size: 2.6rem;
  font-size: clamp(2rem, 10cqw, 3.2rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.03em;
  color: #fff7e2;
  text-shadow:
    0 2px 0 rgba(0, 0, 0, 0.35),
    0 8px 24px rgba(0, 0, 0, 0.45);
  font-variant-numeric: tabular-nums;
}

.hud__actions {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.game-frame[data-state="over"] #pauseBtn {
  visibility: hidden;
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(7, 11, 23, 0.55);
  color: var(--ink);
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.15s ease, transform 0.15s ease;
}

.icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.icon-btn:active { transform: scale(0.94); }

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.icon-btn .wave,
.icon-btn .icon-muted path:last-child {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.icon-btn rect { fill: currentColor; }

.icon-muted { display: none; }

[data-sound="off"] .icon-sound { display: none; }
[data-sound="off"] .icon-muted { display: block; }

/* ------------------------------------------------------------
   Screens
   ------------------------------------------------------------ */

.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  padding: 22px;
  padding: clamp(18px, 5cqw, 30px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}

.screen.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.screen--menu {
  justify-content: space-between;
  background:
    radial-gradient(90% 55% at 50% 0%, rgba(6, 10, 24, 0.15), rgba(6, 10, 24, 0.72) 78%),
    linear-gradient(180deg, rgba(5, 8, 18, 0.1) 0%, rgba(5, 8, 18, 0.62) 100%);
}

.screen--pause,
.screen--over {
  align-items: center;
  justify-content: center;
  background: rgba(4, 7, 16, 0.58);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.menu-top {
  padding-top: 24px;
  padding-top: clamp(10px, 5cqh, 40px);
  text-align: center;
}

.eyebrow {
  display: block;
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--amber);
}

.title {
  margin: 0;
  font-size: 3.6rem;
  font-size: clamp(3rem, 16cqw, 4.6rem);
  font-weight: 900;
  line-height: 0.82;
  letter-spacing: -0.045em;
  text-transform: uppercase;
  color: #fff8e7;
  text-shadow:
    0 4px 0 rgba(9, 12, 24, 0.38),
    0 18px 44px rgba(0, 0, 0, 0.55);
}

.title span {
  background: linear-gradient(180deg, #ffe19a 10%, var(--amber) 55%, var(--amber-2) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 0 rgba(9, 12, 24, 0.35));
}

.tagline {
  margin: 16px auto 0;
  max-width: 260px;
  font-size: 13px;
  font-size: clamp(12px, 3.4cqw, 15px);
  line-height: 1.45;
  color: rgba(240, 238, 230, 0.78);
}

.menu-bottom {
  width: min(100%, 330px);
  margin: 0 auto;
  padding-bottom: clamp(4px, 2cqh, 14px);
}

.menu-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: rgba(8, 13, 27, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.menu-stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 8px;
}

.menu-stat + .menu-stat { border-left: 1px solid rgba(255, 255, 255, 0.08); }

.menu-stat span {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.menu-stat strong {
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--amber);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------
   Buttons + chips
   ------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 48px;
  padding: 13px 20px;
  border: 0;
  border-radius: 15px;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.btn--primary {
  color: #241703;
  background: linear-gradient(180deg, #ffd979, var(--amber) 45%, var(--amber-2));
  box-shadow:
    0 10px 26px rgba(240, 165, 58, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.btn--primary:hover {
  transform: translateY(-2px);
  box-shadow:
    0 14px 32px rgba(240, 165, 58, 0.36),
    inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.btn--primary:active { transform: translateY(0) scale(0.99); }

.btn--ghost {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid rgba(255, 255, 255, 0.13);
}

.btn--ghost:hover { background: rgba(255, 255, 255, 0.11); }

.btn--play {
  width: 100%;
  justify-content: space-between;
  padding-left: 24px;
  padding-right: 18px;
  min-height: 56px;
  font-size: 16px;
}

.btn--play kbd {
  border-color: rgba(36, 23, 3, 0.26);
  background: rgba(36, 23, 3, 0.12);
  color: #3d2a08;
}

.btn-row {
  display: flex;
  gap: 9px;
  margin-top: 16px;
}

.btn-row .btn { flex: 1; }

.btn-row--stack { flex-direction: column; }

.menu-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.chip {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 11px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(8, 13, 27, 0.55);
  color: rgba(240, 238, 230, 0.86);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s ease;
}

.chip:hover { background: rgba(255, 255, 255, 0.09); }

.chip > span:not(.chip__dot) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip svg { width: 17px; height: 17px; flex: none; fill: currentColor; }
.chip .wave, .chip .icon-muted path:last-child {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.chip__dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: var(--muted-2);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.04);
}

.chip__dot[data-online="true"] {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(95, 224, 164, 0.13), 0 0 12px rgba(95, 224, 164, 0.6);
}

.hint {
  margin: 12px 0 0;
  text-align: center;
  font-size: 10.5px;
  line-height: 1.5;
  color: rgba(152, 163, 192, 0.9);
}

.hint kbd { font-size: 0.9em; }

/* ------------------------------------------------------------
   Cards (pause + game over)
   ------------------------------------------------------------ */

.card {
  width: min(100%, 340px);
  max-height: 100%;
  overflow: auto;
  padding: 22px;
  padding: clamp(18px, 5cqw, 26px);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.11);
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255, 200, 87, 0.07), transparent 60%),
    var(--panel);
  box-shadow:
    0 26px 60px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.07);
  text-align: center;
  scrollbar-width: thin;
}

.screen.is-active .card {
  animation: card-in 0.28s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(12px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.card h2 {
  margin: 0;
  font-size: 30px;
  font-size: clamp(26px, 7.5cqw, 34px);
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1;
}

.card--compact .muted { margin: 10px 0 0; }

.muted { color: var(--muted); font-size: 13px; }

.card--over { padding-top: 18px; }

.final-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 7px;
  margin: 10px 0 2px;
}

.final-score span {
  font-size: 60px;
  font-size: clamp(50px, 17cqw, 78px);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -0.055em;
  background: linear-gradient(180deg, #fff6dc 5%, var(--amber) 65%, var(--amber-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-variant-numeric: tabular-nums;
}

.final-score small {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.medal {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0 12px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.035);
  text-align: left;
}

.medal__img {
  width: 42px;
  height: 42px;
  flex: none;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.35));
}

.medal__copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.medal__copy strong {
  font-size: 14px;
  font-weight: 800;
}

.medal__copy span {
  font-size: 10.5px;
  line-height: 1.35;
  color: var(--muted);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin-top: 4px;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.07);
}

.result-grid > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 4px;
  background: rgba(9, 14, 28, 0.94);
}

.result-grid span {
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.result-grid strong {
  font-size: 15px;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.new-best {
  margin: 12px 0 0;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--green);
  animation: pulse-soft 1.6s ease-in-out infinite;
}

@keyframes pulse-soft {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.sync-note {
  margin: 12px 0 0;
  font-size: 10px;
  line-height: 1.45;
  color: var(--muted-2);
}

/* ------------------------------------------------------------
   Toast
   ------------------------------------------------------------ */

.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  z-index: 30;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 200, 87, 0.28);
  background: rgba(8, 12, 24, 0.92);
  color: var(--ink);
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
  transform: translateX(-50%);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
}

/* ------------------------------------------------------------
   Dialog
   ------------------------------------------------------------ */

.dialog {
  width: min(92vw, 420px);
  max-height: 88vh;
  max-height: min(88dvh, 700px);
  overflow: auto;
  padding: 26px;
  border-radius: 26px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  background:
    radial-gradient(120% 70% at 50% 0%, rgba(255, 200, 87, 0.07), transparent 55%),
    #0e1426;
  color: var(--ink);
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.7);
  scrollbar-width: thin;
}

.dialog::backdrop {
  background: rgba(3, 5, 12, 0.7);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

.dialog__close-form {
  position: absolute;
  top: 14px;
  right: 14px;
  margin: 0;
}

.dialog__close {
  width: 32px;
  height: 32px;
  border-radius: 10px;
}

.dialog__close svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.dialog h2 {
  margin: 2px 0 0;
  font-size: 27px;
  font-weight: 900;
  letter-spacing: -0.03em;
}

.dialog__lede {
  margin: 8px 0 18px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
}

.pilot {
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 0 0 16px;
  padding: 10px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: rgba(255, 255, 255, 0.035);
}

.pilot__avatar {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #2a3357, #151b32);
  object-fit: cover;
}

.pilot__meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
}

.pilot__meta strong {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pilot__meta span {
  font-size: 10.5px;
  color: var(--muted-2);
}

.badge {
  flex: none;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 8.5px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.badge--ok {
  color: #0c2a1d;
  background: var(--green);
}

.badge--warn {
  color: #2f2103;
  background: var(--amber);
}

.badge--off {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.08);
}

.dialog__stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.07);
}

.dialog__stats > div {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 8px;
  background: rgba(9, 14, 28, 0.94);
  text-align: center;
}

.dialog__stats span {
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.dialog__stats strong {
  font-size: 17px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.cloud-note {
  margin: 14px 0 0;
  padding: 12px 14px;
  border-radius: 13px;
  border: 1px dashed rgba(255, 200, 87, 0.24);
  background: rgba(255, 200, 87, 0.055);
}

.cloud-note strong {
  display: block;
  margin-bottom: 3px;
  font-size: 12px;
  color: #ffe4a3;
}

.cloud-note p {
  margin: 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
}

.fineprint {
  margin: 14px 0 0;
  font-size: 9.5px;
  line-height: 1.5;
  color: var(--muted-2);
  text-align: center;
}

.fineprint[data-error="true"] {
  color: #ff9f9f;
}

.fineprint a { color: var(--amber); }

/* ------------------------------------------------------------
   Responsive / short frames
   ------------------------------------------------------------ */

@container frame (max-height: 590px) {
  .menu-top { padding-top: 4px; }
  .title { font-size: clamp(2.4rem, 13cqw, 3.4rem); }
  .tagline { margin-top: 10px; font-size: 11px; }
  .menu-stats { margin-bottom: 9px; padding: 7px; }
  .menu-stat strong { font-size: 20px; }
  .btn--play { min-height: 50px; }
  .hint { margin-top: 8px; }
  .medal { margin: 10px 0 8px; padding: 8px 10px; }
  .final-score { margin-top: 6px; }
  .final-score span { font-size: 46px; }
  .card { padding: 16px; }
  .card--over { padding-top: 14px; }
  .result-grid > div { padding: 7px 4px; }
  .btn-row { margin-top: 12px; }
  .sync-note { margin-top: 8px; }
}

@container frame (max-height: 480px) {
  .title { font-size: 2.1rem; }
  .tagline, .hint { display: none; }
  .menu-stats { margin-bottom: 7px; }
  .medal { display: none; }
  .card h2 { font-size: 22px; }
  .final-score span { font-size: 38px; }
  .new-best { margin-top: 8px; }
}

@media (max-width: 560px) {
  .stage { padding: 6px; gap: 0; }
  .game-frame { border-radius: 16px; }
}

/* Very short frames (landscape phones): a compact cockpit. */
@container frame (max-height: 360px) {
  .screen { padding: 8px; }

  .menu-top { padding-top: 0; }
  .menu-top .eyebrow,
  .tagline { display: none; }

  .title { font-size: 2rem; line-height: 0.86; }

  .menu-stats { margin-bottom: 6px; padding: 4px; border-radius: 10px; }
  .menu-stat { padding: 0 4px; gap: 4px; }
  .menu-stat span { font-size: 7px; letter-spacing: 0.1em; }
  .menu-stat strong { font-size: 18px; }

  .btn { min-height: 36px; padding: 8px 12px; font-size: 12px; border-radius: 10px; }
  .btn--play { min-height: 40px; padding-left: 14px; padding-right: 10px; font-size: 13px; }

  .menu-row { margin-top: 6px; gap: 5px; }
  .chip { min-height: 28px; padding: 4px 8px; font-size: 9px; border-radius: 8px; gap: 5px; }
  .chip svg { width: 13px; height: 13px; }
  .hint { display: none; }

  .card { padding: 10px; border-radius: 16px; }
  .card .eyebrow { margin-bottom: 4px; font-size: 8px; letter-spacing: 0.22em; }
  .card h2 { font-size: 20px; }
  .final-score { margin: 4px 0 0; gap: 4px; }
  .final-score span { font-size: 32px; }
  .final-score small { font-size: 7px; }
  .result-grid > div { padding: 4px 2px; }
  .result-grid span { font-size: 7px; letter-spacing: 0.1em; }
  .result-grid strong { font-size: 11px; }
  .medal { display: none; }
  .new-best { margin-top: 6px; font-size: 8px; }
  .btn-row { gap: 5px; margin-top: 8px; }
  .btn-row .btn { min-height: 34px; padding: 7px 6px; border-radius: 9px; font-size: 11px; }
  .sync-note { display: none; }
  .card--compact .muted { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}


/* ------------------------------------------------------------
   Chromebook / desktop shell
   ------------------------------------------------------------ */

.side-rail {
  display: none;
  flex: 0 0 300px;
  width: 300px;
  height: min(600px, 100%);
  flex-direction: column;
  gap: 12px;
  align-self: center;
}

.side-card,
.side-ad,
.side-help {
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: linear-gradient(180deg, rgba(18, 25, 46, 0.94), rgba(9, 13, 26, 0.94));
  border-radius: 16px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
}

.side-card {
  padding: 14px 16px;
}

.side-card .eyebrow {
  margin-bottom: 8px;
}

.side-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.side-stats > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-stats span {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.side-stats strong {
  font-size: 26px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--amber);
  font-variant-numeric: tabular-nums;
}

.side-sync {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 10px;
  color: var(--muted);
}

.side-sync i {
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: 50%;
  background: var(--muted-2);
}

.side-sync i[data-online="true"] {
  background: var(--green);
  box-shadow: 0 0 10px rgba(95, 224, 164, 0.7);
}

.side-ad {
  padding: 10px;
  flex: 1;
  min-height: 272px;
  display: flex;
  flex-direction: column;
}

.side-label {
  display: block;
  margin-bottom: 6px;
  font-size: 7.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.28);
}

.ad-slot--side {
  width: 100%;
  height: 250px;
  min-height: 250px;
  max-height: none;
  flex: none;
  border-radius: 8px;
}

.side-help {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  padding: 12px 14px;
  font-size: 10px;
  color: var(--muted);
}

.side-help strong {
  width: 100%;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.side-help kbd {
  font-size: 8px;
}

@media (min-width: 1180px) and (min-height: 620px) {
  .side-rail { display: flex; }
}

/* Landscape game canvas: put the menu in the left half, plane in the right. */
@container frame (min-aspect-ratio: 1 / 1) {
  .screen--menu {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 0.85fr);
    grid-template-rows: 1fr auto;
    align-items: start;
    padding: 24px 34px;
    background:
      linear-gradient(90deg, rgba(5, 8, 18, 0.72) 0%, rgba(5, 8, 18, 0.38) 52%, rgba(5, 8, 18, 0.08) 100%),
      linear-gradient(180deg, rgba(5, 8, 18, 0.08), rgba(5, 8, 18, 0.38));
  }

  .screen--menu .menu-top {
    grid-column: 1;
    grid-row: 1;
    padding-top: 8px;
    text-align: left;
  }

  .screen--menu .title {
    font-size: 62px;
    font-size: clamp(3.4rem, 7.4cqw, 6rem);
    line-height: 0.82;
  }

  .screen--menu .tagline {
    margin: 16px 0 0;
    max-width: 330px;
    text-align: left;
  }

  .screen--menu .menu-bottom {
    grid-column: 1;
    grid-row: 2;
    align-self: end;
    width: min(100%, 360px);
    margin: 0;
    padding-bottom: 0;
  }

  .screen--menu .menu-stats {
    margin-bottom: 10px;
  }

  .screen--menu .hint {
    text-align: left;
  }

  .card {
    width: min(100%, 430px);
  }
}

/* Keep the old portrait menu usable when the frame is short. */
@container frame (max-height: 360px) and (max-aspect-ratio: 1 / 1) {
  .screen--menu { display: flex; }
}


/* ------------------------------------------------------------
   Fullscreen four-sided ad shell
   Top + bottom banners span the viewport; left + right side ads
   frame the game. The game fills every pixel in between.
   ------------------------------------------------------------ */

body {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr) var(--side-w);
  grid-template-rows: var(--rail-h) minmax(0, 1fr) var(--rail-h);
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

.ad-rail {
  position: relative;
  inset: auto;
  width: auto;
  height: auto;
  padding: 0;
  z-index: 60;
}

.ad-rail--top {
  grid-area: 1 / 1 / 2 / 4;
  height: var(--rail-h);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.ad-rail--bottom {
  grid-area: 3 / 1 / 4 / 4;
  height: var(--rail-h);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35);
}

.ad-rail--left {
  grid-area: 2 / 1 / 3 / 2;
  width: var(--side-w);
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 8px 0 24px rgba(0, 0, 0, 0.3);
}

.ad-rail--right {
  grid-area: 2 / 3 / 3 / 4;
  width: var(--side-w);
  flex-direction: column;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.3);
}

.ad-rail--top .ad-rail__label,
.ad-rail--bottom .ad-rail__label {
  writing-mode: horizontal-tb;
  transform: none;
  left: 10px;
  top: 4px;
}

.ad-rail--left .ad-rail__label,
.ad-rail--right .ad-rail__label {
  writing-mode: vertical-rl;
  transform: translateY(-50%) rotate(180deg);
  left: 4px;
  top: 50%;
}

.ad-rail--top .ad-slot,
.ad-rail--bottom .ad-slot {
  width: min(728px, calc(100% - 24px));
  height: calc(100% - 8px);
  min-height: 0;
  max-height: 64px;
}

.ad-rail--left .ad-slot,
.ad-rail--right .ad-slot {
  width: 152px;
  height: 600px;
  max-height: calc(100% - 20px);
  min-height: 120px;
  flex: none;
}

.stage {
  position: relative;
  inset: auto;
  grid-area: 2 / 2 / 3 / 3;
  display: block;
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

.game-frame {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.game-frame #gameCanvas {
  width: 100%;
  height: 100%;
}

@media (max-width: 1179px) {
  body {
    grid-template-columns: 0 minmax(0, 1fr) 0;
  }

  .ad-rail--left,
  .ad-rail--right {
    display: none;
  }

  .stage {
    display: grid;
    place-items: center;
    padding: 8px;
  }

  .game-frame {
    width: 100%;
    height: auto;
    max-height: 100%;
    aspect-ratio: 8 / 5;
    border-radius: 18px;
    box-shadow:
      0 30px 80px rgba(0, 0, 0, 0.55),
      inset 0 1px 0 rgba(255, 255, 255, 0.06);
  }
}

@media (max-width: 600px) {
  #menuFullscreenBtn { display: none; }
  .menu-row { flex-wrap: wrap; }
  .menu-row .chip { flex: 1 1 130px; }
}


/* ------------------------------------------------------------
   Ads collapse when empty; game takes the rest of the viewport.
   ------------------------------------------------------------ */

body {
  --top-h: 0px;
  --bottom-h: 0px;
  --left-w: 0px;
  --right-w: 0px;
  grid-template-rows: var(--top-h) minmax(0, 1fr) var(--bottom-h);
  grid-template-columns: var(--left-w) minmax(0, 1fr) var(--right-w);
}

body.ads-top { --top-h: var(--rail-h); }
body.ads-bottom { --bottom-h: var(--rail-h); }
body.ads-sides { --left-w: var(--side-w); --right-w: var(--side-w); }

body:not(.ads-top) .ad-rail--top,
body:not(.ads-bottom) .ad-rail--bottom,
body:not(.ads-sides) .ad-rail--left,
body:not(.ads-sides) .ad-rail--right {
  display: none;
}

.ad-rail {
  background: transparent;
  border: 0;
  box-shadow: none;
}

.ad-rail--left .ad-slot,
.ad-rail--right .ad-slot {
  width: 100px;
  height: 250px;
  min-height: 250px;
  max-height: 250px;
}

.ad-slot {
  background: transparent;
}

.ad-slot[data-aa-ad-status="empty"],
.ad-slot[data-aa-ad-status="error"],
.ad-slot[data-aa-ad-status="closed"],
.ad-slot[data-aa-ad-status="limit"] {
  background: transparent;
  box-shadow: none;
}

@media (max-width: 1179px) {
  body {
    grid-template-rows: var(--top-h) minmax(0, 1fr) var(--bottom-h);
    grid-template-columns: 0 minmax(0, 1fr) 0;
  }
}


/* ------------------------------------------------------------
   Final shell: full-viewport canvas, ads as overlays.
   The game world is resized to the viewport aspect in game.js,
   so the canvas is never stretched.
   ------------------------------------------------------------ */

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

body {
  display: block;
  height: 100dvh;
  padding: 0;
  margin: 0;
}

.stage {
  position: fixed;
  inset: 0;
  display: block;
  padding: 0;
  overflow: hidden;
}

.game-frame {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  isolation: auto;
}

.game-frame #gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.ad-rail {
  position: fixed;
  z-index: 20;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.ad-rail--top {
  top: 0;
  left: 0;
  right: 0;
  width: auto;
  height: var(--rail-h);
}

.ad-rail--bottom {
  bottom: 0;
  left: 0;
  right: 0;
  width: auto;
  height: var(--rail-h);
}

.ad-rail--left {
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--side-w);
  height: auto;
  flex-direction: column;
}

.ad-rail--right {
  top: 0;
  bottom: 0;
  right: 0;
  width: var(--side-w);
  height: auto;
  flex-direction: column;
}

body:not(.ads-top) .ad-rail--top,
body:not(.ads-bottom) .ad-rail--bottom,
body:not(.ads-sides) .ad-rail--left,
body:not(.ads-sides) .ad-rail--right {
  display: none;
}

.hud { z-index: 30; }
.screen { z-index: 40; }
.toast { z-index: 50; }

@media (max-width: 1179px) {
  .ad-rail--left,
  .ad-rail--right {
    display: none;
  }

  .game-frame {
    border-radius: 0;
  }
}

/* ------------------------------------------------------------
   Global leaderboard
   ------------------------------------------------------------ */

.menu-stats {
  grid-template-columns: repeat(3, 1fr);
}

.menu-stat {
  padding: 2px 6px;
}

.menu-stat span {
  font-size: 8px;
  letter-spacing: 0.14em;
}

.menu-stat strong {
  font-size: 21px;
}

.leaderboard {
  counter-reset: pilot;
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.leaderboard li {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 38px;
  padding: 7px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.leaderboard li::before {
  counter-increment: pilot;
  content: counter(pilot);
  width: 22px;
  flex: none;
  font-size: 10px;
  font-weight: 800;
  text-align: right;
  color: var(--muted-2);
  font-variant-numeric: tabular-nums;
}

.leaderboard li.is-me {
  margin: 0 -6px;
  padding-left: 12px;
  padding-right: 12px;
  border-radius: 8px;
  background: rgba(255, 200, 87, 0.08);
}

.leaderboard li.is-me::before {
  color: var(--amber);
}

.leaderboard-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
  font-weight: 700;
}

.leaderboard-score {
  font-size: 14px;
  font-weight: 900;
  color: var(--amber);
  font-variant-numeric: tabular-nums;
}

.leaderboard-empty {
  display: block !important;
  padding: 18px 6px !important;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.leaderboard-empty::before {
  display: none;
}

.leaderboard-me {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.45;
}

.global-rank {
  margin: 10px 0 0;
  color: var(--green);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.text-link {
  display: inline-block;
  margin-top: 8px;
  padding: 4px;
  border: 0;
  background: transparent;
  color: var(--amber);
  font: inherit;
  font-size: 10px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.text-link:hover { color: #ffe4a3; }

.leaderboard-dialog {
  width: min(92vw, 460px);
}

/* ------------------------------------------------------------
   Visible global-top panel on the menu
   ------------------------------------------------------------ */

.menu-board {
  position: absolute;
  right: clamp(18px, 4vw, 54px);
  top: 50%;
  transform: translateY(-50%);
  width: 300px;
  max-height: 68%;
  overflow: auto;
  padding: 18px 18px 14px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255, 200, 87, 0.055), transparent 60%),
    rgba(9, 14, 28, 0.82);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  scrollbar-width: thin;
}

.menu-board-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.menu-board-head .eyebrow { margin: 0; }

.menu-board-live {
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(95, 224, 164, 0.12);
  color: var(--green);
  font-size: 7px;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.leaderboard--menu {
  margin-top: 10px;
  border-top: 0;
}

.leaderboard--menu li {
  min-height: 31px;
  padding: 5px 2px;
  gap: 8px;
}

.leaderboard--menu li::before {
  width: 16px;
  font-size: 9px;
}

.leaderboard--menu .leaderboard-name {
  font-size: 11px;
}

.leaderboard--menu .leaderboard-score {
  font-size: 12px;
}

.leaderboard--menu li.is-me {
  margin: 0 -6px;
  padding-left: 8px;
  padding-right: 8px;
}

.menu-board .text-link {
  margin-top: 8px;
  font-size: 9px;
}

@media (max-width: 1100px) {
  .menu-board { display: none; }
}
