/*
 * style.css — Block Blast
 * Sizes (--cell, --gap, --bpad, --board, --trayh) and animation timings
 * (--*-ms) are set from JS (render.js) using logic.js CONFIG.
 *
 * Themes: every color below is a token. A theme is a [data-theme="…"] block
 * that overrides tokens; <html data-theme> picks the active one. The same
 * selectors also style the small previews in the theme picker.
 */

/* Classic (default): dark navy. */
:root,
[data-theme="classic"] {
  --bg-top: #16307a;
  --bg-bottom: #0a1433;
  --bg-glow: rgba(80, 120, 255, 0.35);
  --panel: #0b1a45;
  --panel-edge: rgba(130, 160, 255, 0.18);
  --board-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.45), 0 12px 30px rgba(0, 0, 0, 0.35);
  --empty: #14275e;
  --empty-shadow: inset 0 calc(var(--cell) * 0.06) calc(var(--cell) * 0.1) rgba(0, 0, 0, 0.35);
  --block-glow: 0 0 0 transparent;
  --text: #eef3ff;
  --muted: #9db0e0;
  --gold: #ffd23f;            /* accent: best score, goal, highlights */
  --accent-ink: #2a1a00;      /* text on top of the accent */
  --title-grad: linear-gradient(90deg, #ffe066, #ff9f1c 45%, #ff6ec7);
  --btn-bg: rgba(255, 255, 255, 0.07);
  --btn-bg-hover: rgba(255, 255, 255, 0.14);
  --track: rgba(255, 255, 255, 0.1);
  --goal-1: #ff9f1c;
  --goal-2: #ffd23f;
  --card-top: #1c3a8a;
  --card-bottom: #0f1f4d;
  --banner-bg: rgba(10, 20, 60, 0.82);
  --overlay-bg: rgba(4, 9, 28, 0.72);
  --score-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

/* Pink: soft pastel pink. */
[data-theme="pink"] {
  --bg-top: #ffe1ee;
  --bg-bottom: #ffb8d5;
  --bg-glow: rgba(255, 255, 255, 0.7);
  --panel: #f59cc1;
  --panel-edge: rgba(200, 40, 110, 0.25);
  --board-shadow: inset 0 2px 10px rgba(150, 20, 80, 0.25), 0 12px 28px rgba(200, 50, 120, 0.3);
  --empty: #ffd0e3;
  --empty-shadow: inset 0 calc(var(--cell) * 0.05) calc(var(--cell) * 0.08) rgba(160, 30, 90, 0.22);
  --text: #5c1238;
  --muted: #a4517a;
  --gold: #e8337a;
  --accent-ink: #ffffff;
  --title-grad: linear-gradient(90deg, #ff3d8b, #c2187a);
  --btn-bg: rgba(255, 255, 255, 0.55);
  --btn-bg-hover: rgba(255, 255, 255, 0.8);
  --track: rgba(160, 30, 90, 0.15);
  --goal-1: #ff6aa8;
  --goal-2: #e8337a;
  --card-top: #fff0f6;
  --card-bottom: #ffd3e5;
  --banner-bg: rgba(255, 240, 247, 0.92);
  --overlay-bg: rgba(90, 20, 55, 0.45);
  --score-shadow: 0 2px 0 rgba(255, 255, 255, 0.7);
  color-scheme: light;
}

/* Light blue: sky / ice. */
[data-theme="lightblue"] {
  --bg-top: #e6f6ff;
  --bg-bottom: #a9dcff;
  --bg-glow: rgba(255, 255, 255, 0.75);
  --panel: #7fc3ef;
  --panel-edge: rgba(20, 100, 170, 0.25);
  --board-shadow: inset 0 2px 10px rgba(10, 70, 130, 0.25), 0 12px 28px rgba(30, 110, 180, 0.3);
  --empty: #cbe9fc;
  --empty-shadow: inset 0 calc(var(--cell) * 0.05) calc(var(--cell) * 0.08) rgba(20, 80, 140, 0.22);
  --text: #0e3553;
  --muted: #4a7898;
  --gold: #0d84d8;
  --accent-ink: #ffffff;
  --title-grad: linear-gradient(90deg, #1d9bf0, #0b5fa8);
  --btn-bg: rgba(255, 255, 255, 0.55);
  --btn-bg-hover: rgba(255, 255, 255, 0.8);
  --track: rgba(20, 80, 140, 0.15);
  --goal-1: #4cc3ff;
  --goal-2: #0d84d8;
  --card-top: #f2faff;
  --card-bottom: #cdeaff;
  --banner-bg: rgba(240, 250, 255, 0.92);
  --overlay-bg: rgba(10, 40, 70, 0.45);
  --score-shadow: 0 2px 0 rgba(255, 255, 255, 0.7);
  color-scheme: light;
}

/* Pink + blue: pastel gradient from pink to blue. */
[data-theme="pinkblue"] {
  --bg-top: #ffb3d6;
  --bg-bottom: #8fc8ff;
  --bg-glow: rgba(255, 255, 255, 0.5);
  --panel: rgba(110, 80, 190, 0.35);
  --panel-edge: rgba(255, 255, 255, 0.55);
  --board-shadow: inset 0 2px 10px rgba(60, 30, 120, 0.25), 0 12px 28px rgba(90, 60, 170, 0.3);
  --empty: rgba(255, 255, 255, 0.42);
  --empty-shadow: inset 0 calc(var(--cell) * 0.05) calc(var(--cell) * 0.08) rgba(70, 40, 130, 0.2);
  --text: #2d1b57;
  --muted: #5e4a8f;
  --gold: #7b3ff2;
  --accent-ink: #ffffff;
  --title-grad: linear-gradient(90deg, #ff4f9a, #6a5cff 60%, #1d9bf0);
  --btn-bg: rgba(255, 255, 255, 0.45);
  --btn-bg-hover: rgba(255, 255, 255, 0.7);
  --track: rgba(70, 40, 130, 0.15);
  --goal-1: #ff6aa8;
  --goal-2: #6a8cff;
  --card-top: #ffe3f1;
  --card-bottom: #d4e9ff;
  --banner-bg: rgba(255, 245, 252, 0.9);
  --overlay-bg: rgba(45, 27, 87, 0.45);
  --score-shadow: 0 2px 0 rgba(255, 255, 255, 0.7);
  color-scheme: light;
}

/* Neon: near-black with glowing blocks. */
[data-theme="neon"] {
  --bg-top: #170030;
  --bg-bottom: #04000c;
  --bg-glow: rgba(255, 0, 200, 0.28);
  --panel: #0a0018;
  --panel-edge: rgba(0, 240, 255, 0.55);
  --board-shadow: 0 0 18px rgba(0, 240, 255, 0.35), 0 0 40px rgba(255, 0, 200, 0.2), inset 0 0 20px rgba(0, 240, 255, 0.12);
  --empty: #120628;
  --empty-shadow: inset 0 0 0 1px rgba(0, 240, 255, 0.14);
  --text: #f4ecff;
  --muted: #b892ff;
  --gold: #39ff88;
  --accent-ink: #001a0b;
  --title-grad: linear-gradient(90deg, #00f0ff, #ff2bd6);
  --btn-bg: rgba(0, 240, 255, 0.08);
  --btn-bg-hover: rgba(0, 240, 255, 0.18);
  --track: rgba(0, 240, 255, 0.12);
  --goal-1: #00f0ff;
  --goal-2: #ff2bd6;
  --card-top: #1c0838;
  --card-bottom: #08001a;
  --banner-bg: rgba(10, 0, 26, 0.88);
  --overlay-bg: rgba(0, 0, 0, 0.7);
  color-scheme: dark;
}

/* ---------------- block palettes ----------------
 * 8 colors per theme. Board cells store an index (0–7) and are painted with
 * var(--bN), so switching theme recolors every block on the board and tray.
 */
:root,
[data-theme="classic"] {
  --b0: #ff4d6d; --b1: #ff9f1c; --b2: #ffd23f; --b3: #3ddc84;
  --b4: #22c3ee; --b5: #4f7cff; --b6: #a66cff; --b7: #ff6ec7;
}
/* Pink: raspberry, rose, magenta, plum, peach, honey, sky, lavender. */
[data-theme="pink"] {
  --b0: #e0245e; --b1: #ff5c8a; --b2: #c2189b; --b3: #8e2fc9;
  --b4: #ff8c42; --b5: #f2b705; --b6: #3fb7e8; --b7: #a274f0;
}
/* Light blue: navy, ocean, teal, mint, indigo, plus warm accents. */
[data-theme="lightblue"] {
  --b0: #1747a6; --b1: #0a7fd1; --b2: #0aa6b8; --b3: #22c39a;
  --b4: #5b5fd6; --b5: #ff9f1c; --b6: #ffcc29; --b7: #ff5d73;
}
/* Pink blue: candy pinks and periwinkle blues. */
[data-theme="pinkblue"] {
  --b0: #ff4f8b; --b1: #ff86bd; --b2: #4f7dff; --b3: #6fb3ff;
  --b4: #9b5de5; --b5: #c77dff; --b6: #2ec5e6; --b7: #ffb627;
}
/* Neon: electric, fully saturated. */
[data-theme="neon"] {
  --b0: #ff2bd6; --b1: #00f0ff; --b2: #39ff88; --b3: #fff01f;
  --b4: #ff7a00; --b5: #b026ff; --b6: #ff3860; --b7: #2b8cff;
}
/* White: clean, slightly softer modern colors. */
[data-theme="white"] {
  --b0: #fa5252; --b1: #fd7e14; --b2: #fab005; --b3: #40c057;
  --b4: #15aabf; --b5: #4c6ef5; --b6: #7950f2; --b7: #e64980;
}

/* Neon glow is declared on the blocks, where --c (the block color) exists. */
[data-theme="neon"] .cell.filled,
[data-theme="neon"] .cell.ghost,
[data-theme="neon"] .pc,
[data-theme="neon"] .fx-cell {
  --block-glow: 0 0 calc(var(--u0) * 0.25) var(--c), 0 0 calc(var(--u0) * 0.6) var(--c);
}

/* White: clean and bright. */
[data-theme="white"] {
  --bg-top: #ffffff;
  --bg-bottom: #e9edf4;
  --bg-glow: rgba(255, 255, 255, 0.9);
  --panel: #d5dbe6;
  --panel-edge: rgba(30, 40, 70, 0.12);
  --board-shadow: inset 0 2px 8px rgba(30, 40, 70, 0.15), 0 12px 28px rgba(30, 40, 70, 0.15);
  --empty: #eef1f6;
  --empty-shadow: inset 0 calc(var(--cell) * 0.05) calc(var(--cell) * 0.08) rgba(30, 40, 70, 0.14);
  --text: #1d2433;
  --muted: #6b7488;
  --gold: #e08600;
  --accent-ink: #ffffff;
  --title-grad: linear-gradient(90deg, #ff8a00, #ff3d7f);
  --btn-bg: rgba(30, 40, 70, 0.05);
  --btn-bg-hover: rgba(30, 40, 70, 0.1);
  --track: rgba(30, 40, 70, 0.1);
  --goal-1: #ffb000;
  --goal-2: #ff7a00;
  --card-top: #ffffff;
  --card-bottom: #eef1f6;
  --banner-bg: rgba(255, 255, 255, 0.94);
  --overlay-bg: rgba(20, 25, 40, 0.4);
  --score-shadow: 0 2px 0 rgba(255, 255, 255, 0.7);
  color-scheme: light;
}

:root {
  --cell: 40px;
  --gap: 3px;
  --bpad: 6px;
  --board: 350px;
  --trayh: 140px;

  --clear-ms: 300ms;
  --settle-ms: 220ms;
  --tray-ms: 280ms;
  --return-ms: 200ms;
  --float-ms: 1000ms;

  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

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

body {
  background-color: var(--bg-bottom);
  background-image:
    radial-gradient(120% 60% at 50% 0%, var(--bg-glow), transparent 70%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  color: var(--text);
  font-family: var(--font);
  /* No scrolling, pinch or double-tap zoom while playing. */
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

#app {
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding:
    max(10px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------------- top bar ---------------- */
.topbar {
  width: max(var(--board), min(100%, 360px));
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex: none;
}

.brand { min-width: 0; }

.title {
  margin: 0;
  font-size: clamp(15px, 4.6vw, 22px);
  font-weight: 800;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--title-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hint {
  margin: 2px 0 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--muted);
}
.hint[hidden] { display: none; }

.controls {
  display: flex;
  gap: 6px;
  flex: none;
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--panel-edge);
  background: var(--btn-bg);
  color: var(--text);
  font: 700 18px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s, transform 0.1s;
}
.icon-btn.lang { font-size: 15px; }
.icon-btn:hover { background: var(--btn-bg-hover); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn:focus-visible,
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------------- score ---------------- */
.scorebar {
  width: max(var(--board), min(100%, 360px));
  max-width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  flex: none;
}

.best {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 800;
  font-size: 16px;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.score-box { text-align: center; }
.score-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.score-value {
  font-size: clamp(28px, 8vw, 42px);
  font-weight: 900;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  text-shadow: var(--score-shadow);
}
.score-value.bump { animation: bump 0.35s ease-out; }
@keyframes bump {
  40% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* ---------------- board ---------------- */
.stage {
  position: relative;
  width: var(--board);
  height: var(--board);
  flex: none;
}

.board {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--n, 8), var(--cell));
  grid-auto-rows: var(--cell);
  gap: var(--gap);
  padding: var(--bpad);
  background: var(--panel);
  border-radius: calc(var(--bpad) * 1.6);
  box-shadow:
    inset 0 0 0 1px var(--panel-edge),
    var(--board-shadow);
  touch-action: none;
}

.cell {
  border-radius: calc(var(--cell) * 0.2);
  background: var(--empty);
  box-shadow: var(--empty-shadow);
}

/* Shared block look: bright color, top-left highlight, inner bevel. */
.cell.filled,
.cell.ghost,
.pc,
.fx-cell {
  --u0: var(--u, var(--cell));
  background-color: var(--c);
  background-image: linear-gradient(145deg, rgba(255, 255, 255, 0.38) 0%, rgba(255, 255, 255, 0) 48%, rgba(0, 0, 0, 0.14) 100%);
  border-radius: calc(var(--u0) * 0.2);
  box-shadow:
    inset 0 calc(var(--u0) * 0.09) 0 rgba(255, 255, 255, 0.3),
    inset 0 calc(var(--u0) * -0.11) 0 rgba(0, 0, 0, 0.26),
    var(--block-glow);
}

.cell.ghost {
  background-color: var(--gc);
  opacity: 0.45;
}
.cell.ghost.hint { opacity: 0.85; }

/* Rows/cols that would clear: recolor in the dragged piece's color and glow. */
.cell.hint {
  filter: brightness(1.15) drop-shadow(0 0 calc(var(--cell) * 0.18) var(--hc));
}
.cell.hint.filled { background-color: var(--hc); }

.cell.settle { animation: settle var(--settle-ms) ease-out; }
@keyframes settle {
  0% { transform: scale(0.82); }
  60% { transform: scale(1.07); }
  100% { transform: scale(1); }
}

/* ---------------- effects layer ---------------- */
.fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.fx-cell {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  animation: pop var(--clear-ms) ease-out both;
}
@keyframes pop {
  0% { transform: scale(1); filter: brightness(1); opacity: 1; }
  35% { transform: scale(1.18); filter: brightness(1.9); opacity: 1; }
  100% { transform: scale(0.2); filter: brightness(1.3); opacity: 0; }
}

.float {
  position: absolute;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-weight: 900;
  white-space: nowrap;
  pointer-events: none;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35), 0 0 14px rgba(0, 0, 0, 0.45);
  animation: floatUp var(--float-ms) ease-out both;
}
.float .pts { font-size: calc(var(--cell) * 0.85); color: #fff; }
.float .combo { font-size: calc(var(--cell) * 0.55); color: var(--gold); }
.float .perfect { font-size: calc(var(--cell) * 0.7); color: #7ef9ff; }
@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  70% { opacity: 1; transform: translate(-50%, -80%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -120%) scale(1); }
}

/* ---------------- score milestones ---------------- */
.goal {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.goal-track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--track);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}
.goal-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--goal-1), var(--goal-2));
  box-shadow: 0 0 8px var(--goal-2);
  transition: width 0.45s ease-out;
}
.goal-fill.instant { transition: none; }
.goal-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.goal-label b { color: var(--gold); font-weight: 900; }
.goal.flash .goal-track { animation: goalFlash 0.65s ease-out; }
.goal.flash .goal-label { color: var(--gold); }
@keyframes goalFlash {
  0%, 100% { box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4); }
  30% { box-shadow: 0 0 0 3px rgba(255, 210, 63, 0.5), 0 0 18px rgba(255, 210, 63, 0.9); }
}

/* "🎉 400" banner over the board; never blocks input. */
.milestone {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.milestone[hidden] { display: none; }
.ms-inner {
  padding: calc(var(--cell) * 0.3) calc(var(--cell) * 0.7);
  text-align: center;
  border-radius: 20px;
  border: 2px solid var(--gold);
  background: var(--banner-bg);
  box-shadow: 0 0 40px rgba(255, 210, 63, 0.55), 0 12px 30px rgba(0, 0, 0, 0.45);
}
.milestone.show .ms-inner { animation: msPop 1.8s ease-out both; }
.ms-title {
  font-size: calc(var(--cell) * 0.42);
  font-weight: 800;
  color: var(--gold);
  white-space: nowrap;
}
.ms-value {
  font-size: calc(var(--cell) * 1.4);
  font-weight: 900;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #fff6c2, #ffd23f 55%, #ff9f1c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.35));
}
@keyframes msPop {
  0% { opacity: 0; transform: scale(0.4) rotate(-6deg); }
  14% { opacity: 1; transform: scale(1.15) rotate(2deg); }
  24% { transform: scale(1) rotate(0); }
  80% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.06) translateY(-12px); }
}

/* Full-screen confetti (outside #app so the combo shake doesn't move it). */
#confetti {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  overflow: hidden;
}
.confetti {
  position: absolute;
  top: -20px;
  border-radius: 2px;
  animation-name: confettiFall;
  animation-timing-function: cubic-bezier(0.25, 0.6, 0.4, 1);
  animation-fill-mode: both;
}
@keyframes confettiFall {
  0% { opacity: 1; transform: translate3d(0, 0, 0) rotate(0); }
  85% { opacity: 1; }
  100% { opacity: 0; transform: translate3d(var(--drift), 105vh, 0) rotate(var(--rot)); }
}

/* ---------------- combo celebration ---------------- */
/* Screen shake; amplitude and duration grow with the combo (set from JS). */
#app.shake { animation: shake var(--shake-ms, 400ms) cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }
@keyframes shake {
  10% { transform: translate3d(calc(var(--shake-px) * -0.5), calc(var(--shake-px) * 0.3), 0); }
  20% { transform: translate3d(var(--shake-px), calc(var(--shake-px) * -0.4), 0); }
  30% { transform: translate3d(calc(var(--shake-px) * -1), calc(var(--shake-px) * 0.5), 0); }
  40% { transform: translate3d(calc(var(--shake-px) * 0.8), calc(var(--shake-px) * -0.3), 0); }
  55% { transform: translate3d(calc(var(--shake-px) * -0.6), calc(var(--shake-px) * 0.3), 0); }
  70% { transform: translate3d(calc(var(--shake-px) * 0.4), calc(var(--shake-px) * -0.2), 0); }
  85% { transform: translate3d(calc(var(--shake-px) * -0.2), 0, 0); }
  100% { transform: none; }
}

/* Gold flash around the board. */
.stage.celebrate::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: calc(var(--bpad) * 1.6);
  pointer-events: none;
  animation: boardFlash 0.7s ease-out both;
}
@keyframes boardFlash {
  0% { box-shadow: 0 0 0 0 rgba(255, 210, 63, 0), inset 0 0 0 0 rgba(255, 210, 63, 0); }
  20% {
    box-shadow:
      0 0 calc(var(--cell) * 1.2) calc(var(--cell) * 0.15) rgba(255, 210, 63, var(--glow, 0.6)),
      inset 0 0 calc(var(--cell) * 0.8) rgba(255, 230, 120, var(--glow, 0.6));
  }
  100% { box-shadow: 0 0 0 0 rgba(255, 210, 63, 0), inset 0 0 0 0 rgba(255, 210, 63, 0); }
}

.spark {
  position: absolute;
  z-index: 4;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 6px currentColor;
  animation: spark 0.75s cubic-bezier(0.15, 0.7, 0.3, 1) both;
}
@keyframes spark {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1.3); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.3); }
}

/* ---------------- action bar (reroll) ---------------- */
.actionbar {
  width: var(--board);
  display: flex;
  justify-content: flex-start;
  flex: none;
}

.reroll-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 8px 0 10px;
  border-radius: 999px;
  border: 1px solid var(--panel-edge);
  background: var(--btn-bg);
  color: var(--text);
  font: 700 14px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s, transform 0.1s, opacity 0.2s;
}
.reroll-btn:hover:not(:disabled) { background: var(--btn-bg-hover); }
.reroll-btn:active:not(:disabled) { transform: scale(0.95); }
.reroll-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.reroll-btn:disabled { opacity: 0.4; cursor: default; }
.reroll-icon { font-size: 15px; }
.reroll-count {
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--gold);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 900;
}
/* No piece fits but a swap is left: draw attention to the button. */
.reroll-btn.urgent {
  border-color: var(--gold);
  animation: urgent 0.9s ease-in-out infinite;
}
@keyframes urgent {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 210, 63, 0.7); transform: scale(1); }
  50% { box-shadow: 0 0 0 8px rgba(255, 210, 63, 0); transform: scale(1.06); }
}

/* ---------------- tray ---------------- */
.tray {
  width: var(--board);
  height: var(--trayh);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  flex: none;
  touch-action: none;
}

.slot {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
}

.piece {
  position: relative;
  flex: none;
  transition: filter 0.3s, opacity 0.3s;
}
.piece .pc,
.drag-clone .pc { position: absolute; }
.piece.lifted { visibility: hidden; }
.piece.dead { filter: grayscale(1) brightness(0.55); opacity: 0.8; }
.piece.enter { animation: trayIn var(--tray-ms) cubic-bezier(0.2, 0.9, 0.3, 1.25) both; }
@keyframes trayIn {
  from { opacity: 0; transform: translateY(45%) scale(0.6); }
  to { opacity: 1; transform: none; }
}

#drag-layer {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  overflow: hidden;
}
.drag-clone {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
  filter: drop-shadow(0 10px 12px rgba(0, 0, 0, 0.45));
}
.drag-clone.returning { transition: transform var(--return-ms) ease-out; }

/* ---------------- overlays ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--overlay-bg);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.25s ease-out;
}
.overlay[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } }

.card {
  width: min(320px, 100%);
  padding: 26px 22px 24px;
  text-align: center;
  border-radius: 22px;
  border: 1px solid var(--panel-edge);
  background: linear-gradient(180deg, var(--card-top), var(--card-bottom));
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: cardIn 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes cardIn { from { opacity: 0; transform: scale(0.85) translateY(20px); } }

.card h2 { margin: 0 0 14px; font-size: 26px; font-weight: 900; }
.card-label { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: 0.12em; text-transform: uppercase; }
.final { font-size: 54px; font-weight: 900; line-height: 1.1; font-variant-numeric: tabular-nums; }
.newbest {
  margin: 4px 0 2px;
  font-size: 18px;
  font-weight: 900;
  color: var(--gold);
  animation: pulse 0.8s ease-in-out infinite alternate;
}
.newbest[hidden] { display: none; }
@keyframes pulse { to { transform: scale(1.08); } }
.card-best { margin: 8px 0 20px; color: var(--gold); font-weight: 700; }
.confirm-text { margin: 4px 0 20px; font-size: 17px; line-height: 1.5; }
.btn-row { display: flex; gap: 10px; justify-content: center; }

.btn {
  border: 0;
  border-radius: 999px;
  padding: 12px 28px;
  font: 800 17px/1.2 var(--font);
  color: #2a1a00;
  background: linear-gradient(180deg, #ffe066, #ffb703);
  box-shadow: 0 4px 0 #c27c00, 0 8px 18px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #c27c00; }
.btn.secondary { color: var(--text); background: var(--btn-bg-hover); box-shadow: none; }
.btn-row .btn { padding: 12px 20px; }

/* ---------------- theme picker ---------------- */
.theme-card { width: min(360px, 100%); padding: 20px 18px 18px; text-align: left; }
.theme-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.theme-head h2 { margin: 0; font-size: 22px; }
.theme-head .icon-btn { font-size: 16px; }
.theme-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.theme-opt {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 6px 8px;
  border-radius: 14px;
  border: 2px solid transparent;
  background: var(--btn-bg);
  color: var(--text);
  font: 700 14px/1.2 var(--font);
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s, border-color 0.15s;
}
.theme-opt:hover { background: var(--btn-bg-hover); }
.theme-opt:active { transform: scale(0.96); }
.theme-opt:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.theme-opt[aria-checked="true"] { border-color: var(--gold); }
.theme-opt[aria-checked="true"]::after {
  content: "✓";
  position: absolute;
  top: 2px;
  right: 6px;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--gold);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 900;
}
/* Mini preview: carries its own data-theme, so it shows that theme's tokens. */
.swatch {
  --cell: 14px;
  height: 58px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(120% 60% at 50% 0%, var(--bg-glow), transparent 70%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  border: 1px solid rgba(127, 127, 127, 0.25);
}
.swatch-board {
  display: grid;
  grid-template-columns: repeat(4, var(--cell));
  gap: 2px;
  padding: 3px;
  border-radius: 5px;
  background: var(--panel);
  box-shadow: inset 0 0 0 1px var(--panel-edge), var(--board-shadow);
}
.swatch-board .cell { --u0: var(--cell); width: var(--cell); height: var(--cell); }

/* ---------------- home page ---------------- */
.home {
  position: fixed;
  inset: 0;
  z-index: 80; /* above the game, below popups (theme picker, confirm) */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background-color: var(--bg-bottom);
  background-image:
    radial-gradient(120% 60% at 50% 0%, var(--bg-glow), transparent 70%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  overflow-y: auto;
  animation: fadeIn 0.3s ease-out;
}
.home[hidden] { display: none; }
.home.leaving { animation: homeOut 0.25s ease-in forwards; }
@keyframes homeOut { to { opacity: 0; transform: scale(1.04); } }

.home-tools {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  display: flex;
  gap: 6px;
}
/* Music off: dimmed note with a strike-through. */
.music-btn { position: relative; font-size: 20px; }
.music-btn[aria-pressed="false"] { opacity: 0.55; }
.music-btn[aria-pressed="false"]::after {
  content: "";
  position: absolute;
  left: 22%;
  right: 22%;
  top: 50%;
  height: 2px;
  border-radius: 2px;
  background: var(--text);
  transform: rotate(-40deg);
}
.home-inner {
  width: min(340px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

/* Logo: a little 3×3 block arrangement that bobs gently. */
.home-logo {
  --cell: 40px;
  display: grid;
  grid-template-columns: repeat(3, var(--cell));
  gap: 5px;
  margin-bottom: 18px;
}
.home-logo span {
  width: var(--cell);
  height: var(--cell);
  animation: bob 2.4s ease-in-out infinite;
}
.home-logo span:not(.gap) {
  --u0: var(--cell);
  background-color: var(--c);
  background-image: linear-gradient(145deg, rgba(255, 255, 255, 0.38) 0%, rgba(255, 255, 255, 0) 48%, rgba(0, 0, 0, 0.14) 100%);
  border-radius: calc(var(--cell) * 0.2);
  box-shadow:
    inset 0 calc(var(--cell) * 0.09) 0 rgba(255, 255, 255, 0.3),
    inset 0 calc(var(--cell) * -0.11) 0 rgba(0, 0, 0, 0.26),
    var(--block-glow);
}
[data-theme="neon"] .home-logo span:not(.gap) { --block-glow: 0 0 10px var(--c), 0 0 22px var(--c); }
.home-logo span:nth-child(2) { animation-delay: 0.15s; }
.home-logo span:nth-child(4) { animation-delay: 0.3s; }
.home-logo span:nth-child(5) { animation-delay: 0.45s; }
.home-logo span:nth-child(6) { animation-delay: 0.6s; }
.home-logo span:nth-child(8) { animation-delay: 0.75s; }
.home-logo span:nth-child(9) { animation-delay: 0.9s; }
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.home-title {
  font-size: clamp(34px, 11vw, 48px);
  font-weight: 900;
  line-height: 1.1;
  overflow: visible;
}
.home-tag { margin: 8px 0 14px; color: var(--muted); font-size: 15px; }
.home-best {
  margin-bottom: 26px;
  color: var(--gold);
  font-weight: 800;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}
.home-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.home-actions .btn[hidden] { display: none; }
.btn.big { padding: 16px 28px; font-size: 20px; }

/* ---------------- "New pieces" popup (promo) ---------------- */
.promo-card { position: relative; width: min(340px, 100%); }
.promo-close { position: absolute; top: 12px; right: 12px; font-size: 16px; }
.promo-card h2 { padding: 0 40px; }
/* Placeholder area for the promotion; other developers replace its content. */
.promo-content {
  min-height: 130px;
  margin: 4px 0 20px;
  padding: 18px 14px;
  display: grid;
  place-items: center;
  gap: 10px;
  border: 2px dashed var(--panel-edge);
  border-radius: 14px;
  background: var(--btn-bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}
.promo-content p { margin: 0; }
.promo-content img { max-width: 100%; height: auto; border-radius: 10px; }
.promo-content a { color: var(--gold); font-weight: 800; }
.promo-card .btn { min-width: 140px; }

/* ---------------- Revive (game-over screen) ---------------- */
.revive { margin: -6px 0 14px; }
.revive[hidden] { display: none; }
/* The button IS the countdown: a light-grey button with a gold fill on top that
   shrinks from right to left (no separate bar, no numbers). */
.revive-btn {
  position: relative;
  width: 100%;
  padding: 15px 20px;
  font-size: 20px;
  overflow: hidden;
  isolation: isolate;
  background: linear-gradient(180deg, #d9dce3, #b9bdc7);
  box-shadow: 0 4px 0 #8e939e, 0 8px 18px rgba(0, 0, 0, 0.3);
  animation: reviveBeat 0.9s ease-in-out infinite;
}
.revive-btn:active { box-shadow: 0 2px 0 #8e939e; }
.revive-fill {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg, #ffe066, #ffb703);
  transform-origin: left center;
}
.revive-label { position: relative; }
.revive.low .revive-fill { background: linear-gradient(180deg, #ffc163, #ff7a1f); } /* last third: warmer */
.revive.low .revive-btn { animation-duration: 0.45s; }
.revive.paused .revive-btn { animation: none; }
@keyframes reviveBeat {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* ---------------- tutorial ---------------- */
#app { position: relative; }
#app.tutorial-mode .topbar,
#app.tutorial-mode .scorebar,
#app.tutorial-mode .actionbar { visibility: hidden; }

.coach {
  position: absolute;
  left: 50%;
  width: max(var(--board), min(100%, 360px));
  max-width: calc(100% - 32px);
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 16px;
  border: 1.5px solid var(--gold);
  background: var(--banner-bg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.coach[hidden] { display: none; }
.coach-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.coach-step {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
}
.coach-skip {
  border: 1px solid var(--panel-edge);
  border-radius: 999px;
  padding: 4px 12px;
  background: var(--btn-bg);
  color: var(--text);
  font: 700 13px/1.2 var(--font);
  cursor: pointer;
  touch-action: manipulation;
}
.coach-skip:hover { background: var(--btn-bg-hover); }
.coach-text { margin: 0; font-size: 16px; font-weight: 700; line-height: 1.35; }
.coach.wrong { animation: coachShake 0.45s ease-in-out; border-color: #ff4d6d; }
@keyframes coachShake {
  20%, 60% { transform: translateX(calc(-50% - 6px)); }
  40%, 80% { transform: translateX(calc(-50% + 6px)); }
}

/* Target spot: pulsing outline over the cells where the piece should go. */
.cell.tut-target { position: relative; }
.cell.tut-target::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  border: 2px dashed var(--gold);
  box-shadow: 0 0 calc(var(--cell) * 0.3) var(--gold);
  animation: tutPulse 1s ease-in-out infinite;
  pointer-events: none;
}
@keyframes tutPulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

/* Pointing hand that demonstrates the drag. */
.tut-hand {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 55;
  font-size: 44px;
  line-height: 1;
  pointer-events: none;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.4));
}
.tut-hand[hidden] { display: none; }

.tips {
  margin: 0 0 20px;
  padding: 0;
  list-style: none;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tips li {
  position: relative;
  padding-left: 22px;
  font-size: 15px;
  line-height: 1.4;
}
.tips li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--gold);
  font-weight: 900;
}
.card .btn-row { margin-top: 4px; }

/* Six top-bar buttons: a little smaller on narrow phones. */
@media (max-width: 380px) {
  .controls { gap: 3px; }
  .icon-btn { width: 30px; height: 30px; font-size: 15px; }
  .music-btn { font-size: 18px; }
  .topbar .title { font-size: 14px; }
}

/* ---------------- very short screens (phone landscape) ---------------- */
@media (max-height: 460px) {
  #app { gap: 4px; padding-top: max(4px, env(safe-area-inset-top)); padding-bottom: max(4px, env(safe-area-inset-bottom)); }
  .hint { display: none; }
  .score-label { display: none; }
  .score-value { font-size: 22px; }
  .goal { margin-top: 2px; }
  .icon-btn { width: 30px; height: 30px; font-size: 15px; }
  .reroll-btn { height: 28px; font-size: 13px; }
}

/* ---------------- reduced motion ---------------- */
/* Only active when CONFIG.ui.respectReducedMotion is true and the device asks
 * for reduced motion: render.js then sets <html class="reduce-motion">. */
.reduce-motion .cell.settle,
.reduce-motion .piece.enter,
.reduce-motion .score-value.bump,
.reduce-motion .card,
.reduce-motion .overlay,
.reduce-motion .newbest,
.reduce-motion #app.shake,
.reduce-motion .stage.celebrate::after,
.reduce-motion .reroll-btn.urgent,
.reduce-motion .goal.flash .goal-track,
.reduce-motion .home-logo span,
.reduce-motion .cell.tut-target::after,
.reduce-motion .coach.wrong,
.reduce-motion .revive-btn { animation: none !important; }
.reduce-motion .milestone.show .ms-inner { animation-name: msFade; }
.reduce-motion .float { animation-name: fadeOnly; }
.reduce-motion .piece { transition: none; }
@keyframes msFade {
  0%, 80% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes fadeOnly {
  0%, 70% { opacity: 1; transform: translate(-50%, -50%); }
  100% { opacity: 0; transform: translate(-50%, -50%); }
}
