/* Water Sort — styles. System fonts only; no external resources. */

:root,
[data-bg="ocean"] {
  /* Background theme "ocean" (default). Other themes override these under [data-bg="…"]. */
  --bg: #0a2238;
  --bg-image: radial-gradient(120% 60% at 50% 0%, rgba(80, 220, 210, 0.22), transparent 60%),
    linear-gradient(180deg, #12496a, #0a2238);
  --card-top: #164a6c;
  --soft: rgba(255, 255, 255, 0.1);
  --off: rgba(255, 255, 255, 0.18);
  --overlay-bg: rgba(3, 14, 26, 0.6);
  --toast-bg: rgba(5, 20, 34, 0.88);
  --text-shadow: 0 4px 18px rgba(0, 0, 0, 0.3);
  --accent-hi: #6ff3d0;
  --accent-shadow: #1d9c80;
  --glass-stroke: rgba(235, 252, 255, 0.78);
  --glass-fill: rgba(255, 255, 255, 0.07);
  --lip-fill: rgba(220, 245, 255, 0.28);
  --shine: rgba(255, 255, 255, 0.4);
  --panel: rgba(8, 28, 46, 0.72);
  --panel-solid: #0f3350;
  --line: rgba(255, 255, 255, 0.14);
  --text: #eefaf8;
  --muted: #a9c7d3;
  --accent: #3fe0b8;
  --accent-2: #20b2d8;
  --accent-ink: #053a33;
  --gold: #ffd34d;
  --danger: #ff6b7d;
  --radius: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-image);
  background-attachment: fixed;
  transition: background-color 0.3s;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

[hidden] {
  display: none !important;
}

.ic {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------------- screens ---------------- */
.screen {
  position: fixed;
  inset: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--soft);
  /* Mobile browsers add default button padding/appearance and may ignore grid on
     <button>; reset them and center with flexbox so the icon is exactly centered. */
  -webkit-appearance: none;
  appearance: none;
  padding: 0;
  margin: 0;
  line-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  transition: transform 0.12s, background 0.2s;
}
.icon-btn .ic {
  display: block;
  flex: none;
}
.icon-btn:active {
  transform: scale(0.92);
}
.icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.icon-btn-spacer {
  width: 44px;
  flex: none;
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 12px 26px;
  min-height: 48px;
  font-weight: 700;
  font-size: 17px;
  color: var(--accent-ink);
  background: linear-gradient(180deg, var(--accent-hi), var(--accent));
  box-shadow: 0 4px 0 var(--accent-shadow), 0 10px 24px rgba(0, 0, 0, 0.25);
  transition: transform 0.12s, box-shadow 0.12s, filter 0.2s;
}
.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--accent-shadow), 0 6px 14px rgba(0, 0, 0, 0.25);
}
.btn.secondary {
  color: var(--text);
  background: var(--soft);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
  border: 1px solid var(--line);
}
.btn.danger {
  color: #fff;
  background: linear-gradient(180deg, #ff8796, var(--danger));
  box-shadow: 0 4px 0 #b83b4b;
}
.btn.big {
  font-size: 22px;
  padding: 14px 44px;
  min-height: 60px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
}
.btn.big small {
  font-size: 13px;
  font-weight: 600;
  opacity: 0.75;
}
.btn.small {
  font-size: 15px;
  padding: 8px 16px;
  min-height: 44px; /* minimum tap target */
}
.btn:disabled {
  filter: grayscale(1);
  opacity: 0.45;
  cursor: default;
}
.btn-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------------- home ---------------- */
.home .corner {
  position: absolute;
  top: calc(12px + var(--safe-t));
  right: 12px;
}
.home-main {
  margin: auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  width: 100%;
  max-width: 420px;
}
.logo {
  display: flex;
  gap: 14px;
  align-items: flex-end;
  height: 130px;
  margin-bottom: 4px;
}
.logo-tube {
  width: 40px;
  height: 130px;
  animation: bob 2.6s ease-in-out infinite;
}
.logo-tube:nth-child(2) {
  animation-delay: -0.9s;
}
.logo-tube:nth-child(3) {
  animation-delay: -1.7s;
}
.logo-tube .shaker,
.logo-tube svg {
  width: 100%;
  height: 100%;
  display: block;
}
@keyframes bob {
  50% {
    transform: translateY(-8px);
  }
}
.title {
  margin: 0;
  font-size: clamp(34px, 10vw, 48px);
  font-weight: 800;
  letter-spacing: 0.5px;
  line-height: 1.1;
  text-shadow: var(--text-shadow);
}
.subtitle {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 16px;
}
#btn-levels {
  min-width: 180px;
}

/* ---------------- level select ---------------- */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + var(--safe-t)) 12px 12px;
}
.bar h2 {
  margin: 0;
  font-size: 22px;
}
.level-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 8px 16px 16px;
  align-content: start;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
}
@media (min-width: 420px) {
  .level-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}
.lvl {
  aspect-ratio: 1;
  min-height: 56px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 20px;
  font-weight: 800;
  transition: transform 0.12s;
}
.lvl:active {
  transform: scale(0.94);
}
.lvl.current {
  background: linear-gradient(180deg, var(--accent-hi), var(--accent));
  color: var(--accent-ink);
  border-color: transparent;
}
.lvl.locked {
  opacity: 0.45;
  cursor: default;
  font-size: 18px;
}
.lvl-stars {
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--off);
}
.lvl-stars b {
  color: var(--gold);
  font-weight: 400;
}
.lvl.current .lvl-stars {
  color: rgba(0, 0, 0, 0.22);
}
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 10px 12px calc(16px + var(--safe-b));
}
.page-label {
  min-width: 90px;
  text-align: center;
  color: var(--muted);
  font-weight: 600;
}

/* ---------------- game ---------------- */
.board {
  position: absolute;
  inset: 0;
  touch-action: none;
}
.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(8px + var(--safe-t)) 12px 8px;
  pointer-events: none;
}
.topbar > * {
  pointer-events: auto;
}
.hud {
  text-align: center;
  pointer-events: none;
}
.hud-level {
  font-size: 22px;
  font-weight: 800;
  text-shadow: var(--text-shadow);
}
.hud-moves {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
.bottombar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: clamp(6px, 4vw, 28px);
  padding: 8px 8px calc(10px + var(--safe-b));
  pointer-events: none;
}
.tool {
  pointer-events: auto;
  border: 0;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 70px;
  padding: 0;
}
.tool-icon {
  position: relative;
  width: 54px;
  height: 54px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: var(--soft);
  border: 1px solid var(--line);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
  transition: transform 0.12s, box-shadow 0.12s;
}
.tool:active .tool-icon {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}
.tool-icon .ic {
  width: 26px;
  height: 26px;
}
.tool-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--gold);
  color: #3b2a00;
  font-size: 12px;
  font-weight: 800;
  line-height: 22px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
.tool:disabled {
  cursor: default;
}
.tool:disabled .tool-icon {
  opacity: 0.38;
}
.tool:disabled .tool-label {
  opacity: 0.5;
}
.tool:disabled .badge {
  background: #8a97a0;
  color: #1d2a32;
}
.tool.pulse .tool-icon {
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse {
  50% {
    box-shadow: 0 0 0 6px rgba(63, 224, 184, 0.35), 0 4px 0 rgba(0, 0, 0, 0.25);
  }
}

/* tubes */
.slot {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
  cursor: pointer;
}
.board.relayout .slot {
  transition: transform 320ms cubic-bezier(0.3, 0.9, 0.3, 1);
}
.board.relayout .tube {
  transition: transform 200ms cubic-bezier(0.34, 1.56, 0.64, 1), left 320ms, top 320ms, width 320ms, height 320ms;
}
.slot.active {
  z-index: 20;
}
.slot.done {
  cursor: default;
}
.slot.enter .tube {
  animation: tube-in 420ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes tube-in {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.6);
  }
}
.tube {
  position: absolute;
  transition: transform 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
  will-change: transform;
}
.tube.lifted {
  transform: translateY(calc(-1 * var(--lift, 30px)));
}
.tube.animating {
  transition: none;
}
.shaker,
.shaker svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}
.shaker {
  filter: var(--t-filter);
}
.shaker.shake {
  animation: shake 340ms ease-in-out;
}
@keyframes shake {
  15% { transform: translateX(-7px) rotate(-3deg); }
  35% { transform: translateX(6px) rotate(3deg); }
  55% { transform: translateX(-5px) rotate(-2deg); }
  75% { transform: translateX(3px) rotate(1deg); }
}
.glass-back {
  fill: var(--t-fill);
}
.glass {
  fill: none;
  stroke: var(--t-stroke);
  stroke-width: var(--t-stroke-w);
}
.lip {
  fill: var(--t-lip-fill);
  stroke: var(--t-lip-stroke);
  stroke-width: var(--t-lip-w);
}
.shine {
  fill: var(--t-shine);
}
.sym {
  fill: #fff;
  fill-opacity: 0.92;
  stroke: rgba(0, 0, 0, 0.45);
  stroke-width: 0.8;
}
.cap {
  display: none;
  transform-box: fill-box;
  transform-origin: center bottom;
}
.slot.done .cap {
  display: inline;
}
.slot.pop .cap {
  animation: cap-pop 520ms cubic-bezier(0.34, 1.7, 0.64, 1);
}
@keyframes cap-pop {
  from {
    transform: translateY(-16px) scale(0.3);
    opacity: 0;
  }
}
.cap-body {
  stroke: rgba(255, 255, 255, 0.85);
  stroke-width: 1.6;
  filter: brightness(0.85);
}
.cap-check {
  fill: none;
  stroke: #fff;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tube.glow .shaker {
  animation: glow 0.9s ease-in-out infinite;
}
.tube.glow-target .shaker {
  filter: drop-shadow(0 0 6px rgba(255, 211, 77, 0.6));
}
@keyframes glow {
  0%, 100% { filter: drop-shadow(0 0 4px rgba(255, 211, 77, 0.7)); }
  50% { filter: drop-shadow(0 0 14px rgba(255, 230, 120, 1)); }
}
.hint-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 18;
  overflow: visible;
}
.hint-arrow {
  fill: none;
  stroke: var(--gold);
  stroke-linecap: round;
  stroke-dasharray: 2 12;
  animation: dash 0.6s linear infinite;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}
.hint-head {
  fill: var(--gold);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}
@keyframes dash {
  to { stroke-dashoffset: -14; }
}
.stream {
  position: absolute;
  z-index: 19;
  border-radius: 3px;
  pointer-events: none;
  box-shadow: inset 2px 0 0 rgba(255, 255, 255, 0.3);
}
.fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 30;
}
.spark {
  position: absolute;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  animation: spark 900ms cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}
.spark:nth-child(3n) {
  border-radius: 2px;
  width: 6px;
  height: 10px;
}
@keyframes spark {
  0% { transform: translate(0, 0) scale(0.4); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1); opacity: 0; }
}

/* tutorial */
.tutorial {
  position: absolute;
  inset: 0;
  z-index: 25;
  pointer-events: none;
}
.tutorial-text {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  text-align: center;
  font-weight: 600;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.finger {
  position: absolute;
  left: 0;
  top: 0;
  font-size: 44px;
  line-height: 1;
  margin: -6px 0 0 -18px;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.4));
  animation: finger 2.6s ease-in-out infinite;
}
@keyframes finger {
  0% { transform: translate(var(--ax), var(--ay)); opacity: 0; }
  10% { transform: translate(var(--ax), var(--ay)); opacity: 1; }
  18% { transform: translate(var(--ax), var(--ay)) scale(0.82); }
  26% { transform: translate(var(--ax), var(--ay)) scale(1); }
  55% { transform: translate(var(--bx), var(--by)); }
  63% { transform: translate(var(--bx), var(--by)) scale(0.82); }
  71% { transform: translate(var(--bx), var(--by)) scale(1); opacity: 1; }
  90%, 100% { transform: translate(var(--bx), var(--by)); opacity: 0; }
}

/* banner (stuck / unsolvable) */
.banner {
  position: absolute;
  left: 50%;
  bottom: calc(100px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 26;
  width: min(420px, calc(100% - 24px));
  padding: 14px 14px 16px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  text-align: center;
  animation: rise 260ms ease-out;
}
.banner.soft {
  background: rgba(8, 28, 46, 0.6);
}
.banner-text {
  margin: 0 0 12px;
  font-weight: 700;
  font-size: 17px;
}
@keyframes rise {
  from { transform: translate(-50%, 20px); opacity: 0; }
}

/* toast */
.toast {
  position: fixed;
  top: calc(70px + var(--safe-t));
  left: 50%;
  z-index: 60;
  transform: translate(-50%, -10px);
  max-width: calc(100% - 32px);
  width: max-content;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--toast-bg);
  border: 1px solid var(--line);
  font-weight: 600;
  text-align: center;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------------- overlays ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--overlay-bg);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade 200ms ease-out;
  overflow: hidden;
}
@keyframes fade {
  from { opacity: 0; }
}
.card {
  position: relative;
  width: min(380px, 100%);
  padding: 22px 20px;
  border-radius: 24px;
  background: linear-gradient(180deg, var(--card-top), var(--panel-solid));
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: pop-in 320ms cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 1;
}
@keyframes pop-in {
  from { transform: scale(0.85); opacity: 0; }
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-head h2 {
  margin: 0;
  font-size: 22px;
}
.complete-card {
  text-align: center;
  align-items: center;
}
.complete-card .btn-row {
  width: 100%;
}
.complete-card .btn-row .btn {
  flex: 1;
}
.complete-title {
  margin: 0;
  font-size: 30px;
  font-weight: 800;
  color: var(--gold);
  text-shadow: 0 3px 12px rgba(0, 0, 0, 0.3);
}
.complete-level {
  color: var(--muted);
  font-weight: 700;
}
.complete-moves {
  font-weight: 600;
}
.stars {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.star {
  font-size: 52px;
  line-height: 1;
  color: var(--off);
  transition: color 0.2s;
}
.star:nth-child(2) {
  transform: translateY(-10px);
  font-size: 60px;
}
.star.on {
  color: var(--gold);
  text-shadow: 0 0 18px rgba(255, 211, 77, 0.6);
  animation: star-in 460ms cubic-bezier(0.34, 1.8, 0.64, 1);
}
.star:nth-child(2).on {
  animation-name: star-in-mid;
}
@keyframes star-in {
  from { transform: scale(0) rotate(-90deg); }
}
@keyframes star-in-mid {
  from { transform: translateY(-10px) scale(0) rotate(-90deg); }
}
.confetti {
  position: absolute;
  top: -12px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  pointer-events: none;
  animation: confetti 2s ease-in forwards;
}
@keyframes confetti {
  to { transform: translate(var(--x), 105vh) rotate(var(--r)); }
}

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  font-weight: 600;
  border-bottom: 1px solid var(--line);
}
.switch {
  position: relative;
  width: 54px;
  height: 32px;
  border-radius: 16px;
  border: 0;
  background: var(--off);
  transition: background 0.2s;
  flex: none;
}
.switch i {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s;
}
.switch[aria-checked="true"] {
  background: var(--accent);
}
.switch[aria-checked="true"] i {
  transform: translateX(22px);
}
.seg {
  display: flex;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.seg button {
  border: 0;
  padding: 8px 14px;
  min-height: 38px;
  background: transparent;
  font-weight: 700;
}
.seg button[aria-checked="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}
.settings-card .btn.danger {
  margin-top: 6px;
}
.confirm-text {
  margin: 4px 0;
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  line-height: 1.4;
}
.confirm-text + .btn-row .btn {
  flex: 1;
}

@media (max-width: 360px) {
  .tool {
    width: 62px;
  }
  .tool-icon {
    width: 48px;
    height: 48px;
  }
}

/* Reduced motion: only when CONFIG.anim.respectReducedMotion is true AND the
   device asks for it — main.js then puts .reduce-motion on <html>. Off by
   default, so the animation is the same on every device. */
.reduce-motion *,
.reduce-motion *::before,
.reduce-motion *::after {
  animation-duration: 1ms !important;
  animation-iteration-count: 1 !important;
}
.reduce-motion .tube,
.reduce-motion .board.relayout .slot {
  transition-duration: 1ms !important;
}
.reduce-motion .finger {
  animation: none;
  transform: translate(var(--ax), var(--ay));
}

/* =========================================================================
 * THEMES
 * Background themes set colors on <html data-bg="…">; tube themes set the
 * glass style on <html data-tube="…">. Both are plain CSS variables, so a
 * picker card can preview a theme by carrying its own data-bg / data-tube.
 * Theme ids are listed in CONFIG.themes (js/logic.js).
 * ======================================================================= */

/* ---------- tube themes ---------- */
:root,
[data-tube="classic"] {
  --t-stroke: var(--glass-stroke);
  --t-stroke-w: 2.3;
  --t-fill: var(--glass-fill);
  --t-lip-fill: var(--lip-fill);
  --t-lip-stroke: var(--glass-stroke);
  --t-lip-w: 1.8;
  --t-shine: var(--shine);
  --t-filter: none;
}
/* Neon: cyan glowing tube with a magenta rim. */
[data-tube="neon"] {
  --t-stroke: #3ff6ff;
  --t-stroke-w: 2.6;
  --t-fill: rgba(63, 246, 255, 0.07);
  --t-lip-fill: rgba(255, 79, 216, 0.4);
  --t-lip-stroke: #ff4fd8;
  --t-lip-w: 2;
  --t-shine: rgba(255, 255, 255, 0.35);
  --t-filter: drop-shadow(0 0 3px rgba(63, 246, 255, 0.85)) drop-shadow(0 0 9px rgba(255, 79, 216, 0.4));
}
/* Gold: polished gold rim (gradients live in index.html). */
[data-tube="gold"] {
  --t-stroke: url(#g-gold);
  --t-stroke-w: 3;
  --t-fill: var(--glass-fill);
  --t-lip-fill: url(#g-gold);
  --t-lip-stroke: #a8740a;
  --t-lip-w: 1.2;
  --t-shine: var(--shine);
  --t-filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.28));
}
/* Rainbow: rainbow outline. */
[data-tube="rainbow"] {
  --t-stroke: url(#g-rainbow);
  --t-stroke-w: 3.2;
  --t-fill: var(--glass-fill);
  --t-lip-fill: url(#g-rainbow-h);
  --t-lip-stroke: rgba(255, 255, 255, 0.85);
  --t-lip-w: 1.2;
  --t-shine: var(--shine);
  --t-filter: none;
}
/* Candy: thick bubble-gum pink. */
[data-tube="candy"] {
  --t-stroke: #ff6fae;
  --t-stroke-w: 3.4;
  --t-fill: rgba(255, 182, 214, 0.2);
  --t-lip-fill: #ffb3d4;
  --t-lip-stroke: #ff4f9a;
  --t-lip-w: 2;
  --t-shine: rgba(255, 255, 255, 0.7);
  --t-filter: drop-shadow(0 3px 0 rgba(200, 40, 110, 0.25));
}
/* Frost: thick frosted glass. */
[data-tube="frost"] {
  --t-stroke: var(--glass-stroke);
  --t-stroke-w: 4;
  --t-fill: rgba(255, 255, 255, 0.24);
  --t-lip-fill: rgba(255, 255, 255, 0.55);
  --t-lip-stroke: var(--glass-stroke);
  --t-lip-w: 2;
  --t-shine: rgba(255, 255, 255, 0.8);
  --t-filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.2));
}

/* ---------- background themes ---------- */
/* Neon: dark violet night with pink and cyan glows. */
[data-bg="neon"] {
  --bg: #07010f;
  --bg-image: radial-gradient(70% 45% at 15% 5%, rgba(255, 0, 200, 0.3), transparent 70%),
    radial-gradient(70% 45% at 90% 95%, rgba(0, 240, 255, 0.26), transparent 70%),
    linear-gradient(180deg, #14002e, #05010d);
  --panel: rgba(20, 4, 44, 0.8);
  --panel-solid: #16052e;
  --card-top: #2a0b52;
  --line: rgba(255, 120, 255, 0.24);
  --text: #fbefff;
  --muted: #c4a8e6;
  --accent: #ff4fd8;
  --accent-hi: #ff9bf0;
  --accent-ink: #33003a;
  --accent-shadow: #a3168c;
  --gold: #fff01f;
  --soft: rgba(255, 255, 255, 0.08);
  --overlay-bg: rgba(5, 0, 15, 0.65);
  --toast-bg: rgba(20, 4, 44, 0.92);
  --text-shadow: 0 0 14px rgba(255, 79, 216, 0.7);
  --glass-stroke: rgba(150, 245, 255, 0.85);
}
/* Pink: soft pastel (light). */
[data-bg="pink"] {
  --bg: #ffe3ef;
  --bg-image: radial-gradient(90% 50% at 50% 0%, rgba(255, 255, 255, 0.85), transparent 70%),
    linear-gradient(180deg, #ffd9ea, #ffb7d3);
  --panel: rgba(255, 242, 248, 0.9);
  --panel-solid: #ffe6f1;
  --card-top: #fff8fb;
  --line: rgba(160, 40, 100, 0.18);
  --text: #5c1238;
  --muted: #a4517a;
  --accent: #ff5fa2;
  --accent-hi: #ff9cc6;
  --accent-ink: #ffffff;
  --accent-shadow: #d63f82;
  --gold: #ff9f1c;
  --soft: rgba(255, 255, 255, 0.55);
  --off: rgba(160, 40, 100, 0.18);
  --overlay-bg: rgba(110, 20, 65, 0.3);
  --toast-bg: rgba(255, 242, 248, 0.95);
  --text-shadow: 0 2px 0 rgba(255, 255, 255, 0.8);
  --glass-stroke: rgba(150, 40, 95, 0.55);
  --glass-fill: rgba(255, 255, 255, 0.4);
  --lip-fill: rgba(255, 255, 255, 0.7);
  --shine: rgba(255, 255, 255, 0.75);
  color-scheme: light;
}
/* White: clean and bright (light). */
[data-bg="white"] {
  --bg: #f3f6fa;
  --bg-image: radial-gradient(90% 50% at 50% 0%, #ffffff, transparent 70%), linear-gradient(180deg, #f8fafc, #e3e9f1);
  --panel: rgba(255, 255, 255, 0.92);
  --panel-solid: #f1f4f9;
  --card-top: #ffffff;
  --line: rgba(30, 50, 80, 0.13);
  --text: #1d2a3a;
  --muted: #6b7a8c;
  --accent: #2f7cf6;
  --accent-hi: #6aa6ff;
  --accent-ink: #ffffff;
  --accent-shadow: #1d5cc4;
  --gold: #f5a700;
  --soft: rgba(30, 50, 80, 0.06);
  --off: rgba(30, 50, 80, 0.16);
  --overlay-bg: rgba(20, 35, 55, 0.3);
  --toast-bg: rgba(255, 255, 255, 0.96);
  --text-shadow: none;
  --glass-stroke: rgba(40, 60, 90, 0.5);
  --glass-fill: rgba(30, 50, 80, 0.04);
  --lip-fill: rgba(30, 50, 80, 0.06);
  --shine: rgba(255, 255, 255, 0.7);
  color-scheme: light;
}
/* Sunset: peach to violet. */
[data-bg="sunset"] {
  --bg: #4b1d5e;
  --bg-image: radial-gradient(60% 35% at 50% 8%, rgba(255, 230, 150, 0.45), transparent 70%),
    linear-gradient(180deg, #ff9a62 0%, #e8577e 42%, #6a2470 78%, #3a1450 100%);
  --panel: rgba(60, 18, 70, 0.78);
  --panel-solid: #4a1a5a;
  --card-top: #7a2c6c;
  --line: rgba(255, 220, 200, 0.22);
  --text: #fff6ef;
  --muted: #ffd0c0;
  --accent: #ffc94d;
  --accent-hi: #ffe28f;
  --accent-ink: #4a2300;
  --accent-shadow: #c48a1c;
  --gold: #ffe066;
  --soft: rgba(255, 255, 255, 0.14);
  --overlay-bg: rgba(40, 8, 40, 0.55);
  --toast-bg: rgba(60, 18, 70, 0.92);
  --text-shadow: 0 1px 8px rgba(90, 20, 60, 0.55);
  --glass-stroke: rgba(255, 244, 236, 0.88);
}
/* Forest: deep greens with a lime glow. */
[data-bg="forest"] {
  --bg: #0c2a20;
  --bg-image: radial-gradient(110% 55% at 50% 0%, rgba(170, 240, 120, 0.22), transparent 65%),
    linear-gradient(180deg, #1f5e46, #0c2a20);
  --panel: rgba(8, 34, 24, 0.78);
  --panel-solid: #123a2c;
  --card-top: #1e5641;
  --line: rgba(200, 255, 200, 0.16);
  --text: #f0fff4;
  --muted: #a8d4b6;
  --accent: #9be15d;
  --accent-hi: #c4f592;
  --accent-ink: #173a07;
  --accent-shadow: #5f9f2b;
  --overlay-bg: rgba(3, 20, 12, 0.6);
  --toast-bg: rgba(8, 34, 24, 0.92);
  --glass-stroke: rgba(230, 255, 236, 0.8);
}
/* Midnight: starry night sky. */
[data-bg="midnight"] {
  --bg: #04060f;
  --bg-image: radial-gradient(1.5px 1.5px at 12% 18%, #fff 60%, transparent 61%),
    radial-gradient(1px 1px at 28% 62%, #fff 60%, transparent 61%),
    radial-gradient(1.5px 1.5px at 44% 9%, #fff 60%, transparent 61%),
    radial-gradient(1px 1px at 57% 41%, #cfe0ff 60%, transparent 61%),
    radial-gradient(2px 2px at 71% 23%, #fff 60%, transparent 61%),
    radial-gradient(1px 1px at 86% 55%, #fff 60%, transparent 61%),
    radial-gradient(1.5px 1.5px at 92% 12%, #dfe8ff 60%, transparent 61%),
    radial-gradient(1px 1px at 8% 78%, #fff 60%, transparent 61%),
    radial-gradient(1.5px 1.5px at 36% 88%, #fff 60%, transparent 61%),
    radial-gradient(1px 1px at 64% 80%, #fff 60%, transparent 61%),
    radial-gradient(1px 1px at 80% 92%, #cfe0ff 60%, transparent 61%),
    radial-gradient(1px 1px at 20% 40%, #fff 60%, transparent 61%),
    radial-gradient(80% 45% at 75% 0%, rgba(110, 130, 255, 0.22), transparent 70%),
    linear-gradient(180deg, #0d1336, #03040a);
  --panel: rgba(10, 14, 38, 0.8);
  --panel-solid: #0e1430;
  --card-top: #1b2454;
  --line: rgba(180, 200, 255, 0.16);
  --text: #eef2ff;
  --muted: #a3afd9;
  --accent: #8fa8ff;
  --accent-hi: #c0ceff;
  --accent-ink: #0b1440;
  --accent-shadow: #5068c9;
  --overlay-bg: rgba(2, 3, 12, 0.65);
  --toast-bg: rgba(10, 14, 38, 0.92);
  --glass-stroke: rgba(220, 230, 255, 0.8);
}

/* ---------- theme picker ---------- */
.theme-card {
  width: min(420px, 100%);
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  gap: 10px;
}
.theme-sec {
  margin: 4px 0 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.theme-opt {
  position: relative;
  border: 2px solid transparent;
  border-radius: 16px;
  padding: 0;
  overflow: hidden;
  background: var(--soft);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  transition: transform 0.12s, border-color 0.2s;
}
.theme-opt:active {
  transform: scale(0.95);
}
.theme-opt:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.theme-opt[aria-checked="true"] {
  border-color: var(--accent);
}
.theme-opt[aria-checked="true"]::after {
  content: "✓";
  position: absolute;
  top: 5px;
  right: 5px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
  background: var(--accent);
  color: var(--accent-ink);
}
.theme-opt-name {
  font-size: 13px;
  font-weight: 700;
  padding: 6px 4px 7px;
}
/* A background card carries its own data-bg, so these vars are that theme's. */
.bg-swatch {
  height: 64px;
  background: var(--bg);
  background-image: var(--bg-image);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 5px;
  padding-bottom: 8px;
}
.bg-swatch i {
  width: 22px;
  height: 7px;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--accent-hi), var(--accent));
}
.bg-swatch i + i {
  width: 12px;
  background: var(--text);
  opacity: 0.7;
}
.tube-swatch {
  height: 92px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  padding-top: 10px;
}
.mini-tube {
  width: 22px;
  height: 72px;
}
/* Preview tubes (home logo, theme picker): size the glass to its own box. */
.mini-tube,
.logo-tube {
  position: relative;
}
.mini-tube .tube,
.logo-tube .tube {
  position: absolute;
  inset: 0;
}
.mini-tube .shaker,
.mini-tube svg {
  width: 100%;
  height: 100%;
  display: block;
}
.home .corner {
  display: flex;
  gap: 8px;
}

/* ---------- how to play ---------- */
#btn-howto {
  min-width: 180px;
}
.howto-card {
  width: min(400px, 100%);
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  text-align: center;
  gap: 10px;
  touch-action: pan-y;
}
.howto-step {
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}
.howto-demo {
  position: relative;
  min-height: 176px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 4px;
  border-radius: 18px;
  background: var(--soft);
  overflow: hidden;
}
.howto-title {
  margin: 4px 0 0;
  font-size: 24px;
  font-weight: 800;
}
.howto-text {
  margin: 0;
  min-height: 3em;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.5;
}
.demo-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}
.demo-group {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.howto-demo .mini-tube {
  width: 30px;
  height: 98px;
}
.demo-arrow {
  align-self: center;
  font-size: 26px;
  font-weight: 800;
  color: var(--muted);
}
.mini-tube.done .cap {
  display: inline;
}
.demo-lift {
  animation: demo-lift 2.6s ease-in-out infinite;
}
/* In step with the finger animation: lift on the first tap, drop after the second. */
@keyframes demo-lift {
  0%, 15% { transform: none; }
  22%, 60% { transform: translateY(-14px); }
  68%, 100% { transform: none; }
}
.howto-demo .finger {
  font-size: 32px;
  margin: -4px 0 0 -12px;
}
.rule-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}
.rule {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px 6px;
  border-radius: 14px;
  border: 2px solid transparent;
}
.rule.ok {
  border-color: rgba(61, 220, 132, 0.6);
}
.rule.no {
  border-color: rgba(255, 90, 110, 0.6);
}
.rule-tubes {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}
.howto-demo .rule .mini-tube {
  width: 18px;
  height: 58px;
}
.rule-arrow {
  align-self: center;
  font-size: 16px;
  font-weight: 800;
  color: var(--muted);
}
.rule-label {
  font-size: 12px;
  font-weight: 700;
}
.rule-mark {
  position: absolute;
  top: 4px;
  right: 6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
}
.rule.ok .rule-mark {
  background: #2fbf71;
}
.rule.no .rule-mark {
  background: #f0506a;
}
.howto-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  text-align: left;
}
.howto-item {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}
.howto-item .tool-icon {
  width: 40px;
  height: 40px;
  border-radius: 13px;
  flex: none;
  box-shadow: none;
}
.howto-item .tool-icon .ic {
  width: 22px;
  height: 22px;
}
.howto-item div {
  display: flex;
  flex-direction: column;
}
.howto-item div span {
  color: var(--muted);
  font-size: 13px;
}
.howto-stars {
  flex: none;
  width: 64px;
  font-size: 18px;
  letter-spacing: 1px;
  color: var(--off);
}
.howto-stars b {
  color: var(--gold);
  font-weight: 400;
}
.howto-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
}
.howto-dots i {
  width: 8px;
  height: 8px;
  border-radius: 4px;
  background: var(--off);
  transition: width 0.2s, background 0.2s;
}
.howto-dots i.on {
  width: 22px;
  background: var(--accent);
}
.howto-nav .btn {
  flex: 1;
}
@media (max-height: 640px) {
  .logo,
  .logo-tube {
    height: 96px;
  }
  .logo-tube {
    width: 30px;
  }
  .home-main {
    gap: 12px;
  }
}

/* ---------- volume sliders (Settings) ---------- */
.setting > span:first-child {
  flex: 1;
}
.vol {
  width: clamp(80px, 30vw, 130px);
  height: 44px; /* tap target */
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
  touch-action: pan-x;
}
.vol:disabled {
  opacity: 0.35;
  cursor: default;
}

/* =========================================================================
 * LOCAL PLAYER PROFILE (one-tap register, no forms)
 * Reuses the existing palette: mint primary, translucent secondary, cards.
 * ======================================================================= */
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.overlay {
  padding: max(16px, var(--safe-t)) 16px max(16px, var(--safe-b));
}

/* home */
.home {
  overflow-y: auto; /* short screens may scroll; nothing gets cut off */
}
.home-main {
  padding: calc(64px + var(--safe-t)) 16px calc(24px + var(--safe-b));
  gap: 12px;
}
.home-cta {
  width: 100%;
}
.btn.wide {
  width: 100%;
}
.btn.outline {
  color: var(--text);
  background: var(--soft);
  border: 1.5px solid color-mix(in srgb, var(--text) 38%, transparent);
  box-shadow: none;
}
.btn.outline:active {
  transform: scale(0.98);
  box-shadow: none;
}
.home-register {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.note {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
  text-align: center;
}
.home-aux {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.btn.compact,
#btn-levels.compact,
#btn-howto.compact {
  flex: 1 1 140px;
  min-width: 0;
  min-height: 44px;
  padding: 8px 14px;
  font-size: 15px;
}
.profile-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 5px 16px 5px 5px;
  border-radius: 999px;
  background: var(--soft);
  border: 1px solid var(--line);
}
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, var(--accent-hi), var(--accent));
  color: var(--accent-ink);
}
.avatar .ic {
  width: 18px;
  height: 18px;
}
.profile-name {
  font-weight: 700;
  letter-spacing: 0.3px;
  overflow-wrap: anywhere;
}
/* short "working…" state while registering */
.btn.busy {
  pointer-events: none;
  opacity: 0.85;
}
.btn.busy::after {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-left: 8px;
  vertical-align: -2px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* settings: player profile */
.settings-card {
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}
.profile-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.profile-row {
  display: flex;
  flex-wrap: wrap; /* narrow phones: the button moves to its own line */
  align-items: center;
  gap: 10px;
  min-height: 44px;
}
.profile-row .profile-name {
  flex: 1 1 auto;
  overflow-wrap: normal;
}
#btn-settings-register {
  flex: 1 0 auto; /* fills its line when wrapped */
}
.profile-box .note {
  text-align: left;
}

/* register dialogs */
.reg-card {
  width: min(380px, 100%);
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  align-items: center;
  text-align: center;
  gap: 12px;
  padding-top: 26px;
}
.dlg-close {
  position: absolute;
  top: 12px;
  right: 12px;
}
.dlg-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--soft);
  border: 1px solid var(--line);
  flex: none;
}
.dlg-icon.check {
  background: linear-gradient(180deg, var(--accent-hi), var(--accent));
  color: var(--accent-ink);
  border: 0;
}
.dlg-icon.check .ic {
  width: 30px;
  height: 30px;
  stroke-width: 2.6;
}
.dlg-icon.tubes {
  width: auto;
  height: auto;
  border-radius: 16px;
  padding: 10px 14px 8px;
  display: flex;
  align-items: flex-end;
  gap: 6px;
}
.dlg-icon.tubes .mini-tube {
  width: 16px;
  height: 52px;
}
.dlg-title {
  margin: 2px 0 0;
  font-size: 26px;
  font-weight: 800;
}
.dlg-text {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.45;
}
.dlg-text.strong {
  color: var(--text);
  font-weight: 600;
}
.name-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 10px;
  border-radius: 16px;
  background: var(--soft);
  border: 1px solid var(--line);
}
.name-card-text {
  flex: 1;
  min-width: 0;
  text-align: left;
  font-size: clamp(17px, 5.4vw, 22px);
  font-weight: 800;
  letter-spacing: 0.3px;
  white-space: nowrap; /* never split the username */
}
/* Dialog buttons: one line on narrow phones */
.reg-card .btn.big {
  font-size: 19px;
  min-height: 54px;
  padding: 12px 20px;
}

/* Switches stay 54×32 visually, but the tap area is at least 44px tall. */
.switch::before {
  content: "";
  position: absolute;
  inset: -6px -4px;
}
/* Message dialogs with a ✕: keep the text clear of the close button. */
.dlg-msg {
  padding: 30px 8px 0;
}

/* Any dialog card taller than a short / landscape screen scrolls inside itself,
   so no button is ever out of reach (the overlay itself doesn't scroll). */
.card {
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
