:root {
  --bg: #121a12;
  --panel: #1f2b1f;
  --panel2: #2a3a2a;
  --line: #3e553e;
  --text: #e8efe0;
  --muted: #9fb39a;
  --accent: #f2c14e;
  --good: #5fbf55;
  --bad: #d9534f;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden;
  font: 14px/1.35 -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  overscroll-behavior: none; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; max-width: 560px; margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
button { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px; min-height: 40px; cursor: pointer; }
button:active { filter: brightness(1.3); }
button:disabled { opacity: .45; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

#hud { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 6px 8px; background: var(--panel); }
.stat { display: flex; align-items: center; gap: 6px; justify-content: center; font-variant-numeric: tabular-nums; }
.stat b { font-size: 16px; }
.ico { width: 14px; height: 14px; border-radius: 50%; display: inline-block; flex: none; }
.ico.coin { background: var(--accent); box-shadow: inset 0 0 0 3px #c99a2a; }
.ico.star { background: #8fd3ff; clip-path: polygon(50% 0, 62% 36%, 100% 38%, 70% 60%, 80% 100%, 50% 76%, 20% 100%, 30% 60%, 0 38%, 38% 36%); border-radius: 0; }
.ico.clock { border: 3px solid #cfd8c9; }
.ico.heart { background: var(--bad); }

#stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
#board { display: block; touch-action: none; image-rendering: auto; }
#toast { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); background: rgba(0,0,0,.75);
  padding: 6px 14px; border-radius: 16px; opacity: 0; transition: opacity .2s; pointer-events: none; white-space: nowrap; }
#toast.show { opacity: 1; animation: toastIn .25s ease-out; }

#info { min-height: 58px; padding: 6px 10px; background: var(--panel); border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px; font-size: 13px; }
#info .txt { flex: 1; min-width: 0; }
#info .name { font-weight: 700; font-size: 14px; }
#info .muted { color: var(--muted); }
#info .act { display: flex; gap: 6px; }
#info .up { background: #2f5d2a; border-color: var(--good); }
#info .sell { background: #5d2a2a; border-color: var(--bad); }

#bar { background: var(--panel); padding: 6px 6px 8px; display: flex; flex-direction: column; gap: 6px; }
#towers { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
#towers button { padding: 2px; min-height: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; }
#towers button canvas { width: 30px; height: 30px; }
#towers button small { font-size: 11px; color: var(--accent); }
#towers button[aria-pressed="true"] { border-color: var(--accent); background: #4a4320; }
#towers button.poor small { color: var(--bad); }
#controls { display: grid; grid-template-columns: 48px 56px 56px 1fr; gap: 6px; }
#btnNext { background: #2f5d2a; border-color: var(--good); font-weight: 700; }

.overlay { position: absolute; inset: 0; background: rgba(8,12,8,.88); display: none; align-items: center; justify-content: center; z-index: 10; padding: 16px; }
.overlay.open { display: flex; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: 8px; max-height: 100%; overflow: auto; }
.panel h1 { margin: 0; text-align: center; letter-spacing: 3px; color: var(--accent); font-size: 26px; }
.panel h2 { margin: 6px 0 2px; font-size: 16px; color: var(--accent); }
.panel .sub { margin: -4px 0 8px; text-align: center; color: var(--muted); }
.panel .big { font-size: 16px; min-height: 46px; background: #2f5d2a; border-color: var(--good); }
.panel .ghost { background: transparent; }
#diffs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#diffs button { min-height: 54px; }
#diffs small { display: block; color: var(--muted); font-size: 11px; }
#dialogBody { font-size: 13px; }
#dialogBody p { margin: 4px 0; }
#dialogBody table { width: 100%; border-collapse: collapse; }
#dialogBody td, #dialogBody th { padding: 3px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.result { text-align: center; font-size: 15px; }
.result .big-num { font-size: 32px; color: var(--accent); font-weight: 700; }

/* ---------- 动效 ---------- */
@keyframes toastIn { from { transform: translate(-50%, -8px) scale(.9); } to { transform: translate(-50%, 0) scale(1); } }
@keyframes bumpUp { 0% { transform: scale(1); } 35% { transform: scale(1.22); color: var(--accent); } 100% { transform: scale(1); } }
@keyframes bumpDown { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-3px); color: var(--bad); } 40% { transform: translateX(3px); color: var(--bad); } 60% { transform: translateX(-2px); } 80% { transform: translateX(2px); } }
@keyframes pulse { 50% { color: var(--bad); transform: scale(1.12); } }
@keyframes panelIn { from { transform: translateY(18px) scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.stat.bump-up b { animation: bumpUp .35s ease-out; }
.stat.bump-down { animation: bumpDown .4s ease-out; }
.stat.warn b { animation: pulse .8s ease-in-out infinite; }
.overlay.open { animation: fadeIn .2s ease-out; }
.overlay.open .panel { animation: panelIn .28s cubic-bezier(.2,1.3,.4,1); }
#towers button { transition: transform .12s, border-color .15s, background .15s; }
#towers button:active { transform: scale(.92); }
#towers button[aria-pressed="true"] { transform: translateY(-3px); box-shadow: 0 3px 0 #a07f22; }
#btnNext:not(:disabled) { transition: transform .1s; }
#btnNext:active { transform: scale(.97); }

/* ---------- 图鉴卡片 ---------- */
.card { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.card:last-child { border-bottom: 0; }
.card .cv-creature { width: 64px; height: 64px; flex: none; background: radial-gradient(circle at 50% 60%, #3f5d30, #263a1d); border-radius: 12px; }
.card-body { flex: 1; min-width: 0; }
.card-body p { margin: 4px 0; }
.card-title { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.badge { font-size: 11px; background: var(--accent); color: #2a2000; padding: 1px 6px; border-radius: 8px; animation: pulse 1.2s ease-in-out infinite; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.chip { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); }
.hl { color: var(--accent); }
.tip { color: #cfe3c2; }
.ctrs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; }
.ctr { display: inline-flex; align-items: center; gap: 3px; }
.ctr canvas { width: 22px; height: 22px; }
.chipbtn { min-height: 0; padding: 1px 8px; font-size: 12px; border-radius: 10px; margin-left: 4px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row2 button { font-size: 13px; }

/* ---------- 排行榜 ---------- */
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 6px 0; }
.tabs .tab { min-height: 34px; padding: 4px; font-size: 12px; }
.tabs .tab[aria-pressed="true"] { border-color: var(--accent); background: #4a4320; }
.lb ol { list-style: none; margin: 0; padding: 0; }
.lb li { display: grid; grid-template-columns: 32px 1fr auto auto; gap: 8px; align-items: center; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.lb li.me { background: #4a4320; border-radius: 6px; }
.lb .rk { text-align: center; font-weight: 700; }
.lb .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb .sc { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.lb .wv { font-size: 12px; min-width: 52px; text-align: right; }
.submit { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.submit .row { display: flex; gap: 6px; }
.submit input { flex: 1; min-width: 0; font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; user-select: text; -webkit-user-select: text; }
.submit input:focus { outline: 2px solid var(--accent); }
.submit .up { background: #2f5d2a; border-color: var(--good); }
.submit p { margin: 0; }
