/* LUMIFOLK — styles. Dark bioluminescent lagoon; Abyss theme via body.theme-abyss.
   All motion uses transform/opacity only (60fps target). */

:root {
  --bg0: #0d2149;
  --bg1: #071231;
  --bg2: #04091c;
  --ink: #e8f4ff;
  --ink-dim: #9db8d6;
  --panel: rgba(10, 26, 56, 0.72);
  --line: rgba(120, 190, 255, 0.16);
  --accent: #3ec9e6;
  --glow: rgba(62, 201, 230, 0.35);
  --seabed: #0a1b3c;
}
/* ---- world palettes (world-lagoon = :root defaults) ---- */
body.world-reef {
  --bg0: #0b3a50;
  --bg1: #06263c;
  --bg2: #031424;
  --accent: #3ee6b8;
  --glow: rgba(62, 230, 184, 0.35);
  --seabed: #0a2d3c;
}
body.world-polar {
  --bg0: #123862;
  --bg1: #0a2549;
  --bg2: #041430;
  --accent: #a8dcff;
  --glow: rgba(168, 220, 255, 0.38);
  --seabed: #12335c;
}
body.world-vent {
  --bg0: #2e1020;
  --bg1: #1b0913;
  --bg2: #0a0307;
  --accent: #ff7a5c;
  --glow: rgba(255, 122, 92, 0.4);
  --seabed: #26101a;
}
body.world-abyss {
  --bg0: #120b2e;
  --bg1: #090619;
  --bg2: #03020a;
  --accent: #7c5cff;
  --glow: rgba(124, 92, 255, 0.4);
  --seabed: #0d0824;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(180deg, var(--bg0) 0%, var(--bg1) 55%, var(--bg2) 100%);
  overflow: hidden;
  transition: background 0.6s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
#game { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------- logo ---------- */
.logo {
  font-weight: 800; letter-spacing: 0.14em;
  color: var(--ink);
  text-shadow: 0 0 18px var(--glow);
}
.logo span { color: var(--accent); }
h1.logo { font-size: 44px; margin: 0 0 4px; }
.logo-small { font-size: 20px; }

/* ---------- boot ---------- */
#boot {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(120% 90% at 50% 10%, var(--bg0), var(--bg2));
}
#boot-card { text-align: center; padding: 32px; }
#boot h1.logo { animation: logo-breathe 3.2s ease-in-out infinite; }
@keyframes logo-breathe {
  0%, 100% { text-shadow: 0 0 18px var(--glow); }
  50% { text-shadow: 0 0 34px var(--glow), 0 0 10px var(--glow); }
}
#boot-tag { color: var(--ink-dim); margin: 0 0 22px; letter-spacing: 0.08em; }
#boot-bar {
  width: 300px; height: 10px; margin: 0 auto 10px;
  background: rgba(255,255,255,0.1);
  border-radius: 6px; overflow: hidden;
}
#boot-fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), #8be9ff);
  border-radius: 6px;
  transition: width 0.15s;
}
#boot-status { color: var(--ink-dim); font-size: 13px; min-height: 18px; margin-bottom: 22px; }

.big-btn {
  background: linear-gradient(180deg, var(--accent), #2a9cc0);
  color: #04222e; border: 0;
  font-size: 18px; font-weight: 700; letter-spacing: 0.04em;
  padding: 13px 40px; border-radius: 999px; cursor: pointer;
  box-shadow: 0 6px 24px var(--glow);
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s;
}
.big-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 10px 30px var(--glow); }
.big-btn:disabled { opacity: 0.35; cursor: default; }

/* ---------- topbar ---------- */
#topbar {
  position: relative; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
}
#controls { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ctl {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; font-size: 14px; cursor: pointer;
  min-height: 44px; min-width: 44px;
  transition: border-color 0.15s, transform 0.15s, background 0.2s;
}
.ctl:hover { border-color: var(--accent); transform: translateY(-1px); }
.ctl-label { font-size: 13px; }
.theme-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 8px var(--glow);
}
#vol-wrap { display: inline-flex; align-items: center; gap: 6px; padding: 0 6px; min-height: 44px; }
#vol { width: 90px; accent-color: var(--accent); cursor: pointer; }
.popover {
  position: absolute; top: 60px; right: 16px; z-index: 40;
  background: var(--panel); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; display: flex; gap: 10px; align-items: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  animation: pop-in 0.16s ease-out; /* replays whenever [hidden] is lifted */
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
}
.mini-btn {
  background: var(--accent); color: #04222e; border: 0;
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 600;
  min-height: 34px;
}
.mini-btn:hover { filter: brightness(1.1); }
.ctl-slim { padding: 8px 10px; font-size: 16px; }
.ctl:disabled { opacity: 0.35; cursor: default; transform: none; }

/* overflow "…" sheet on narrow screens: secondary controls move in here */
#more-panel {
  flex-direction: column; align-items: stretch; gap: 6px;
  min-width: 210px; max-height: calc(100dvh - 80px); overflow-y: auto;
}
#more-panel .ctl { justify-content: flex-start; width: 100%; }
#more-panel .ctl-label { display: inline !important; font-size: 14px; }
#more-panel #vol-wrap { width: 100%; justify-content: flex-start; padding: 4px 12px; }
#more-panel #vol { flex: 1; width: auto; }

/* world selector */
#world-panel { flex-direction: column; align-items: stretch; gap: 4px; }
.world-opt {
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: 1px solid transparent; border-radius: 10px;
  color: var(--ink); font-size: 14px; padding: 8px 12px; cursor: pointer;
  min-height: 44px;
  transition: background 0.15s, border-color 0.15s;
}
.world-opt:hover { background: rgba(255,255,255,0.06); }
.world-opt.active { border-color: var(--accent); background: rgba(255,255,255,0.05); }
.world-swatch {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.25);
}
.world-opt-lagoon .world-swatch, .swatch-lagoon { background: linear-gradient(135deg, #0d2149, #3ec9e6); }
.world-opt-reef   .world-swatch, .swatch-reef   { background: linear-gradient(135deg, #0b3a50, #3ee6b8); }
.world-opt-polar  .world-swatch, .swatch-polar  { background: linear-gradient(135deg, #123862, #a8dcff); }
.world-opt-vent   .world-swatch, .swatch-vent   { background: linear-gradient(135deg, #2e1020, #ff7a5c); }
.world-opt-abyss  .world-swatch, .swatch-abyss  { background: linear-gradient(135deg, #120b2e, #7c5cff); }

/* preset panel */
#preset-panel { flex-direction: column; align-items: stretch; gap: 2px; max-height: 70vh; overflow-y: auto; }
.preset-opt {
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: 1px solid transparent; border-radius: 10px;
  color: var(--ink); font-size: 14px; padding: 8px 12px; cursor: pointer;
  min-height: 44px; text-align: left;
  transition: background 0.15s, border-color 0.15s;
}
.preset-opt:hover { background: rgba(255,255,255,0.06); border-color: var(--line); }
.preset-name { flex: 1; font-weight: 600; }
.preset-world { font-size: 11px; color: var(--ink-dim); letter-spacing: 0.06em; }

/* ---------- stage ---------- */
#stage-wrap {
  position: relative; flex: 1; min-height: 0;
  display: flex; align-items: flex-end; justify-content: center;
}
#viz { position: absolute; inset: 0; width: 100%; height: 100%; }
/* while a figure menu/pill is open (or hovered), lift the stage above the
   front-particle and combo-FX canvases — z-index inside #stage's stacking
   context can't escape it otherwise (progressive enhancement via :has) */
#stage:has(.slot.menu-open), #stage:has(.slot.occupied:hover) { z-index: 9; }
#stage {
  --slot-gap: clamp(6px, 1.2vw, 16px);
  position: relative; z-index: 5;
  display: flex; gap: var(--slot-gap); align-items: flex-end; justify-content: center;
  padding: 0 12px 4vh;
  width: 100%; max-width: 1200px;
}
.slot {
  position: relative;
  /* never wider than 1/7 of the stage row → a full stage always fits */
  width: min(clamp(88px, 11.5vw, 150px),
             calc((min(100vw, 1200px) - 24px - 6 * var(--slot-gap)) / 7));
  aspect-ratio: 3 / 4;
  border-radius: 16px;
  outline: none;
  cursor: pointer;
  flex: 0 1 auto;
}
.slot::after { /* seabed pad */
  content: "";
  position: absolute; left: 12%; right: 12%; bottom: -6px; height: 12px;
  border-radius: 50%;
  background: radial-gradient(50% 100% at 50% 50%, rgba(62,201,230,0.25), transparent 70%);
}
.slot-glow {
  position: absolute; inset: 0; border-radius: 16px;
  border: 2px dashed rgba(140, 200, 255, 0.28);
  transition: opacity 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.slot.occupied .slot-glow { opacity: 0; }
.slot:focus-visible .slot-glow {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--glow);
  opacity: 1;
}
.slot.drop-hint .slot-glow,
body.placing .slot:not(.occupied) .slot-glow {
  opacity: 1;
  border-color: var(--accent);
  box-shadow: 0 0 22px var(--glow), inset 0 0 18px var(--glow);
  animation: pulse-glow 1s ease-in-out infinite;
}
@keyframes pulse-glow {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}
.figure { position: absolute; inset: 4px; display: flex; align-items: flex-end; }
/* arrival flourish: figure pops in with overshoot, a light ring expands */
.slot.just-placed .figure {
  animation: fig-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: 50% 95%;
}
@keyframes fig-pop {
  0% { transform: scale(0.4); opacity: 0; }
  60% { opacity: 1; }
  100% { transform: scale(1); }
}
.place-ring {
  position: absolute; left: 50%; bottom: 8%;
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--cat, var(--accent));
  box-shadow: 0 0 14px var(--glow);
  pointer-events: none; z-index: 4;
  animation: ring-out 0.55s ease-out forwards;
}
@keyframes ring-out {
  0% { transform: translate(-50%, 50%) scale(0.4); opacity: 0.9; }
  100% { transform: translate(-50%, 50%) scale(4.5); opacity: 0; }
}
.char-svg {
  width: 100%; height: 100%;
  transform-origin: 50% 92%;
  animation: idle 3.4s ease-in-out infinite;
  filter: drop-shadow(0 6px 14px rgba(0, 8, 20, 0.55));
}
.slot.muted .char-svg { opacity: 0.35; filter: grayscale(0.7) drop-shadow(0 6px 14px rgba(0,8,20,0.55)); }
.slot.soloed::before {
  content: "SOLO";
  position: absolute; top: -4px; left: 50%; transform: translateX(-50%);
  font-size: 10px; font-weight: 800; letter-spacing: 0.12em;
  color: var(--accent); text-shadow: 0 0 8px var(--glow);
  z-index: 3;
}
body.paused .char-svg { animation-play-state: paused; }

/* figure hover menu */
.fig-menu {
  position: absolute; top: 2px; left: 50%;
  transform: translate(-50%, -4px);
  display: flex; gap: 5px; z-index: 6;
  opacity: 0; pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
}
.slot.occupied:hover .fig-menu,
.slot.occupied:focus-visible .fig-menu,
.slot.occupied.menu-open .fig-menu {
  opacity: 1; pointer-events: auto; transform: translate(-50%, 0);
}
.fig-btn {
  width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel); color: var(--ink);
  font-size: 12px; font-weight: 700; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.fig-btn:hover { border-color: var(--accent); background: rgba(62,201,230,0.2); }
.slot.muted .fig-mute, .slot.soloed .fig-solo {
  background: var(--accent); color: #04222e; border-color: var(--accent);
}
@media (pointer: coarse) {
  .fig-btn { width: 48px; height: 48px; font-size: 16px; border-radius: 50%; }
  /* touch: no unreliable hover menu — tapping a figure docks an action pill
     top-center of the screen, so edge slots never overflow the viewport.
     display:none while closed: an invisible row would still widen the page. */
  .fig-menu { display: none; }
  .slot.occupied.menu-open .fig-menu {
    display: flex;
    position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 62px);
    transform: translateX(-50%);
    flex-direction: row; gap: 10px;
    background: var(--panel); border: 1px solid var(--line);
    border-radius: 999px; padding: 8px 12px;
    box-shadow: 0 10px 34px rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(8px);
    opacity: 1; pointer-events: auto;
    z-index: 45;
  }
}

/* ---------- icon bar (category tabs + one icon row per category) ---------- */
#iconbar {
  position: relative; z-index: 10;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, rgba(3, 8, 22, 0.85) 30%);
}
.tab-row {
  display: flex; gap: 6px; justify-content: center; flex-wrap: nowrap;
  max-width: 100%; overflow-x: auto;
}
.cat-tab {
  position: relative;
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 44px; padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel); color: var(--ink-dim);
  font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  cursor: pointer; white-space: nowrap;
  transition: border-color 0.15s, background 0.2s, color 0.15s, transform 0.15s;
}
.cat-tab:hover { border-color: var(--cat); transform: translateY(-1px); }
.cat-tab.active {
  border-color: var(--cat); color: var(--ink);
  background: rgba(6, 14, 32, 0.9);
  background: color-mix(in srgb, var(--cat) 20%, rgba(6, 14, 32, 0.9));
  box-shadow: 0 0 14px color-mix(in srgb, var(--cat) 35%, transparent);
}
.tab-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--cat); box-shadow: 0 0 8px var(--cat);
}
.tab-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 999px; font-size: 10px;
  background: var(--cat); color: #041220;
}
.icon-rows { width: 100%; display: flex; justify-content: center; min-height: 86px; }
.cat-row { display: none; gap: 8px; max-width: 100%; overflow-x: auto; padding: 4px 2px; }
.cat-row.active { display: flex; }
/* clean horizontal scrolling on touch: hidden scrollbars, soft edge fade */
.tab-row, .cat-row { scrollbar-width: none; overscroll-behavior-x: contain; }
.tab-row::-webkit-scrollbar, .cat-row::-webkit-scrollbar { display: none; }
@media (max-width: 768px) {
  .tab-row, .cat-row {
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 14px, #000 calc(100% - 14px), transparent);
    mask-image: linear-gradient(90deg, transparent, #000 14px, #000 calc(100% - 14px), transparent);
    padding-left: 8px; padding-right: 8px;
  }
}
.icon {
  position: relative; flex: 0 0 auto;
  width: 60px; height: 78px; border-radius: 14px;
  border: 2px solid var(--cat, #888);
  background: rgba(6, 14, 32, 0.9); /* fallback if color-mix unsupported */
  background: color-mix(in srgb, var(--cat, #888) 16%, rgba(6, 14, 32, 0.9));
  color: var(--cat, #888);
  cursor: grab;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  padding: 4px 2px 3px;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s;
  touch-action: none;
}
.icon:hover:not(.used) {
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 8px 20px color-mix(in srgb, var(--cat) 45%, transparent);
}
.icon-fig { width: 42px; height: 56px; pointer-events: none; display: block; }
.icon-fig .char-svg { animation: none; filter: none; width: 100%; height: 100%; }
.icon-fig .c-glow { animation: none; }
.icon-name {
  font-size: 8px; font-weight: 700; letter-spacing: 0.04em;
  max-width: 56px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--ink-dim); pointer-events: none;
}
.icon.used { opacity: 0.25; cursor: default; transform: none; }
/* touch: larger targets + labels (must come AFTER the base .icon rules —
   media queries add no specificity, source order decides) */
@media (pointer: coarse) {
  .icon { width: 64px; height: 84px; }
  .icon-fig { width: 46px; height: 60px; }
  .icon-name { font-size: 9px; max-width: 60px; }
}
.icon.selected {
  box-shadow: 0 0 0 3px var(--cat), 0 0 24px color-mix(in srgb, var(--cat) 60%, transparent);
  animation: pulse-glow 0.9s ease-in-out infinite;
}
.icon.drag-src { opacity: 0.35; }
.icon.flyback { animation: flyback 0.45s ease; }
@keyframes flyback {
  0% { transform: scale(1.25); opacity: 0.4; }
  100% { transform: scale(1); opacity: 1; }
}
.drag-ghost {
  position: fixed; z-index: 100;
  transform: translate(-50%, -50%) scale(1.15);
  pointer-events: none;
  box-shadow: 0 14px 34px rgba(0,0,0,0.5);
  cursor: grabbing;
}
body.dragging { cursor: grabbing; }

/* ---------- dances (duration set inline from BPM) ---------- */
@keyframes idle {
  0%, 100% { transform: translateY(0) rotate(0deg) scale(1); }
  30% { transform: translateY(-2.2%) rotate(0.8deg) scale(1.008); }
  55% { transform: translateY(-3%) rotate(-0.4deg) scale(1.012); }
  80% { transform: translateY(-1%) rotate(-0.9deg) scale(1.004); }
}
/* stagger idle phase per slot so the lineup never bobs in lockstep */
.slot:nth-child(2n) .char-svg { animation-delay: -1.1s; }
.slot:nth-child(3n) .char-svg { animation-delay: -2.3s; }
.slot:nth-child(5n) .char-svg { animation-delay: -0.6s; }
@keyframes stomp {
  0%, 100% { transform: translateY(0) scaleY(1); }
  20% { transform: translateY(-9%) scaleY(1.04); }
  45% { transform: translateY(0) scaleY(0.93) scaleX(1.06); }
  60% { transform: translateY(-5%) scaleY(1.02); }
  80% { transform: translateY(0) scaleY(0.96) scaleX(1.03); }
}
@keyframes sway {
  0%, 100% { transform: rotate(-5deg) translateY(0); }
  25% { transform: rotate(0deg) translateY(-3%); }
  50% { transform: rotate(5deg) translateY(0); }
  75% { transform: rotate(0deg) translateY(-3%); }
}
@keyframes bounce {
  0%, 100% { transform: translateY(0) scale(1); }
  15% { transform: translateY(-11%) scale(1.02); }
  30% { transform: translateY(0) scaleY(0.94); }
  50% { transform: translateY(-6%); }
  65% { transform: translateY(0) scaleY(0.97); }
  82% { transform: translateY(-3%); }
}
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-7%) rotate(2deg); }
}
@keyframes wiggle {
  0%, 100% { transform: rotate(0deg) skewX(0deg); }
  20% { transform: rotate(4deg) skewX(3deg) translateY(-4%); }
  40% { transform: rotate(-3deg) skewX(-3deg); }
  60% { transform: rotate(4deg) skewX(2deg) translateY(-5%); }
  80% { transform: rotate(-4deg) skewX(-2deg); }
}
@keyframes hop { /* two quick hops with squash landings */
  0%, 100% { transform: translateY(0) scaleY(1); }
  12% { transform: translateY(-13%) scaleY(1.05) scaleX(0.97); }
  26% { transform: translateY(0) scaleY(0.9) scaleX(1.08); }
  38% { transform: translateY(-4%) scaleY(1.01); }
  50% { transform: translateY(0) scaleY(0.97); }
  62% { transform: translateY(-13%) scaleY(1.05) scaleX(0.97) rotate(3deg); }
  76% { transform: translateY(0) scaleY(0.9) scaleX(1.08) rotate(-1deg); }
  88% { transform: translateY(-3%) scaleY(1.01); }
}
@keyframes spinwob { /* turning wobble, like grooving on the spot */
  0%, 100% { transform: rotate(0deg) translateY(0); }
  20% { transform: rotate(9deg) translateY(-6%) skewX(2deg); }
  40% { transform: rotate(-4deg) translateY(-1%); }
  55% { transform: rotate(-10deg) translateY(-7%) skewX(-2deg); }
  75% { transform: rotate(4deg) translateY(-2%); }
  90% { transform: rotate(-2deg) translateY(-4%); }
}
@keyframes pulsebeat { /* blob pulse on the beat */
  0%, 100% { transform: scale(1) translateY(0); }
  14% { transform: scale(1.09, 0.95) translateY(1%); }
  32% { transform: scale(0.97, 1.05) translateY(-4%); }
  50% { transform: scale(1.05, 0.97) translateY(0); }
  66% { transform: scale(0.98, 1.03) translateY(-2%); }
  84% { transform: scale(1.03, 0.98) translateY(0); }
}
@keyframes driftglide { /* sideways glide, tail-led */
  0%, 100% { transform: translateX(0) translateY(0) rotate(0deg); }
  22% { transform: translateX(-5%) translateY(-4%) rotate(-4deg); }
  46% { transform: translateX(1%) translateY(-7%) rotate(1deg); }
  70% { transform: translateX(5%) translateY(-3%) rotate(4deg); }
  88% { transform: translateX(1%) translateY(-5%) rotate(0deg); }
}
@keyframes shimmy { /* fast funky shoulder shimmy */
  0%, 100% { transform: translateX(0) skewX(0deg) translateY(0); }
  10% { transform: translateX(-3%) skewX(-5deg) translateY(-2%); }
  25% { transform: translateX(3%) skewX(5deg); }
  40% { transform: translateX(-3%) skewX(-5deg) translateY(-5%); }
  55% { transform: translateX(3%) skewX(4deg); }
  70% { transform: translateX(-2%) skewX(-3deg) translateY(-2%); }
  85% { transform: translateX(2%) skewX(3deg); }
}
.dance-stomp { animation-name: stomp; animation-timing-function: ease-in-out; }
.dance-sway { animation-name: sway; animation-timing-function: ease-in-out; }
.dance-bounce { animation-name: bounce; animation-timing-function: ease-in-out; }
.dance-float { animation-name: float; animation-timing-function: ease-in-out; }
.dance-wiggle { animation-name: wiggle; animation-timing-function: ease-in-out; }
.dance-hop { animation-name: hop; animation-timing-function: ease-in-out; }
.dance-spin { animation-name: spinwob; animation-timing-function: ease-in-out; }
.dance-pulse { animation-name: pulsebeat; animation-timing-function: ease-in-out; }
.dance-drift { animation-name: driftglide; animation-timing-function: ease-in-out; }
.dance-shimmy { animation-name: shimmy; animation-timing-function: ease-in-out; }

/* ---------- scenery ---------- */
:root { --dune1: #13295a; --dune2: #0d1e44; --kelp: #1c4a6e; }
body.world-reef  { --dune1: #10465a; --dune2: #0a3244; --kelp: #1e6b58; }
body.world-polar { --dune1: #1c4a80; --dune2: #143a68; --kelp: #3a7fae; }
body.world-vent  { --dune1: #3c1622; --dune2: #260c14; --kelp: #642836; }
body.world-abyss { --dune1: #170f38; --dune2: #0e0a24; --kelp: #2a1e55; }
#scenery { position: absolute; inset: 0; pointer-events: none; z-index: 1; overflow: hidden; }
#viz-front { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 7; }
#seabed-svg { position: absolute; bottom: 0; left: 0; width: 100%; height: 24%; }
.dune-far { fill: var(--dune1); transition: fill 0.6s; }
.dune-near { fill: var(--dune2); transition: fill 0.6s; }
.kelp {
  fill: none; stroke: var(--kelp); stroke-width: 9; stroke-linecap: round;
  transform-box: fill-box; transform-origin: 50% 100%;
  animation: kelp-sway 7s ease-in-out infinite;
  transition: stroke 0.6s;
}
.k2 { animation-delay: -2s; stroke-width: 7; }
.k3 { animation-delay: -4s; }
.k4 { animation-delay: -5.5s; stroke-width: 7; }
@keyframes kelp-sway {
  0%, 100% { transform: rotate(-2.5deg); }
  50% { transform: rotate(2.5deg); }
}
.pearl { fill: #bff7ff; opacity: 0.4; animation: pearl-pulse 4s ease-in-out infinite; }
@keyframes pearl-pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 0.75; } }

/* ---------- world-specific scenery (crossfaded via opacity) ---------- */
.scn { opacity: 0; transition: opacity 0.8s; }
body.world-vent  .scn-vent  { opacity: 1; }
body.world-reef  .scn-reef  { opacity: 1; }
body.world-polar .scn-polar { opacity: 1; }
.chimney { fill: #1c0a10; stroke: #3a1420; stroke-width: 2; }
.vent-glow { fill: #ff7a5c; opacity: 0.7; animation: pearl-pulse 2.3s ease-in-out infinite; }
.coral { fill: #12554e; stroke: #0c3f3a; stroke-width: 2; }
.c-br2 { fill: #155f50; }
.c-fan { fill: #0f4d46; }
.coral-dot { fill: #3ee6b8; opacity: 0.7; animation: pearl-pulse 3.1s ease-in-out infinite; }
.icerock { fill: #2a5a94; stroke: #3f79b8; stroke-width: 2; opacity: 0.85; }
body.paused .pearl, body.paused .vent-glow, body.paused .coral-dot { animation-play-state: paused; }

/* ---------- character part animations ---------- */
.c-glow { animation: glow-pulse 1.143s ease-in-out infinite; } /* 2 beats @105bpm */
@keyframes glow-pulse { 0%, 100% { opacity: 0.75; } 50% { opacity: 1; } }
/* blink: quick lid-dip every few seconds, offset per side so it feels alive */
.slot .c-eye, .slot .c-pupil {
  transform-box: fill-box; transform-origin: 50% 50%;
  animation: blink 4.6s ease-in-out infinite;
}
.slot:nth-child(2n) .c-eye, .slot:nth-child(2n) .c-pupil { animation-delay: -1.7s; }
.slot:nth-child(3n) .c-eye, .slot:nth-child(3n) .c-pupil { animation-delay: -3.1s; }
@keyframes blink {
  0%, 91%, 100% { transform: scaleY(1); }
  93.5% { transform: scaleY(0.12); }
  96% { transform: scaleY(1); }
}
/* transform-box only while dancing — applying it statically would re-origin
   the SVG rotate(a x y) attribute transforms and displace fins */
.slot.dancing .c-fin, .slot.dancing .c-limb {
  transform-box: fill-box; transform-origin: 50% 30%;
  animation-composition: add;
}
.slot.dancing .c-fin { animation-name: fin-flap; animation-duration: 0.5714s; animation-timing-function: ease-in-out; animation-iteration-count: infinite; }
.slot.dancing .c-limb { animation-name: limb-groove; animation-duration: 1.143s; animation-timing-function: ease-in-out; animation-iteration-count: infinite; }
.slot.dancing .c-fin.c-r, .slot.dancing .c-limb.c-r { animation-direction: reverse; }
@keyframes fin-flap { 0%, 100% { transform: rotate(-7deg); } 50% { transform: rotate(7deg); } }
@keyframes limb-groove { 0%, 100% { transform: rotate(-9deg); } 50% { transform: rotate(9deg); } }
/* mouth bops while the figure sings/dances */
.slot.dancing .c-mouth {
  transform-box: fill-box; transform-origin: 50% 50%;
  animation: mouth-bop 0.5714s ease-in-out infinite;
}
@keyframes mouth-bop {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.25, 1.45); }
}
/* soft idle fin drift even when not dancing (very subtle) */
.slot.occupied:not(.dancing) .c-fin {
  transform-box: fill-box; transform-origin: 50% 30%;
  animation: fin-idle 3.4s ease-in-out infinite;
  animation-composition: add;
}
@keyframes fin-idle { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2.5deg); } }
/* bubbles rising from a dancing creature */
.slot-bubbles { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.bub {
  position: absolute; bottom: 18%; left: 50%;
  width: 7px; height: 7px; border-radius: 50%;
  border: 1.5px solid rgba(190, 240, 255, 0.55);
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.4), rgba(190,240,255,0.05));
  opacity: 0;
}
.slot.dancing .bub { animation: bub-rise 2.286s linear infinite; } /* 4 beats */
.bub:nth-child(1) { left: 34%; }
.bub:nth-child(2) { left: 56%; width: 5px; height: 5px; animation-delay: -0.9s !important; }
.bub:nth-child(3) { left: 70%; width: 4px; height: 4px; animation-delay: -1.6s !important; }
@keyframes bub-rise {
  0% { transform: translateY(0) translateX(0) scale(0.6); opacity: 0; }
  12% { opacity: 0.85; }
  60% { transform: translateY(-70px) translateX(4px) scale(0.95); opacity: 0.6; }
  100% { transform: translateY(-120px) translateX(-3px) scale(1.1); opacity: 0; }
}
body.paused .c-glow, body.paused .c-fin, body.paused .c-limb, body.paused .c-eye,
body.paused .c-pupil, body.paused .c-mouth, body.paused .bub,
body.paused .kelp { animation-play-state: paused; }

/* ---------- combo FX ---------- */
#combo-fx { position: absolute; inset: 0; pointer-events: none; z-index: 8; overflow: hidden; }
.combo-flash {
  position: absolute; inset: 0;
  background: radial-gradient(60% 60% at 50% 55%, var(--glow), transparent 70%);
  animation: combo-flash 1.6s ease-out forwards;
}
@keyframes combo-flash { 0% { opacity: 0; } 25% { opacity: 1; } 100% { opacity: 0; } }
.combo-badge {
  position: absolute; left: 50%; top: 16%;
  transform: translateX(-50%);
  font-size: 26px; font-weight: 800; letter-spacing: 0.28em;
  color: #fff; text-shadow: 0 0 24px var(--glow), 0 0 6px var(--accent);
  animation: badge-in 2.6s ease-out forwards;
}
@keyframes badge-in {
  0% { opacity: 0; transform: translateX(-50%) translateY(14px) scale(0.85); }
  18% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1.05); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-12px) scale(1); }
}
.fx-whale {
  position: absolute; top: 12%; left: -30%;
  width: 300px; height: 150px; opacity: 0;
  animation: whale-swim 10.5s ease-in-out forwards; /* ~1 loop pass */
}
.fx-whale path { fill: rgba(150, 190, 255, 0.16); }
.fx-whale .fx-eye { fill: rgba(230, 245, 255, 0.5); }
@keyframes whale-swim {
  0% { transform: translateX(0) translateY(0); opacity: 0; }
  12% { opacity: 1; }
  50% { transform: translateX(60vw) translateY(-30px); }
  88% { opacity: 1; }
  100% { transform: translateX(130vw) translateY(6px); opacity: 0; }
}
.aurora-ray {
  position: absolute; top: -10%; height: 70%; width: 18vw;
  background: linear-gradient(180deg, rgba(94, 230, 168, 0.28), rgba(124, 92, 255, 0.12), transparent 80%);
  filter: blur(6px);
  animation: aurora-sway 9.14s ease-in-out forwards;
  transform-origin: top center;
}
@keyframes aurora-sway {
  0% { opacity: 0; transform: rotate(-8deg); }
  15% { opacity: 1; }
  50% { transform: rotate(8deg); }
  85% { opacity: 1; }
  100% { opacity: 0; transform: rotate(-5deg); }
}
.fx-bubble {
  position: absolute; bottom: -30px; left: var(--x, 50%);
  width: var(--s, 14px); height: var(--s, 14px);
  border-radius: 50%;
  border: 2px solid rgba(190, 240, 255, 0.55);
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.5), rgba(190,240,255,0.08));
  animation: bubble-rise var(--d, 4s) ease-in forwards;
}
@keyframes bubble-rise {
  0% { transform: translateY(0) translateX(0) scale(0.7); opacity: 0; }
  10% { opacity: 1; }
  100% { transform: translateY(-88vh) translateX(var(--wob, 20px)) scale(1.15); opacity: 0; }
}
/* starfall: shooting star streaks */
.fx-star {
  position: absolute; top: -6%; left: var(--x, 50%);
  width: 3px; height: 34px; border-radius: 2px;
  background: linear-gradient(180deg, rgba(255,255,255,0), #fff 75%, #bff7ff);
  box-shadow: 0 0 10px rgba(190, 240, 255, 0.9);
  transform: rotate(18deg);
  animation: star-fall 2.4s ease-in forwards;
  opacity: 0;
}
@keyframes star-fall {
  0% { transform: translate(0, 0) rotate(18deg); opacity: 0; }
  8% { opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(-22vw, 68vh) rotate(18deg); opacity: 0; }
}
/* riptide: rushing current streaks */
.fx-current {
  position: absolute; left: -22%;
  width: 20%; height: 3px; border-radius: 3px;
  background: linear-gradient(90deg, transparent, rgba(160, 230, 255, 0.5), transparent);
  animation: current-rush 2.6s ease-in-out forwards;
  opacity: 0;
}
@keyframes current-rush {
  0% { transform: translateX(0) scaleX(0.6); opacity: 0; }
  15% { opacity: 1; }
  85% { opacity: 0.8; }
  100% { transform: translateX(145vw) scaleX(1.4); opacity: 0; }
}
/* moonveil: drifting jellyfish silhouettes */
.fx-jelly {
  position: absolute; bottom: -14%;
  width: 64px; height: 86px; opacity: 0;
  animation: jelly-drift 10s ease-in-out forwards;
}
.fx-jelly path { fill: rgba(190, 200, 255, 0.18); stroke: rgba(190, 200, 255, 0.35); }
@keyframes jelly-drift {
  0% { transform: translateY(0) translateX(0); opacity: 0; }
  12% { opacity: 1; }
  50% { transform: translateY(-46vh) translateX(24px); }
  88% { opacity: 0.8; }
  100% { transform: translateY(-92vh) translateX(-12px); opacity: 0; }
}

/* ---------- export panel ---------- */
#export-panel { gap: 12px; }
.loop-group { display: flex; gap: 4px; }
.loop-btn { opacity: 0.5; min-width: 36px; }
.loop-btn.active { opacity: 1; box-shadow: 0 0 0 2px rgba(255,255,255,0.35); }
.fade-wrap { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-dim); cursor: pointer; }
.fade-wrap input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- save panel / shimmer hint ---------- */
.save-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.save-label { flex: 1; font-size: 13px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.slot.shimmer::before {
  content: "✦";
  position: absolute; top: 6px; right: 8px; z-index: 4;
  color: #fff; font-size: 13px;
  text-shadow: 0 0 8px var(--glow);
  animation: shimmer-tw 1.6s ease-in-out infinite;
  pointer-events: none;
}
@keyframes shimmer-tw {
  0%, 100% { opacity: 0.15; transform: scale(0.8) rotate(0deg); }
  50% { opacity: 1; transform: scale(1.15) rotate(20deg); }
}

/* ---------- toast / onboarding ---------- */
#toast {
  position: fixed; left: 50%; bottom: 120px; z-index: 60;
  transform: translateX(-50%) translateY(10px);
  background: var(--panel); border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  padding: 10px 18px; border-radius: 12px;
  opacity: 0; transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#onboarding {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(2, 6, 16, 0.72); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
.ob-card {
  background: linear-gradient(180deg, var(--bg0), var(--bg1));
  border: 1px solid var(--line); border-radius: 20px;
  padding: 28px 34px; max-width: 440px; margin: 16px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
  text-align: center;
}
.ob-card h2 { margin: 0 0 12px; }
.ob-card p { color: var(--ink-dim); line-height: 1.5; }
.ob-card .big-btn { margin-top: 10px; }

/* ---------- responsive ---------- */
/* Wide → narrow: 1) drop button labels, 2) collapse secondary controls into
   the "…" sheet (JS moves them at 768px), 3) portrait phones wrap the stage
   into 2 rows of 4/3, landscape phones keep one shallow row of 7. */
@media (max-width: 1180px) {
  .ctl-label { display: none; }
  .ctl { padding: 8px 10px; }
  #vol { width: 72px; }
  #controls { gap: 6px; }
}
@media (max-width: 768px) {
  #topbar { gap: 10px; padding: 6px 10px; padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .logo-small { font-size: 17px; }
  #controls { flex-wrap: nowrap; }
  .popover { right: 8px; left: auto; max-width: calc(100vw - 16px); }
  /* stage: 2 rows (4 + 3). The max-width caps the row at 4 slots even when
     the slot cap (112px) is reached — without it, 624–768px viewports would
     wrap 5+2 or 6+1 with an orphaned last slot */
  #stage {
    flex-wrap: wrap; gap: 10px; row-gap: 16px; padding-bottom: 2.5vh;
    max-width: calc(4 * 112px + 3 * 10px + 24px);
  }
  .slot { width: min(112px, calc((100vw - 24px - 3 * 10px) / 4)); }
  .icon-rows { min-height: 88px; }
}
/* landscape phones: shallow screen → single stage row of 7, slim chrome */
@media (max-height: 520px) {
  h1.logo { font-size: 30px; }
  #topbar { padding: 4px 10px; }
  .logo-small { font-size: 15px; }
  #stage { flex-wrap: nowrap; gap: 6px; padding-bottom: 1.5vh; max-width: none; }
  .slot { width: min(92px, calc((100vw - 24px - 6 * 6px) / 7)); }
  #iconbar { gap: 4px; padding-top: 4px; }
  .icon-rows { min-height: 74px; }
  .icon { width: 54px; height: 70px; }
  .icon-fig { width: 38px; height: 50px; }
  .cat-tab { min-height: 40px; padding: 4px 11px; }
  .slot.occupied.menu-open .fig-menu { top: auto; bottom: calc(env(safe-area-inset-bottom) + 128px); }
  @media (pointer: coarse) { .fig-btn { width: 44px; height: 44px; } }
}
/* tiny phones (320px class): squeeze the topbar into one row */
@media (max-width: 350px) {
  #topbar { gap: 6px; padding-left: 6px; padding-right: 6px; }
  #controls { gap: 4px; }
  .logo-small { font-size: 13px; letter-spacing: 0.1em; }
  .ctl { padding: 8px 8px; }
}
/* very narrow phones: keep all five tabs visible without scrolling —
   inactive tabs collapse to their colored dot, only the active tab is named */
@media (max-width: 460px) {
  .cat-tab { padding: 6px 10px; font-size: 11px; gap: 6px; letter-spacing: 0.06em; }
  .cat-tab:not(.active) .tab-name { display: none; }
  .cat-tab .tab-dot { width: 12px; height: 12px; }
  .tab-badge { min-width: 15px; height: 15px; font-size: 9px; }
  #stage { row-gap: 12px; }
}
