:root {
  /* Set by shell from chosen character (matches canvas bg). */
  --frappy-bg-page: url("assets/bg01.png");
  --lo-blue: #4C6FFF;
  --lo-yellow: #FFDD55;
  --lo-bg-top: #6DE0FF;
  --lo-bg-bottom: #4C6FFF;
  --lo-blue-start: #6DE0FF;
  --lo-blue-end: #4C6FFF;
  --game-aspect: 480 / 640; /* portrait frame; CSS sizes wrap to this ratio */
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

button {
  text-transform: uppercase;
}

html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  height: -webkit-fill-available;
}

body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  overflow: hidden;
  font-family: "Fredoka", sans-serif;
  /* Fallback: same gradient as Frappy Brew / links when image hasn’t loaded */
  background: linear-gradient(180deg, var(--lo-bg-top) 0%, var(--lo-bg-bottom) 100%);
  color: #ffffff;
}

.page {
  position: relative;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  overflow: hidden;
}

/* Page backdrop — one rule everywhere (no dueling mobile/desktop BG math). */
.frappy-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  min-height: 100lvh;
  min-height: -webkit-fill-available;
  background-image: var(--frappy-bg-page);
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
}

.frappy-bg-overlay {
  position: fixed;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  min-height: 100lvh;
  min-height: -webkit-fill-available;
  /* Very light tint — keeps art bright */
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.03) 0%,
    rgba(0, 0, 0, 0.05) 50%,
    rgba(0, 0, 0, 0.08) 100%
  );
}

@media (max-width: 480px) {
  html,
  body,
  .page,
  .page-fullscreen {
    min-height: 100lvh;
    min-height: 100dvh;
    min-height: -webkit-fill-available;
  }
}

/* Letterboxed 480:640 playfield; HUD fixed on top */
.page-fullscreen {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  min-height: 100%;
  min-height: 100dvh;
  min-height: 100lvh;
  min-height: -webkit-fill-available;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
}

/* First screen: big LO, ×, DDG, PLAY — above game layers */
.intro-splash {
  position: fixed;
  inset: 0;
  z-index: 85;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background-color: #0a1830;
  background-image: linear-gradient(
    180deg,
    rgba(10, 24, 48, 0.98) 0%,
    rgba(20, 50, 90, 0.95) 45%,
    rgba(12, 32, 64, 0.98) 100%
  );
  pointer-events: auto;
}

.intro-splash:not(.hidden) ~ .game-top-bar,
.intro-splash:not(.hidden) ~ .game-viewport,
.intro-splash:not(.hidden) ~ .btn-back--corner,
.intro-splash:not(.hidden) ~ .btn-help--corner {
  visibility: hidden;
  pointer-events: none;
}

.intro-splash.hidden {
  display: none;
}

/* LO Arcade — leave DDG splash */
.intro-back-to-arcade {
  position: absolute;
  top: max(12px, env(safe-area-inset-top, 0px));
  left: max(12px, env(safe-area-inset-left, 0px));
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.28);
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: rgba(255, 255, 255, 0.95);
  text-decoration: none;
  background: rgba(0, 0, 0, 0.4);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  transition: background 0.15s ease, transform 0.12s ease;
  touch-action: manipulation;
}

.intro-back-to-arcade:hover {
  background: rgba(255, 255, 255, 0.12);
}

.intro-back-to-arcade:active {
  transform: scale(0.98);
}

.intro-back-to-arcade:focus-visible {
  outline: 2px solid var(--lo-yellow, #ffdd55);
  outline-offset: 2px;
}

.intro-splash-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 3vh, 20px);
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.intro-splash-lo {
  display: block;
  width: min(88vw, 360px);
  height: auto;
  max-height: min(38vh, 280px);
  object-fit: contain;
  /* Transparent PNG — no fill behind logo */
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.45));
}

.intro-splash-x {
  font-size: clamp(36px, 10vw, 52px);
  font-weight: 800;
  line-height: 1;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  user-select: none;
}

/* DDG: crop + zoom to skull only — no shadow/background (just the PNG) */
.ddg-skull-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  line-height: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  filter: none;
  --ddg-skull-zoom: 1.58;
  --ddg-skull-fx: 50%;
  --ddg-skull-fy: 42%;
}

.ddg-skull-wrap img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--ddg-skull-fx) var(--ddg-skull-fy);
  transform: scale(var(--ddg-skull-zoom));
  transform-origin: var(--ddg-skull-fx) var(--ddg-skull-fy);
  box-shadow: none;
  filter: none;
  background: transparent;
}

.ddg-skull-wrap--intro {
  width: min(48vw, 162px);
  height: min(48vw, 162px);
}

.ddg-skull-wrap--cobrand {
  width: 48px;
  height: 48px;
}

.ddg-skull-wrap--overlay {
  width: 36px;
  height: 36px;
}

.ddg-skull-wrap--btn {
  width: 26px;
  height: 26px;
}

.ddg-skull-wrap--watermark {
  width: min(100%, 228px);
  max-width: 100%;
  aspect-ratio: 1;
  max-height: min(228px, 58vh);
}

.ddg-skull-wrap--modal {
  width: 46px;
  height: 46px;
}

.intro-welcome {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.35);
}

.intro-welcome[hidden] {
  display: none !important;
}

.intro-splash-loading {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.85);
}

.intro-splash-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 4px;
  width: 100%;
  max-width: 360px;
}

.btn-secondary {
  flex: 1 1 auto;
  min-width: min(140px, 42vw);
  padding: 11px 16px;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease, transform 0.12s ease;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
}

.btn-secondary:active {
  transform: scale(0.98);
}

.btn-secondary:focus-visible {
  outline: 2px solid var(--lo-yellow);
  outline-offset: 2px;
}

/* HOW TO PLAY — glow after a Lord is chosen (shell adds class per skin). */
#howToPlayBtn.howto-btn--accent-none {
  opacity: 0.85;
  box-shadow: none;
}

#howToPlayBtn.howto-btn--accent-1 {
  border-color: rgba(186, 104, 255, 0.95);
  background: linear-gradient(
    145deg,
    rgba(90, 40, 140, 0.55) 0%,
    rgba(40, 20, 80, 0.65) 100%
  );
  box-shadow:
    0 0 0 1px rgba(200, 150, 255, 0.35),
    0 0 22px rgba(160, 80, 255, 0.55),
    0 0 42px rgba(120, 40, 200, 0.35);
}

#howToPlayBtn.howto-btn--accent-2 {
  border-color: rgba(255, 120, 80, 0.95);
  background: linear-gradient(
    145deg,
    rgba(140, 35, 20, 0.6) 0%,
    rgba(80, 15, 10, 0.7) 100%
  );
  box-shadow:
    0 0 0 1px rgba(255, 140, 90, 0.4),
    0 0 22px rgba(255, 80, 40, 0.55),
    0 0 40px rgba(200, 40, 20, 0.4);
}

#howToPlayBtn.howto-btn--accent-3 {
  border-color: rgba(80, 180, 255, 0.95);
  background: linear-gradient(
    145deg,
    rgba(25, 70, 120, 0.55) 0%,
    rgba(15, 40, 90, 0.65) 100%
  );
  box-shadow:
    0 0 0 1px rgba(120, 200, 255, 0.35),
    0 0 22px rgba(60, 160, 255, 0.5),
    0 0 40px rgba(30, 100, 200, 0.4);
}

.intro-splash-actions #howToPlayBtn.howto-btn--accent-1:hover {
  background: linear-gradient(
    145deg,
    rgba(110, 55, 165, 0.65) 0%,
    rgba(50, 25, 95, 0.75) 100%
  );
  border-color: rgba(210, 170, 255, 1);
  box-shadow:
    0 0 0 1px rgba(220, 180, 255, 0.45),
    0 0 28px rgba(170, 100, 255, 0.65),
    0 0 48px rgba(130, 60, 220, 0.45);
}

.intro-splash-actions #howToPlayBtn.howto-btn--accent-2:hover {
  background: linear-gradient(
    145deg,
    rgba(170, 50, 30, 0.7) 0%,
    rgba(100, 25, 15, 0.78) 100%
  );
  border-color: rgba(255, 150, 110, 1);
  box-shadow:
    0 0 0 1px rgba(255, 160, 100, 0.5),
    0 0 28px rgba(255, 90, 50, 0.65),
    0 0 46px rgba(220, 60, 30, 0.45);
}

.intro-splash-actions #howToPlayBtn.howto-btn--accent-3:hover {
  background: linear-gradient(
    145deg,
    rgba(40, 100, 160, 0.65) 0%,
    rgba(20, 55, 110, 0.75) 100%
  );
  border-color: rgba(130, 210, 255, 1);
  box-shadow:
    0 0 0 1px rgba(140, 210, 255, 0.45),
    0 0 28px rgba(80, 180, 255, 0.6),
    0 0 46px rgba(40, 120, 220, 0.45);
}

.intro-play-btn {
  margin-top: 8px;
  min-width: min(280px, 86vw);
  padding: 14px 24px;
  font-size: 20px;
  letter-spacing: 0.06em;
}

.game-viewport {
  position: relative;
  width: 100%;
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  container-type: size;
  container-name: game;
}

/* Portrait 480:640 — same framing on Mac and iPhone */
.canvas-wrap {
  position: relative;
  overflow: hidden;
  flex: 0 0 auto;
  width: min(100vw, 100dvh * 0.75);
  height: min(100dvh, 100vw / 0.75);
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: var(--game-aspect);
  touch-action: none;
}

@supports (width: 1cqw) {
  .canvas-wrap {
    width: min(100cqw, 100cqh * 0.75);
    height: min(100cqh, 100cqw / 0.75);
  }
}

/* LO × DDG + HUD stacked at top — above canvas (25) during play */
.game-top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  /* Side padding reserves space for fixed corner buttons (44px) + gutter */
  padding: 8px calc(12px + 44px) 10px calc(12px + 44px);
  pointer-events: none;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.45) 0%,
    rgba(0, 0, 0, 0.12) 55%,
    transparent 100%
  );
}

.co-brand-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  max-width: min(92vw, 420px);
}

.game-handle-bar {
  margin: 0;
  padding: 0 8px;
  width: 100%;
  max-width: min(92vw, 420px);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.game-handle-bar[hidden] {
  display: none !important;
}

.co-brand-img {
  display: block;
  flex-shrink: 0;
}

.co-brand-lo {
  height: 42px;
  width: auto;
  max-width: min(56vw, 260px);
  object-fit: contain;
}


.co-brand-x {
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  opacity: 0.9;
  user-select: none;
}

.hud-overlay {
  position: static;
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 4px 4px;
  pointer-events: none;
}

/* Pills are display-only — must not steal taps from canvas or centered overlay cards */
.hud-overlay .hud-pill {
  pointer-events: none;
}

/* Small top-left — How to play (mirrors back arrow) */
.btn-help--corner {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 62;
  width: 40px;
  height: 40px;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  font-family: inherit;
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  transition: background 0.15s ease, transform 0.12s ease;
}

.btn-help--corner:hover {
  background: rgba(0, 0, 0, 0.6);
  transform: scale(1.05);
}

.btn-help--corner:active {
  transform: scale(0.96);
}

/* Small top-right control — out of the way of logo + HUD */
.btn-back--corner {
  position: fixed;
  top: 8px;
  right: 8px;
  z-index: 62;
  width: 40px;
  height: 40px;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  font-family: inherit;
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  transition: background 0.15s ease, transform 0.12s ease;
}

.btn-back--corner:hover {
  background: rgba(0, 0, 0, 0.6);
  transform: scale(1.05);
}

.btn-back--corner:active {
  transform: scale(0.96);
}

.btn-back-arrow {
  display: block;
  margin-left: -2px;
}

.hud {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: rgba(0, 0, 0, 0.35);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.6);
  border: 1px solid transparent;
  transition: background 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.hud-pill span:last-child {
  font-variant-numeric: tabular-nums;
}

/* Scene-tinted pills only (data-frappy-skin set from shell when a Lord is chosen) */
[data-frappy-skin="1"] .hud-pill {
  background: rgba(55, 25, 85, 0.62);
  border-color: rgba(190, 130, 255, 0.4);
  box-shadow: 0 3px 0 rgba(30, 15, 50, 0.65);
}

[data-frappy-skin="2"] .hud-pill {
  background: rgba(95, 25, 18, 0.62);
  border-color: rgba(255, 130, 90, 0.42);
  box-shadow: 0 3px 0 rgba(50, 15, 10, 0.65);
}

[data-frappy-skin="3"] .hud-pill {
  background: rgba(18, 55, 105, 0.62);
  border-color: rgba(110, 190, 255, 0.42);
  box-shadow: 0 3px 0 rgba(12, 35, 70, 0.65);
}

#gameCanvas {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  background: #1a1a2e;
  touch-action: none;
  pointer-events: auto;
  cursor: pointer;
  z-index: 1;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

/* Game Over: escape the letterboxed canvas. Exact size/position come from
   frappy-brew.js syncGameOverOverlayViewport() + window.visualViewport (iOS Safari).
   Fallback CSS only when JS hasn’t run yet. No safe-area padding — full edge-to-edge. */
body.game-over-active #overlay {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  box-sizing: border-box;
  pointer-events: auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 10px;
}

.overlay-card {
  max-width: 440px;
  width: 92%;
  background: rgba(0, 0, 0, 0.78);
  border-radius: 20px;
  padding: 22px 22px 24px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.7);
  pointer-events: auto;
}

/* Full-screen dim + hide HUD branding when Game Over is up (HUD was fixed above canvas). */
body.game-over-active .game-top-bar {
  visibility: hidden;
}

body.game-over-active .game-viewport {
  z-index: 70;
}

body.game-over-active .btn-help--corner,
body.game-over-active .btn-back--corner {
  z-index: 90;
}

body.game-over-active .canvas-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 8;
  border-radius: inherit;
  background: rgba(4, 8, 18, 0.82);
  pointer-events: none;
}

.overlay-card .loading-text {
  margin: 0 0 8px 0;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.9);
}

.overlay-card .ready-title,
.overlay-card .ready-desc {
  display: none;
}

.overlay-card h2 {
  margin: 0 0 10px 0;
  font-size: 24px;
  font-weight: 800;
}

.overlay-card p {
  margin: 0 0 14px 0;
  font-size: 16px;
  color: rgba(255, 255, 255, 0.88);
}

.overlay-card.hidden {
  display: none;
}

/* Game Over: LO×DDG + subtle DDG watermark — outer #overlay scrolls on iPhone (see body.game-over-active #overlay) */
.overlay-card--gameover {
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  max-height: min(88vh, 88dvh);
  max-height: min(92svh, 92dvh);
  z-index: 10;
  background: rgba(8, 12, 24, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.85),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* Single scroll surface: fixed overlay scrolls; drop inner max-height to avoid nested scroll + clipping */
body.game-over-active #overlay .overlay-card--gameover {
  max-height: none;
  overflow: visible;
}

.overlay-card-brand--gameover {
  margin-top: 0;
  margin-bottom: 10px;
}

.overlay-card-ddg-watermark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 0;
  opacity: 0.16;
  padding: 12px 8px;
}

.overlay-card-gameover-body {
  position: relative;
  z-index: 1;
}

.overlay-card--gameover h2,
.overlay-card--gameover .overlay-card-gameover-body p {
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.55);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 12px 16px;
  border-radius: 14px;
  border: none;
  font-family: "Fredoka", sans-serif;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  background: linear-gradient(180deg, #FFE986 0%, var(--lo-yellow) 90%);
  color: #1a1a2e;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.7);
  letter-spacing: 0.02em;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.btn-primary-content {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  pointer-events: none;
}

.btn-brand-lo {
  height: 22px;
  width: auto;
  max-width: 72px;
  object-fit: contain;
  flex-shrink: 0;
}


.btn-primary-text-only {
  padding: 12px 18px;
  font-size: 17px;
}

.btn-primary-text-only .btn-primary-text {
  pointer-events: none;
}

.overlay-card-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 14px;
  opacity: 0.95;
}

.overlay-card-brand .overlay-brand-lo {
  height: 31px;
  width: auto;
  max-width: 130px;
  object-fit: contain;
}


.overlay-card-brand .co-brand-x {
  font-size: 18px;
  font-weight: 700;
  opacity: 0.85;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 7px 0 rgba(0, 0, 0, 0.8);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.7);
}

@media (max-width: 480px) {
  .hud-overlay {
    gap: 6px;
    padding-top: 10px;
  }

  .hud-pill {
    font-size: 12px;
    padding: 6px 8px;
  }

  .btn-back--corner {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }

  .btn-help--corner {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }
}

