:root {
  --bg-top: #dce8ff;
  --bg-mid: #ebe4ff;
  --bg-bot: #ffe5f1;

  --glass-bg: rgba(255, 255, 255, 0.74);
  --glass-bg-strong: rgba(255, 255, 255, 0.9);
  --glass-border: rgba(255, 255, 255, 0.92);
  --glass-shadow:
    0 12px 28px rgba(67, 86, 152, 0.12),
    0 2px 6px rgba(67, 86, 152, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.95);

  --ink-primary: #1a2440;
  --ink-secondary: #5c698c;
  --ink-muted: #8f9bb8;
  --accent-blue: #4c95ff;
  --accent-indigo: #6c63ff;

  --board-size: min(calc(100vw - 28px), calc(100dvh - 286px), 400px);
  --board-pad: 9px;
  --grid-gap: 6px;
  --cell-radius: 11px;
  --tile-radius: 10px;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(152deg, var(--bg-top) 0%, var(--bg-mid) 50%, var(--bg-bot) 100%);
  color: var(--ink-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

.hidden {
  display: none !important;
}

/* Dreamy Porcelain Sky & Drifting Aurora Backdrop + Micro-Dot Texture */
.ambient-bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.ambient-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(99, 118, 178, 0.09) 1px, transparent 1px);
  background-size: 20px 20px;
  opacity: 0.55;
}

.ambient-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(56px);
  opacity: 0.78;
  will-change: transform;
}

.orb-1 {
  width: 310px;
  height: 310px;
  top: -85px;
  left: -70px;
  background: radial-gradient(circle, #93c5fd 0%, transparent 70%);
  animation: orbDriftA 18s ease-in-out infinite;
}

.orb-2 {
  width: 320px;
  height: 320px;
  top: 24%;
  right: -100px;
  background: radial-gradient(circle, #f9a8d4 0%, transparent 70%);
  animation: orbDriftB 22s ease-in-out infinite;
}

.orb-3 {
  width: 290px;
  height: 290px;
  bottom: -75px;
  left: 12%;
  background: radial-gradient(circle, #a5b4fc 0%, transparent 70%);
  animation: orbDriftC 20s ease-in-out infinite;
}

/* App Shell */
#app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 440px;
  height: 100dvh;
  margin: 0 auto;
  padding:
    max(10px, env(safe-area-inset-top))
    14px
    max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  touch-action: none;
}

#app.is-stage-mode {
  --board-size: min(calc(100vw - 28px), calc(100dvh - 320px), 388px);
  gap: 6px;
}

#app.is-stage-mode .score-card {
  min-height: 45px;
  padding: 5px 10px;
}

#app.is-stage-mode .tray {
  height: clamp(72px, 11.4dvh, 94px);
}

/* Top Bar */
.top-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  box-shadow:
    0 6px 14px rgba(79, 118, 224, 0.24),
    0 0 0 1.5px rgba(255, 255, 255, 0.9);
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.08;
}

.brand-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--ink-primary);
  white-space: nowrap;
}

.brand-sub {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--ink-secondary);
  letter-spacing: 0.02em;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.game-switch-pill {
  height: 33px;
  padding: 0 9px;
  border-radius: 11px;
  border: 1px solid rgba(16, 185, 129, 0.28);
  background: linear-gradient(135deg, rgba(236, 253, 245, 0.94) 0%, rgba(255, 241, 246, 0.9) 100%);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow:
    0 5px 14px rgba(16, 185, 129, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.95);
  color: #047857;
  text-decoration: none;
  font-size: 11.5px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.game-switch-pill:active {
  transform: scale(0.94) translateY(1px);
}

.glass-icon-btn {
  width: 33px;
  height: 33px;
  border-radius: 11px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg-strong);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow:
    0 5px 14px rgba(67, 86, 152, 0.11),
    inset 0 1px 0 rgba(255, 255, 255, 0.96);
  color: var(--ink-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.glass-icon-btn:active {
  transform: scale(0.92) translateY(1px);
}

.glass-icon-btn svg {
  width: 16.5px;
  height: 16.5px;
}

.glass-icon-btn.is-active-bgm {
  color: #4f46e5;
  border-color: rgba(99, 102, 241, 0.34);
  background: linear-gradient(145deg, rgba(238, 242, 255, 0.96) 0%, rgba(255, 255, 255, 0.9) 100%);
  box-shadow:
    0 5px 14px rgba(99, 102, 241, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.98);
}

.glass-icon-btn.is-muted {
  color: var(--ink-muted);
  background: rgba(255, 255, 255, 0.62);
}

/* Score & Mode Strip */
.score-strip {
  width: 100%;
  display: grid;
  grid-template-columns: 1.1fr 0.85fr 1.1fr;
  gap: 7px;
  flex-shrink: 0;
}

.glass-card {
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.86) 0%, rgba(255, 255, 255, 0.66) 100%);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-radius: 16px;
  box-shadow: var(--glass-shadow);
}

.score-card {
  padding: 6px 11px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 50px;
}

.score-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--ink-secondary);
  line-height: 1.2;
}

.score-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 1px;
}

.score-num {
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  color: var(--ink-primary);
}

.primary-score {
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.92) 0%, rgba(235, 243, 255, 0.78) 100%);
}

.primary-score .score-num {
  background: linear-gradient(135deg, #2563eb 0%, #6366f1 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.streak-pill {
  font-size: 10px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #ff7eb3 0%, #f43f5e 100%);
  padding: 2px 7px;
  border-radius: 999px;
  box-shadow: 0 4px 10px rgba(244, 63, 94, 0.36);
  white-space: nowrap;
  animation: pillPop 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mode-card {
  padding: 3.5px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  align-items: stretch;
  background: rgba(255, 255, 255, 0.72);
}

.mode-pill {
  border: none;
  border-radius: 11px;
  background: transparent;
  color: var(--ink-secondary);
  font-size: 12px;
  font-weight: 800;
  padding: 0 4px;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.12s ease;
}

.mode-pill:active {
  transform: scale(0.95);
}

.mode-pill.is-active {
  background: linear-gradient(135deg, #4f9cff 0%, #6366f1 100%);
  color: #fff;
  box-shadow:
    0 5px 12px rgba(79, 128, 255, 0.34),
    inset 0 1px 0 rgba(255, 255, 255, 0.42);
}

/* Stage Objective Bar */
.stage-bar {
  width: 100%;
  height: 35px;
  padding: 0 7px;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-shrink: 0;
}

.stage-select-pill {
  border: 1px solid rgba(99, 102, 241, 0.22);
  background: linear-gradient(135deg, rgba(224, 231, 255, 0.78) 0%, rgba(238, 242, 255, 0.92) 100%);
  color: #4338ca;
  border-radius: 9px;
  padding: 4px 9px;
  font-size: 11.5px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 48%;
  transition: transform 0.12s ease;
}

.stage-select-pill:active {
  transform: scale(0.96);
}

.stage-goal-wrap {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 800;
  color: var(--ink-primary);
  white-space: nowrap;
}

.stage-goal-chip {
  min-width: 24px;
  height: 22px;
  padding: 0 6px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  box-shadow:
    0 3px 8px rgba(67, 86, 152, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.stage-goal-chip.goal-clear {
  background: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
}

.stage-goal-chip.goal-ice {
  background: linear-gradient(135deg, #38bdf8 0%, #0284c7 100%);
}

.stage-moves-pill {
  padding: 3.5px 9px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(219, 234, 254, 0.9) 0%, rgba(224, 231, 255, 0.88) 100%);
  color: #1d4ed8;
  font-size: 11.5px;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

.stage-moves-pill.is-low {
  background: linear-gradient(135deg, rgba(255, 228, 230, 0.96) 0%, rgba(254, 205, 211, 0.92) 100%);
  color: #be123c;
  animation: dangerPulseLow 0.8s ease-in-out infinite;
}

/* Board Stage — Sculptural Double-Bezel Porcelain Frame */
.board-wrapper {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-stage {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  padding: var(--board-pad);
  border-radius: 24px;
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.84) 0%, rgba(240, 245, 255, 0.7) 100%);
  border: 1.5px solid rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  box-shadow:
    0 20px 44px rgba(67, 86, 152, 0.16),
    0 4px 12px rgba(67, 86, 152, 0.08),
    inset 0 1.5px 0 rgba(255, 255, 255, 0.98),
    inset 0 -2px 6px rgba(148, 163, 206, 0.12);
}

.board-stage.hammer-active {
  box-shadow:
    0 0 0 3px rgba(251, 146, 60, 0.5),
    0 20px 44px rgba(251, 146, 60, 0.22);
}

.board-grid {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: var(--grid-gap);
}

.board-cell {
  position: relative;
  border-radius: var(--cell-radius);
  background: rgba(196, 211, 244, 0.44);
  box-shadow:
    inset 0 2px 4px rgba(82, 102, 154, 0.16),
    inset 0 -1px 0 rgba(255, 255, 255, 0.78);
}

.board-cell.has-ice {
  background: linear-gradient(145deg, rgba(224, 242, 254, 0.9) 0%, rgba(186, 230, 253, 0.72) 100%);
  box-shadow:
    inset 0 1px 4px rgba(14, 165, 233, 0.28),
    0 0 8px rgba(56, 189, 248, 0.25);
}

.board-cell.has-ice::before {
  content: "❄";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  color: rgba(14, 165, 233, 0.48);
  pointer-events: none;
  z-index: 0;
}

.board-cell.has-ice::after {
  content: "";
  position: absolute;
  inset: -1px;
  z-index: 2;
  pointer-events: none;
  border-radius: var(--cell-radius);
  border: 2px solid rgba(56, 189, 248, 0.92);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.36) 0%, transparent 45%, rgba(125, 211, 252, 0.22) 100%);
  box-shadow:
    inset 0 0 8px rgba(125, 211, 252, 0.52),
    0 0 8px rgba(56, 189, 248, 0.28);
}

.mini-tile-badge {
  margin-top: 2px;
  min-width: 34px;
  height: 24px;
  padding: 0 7px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  box-shadow:
    0 4px 10px rgba(67, 86, 152, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.mini-tile-badge.empty-badge {
  background: rgba(148, 163, 184, 0.18);
  color: var(--ink-muted);
  box-shadow: none;
}

.board-overlay {
  position: absolute;
  inset: var(--board-pad);
  pointer-events: none;
}

.ghost-layer {
  z-index: 3;
}

.fx-layer {
  z-index: 4;
}

.particle-canvas {
  z-index: 5;
  width: calc(100% - var(--board-pad) * 2);
  height: calc(100% - var(--board-pad) * 2);
}

.toast-layer {
  z-index: 6;
  overflow: visible;
}

/* Jewel Candy Glass Tile System */
.tile {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  border-radius: var(--tile-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.02em;
  text-shadow: 0 1px 2px rgba(15, 23, 42, 0.24);
  box-shadow:
    0 5px 12px rgba(30, 41, 59, 0.16),
    inset 0 -3px 0 rgba(0, 0, 0, 0.16),
    inset 0 1.5px 1px rgba(255, 255, 255, 0.78);
  overflow: hidden;
  user-select: none;
}

.tile::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 6%;
  right: 6%;
  height: 44%;
  border-radius: 8px 8px 16px 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.56) 0%, rgba(255, 255, 255, 0.04) 100%);
  pointer-events: none;
}

.tile::after {
  content: "";
  position: absolute;
  bottom: 3px;
  left: 16%;
  right: 16%;
  height: 22%;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(255, 255, 255, 0.28) 0%, transparent 72%);
  pointer-events: none;
}

.tile-label {
  position: relative;
  z-index: 1;
  line-height: 1;
}

/* Font scaling based on digit length */
.tile.len-1 { font-size: clamp(18px, 5.2vw, 24px); }
.tile.len-2 { font-size: clamp(16px, 4.5vw, 21px); }
.tile.len-3 { font-size: clamp(13px, 3.6vw, 17px); }
.tile.len-4 { font-size: clamp(11px, 3vw, 14px); }

/* Jewel Candy Color Tiers with subtle tinted glow shadows */
.tile-v2 {
  background: linear-gradient(155deg, #93d7ff 0%, #4da8ff 58%, #2f89f5 100%);
  box-shadow: 0 5px 12px rgba(59, 130, 246, 0.28), inset 0 -3px 0 rgba(0, 0, 0, 0.14), inset 0 1.5px 1px rgba(255, 255, 255, 0.8);
}
.tile-v4 {
  background: linear-gradient(155deg, #86f2cb 0%, #2fd098 58%, #10b981 100%);
  box-shadow: 0 5px 12px rgba(16, 185, 129, 0.28), inset 0 -3px 0 rgba(0, 0, 0, 0.14), inset 0 1.5px 1px rgba(255, 255, 255, 0.8);
}
.tile-v8 {
  background: linear-gradient(155deg, #ffda8a 0%, #fb9b3a 58%, #f97316 100%);
  box-shadow: 0 5px 12px rgba(249, 115, 22, 0.3), inset 0 -3px 0 rgba(0, 0, 0, 0.14), inset 0 1.5px 1px rgba(255, 255, 255, 0.8);
}
.tile-v16 {
  background: linear-gradient(155deg, #ffa9b6 0%, #f5597d 58%, #e11d48 100%);
  box-shadow: 0 5px 12px rgba(244, 63, 94, 0.3), inset 0 -3px 0 rgba(0, 0, 0, 0.15), inset 0 1.5px 1px rgba(255, 255, 255, 0.78);
}
.tile-v32 {
  background: linear-gradient(155deg, #cbbcff 0%, #8f60f8 58%, #7c3aed 100%);
  box-shadow: 0 5px 12px rgba(139, 92, 246, 0.3), inset 0 -3px 0 rgba(0, 0, 0, 0.15), inset 0 1.5px 1px rgba(255, 255, 255, 0.78);
}
.tile-v64 {
  background: linear-gradient(155deg, #67f0da 0%, #14b8a6 58%, #0f766e 100%);
  box-shadow: 0 5px 12px rgba(20, 184, 166, 0.3), inset 0 -3px 0 rgba(0, 0, 0, 0.16), inset 0 1.5px 1px rgba(255, 255, 255, 0.78);
}
.tile-v128 {
  background: linear-gradient(155deg, #fef08a 0%, #facc15 55%, #eab308 100%);
  color: #5c3a00;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
  box-shadow: 0 6px 14px rgba(234, 179, 8, 0.36), inset 0 -3px 0 rgba(0, 0, 0, 0.12), inset 0 1.5px 1px rgba(255, 255, 255, 0.88);
}
.tile-v256 {
  background: linear-gradient(155deg, #fbb4da 0%, #ec4899 55%, #be185d 100%);
  box-shadow: 0 6px 14px rgba(236, 72, 153, 0.34), inset 0 -3px 0 rgba(0, 0, 0, 0.16), inset 0 1.5px 1px rgba(255, 255, 255, 0.8);
}
.tile-v512 {
  background: linear-gradient(155deg, #9ccbff 0%, #5b54ea 55%, #3730a3 100%);
  box-shadow: 0 6px 15px rgba(79, 70, 229, 0.36), inset 0 -3px 0 rgba(0, 0, 0, 0.16), inset 0 1.5px 1px rgba(255, 255, 255, 0.8);
}
.tile-v1024 {
  background: linear-gradient(155deg, #ff7b90 0%, #e11d48 55%, #9f1239 100%);
  box-shadow: 0 6px 16px rgba(225, 29, 72, 0.38), inset 0 -3px 0 rgba(0, 0, 0, 0.18), inset 0 1.5px 1px rgba(255, 255, 255, 0.82);
}
.tile-v2048 {
  background: linear-gradient(145deg, #fef08a 0%, #f59e0b 48%, #ea580c 100%);
  box-shadow:
    0 7px 20px rgba(245, 158, 11, 0.48),
    inset 0 -3px 0 rgba(0, 0, 0, 0.16),
    inset 0 1.5px 2px rgba(255, 255, 255, 0.92);
}
.tile-v4096 {
  background: linear-gradient(145deg, #67e8f9 0%, #6366f1 50%, #d946ef 100%);
  box-shadow:
    0 7px 22px rgba(139, 92, 246, 0.5),
    inset 0 -3px 0 rgba(0, 0, 0, 0.18),
    inset 0 1.5px 2px rgba(255, 255, 255, 0.92);
}

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

.tile.anim-super {
  animation: tileSuperPop 0.42s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.board-cell.hammer-target {
  cursor: pointer;
}

.board-cell.hammer-target .tile {
  animation: hammerWiggle 0.55s ease-in-out infinite;
  box-shadow:
    0 0 0 2.5px rgba(251, 146, 60, 0.9),
    0 6px 16px rgba(251, 146, 60, 0.34);
}

/* Preview & FX Overlay elements */
.ghost-cell {
  position: absolute;
  border-radius: var(--tile-radius);
  opacity: 0.65;
  transform: scale(0.95);
  outline: 2px dashed rgba(255, 255, 255, 0.95);
  outline-offset: -2px;
}

.merge-preview-ring {
  position: absolute;
  border-radius: var(--tile-radius);
  border: 2.5px solid #fff;
  box-shadow: 0 0 0 2px rgba(251, 146, 60, 0.85), 0 0 16px rgba(251, 146, 60, 0.58);
  animation: mergePreviewPulse 0.9s ease-in-out infinite;
}

.merge-anchor-chip {
  position: absolute;
  transform: translate(-50%, -125%);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #ff8a3d 0%, #f43f5e 100%);
  box-shadow: 0 4px 12px rgba(244, 63, 94, 0.38);
  white-space: nowrap;
  z-index: 4;
}

.clear-beam {
  position: absolute;
  border-radius: 12px;
  background: linear-gradient(90deg, rgba(253, 224, 71, 0.28), rgba(251, 191, 36, 0.48), rgba(253, 224, 71, 0.28));
  border: 1.5px solid rgba(251, 191, 36, 0.88);
  box-shadow: 0 0 18px rgba(251, 191, 36, 0.45);
  animation: clearLineBeam 0.85s ease-in-out infinite;
}

.fx-clone {
  position: absolute;
  transition: transform 0.18s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.18s ease;
  will-change: transform, opacity;
}

.fx-clear-cell {
  position: absolute;
  animation: lineClearFlash 0.26s ease-out forwards;
}

.float-toast {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 800;
  color: #fff;
  background: rgba(26, 36, 64, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.26);
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 18px rgba(26, 36, 64, 0.24);
  white-space: nowrap;
  animation: floatToast 1.15s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.float-toast.toast-combo {
  background: linear-gradient(135deg, #f97316 0%, #ec4899 100%);
}

.float-toast.toast-clear {
  background: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
}

.float-toast.toast-milestone {
  font-size: 13.5px;
  background: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%);
}

/* Contextual Status / Rescue Banner */
.status-banner {
  width: 100%;
  padding: 6px 12px;
  border-radius: 14px;
  background: rgba(255, 247, 237, 0.94);
  border: 1px solid rgba(251, 146, 60, 0.5);
  box-shadow: 0 6px 18px rgba(251, 146, 60, 0.16);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.status-banner-text {
  font-size: 12px;
  font-weight: 700;
  color: #9a3412;
}

.status-banner-btn {
  border: none;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #fb923c 0%, #f43f5e 100%);
  cursor: pointer;
  white-space: nowrap;
}

/* Piece Tray */
.tray {
  width: 100%;
  height: clamp(76px, 12.2dvh, 98px);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  flex-shrink: 0;
}

.tray-slot {
  position: relative;
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.86) 0%, rgba(244, 247, 255, 0.72) 100%);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--glass-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  transition: transform 0.15s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}

.tray-slot.is-empty {
  cursor: default;
  background: rgba(255, 255, 255, 0.36);
  border-color: rgba(255, 255, 255, 0.56);
  box-shadow: inset 0 1px 3px rgba(82, 102, 154, 0.08);
}

.tray-slot.is-unfit {
  opacity: 0.44;
  cursor: not-allowed;
}

.tray-slot.is-dragging {
  opacity: 0.22;
  transform: scale(0.95);
}

.tray-slot.anim-enter .piece-mini-grid {
  animation: trayEnter 0.34s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.piece-mini-grid {
  position: relative;
  pointer-events: none;
}

.piece-mini-cell {
  position: absolute;
}

.piece-mini-cell .tile {
  border-radius: 7px;
  box-shadow:
    0 3px 7px rgba(30, 41, 59, 0.16),
    inset 0 -2px 0 rgba(0, 0, 0, 0.14),
    inset 0 1px 1px rgba(255, 255, 255, 0.75);
}

.piece-mini-cell .tile.len-1 { font-size: 13px; }
.piece-mini-cell .tile.len-2 { font-size: 11px; }
.piece-mini-cell .tile.len-3 { font-size: 9px; }
.piece-mini-cell .tile.len-4 { font-size: 8px; }

/* Bottom Tool Dock */
.tool-dock {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  flex-shrink: 0;
}

.tool-btn {
  height: 41px;
  border-radius: 15px;
  border: 1px solid var(--glass-border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(244, 247, 255, 0.86) 100%);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow:
    0 8px 20px rgba(67, 86, 152, 0.12),
    inset 0 -2px 0 rgba(67, 86, 152, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.98);
  color: var(--ink-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.14s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}

.tool-btn:active:not(:disabled) {
  transform: scale(0.96) translateY(1px);
}

.tool-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.tool-btn.is-active {
  background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
  border-color: #fb923c;
  color: #c2410c;
  box-shadow: 0 8px 20px rgba(251, 146, 60, 0.3);
}

.tool-icon {
  display: inline-flex;
  width: 16px;
  height: 16px;
  color: #4f46e5;
}

#btn-hammer .tool-icon {
  color: #f97316;
}

.tool-icon svg {
  width: 100%;
  height: 100%;
}

.tool-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent-blue) 0%, var(--accent-indigo) 100%);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 8px rgba(79, 128, 255, 0.32);
}

#btn-hammer .tool-badge {
  background: linear-gradient(135deg, #fb923c 0%, #f43f5e 100%);
  box-shadow: 0 3px 8px rgba(244, 63, 94, 0.3);
}

.tool-btn.is-active .tool-badge {
  background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
}

/* iOS Install Tip */
.ios-install-tip {
  width: 100%;
  padding: 5px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--glass-border);
  font-size: 11px;
  color: var(--ink-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.tip-close {
  border: none;
  background: rgba(148, 163, 184, 0.2);
  color: var(--ink-secondary);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

/* Floating Drag Ghost */
.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 100;
  will-change: transform;
  filter: drop-shadow(0 16px 24px rgba(31, 41, 66, 0.28));
}

.drag-ghost-cell {
  position: absolute;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 150;
  padding: 18px;
  background: rgba(26, 36, 64, 0.36);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.modal-sheet {
  width: 100%;
  max-width: 374px;
  max-height: 88dvh;
  overflow-y: auto;
  border-radius: 26px;
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.97) 0%, rgba(246, 248, 255, 0.94) 100%);
  border: 1.5px solid #fff;
  box-shadow: 0 26px 56px rgba(26, 36, 64, 0.26);
  padding: 19px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: modalPop 0.26s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-compact {
  text-align: center;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-sheet h2 {
  margin: 0;
  font-size: 18.5px;
  font-weight: 800;
  color: var(--ink-primary);
}

.modal-desc {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-secondary);
}

.modal-close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(148, 163, 184, 0.18);
  color: var(--ink-secondary);
  font-size: 18px;
  cursor: pointer;
}

.help-rules {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.rule-card {
  padding: 11px 12px;
  border-radius: 16px;
  background: rgba(235, 242, 255, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.96);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rule-visual {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.demo-tile {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  box-shadow: 0 3px 8px rgba(30, 41, 59, 0.15), inset 0 -2px 0 rgba(0, 0, 0, 0.14);
}

.rule-arrow,
.rule-spark {
  font-size: 15px;
  font-weight: 800;
  color: var(--ink-secondary);
}

.rule-copy h3 {
  margin: 0 0 2px;
  font-size: 13.5px;
  font-weight: 800;
  color: var(--ink-primary);
}

.rule-copy p {
  margin: 0;
  font-size: 12px;
  line-height: 1.48;
  color: var(--ink-secondary);
}

/* Grouped iOS Settings Panel */
.settings-group {
  border-radius: 16px;
  background: rgba(241, 245, 255, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.98);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  cursor: pointer;
}

.setting-row + .setting-row {
  border-top: 1px solid rgba(148, 163, 184, 0.18);
}

.setting-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.setting-label strong {
  font-size: 12.5px;
  font-weight: 800;
  color: var(--ink-primary);
}

.setting-label span {
  font-size: 10.5px;
  line-height: 1.35;
  color: var(--ink-secondary);
}

.ios-switch {
  position: relative;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}

.ios-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.ios-switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.42);
  transition: background 0.2s ease;
}

.ios-switch-track::after {
  content: "";
  position: absolute;
  left: 2.5px;
  top: 2.5px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.22);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ios-switch input:checked + .ios-switch-track {
  background: linear-gradient(135deg, #4f9cff 0%, #6366f1 100%);
}

.ios-switch input:checked + .ios-switch-track::after {
  transform: translateX(18px);
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary-cta,
.secondary-cta {
  height: 44px;
  border: none;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.14s ease;
}

.primary-cta:active,
.secondary-cta:active {
  transform: scale(0.97);
}

.primary-cta {
  background: linear-gradient(135deg, #4f9cff 0%, #6366f1 100%);
  color: #fff;
  box-shadow: 0 8px 22px rgba(79, 128, 255, 0.36);
}

.secondary-cta {
  background: rgba(226, 232, 240, 0.76);
  color: var(--ink-primary);
}

.record-ribbon {
  align-self: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  color: #9a3412;
  background: linear-gradient(135deg, #fef08a 0%, #fdba74 100%);
}

.gameover-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat-box {
  padding: 12px;
  border-radius: 16px;
  background: rgba(235, 242, 255, 0.78);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-secondary);
}

.stat-val {
  font-size: 24px;
  font-weight: 800;
  color: #2563eb;
}

/* Stage Clear & Stage Select */
.clear-stars {
  font-size: 32px;
  letter-spacing: 6px;
  line-height: 1.1;
  color: #f59e0b;
  text-shadow: 0 4px 12px rgba(245, 158, 11, 0.35);
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-height: 55dvh;
  overflow-y: auto;
  padding: 2px;
}

.stage-cell-btn {
  border: 1px solid rgba(99, 102, 241, 0.24);
  border-radius: 15px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.94) 0%, rgba(235, 242, 255, 0.88) 100%);
  box-shadow: 0 4px 10px rgba(67, 86, 152, 0.08);
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  color: var(--ink-primary);
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.stage-cell-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.stage-cell-btn.is-current {
  border: 2px solid #4f9cff;
  background: linear-gradient(155deg, #e0ecff 0%, #ffffff 100%);
  box-shadow: 0 6px 16px rgba(79, 128, 255, 0.24);
}

.stage-cell-btn.is-locked {
  opacity: 0.48;
  cursor: not-allowed;
  background: rgba(226, 232, 240, 0.55);
  border-color: rgba(148, 163, 184, 0.3);
  box-shadow: none;
}

.stage-num {
  font-size: 16px;
  font-weight: 800;
}

.stage-cell-name {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--ink-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.stage-goal-mini {
  font-size: 9.5px;
  font-weight: 700;
  color: #4f46e5;
  white-space: nowrap;
}

.stage-stars {
  font-size: 11px;
  color: #f59e0b;
  letter-spacing: 1px;
}

@keyframes dangerPulseLow {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* Keyframes */
@keyframes orbDriftA {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(24px, 18px) scale(1.06); }
}

@keyframes orbDriftB {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-22px, 20px) scale(1.05); }
}

@keyframes orbDriftC {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(18px, -18px) scale(1.07); }
}

@keyframes tilePop {
  0% { transform: scale(0.55); opacity: 0.4; }
  65% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes tileSuperPop {
  0% { transform: scale(0.4); }
  50% { transform: scale(1.22); }
  80% { transform: scale(0.95); }
  100% { transform: scale(1); }
}

@keyframes lineClearFlash {
  0% { transform: scale(1); opacity: 1; filter: brightness(1.3); }
  50% { transform: scale(1.12); opacity: 0.9; filter: brightness(1.65); }
  100% { transform: scale(0.25); opacity: 0; }
}

@keyframes mergePreviewPulse {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50% { transform: scale(1.04); opacity: 1; }
}

@keyframes clearLineBeam {
  0%, 100% { opacity: 0.65; }
  50% { opacity: 1; }
}

@keyframes floatToast {
  0% { transform: translate(-50%, -30%) scale(0.82); opacity: 0; }
  16% { transform: translate(-50%, -60%) scale(1.05); opacity: 1; }
  100% { transform: translate(-50%, -170%) scale(0.96); opacity: 0; }
}

@keyframes trayEnter {
  0% { transform: translateY(14px) scale(0.84); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes pillPop {
  0% { transform: scale(0.75); }
  70% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

@keyframes hammerWiggle {
  0%, 100% { transform: rotate(-2deg) scale(0.98); }
  50% { transform: rotate(2deg) scale(1.02); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalPop {
  from { transform: scale(0.9) translateY(8px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .ambient-orb,
  .tile.anim-pop,
  .tile.anim-super,
  .merge-preview-ring,
  .clear-beam,
  .board-cell.hammer-target .tile,
  .tray-slot.anim-enter .piece-mini-grid {
    animation: none !important;
  }
}
