/* ================= 基础 ================= */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  color: var(--c-text);
  background: var(--bg);
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: background .6s;
}

/* 章节主题 */
body.theme-1 { --bg: linear-gradient(165deg,#ffe9f0 0%,#fff6e9 60%,#ffeef5 100%); --c-accent:#ff7fa5; --c-accent-dark:#e85d88; --c-text:#6b4a58; --scenery:url(../assets/bg1.svg); }
body.theme-2 { --bg: linear-gradient(165deg,#fff3e0 0%,#ffe9f6 60%,#fff7e6 100%); --c-accent:#ffab5e; --c-accent-dark:#e88b3a; --c-text:#6e5340; --scenery:url(../assets/bg2.svg); }
body.theme-3 { --bg: linear-gradient(165deg,#e0f5ff 0%,#e9fff6 60%,#e6f4ff 100%); --c-accent:#5ec7ff; --c-accent-dark:#3aa4e8; --c-text:#3f5a6e; --scenery:url(../assets/bg3.svg); }
body.theme-4 { --bg: linear-gradient(165deg,#efe9ff 0%,#ffe9fa 60%,#ece6ff 100%); --c-accent:#a98cff; --c-accent-dark:#8a66e8; --c-text:#55486e; --scenery:url(../assets/bg4.svg); }
body.theme-5 { --bg: linear-gradient(165deg,#e9ffe9 0%,#fdffe6 60%,#eaffef 100%); --c-accent:#6fd66f; --c-accent-dark:#4cb84c; --c-text:#3f6e46; --scenery:url(../assets/bg5.svg); }

/* 手绘场景背景（章节切换自动换景） */
body::after {
  content: '';
  position: fixed; left: 0; right: 0; bottom: 0; height: 32vh;
  background: var(--scenery) bottom center / cover no-repeat;
  pointer-events: none; z-index: 0;
  transition: opacity .5s;
}

#app {
  max-width: 560px; height: 100vh; height: 100dvh;
  margin: 0 auto; position: relative; overflow: hidden;
  display: flex; flex-direction: column;
  z-index: 1;
}

.scene { display: none; flex: 1; flex-direction: column; align-items: center; min-height: 0; }
.scene.active { display: flex; }
.scroll-area { flex: 1; overflow-y: auto; width: 100%; padding: 12px 14px 30px; }

/* ================= 通用按钮 ================= */
button { font-family: inherit; color: inherit; cursor: pointer; border: none; background: none; }

.big-btn {
  font-size: 22px; font-weight: 800; color: #fff;
  padding: 15px 52px; border-radius: 999px;
  background: linear-gradient(180deg, var(--c-accent), var(--c-accent-dark));
  box-shadow: 0 6px 0 rgba(0,0,0,.14), 0 10px 24px rgba(0,0,0,.12), inset 0 2px 2px rgba(255,255,255,.5);
  transition: transform .12s, box-shadow .12s;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.14); }

.mid-btn {
  font-size: 15px; font-weight: 700;
  padding: 10px 16px; border-radius: 999px;
  background: rgba(255,255,255,.85);
  box-shadow: 0 4px 0 rgba(0,0,0,.08);
  transition: transform .12s, box-shadow .12s;
}
.mid-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.08); }

.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  font-size: 19px; font-weight: 800;
  background: rgba(255,255,255,.85);
  box-shadow: 0 3px 0 rgba(0,0,0,.08);
  transition: transform .12s;
}
.icon-btn:active { transform: translateY(2px); }

.coin-chip {
  background: rgba(255,255,255,.85); border-radius: 999px;
  padding: 7px 14px; font-weight: 800; font-size: 15px;
  box-shadow: 0 3px 0 rgba(0,0,0,.08);
  white-space: nowrap;
}

/* ================= 首页 ================= */
#scene-home { justify-content: center; gap: 22px; position: relative; }

.home-hall-link:not([hidden]) {
  position: absolute;
  top: 12px;
  left: 14px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(255,255,255,.82);
  color: var(--c-text);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}
.home-hall-link:hover { background: white; }
.home-hall-link:focus-visible { outline: 2px solid var(--c-accent-dark); outline-offset: 3px; }

.home-deco { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.home-deco span {
  position: absolute; left: var(--fx); bottom: -40px; font-size: 26px; opacity: .55;
  animation: floatUpSlow 9s linear infinite; animation-delay: var(--fd);
}
@keyframes floatUpSlow {
  0% { transform: translateY(0) rotate(0deg); opacity: 0; }
  10% { opacity: .55; }
  90% { opacity: .4; }
  100% { transform: translateY(-105vh) rotate(40deg); opacity: 0; }
}

.game-title { display: flex; gap: 2px; margin: 0; z-index: 1; }
.game-title span {
  font-size: 42px; font-weight: 900; color: var(--c-accent-dark);
  text-shadow: 0 3px 0 #fff, 0 6px 10px rgba(0,0,0,.12);
  animation: titleBounce 2.2s ease-in-out infinite;
  animation-delay: calc(var(--i) * .12s);
  display: inline-block;
}
@keyframes titleBounce {
  0%, 100% { transform: translateY(0) rotate(0); }
  30% { transform: translateY(-10px) rotate(-4deg); }
  50% { transform: translateY(0) rotate(0); }
}

.home-mascot {
  z-index: 1; filter: drop-shadow(0 8px 10px rgba(0,0,0,.14));
  animation: mascotWiggle 3s ease-in-out infinite;
  cursor: pointer; line-height: 0;
}
.home-mascot.squish { animation: mascotSquish .45s cubic-bezier(.4,1.8,.4,1); }
@keyframes mascotSquish {
  0% { transform: scale(1,1); }
  35% { transform: scale(1.15,.82); }
  70% { transform: scale(.92,1.1); }
  100% { transform: scale(1,1); }
}
.home-mascot .cat-eyes { animation: catBlink 4.6s infinite; transform-origin: center 74px; }
@keyframes catBlink {
  0%, 93%, 100% { transform: scaleY(1); }
  95.5% { transform: scaleY(.08); }
}
@keyframes mascotWiggle {
  0%,100% { transform: rotate(-4deg) scale(1); }
  50% { transform: rotate(4deg) scale(1.06); }
}

.home-row { display: flex; gap: 10px; z-index: 1; flex-wrap: wrap; justify-content: center; }
.daily-btn {
  background: linear-gradient(180deg,#ffe08a,#f7b733);
  color: #7a5200; font-size: 16px; padding: 11px 26px;
  box-shadow: 0 4px 0 rgba(160,105,0,.35);
  z-index: 1;
}
.home-bottom { display: flex; gap: 12px; align-items: center; z-index: 1; }

/* ================= 场景头部 ================= */
.scene-header {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 14px 14px 6px;
}
.scene-header h2 { flex: 1; margin: 0; font-size: 21px; font-weight: 900; }

/* ================= 选关 ================= */
.chapter-card {
  background: rgba(255,255,255,.72); border-radius: 24px;
  padding: 16px; margin-bottom: 16px;
  box-shadow: 0 5px 0 rgba(0,0,0,.06);
}
.chapter-card.locked { opacity: .55; filter: grayscale(.6); }
.chapter-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.chapter-head .ch-icon { font-size: 30px; }
.chapter-head .ch-name { font-size: 18px; font-weight: 900; }
.chapter-head .ch-progress { margin-left: auto; font-size: 13px; font-weight: 700; opacity: .7; }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.level-btn {
  aspect-ratio: 1; border-radius: 18px; position: relative;
  font-size: 17px; font-weight: 900;
  background: #fff; box-shadow: 0 4px 0 rgba(0,0,0,.1);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  transition: transform .12s;
}
.level-btn:active { transform: translateY(2px); }
.level-btn.locked { color: #bbb; background: #f1eef0; box-shadow: 0 4px 0 rgba(0,0,0,.05); }
.level-btn.current {
  color: #fff; background: linear-gradient(180deg,var(--c-accent),var(--c-accent-dark));
  animation: pulseSoft 1.6s ease-in-out infinite;
}
@keyframes pulseSoft { 0%,100% { transform: scale(1); } 50% { transform: scale(1.07); } }
.level-btn .lv-stars { font-size: 9px; letter-spacing: -1px; line-height: 1; margin-top: 2px; }

/* ================= 图鉴 ================= */
.gallery-chapter { background: rgba(255,255,255,.72); border-radius: 24px; padding: 16px; margin-bottom: 16px; box-shadow: 0 5px 0 rgba(0,0,0,.06); }
.gallery-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-top: 10px; }
.gallery-cell {
  aspect-ratio: 1; border-radius: 14px; background: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 24px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,.06);
}
.gallery-cell.locked { filter: grayscale(1); opacity: .35; font-size: 18px; }
.gallery-cell.unlocked { animation: popIn .4s cubic-bezier(.5,1.8,.4,1); }
.gallery-cell.shiny {
  position: relative;
  background: linear-gradient(160deg, #fff6d8, #ffe9a8);
  box-shadow: inset 0 2px 4px rgba(0,0,0,.06), 0 0 10px rgba(255,201,58,.65);
  animation: shinyGlow 2s ease-in-out infinite;
}
@keyframes shinyGlow {
  0%,100% { box-shadow: inset 0 2px 4px rgba(0,0,0,.06), 0 0 6px rgba(255,201,58,.45); }
  50% { box-shadow: inset 0 2px 4px rgba(0,0,0,.06), 0 0 14px rgba(255,201,58,.9); }
}
.gallery-cell .shiny-mark { position: absolute; top: -5px; right: -4px; font-size: 12px; }

/* ================= 成就 ================= */
.achv-row {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255,255,255,.72); border-radius: 20px;
  padding: 12px 16px; margin-bottom: 10px;
  box-shadow: 0 4px 0 rgba(0,0,0,.06);
}
.achv-row.locked { opacity: .5; filter: grayscale(.8); }
.achv-row .a-icon { font-size: 30px; }
.achv-row .a-name { font-weight: 900; font-size: 15px; }
.achv-row .a-desc { font-size: 12px; opacity: .7; }
.achv-row .a-done { margin-left: auto; font-size: 20px; }

/* ================= 游戏HUD ================= */
.game-hud {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 10px 12px 2px;
}
.game-hud .icon-btn { width: 36px; height: 36px; font-size: 15px; flex: none; }
.game-hud .coin-chip { padding: 5px 10px; font-size: 13px; flex: none; }
.hud-mid { flex: 1; text-align: center; min-width: 0; }
.hud-level { font-size: 16px; font-weight: 900; white-space: nowrap; }
.hud-pairs { font-size: 12px; opacity: .7; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-pairs.urgent { color: #a32253; opacity: 1; }
.game-brief {
  display: grid; gap: 3px; width: calc(100% - 24px); padding: 8px 12px; margin-top: 5px;
  background: rgba(255,255,255,.7); border-radius: 12px;
  font-size: 12px; line-height: 1.4;
}
.game-brief strong { font-size: 13px; font-weight: 900; }
.game-tools { display: flex; gap: 8px; width: 100%; padding: 0 14px; justify-content: center; }
.game-tools button {
  min-height: 37px; border-radius: 12px; background: rgba(255,255,255,.87);
  font-size: 13px; font-weight: 800; padding: 6px 12px;
}
.game-tools button:disabled { opacity: .62; cursor: default; }
.game-tools .resonance-btn { display: flex; gap: 8px; align-items: center; justify-content: space-between; min-width: 126px; }
.resonance-btn.ready { background: #fff0b7; color: #61410b; box-shadow: inset 0 0 0 2px #e8ad41; }
.resonance-btn[aria-pressed="true"] { background: #ffe192; box-shadow: inset 0 0 0 2px #a8651f; }
.sudoku-btn.urgent { box-shadow: inset 0 0 0 2px var(--c-accent); }
.game-status { padding: 4px 14px 0; min-height: 20px; font-size: 12px; line-height: 1.25; text-align: center; }
.puzzle-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; align-content: start; }
.puzzle-card {
  display: grid; align-content: start; gap: 4px; padding: 12px; text-align: left; border-radius: 15px;
  background: rgba(255,255,255,.85); box-shadow: 0 3px 0 rgba(0,0,0,.07);
}
.puzzle-card > span { font-size: 12px; }
.puzzle-card-heading {
  display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 20px;
  line-height: 1.3;
}
.puzzle-card-heading strong { font-size: 14px; }
.puzzle-clear-badge {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; flex: none;
  height: 20px; padding: 0 6px; border: 1px solid #f4cadd; border-radius: 999px;
  background: #fff0f6; color: #a83e69; font-size: 10px; font-weight: 800; white-space: nowrap;
}
.puzzle-clear-paw {
  width: 14px; height: 14px; flex: none; transform: rotate(-12deg);
  background:
    radial-gradient(ellipse, currentColor 64%, transparent 72%) 50% 91% / 9px 7px,
    radial-gradient(ellipse, currentColor 60%, transparent 73%) 0 39% / 4px 5px,
    radial-gradient(ellipse, currentColor 60%, transparent 73%) 32% 5% / 4px 5px,
    radial-gradient(ellipse, currentColor 60%, transparent 73%) 68% 5% / 4px 5px,
    radial-gradient(ellipse, currentColor 60%, transparent 73%) 100% 39% / 4px 5px;
  background-repeat: no-repeat;
}
@media (max-width: 400px) {
  .puzzle-clear-badge { width: 20px; padding: 0; }
  .puzzle-clear-label {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%);
  }
}
.level-btn.fixed-puzzle { box-shadow: inset 0 0 0 2px var(--c-accent); }
.tile.resonance-target .tile-inner { outline: 2px solid #bc781f; outline-offset: -2px; }

.timer-wrap { width: 100%; display: flex; align-items: center; gap: 8px; padding: 4px 16px 2px; }
.timer-wrap.hidden { display: none; }
.timer-icon { font-size: 16px; }
.timer-track {
  flex: 1; height: 14px; border-radius: 999px; background: rgba(255,255,255,.7);
  overflow: hidden; box-shadow: inset 0 2px 3px rgba(0,0,0,.08);
}
.timer-bar {
  height: 100%; width: 100%; border-radius: 999px;
  background: linear-gradient(90deg, #7be3a0, #ffd66e, var(--c-accent));
  transition: width .5s linear;
}
.timer-wrap.low .timer-bar { background: #ff6e87; animation: barBlink .5s linear infinite alternate; }
@keyframes barBlink { from { opacity: 1; } to { opacity: .55; } }
.timer-text { font-size: 13px; font-weight: 800; min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; }

/* ================= 棋盘 ================= */
.board-wrap { flex: 1; display: flex; align-items: center; justify-content: center; width: 100%; position: relative; min-height: 0; }
.board {
  position: relative;
  background:
    radial-gradient(circle, rgba(255,255,255,.5) 16%, transparent 17%) 0 0 / 26px 26px,
    rgba(255,255,255,.4);
  border-radius: 26px;
  box-shadow: 0 6px 0 rgba(0,0,0,.05), inset 0 2px 6px rgba(255,255,255,.65);
}
.board.shake { animation: boardShake .3s; }
@keyframes boardShake {
  0%,100% { transform: translate(0,0); }
  25% { transform: translate(-3px,2px); } 50% { transform: translate(3px,-2px); } 75% { transform: translate(-2px,-2px); }
}
.line-layer { position: absolute; inset: 0; pointer-events: none; z-index: 5; overflow: visible; }

/* --- 方块 --- */
.tile {
  position: absolute; padding: 0; background: none;
  width: var(--ts); height: var(--ts);
  transition: left .3s cubic-bezier(.4,1.4,.5,1), top .3s cubic-bezier(.4,1.4,.5,1);
  z-index: 1;
}
.tile-inner {
  width: calc(100% - 5px); height: calc(100% - 5px); margin: auto;
  border-radius: 24%;
  /* 贴纸质感：糖果底色上一个白色圆形徽章 */
  background:
    radial-gradient(circle at 50% 54%, rgba(255,255,255,.95) 0 35%, rgba(255,255,255,0) 37%),
    var(--tile-bg, #fff);
  box-shadow: 0 3px 0 var(--tile-edge, rgba(0,0,0,.14)), inset 0 2px 3px rgba(255,255,255,.85);
  display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
  animation: breathe 3.4s ease-in-out infinite;
  animation-delay: var(--bd, 0s);
}
.tile-face { font-size: calc(var(--ts) * .52); line-height: 1; filter: drop-shadow(0 1px 1px rgba(0,0,0,.15)); }
/* 顶部高光 */
.tile-inner::after {
  content: ''; position: absolute; top: 7%; left: 10%; width: 36%; height: 17%;
  background: rgba(255,255,255,.7); border-radius: 50%; transform: rotate(-16deg);
  pointer-events: none;
}
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.035); } }

/* 闪光扫过 */
.tile.shimmer .tile-inner::before {
  content: ''; position: absolute; top: -30%; left: -80%; width: 45%; height: 160%;
  background: linear-gradient(105deg, transparent, rgba(255,255,255,.95), transparent);
  animation: shimmerSweep .9s ease; pointer-events: none;
}
@keyframes shimmerSweep { to { left: 140%; } }

/* 选中 */
.tile.selected { z-index: 3; }
.tile.selected .tile-inner {
  animation: pickWobble .55s ease-in-out infinite;
  box-shadow: 0 3px 0 var(--tile-edge, rgba(0,0,0,.14)),
              0 0 0 3px #fff, 0 0 0 6px var(--c-accent), 0 0 16px var(--c-accent);
}
@keyframes pickWobble {
  0%,100% { transform: scale(1.08) rotate(-3deg); }
  50% { transform: scale(1.12) rotate(3deg); }
}

/* 提示 */
.tile.hinted .tile-inner {
  animation: hintPulse .7s ease-in-out infinite;
  box-shadow: 0 3px 0 var(--tile-edge, rgba(0,0,0,.14)), 0 0 0 4px #ffd66e, 0 0 18px #ffc93a;
}
@keyframes hintPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.1); } }

/* 消除 */
.tile.matched { z-index: 4; pointer-events: none; }
.tile.matched .tile-inner { animation: matchedPop .42s ease forwards; }
@keyframes matchedPop {
  0% { transform: scale(1); filter: brightness(1); }
  40% { transform: scale(1.35); filter: brightness(2.2); opacity: 1; }
  100% { transform: scale(.2); filter: brightness(3); opacity: 0; }
}

/* 配错 */
.tile.wrong .tile-inner { animation: wrongShake .35s ease; box-shadow: 0 3px 0 var(--tile-edge), 0 0 0 3px #ff8b8b; }
@keyframes wrongShake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-4px) rotate(-3deg); } 75% { transform: translateX(4px) rotate(3deg); }
}

/* 冰冻 */
.tile.frozen .tile-inner { animation: none; }
.tile .ice-cover {
  position: absolute; inset: 0; border-radius: 24%;
  background: linear-gradient(160deg, rgba(190,230,255,.85), rgba(150,200,255,.65));
  display: none; align-items: center; justify-content: center;
  font-size: calc(var(--ts) * .38); z-index: 2;
  box-shadow: inset 0 0 8px rgba(255,255,255,.9);
}
.tile.frozen .ice-cover { display: flex; }
.tile.unfreezing .ice-cover { animation: iceBreak .4s ease forwards; }
@keyframes iceBreak {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* 特殊方块：金色发光 */
.tile.sp .tile-inner {
  background:
    radial-gradient(circle at 50% 54%, rgba(255,255,255,.95) 0 35%, rgba(255,255,255,0) 37%),
    linear-gradient(160deg, #ffe9a8, #ffc95e);
  animation: spGlow 1.6s ease-in-out infinite;
}
@keyframes spGlow {
  0%,100% { box-shadow: 0 3px 0 rgba(160,105,0,.35), 0 0 8px rgba(255,200,80,.7), inset 0 2px 3px rgba(255,255,255,.85); transform: scale(1); }
  50% { box-shadow: 0 3px 0 rgba(160,105,0,.35), 0 0 18px rgba(255,200,80,1), inset 0 2px 3px rgba(255,255,255,.85); transform: scale(1.04); }
}

/* 迷雾 */
.tile .fog-cover {
  position: absolute; inset: 0; border-radius: 24%;
  background: linear-gradient(160deg, rgba(235,242,250,.96), rgba(205,218,235,.94));
  display: none; align-items: center; justify-content: center;
  font-size: calc(var(--ts) * .42); z-index: 2;
  box-shadow: inset 0 0 10px rgba(255,255,255,.95);
}
.tile.fogged .fog-cover { display: flex; }
.tile.fogged .tile-inner { animation: none; }
.tile.unfogging .fog-cover { animation: iceBreak .4s ease forwards; }

/* 动物笼子 */
.tile.animal .tile-inner {
  background:
    radial-gradient(circle at 50% 54%, rgba(255,255,255,.95) 0 35%, rgba(255,255,255,0) 37%),
    linear-gradient(160deg, #ffe9d1, #f5cba0);
}
.tile .cage-cover {
  position: absolute; inset: 0; border-radius: 24%; z-index: 2; pointer-events: none;
  background: repeating-linear-gradient(90deg, rgba(130,95,60,.5) 0 3px, transparent 3px 22%);
  box-shadow: inset 0 0 0 3px rgba(130,95,60,.55);
}
.tile.freed { z-index: 30; pointer-events: none; }
.tile.freed .cage-cover { animation: iceBreak .3s ease forwards; }
.tile.freed .tile-inner { animation: freedFly .8s ease forwards; }
@keyframes freedFly {
  0% { transform: scale(1); opacity: 1; }
  40% { transform: scale(1.4) translateY(-14px); opacity: 1; }
  100% { transform: scale(1.1) translateY(-72px); opacity: 0; }
}

/* 传送门 */
.portal-cell {
  position: absolute; width: var(--ts); height: var(--ts);
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--ts) * .6); pointer-events: none;
  animation: portalSpin 3s linear infinite;
  filter: drop-shadow(0 0 6px rgba(120,160,255,.8));
}
@keyframes portalSpin { to { transform: rotate(360deg); } }

/* 捣蛋鼠交换 */
.tile.swapping .tile-inner { animation: swapSpin .55s cubic-bezier(.4,1.5,.4,1); }
@keyframes swapSpin {
  0% { transform: scale(1) rotate(0); }
  50% { transform: scale(.55) rotate(180deg); }
  100% { transform: scale(1) rotate(360deg); }
}

/* FEVER 模式：棋盘彩虹光晕 */
.board.fever { animation: feverGlow 1.2s linear infinite; }
@keyframes feverGlow {
  0%   { box-shadow: 0 6px 0 rgba(0,0,0,.05), 0 0 26px 6px rgba(255,127,165,.55); }
  25%  { box-shadow: 0 6px 0 rgba(0,0,0,.05), 0 0 26px 6px rgba(255,214,110,.55); }
  50%  { box-shadow: 0 6px 0 rgba(0,0,0,.05), 0 0 26px 6px rgba(123,227,160,.55); }
  75%  { box-shadow: 0 6px 0 rgba(0,0,0,.05), 0 0 26px 6px rgba(94,199,255,.55); }
  100% { box-shadow: 0 6px 0 rgba(0,0,0,.05), 0 0 26px 6px rgba(255,127,165,.55); }
}

/* 猫咪徽章 & 养成面板 */
.home-mascot { position: relative; }
.pet-badge {
  position: absolute; right: -6px; top: 4px; z-index: 2;
  background: linear-gradient(180deg,#ffd66e,#f7b733); color: #7a5200;
  font-size: 12px; font-weight: 900; padding: 3px 9px; border-radius: 999px;
  box-shadow: 0 2px 0 rgba(160,105,0,.35);
}
.home-mascot svg { transition: transform .4s cubic-bezier(.4,1.6,.4,1); }
.pet-hat {
  position: absolute; top: -16px; left: 50%;
  transform: translateX(-50%) rotate(-10deg);
  font-size: 36px; z-index: 3; pointer-events: none;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,.18));
}

/* 装扮小铺 */
.shop-title { font-size: 15px; font-weight: 900; text-align: left; margin: 6px 0 2px; }
.shop-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0 12px; }
.shop-item {
  background: #fff; border-radius: 16px; padding: 10px 4px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  box-shadow: 0 3px 0 rgba(0,0,0,.08);
  transition: transform .12s;
}
.shop-item:active { transform: translateY(2px); }
.shop-item .si-icon { font-size: 26px; }
.shop-item .si-name { font-size: 12px; font-weight: 800; }
.shop-item .si-price { font-size: 11px; opacity: .7; font-weight: 700; }
.shop-item.equipped { box-shadow: 0 3px 0 rgba(0,0,0,.08), 0 0 0 3px var(--c-accent); }
.pet-panel { margin-bottom: 14px; }
.pet-passive {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border-radius: 14px; padding: 9px 14px; margin-bottom: 7px;
  font-size: 14px; font-weight: 700; opacity: .45; text-align: left;
}
.pet-passive.on { opacity: 1; box-shadow: 0 2px 0 rgba(0,0,0,.06); }
.pet-passive .pp-txt { flex: 1; }
.pet-passive .pp-lv { font-size: 12px; opacity: .8; }

.tower-btn {
  background: linear-gradient(180deg,#c9b8ff,#9a7ff0); color: #fff;
  font-size: 16px; padding: 11px 22px;
  box-shadow: 0 4px 0 rgba(90,60,160,.4);
  z-index: 1;
}

/* ================= 粒子 / 特效 ================= */
.particle {
  position: absolute; left: var(--x); top: var(--y);
  font-size: var(--ps, 15px); pointer-events: none; z-index: 20;
  animation: particleFly var(--pd, .75s) ease-out forwards;
}
@keyframes particleFly {
  0% { transform: translate(0,0) scale(1) rotate(0); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(.2) rotate(var(--rot)); opacity: 0; }
}

.float-text {
  position: absolute; left: var(--x); top: var(--y);
  font-size: 17px; font-weight: 900; color: var(--c-accent-dark);
  text-shadow: 0 2px 0 #fff; pointer-events: none; z-index: 21;
  animation: floatUp .9s ease-out forwards; white-space: nowrap;
  transform: translateX(-50%);
}
@keyframes floatUp {
  0% { transform: translate(-50%, 0) scale(.6); opacity: 0; }
  25% { transform: translate(-50%, -12px) scale(1.15); opacity: 1; }
  100% { transform: translate(-50%, -46px) scale(1); opacity: 0; }
}

.combo-pop {
  position: absolute; left: 50%; top: 38%; transform: translate(-50%,-50%);
  font-size: 34px; font-weight: 900; color: #fff; pointer-events: none; z-index: 22;
  text-shadow: 0 0 12px var(--c-accent), 0 3px 0 var(--c-accent-dark);
  opacity: 0;
}
.combo-pop.show { animation: comboPop .8s cubic-bezier(.4,1.8,.4,1); }
@keyframes comboPop {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(.3) rotate(-8deg); }
  30% { opacity: 1; transform: translate(-50%,-50%) scale(1.25) rotate(3deg); }
  60% { transform: translate(-50%,-50%) scale(1) rotate(0); opacity: 1; }
  100% { opacity: 0; transform: translate(-50%,-60%) scale(1); }
}

/* 彩带 */
.confetti {
  position: absolute; top: -20px; left: var(--cx);
  width: 9px; height: 15px; border-radius: 3px; background: var(--cc);
  pointer-events: none; z-index: 60;
  animation: confettiFall var(--cd) linear forwards;
}
@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0) rotateY(0); opacity: 1; }
  100% { transform: translateY(110vh) rotate(560deg) rotateY(720deg); opacity: .7; }
}

/* ================= 道具栏 ================= */
.props { display: flex; gap: 10px; padding: 7px 14px 14px; width: 100%; justify-content: center; }
.prop-btn {
  flex: 1; max-width: 130px;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  font-size: 21px; padding: 8px 0 6px; border-radius: 20px;
  background: rgba(255,255,255,.85);
  box-shadow: 0 4px 0 rgba(0,0,0,.1);
  transition: transform .12s, box-shadow .12s;
}
.prop-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.1); }
.prop-btn:disabled { opacity: .4; }
.prop-btn.active {
  box-shadow: 0 4px 0 rgba(0,0,0,.1), 0 0 0 3px var(--c-accent), 0 0 14px var(--c-accent);
  animation: pulseSoft 1s ease-in-out infinite;
}
.prop-btn i { font-style: normal; font-size: 12px; font-weight: 800; }
.prop-btn .cost { font-style: normal; font-size: 10px; font-weight: 700; opacity: .65; }

/* ================= 弹窗 ================= */
.modal-root {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(90,60,80,.45); backdrop-filter: blur(3px);
  padding: 20px;
}
.modal-root.hidden { display: none; }
.modal-card {
  background: linear-gradient(180deg,#fffdfa,#fff2f6);
  border-radius: 30px; padding: 24px 22px;
  width: 100%; max-width: 400px; max-height: 88vh; overflow-y: auto;
  box-shadow: 0 8px 0 rgba(0,0,0,.15), 0 20px 50px rgba(0,0,0,.25);
  text-align: center; position: relative;
  animation: modalPop .45s cubic-bezier(.4,1.6,.4,1);
}
@keyframes modalPop {
  0% { transform: scale(.6) translateY(30px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}
.modal-emoji { font-size: 52px; margin-bottom: 6px; animation: mascotWiggle 2.5s ease-in-out infinite; display: inline-block; }
.modal-title { font-size: 22px; font-weight: 900; margin: 4px 0 8px; }
.modal-desc { font-size: 14px; opacity: .75; line-height: 1.6; margin-bottom: 16px; }
.modal-btns { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.modal-btn {
  width: 100%; max-width: 260px; padding: 12px; border-radius: 999px;
  font-size: 16px; font-weight: 800; color: #fff;
  background: linear-gradient(180deg,var(--c-accent),var(--c-accent-dark));
  box-shadow: 0 4px 0 rgba(0,0,0,.15);
  transition: transform .12s;
}
.modal-btn:active { transform: translateY(3px); }
.modal-btn.ghost { background: #fff; color: var(--c-text); box-shadow: 0 4px 0 rgba(0,0,0,.08); }
.modal-btn.danger { background: linear-gradient(180deg,#ff8a8a,#e85454); }
.modal-btn:disabled { opacity: .45; }

/* 胜利星星 */
.win-stars { display: flex; justify-content: center; gap: 8px; margin: 8px 0 4px; height: 62px; }
.win-star { font-size: 48px; opacity: 0; filter: grayscale(1) opacity(.3); }
.win-star.earned { animation: starDrop .5s cubic-bezier(.4,1.6,.5,1) forwards; animation-delay: var(--sd); filter: none; }
.win-star.dim { opacity: .25; filter: grayscale(1); }
@keyframes starDrop {
  0% { opacity: 0; transform: translateY(-70px) scale(2.2) rotate(-30deg); }
  60% { opacity: 1; transform: translateY(6px) scale(.95) rotate(5deg); }
  100% { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
}
.win-reward { font-size: 16px; font-weight: 800; margin-bottom: 14px; }

/* ================= 数独 ================= */
.sudoku-grid {
  display: grid; gap: 3px; margin: 10px auto; width: fit-content;
  background: #e8d5de; padding: 5px; border-radius: 16px;
}
.sudoku-cell {
  width: var(--scs, 48px); height: var(--scs, 48px); border-radius: 10px;
  background: #fff; display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--scs, 48px) * .55);
  transition: transform .1s, box-shadow .15s;
}
.sudoku-cell.given { background: #ffeef4; }
.sudoku-cell.sel { box-shadow: 0 0 0 3px var(--c-accent); transform: scale(1.06); z-index: 1; }
.sudoku-cell.conflict { background: #ffd9d9; animation: wrongShake .35s; }
.sudoku-cell.boxline-r { margin-right: 4px; }
.sudoku-cell.boxline-b { margin-bottom: 4px; }
.sudoku-cell.celebrate { animation: cellPop .5s cubic-bezier(.4,1.8,.4,1); animation-delay: var(--cd2); }
@keyframes cellPop { 50% { transform: scale(1.25); background: #fff4b8; } }
.sudoku-palette { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin: 12px 0 4px; }
.sudoku-key {
  width: 46px; height: 46px; border-radius: 14px; font-size: 24px;
  background: #fff; box-shadow: 0 3px 0 rgba(0,0,0,.1);
  transition: transform .1s;
}
.sudoku-key:active { transform: translateY(2px); }
.sudoku-key.sel { box-shadow: 0 3px 0 rgba(0,0,0,.1), 0 0 0 3px var(--c-accent); }
.sudoku-timer { font-size: 14px; font-weight: 800; margin-top: 2px; }
.sudoku-timer.low { color: #ff5470; animation: barBlink .5s linear infinite alternate; }

/* 设置面板 */
.settings-panel { margin-bottom: 12px; }
.settings-row {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border-radius: 16px; padding: 12px 16px; margin-bottom: 8px;
  box-shadow: 0 2px 0 rgba(0,0,0,.06);
}
.settings-row .sr-icon { font-size: 20px; }
.settings-row .sr-label { flex: 1; text-align: left; font-size: 15px; font-weight: 800; }
.set-toggle {
  min-width: 64px; padding: 7px 14px; border-radius: 999px;
  font-size: 13px; font-weight: 800; color: #9a8a92;
  background: #efe8ec; transition: all .15s;
}
.set-toggle.on {
  color: #fff;
  background: linear-gradient(180deg, var(--c-accent), var(--c-accent-dark));
  box-shadow: 0 2px 0 rgba(0,0,0,.12);
}

/* 存档码 */
.save-ta {
  width: 100%; height: 92px; border-radius: 14px;
  border: 2px solid #f0dee6; padding: 10px; font-size: 11px;
  font-family: monospace; resize: none; background: #fff;
  color: var(--c-text); user-select: text; -webkit-user-select: text;
}
.save-ta:focus { outline: none; border-color: var(--c-accent); }

/* 分享卡 */
.share-img { width: 100%; border-radius: 18px; box-shadow: 0 8px 24px rgba(0,0,0,.18); margin-bottom: 6px; }

/* ================= Toast ================= */
#toast-root { position: fixed; bottom: 90px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 200; pointer-events: none; }
.toast {
  background: rgba(70,45,60,.88); color: #fff; font-size: 14px; font-weight: 700;
  padding: 10px 20px; border-radius: 999px;
  animation: toastIn .35s cubic-bezier(.4,1.6,.4,1), toastOut .3s ease 2.4s forwards;
  box-shadow: 0 6px 18px rgba(0,0,0,.25);
}
@keyframes toastIn { from { transform: translateY(20px) scale(.8); opacity: 0; } }
@keyframes toastOut { to { transform: translateY(10px); opacity: 0; } }

@keyframes popIn { 0% { transform: scale(0); } 70% { transform: scale(1.2); } 100% { transform: scale(1); } }

/* 小屏适配 */
@media (max-height: 640px) {
  .home-mascot { font-size: 60px; }
  .game-title span { font-size: 32px; }
}
