/* =========================================================
   WIPuzzle — style.css
   Design tokens
   Background: deep indigo void (evokes a portal / omnitrix core)
   Accent duo: aurora teal + violet, gold reserved for stars/score
   Signature element: the empty tile glows like a soft portal void,
   and a light-sweep "assembly ripple" plays across the board on win.
   ========================================================= */

:root {
  --bg-deep: #0b0e1a;
  --bg-panel: #131a2b;
  --bg-panel-2: #1a2338;
  --accent-teal: #5eead4;
  --accent-violet: #a78bfa;
  --accent-gold: #fbbf24;
  --text-primary: #f1f5f9;
  --text-muted: #94a3b8;
  --danger: #fb7185;
  --success: #34d399;

  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;
  --tile-gap: 6px;

  --shadow-soft: 0 8px 30px rgba(0, 0, 0, 0.35);
  --border-glass: 1px solid rgba(255, 255, 255, 0.08);

  --font-display: 'Segoe UI', 'Avenir Next', system-ui, -apple-system, sans-serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', sans-serif;

  color-scheme: dark;
}

[data-theme="light"] {
  --bg-deep: #eef1f9;
  --bg-panel: #ffffff;
  --bg-panel-2: #f3f5fb;
  --text-primary: #12172b;
  --text-muted: #5b6578;
  --shadow-soft: 0 8px 24px rgba(30, 41, 82, 0.12);
  --border-glass: 1px solid rgba(20, 25, 50, 0.08);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  background:
    radial-gradient(1200px 800px at 50% -10%, rgba(167, 139, 250, 0.18), transparent 60%),
    radial-gradient(900px 700px at 100% 100%, rgba(94, 234, 212, 0.12), transparent 55%),
    var(--bg-deep);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  min-height: 100vh;
  min-height: 100dvh;
}

button {
  font-family: inherit;
  color: inherit;
  cursor: pointer;
}

img { max-width: 100%; display: block; }

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  padding-bottom: env(safe-area-inset-bottom);
}

.screen { display: none; padding: 20px 18px calc(24px + env(safe-area-inset-bottom)); min-height: 100dvh; }
.screen.is-active { display: flex; flex-direction: column; }

/* ---------------- Icon buttons / generic controls ---------------- */

.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.06);
  border: var(--border-glass);
  border-radius: 50%;
  backdrop-filter: blur(10px);
  transition: transform 0.15s ease, background 0.15s ease;
}
.icon-btn:active { transform: scale(0.92); background: rgba(255, 255, 255, 0.12); }

.icon { width: 22px; height: 22px; color: var(--text-primary); }
.icon--sm { width: 16px; height: 16px; }
.icon--lg { width: 40px; height: 40px; color: var(--text-muted); }

.ctrl-btn {
  border: var(--border-glass);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 13px 18px;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  backdrop-filter: blur(10px);
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.ctrl-btn:active { transform: scale(0.96); }
.ctrl-btn--primary {
  background: linear-gradient(135deg, var(--accent-teal), var(--accent-violet));
  color: #0b0e1a;
  box-shadow: 0 6px 20px rgba(94, 234, 212, 0.25);
  border: none;
}
.ctrl-btn--ghost { background: transparent; }

/* ---------------- Home / world map ---------------- */

.home__header { display: flex; align-items: center; justify-content: space-between; padding: 6px 2px 18px; }
.home__brand { display: flex; align-items: center; gap: 10px; }
.home__logo {
  width: 30px; height: 30px;
  border-radius: 8px;
  object-fit: cover;
  filter: drop-shadow(0 0 10px rgba(94, 234, 212, 0.5));
}
.home__title { font-family: var(--font-display); font-size: 24px; font-weight: 800; letter-spacing: 0.5px; margin: 0; }
.home__title span { color: var(--accent-teal); }

.home__stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 22px; }
.stat-chip {
  background: rgba(255, 255, 255, 0.05);
  border: var(--border-glass);
  border-radius: var(--radius-md);
  padding: 12px 8px;
  text-align: center;
  backdrop-filter: blur(10px);
}
.stat-chip__value { display: block; font-size: 20px; font-weight: 800; font-family: var(--font-display); color: var(--accent-gold); }
.stat-chip__label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

.worlds { display: flex; flex-direction: column; gap: 26px; flex: 1; }
.world { }
.world__header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.world__name { font-family: var(--font-display); font-size: 17px; font-weight: 700; }
.world__difficulty { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.level-node {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: var(--border-glass);
  background-color: rgba(255, 255, 255, 0.04);
  background-size: cover;
  background-position: center;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  gap: 1px;
  position: relative;
  overflow: hidden;
  color: white;
  transition: transform 0.15s ease;
}
.level-node:active { transform: scale(0.93); }
.level-node__scrim {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(6,8,16,0.05) 40%, rgba(6,8,16,0.65) 100%);
}
.level-node__num, .level-node__stars, .level-node__lock { position: relative; z-index: 1; }
.level-node__num { font-weight: 800; font-size: 14px; padding-bottom: 2px; text-shadow: 0 1px 3px rgba(0,0,0,0.6); }
.level-node__stars { font-size: 8px; color: var(--accent-gold); letter-spacing: 1px; padding-bottom: 3px; text-shadow: 0 1px 2px rgba(0,0,0,0.6); }

.level-node--locked .level-node__scrim { background: rgba(6, 8, 16, 0.68); }
.level-node--locked .level-node__num,
.level-node--locked .level-node__stars { display: none; }
.level-node__lock {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 18px; height: 18px;
  color: rgba(255,255,255,0.92);
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
  z-index: 1;
}

.level-node--current {
  border-color: var(--accent-teal);
  box-shadow: 0 0 0 2px rgba(94, 234, 212, 0.45), 0 0 18px rgba(94, 234, 212, 0.45);
}
.level-node--completed .level-node__scrim {
  background: linear-gradient(180deg, rgba(94, 234, 212, 0.05) 30%, rgba(6,8,16,0.7) 100%);
}
.level-node--completed {
  box-shadow: 0 0 0 1px rgba(94, 234, 212, 0.3);
}

/* ---------------- Game screen ---------------- */

/* ---------------- Gameplay header (Back | Logo | Target) ----------------
   Requirement: back button on the left, game logo centered, and a large
   target-image preview on the right — visible without scrolling. */

.game__topbar { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 10px; padding-bottom: 12px; }

.game__brand { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.game__brand-logo {
  width: 26px; height: 26px;
  border-radius: 7px;
  object-fit: cover;
  filter: drop-shadow(0 0 8px rgba(94, 234, 212, 0.5));
}
.game__brand-title { font-family: var(--font-display); font-size: 12px; font-weight: 800; letter-spacing: 0.04em; color: var(--text-muted); }
.game__brand-title span { color: var(--accent-teal); }

.game__target {
  position: relative;
  width: 56px; height: 56px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255,255,255,0.25);
  justify-self: end;
  transition: transform 0.15s ease;
}
.game__target:active { transform: scale(0.94); }
.game__target img { width: 100%; height: 100%; object-fit: cover; }
.game__target-label {
  position: absolute; left: 0; right: 0; bottom: 0;
  font-size: 8px; text-transform: uppercase; letter-spacing: 0.08em;
  text-align: center; padding: 2px 0;
  background: rgba(0,0,0,0.55);
  color: rgba(255,255,255,0.9);
}

.game__subbar { display: flex; align-items: center; justify-content: space-between; padding-bottom: 14px; }
.game__title { text-align: left; display: flex; flex-direction: column; }
.game__world { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.game__level { font-family: var(--font-display); font-weight: 800; font-size: 16px; }

.game__hud { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.hud-chip {
  background: rgba(255, 255, 255, 0.05);
  border: var(--border-glass);
  border-radius: var(--radius-sm);
  padding: 8px 6px;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  font-size: 13px; font-weight: 700;
  backdrop-filter: blur(10px);
}
.hud-chip--stars { gap: 1px; }
.hud-chip--stars .star { color: rgba(255,255,255,0.18); font-size: 15px; }
.hud-chip--stars .star.is-lit { color: var(--accent-gold); text-shadow: 0 0 8px rgba(251, 191, 36, 0.7); }

/* ---------------- Puzzle frame (classic handheld toy layout) ----------------
   A single solid "physical case" — thick rounded plastic borders, soft
   glossy highlights, inner/outer shadows — that holds a FUNCTIONAL
   holding slot above a perfectly square NxN tile grid. The holding slot
   is a real gameplay position (see engine.js / board.js): it connects to
   exactly one column of the board (the "anchor" column), and its
   horizontal position is kept pixel-aligned to that column via
   --slot-offset, set by board.js on every layout pass. */

.game__board-wrap {
  position: relative;
  width: 100%;
  margin-bottom: 14px;
}

.puzzle-frame {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--tile-gap);
  background: linear-gradient(160deg, var(--accent-violet), var(--accent-teal));
  border-radius: calc(var(--radius-lg) + 6px);
  padding: 16px;
  border: 3px solid rgba(255, 255, 255, 0.35);
  box-shadow:
    0 20px 40px rgba(0, 0, 0, 0.45),
    0 2px 0 rgba(0, 0, 0, 0.25),
    inset 0 3px 0 rgba(255, 255, 255, 0.4),
    inset 0 -10px 20px rgba(0, 0, 0, 0.22),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  isolation: isolate; /* own stacking context so tiles floating above the grid layer correctly over the slot */
}
.puzzle-frame::before {
  /* Soft glossy highlight sweeping across the top of the case, like
     molded, polished plastic catching the light. */
  content: '';
  position: absolute;
  top: 6px; left: 10%; right: 10%;
  height: 30%;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255,255,255,0.35), transparent);
  filter: blur(6px);
  pointer-events: none;
  z-index: 0;
}

.puzzle-frame__slot-row {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: flex-start;
  min-height: var(--cell-size, 60px);
}

/* The holding slot: a FUNCTIONAL gameplay position (not decorative) —
   the tile currently stored here is rendered by board.js directly above
   this fixture. Styled to look like a recessed plastic tray when empty,
   with the same premium bevel/gloss language as a real tile. Dimensions
   come from the same --cell-size the board sets on every layout pass, so
   it is always pixel-identical to a real tile; --slot-offset aligns it
   horizontally with the exact board column it connects to. */
.holding-slot {
  width: var(--cell-size, 60px);
  height: var(--cell-size, 60px);
  margin-left: var(--slot-offset, 0px);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.28);
  box-shadow:
    inset 0 4px 10px rgba(0, 0, 0, 0.55),
    inset 0 -1px 0 rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(0, 0, 0, 0.3);
  position: relative;
  transition: box-shadow 0.2s ease;
}
.holding-slot--missing { background: rgba(0, 0, 0, 0.18); }

.puzzle-board-host {
  position: relative;
  z-index: 1;
  width: 100%;
  aspect-ratio: 1;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-md);
  box-shadow: inset 0 3px 12px rgba(0, 0, 0, 0.45);
  overflow: visible; /* tiles sliding into/out of the holding slot render above this box */
}

.tile {
  position: absolute;
  top: 0; left: 0;
  border: none;
  border-radius: var(--radius-sm);
  background-color: var(--bg-panel-2);
  background-repeat: no-repeat;
  /* Physical plastic-piece look: crisp bevel edge, soft drop shadow,
     subtle top-edge gloss highlight, slight depth. */
  box-shadow:
    0 3px 8px rgba(0, 0, 0, 0.4),
    0 1px 0 rgba(0, 0, 0, 0.25),
    inset 0 0 0 2px rgba(255, 255, 255, 0.55),
    inset 0 2px 3px rgba(255, 255, 255, 0.35),
    inset 0 -3px 5px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s cubic-bezier(0.34, 1.1, 0.4, 1);
  will-change: transform;
  padding: 0;
  overflow: hidden;
  z-index: 2;
  backface-visibility: hidden;
}
.tile::after {
  /* Glossy highlight sweep across the top third of every tile. */
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.22) 0%, rgba(255,255,255,0) 38%);
  pointer-events: none;
}
.tile:active { filter: brightness(1.08); }
.tile--holding { z-index: 3; }

.tile__fallback-number {
  position: absolute;
  z-index: 1;
  bottom: 4px; right: 6px;
  font-size: 10px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.55);
  background: rgba(0, 0, 0, 0.35);
  border-radius: 4px;
  padding: 1px 4px;
  pointer-events: none;
  opacity: 0; /* visible only while dev has no image, toggled via CSS below */
}
.puzzle-board--missing .tile { background-image: none !important; background-color: var(--bg-panel-2); }
.puzzle-board--missing .tile__fallback-number { opacity: 1; font-size: 22px; inset: 0; bottom: auto; right: auto; display: grid; place-items: center; background: transparent; }

@keyframes tile-shake {
  0%, 100% { }
  25% { filter: brightness(1.15); }
  50% { filter: brightness(1); }
  75% { filter: brightness(1.15); }
}
.tile--shake { animation: tile-shake 0.22s ease; }

/* Signature "assembly ripple": a brief light sweep across every tile the
   moment the puzzle is solved, before the victory modal takes over. */
@keyframes solved-pulse {
  0% { box-shadow: 0 3px 8px rgba(0,0,0,0.4), inset 0 0 0 2px rgba(255,255,255,0.55), 0 0 0 rgba(94,234,212,0); }
  35% { box-shadow: 0 4px 18px rgba(94,234,212,0.4), inset 0 0 0 2px rgba(255,255,255,0.8), 0 0 24px rgba(94,234,212,0.6); }
  100% { box-shadow: 0 3px 8px rgba(0,0,0,0.4), inset 0 0 0 2px rgba(255,255,255,0.55), 0 0 0 rgba(94,234,212,0); }
}
.puzzle-board--solved .tile { animation: solved-pulse 0.9s ease-out; }

.missing-image-note {
  position: absolute; inset: 10px;
  display: none;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 20px;
  border-radius: var(--radius-md);
  background: rgba(0,0,0,0.15);
  z-index: 2;
}
.missing-image-note code {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent-teal);
}
.board-wrap--missing .missing-image-note { display: flex; }
.board-wrap--missing .puzzle-board-host { visibility: hidden; }

/* ---------------- Loading skeleton ---------------- */

.board-skeleton {
  position: absolute; inset: 10px;
  display: none;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 14px;
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.1);
  z-index: 3;
}
.board-wrap--skeleton .board-skeleton { display: flex; }
.board-wrap--skeleton .puzzle-board-host { visibility: hidden; }

.board-skeleton__grid {
  position: absolute; inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--grid-size, 3), 1fr);
  grid-template-rows: repeat(var(--grid-size, 3), 1fr);
  gap: var(--tile-gap);
  padding: 0;
}
.board-skeleton__cell {
  border-radius: var(--radius-sm);
  background: linear-gradient(100deg, var(--bg-panel-2) 30%, rgba(255,255,255,0.09) 50%, var(--bg-panel-2) 70%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}
@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.board-skeleton__spinner {
  position: relative;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent-teal);
  animation: spin 0.8s linear infinite;
  z-index: 1;
}
@keyframes spin { to { transform: rotate(360deg); } }

.board-skeleton__label {
  z-index: 1;
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(0,0,0,0.4);
  padding: 4px 10px;
  border-radius: 999px;
  backdrop-filter: blur(6px);
}

.game__controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: auto; }

/* ---------------- Overlays ---------------- */

.overlay {
  position: fixed; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  background: rgba(6, 8, 16, 0.72);
  backdrop-filter: blur(6px);
  z-index: 50;
  padding: 20px;
}
.overlay.is-active { display: flex; }

.pause-card, .settings-card {
  background: var(--bg-panel);
  border: var(--border-glass);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow-soft);
  position: relative;
  z-index: 2;
  animation: card-pop 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes card-pop {
  from { opacity: 0; transform: scale(0.9) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.confetti-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }

/* ---------------- Victory Modal ----------------
   The completed image is the hero: a large tappable frame fills the top
   of the card, with the stats and actions sitting underneath it. */

.overlay--victory { align-items: stretch; padding: 0; }
.victory-modal {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 460px;
  margin: auto;
  max-height: min(92dvh, 820px);
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border: var(--border-glass);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  animation: card-pop 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.victory-modal__hero {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  flex-shrink: 0;
  background: var(--bg-panel-2);
}
.victory-modal__hero-btn {
  position: relative;
  display: block;
  width: 100%; height: 100%;
  border: none;
  padding: 0;
  background: none;
}
.victory-modal__hero-btn img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.victory-modal__hero-btn::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(11,14,26,0) 55%, rgba(11,14,26,0.85) 100%);
}
.victory-modal__hero-hint {
  position: absolute;
  right: 12px; bottom: 12px;
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(11, 14, 26, 0.55);
  border: 1px solid rgba(255,255,255,0.15);
  color: white;
  font-size: 12px; font-weight: 600;
  padding: 7px 12px;
  border-radius: 999px;
  backdrop-filter: blur(8px);
}

.victory-modal__body {
  padding: 20px 22px calc(20px + env(safe-area-inset-bottom));
  text-align: center;
  overflow-y: auto;
}

.victory-modal__badge {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 21px;
  background: linear-gradient(135deg, var(--accent-teal), var(--accent-violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.victory-modal__meta { font-size: 12px; color: var(--text-muted); margin: 4px 0 12px; text-transform: uppercase; letter-spacing: 0.06em; }

.win-card__stars { font-size: 34px; letter-spacing: 6px; color: rgba(255,255,255,0.15); margin-bottom: 14px; }
.win-card__stars .star.is-lit { color: var(--accent-gold); text-shadow: 0 0 14px rgba(251, 191, 36, 0.8); animation: star-in 0.4s ease backwards; }
.win-card__stars .star:nth-child(1).is-lit { animation-delay: 0.05s; }
.win-card__stars .star:nth-child(2).is-lit { animation-delay: 0.2s; }
.win-card__stars .star:nth-child(3).is-lit { animation-delay: 0.35s; }
@keyframes star-in { from { transform: scale(0) rotate(-30deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }

.win-card__stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.win-stat { background: rgba(255,255,255,0.04); border-radius: var(--radius-sm); padding: 10px 4px; }
.win-stat__label { display: block; font-size: 10px; color: var(--text-muted); text-transform: uppercase; }
.win-stat__value { font-family: var(--font-display); font-weight: 800; font-size: 17px; }
.win-card__record { font-size: 12px; color: var(--accent-teal); min-height: 16px; margin: 0 0 12px; }

.victory-modal__achievements {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px;
  margin-bottom: 14px;
}
.achievement-chip {
  font-size: 11px; font-weight: 700;
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.18), rgba(167, 139, 250, 0.14));
  border: 1px solid rgba(251, 191, 36, 0.35);
  color: var(--accent-gold);
  padding: 6px 10px;
  border-radius: 999px;
  animation: star-in 0.4s ease backwards;
}

.victory-modal__actions { display: flex; flex-direction: column; gap: 8px; }
.victory-modal__actions .ctrl-btn { width: 100%; }

/* ---------------- Fullscreen Image Viewer ---------------- */

.overlay--viewer {
  background: rgba(4, 5, 10, 0.88);
  backdrop-filter: blur(14px);
  padding: 0;
}
.viewer-stage {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  touch-action: none;
}
.viewer-image {
  max-width: 92vw;
  max-height: 92dvh;
  border-radius: 10px;
  will-change: transform;
  transform-origin: center center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  opacity: 0;
  transform: scale(0.92);
  transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.2,0.8,0.3,1);
}
.overlay--viewer.is-open .viewer-image { opacity: 1; transform: scale(1); }

.viewer-close {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  right: 14px;
  z-index: 3;
  background: rgba(255,255,255,0.08);
}

.pause-card h2, .settings-card h2 { font-family: var(--font-display); margin-top: 0; }
.pause-card { display: flex; flex-direction: column; gap: 10px; }

.settings-card { text-align: left; }
.setting-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid rgba(255,255,255,0.06); font-size: 14px; }
.setting-row .slider { width: 130px; }
.settings-card__stats { font-size: 12px; color: var(--text-muted); padding: 12px 0; line-height: 1.6; }
.settings-card > .ctrl-btn { width: 100%; margin-top: 14px; }

.switch { position: relative; width: 44px; height: 26px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch__track { position: absolute; inset: 0; background: rgba(255,255,255,0.15); border-radius: 999px; transition: background 0.2s; }
.switch__track::before { content: ''; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: white; border-radius: 50%; transition: transform 0.2s; }
.switch input:checked + .switch__track { background: linear-gradient(135deg, var(--accent-teal), var(--accent-violet)); }
.switch input:checked + .switch__track::before { transform: translateX(18px); }

.slider { -webkit-appearance: none; height: 4px; border-radius: 2px; background: rgba(255,255,255,0.15); }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--accent-teal); cursor: pointer; }

.segmented { display: flex; background: rgba(255,255,255,0.06); border-radius: 999px; padding: 3px; gap: 2px; }
.segmented__btn { border: none; background: transparent; color: var(--text-muted); font-size: 12px; font-weight: 600; padding: 6px 10px; border-radius: 999px; }
.segmented__btn.is-active { background: var(--bg-panel-2); color: var(--text-primary); }

.toast {
  position: fixed;
  left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-panel-2);
  border: var(--border-glass);
  color: var(--text-primary);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 80;
  box-shadow: var(--shadow-soft);
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

.install-fab {
  position: fixed;
  right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(135deg, var(--accent-teal), var(--accent-violet));
  color: #0b0e1a;
  border: none;
  border-radius: 999px;
  padding: 12px 16px;
  font-weight: 700;
  font-size: 13px;
  display: flex; align-items: center; gap: 6px;
  box-shadow: 0 8px 22px rgba(94, 234, 212, 0.35);
  z-index: 60;
  animation: install-fab-in 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.install-fab[hidden] { display: none; }
@keyframes install-fab-in { from { opacity: 0; transform: translateY(12px) scale(0.9); } to { opacity: 1; transform: translateY(0) scale(1); } }

@media (min-width: 720px) {
  .app { max-width: 640px; }
  .game__board-wrap { max-width: 480px; margin-left: auto; margin-right: auto; }
}

/* ---------------- Custom Puzzle CTA (home screen) ---------------- */

.custom-cta {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: linear-gradient(135deg, rgba(94, 234, 212, 0.14), rgba(167, 139, 250, 0.14));
  border: 1px dashed rgba(255, 255, 255, 0.22);
  border-radius: var(--radius-md);
  padding: 14px 14px;
  margin-bottom: 22px;
  transition: transform 0.15s ease, background 0.15s ease;
}
.custom-cta:active { transform: scale(0.98); }
.custom-cta__icon {
  width: 40px; height: 40px;
  flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.08);
  color: var(--accent-teal);
}
.custom-cta__text { flex: 1; display: flex; flex-direction: column; gap: 1px; }
.custom-cta__title { font-family: var(--font-display); font-weight: 800; font-size: 14px; }
.custom-cta__sub { font-size: 11px; color: var(--text-muted); }
.custom-cta__chevron { color: var(--text-muted); flex-shrink: 0; }

/* ---------------- Custom Puzzle setup screen ---------------- */

.custom__topbar { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; padding-bottom: 18px; }
.custom__title { font-family: var(--font-display); font-size: 17px; font-weight: 800; text-align: center; margin: 0; }
.custom__topbar-spacer { width: 44px; }

.custom-picker {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 20px;
}
.custom-picker__icon { color: var(--text-muted); }
.custom-picker__lede { color: var(--text-muted); font-size: 13px; max-width: 260px; margin: 0; }
.custom-picker__btn { padding: 14px 28px; margin-top: 6px; }
.custom-picker__hint { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

.custom-editor { display: flex; flex-direction: column; align-items: center; gap: 14px; flex: 1; }

.custom-crop-frame {
  position: relative;
  width: 100%;
  max-width: 380px;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: var(--radius-md);
  border: 3px solid rgba(255, 255, 255, 0.35);
  box-shadow: var(--shadow-soft), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.3);
  touch-action: none;
}
.custom-crop-frame img {
  position: absolute;
  top: 0; left: 0;
  max-width: none;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
}
.custom-crop-frame__grid {
  position: absolute; inset: 0;
  pointer-events: none;
  opacity: 0.55;
  background-image:
    linear-gradient(to right, rgba(255,255,255,0.28) 1px, transparent 1px),
    linear-gradient(to right, rgba(255,255,255,0.28) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,0.28) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,0.28) 1px, transparent 1px);
  background-position: 33.333% 0, 66.666% 0, 0 33.333%, 0 66.666%;
  background-size: 1px 100%, 1px 100%, 100% 1px, 100% 1px;
  background-repeat: no-repeat;
}

.custom-editor__hint { font-size: 12px; color: var(--text-muted); margin: 0; text-align: center; }

.custom-editor__zoom { display: flex; align-items: center; gap: 10px; width: 100%; max-width: 380px; color: var(--text-muted); }
.custom-editor__zoom .slider { flex: 1; }

.custom-editor__actions { display: flex; gap: 8px; width: 100%; max-width: 380px; }
.custom-editor__actions .ctrl-btn { flex: 1; }

.custom-difficulty { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 8px; }
.custom-difficulty__label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.segmented--wide { width: 100%; }
.segmented--wide .segmented__btn { flex: 1; text-align: center; }

.custom-start-btn { width: 100%; max-width: 380px; margin-top: auto; margin-bottom: 4px; }

/* ---------------- Settings sections ---------------- */

.settings-section { margin-bottom: 6px; }
.settings-section__title {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-teal);
  margin: 14px 0 2px;
}
.settings-section:first-of-type .settings-section__title { margin-top: 4px; }

/* ---------------- Boot / first-launch download screen ----------------
   Shown ONLY on the very first launch while assets are actually being
   downloaded — a premium animated game-boot experience, never a
   developer-facing cache log. No filenames or technical text are ever
   displayed here (see ui.js rotating friendly messages). */

.boot-screen {
  position: fixed; inset: 0;
  z-index: 999;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px;
  overflow: hidden;
  background:
    radial-gradient(1200px 800px at 50% -10%, rgba(167, 139, 250, 0.22), transparent 60%),
    radial-gradient(900px 700px at 100% 100%, rgba(94, 234, 212, 0.16), transparent 55%),
    var(--bg-deep);
  background-size: 200% 200%;
  animation: boot-gradient-drift 12s ease-in-out infinite;
  transition: opacity 0.4s ease;
}
@keyframes boot-gradient-drift {
  0%, 100% { background-position: 0% 0%, 100% 100%, 0 0; }
  50% { background-position: 20% 10%, 80% 90%, 0 0; }
}
.boot-screen--done { opacity: 0; pointer-events: none; }

.boot-bg { position: absolute; inset: 0; z-index: 0; overflow: hidden; }
.boot-particle {
  position: absolute;
  bottom: -10%;
  left: calc(10% + (var(--i) * 15%));
  width: 6px; height: 6px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(94,234,212,0.9), rgba(167,139,250,0.1));
  filter: blur(0.5px);
  opacity: 0.55;
  animation: boot-particle-float calc(9s + var(--i) * 1.3s) ease-in-out infinite;
  animation-delay: calc(var(--i) * -1.6s);
}
@keyframes boot-particle-float {
  0% { transform: translateY(0) scale(0.8); opacity: 0; }
  15% { opacity: 0.6; }
  50% { transform: translateY(-55vh) translateX(12px) scale(1.1); }
  85% { opacity: 0.35; }
  100% { transform: translateY(-105vh) translateX(-8px) scale(0.7); opacity: 0; }
}

.boot-topbar {
  position: relative; z-index: 1;
  width: 100%; max-width: 360px;
  display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  margin-bottom: 40px;
}
.boot-topbar__slot { display: flex; align-items: center; gap: 8px; }
.boot-topbar__slot--target {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.25);
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  background: rgba(255,255,255,0.06);
}
.boot-topbar__slot--target img { width: 100%; height: 100%; object-fit: cover; display: block; }
.boot-topbar__slot--brand { justify-content: center; flex-direction: column; text-align: center; }
.boot-topbar__slot--brand img {
  width: 34px; height: 34px; border-radius: 9px; object-fit: cover;
  filter: drop-shadow(0 0 14px rgba(94, 234, 212, 0.55));
  animation: portal-pulse 2.4s ease-in-out infinite;
}
.boot-brand-title { font-family: var(--font-display); font-size: 13px; font-weight: 800; letter-spacing: 0.04em; margin-top: 4px; }
.boot-brand-title span { color: var(--accent-teal); }
.boot-tagline { display: block; font-size: 11px; color: var(--text-muted); margin-top: 3px; letter-spacing: 0.01em; }
@keyframes portal-pulse { 0%, 100% { opacity: 0.85; transform: scale(1); } 50% { opacity: 1; transform: scale(1.06); } }
.boot-topbar__slot--icon { justify-content: flex-end; }
.boot-topbar__slot--icon img {
  width: 40px; height: 40px; border-radius: var(--radius-sm);
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
}

.boot-card { position: relative; z-index: 1; width: 100%; max-width: 320px; text-align: center; }
.boot-card__subtitle { font-size: 13px; color: var(--text-muted); margin: 14px 0 0; min-height: 18px; transition: opacity 0.25s ease; }

.boot-loader { width: 100%; }
.boot-loader__track {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.4);
}
.boot-loader__fill {
  position: relative;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-teal), var(--accent-violet));
  box-shadow: 0 0 12px rgba(94, 234, 212, 0.55);
  transition: width 0.3s cubic-bezier(0.2, 0.8, 0.3, 1);
  overflow: hidden;
}
.boot-loader__shine {
  position: absolute; top: 0; bottom: 0; left: -40%;
  width: 40%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.65), transparent);
  animation: boot-shine 1.6s ease-in-out infinite;
}
@keyframes boot-shine {
  0% { left: -40%; }
  100% { left: 120%; }
}
.boot-loader__size {
  display: block;
  margin-top: 12px;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  transition: opacity 0.2s ease;
}

.boot-card--ready .boot-loader__fill { box-shadow: 0 0 16px rgba(94, 234, 212, 0.85); }
.boot-card--ready .boot-loader__size { color: var(--accent-teal); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
