:root {
  --bg-deep: #0b1622;
  --bg-mid: #132837;
  --sun: #ffb347;
  --coral: #ff6b35;
  --teal: #14f195;
  --cream: #ffe8c8;
  --ink: #0a1218;
  --panel: rgba(11, 22, 34, 0.78);
  --danger: #ff5a5a;
  --ok: #14f195;
  --touch-min: 48px;
  --font-display: "Bangers", system-ui, sans-serif;
  --font-body: "Space Grotesk", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background:
    radial-gradient(ellipse 120% 80% at 70% -10%, rgba(255, 179, 71, 0.35), transparent 55%),
    radial-gradient(ellipse 80% 60% at 10% 100%, rgba(20, 241, 149, 0.12), transparent 50%),
    linear-gradient(165deg, #1a3348 0%, var(--bg-deep) 45%, #071018 100%);
  color: var(--cream);
  font-family: var(--font-body);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#app {
  min-height: 100%;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "topbar"
    "game"
    "footer";
  gap: 0.5rem;
  padding:
    max(0.75rem, var(--safe-top))
    max(1rem, var(--safe-right))
    max(0.5rem, var(--safe-bottom))
    max(1rem, var(--safe-left));
}

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3.2rem);
  letter-spacing: 0.04em;
  line-height: 1;
  color: var(--coral);
  text-shadow: 3px 3px 0 #000, 0 0 24px rgba(255, 107, 53, 0.35);
  animation: brand-pop 1.2s ease-out both;
  /* Italic Bangers overhang — keep final glyphs visible */
  padding-right: 0.2em;
}

.brand span {
  color: var(--teal);
  text-shadow: 3px 3px 0 #000, 0 0 24px rgba(20, 241, 149, 0.35);
}

.brand-logo {
  width: clamp(2rem, 4.5vw, 2.75rem);
  height: clamp(2rem, 4.5vw, 2.75rem);
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.55), 0 0 18px rgba(255, 107, 53, 0.35);
}

.brand-text {
  display: inline-block;
}

@keyframes brand-pop {
  from { transform: scale(0.85) rotate(-2deg); opacity: 0; }
  to { transform: scale(1) rotate(0); opacity: 1; }
}

#game-shell {
  grid-area: game;
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid rgba(255, 179, 71, 0.35);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.45),
    inset 0 0 80px rgba(255, 107, 53, 0.06);
  min-height: 0;
  background: #1a2a38;
}

.finale-movie {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: #000;
  opacity: 0;
}

.finale-movie.hidden {
  display: none;
  opacity: 0;
}

.finale-movie.is-visible {
  opacity: 1;
}

.finale-movie video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.finale-skip {
  position: absolute;
  /* Clear home indicator / rounded corners when shell goes edge-to-edge */
  right: max(12px, var(--safe-right));
  bottom: max(12px, var(--safe-bottom));
  z-index: 2;
  font-family: var(--font-display);
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  padding: 0.55rem 1.45rem 0.55rem 1.15rem;
  border: 2px solid rgba(255, 232, 200, 0.35);
  border-radius: 10px;
  background: rgba(11, 22, 34, 0.85);
  color: var(--cream);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.finale-skip:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.finale-skip:focus-visible {
  outline: 2px solid var(--sun);
  outline-offset: 2px;
}

/* Level-map chips live in Phaser; keep shell readable on small viewports */
#game-container {
  width: 100%;
  height: min(66vh, 780px);
  min-height: 340px;
  background: #0b1622;
  touch-action: none;
}

@media (max-width: 640px) {
  #game-container {
    height: min(54vh, 580px);
    min-height: 300px;
  }
  .hud-stat {
    min-width: 56px;
    padding: 0.35rem 0.55rem;
  }
  .hud-stat strong {
    font-size: 1.15rem;
  }
}

/* Desktop / default: polished top-right chip cluster (Agent 6) */
.hud-overlay {
  position: absolute;
  top: max(12px, var(--safe-top));
  right: max(12px, var(--safe-right));
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  pointer-events: none;
  z-index: 5;
}

.hud-stat {
  background: var(--panel);
  border: 1px solid rgba(20, 241, 149, 0.3);
  border-radius: 10px;
  padding: 0.45rem 1.1rem 0.45rem 0.85rem;
  min-width: 84px;
  text-align: center;
  overflow: visible;
}

.hud-stat span {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.7;
}

.hud-stat strong {
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--sun);
  display: inline-block;
  padding-right: 0.18em;
}

.site-footer {
  grid-area: footer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  padding: 0.15rem 0.25rem 0.35rem;
  text-align: center;
}

.token-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.45rem 0.65rem;
}

.token-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 40px;
  padding: 0.35rem 0.75rem 0.35rem 0.55rem;
  border: 1px solid rgba(255, 232, 200, 0.18);
  border-radius: 10px;
  background: rgba(11, 22, 34, 0.55);
  color: var(--cream);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.token-link img {
  width: 22px;
  height: 22px;
  object-fit: contain;
  flex-shrink: 0;
}

.token-link:hover {
  border-color: rgba(20, 241, 149, 0.55);
  color: var(--teal);
  background: rgba(11, 22, 34, 0.85);
}

.token-link:focus-visible {
  outline: 2px solid var(--sun);
  outline-offset: 2px;
}

.ca-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.4rem 0.55rem;
  max-width: 100%;
  font-size: 0.78rem;
}

.ca-label {
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.7;
  font-size: 0.68rem;
}

#token-ca {
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  font-size: 0.72rem;
  color: var(--sun);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 179, 71, 0.28);
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
  max-width: min(100%, 28rem);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.copy-ca {
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  min-height: 36px;
  padding: 0.35rem 0.75rem;
  border: 1px solid rgba(20, 241, 149, 0.4);
  border-radius: 8px;
  background: rgba(20, 241, 149, 0.12);
  color: var(--teal);
  cursor: pointer;
}

.copy-ca:hover {
  background: rgba(20, 241, 149, 0.22);
}

.copy-ca:focus-visible {
  outline: 2px solid var(--sun);
  outline-offset: 2px;
}

.copy-ca.is-copied {
  border-color: rgba(255, 179, 71, 0.55);
  color: var(--sun);
  background: rgba(255, 179, 71, 0.14);
}

.disclaimer-fold {
  max-width: 46rem;
  text-align: center;
}

.disclaimer-fold > summary {
  display: none;
  list-style: none;
  cursor: pointer;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.55;
  padding: 0.2rem 0.5rem;
  min-height: 44px;
  align-items: center;
  justify-content: center;
}

.disclaimer-fold > summary::-webkit-details-marker {
  display: none;
}

.disclaimer {
  max-width: 46rem;
  font-size: 0.68rem;
  line-height: 1.45;
  opacity: 0.55;
  padding: 0 0.35rem;
}

/* Desktop / non-mobile: always show full disclaimer (override closed <details>) */
html:not([data-mode="mobile"]) .disclaimer-fold > .disclaimer {
  display: block !important;
}

/* —— Agent 3: mobile in-game Links control (chrome hide owned by Agent 1) —— */
.play-links-btn {
  display: none;
  grid-area: game;
  position: fixed;
  z-index: 45;
  /* F5 — clear of home indicator / rounded corners */
  bottom: max(1rem, calc(var(--safe-bottom) + 0.5rem));
  right: max(1rem, calc(var(--safe-right) + 0.5rem));
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  padding: 0.35rem 0.85rem;
  border: 1px solid rgba(255, 179, 71, 0.45);
  border-radius: 10px;
  background: rgba(11, 22, 34, 0.88);
  color: var(--sun);
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.play-links-btn:focus-visible {
  outline: 2px solid var(--sun);
  outline-offset: 2px;
}

/* Visible only in mobile + active play (Agent 9 sets data-mode). */
html[data-mode="mobile"][data-play="game"] .play-links-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Reveal footer as overlay when Links is open (overrides Agent 1 collapse). */
html[data-mode="mobile"][data-play="game"].links-open .site-footer {
  display: flex;
  flex-direction: column;
  position: fixed;
  z-index: 50;
  left: max(0.5rem, var(--safe-left));
  right: max(0.5rem, var(--safe-right));
  bottom: max(0.5rem, var(--safe-bottom));
  max-height: min(70dvh, 420px);
  overflow: auto;
  padding: 0.75rem 0.85rem;
  border-radius: 14px;
  border: 1px solid rgba(255, 179, 71, 0.4);
  background: rgba(11, 22, 34, 0.96);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
}

/* —— Responsive —— */
@media (max-width: 720px) {
  #app {
    gap: 0.4rem;
    padding:
      max(0.5rem, var(--safe-top))
      max(0.6rem, var(--safe-right))
      max(0.4rem, var(--safe-bottom))
      max(0.6rem, var(--safe-left));
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .brand {
    text-align: center;
    font-size: clamp(1.85rem, 9vw, 2.6rem);
  }

  #game-container {
    height: min(50dvh, 500px);
    min-height: 260px;
  }

  .hud-overlay {
    top: auto;
    bottom: 8px;
    right: 8px;
    left: 8px;
    justify-content: center;
  }

  .hud-stat {
    flex: 1;
    min-width: 0;
    padding: 0.5rem 0.4rem;
  }

  .site-footer {
    gap: 0.4rem;
    padding-bottom: 0.2rem;
  }

  .token-link {
    min-height: 36px;
    padding: 0.3rem 0.6rem 0.3rem 0.45rem;
    font-size: 0.74rem;
  }

  #token-ca {
    font-size: 0.62rem;
    max-width: calc(100vw - 8rem);
  }

  .disclaimer {
    font-size: 0.6rem;
    line-height: 1.4;
  }
}

/*
 * Agent 6 — mobile landscape HUD
 * Compact top strip, right-biased; left slingshot zone stays clear.
 * Higher specificity than the ≤720px bottom-bar HUD rule above.
 */
html[data-mode="mobile"][data-orientation="landscape"] .hud-overlay {
  top: max(4px, var(--safe-top));
  right: max(4px, var(--safe-right));
  bottom: auto;
  left: auto;
  /* Leave left play / slingshot thumb zone free (~28% or ≥5.5rem + notch) */
  max-width: min(72%, calc(100% - max(5.5rem, var(--safe-left) + 4.5rem)));
  justify-content: flex-end;
  flex-wrap: nowrap;
  gap: 0.28rem;
}

html[data-mode="mobile"][data-orientation="landscape"] .hud-stat {
  flex: 0 1 auto;
  min-width: 0;
  padding: 0.2rem 0.42rem 0.2rem 0.38rem;
  border-radius: 8px;
}

html[data-mode="mobile"][data-orientation="landscape"] .hud-stat span {
  font-size: 0.52rem;
  letter-spacing: 0.05em;
  line-height: 1.1;
}

html[data-mode="mobile"][data-orientation="landscape"] .hud-stat strong {
  font-size: 1.02rem;
  line-height: 1.15;
  padding-right: 0.1em;
}

/* F6 — hide DOM HUD on menu; show only during play */
html[data-play="menu"] #dom-hud {
  display: none;
}

/* Finale / full-bleed movie owns the shell — tuck HUD away */
#game-shell:has(#finale-movie:not(.hidden)) #dom-hud {
  opacity: 0;
  visibility: hidden;
}

@media (max-width: 400px) {
  #game-container {
    height: min(46dvh, 420px);
    min-height: 240px;
  }

  .hud-stat strong { font-size: 1.15rem; }
}

@media (min-width: 1100px) {
  #game-container {
    height: min(70vh, 800px);
  }
}

/* —— Agent 1: mobile landscape dual shell (desktop vh above unchanged) —— */
html[data-mode="mobile"][data-orientation="landscape"] #app {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  overflow: hidden;
  gap: 0.2rem;
  padding:
    max(0.25rem, var(--safe-top))
    max(0.4rem, var(--safe-right))
    max(0.2rem, var(--safe-bottom))
    max(0.4rem, var(--safe-left));
}

html[data-mode="mobile"][data-orientation="landscape"] .topbar {
  flex-direction: row;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

html[data-mode="mobile"][data-orientation="landscape"] .brand {
  font-size: clamp(1.15rem, 4.2vh, 1.65rem);
  text-shadow: 2px 2px 0 #000, 0 0 16px rgba(255, 107, 53, 0.3);
  padding-right: 0.15em;
  text-align: center;
  justify-content: center;
}

html[data-mode="mobile"][data-orientation="landscape"] .brand-logo {
  width: clamp(1.25rem, 3.6vh, 1.75rem);
  height: clamp(1.25rem, 3.6vh, 1.75rem);
}

html[data-mode="mobile"][data-orientation="landscape"] #game-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  border-radius: 10px;
  border-width: 1px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
}

html[data-mode="mobile"][data-orientation="landscape"] #game-container {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-height: 0;
}

html[data-mode="mobile"][data-orientation="landscape"] .site-footer {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.25rem 0.65rem;
  padding: 0.05rem 0.15rem 0.1rem;
}

html[data-mode="mobile"][data-orientation="landscape"] .token-links {
  flex-wrap: nowrap;
  gap: 0.35rem;
}

html[data-mode="mobile"][data-orientation="landscape"] .token-link {
  position: relative;
  min-width: 44px;
  min-height: 44px;
  padding: 0.35rem;
  justify-content: center;
  border-radius: 10px;
}

html[data-mode="mobile"][data-orientation="landscape"] .token-link span {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html[data-mode="mobile"][data-orientation="landscape"] .token-link img {
  width: 24px;
  height: 24px;
}

html[data-mode="mobile"][data-orientation="landscape"] .ca-row {
  flex-wrap: nowrap;
  gap: 0.3rem 0.4rem;
  max-width: 100%;
  font-size: 0.68rem;
}

html[data-mode="mobile"][data-orientation="landscape"] #token-ca {
  font-size: 0.58rem;
  padding: 0.3rem 0.45rem;
  max-width: min(42vw, 14rem);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

html[data-mode="mobile"][data-orientation="landscape"] .copy-ca {
  min-height: 44px;
  min-width: 44px;
  padding: 0.3rem 0.65rem;
  font-size: 0.65rem;
}

html[data-mode="mobile"][data-orientation="landscape"] .disclaimer-fold > summary {
  display: inline-flex;
  font-size: 0.58rem;
  opacity: 0.6;
}

html[data-mode="mobile"][data-orientation="landscape"] .disclaimer-fold > .disclaimer {
  font-size: 0.55rem;
  line-height: 1.35;
  padding: 0.15rem 0.35rem 0.25rem;
  max-width: min(100%, 36rem);
}

/* F1-A — menu: maximize canvas (hide brand; icon-only footer) */
html[data-mode="mobile"][data-orientation="landscape"][data-play="menu"] #app {
  grid-template-areas:
    "game"
    "footer";
  grid-template-rows: 1fr auto;
  gap: 0.12rem;
  padding:
    max(0.15rem, var(--safe-top))
    max(0.3rem, var(--safe-right))
    max(0.15rem, var(--safe-bottom))
    max(0.3rem, var(--safe-left));
}

html[data-mode="mobile"][data-orientation="landscape"][data-play="menu"] .topbar {
  display: none;
}

html[data-mode="mobile"][data-orientation="landscape"][data-play="menu"] .site-footer {
  gap: 0.2rem 0.45rem;
  padding: 0.05rem 0.1rem;
}

html[data-mode="mobile"][data-orientation="landscape"][data-play="menu"] .ca-row,
html[data-mode="mobile"][data-orientation="landscape"][data-play="menu"] .disclaimer-fold {
  display: none;
}

html[data-mode="mobile"][data-orientation="landscape"][data-play="menu"] #game-shell {
  border-radius: 8px;
}

/* F3 — letterbox gutters match play field */
html[data-mode="mobile"] #game-container {
  background: #1a2a38;
}

/* Mobile portrait: inert under Agent 9 gate */
html[data-mode="mobile"][data-orientation="portrait"] #app {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

/* —— Agent 1: in-game chrome minimize (Agent 3 sets data-play; Links uses .links-open) —— */
html[data-mode="mobile"][data-play="game"] .topbar {
  display: none;
}

html[data-mode="mobile"][data-play="game"] .site-footer {
  display: none;
}

html[data-mode="mobile"][data-play="game"] #app {
  grid-template-rows: 1fr;
  grid-template-areas: "game";
  gap: 0;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  padding:
    max(0px, var(--safe-top))
    max(0px, var(--safe-right))
    max(0px, var(--safe-bottom))
    max(0px, var(--safe-left));
}

html[data-mode="mobile"][data-play="game"] #game-shell {
  display: flex;
  flex-direction: column;
  border-radius: 0;
  border: none;
  box-shadow: none;
  height: 100%;
  min-height: 0;
  background: #1a2a38;
}

html[data-mode="mobile"][data-play="game"] #game-container {
  flex: 1 1 auto;
  height: 100%;
  min-height: 0;
}

/* —— Orientation gate (mobile portrait only; desktop never shows) —— */
#orient-gate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
  align-items: center;
  justify-content: center;
  padding:
    max(1.5rem, var(--safe-top))
    max(1.5rem, var(--safe-right))
    max(1.5rem, var(--safe-bottom))
    max(1.5rem, var(--safe-left));
  background:
    radial-gradient(ellipse 90% 70% at 50% 20%, rgba(255, 107, 53, 0.22), transparent 55%),
    linear-gradient(165deg, #1a3348 0%, var(--bg-deep) 50%, #071018 100%);
  color: var(--cream);
  text-align: center;
  touch-action: none;
}

html[data-mode="mobile"][data-orientation="portrait"] #orient-gate {
  display: flex;
}

.orient-gate-inner {
  max-width: 22rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
}

.orient-gate-icon {
  width: 4.5rem;
  height: 4.5rem;
  display: grid;
  place-items: center;
  margin-bottom: 0.35rem;
}

.orient-phone {
  display: block;
  width: 1.75rem;
  height: 2.85rem;
  border: 3px solid var(--cream);
  border-radius: 0.4rem;
  box-shadow: 3px 3px 0 #000;
  transform: rotate(0deg);
  animation: orient-tilt 1.6s ease-in-out infinite;
}

.orient-phone::after {
  content: "";
  display: block;
  width: 0.45rem;
  height: 0.45rem;
  margin: 0.2rem auto 0;
  border-radius: 50%;
  background: var(--teal);
}

@keyframes orient-tilt {
  0%, 20% { transform: rotate(0deg); }
  45%, 70% { transform: rotate(90deg); }
  100% { transform: rotate(0deg); }
}

#orient-gate-title {
  font-family: var(--font-display);
  font-size: clamp(1.85rem, 7vw, 2.6rem);
  letter-spacing: 0.04em;
  line-height: 1.05;
  color: var(--coral);
  text-shadow: 3px 3px 0 #000;
}

#orient-gate-desc {
  font-size: clamp(0.95rem, 3.5vw, 1.15rem);
  line-height: 1.45;
  color: var(--cream);
  opacity: 0.92;
}

@media (prefers-reduced-motion: reduce) {
  .brand { animation: none; }
  .orient-phone { animation: none; transform: rotate(90deg); }
  * { scroll-behavior: auto; }
}
