:root {
  color-scheme: dark;
  --bg: #070a10;
  --panel: #121826;
  --text: #e4e9f4;
  --muted: #8b9ab8;
  --accent: #6b9fff;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: radial-gradient(ellipse 120% 80% at 50% 0%, #1a2438 0%, var(--bg) 52%);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.screen {
  display: none;
  flex-direction: column;
  width: min(100vw, 480px);
  flex: 1;
  min-height: 0;
}

.screen--active {
  display: flex;
  position: relative;
  z-index: 260;
}

.menu-card {
  margin: auto;
  width: 100%;
  max-width: 400px;
  padding: 28px 22px;
  border-radius: var(--radius);
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0.25));
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.menu-card h1 {
  margin: 0 0 8px;
  font-size: 1.85rem;
  letter-spacing: 0.04em;
}

.menu-tagline {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.menu-meta {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.sub-status {
  font-size: 0.78rem;
  color: var(--muted);
}

.btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-primary {
  background: linear-gradient(180deg, rgba(107, 159, 255, 0.35), rgba(107, 159, 255, 0.12));
  border-color: rgba(107, 159, 255, 0.45);
}

.btn-ghost {
  background: transparent;
  font-weight: 500;
  font-size: 0.85rem;
}

.btn-small {
  padding: 8px 10px;
  font-size: 0.78rem;
}

.screen-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.screen-head h2 {
  margin: 0;
  font-size: 1.15rem;
}

.map-stages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  overflow: auto;
}

.map-stage {
  text-align: left;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

.map-stage--locked {
  opacity: 0.45;
  cursor: not-allowed;
}

.screen-tutorial {
  position: relative;
  width: min(100vw, 480px);
  min-height: min(100dvh, 900px);
}

.tutorial-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(1.05);
  z-index: 0;
}

.tutorial-panel {
  position: relative;
  z-index: 1;
  margin-top: auto;
  padding: 20px 18px max(24px, env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(7, 10, 16, 0.94) 60%, transparent);
}

.tutorial-panel h2 {
  margin: 0 0 10px;
  font-size: 1.2rem;
}

.tutorial-body {
  margin: 0 0 16px;
  color: #c8d2e8;
  font-size: 0.9rem;
  line-height: 1.5;
}

/* Step accents: `highlight` in campaign TUTORIAL_SCRIPT → class tutorial-focus-* on #screen-tutorial */
.screen-tutorial.tutorial-focus-content .tutorial-panel {
  box-shadow: 0 -1px 0 0 rgba(177, 140, 255, 0.55), inset 0 1px 0 0 rgba(177, 140, 255, 0.12);
}
.screen-tutorial.tutorial-focus-match3 .tutorial-panel {
  box-shadow: 0 -1px 0 0 rgba(244, 91, 105, 0.65), inset 0 1px 0 0 rgba(244, 91, 105, 0.12);
}
.screen-tutorial.tutorial-focus-match4 .tutorial-panel {
  box-shadow: 0 -1px 0 0 rgba(248, 205, 83, 0.65), inset 0 1px 0 0 rgba(248, 205, 83, 0.12);
}
.screen-tutorial.tutorial-focus-match5 .tutorial-panel {
  box-shadow: 0 -1px 0 0 rgba(91, 168, 255, 0.65), inset 0 1px 0 0 rgba(91, 168, 255, 0.12);
}
.screen-tutorial.tutorial-focus-shells .tutorial-panel {
  box-shadow: 0 -1px 0 0 rgba(180, 190, 210, 0.55), inset 0 1px 0 0 rgba(180, 190, 210, 0.12);
}
.screen-tutorial.tutorial-focus-rainbow .tutorial-panel {
  box-shadow: 0 -1px 0 0 rgba(76, 213, 143, 0.65), inset 0 1px 0 0 rgba(76, 213, 143, 0.12);
}
.screen-tutorial.tutorial-focus-shuffle .tutorial-panel {
  box-shadow: 0 -1px 0 0 rgba(255, 160, 90, 0.6), inset 0 1px 0 0 rgba(255, 160, 90, 0.12);
}
.screen-tutorial.tutorial-focus-stuck .tutorial-panel {
  box-shadow: 0 -1px 0 0 rgba(255, 120, 200, 0.5), inset 0 1px 0 0 rgba(255, 120, 200, 0.1);
}
.screen-tutorial.tutorial-focus-map .tutorial-panel {
  box-shadow: 0 -1px 0 0 rgba(107, 159, 255, 0.65), inset 0 1px 0 0 rgba(107, 159, 255, 0.12);
}

.screen-game.screen-game--celebrating .topbar,
.screen-game.screen-game--celebrating .bonus-bar,
.screen-game.screen-game--celebrating .game-stage-hint,
.screen-game.screen-game--celebrating .help,
.screen-game.screen-game--celebrating #board-wrap {
  opacity: 0;
  pointer-events: none;
}

.gallery-root {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.gallery-decks {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px 0 12px;
}

.gallery-deck-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.05), rgba(0, 0, 0, 0.22));
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.gallery-deck-card:active {
  transform: scale(0.99);
}

.gallery-deck-strip {
  display: flex;
  gap: 6px;
  justify-content: space-between;
}

.gallery-deck-thumb {
  flex: 1;
  aspect-ratio: 3 / 4;
  border-radius: 8px;
  overflow: hidden;
  background: #0a0e18;
  border: 1px solid rgba(255, 255, 255, 0.08);
  min-width: 0;
}

.gallery-deck-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-deck-thumb--empty {
  background: repeating-linear-gradient(
    -12deg,
    rgba(255, 255, 255, 0.04),
    rgba(255, 255, 255, 0.04) 6px,
    rgba(0, 0, 0, 0.12) 6px,
    rgba(0, 0, 0, 0.12) 12px
  );
}

.gallery-deck-caption {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}

.gallery-zoom {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  background: var(--bg, #0a0c12);
  padding: 8px 0 0;
}

.gallery-zoom[hidden] {
  display: none;
}

.gallery-zoom-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.gallery-zoom-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  flex: 1;
}

.gallery-zoom-grid {
  flex: 1;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  align-content: start;
  padding-bottom: 12px;
}

.gallery-zoom-cell {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 0;
  background: #0e1320;
  cursor: pointer;
  color: inherit;
  font: inherit;
}

.gallery-zoom-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-zoom-cell--empty {
  cursor: default;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  color: var(--muted);
  padding: 8px;
  text-align: center;
}

.gallery-lightbox {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.88);
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.gallery-lightbox[hidden] {
  display: none;
}

.gallery-lightbox-img {
  max-width: 100%;
  max-height: min(88vh, 900px);
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.65);
}

.gallery-lightbox-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.screen-game {
  width: min(100vw, 480px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1rem, 4vw, 1.5rem);
}

.stats {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: clamp(0.72rem, 3vw, 0.88rem);
  gap: 4px;
  color: var(--muted);
}

.game-level-num {
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.03em;
}

.game-stage-hint {
  margin: 0 0 8px;
  font-size: clamp(0.72rem, 3vw, 0.82rem);
  color: var(--muted);
  line-height: 1.35;
}

.bonus-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.board-wrap {
  flex: 1;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  aspect-ratio: 9 / 10;
  max-height: min(72dvh, 560px);
}

#board {
  display: block;
  touch-action: none;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #0e1320;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
}

.help {
  margin: 8px 2px 0;
  color: var(--muted);
  font-size: clamp(0.68rem, 3vw, 0.82rem);
  flex-shrink: 0;
  line-height: 1.4;
}

.celebration-overlay {
  position: fixed;
  inset: 0;
  z-index: -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease, visibility 0.35s;
}

.celebration-dismiss {
  position: absolute;
  inset: 0;
  z-index: 500;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  cursor: pointer;
  opacity: 0;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}

.celebration-overlay--visible {
  /* Above .screen--active (260) so win dismiss receives taps; must not stay below the game canvas. */
  z-index: 600;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  cursor: pointer;
}

.celebration-overlay--minimal .celebration-confetti,
.celebration-overlay--minimal .celebration-flash,
.celebration-overlay--minimal .celebration-vignette,
.celebration-overlay--minimal .celebration-label {
  display: none !important;
}

.celebration-overlay--minimal.celebration-overlay--visible {
  background: radial-gradient(ellipse 120% 90% at 50% 40%, #121a2e 0%, #05070e 72%);
}

.celebration-vignette {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: radial-gradient(circle at 50% 45%, transparent 0%, rgba(0, 0, 0, 0.1) 38%, rgba(0, 0, 0, 0.82) 100%);
  opacity: 0;
  transition: opacity 0.5s ease 0.15s;
  pointer-events: none;
}

.celebration-vignette--on {
  opacity: 1;
}

.celebration-flash {
  position: absolute;
  inset: 0;
  z-index: 6;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

.celebration-flash--bang {
  animation: photo-flash 0.55s ease-out forwards;
}

@keyframes photo-flash {
  0% {
    opacity: 0;
  }
  15% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.celebration-frame {
  position: relative;
  z-index: 2;
  width: min(88vw, 380px);
  border-radius: 12px;
  overflow: visible;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

.celebration-confetti {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  overflow: hidden;
}

.confetti-bit {
  position: absolute;
  top: -6%;
  left: var(--left, 50%);
  width: 8px;
  height: 11px;
  border-radius: 2px;
  background: var(--color, #f2f6ff);
  opacity: 0.95;
  box-shadow: 0 0 1px rgba(0, 0, 0, 0.25);
  animation: confetti-fall var(--dur, 2s) cubic-bezier(0.33, 0.66, 0.42, 0.98) var(--delay, 0s) forwards;
}

@keyframes confetti-fall {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
    opacity: 1;
  }
  85% {
    opacity: 0.92;
  }
  100% {
    transform: translate3d(var(--drift, 0px), 110vh, 0) rotate(720deg);
    opacity: 0;
  }
}

.celebration-image {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
  opacity: 0;
  transform: scale(0.94);
  transition: opacity 0.45s ease, transform 0.55s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.celebration-overlay--visible .celebration-image {
  opacity: 1;
  transform: scale(1.04);
}

.celebration-image.celebration-image--pop {
  animation: wiggle-float 2.8s ease-in-out 0.5s infinite;
}

@keyframes wiggle-float {
  0%,
  100% {
    transform: scale(1.06) rotate(-0.8deg) translateY(0);
  }
  50% {
    transform: scale(1.07) rotate(0.8deg) translateY(-6px);
  }
}

.celebration-label {
  position: relative;
  z-index: 5;
  margin: 18px 16px 0;
  text-align: center;
  font-size: 0.95rem;
  color: #e8ecf7;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.65);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.4s ease 0.35s, transform 0.4s ease 0.35s;
  pointer-events: none;
}

.celebration-label--on {
  opacity: 1;
  transform: translateY(0);
}
