:root {
  --ink: #4a3425;
  --ink-soft: #73583f;
  --paper: #f7ecd8;
  --paper-deep: #ead8b7;
  --wood: #a86f49;
  --wood-dark: #70452b;
  --wood-deep: #5b3a25;
  --green: #738d4f;
  --green-dark: #4f6634;
  --green-pale: #dce6c3;
  --gold: #c49a48;
  --gold-pale: #f0d99c;
  --red: #a8443b;
  --shadow: 0 12px 28px rgba(63, 42, 24, 0.2);
  --shadow-soft: 0 4px 12px rgba(63, 42, 24, 0.14);
  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
}

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

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font-family: "STKaiti", "KaiTi", "FangSong", "Noto Serif SC", "Songti SC", serif;
  background: #6e4b31 url("背景图.png") center / cover no-repeat fixed;
  overscroll-behavior: none;
  user-select: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(255, 220, 130, 0.85);
  outline-offset: 2px;
}

.app {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 46px rgba(0, 0, 0, 0.32);
}

.screen {
  display: none;
  position: relative;
  z-index: 1;
  overflow-y: auto;
}

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

/* ---------- 首页 ---------- */
#home-screen {
  min-height: 100vh;
  min-height: 100dvh;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 26px;
  padding: max(30px, env(safe-area-inset-top)) 24px max(34px, env(safe-area-inset-bottom));
  text-align: center;
  background:
    linear-gradient(180deg, rgba(72, 45, 28, 0.06), rgba(72, 45, 28, 0.42)),
    radial-gradient(circle at 50% 36%, rgba(255, 239, 206, 0.18), rgba(63, 37, 21, 0.68));
}

.home-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.home-seal {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  color: #fff7e7;
  font-size: 42px;
  line-height: 1;
  background: linear-gradient(145deg, #b43f36, #7e2b27);
  border: 3px solid rgba(255, 225, 178, 0.8);
  border-radius: 20px 14px 18px 12px;
  box-shadow: 0 8px 22px rgba(91, 32, 24, 0.36);
  transform: rotate(-3deg);
}

.home-kicker {
  margin: 22px 0 8px;
  color: #f5e2bd;
  font-size: 14px;
  letter-spacing: 0.32em;
}

.home-title {
  margin: 0;
  color: #fff8e9;
  font-size: clamp(48px, 16vw, 70px);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-shadow: 0 5px 0 rgba(79, 41, 24, 0.28), 0 12px 28px rgba(0, 0, 0, 0.3);
}

.home-subtitle {
  margin: 12px 0 0;
  color: #f9e5bb;
  font-size: 20px;
  letter-spacing: 0.22em;
  text-shadow: 0 2px 8px rgba(65, 38, 21, 0.35);
}

.home-menu {
  width: min(100%, 320px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 8px;
}

.btn {
  min-height: 50px;
  padding: 0 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  font-size: 18px;
  letter-spacing: 0.08em;
  box-shadow: var(--shadow-soft);
  transition: transform 0.18s ease, filter 0.18s ease, box-shadow 0.18s ease;
}

.btn:active {
  transform: translateY(2px) scale(0.98);
  filter: brightness(0.95);
}

.btn-primary {
  color: #fff9ec;
  background: linear-gradient(135deg, #8aa457, #5f7a38);
  border: 1px solid rgba(255, 242, 204, 0.55);
  box-shadow: 0 10px 22px rgba(56, 75, 34, 0.32);
}

.btn-paper {
  color: var(--ink);
  background: linear-gradient(180deg, #fbf0d7, #ebd5ae);
  border: 1px solid rgba(122, 77, 43, 0.22);
}

.round-icon {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  color: var(--ink);
  background: rgba(250, 235, 205, 0.9);
  border: 1px solid rgba(112, 69, 43, 0.24);
  box-shadow: var(--shadow-soft);
}

.round-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.home-settings {
  position: absolute;
  top: max(20px, env(safe-area-inset-top));
  right: 20px;
}

.home-footnote {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: max(18px, env(safe-area-inset-bottom));
  margin: 0;
  color: rgba(255, 237, 207, 0.78);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-align: center;
  text-shadow: 0 1px 4px rgba(39, 23, 12, 0.3);
}

/* ---------- 游戏主界面 ---------- */
#game-screen {
  min-height: 100vh;
  min-height: 100dvh;
  flex-direction: column;
  gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  background:
    linear-gradient(180deg, rgba(246, 233, 204, 0.86), rgba(214, 183, 134, 0.94)),
    url("背景图.png") center / cover no-repeat;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: 5px 6px 3px;
}

.game-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.game-brand-seal {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: #fff7e5;
  background: linear-gradient(145deg, #b43f36, #7e2b27);
  border-radius: 12px 10px 13px 9px;
  font-size: 25px;
  transform: rotate(-3deg);
  box-shadow: 0 4px 12px rgba(91, 32, 24, 0.26);
}

.game-brand h2 {
  margin: 0;
  font-size: 21px;
  letter-spacing: 0.08em;
}

.game-brand p {
  margin: 3px 0 0;
  color: var(--ink-soft);
  font-size: 13px;
  letter-spacing: 0.04em;
}

.progress-panel {
  padding: 9px 10px;
  background: rgba(255, 247, 228, 0.66);
  border: 1px solid rgba(122, 77, 43, 0.16);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
}

.progress-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--ink-soft);
  font-size: 13px;
  letter-spacing: 0.02em;
}

.rank-chip {
  padding: 3px 8px;
  color: #7b4a26;
  background: #f3e3be;
  border: 1px solid rgba(139, 93, 45, 0.22);
  border-radius: 999px;
  white-space: nowrap;
  font-size: 12px;
}

.progress-chain {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(112, 69, 43, 0.35) transparent;
  scroll-behavior: smooth;
}

.progress-chain::-webkit-scrollbar {
  height: 5px;
}

.progress-chain::-webkit-scrollbar-thumb {
  background: rgba(112, 69, 43, 0.3);
  border-radius: 999px;
}

.chain-item {
  position: relative;
  flex: 0 0 58px;
  height: 66px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 14px;
  background: rgba(255, 252, 240, 0.82);
  border: 1px solid rgba(112, 69, 43, 0.18);
  box-shadow: 0 3px 8px rgba(72, 45, 28, 0.09);
}

.chain-item img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  pointer-events: none;
}

.chain-item .chain-no {
  font-size: 10px;
  color: var(--ink-soft);
  line-height: 1;
}

.chain-item.is-unlocked {
  border-color: rgba(96, 126, 62, 0.55);
  background: #f9f3dc;
}

.chain-item.is-locked img {
  filter: grayscale(1) brightness(1.35) opacity(0.48);
}

.chain-item .chain-lock {
  position: absolute;
  top: 3px;
  right: 4px;
  color: #8d6c47;
  font-size: 13px;
}

.chain-item.is-current {
  transform: translateY(-2px);
  border: 2px solid var(--gold);
  background: #fff8e5;
  box-shadow: 0 7px 14px rgba(141, 93, 31, 0.18);
}

.chain-item.is-current::after {
  content: "●";
  position: absolute;
  left: 50%;
  bottom: 3px;
  transform: translateX(-50%);
  color: var(--gold);
  font-size: 8px;
}

.board {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 9px;
  padding: 12px;
  background:
    linear-gradient(145deg, rgba(162, 107, 62, 0.98), rgba(105, 62, 37, 0.98)),
    repeating-linear-gradient(45deg, rgba(255, 233, 189, 0.06) 0 2px, transparent 2px 7px);
  border: 5px solid #4f3221;
  border-radius: 26px;
  box-shadow: inset 0 0 0 1px rgba(255, 220, 160, 0.2), 0 12px 26px rgba(57, 34, 20, 0.24);
  touch-action: manipulation;
}

.board::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 20px;
  pointer-events: none;
  background: radial-gradient(circle at 30% 20%, rgba(255, 226, 166, 0.14), transparent 38%);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 17px;
  background: rgba(251, 240, 211, 0.78);
  border: 1px solid rgba(108, 65, 38, 0.18);
  box-shadow: inset 0 2px 5px rgba(255, 255, 255, 0.45), inset 0 -4px 8px rgba(103, 61, 35, 0.09);
  overflow: hidden;
  transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.cell.is-empty {
  background: rgba(241, 221, 185, 0.42);
}

.cell.is-filled {
  background:
    radial-gradient(circle at 50% 35%, rgba(255, 255, 255, 0.55), transparent 54%),
    linear-gradient(180deg, rgba(255, 249, 229, 0.96), rgba(232, 213, 172, 0.94));
}

.cell.is-selected {
  z-index: 2;
  border: 3px solid #e5b94f;
  box-shadow: 0 0 0 3px rgba(235, 186, 70, 0.24), 0 8px 18px rgba(99, 64, 27, 0.22);
  transform: translateY(-2px);
}

.cell.is-merging {
  z-index: 3;
  animation: merge-pop 0.42s ease both;
}

.cell img {
  width: 78%;
  height: 78%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 5px 4px rgba(65, 40, 20, 0.22));
}

.cell .tile-level {
  position: absolute;
  left: 6px;
  bottom: 5px;
  color: rgba(74, 52, 37, 0.72);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.game-footer {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.spawn-area {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.btn-spawn {
  flex: 1 1 auto;
  color: #fff8e8;
  background: linear-gradient(135deg, #7d9a55, #5a7436);
  border: 1px solid rgba(255, 242, 201, 0.46);
}

.spawn-emoji {
  font-size: 23px;
  filter: drop-shadow(0 2px 3px rgba(42, 53, 21, 0.25));
}

.score-box {
  min-width: 92px;
  padding: 5px 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  color: var(--ink);
  background: rgba(255, 247, 226, 0.78);
  border: 1px solid rgba(112, 69, 43, 0.18);
  border-radius: 18px;
  box-shadow: var(--shadow-soft);
  text-align: center;
}

.score-label {
  font-size: 11px;
  color: var(--ink-soft);
}

.score-box strong {
  font-size: 21px;
  line-height: 1.05;
}

.footer-tools {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.footer-tools button {
  min-height: 42px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--ink);
  font-size: 13px;
  background: rgba(251, 240, 211, 0.76);
  border: 1px solid rgba(112, 69, 43, 0.16);
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
  transition: transform 0.15s ease, background 0.2s ease;
}

.footer-tools button:active {
  transform: translateY(2px);
  background: #f2e2bf;
}

.footer-tools button span {
  font-size: 18px;
  line-height: 1;
}

/* ---------- 弹窗通用 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.24s ease, visibility 0.24s ease;
}

.modal.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(54, 34, 20, 0.52);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(100%, 420px);
  max-height: min(86vh, 760px);
  overflow: auto;
  padding: 20px;
  color: var(--ink);
  background:
    radial-gradient(circle at 14% 12%, rgba(255, 255, 255, 0.55), transparent 32%),
    linear-gradient(160deg, #f9efd8, #e9d5ac);
  border: 1px solid rgba(117, 71, 39, 0.24);
  border-radius: 26px;
  box-shadow: 0 22px 50px rgba(45, 26, 14, 0.34);
  transform: translateY(16px) scale(0.98);
  transition: transform 0.24s ease;
}

.modal.is-open .modal-card {
  transform: translateY(0) scale(1);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-eyebrow {
  margin: 0 0 4px;
  color: var(--wood);
  font-size: 12px;
  letter-spacing: 0.18em;
}

.modal-head h3 {
  margin: 0;
  font-size: 27px;
  letter-spacing: 0.06em;
}

.modal-close {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: rgba(255, 249, 234, 0.62);
  border: 1px solid rgba(112, 69, 43, 0.18);
  border-radius: 50%;
  font-size: 27px;
  line-height: 1;
  box-shadow: var(--shadow-soft);
}

/* 图鉴 */
.modal-card-wide {
  width: min(100%, 440px);
}

.encyclopedia-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.ency-tab {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 6px;
  background: rgba(255, 251, 237, 0.62);
  border: 1px solid rgba(112, 69, 43, 0.16);
  border-radius: 14px;
  transition: transform 0.15s ease, border-color 0.2s ease, background 0.2s ease;
}

.ency-tab img {
  width: 76%;
  height: 76%;
  object-fit: contain;
  pointer-events: none;
}

.ency-tab .ency-no {
  position: absolute;
  left: 5px;
  bottom: 4px;
  font-size: 10px;
  color: var(--ink-soft);
}

.ency-tab.is-locked img {
  filter: grayscale(1) brightness(1.4) opacity(0.4);
}

.ency-tab.is-active {
  background: #fff7df;
  border: 2px solid var(--gold);
  transform: translateY(-2px);
}

.encyclopedia-detail {
  min-height: 210px;
  padding: 16px;
  background: rgba(255, 251, 237, 0.7);
  border: 1px solid rgba(112, 69, 43, 0.14);
  border-radius: 18px;
}

.ency-detail-main {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}

.ency-detail-img {
  width: 108px;
  height: 108px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  background: #fff8e7;
  border: 1px solid rgba(112, 69, 43, 0.14);
  border-radius: 20px;
  box-shadow: var(--shadow-soft);
}

.ency-detail-img img {
  width: 82%;
  height: 82%;
  object-fit: contain;
}

.ency-detail-head h4 {
  margin: 0 0 4px;
  font-size: 24px;
}

.ency-detail-head .ency-level {
  color: var(--wood);
  font-size: 13px;
}

.ency-detail-body p {
  margin: 0;
  line-height: 1.7;
  font-size: 15px;
  color: var(--ink-soft);
}

.ency-detail-body .ency-locked {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 120px;
  justify-content: center;
  color: #8e6e4b;
  text-align: center;
  line-height: 1.6;
}

/* 典籍 */
.modal-card-book {
  width: min(100%, 420px);
  max-height: min(88vh, 780px);
  overflow: hidden;
  padding: 18px 20px 20px;
  background:
    linear-gradient(90deg, rgba(92, 57, 32, 0.13), transparent 8% 92%, rgba(92, 57, 32, 0.13)),
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.5), transparent 45%),
    linear-gradient(160deg, #f7ecd1, #e4cfa0);
}

.book-decor {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(90deg, rgba(114, 74, 42, 0.04) 0 1px, transparent 1px 10px);
  mix-blend-mode: multiply;
}

.book-page {
  position: relative;
  z-index: 1;
  height: 350px;
  padding: 20px 17px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(122, 77, 43, 0.06), transparent 12% 88%, rgba(122, 77, 43, 0.06)),
    #f6ead0;
  border: 1px solid rgba(122, 77, 43, 0.22);
  border-radius: 6px 20px 20px 6px;
  box-shadow: inset 0 0 30px rgba(124, 82, 45, 0.1), 0 8px 18px rgba(78, 48, 26, 0.16);
}

.classic-content {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.classic-content h4 {
  margin: 0 0 12px;
  font-size: 22px;
  letter-spacing: 0.08em;
}

.classic-text {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 270px;
  overflow: auto;
  color: #3f2b1e;
  font-size: 18px;
  line-height: 1.7;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  letter-spacing: 0.14em;
  white-space: pre-wrap;
  scrollbar-width: none;
}

.classic-text::-webkit-scrollbar {
  display: none;
}

.classic-source {
  align-self: flex-end;
  margin-top: 10px;
  color: var(--wood-dark);
  font-size: 13px;
  letter-spacing: 0.04em;
}

.classic-locked {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #9a7853;
  text-align: center;
  line-height: 1.6;
}

.classic-locked .lock-glyph {
  font-size: 48px;
  opacity: 0.75;
}

.classic-seal {
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  color: rgba(161, 50, 41, 0.82);
  border: 3px solid rgba(161, 50, 41, 0.78);
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.2;
  text-align: center;
  letter-spacing: 0.08em;
  transform: rotate(-8deg);
  pointer-events: none;
}

.book-nav {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 14px;
}

.book-nav button {
  min-height: 38px;
  padding: 0 13px;
  color: var(--ink);
  background: rgba(255, 248, 230, 0.72);
  border: 1px solid rgba(112, 69, 43, 0.18);
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow-soft);
}

.book-nav button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.book-nav span {
  color: var(--ink-soft);
  font-size: 13px;
}

/* 设置 */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.setting-row {
  position: relative;
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px;
  background: rgba(255, 251, 237, 0.62);
  border: 1px solid rgba(112, 69, 43, 0.14);
  border-radius: 15px;
  cursor: pointer;
}

.setting-row span {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.setting-row strong {
  font-size: 16px;
}

.setting-row small {
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.35;
}

.setting-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #c9b58d;
  transition: background 0.2s ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff8e6;
  box-shadow: 0 2px 5px rgba(56, 37, 21, 0.24);
  transition: transform 0.2s ease;
}

.setting-row input:checked + .switch {
  background: var(--green);
}

.setting-row input:checked + .switch::after {
  transform: translateX(20px);
}

/* 完成弹窗 */
.completion-modal {
  overflow: hidden;
  background: radial-gradient(circle at 50% 36%, rgba(255, 220, 117, 0.28), rgba(58, 37, 22, 0.74));
}

.completion-glow {
  position: absolute;
  inset: -40%;
  background: conic-gradient(from 0deg, transparent, rgba(255, 216, 122, 0.25), transparent 30%, rgba(233, 190, 82, 0.24), transparent 60%, rgba(255, 226, 154, 0.18), transparent 90%);
  animation: slow-spin 9s linear infinite;
  pointer-events: none;
}

.completion-card {
  position: relative;
  z-index: 2;
  width: min(100%, 380px);
  padding: 26px 24px 22px;
  text-align: center;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.65), transparent 44%),
    linear-gradient(160deg, #fff4d9, #eacf9e);
  border: 1px solid rgba(255, 244, 214, 0.72);
  border-radius: 30px;
  box-shadow: 0 24px 70px rgba(25, 16, 9, 0.45);
  transform: translateY(14px) scale(0.96);
  transition: transform 0.28s ease;
}

.completion-modal.is-open .completion-card {
  transform: translateY(0) scale(1);
}

.completion-sachet {
  width: 170px;
  height: 170px;
  margin: 0 auto 12px;
  display: grid;
  place-items: center;
  background: #fff8e6;
  border: 1px solid rgba(119, 72, 38, 0.16);
  border-radius: 32px;
  box-shadow: 0 15px 35px rgba(85, 49, 24, 0.24);
  animation: sachet-sway 2.4s ease-in-out infinite;
}

.completion-sachet img {
  width: 84%;
  height: 84%;
  object-fit: contain;
  filter: drop-shadow(0 7px 5px rgba(71, 43, 22, 0.2));
}

.completion-eyebrow {
  margin: 0 0 7px;
  color: var(--wood);
  font-size: 13px;
  letter-spacing: 0.2em;
}

.completion-card h3 {
  margin: 0;
  font-size: 27px;
  letter-spacing: 0.04em;
}

.completion-quote {
  margin: 12px 0 22px;
  color: var(--wood-dark);
  font-size: 17px;
  letter-spacing: 0.14em;
}

.completion-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.completion-actions .btn {
  min-width: 132px;
}

.leaf-field {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}

.falling-leaf,
.completion-particle {
  position: absolute;
  top: -40px;
  animation: leaf-fall linear forwards;
  will-change: transform, opacity;
}

.falling-leaf {
  font-size: 24px;
  opacity: 0.9;
}

.completion-particle {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ffd979;
  box-shadow: 0 0 10px #f2c452;
  animation: gold-float 4s ease-in forwards;
}

/* 粒子 */
.particle {
  position: absolute;
  z-index: 30;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  pointer-events: none;
  animation: particle-fly 0.65s ease-out forwards;
  will-change: transform, opacity;
}

.particle--gold {
  background: #f4c95d;
  box-shadow: 0 0 8px #ffd86c;
}

.particle--green {
  background: #9cbb6b;
  box-shadow: 0 0 6px #b5d17f;
}

.particle--red {
  background: #c65b50;
  box-shadow: 0 0 6px #e17b6e;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 100;
  max-width: calc(100vw - 40px);
  padding: 10px 16px;
  color: #fff8e7;
  background: rgba(75, 47, 29, 0.9);
  border: 1px solid rgba(255, 226, 164, 0.25);
  border-radius: 999px;
  box-shadow: 0 8px 22px rgba(32, 20, 11, 0.28);
  font-size: 14px;
  letter-spacing: 0.04em;
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 12px);
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s ease;
  pointer-events: none;
}

.toast.is-showing {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

/* ---------- 动画 ---------- */
@keyframes merge-pop {
  0% {
    transform: scale(1);
    filter: brightness(1);
  }
  38% {
    transform: scale(1.16);
    filter: brightness(1.25);
    box-shadow: 0 0 0 5px rgba(246, 201, 90, 0.32), 0 0 24px rgba(255, 214, 111, 0.55);
  }
  100% {
    transform: scale(0.95);
    filter: brightness(1.02);
  }
}

@keyframes particle-fly {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0.25);
  }
}

@keyframes leaf-fall {
  0% {
    opacity: 0;
    transform: translateY(-4vh) rotate(0deg) translateX(0);
  }
  12% {
    opacity: 0.9;
  }
  100% {
    opacity: 0;
    transform: translateY(105vh) rotate(360deg) translateX(var(--drift, 20px));
  }
}

@keyframes gold-float {
  0% {
    opacity: 0;
    transform: translateY(-5vh) translateX(0) scale(0.7);
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(105vh) translateX(var(--drift, -20px)) scale(1.2);
  }
}

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

@keyframes sachet-sway {
  0%,
  100% {
    transform: rotate(-3deg);
  }
  50% {
    transform: rotate(3deg);
  }
}

/* ---------- 响应式微调 ---------- */
@media (max-width: 370px) {
  #game-screen {
    gap: 7px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .board {
    gap: 7px;
    padding: 9px;
    border-radius: 22px;
  }

  .chain-item {
    flex-basis: 53px;
    height: 62px;
  }

  .chain-item img {
    width: 38px;
    height: 38px;
  }

  .home-title {
    font-size: 46px;
  }
}

@media (max-height: 720px) {
  .board {
    min-height: 300px;
  }

  .game-footer {
    gap: 7px;
  }

  .footer-tools button {
    min-height: 38px;
  }
}

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