:root {
  --bg-0: #140a26;
  --bg-1: #1c1035;
  --bg-2: #0f0a1e;
  --panel: rgba(139, 92, 246, 0.10);
  --panel-border: rgba(167, 139, 250, 0.16);
  --text: #f5f3ff;
  --text-dim: #b8aed6;
  --violet: #8b5cf6;
  --violet-soft: #a78bfa;
  --yellow: #facc15;
  --yellow-soft: #fde047;
  --orange: #f97316;
  --red: #ef4444;
  --gold: #fbbf24;
  --ok: #34d399;
  --danger: #f87171;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(1100px 700px at 50% -8%, rgba(139, 92, 246, 0.28) 0%, rgba(139, 92, 246, 0) 55%),
    radial-gradient(900px 600px at 85% 110%, rgba(250, 204, 21, 0.10) 0%, rgba(250, 204, 21, 0) 50%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 45%, var(--bg-2) 100%);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  padding: 22px 16px;
  animation: fadein 0.28s ease;
}
.screen.active { display: flex; }

@keyframes fadein {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.hidden { display: none !important; }

/* ---------- Typography & buttons ---------- */
h1.title {
  font-size: 44px;
  margin: 10px 0 2px;
  font-weight: 900;
  letter-spacing: -1px;
  background: linear-gradient(100deg, var(--yellow-soft) 0%, var(--yellow) 35%, var(--violet-soft) 80%, var(--violet) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 20px rgba(139, 92, 246, 0.35));
  text-align: center;
}
.subtitle { color: var(--text-dim); margin: 0 0 18px; text-align: center; font-size: 14px; }

.btn {
  display: block;
  width: 100%;
  max-width: 320px;
  padding: 15px 18px;
  margin: 8px 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.05));
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    inset 0 -3px 0 rgba(0, 0, 0, 0.2),
    0 8px 18px rgba(0, 0, 0, 0.3);
  transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.1s ease;
}
.btn:active {
  transform: translateY(2px);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.03));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    inset 0 -1px 0 rgba(0, 0, 0, 0.22),
    0 4px 10px rgba(0, 0, 0, 0.25);
}
.btn.primary {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    inset 0 -3px 0 rgba(0, 0, 0, 0.28),
    0 10px 24px rgba(124, 58, 237, 0.38);
}
.btn.primary:active {
  background: linear-gradient(135deg, #6d28d9, #5b21b6);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    inset 0 -1px 0 rgba(0, 0, 0, 0.3),
    0 5px 12px rgba(124, 58, 237, 0.28);
}
.btn.accent {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  border-color: rgba(255, 255, 255, 0.25);
  color: #3b2505;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    inset 0 -3px 0 rgba(0, 0, 0, 0.18),
    0 10px 24px rgba(245, 158, 11, 0.3);
}
.btn.accent:active {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    inset 0 -1px 0 rgba(0, 0, 0, 0.2),
    0 5px 12px rgba(245, 158, 11, 0.22);
}
.btn.small { padding: 10px 14px; font-size: 14px; max-width: 190px; display: inline-block; margin: 4px; }
.btn.ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--text-dim);
}
.btn.ghost:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: default; }

.menu-list { width: 100%; max-width: 340px; display: flex; flex-direction: column; align-items: center; }

/* ---------- Difficulty cards ---------- */
.diff-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; max-width: 420px; }
.diff-card {
  padding: 18px 12px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0.03));
  text-align: center;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 8px 16px rgba(0, 0, 0, 0.22);
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.diff-card:active { transform: scale(0.96); box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 4px 10px rgba(0,0,0,0.22); }
.diff-card .icon { font-size: 32px; display: block; margin-bottom: 6px; }
.diff-card .name { font-weight: 800; font-size: 17px; }
.diff-card .meta { color: var(--text-dim); font-size: 12px; margin-top: 3px; }

/* ---------- Column groups & level grid ---------- */
.group-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 14px 0; }
.group-chip {
  min-width: 64px;
  padding: 12px 10px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.03));
  text-align: center;
  cursor: pointer;
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.12), 0 6px 12px rgba(0,0,0,0.18);
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.group-chip:active { transform: scale(0.94) translateY(1px); box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 3px 7px rgba(0,0,0,0.18); }
.group-chip .cols { font-size: 20px; }
.group-chip .lab { font-size: 11px; color: var(--text-dim); }

.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; width: 100%; max-width: 420px; }
.level-cell {
  aspect-ratio: 1;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: 700;
  font-size: 15px;
  position: relative;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.10), 0 5px 10px rgba(0,0,0,0.18);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.level-cell:active { transform: scale(0.92) translateY(1px); box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), 0 3px 6px rgba(0,0,0,0.18); }
.level-cell.done {
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.16), rgba(139, 92, 246, 0.16));
  border-color: rgba(250, 204, 21, 0.35);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.12), 0 5px 12px rgba(245, 158, 11, 0.14);
}
.level-cell .stars { font-size: 9px; letter-spacing: 1px; color: var(--gold); }
.level-cell .best { font-size: 9px; color: var(--text-dim); }

/* ---------- HUD ---------- */
#hud { width: 100%; align-self: stretch; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 2px 8px; }
#hud .left, #hud .right { display: flex; align-items: center; gap: 8px; }
.hud-btn {
  width: 44px; height: 44px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04));
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    inset 0 -2px 0 rgba(0, 0, 0, 0.18),
    0 6px 12px rgba(0, 0, 0, 0.25);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.hud-btn:active { transform: translateY(1px) scale(0.94); box-shadow: inset 0 1px 0 rgba(255,255,255,0.12), inset 0 -1px 0 rgba(0,0,0,0.2), 0 3px 6px rgba(0,0,0,0.25); }
.hud-stat {
  padding: 6px 12px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 6px 12px rgba(0, 0, 0, 0.2);
  text-align: center;
}
.hud-stat .val { font-size: 22px; font-weight: 900; font-variant-numeric: tabular-nums; }
.hud-stat .lab { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }

/* ---------- Board & shelves ---------- */
#board-wrap {
  position: relative;
  flex: 1;
  /* .screen centres its children, so without this the wrap shrinks to its content
     and computeLayout measures a board far narrower than the screen. */
  width: 100%;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
#board {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  gap: var(--tube-gap, 10px);
  width: 100%;
}

.tube {
  position: relative;
  width: var(--tube-w, 42px);
  height: var(--tube-h, 240px);
  cursor: pointer;
  overflow: visible;
  transition: transform 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}
.tube.sel { transform: translateY(-5px); }

/* Back guide: a faint slot behind the pieces so a column stays readable even when
   it is empty — empty columns are exactly the ones a player needs to see to plan. */
.tube::before {
  content: '';
  position: absolute;
  left: 50%;
  bottom: var(--lip, 24px);
  transform: translateX(-50%);
  width: calc(var(--piece-w, 34px) + 10px);
  height: calc(100% - var(--lip, 24px));
  border-radius: 12px 12px 4px 4px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.085) 0%, rgba(255, 255, 255, 0.028) 55%, rgba(255, 255, 255, 0.01) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.055),
    inset 0 10px 18px -12px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  transition: background 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}
.tube.empty::before { opacity: 0.5; }

/* Wooden shelf plank; its own drop shadow doubles as the ground shadow. */
.tube::after {
  content: '';
  position: absolute;
  bottom: calc(var(--lip, 24px) - 13px);
  left: 50%;
  transform: translateX(-50%);
  width: calc(var(--tube-w, 42px) + 10px);
  height: 13px;
  border-radius: 4px 4px 6px 6px;
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.09) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #c99a68 0%, #ac8054 36%, #8b6541 64%, #5d3f27 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.3),
    inset 0 -3px 0 rgba(0, 0, 0, 0.34),
    0 5px 9px rgba(0, 0, 0, 0.45),
    0 14px 20px -8px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  transition: box-shadow 0.2s ease, filter 0.2s ease, transform 0.18s ease;
}

.tube.sel::before {
  background: linear-gradient(180deg, rgba(251, 191, 36, 0.16) 0%, rgba(251, 191, 36, 0.05) 60%, rgba(255, 255, 255, 0.01) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(251, 191, 36, 0.3),
    inset 0 10px 18px -12px rgba(0, 0, 0, 0.6);
}
.tube.sel::after {
  filter: brightness(1.1);
  /* Lifted: the contact shadow tightens instead of staying flat. */
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.34),
    inset 0 -3px 0 rgba(0, 0, 0, 0.34),
    0 3px 6px rgba(0, 0, 0, 0.4),
    0 10px 16px -8px rgba(0, 0, 0, 0.45),
    0 0 22px rgba(251, 191, 36, 0.45);
}

/* Finished column: the plank turns to gold and stays that way. */
.tube.done::after {
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.07) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #f3cf7a 0%, #d9a441 38%, #b07f2c 66%, #7a5518 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.42),
    inset 0 -3px 0 rgba(0, 0, 0, 0.28),
    0 5px 9px rgba(0, 0, 0, 0.4),
    0 0 20px rgba(251, 191, 36, 0.4);
}
.tube.done::before {
  background: linear-gradient(180deg, rgba(251, 191, 36, 0.12) 0%, rgba(251, 191, 36, 0.035) 60%, rgba(255, 255, 255, 0.01) 100%);
}

.tube.wrong { animation: shake 0.3s; }
.tube.wrong::after {
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.25),
    inset 0 -3px 0 rgba(0, 0, 0, 0.34),
    0 5px 9px rgba(0, 0, 0, 0.45),
    0 0 18px rgba(248, 113, 113, 0.7);
}
.tube.wrong::before {
  background: linear-gradient(180deg, rgba(248, 113, 113, 0.18) 0%, rgba(248, 113, 113, 0.05) 60%, rgba(255, 255, 255, 0.01) 100%);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.piece {
  position: absolute;
  left: 50%;
  width: var(--piece-w, 34px);
  height: var(--piece-box-h, 34px);
  /* Round themes use a box taller than one stack step so they nest; centring the
     overflow keeps the piece on its own slot. */
  margin-bottom: calc((var(--piece-h, 34px) - var(--piece-box-h, 34px)) / 2);
  transform: translateX(-50%);
  pointer-events: none;
  transition: bottom 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}
.piece svg {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.35));
}
.piece.top svg { filter: drop-shadow(0 4px 7px rgba(0, 0, 0, 0.42)); }

/* The lifted run floats and keeps breathing, so "held" reads as a state and not
   as a one-off 170ms nudge. */
.piece.lift {
  z-index: 2;
  animation: bob 1.5s ease-in-out infinite;
}
.piece.lift svg {
  filter: drop-shadow(0 12px 14px rgba(0, 0, 0, 0.45)) drop-shadow(0 0 8px rgba(251, 191, 36, 0.35));
}

@keyframes bob {
  0%, 100% { transform: translateX(-50%) translateY(calc(-1 * min(var(--piece-h, 34px) * 0.6, 22px))); }
  50% { transform: translateX(-50%) translateY(calc(-1 * min(var(--piece-h, 34px) * 0.6, 22px) - 4px)); }
}

.piece.pop { animation: pop 0.28s cubic-bezier(0.34, 1.56, 0.64, 1); }

@keyframes pop {
  0% { transform: translateX(-50%) scale(0.6); }
  60% { transform: translateX(-50%) scale(1.12); }
  100% { transform: translateX(-50%) scale(1); }
}

/* Landing ring, spawned by impactRing() in ui/animations.ts. */
.impact-ring {
  position: fixed;
  border: 3px solid currentColor;
  border-radius: 50%;
  pointer-events: none;
  z-index: 60;
}

/* Desktop only: without this the board has no resting-state response at all. */
@media (hover: hover) and (pointer: fine) {
  .tube:hover::before {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.13) 0%, rgba(255, 255, 255, 0.05) 55%, rgba(255, 255, 255, 0.015) 100%);
  }
  .tube:hover::after { filter: brightness(1.14); }
  .tube:hover .piece.top:not(.lift) { transform: translateX(-50%) translateY(-3px); }
  .piece.top:not(.lift) { transition: bottom 0.26s cubic-bezier(0.22, 1, 0.36, 1), transform 0.16s ease; }
}

/* ---------- Game controls ---------- */
#game-controls { display: flex; gap: 10px; justify-content: center; padding: 12px 0 4px; }
#game-controls .btn { margin: 0; flex: 1; max-width: 170px; }

/* ---------- Overlay / win ---------- */
#overlay {
  position: absolute; inset: 0;
  background: rgba(10, 6, 22, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
  animation: fadein 0.25s ease;
}
.panel {
  width: 100%;
  max-width: 380px;
  max-height: 88vh;
  overflow-y: auto;
  background: linear-gradient(180deg, rgba(48, 34, 82, 0.95), rgba(26, 18, 48, 0.96));
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
  padding: 22px;
  text-align: center;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 28px 70px rgba(0, 0, 0, 0.55);
}
.panel h2 { margin: 4px 0 10px; font-size: 26px; }
.panel h3 { margin: 14px 0 6px; color: var(--text-dim); font-size: 14px; text-transform: uppercase; letter-spacing: 1px; }

.stars-row { font-size: 42px; letter-spacing: 8px; margin: 6px 0; }
.stars-row .star { display: inline-block; opacity: 0.22; filter: grayscale(1); }
.stars-row .star.on { opacity: 1; filter: none; animation: starpop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); }
.stars-row .star:nth-child(2).on { animation-delay: 0.12s; }
.stars-row .star:nth-child(3).on { animation-delay: 0.24s; }

@keyframes starpop {
  0% { transform: scale(0) rotate(-90deg); }
  100% { transform: scale(1) rotate(0); }
}

.stat-line { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed rgba(167, 139, 250, 0.16); font-size: 15px; }
.stat-line .k { color: var(--text-dim); }
.stat-line .v { font-weight: 800; }

.rank-list { text-align: left; margin: 8px 0; }
.rank-row { display: flex; gap: 8px; padding: 6px 4px; font-size: 14px; border-bottom: 1px solid rgba(167, 139, 250, 0.10); }
.rank-row .pos { width: 22px; color: var(--text-dim); font-weight: 700; }
.rank-row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row .vl { font-weight: 800; color: var(--gold); }
.rank-row.me { background: rgba(139, 92, 246, 0.14); border-radius: 6px; }

/* ---------- Forms ---------- */
.field { margin: 10px 0; text-align: left; }
.field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 1px; }
.field input[type=text] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: rgba(167, 139, 250, 0.08);
  color: var(--text);
  font-size: 16px;
}
.range-row { display: flex; justify-content: space-between; align-items: center; margin: 8px 0; font-size: 15px; }
.range-row .val { font-weight: 800; color: var(--yellow-soft); }
.stepper { display: flex; gap: 8px; align-items: center; }
.stepper button {
  width: 38px; height: 38px; border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: rgba(167, 139, 250, 0.10); color: var(--text);
  font-size: 20px; cursor: pointer; font-weight: 800;
}
.stepper button:active { transform: scale(0.9); }

/* ---------- Theme picker ---------- */
.theme-row { display: flex; gap: 12px; justify-content: center; margin: 10px 0; }
.theme-opt {
  flex: 1; max-width: 110px;
  padding: 12px 6px;
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, 0.10);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
  text-align: center; cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.10), 0 6px 12px rgba(0,0,0,0.18);
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.theme-opt.sel { border-color: var(--yellow); background: rgba(250, 204, 21, 0.10); box-shadow: inset 0 1px 0 rgba(255,255,255,0.14), 0 6px 14px rgba(245, 158, 11, 0.18); }
.theme-opt:active { transform: scale(0.96) translateY(1px); box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), 0 3px 7px rgba(0,0,0,0.18); }
.theme-opt.locked { opacity: 0.45; }
.theme-opt .th { height: 40px; display: flex; align-items: center; justify-content: center; }
.theme-opt .th svg { width: 38px; height: 38px; }
.theme-opt .tn { font-size: 12px; margin-top: 6px; font-weight: 700; }
.theme-opt .locknote { font-size: 10px; color: var(--text-dim); margin-top: 2px; }

.back-row { text-align: left; width: 100%; max-width: 420px; }

.toggle-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 2px; }
.toggle {
  width: 52px; height: 30px; border-radius: 20px;
  background: rgba(167, 139, 250, 0.2);
  position: relative; cursor: pointer; border: none;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.08);
  transition: background 0.2s;
}
.toggle::after {
  content: '';
  position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; border-radius: 50%;
  background: linear-gradient(180deg, #ffffff, #e8e8e8);
  box-shadow: 0 2px 5px rgba(0,0,0,0.3);
  transition: left 0.2s;
}
.toggle.on { background: var(--violet); box-shadow: inset 0 2px 4px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.12); }
.toggle.on::after { left: 25px; }

.confetti { position: absolute; width: 8px; height: 12px; border-radius: 2px; z-index: 60; pointer-events: none; }

/* ---------- Responsive ---------- */
@media (min-width: 768px) {
  #app { max-width: 760px; }
  h1.title { font-size: 52px; }
  .btn { font-size: 18px; }
}
@media (min-width: 1024px) {
  #app { max-width: 960px; }
  h1.title { font-size: 60px; }
  .btn { font-size: 19px; max-width: 360px; }
  .hud-btn { width: 48px; height: 48px; font-size: 22px; }
  .hud-stat .val { font-size: 26px; }
  .hud-stat .lab { font-size: 11px; }
}

/* ---------- Reduced motion ---------- */
/* The board's idle bob, pour arc and impact effects run continuously, so they need
   an explicit opt-out. State changes stay, only the motion goes. */
@media (prefers-reduced-motion: reduce) {
  .screen { animation: none; }
  .tube, .tube::after, .piece { transition: none; }
  .tube.wrong { animation: none; }
  .piece.lift {
    animation: none;
    transform: translateX(-50%) translateY(calc(-1 * min(var(--piece-h, 34px) * 0.5, 16px)));
  }
  .piece.pop { animation: none; }
  .stars-row .star.on { animation: none; }
}
