:root {
  --bg: #f7efe4;
  --bg-deep: #efdfcd;
  --paper: #fffaf2;
  --ink: #45322a;
  --muted: #8c776b;
  --line: rgba(107, 77, 61, 0.12);
  --coral: #e27560;
  --coral-deep: #c95845;
  --gold: #e6aa45;
  --green: #6c9b75;
  --shadow: 0 22px 55px rgba(104, 70, 49, 0.17);
  --font: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 8%, rgba(255, 255, 255, 0.9), transparent 30%),
    radial-gradient(circle at 86% 92%, rgba(228, 171, 126, 0.26), transparent 34%),
    linear-gradient(155deg, #faf3e9 0%, var(--bg) 48%, #f3e5d5 100%);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle, rgba(150, 112, 86, 0.055) 1.4px, transparent 1.6px);
  background-size: 24px 24px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.55), transparent 55%);
  -webkit-mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.55), transparent 55%);
}

button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 3px solid rgba(201, 88, 69, 0.55);
  outline-offset: 2px;
}

svg {
  display: block;
}

[hidden] {
  display: none !important;
}

.svg-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.app {
  position: relative;
  z-index: 1;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding:
    max(14px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.game-panel {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: none;
}

/* ---------- 顶部 ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 1px 2px 0;
}

.brand {
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: clamp(18px, 4.8vw, 24px);
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-weight: 800;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: none;
}

.level-pill {
  min-height: 36px;
  padding: 0 11px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  background: rgba(255, 252, 247, 0.74);
  box-shadow: 0 4px 12px rgba(104, 70, 49, 0.08);
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}

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

.level-pill .chev {
  width: 10px;
  height: 7px;
  color: var(--muted);
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  background: rgba(255, 252, 247, 0.74);
  box-shadow: 0 4px 12px rgba(104, 70, 49, 0.08);
  color: var(--muted);
  cursor: pointer;
  transition: transform 0.12s ease, color 0.15s ease, background 0.15s ease;
}

.icon-btn:hover {
  color: var(--coral-deep);
}

.icon-btn:active {
  transform: scale(0.93);
}

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

/* ---------- HUD ---------- */

.hud {
  display: grid;
  grid-template-columns: 0.82fr 1.6fr 0.94fr;
  gap: 7px;
}

.hud-card {
  min-width: 0;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-radius: 15px;
  background: rgba(255, 250, 242, 0.82);
  box-shadow: 0 6px 17px rgba(104, 70, 49, 0.075);
}

.hud-label {
  color: var(--muted);
  font-size: 9.5px;
  font-weight: 650;
  letter-spacing: 0.06em;
  line-height: 1.2;
  white-space: nowrap;
}

.moves-value {
  color: var(--coral-deep);
  font-size: 25px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.moves-card.low .moves-value {
  color: #b83c30;
  animation: lowPulse 0.9s ease-in-out infinite;
}

.goal-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 5px;
  min-width: 0;
}

.goal-top b {
  overflow: hidden;
  color: var(--ink);
  font-size: 11.5px;
  font-weight: 750;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meter {
  height: 6px;
  margin-top: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(107, 77, 61, 0.12);
}

.meter span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #edbb62, #df745d);
  transition: width 0.36s cubic-bezier(0.2, 0.8, 0.3, 1);
}

.collect-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
}

.collect-row img {
  width: 19px;
  height: 19px;
  padding: 1px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.78);
}

.collect-row span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.score-card > b {
  overflow: hidden;
  font-size: 19px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  text-overflow: ellipsis;
}

.best {
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 棋盘 ---------- */

.board-area {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}

.board-stage {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-shell {
  position: relative;
  width: 320px;
  height: 320px;
  touch-action: none;
}

.board-shell.shake {
  animation: boardShake 0.3s ease-in-out;
}

.board-shell.impact {
  animation: boardImpact 0.42s cubic-bezier(0.2, 0.8, 0.3, 1);
}

.board-head {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 16px 28px rgba(104, 70, 49, 0.19));
  pointer-events: none;
}

.head-fill {
  fill: url(#headGradient);
}

.head-line {
  fill: none;
  stroke: rgba(255, 255, 255, 0.92);
  stroke-width: 0.055;
  stroke-linejoin: round;
}

.board {
  position: absolute;
  inset: 0;
  overflow: hidden;
  clip-path: url(#headClipPath);
  -webkit-clip-path: url(#headClipPath);
  touch-action: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.board-shell.shuffling .board {
  opacity: 0.22;
  transform: scale(0.97);
}

.tile {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--tile-size, 36px);
  height: var(--tile-size, 36px);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  transform: translate3d(var(--tx, 0), var(--ty, 0), 0);
  transition: transform 0.23s cubic-bezier(0.2, 0.8, 0.3, 1);
  cursor: pointer;
  touch-action: none;
  will-change: transform;
  z-index: 2;
  -webkit-appearance: none;
  appearance: none;
}

.tile-face {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 2px solid var(--accent, #d6b697);
  border-radius: 22%;
  background: linear-gradient(150deg, rgba(255, 255, 255, 0.96) 6%, var(--tint, #f6e9d9) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    0 2px 4px rgba(95, 62, 45, 0.13);
  transition: transform 0.15s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

.tile-photo {
  width: 98%;
  height: 98%;
  object-fit: contain;
  object-position: center;
  pointer-events: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.7));
}

.tile[data-special="rainbow"] .tile-face {
  border-color: #dca63e;
  background:
    conic-gradient(from 20deg, #fff1c9, #ffe0df, #dcecff, #e3f5dc, #fff1c9);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 0 0 2px rgba(230, 170, 69, 0.23),
    0 3px 7px rgba(95, 62, 45, 0.15);
}

.special-badge {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 44%;
  height: 44%;
  min-width: 14px;
  min-height: 14px;
  display: grid;
  place-items: center;
  border: 1.5px solid rgba(88, 56, 42, 0.2);
  border-radius: 50%;
  background: #fffaf2;
  box-shadow: 0 2px 5px rgba(75, 44, 30, 0.24);
  color: var(--accent, #b86d45);
}

.special-badge svg {
  width: 74%;
  height: 74%;
}

.tile[data-special="col"] .special-badge svg {
  transform: rotate(90deg);
}

.tile[data-special="rainbow"] .special-badge {
  color: #ad761d;
  background: #fff6dd;
}

.tile.selected {
  z-index: 5;
}

.tile.selected .tile-face {
  transform: scale(1.07);
  box-shadow:
    0 0 0 3px #fffaf2,
    0 0 0 5px var(--accent, #d6b697),
    0 7px 18px rgba(84, 53, 37, 0.23);
}

.tile.clearing {
  z-index: 4;
  pointer-events: none;
}

.tile.clearing .tile-face {
  animation: clearPop 0.23s ease-in forwards;
}

.tile.special-born {
  z-index: 6;
}

.tile.special-born .tile-face {
  animation: specialBorn 0.48s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.tile.landed .tile-face {
  animation: tileLand 0.26s cubic-bezier(0.2, 1.2, 0.4, 1);
}

.board-shell.busy .tile {
  pointer-events: none;
}

.board-tip {
  min-height: 15px;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.25;
  text-align: center;
  white-space: nowrap;
}

.board-tip svg {
  width: 13px;
  height: 13px;
  flex: none;
  opacity: 0.72;
}

/* ---------- 棋盘特效 ---------- */

.effects-layer {
  position: absolute;
  inset: 0;
  z-index: 8;
  overflow: hidden;
  clip-path: url(#headVisualClipPath);
  -webkit-clip-path: url(#headVisualClipPath);
  pointer-events: none;
}

.fx-row,
.fx-col {
  position: absolute;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, #fff1b5 16%, #fffdf4 48%, #ffe9a8 82%, transparent);
  box-shadow: 0 0 22px rgba(255, 212, 112, 0.95);
  animation: beamRow 0.43s ease-out forwards;
}

.fx-row {
  left: -3%;
  right: -3%;
  height: 62%;
}

.fx-col {
  top: -3%;
  bottom: -3%;
  width: 62%;
  background: linear-gradient(180deg, transparent, #fff1b5 16%, #fffdf4 48%, #ffe9a8 82%, transparent);
  animation-name: beamCol;
}

.fx-burst {
  position: absolute;
  width: var(--fx-size, 80px);
  height: var(--fx-size, 80px);
  border: 3px solid rgba(255, 228, 150, 0.95);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.95), rgba(255, 203, 94, 0.52) 34%, transparent 68%);
  box-shadow: 0 0 30px rgba(255, 193, 72, 0.85);
  transform: translate(-50%, -50%) scale(0.2);
  animation: burst 0.48s ease-out forwards;
}

.fx-rainbow {
  position: absolute;
  inset: -15%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 251, 220, 0.92), rgba(255, 218, 227, 0.52) 30%, rgba(193, 224, 255, 0.36) 48%, rgba(212, 244, 206, 0.2) 62%, transparent 75%);
  animation: rainbowFlash 0.52s ease-out forwards;
}

.fx-spark {
  position: absolute;
  width: 5px;
  height: 5px;
  margin: -2.5px 0 0 -2.5px;
  border-radius: 50%;
  background: var(--fx-color, #fff6c8);
  box-shadow: 0 0 8px rgba(255, 222, 130, 0.95);
  pointer-events: none;
  animation: sparkFly 0.56s ease-out forwards;
}

.fx-star {
  position: absolute;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  background: var(--fx-color, #ffe08a);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 94%, 50% 71%, 21% 94%, 32% 57%, 2% 35%, 39% 35%);
  filter: drop-shadow(0 0 4px rgba(255, 222, 130, 0.9));
  pointer-events: none;
  animation: starFly 0.66s ease-out forwards;
}

.fx-confetti {
  position: absolute;
  width: 5px;
  height: 9px;
  margin: -4.5px 0 0 -2.5px;
  border-radius: 2px;
  background: var(--fx-color, #ffd166);
  pointer-events: none;
  animation: confettiFly 0.7s ease-out forwards;
}

.fx-ring {
  position: absolute;
  width: var(--fx-size, 80px);
  height: var(--fx-size, 80px);
  border: 3px solid var(--fx-color, #ffe09a);
  border-radius: 50%;
  box-shadow:
    0 0 16px rgba(255, 219, 128, 0.72),
    inset 0 0 16px rgba(255, 240, 190, 0.5);
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.18);
  animation: ringBurst 0.62s ease-out forwards;
}

.fx-flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(
    circle at var(--fx-x, 50%) var(--fx-y, 50%),
    rgba(255, 252, 226, 0.9),
    rgba(255, 221, 134, 0.28) 34%,
    transparent 64%
  );
  mix-blend-mode: screen;
  pointer-events: none;
  animation: boardFlash 0.38s ease-out forwards;
}

.fx-link {
  position: absolute;
  height: 3px;
  margin-top: -1.5px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.95), #ffd76a 46%, rgba(255, 255, 255, 0.18));
  box-shadow: 0 0 12px rgba(255, 213, 100, 0.92);
  pointer-events: none;
  transform-origin: 0 50%;
  transform: rotate(var(--angle, 0deg)) scaleX(0);
  animation: linkFlash 0.52s ease-out forwards;
}

.fx-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, transparent 44%, rgba(255, 207, 111, 0.32) 100%);
  box-shadow: inset 0 0 34px 8px rgba(255, 207, 111, 0.4);
  pointer-events: none;
  animation: vignettePulse 0.82s ease-out forwards;
}

.score-pop.big {
  font-size: 17px;
}

.score-pop.huge {
  color: #fff5b8;
  font-size: 21px;
  text-shadow:
    0 2px 0 rgba(190, 105, 44, 0.6),
    0 0 16px rgba(255, 213, 102, 0.9),
    0 6px 16px rgba(93, 50, 32, 0.38);
}

.score-pop {
  position: absolute;
  z-index: 2;
  color: #fffaf2;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.01em;
  text-shadow: 0 2px 0 rgba(161, 88, 54, 0.55), 0 5px 12px rgba(93, 50, 32, 0.35);
  transform: translate(-50%, 0);
  animation: scoreFloat 0.7s ease-out forwards;
  pointer-events: none;
}

.combo-banner {
  position: absolute;
  top: 42%;
  left: 50%;
  z-index: 9;
  opacity: 0;
  color: #fffaf2;
  font-size: clamp(26px, 8vw, 42px);
  font-weight: 900;
  letter-spacing: 0.02em;
  text-shadow:
    0 2px 0 #c95845,
    0 0 18px rgba(255, 191, 87, 0.85),
    0 9px 24px rgba(104, 52, 31, 0.36);
  transform: translate(-50%, -50%);
  pointer-events: none;
  white-space: nowrap;
}

.combo-banner::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 190%;
  height: 190%;
  border-radius: 50%;
  background: radial-gradient(
    closest-side,
    rgba(255, 218, 125, 0.52),
    rgba(255, 171, 92, 0.2) 52%,
    transparent 72%
  );
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.5);
  pointer-events: none;
}

.combo-banner.show {
  animation: comboPop 0.85s ease-out forwards;
}

.combo-banner.show::before {
  animation: comboGlow 0.85s ease-out forwards;
}

.combo-banner.hot {
  color: #fff5b8;
}

.combo-banner.mega {
  font-size: clamp(31px, 10vw, 52px);
}

.shuffle-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(69, 50, 42, 0.84);
  box-shadow: 0 8px 24px rgba(58, 35, 25, 0.28);
  color: #fff9f0;
  font-size: 11px;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.shuffle-banner .spin {
  width: 15px;
  height: 15px;
  animation: spin 0.9s linear infinite;
}

.loading {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 11;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 250, 242, 0.9);
  color: var(--muted);
  font-size: 11px;
  transform: translate(-50%, -50%);
  box-shadow: 0 5px 16px rgba(104, 70, 49, 0.12);
}

/* ---------- 覆盖层 ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(68, 47, 37, 0.38);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fadeIn 0.18s ease-out;
}

.modal {
  width: min(92vw, 440px);
  max-height: 88dvh;
  overflow: auto;
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-radius: 26px;
  background: linear-gradient(180deg, #fffbf5 0%, #fdf3e7 100%);
  box-shadow: 0 28px 75px rgba(57, 33, 23, 0.3);
  animation: modalIn 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.08);
  -webkit-overflow-scrolling: touch;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.close-btn {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0 0 2px;
  border: 0;
  border-radius: 50%;
  background: rgba(107, 77, 61, 0.08);
  color: var(--muted);
  font-size: 23px;
  line-height: 1;
  cursor: pointer;
}

.rules-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 17px 0 18px;
  padding: 0;
  list-style: none;
}

.rules-list li {
  display: flex;
  align-items: flex-start;
  gap: 11px;
}

.rule-ic {
  width: 41px;
  height: 41px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fffdf9;
  box-shadow: 0 3px 9px rgba(105, 71, 52, 0.08);
  color: var(--coral-deep);
}

.rule-ic svg {
  width: 22px;
  height: 22px;
}

.rule-ic.rocket {
  color: #bc7c31;
  background: #fff6e5;
}

.rule-ic.rainbow {
  color: #ad761d;
  background: #fff8dc;
}

.rule-ic.bomb {
  color: #697c95;
  background: #f0f4f9;
}

.rules-list b {
  display: block;
  margin-top: 1px;
  font-size: 13.5px;
  line-height: 1.35;
}

.rules-list p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.55;
}

.primary,
.secondary {
  border: 0;
  border-radius: 999px;
  font-weight: 750;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.primary {
  padding: 12px 18px;
  background: linear-gradient(180deg, #eb836d 0%, #d8614e 100%);
  box-shadow:
    0 8px 18px rgba(198, 82, 63, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
  color: #fffaf7;
}

.primary:hover {
  background: linear-gradient(180deg, #ef8d77, #d96551);
}

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

.secondary {
  padding: 12px 18px;
  background: rgba(107, 77, 61, 0.09);
  color: var(--ink);
}

.secondary:hover {
  background: rgba(107, 77, 61, 0.13);
}

.wide {
  width: 100%;
}

/* ---------- 结算 ---------- */

.result-card {
  width: min(92vw, 400px);
  padding-top: 6px;
  text-align: center;
}

.result-cat-wrap {
  height: clamp(105px, 24vh, 155px);
  margin-top: -8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.result-cat-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 11px 17px rgba(103, 63, 40, 0.24));
  animation: catBounce 0.65s cubic-bezier(0.2, 1.2, 0.4, 1);
}

.stars {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin: 1px 0 2px;
}

.stars svg {
  width: 35px;
  height: 35px;
  color: rgba(107, 77, 61, 0.14);
  fill: currentColor;
}

.stars svg.filled {
  color: var(--gold);
  filter: drop-shadow(0 3px 5px rgba(195, 137, 33, 0.34));
  animation: starPop 0.44s cubic-bezier(0.2, 1.4, 0.4, 1) backwards;
}

.stars svg.filled:nth-child(2) {
  animation-delay: 0.11s;
}

.stars svg.filled:nth-child(3) {
  animation-delay: 0.22s;
}

.result-card h2 {
  margin: 2px 0 0;
  font-size: 23px;
}

.result-text {
  margin: 6px 0 16px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.5;
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.6);
}

.result-stats span {
  display: block;
  color: var(--muted);
  font-size: 9.5px;
  line-height: 1.3;
}

.result-stats b {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1.1fr;
  gap: 8px;
}

.result-actions button {
  padding: 12px 7px;
  font-size: 12.5px;
}

.result-card.lost .result-actions {
  grid-template-columns: 1fr 1fr;
}

/* ---------- 选关 ---------- */

.map-card {
  width: min(94vw, 560px);
  padding: 19px;
}

.map-head {
  justify-content: space-between;
}

.map-title-wrap {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.map-title-wrap p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 10.5px;
}

.page-btn {
  width: 36px;
  height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0 0 2px;
  border: 0;
  border-radius: 50%;
  background: rgba(107, 77, 61, 0.08);
  color: var(--ink);
  font-size: 23px;
  line-height: 1;
  cursor: pointer;
}

.page-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.map-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  max-height: 52dvh;
  margin: 17px 0;
  padding: 2px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.map-btn {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0;
  border: 1px solid rgba(107, 77, 61, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}

.map-btn.locked {
  background: rgba(107, 77, 61, 0.045);
  color: rgba(107, 77, 61, 0.33);
  cursor: default;
}

.map-btn.locked svg {
  width: 13px;
  height: 13px;
}

.map-btn.cleared {
  background: linear-gradient(180deg, #fffaf2, #ffecd9);
}

.map-btn.current {
  outline: 3px solid var(--coral);
  outline-offset: 1px;
  background: #fff8f1;
}

.map-stars {
  height: 6px;
  display: flex;
  align-items: center;
  gap: 2px;
}

.map-stars i {
  width: 5px;
  height: 5px;
  display: block;
  border-radius: 50%;
  background: rgba(107, 77, 61, 0.15);
}

.map-stars i.on {
  background: var(--gold);
}

.map-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
}

.map-foot button {
  padding: 9px 18px;
  font-size: 12px;
}

/* ---------- 提示条 ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 80;
  max-width: calc(100vw - 36px);
  padding: 9px 16px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(69, 50, 42, 0.9);
  box-shadow: 0 8px 24px rgba(63, 38, 26, 0.25);
  color: #fff9f0;
  font-size: 11.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- 宽屏 / 横屏 ---------- */

@media (min-width: 900px) {
  .app {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: clamp(26px, 4vw, 58px);
    padding:
      max(28px, env(safe-area-inset-top))
      max(36px, env(safe-area-inset-right))
      max(28px, env(safe-area-inset-bottom))
      max(36px, env(safe-area-inset-left));
  }

  .game-panel {
    width: 340px;
    max-width: none;
    margin: 0;
    flex: 0 0 340px;
    gap: 13px;
  }

  .brand h1 {
    font-size: 25px;
  }

  .brand p {
    font-size: 11.5px;
  }

  .hud {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .moves-card {
    grid-column: 1;
    grid-row: 1;
  }

  .score-card {
    grid-column: 2;
    grid-row: 1;
  }

  .goal-card {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .moves-value {
    font-size: 27px;
  }

  .board-area {
    flex: 0 1 auto;
    width: min(58vw, 680px);
    height: min(84dvh, 720px);
    gap: 8px;
  }

  .board-tip {
    font-size: 11.5px;
  }

  .map-grid {
    grid-template-columns: repeat(10, 1fr);
  }
}

@media (min-width: 740px) and (max-height: 620px) {
  .app {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 18px;
    padding:
      max(9px, env(safe-area-inset-top))
      max(18px, env(safe-area-inset-right))
      max(9px, env(safe-area-inset-bottom))
      max(18px, env(safe-area-inset-left));
  }

  .game-panel {
    width: 294px;
    max-width: none;
    flex: 0 0 294px;
    gap: 9px;
    margin: 0;
  }

  .brand h1 {
    font-size: 18px;
  }

  .brand p {
    display: none;
  }

  .hud {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .moves-card {
    grid-column: 1;
    grid-row: 1;
  }

  .score-card {
    grid-column: 2;
    grid-row: 1;
  }

  .goal-card {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .hud-card {
    padding: 7px 9px;
  }

  .moves-value {
    font-size: 22px;
  }

  .board-area {
    flex: 1;
    height: 100%;
    width: auto;
    max-width: none;
    gap: 0;
  }

  .board-tip {
    display: none;
  }
}

/* ---------- 手机 ---------- */

@media (max-width: 680px) {
  .app {
    gap: 9px;
    padding:
      max(10px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(11px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }

  .game-panel {
    gap: 8px;
  }

  .brand h1 {
    font-size: 18px;
  }

  .brand p {
    display: none;
  }

  .top-actions {
    gap: 5px;
  }

  .level-pill {
    min-height: 34px;
    padding: 0 9px;
    font-size: 11.5px;
  }

  .icon-btn {
    width: 34px;
    height: 34px;
  }

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

  .hud {
    gap: 6px;
  }

  .hud-card {
    padding: 8px 9px;
    border-radius: 14px;
  }

  .moves-value {
    font-size: 23px;
  }

  .score-card > b {
    font-size: 17px;
  }

  .goal-top b {
    font-size: 10.5px;
  }

  .modal {
    padding: 18px;
    border-radius: 23px;
  }

  .result-card {
    width: min(94vw, 370px);
  }

  .result-actions {
    gap: 6px;
  }

  .result-actions button {
    padding: 11px 5px;
    font-size: 12px;
  }

  .map-card {
    width: min(94vw, 500px);
  }

  .map-grid {
    gap: 6px;
  }

  .toast {
    font-size: 11px;
  }
}

@media (max-width: 360px) {
  .brand h1 {
    font-size: 16px;
  }

  .level-pill {
    padding: 0 7px;
    font-size: 10.5px;
  }

  .icon-btn {
    width: 31px;
    height: 31px;
  }

  .top-actions {
    gap: 4px;
  }

  .hud-card {
    padding: 7px 7px;
  }

  .hud-label {
    font-size: 8.5px;
  }

  .goal-top b {
    font-size: 9.5px;
  }

  .moves-value {
    font-size: 21px;
  }

  .score-card > b {
    font-size: 15px;
  }

  .best {
    font-size: 8px;
  }
}

/* ---------- 动效 ---------- */

@keyframes clearPop {
  0% {
    transform: scale(1) rotate(0);
    opacity: 1;
    filter: brightness(1);
  }
  42% {
    transform: scale(1.2) rotate(2deg);
    opacity: 1;
    filter: brightness(1.18);
  }
  100% {
    transform: scale(0.22) rotate(9deg);
    opacity: 0;
    filter: brightness(1.25);
  }
}

@keyframes specialBorn {
  0% {
    transform: scale(0.62) rotate(-10deg);
    filter: brightness(1.5);
  }
  58% {
    transform: scale(1.16) rotate(4deg);
    filter: brightness(1.18);
  }
  100% {
    transform: scale(1) rotate(0);
    filter: brightness(1);
  }
}

@keyframes boardShake {
  0%,
  100% {
    transform: translateX(0);
  }
  18% {
    transform: translateX(-7px) rotate(-0.3deg);
  }
  38% {
    transform: translateX(6px) rotate(0.3deg);
  }
  58% {
    transform: translateX(-4px);
  }
  78% {
    transform: translateX(2px);
  }
}

@keyframes boardImpact {
  0%,
  100% {
    transform: translate(0, 0) scale(1);
  }
  12% {
    transform: translate(-3px, 2px) scale(1.012);
  }
  28% {
    transform: translate(3px, -2px) scale(1.008);
  }
  48% {
    transform: translate(-2px, 1px) scale(1.004);
  }
  70% {
    transform: translate(1px, -1px) scale(1.002);
  }
}

@keyframes beamRow {
  0% {
    opacity: 0;
    transform: scaleX(0.08);
  }
  22% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scaleX(1.04);
  }
}

@keyframes beamCol {
  0% {
    opacity: 0;
    transform: scaleY(0.08);
  }
  22% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scaleY(1.04);
  }
}

@keyframes burst {
  0% {
    opacity: 0.95;
    transform: translate(-50%, -50%) scale(0.18);
  }
  55% {
    opacity: 0.85;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.75);
  }
}

@keyframes rainbowFlash {
  0% {
    opacity: 0;
  }
  28% {
    opacity: 0.92;
  }
  100% {
    opacity: 0;
  }
}

@keyframes sparkFly {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx, 20px), var(--dy, -22px)) scale(0.2);
  }
}

@keyframes starFly {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(0.2) rotate(0);
  }
  18% {
    opacity: 1;
    transform: translate(0, 0) scale(1.1) rotate(0);
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx, 24px), var(--dy, -26px)) scale(0.25) rotate(var(--rot, 160deg));
  }
}

@keyframes confettiFly {
  0% {
    opacity: 0;
    transform: translate(0, 0) rotate(0) scale(0.6);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx, 24px), calc(var(--dy, -26px) + 26px)) rotate(var(--rot, 220deg)) scale(0.85);
  }
}

@keyframes ringBurst {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.18);
  }
  16% {
    opacity: 0.95;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.45);
  }
}

@keyframes boardFlash {
  0% {
    opacity: 0;
  }
  12% {
    opacity: 0.9;
  }
  100% {
    opacity: 0;
  }
}

@keyframes linkFlash {
  0% {
    opacity: 0;
    transform: rotate(var(--angle, 0deg)) scaleX(0.05);
  }
  24% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: rotate(var(--angle, 0deg)) scaleX(1);
  }
}

@keyframes vignettePulse {
  0% {
    opacity: 0;
  }
  22% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes tileLand {
  0% {
    transform: scale(1, 1);
  }
  38% {
    transform: scale(1.08, 0.88);
  }
  70% {
    transform: scale(0.97, 1.03);
  }
  100% {
    transform: scale(1, 1);
  }
}

@keyframes scoreFloat {
  0% {
    opacity: 0;
    transform: translate(-50%, 4px) scale(0.75);
  }
  24% {
    opacity: 1;
    transform: translate(-50%, -7px) scale(1.08);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -37px) scale(1);
  }
}

@keyframes comboPop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.58) rotate(-4deg);
  }
  22% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.08) rotate(1deg);
  }
  64% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(0);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -54%) scale(1.02);
  }
}

@keyframes comboGlow {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5);
  }
  24% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.9);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.18);
  }
}

@keyframes catBounce {
  0% {
    opacity: 0;
    transform: translateY(16px) scale(0.88);
  }
  55% {
    opacity: 1;
    transform: translateY(-7px) scale(1.04);
  }
  78% {
    transform: translateY(2px) scale(0.99);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

@keyframes starPop {
  0% {
    opacity: 0;
    transform: scale(0.2) rotate(-18deg);
  }
  62% {
    opacity: 1;
    transform: scale(1.18) rotate(4deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

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

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
