/* Pet Link — 深色界面、棋盘无卡片区、道具立体按钮 */

:root {
  --pl-bg-deep: #14101f;
  --pl-bg-purple: #2a1f42;
  --pl-text: #f8f4ff;
  --pl-text-soft: rgba(248, 244, 255, 0.72);
  --pl-text-dim: rgba(248, 244, 255, 0.5);
  --pl-glass: rgba(255, 255, 255, 0.1);
  --pl-glass-strong: rgba(255, 255, 255, 0.16);
  --pl-stroke: rgba(255, 255, 255, 0.22);
  --pl-gold: #f4c14d;
  --pl-gold-soft: #ffd06b;
  --pl-pink: #ff8fb8;
  --pl-cyan: #7ec8e3;
  --pl-violet: #8b76ff;
  --pl-gradient-cta: linear-gradient(125deg, #7b68ee 0%, #5b7cfa 45%, #4ec8e8 100%);
  --pl-gradient-hud: linear-gradient(180deg, rgba(40, 32, 62, 0.55) 0%, rgba(25, 18, 40, 0.4) 100%);
  --pl-shadow-soft: 0 8px 32px rgba(0, 0, 0, 0.35);
  --pl-radius-lg: 22px;
  --pl-radius-md: 16px;
  --pl-radius-sm: 12px;
  --pl-font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

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

  .splash-pet-wrap,
  .splash-pet-img {
    animation: none !important;
  }

  .tile.selected {
    animation: none !important;
  }

  .tile.tile--matching {
    animation-duration: 0.32s !important;
  }

  /* 连不上时的反馈：保留可辨的晃动，不被 * 的 0.01ms 动画时长压没 */
  .tile.tile--nope {
    animation-duration: 0.38s !important;
    animation-iteration-count: 1 !important;
  }

  .tile.tile--mismatch {
    animation-duration: 0.34s !important;
    animation-iteration-count: 1 !important;
  }

  .tile.hint-pulse {
    animation: none !important;
  }

  .combo-burst-inner.combo-burst--tick {
    animation: none !important;
    transform: none !important;
    opacity: 1 !important;
  }
}

* {
  box-sizing: border-box;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html {
  color-scheme: dark;
}

html,
body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  font-family: var(--pl-font);
  touch-action: manipulation;
  color: var(--pl-text);
  background: var(--pl-bg-deep);
}

body {
  position: relative;
  isolation: isolate;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(ellipse 110% 70% at 50% -24%, rgba(140, 106, 255, 0.18) 0%, transparent 55%),
    radial-gradient(ellipse 95% 70% at 105% 20%, rgba(128, 88, 255, 0.14) 0%, transparent 58%),
    linear-gradient(180deg, #210640 0%, #1a0638 45%, #160530 100%);
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg, rgba(6, 3, 14, 0.24) 0%, rgba(10, 4, 20, 0.18) 36%, rgba(6, 3, 14, 0.36) 100%);
  pointer-events: none;
}

.app {
  max-width: min(100%, 440px);
  margin: 0 auto;
  padding: 12px max(12px, env(safe-area-inset-left, 0px)) calc(24px + env(safe-area-inset-bottom, 0px))
    max(12px, env(safe-area-inset-right, 0px));
}

.screen {
  display: none;
}

.screen.is-active {
  display: block;
}

/* —— 启动画 —— */
.screen-splash.is-active {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px)
    env(safe-area-inset-left, 0px);
  min-height: 100dvh;
  min-height: 100svh;
  cursor: pointer;
  animation: splash-fade-in 0.4s ease-out both;
  background:
    radial-gradient(ellipse 100% 70% at 50% 0%, rgba(129, 140, 248, 0.35) 0%, transparent 55%),
    linear-gradient(165deg, #161322 0%, #1e1a2e 45%, #12101a 100%);
}

@keyframes splash-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.splash-inner {
  text-align: center;
  pointer-events: none;
}

.splash-brand {
  margin: 0 0 clamp(12px, 3vw, 20px);
  font-size: clamp(1.65rem, 7vw, 2.1rem);
  font-weight: 900;
  letter-spacing: 0.14em;
  color: var(--pl-text);
  text-shadow: 0 2px 24px rgba(123, 104, 238, 0.45);
}

.splash-pets {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(8px, 3vw, 20px);
  margin: 0 0 clamp(16px, 4vw, 24px);
  flex-wrap: wrap;
}

.splash-pet-wrap {
  animation: splash-pet-float 2.4s ease-in-out 0.65s infinite;
}

.splash-pet-wrap--b {
  animation-delay: 0.77s;
}

.splash-pet-img {
  display: block;
  width: clamp(88px, 28vw, 130px);
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 12px 28px rgba(0, 0, 0, 0.45));
  animation: splash-pet-pop 0.6s cubic-bezier(0.34, 1.3, 0.64, 1) both;
}

.splash-pet-wrap--b .splash-pet-img {
  animation-delay: 0.12s;
}

@keyframes splash-pet-pop {
  0% {
    transform: scale(0.65) translateY(12px);
    opacity: 0;
  }
  100% {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

@keyframes splash-pet-float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

.splash-hint {
  margin: 0;
  font-size: clamp(0.72rem, 2.8vw, 0.82rem);
  color: var(--pl-text-soft);
  letter-spacing: 0.12em;
}

/* —— 选关：与全局背景融合，不使用独立内容底色 —— */
.screen-levels {
  background: transparent;
}

.screen-levels.is-active {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 24px);
  max-height: 100dvh;
}

.screen-levels .header-brand {
  margin-bottom: 10px;
  flex-shrink: 0;
  padding: 6px 4px;
}

.screen-levels .brand-title {
  margin: 0;
  font-size: clamp(1.45rem, 5.5vw, 1.85rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--pl-text);
  text-align: center;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.35);
}

.level-list {
  list-style: none;
  margin: 0;
  padding: 8px 8px 14px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  flex: 1;
  min-height: 0;
  align-content: start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.level-list > li {
  min-width: 0;
}

.level-card {
  width: 100%;
  aspect-ratio: 1;
  margin: 0 auto;
  padding: 5px 4px 7px;
  border-radius: 14px;
  border: 2px solid var(--pl-stroke);
  cursor: pointer;
  font: inherit;
  color: inherit;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  transition: transform 0.12s ease, filter 0.12s ease, border-color 0.12s ease;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.level-card--playable {
  background: linear-gradient(165deg, #faf8ff 0%, #ebe4f5 55%, #e2daf0 100%);
}

.level-card--playable:not(.level-card--current):hover {
  filter: brightness(1.05);
}

.level-card--current {
  background: linear-gradient(165deg, #fffaf0 0%, #f5efe8 100%);
  border-color: var(--pl-gold);
  border-width: 3px;
}

.level-card--locked {
  background: linear-gradient(165deg, rgba(52, 44, 72, 0.95) 0%, rgba(38, 32, 56, 0.98) 100%);
  border-color: rgba(255, 255, 255, 0.08);
  opacity: 0.98;
}

.level-card:disabled {
  cursor: not-allowed;
  filter: none;
}

.level-card:not(:disabled):active {
  transform: scale(0.97);
}

.level-card-stars-row {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 1px;
  min-height: clamp(1.15rem, 5.5vw, 1.45rem);
  margin: 0 0 5px;
  padding-top: 3px;
}


.level-card-star {
  line-height: 1;
  font-size: clamp(1rem, 5vw, 1.28rem);
  color: rgba(90, 72, 120, 0.45);
}

.level-card-star--l {
  transform: translateY(6px) scale(0.88);
}

.level-card-star--c {
  transform: translateY(0) scale(1.2);
  font-size: clamp(1.12rem, 5.6vw, 1.45rem);
}

.level-card-star--r {
  transform: translateY(6px) scale(0.88);
}

.level-card-star--on {
  color: var(--pl-gold);
}

.level-card-star--off {
  color: rgba(75, 60, 105, 0.38);
}

.level-card-star--muted {
  color: rgba(140, 128, 175, 0.55);
}


.level-card-bar {
  margin-top: auto;
  width: 100%;
  padding: 5px 4px;
  border-radius: 8px;
  background: linear-gradient(180deg, #5c4d8a 0%, #453a6e 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
}

.level-card--current .level-card-bar {
  background: linear-gradient(180deg, #6b5a9e 0%, #52457c 100%);
}

.level-card--locked .level-card-bar {
  background: linear-gradient(180deg, #3a3248 0%, #2c2538 100%);
}

.level-card-num {
  font-weight: 800;
  font-size: clamp(0.74rem, 3.5vw, 0.9rem);
  line-height: 1;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.level-card-lock {
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.95);
}

.level-card-lock-svg {
  display: block;
}

/* —— 对局 —— */
.screen.screen-game.is-active {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 24px);
}

.game-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  padding: 10px 4px 12px;
  margin-bottom: 4px;
}

.game-status {
  position: relative;
  display: block;
  min-width: 0;
  width: 182px;
  height: 60px;
}

.game-hud .btn-ghost {
  margin-left: 0;
}

.game-level {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 62px;
  height: 62px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 900;
  font-size: 0.96rem;
  color: #ffefcc;
  letter-spacing: 0.015em;
  padding: 0;
  border-radius: 999px;
  border: 3px solid #9f75ff;
  background:
    radial-gradient(circle at 28% 20%, rgba(255, 255, 255, 0.34) 0%, rgba(255, 255, 255, 0.06) 40%, transparent 56%),
    linear-gradient(180deg, #7d3cff 0%, #5f24d6 45%, #4f1dad 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.28),
    inset 0 -3px 0 rgba(38, 16, 91, 0.72),
    inset 0 0 0 1px rgba(255, 255, 255, 0.2),
    0 0 0 2px rgba(167, 128, 255, 0.4),
    0 6px 14px rgba(16, 6, 42, 0.55);
}

.game-time {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 138px;
  height: 44px;
  text-align: center;
  padding: 0 10px 0 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 3px solid #9f75ff;
  background:
    radial-gradient(ellipse 36% 46% at 22% 24%, rgba(255, 255, 255, 0.26) 0%, rgba(255, 255, 255, 0.04) 64%, transparent 100%),
    linear-gradient(180deg, #0f2e96 0%, #0c2380 55%, #0a1f72 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.25),
    inset 0 -3px 0 rgba(6, 24, 98, 0.75),
    inset 0 0 0 1px rgba(255, 255, 255, 0.14),
    0 0 0 2px rgba(167, 128, 255, 0.4),
    0 6px 14px rgba(10, 6, 32, 0.58);
  font-weight: 900;
  font-size: clamp(0.82rem, 3.2vw, 0.98rem);
  font-variant-numeric: tabular-nums;
  color: #ffefcc;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 0 rgba(30, 18, 76, 0.45);
}

.combo-burst {
  position: absolute;
  left: 50%;
  top: 2px;
  z-index: 8;
  transform: translateX(-50%);
  pointer-events: none;
}

.combo-burst-inner {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 6px 14px 8px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(244, 193, 77, 0.22) 0%, rgba(255, 143, 184, 0.18) 50%, rgba(139, 118, 255, 0.2) 100%);
  border: 1px solid rgba(244, 193, 77, 0.45);
  box-shadow:
    0 0 24px rgba(244, 193, 77, 0.35),
    0 8px 28px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
}

.combo-burst-inner.combo-burst--tick {
  animation: combo-burst-pop 0.42s var(--tile-ease-out, cubic-bezier(0.22, 1, 0.36, 1)) both;
}

.combo-burst-label {
  font-weight: 800;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  color: var(--pl-gold-soft);
  text-shadow: 0 0 12px rgba(244, 193, 77, 0.5);
}

.combo-burst-value {
  font-weight: 900;
  font-size: clamp(1.35rem, 5.5vw, 1.75rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  background: linear-gradient(180deg, #fff8e8 0%, var(--pl-gold) 45%, #e8a820 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 8px rgba(244, 193, 77, 0.55));
}

@keyframes combo-burst-pop {
  0% {
    transform: scale(0.65);
    opacity: 0;
  }
  55% {
    transform: scale(1.08);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

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

.board-wrap {
  position: relative;
  display: inline-block;
  overflow: visible;
}

.board-link-layer {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  z-index: 6;
}

/* 连线：底层柔光 + 顶层渐变描边（样式由 SVG 属性与 showMatchLine 内联动画配合） */
.board-link-layer .board-link-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.board-link-layer .board-link-line--glow {
  stroke: rgba(126, 232, 255, 0.5);
  stroke-width: 12;
  opacity: 0.95;
  filter: drop-shadow(0 0 8px rgba(126, 210, 255, 0.6)) drop-shadow(0 0 16px rgba(244, 193, 77, 0.4));
}

.board-link-layer .board-link-line--core {
  stroke-width: 4.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 3px rgba(255, 255, 255, 0.9)) drop-shadow(0 0 14px rgba(126, 230, 255, 0.7));
}

@media (prefers-reduced-motion: reduce) {
  .board-link-layer .board-link-line--glow {
    opacity: 1;
  }
}

.board-tools {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: clamp(14px, 4vw, 18px);
  width: 100%;
  margin: 14px auto 0;
  padding: 8px 0 2px;
  border: none;
  background: transparent;
  box-shadow: none;
  flex-shrink: 0;
}

.tool-card {
  --tool-w: clamp(68px, 18vw, 82px);
  position: relative;
  width: var(--tool-w);
  height: calc(var(--tool-w) + 12px);
  padding: 0;
  border: none;
  cursor: pointer;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}

.tool-card:focus-visible {
  outline: 2px solid var(--pl-cyan);
  outline-offset: 4px;
}

.tool-card-face {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: var(--tool-w);
  border-radius: 999px;
  background:
    radial-gradient(circle at 30% 24%, rgba(255, 255, 255, 0.34) 0%, transparent 44%),
    linear-gradient(180deg, #5968ff 0%, #3b43e6 40%, #2a2fc8 72%, #211f9f 100%);
  border: 3px solid #f6f9ff;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.74),
    inset 0 -4px 0 rgba(21, 21, 98, 0.62),
    inset 0 0 0 1px rgba(255, 255, 255, 0.3),
    0 0 0 2px rgba(216, 229, 255, 0.42),
    0 1px 0 rgba(255, 255, 255, 0.58),
    0 5px 0 rgba(20, 22, 112, 0.82),
    0 10px 18px rgba(11, 8, 52, 0.42);
  transform: translateY(0);
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.1s ease;
}

.tool-card:hover .tool-card-face {
  filter: brightness(1.08);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.58),
    inset 0 -4px 0 rgba(21, 21, 98, 0.56),
    inset 0 0 0 1px rgba(255, 255, 255, 0.22),
    0 1px 0 rgba(255, 255, 255, 0.48),
    0 5px 0 rgba(20, 22, 112, 0.78),
    0 12px 20px rgba(11, 8, 52, 0.46);
}

.tool-card:active .tool-card-face {
  transform: translateY(3px) scale(0.98);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.24),
    inset 0 -2px 0 rgba(23, 35, 98, 0.4),
    0 2px 0 rgba(24, 35, 100, 0.6),
    0 6px 10px rgba(6, 10, 38, 0.3);
}

.tool-card img {
  display: block;
  width: 34px;
  height: 34px;
  filter: brightness(0) invert(1) drop-shadow(0 2px 4px rgba(20, 30, 90, 0.55));
  pointer-events: none;
}

.tool-icon-refresh {
  display: block;
  color: #fff;
  filter: drop-shadow(0 2px 4px rgba(20, 30, 90, 0.55));
  pointer-events: none;
}

.tool-card-count {
  position: absolute;
  right: -4px;
  top: -4px;
  min-width: 30px;
  height: 30px;
  padding: 0 7px;
  border-radius: 999px;
  border: 2px solid #8a0b48;
  background: radial-gradient(circle at 32% 28%, #ff6fb2 0%, #e32073 48%, #b80f57 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.38),
    0 3px 0 #7f093f,
    0 5px 10px rgba(40, 10, 35, 0.4);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 900;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.tool-card.tool-card--empty .tool-card-face {
  filter: grayscale(0.2) saturate(0.75) brightness(0.9);
}

.tool-card.tool-card--empty .tool-card-count {
  background: radial-gradient(circle at 32% 28%, #ff84bc 0%, #ca1c66 48%, #8f1244 100%);
}

.btn-ghost {
  flex: 0 0 auto;
  min-width: 104px;
  justify-content: center;
  padding: 9px 16px;
  font-size: 1.05rem;
  font-weight: 900;
  color: #ffefcc;
  border: 3px solid #9f75ff;
  border-radius: 999px;
  background: linear-gradient(180deg, #0f2e96 0%, #0c2380 55%, #0a1f72 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.25),
    inset 0 -3px 0 rgba(6, 24, 98, 0.75),
    inset 0 0 0 1px rgba(255, 255, 255, 0.14),
    0 0 0 2px rgba(167, 128, 255, 0.4),
    0 6px 14px rgba(10, 6, 32, 0.58);
  line-height: 1;
  letter-spacing: 0.01em;
}

.btn-ghost:hover {
  filter: brightness(1.06) saturate(1.05);
}

.btn-ghost:active {
  transform: translateY(2px) scale(0.99);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    inset 0 -2px 0 rgba(6, 24, 98, 0.72),
    0 4px 10px rgba(10, 6, 32, 0.52);
}

.end-actions .btn {
  justify-content: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--pl-radius-sm);
  border: 1px solid var(--pl-stroke);
  background: var(--pl-glass-strong);
  backdrop-filter: blur(8px);
  color: var(--pl-text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.btn:hover {
  border-color: rgba(255, 255, 255, 0.35);
}

.btn.primary {
  background: var(--pl-gradient-cta);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.25);
  box-shadow: 0 8px 28px rgba(91, 124, 250, 0.35);
}

.btn.primary:hover {
  filter: brightness(1.06);
}

.main {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 2px 0 0;
  overflow: visible;
}

/* 纵向滚动只放在内层，避免 .main overflow-y:auto 连带裁切横向（棋子放大、连线光晕） */
.game-scroll {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  overflow-x: visible;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* 为选中/消除缩放、描边、连线 SVG 滤镜留出边距，避免贴边被切 */
  padding: 8px clamp(14px, 5vw, 22px) 10px;
}

.board {
  --cell: 52px;
  --gap: 6px;
  --tile-ease: cubic-bezier(0.34, 1.45, 0.64, 1);
  --tile-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  display: grid;
  gap: var(--gap);
  padding: 0;
  margin: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  grid-template-columns: repeat(var(--cols), var(--cell));
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  overflow: visible;
}

.tile {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  border-radius: 14px;
  border: none;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  background: linear-gradient(165deg, #fefeff 0%, #f3effa 48%, #ebe4f5 100%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.85) inset,
    0 -1px 0 rgba(80, 60, 120, 0.06) inset,
    0 5px 0 rgba(45, 32, 58, 0.14),
    0 8px 14px rgba(25, 18, 40, 0.12);
  transition:
    transform 0.14s var(--tile-ease),
    box-shadow 0.14s var(--tile-ease),
    filter 0.14s ease;
}

.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.55) 0%, transparent 42%, transparent 100%);
  opacity: 0.5;
}

/* 所有棋子同一套尺寸与 contain，不裁切；视觉大小由素材留白决定，请在图里统一。 */
.tile img {
  position: relative;
  z-index: 1;
  width: 78%;
  height: 78%;
  object-fit: contain;
  object-position: center center;
  pointer-events: none;
  user-select: none;
  border-radius: 10px;
}

.tile .tile-num {
  position: relative;
  z-index: 1;
  width: 86%;
  height: 86%;
  min-width: 0;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  font-size: clamp(0.72rem, calc(var(--cell) * 0.34), 1.35rem);
  letter-spacing: -0.03em;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.28);
  background: hsl(var(--hue), 52%, 48%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    0 2px 6px rgba(0, 0, 0, 0.15);
  pointer-events: none;
  user-select: none;
}

.tile:active {
  transform: translateY(2px) scale(0.97);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.7) inset,
    0 2px 0 rgba(45, 32, 58, 0.12),
    0 3px 8px rgba(25, 18, 40, 0.1);
}

.tile.tile--pressed {
  transform: translateY(3px) scale(0.96);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.5) inset,
    0 1px 0 rgba(45, 32, 58, 0.1),
    0 2px 6px rgba(25, 18, 40, 0.12);
  transition-duration: 0.05s;
}

.tile.tile--pressed:active {
  transform: translateY(3px) scale(0.95);
}

.tile.selected {
  transform: scale(1.05);
  z-index: 2;
  outline: none;
  box-shadow:
    0 0 0 3px rgba(139, 118, 255, 0.95),
    0 0 0 1px rgba(255, 255, 255, 0.35) inset,
    0 0 24px rgba(139, 118, 255, 0.55),
    0 6px 0 rgba(45, 32, 58, 0.1),
    0 12px 20px rgba(79, 70, 229, 0.25);
  animation: tile-selected-pulse 1.6s ease-in-out infinite;
}

.tile.selected.tile--pressed {
  transform: scale(1.02) translateY(2px);
}

@keyframes tile-selected-pulse {
  0%,
  100% {
    box-shadow:
      0 0 0 3px rgba(139, 118, 255, 0.9),
      0 0 0 1px rgba(255, 255, 255, 0.35) inset,
      0 0 20px rgba(139, 118, 255, 0.45),
      0 6px 0 rgba(45, 32, 58, 0.1),
      0 12px 20px rgba(79, 70, 229, 0.22);
  }
  50% {
    box-shadow:
      0 0 0 3px rgba(167, 139, 250, 1),
      0 0 0 1px rgba(255, 255, 255, 0.45) inset,
      0 0 28px rgba(167, 139, 250, 0.65),
      0 6px 0 rgba(45, 32, 58, 0.1),
      0 14px 24px rgba(129, 140, 248, 0.35);
  }
}

.tile.hint-pulse {
  animation: hint-pulse 0.9s ease-in-out infinite;
}

@keyframes hint-pulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow:
      0 1px 0 rgba(255, 255, 255, 0.85) inset,
      0 5px 0 rgba(45, 32, 58, 0.14),
      0 8px 14px rgba(25, 18, 40, 0.12);
  }
  50% {
    transform: scale(1.04);
    box-shadow:
      0 0 0 3px rgba(255, 200, 120, 0.85),
      0 0 20px rgba(244, 193, 77, 0.45),
      0 6px 0 rgba(45, 32, 58, 0.1);
  }
}

.tile.tile--matching {
  pointer-events: none;
  z-index: 4;
  transition: none;
  animation: tile-match-pop 0.5s cubic-bezier(0.22, 0.82, 0.24, 1) forwards;
}

.tile.tile--matching::after {
  animation: tile-match-shine 0.5s ease-out forwards;
}

@keyframes tile-match-pop {
  0% {
    transform: scale(1) rotate(0deg);
    filter: brightness(1) saturate(1);
    box-shadow:
      0 1px 0 rgba(255, 255, 255, 0.85) inset,
      0 -1px 0 rgba(80, 60, 120, 0.06) inset,
      0 5px 0 rgba(45, 32, 58, 0.14),
      0 8px 14px rgba(25, 18, 40, 0.12);
    opacity: 1;
  }
  14% {
    transform: scale(1.06) rotate(-0.5deg);
    filter: brightness(1.12) saturate(1.08);
    box-shadow:
      0 0 0 3px rgba(126, 232, 255, 0.55),
      0 0 22px rgba(126, 220, 255, 0.45),
      0 1px 0 rgba(255, 255, 255, 0.9) inset,
      0 6px 0 rgba(45, 32, 58, 0.12),
      0 14px 24px rgba(79, 70, 229, 0.2);
    opacity: 1;
  }
  32% {
    transform: scale(1.16) rotate(1deg);
    filter: brightness(1.22) saturate(1.18);
    box-shadow:
      0 0 0 3px rgba(244, 193, 77, 0.85),
      0 0 28px rgba(244, 193, 77, 0.55),
      0 0 36px rgba(139, 118, 255, 0.35),
      0 1px 0 rgba(255, 255, 255, 0.95) inset,
      0 7px 0 rgba(45, 32, 58, 0.1),
      0 16px 28px rgba(244, 193, 77, 0.25);
    opacity: 1;
  }
  52% {
    transform: scale(1.08) rotate(0deg);
    filter: brightness(1.14) saturate(1.1);
    box-shadow:
      0 0 0 2px rgba(255, 230, 160, 0.7),
      0 0 20px rgba(244, 193, 77, 0.4),
      0 5px 0 rgba(45, 32, 58, 0.12),
      0 12px 20px rgba(25, 18, 40, 0.12);
    opacity: 1;
  }
  72% {
    transform: scale(0.92) rotate(-2deg);
    filter: brightness(1.08) saturate(1.05);
    opacity: 1;
  }
  100% {
    transform: scale(0.12) rotate(-10deg);
    filter: brightness(1.45) saturate(1.2) blur(2px);
    box-shadow:
      0 0 24px rgba(255, 255, 255, 0.5),
      0 0 40px rgba(126, 220, 255, 0.4);
    opacity: 0;
  }
}

@keyframes tile-match-shine {
  0% {
    opacity: 0.45;
  }
  25% {
    opacity: 0.85;
  }
  100% {
    opacity: 0;
  }
}

/* 必须关掉对 transform 的 transition，否则会与 keyframes 抢同一属性，晃动看不见（Safari/WebKit 尤甚） */
.tile.tile--nope {
  animation: tile-nope-shake 0.42s var(--tile-ease) both;
  transition: none;
}

/* 与 .selected 同时存在时避免「呼吸」动画抢掉晃动；连不上时 JS 会延后加 selected，此为兜底 */
.tile.selected.tile--nope {
  animation: tile-nope-shake 0.42s var(--tile-ease) both;
  transition: none;
}

.tile.tile--nope.tile--pressed {
  transition: none;
}

@keyframes tile-nope-shake {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  15% {
    transform: translate3d(-9px, 0, 0);
  }
  30% {
    transform: translate3d(9px, 0, 0);
  }
  45% {
    transform: translate3d(-7px, 0, 0);
  }
  60% {
    transform: translate3d(6px, 0, 0);
  }
  75% {
    transform: translate3d(-3px, 0, 0);
  }
}

/* 图案不同：旋转 + 轻缩放回弹 + 粉边闪一下（与同图连不上的左右晃区分） */
.tile.tile--mismatch {
  animation: tile-mismatch-wobble 0.4s var(--tile-ease) both;
  transition: none;
  z-index: 3;
}

.tile.selected.tile--mismatch {
  animation: tile-mismatch-wobble 0.4s var(--tile-ease) both;
  transition: none;
}

.tile.tile--mismatch.tile--pressed {
  transition: none;
}

@keyframes tile-mismatch-wobble {
  0%,
  100% {
    transform: rotate(0deg) scale(1);
    filter: brightness(1) saturate(1);
    box-shadow:
      0 1px 0 rgba(255, 255, 255, 0.85) inset,
      0 -1px 0 rgba(80, 60, 120, 0.06) inset,
      0 5px 0 rgba(45, 32, 58, 0.14),
      0 8px 14px rgba(25, 18, 40, 0.12);
  }
  18% {
    transform: rotate(-7deg) scale(0.94);
    filter: brightness(0.9) saturate(0.88);
    box-shadow:
      0 0 0 2px rgba(255, 120, 160, 0.75),
      0 0 18px rgba(255, 100, 150, 0.45),
      0 4px 0 rgba(45, 32, 58, 0.12),
      0 8px 14px rgba(25, 18, 40, 0.12);
  }
  38% {
    transform: rotate(7deg) scale(0.94);
    filter: brightness(0.92) saturate(0.9);
    box-shadow:
      0 0 0 2px rgba(255, 130, 170, 0.7),
      0 0 16px rgba(255, 110, 160, 0.4),
      0 4px 0 rgba(45, 32, 58, 0.12),
      0 8px 14px rgba(25, 18, 40, 0.12);
  }
  58% {
    transform: rotate(-4deg) scale(0.97);
    filter: brightness(1.02) saturate(1.02);
    box-shadow:
      0 0 0 1px rgba(255, 143, 184, 0.5),
      0 6px 0 rgba(45, 32, 58, 0.12),
      0 10px 16px rgba(25, 18, 40, 0.1);
  }
  78% {
    transform: rotate(2deg) scale(1.01);
    filter: brightness(1.03) saturate(1.03);
  }
}

.tile.empty {
  visibility: hidden;
  pointer-events: none;
  box-shadow: none;
  background: transparent;
}


.toast {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(25, 18, 40, 0.92);
  backdrop-filter: blur(10px);
  color: var(--pl-text);
  font-size: 0.88rem;
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  z-index: 10;
  max-width: 90vw;
  text-align: center;
  border: 1px solid var(--pl-stroke);
  box-shadow: var(--pl-shadow-soft);
}

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

/* —— 结算全屏 —— */
.result-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-right, 0px))
    max(20px, env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px));
  min-height: 100dvh;
  min-height: 100svh;
  background: linear-gradient(165deg, #14101f 0%, #1a1528 50%, #0f0d16 100%);
}

.result-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 100% 70% at 50% 0%, rgba(129, 140, 248, 0.18) 0%, transparent 55%),
    linear-gradient(180deg, rgba(18, 14, 28, 0.92) 0%, rgba(12, 10, 20, 0.96) 100%);
  pointer-events: none;
}

.result-screen > * {
  position: relative;
  z-index: 1;
}

.result-screen.result-screen--fail {
  background:
    radial-gradient(ellipse 80% 50% at 50% 20%, rgba(255, 120, 140, 0.08) 0%, transparent 50%),
    linear-gradient(180deg, rgba(30, 22, 38, 0.95) 0%, rgba(18, 14, 24, 0.96) 100%);
}

.result-screen.result-screen--fail::before {
  background: linear-gradient(180deg, rgba(25, 18, 32, 0.92) 0%, rgba(15, 12, 22, 0.96) 100%);
}

.result-screen.hidden {
  display: none !important;
}

.result-screen-inner {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.result-stars {
  font-size: clamp(2.5rem, 12vw, 3.5rem);
  line-height: 1;
  letter-spacing: 0.15em;
  margin: 0 0 28px;
  padding: 0;
  display: inline-block;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.3));
}

.result-screen--fail .result-end-title:not(:empty) + .result-stars {
  margin-top: 8px;
}

.result-screen--win .result-stars {
  margin-top: 0;
  margin-bottom: 36px;
}

.result-star {
  display: inline-block;
  color: rgba(120, 100, 150, 0.6);
  text-shadow: none;
  transform-origin: center 60%;
}

.result-star.star--on {
  color: var(--pl-gold);
  text-shadow: 0 2px 12px rgba(244, 193, 77, 0.5);
}

.result-star.star--pop {
  animation: star-pop 0.58s cubic-bezier(0.34, 1.45, 0.64, 1) both;
}

@keyframes star-pop {
  0% {
    transform: scale(0.15) rotate(-28deg);
    opacity: 0;
    filter: blur(3px);
  }
  55% {
    transform: scale(1.12) rotate(6deg);
    opacity: 1;
    filter: blur(0);
  }
  100% {
    transform: scale(1) rotate(0deg);
  }
}

.result-stars--empty .result-star {
  color: rgba(100, 90, 120, 0.45);
}

.result-stars--shake {
  animation: stars-shake 0.5s ease-out both;
}

@keyframes stars-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-6px);
  }
  40% {
    transform: translateX(6px);
  }
  60% {
    transform: translateX(-4px);
  }
  80% {
    transform: translateX(4px);
  }
}

.result-end-title {
  margin: 0 0 8px;
  font-size: clamp(1.2rem, 4.5vw, 1.45rem);
  font-weight: 900;
  color: var(--pl-text-soft);
  min-height: 0;
}

.result-end-title:empty {
  display: none;
  margin: 0;
  padding: 0;
  height: 0;
  overflow: hidden;
}

.result-screen--fail .result-end-title {
  color: var(--pl-text);
}

.end-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
  max-width: 280px;
  margin: 0 auto;
}

.btn-result {
  justify-content: center;
  padding: 12px 18px;
  border-radius: var(--pl-radius-md);
}

@media (max-width: 420px) {
  .screen-levels .brand-title {
    font-size: 1.4rem;
  }
}

@media (min-width: 480px) {
  .app {
    padding-top: 16px;
  }
}
