:root {
  --bg: #fdf3e2;
  --ink: #5b4028;
  --ink-light: #a08464;
  --board: #c9524a;
  --cell: #d7716a;
  --accent: #e0a010;
  --accent-deep: #c98a06;
  --card: #fffdf6;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  background: var(--bg) radial-gradient(ellipse at 50% -20%, #fffaf0 0%, var(--bg) 60%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  display: flex;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

.wrap {
  width: min(94vw, 470px);
  padding: 18px 0 32px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

h1 { font-size: clamp(26px, 7vw, 36px); letter-spacing: -1px; line-height: 1.05; color: #a03a30; }
h1 span { display: block; color: var(--ink-light); font-size: 18px; letter-spacing: 3px; margin-top: 5px; }

.scores { display: flex; gap: 8px; }

.score-box {
  position: relative;
  background: #fff;
  border-radius: 10px;
  padding: 6px 10px 8px;
  text-align: center;
  min-width: 74px;
  box-shadow: 0 2px 8px rgba(160, 90, 60, .16);
}
.score-box label { font-size: 12px; color: var(--ink-light); }
#score, #best { font-size: 22px; font-weight: 700; line-height: 1.15; color: #a03a30; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
  margin: 12px 0 10px;
}
.hint { flex-basis: 100%; font-size: 14px; color: var(--ink-light); }
.hint strong { color: var(--accent); }

button {
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  padding: 9px 16px;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .12);
}
button:active { transform: translateY(2px) scale(0.98); box-shadow: 0 1px 0 rgba(0, 0, 0, .12); }

.btns { display: flex; gap: 8px; }
#lb-btn { background: #c9524a; }
#mute-btn { background: #fff; color: var(--ink); box-shadow: 0 3px 0 rgba(160, 90, 60, .2); }

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background: var(--board);
  border-radius: 16px;
  box-shadow: inset 0 3px 12px rgba(90, 25, 18, .22), 0 4px 14px rgba(160, 90, 60, .2);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}
.board.thump { animation: thump .18s ease-out; }
@keyframes thump {
  35% { transform: scale(1.012); }
  100% { transform: scale(1); }
}

.cells, .tiles { position: absolute; inset: 0; }
.cell { position: absolute; background: var(--cell); border-radius: 12px; }

.tile {
  position: absolute;
  transition: transform .11s ease-in-out;
  will-change: transform;
  z-index: 2;
}
.tiles.no-anim .tile { transition: none; }

.tile .inner {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  background: var(--card);
  border: 3px solid var(--fr, #dcc9a2);
  border-bottom-width: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1%;
  padding: 4% 4% 6%;
  font-weight: 700;
  box-shadow: 0 2px 5px rgba(60, 90, 70, .15);
}

/* 金额大字 */
.tile .amt {
  font-weight: 800;
  line-height: 1;
  color: #7a4a12;
  letter-spacing: .02em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .7);
  white-space: nowrap;
}
.t512 .amt, .t1024 .amt, .t2048 .amt, .t4096 .amt, .t8192 .amt {
  color: #fff;
  text-shadow: 0 1px 3px rgba(120, 60, 0, .45);
}


/* 等级配色：铜币→银币→金币→票面青红→金砖一路到亿档金光 */
.t2    .inner { background: #f6ede0; --fr: #c7a27c; }
.t4    .inner { background: #eef1f4; --fr: #a9b4bf; }
.t8    .inner { background: #fdf2c8; --fr: #ddb43a; }
.t16   .inner { background: #e6f2ef; --fr: #6fb0a5; }
.t32   .inner { background: #fbe4dc; --fr: #dd8069; }
.t64   .inner { background: #fbdfb9; --fr: #e19a34; }
.t128  .inner { background: #f9d190; --fr: #d78a1b; }
.t256  .inner { background: #f7c168; --fr: #c97a0d; }
.t512  .inner { background: #eda634; --fr: #b56c05; }
.t1024 .inner { background: #e39112; --fr: #a35c02; }
.t2048 .inner {
  background: linear-gradient(160deg, #ffd34d, #f0a000);
  --fr: #d68f00;
  box-shadow: 0 0 20px rgba(255, 190, 60, .9), 0 2px 5px rgba(120, 60, 30, .15);
}
.t4096 .inner {
  background: linear-gradient(160deg, #ffde6b, #ff8c00);
  --fr: #e97e00;
  box-shadow: 0 0 26px rgba(255, 165, 0, .95), 0 2px 5px rgba(120, 60, 30, .15);
}
.t8192 .inner {
  background: linear-gradient(160deg, #e8d5ff, #ffd700);
  --fr: #b98ff5;
  box-shadow: 0 0 30px rgba(185, 143, 245, .95), 0 2px 5px rgba(120, 60, 30, .15);
}

/* 钱的小动作 */
.amt.b-hop { animation: bhop .75s cubic-bezier(.34, 1.4, .64, 1); }
@keyframes bhop {
  0% { transform: scale(1, 1); }
  25% { transform: scale(1.1, .82); }
  50% { transform: translateY(-24%) scale(.95, 1.1) rotate(3deg); }
  75% { transform: translateY(0) scale(1.14, .84); }
  100% { transform: scale(1, 1); }
}
.amt.b-wiggle { animation: bwiggle .9s ease-in-out; }
@keyframes bwiggle {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-11deg); }
  45% { transform: rotate(9deg); }
  70% { transform: rotate(-6deg); }
}
.amt.b-shine { animation: bshine 1.2s ease-in-out; }
@keyframes bshine {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  40% { transform: scale(1.12) rotate(-2deg); filter: brightness(1.55); }
  70% { transform: scale(1.04) rotate(1deg); filter: brightness(1.2); }
}

/* 出生：弹性冒出来 */
.inner.appear { animation: appear .26s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes appear {
  0% { transform: scale(.15); }
  70% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* 合成 duang：果冻弹 */
.inner.pop { animation: duang .46s cubic-bezier(.3, 1.4, .6, 1); }
@keyframes duang {
  0% { transform: scale(.35); }
  38% { transform: scale(1.42, .62); }
  60% { transform: scale(.8, 1.26); }
  78% { transform: scale(1.14, .92); }
  90% { transform: scale(.97, 1.04); }
  100% { transform: scale(1); }
}

/* 被撞前的绷紧 */
.inner.brace { animation: brace .12s ease-in; }
@keyframes brace {
  50% { transform: scale(.88); }
  100% { transform: scale(1); }
}

/* 合成金额爆字 */
.money-pop {
  position: absolute;
  z-index: 7;
  font-weight: 900;
  color: #ffd75e;
  text-shadow: 0 2px 0 #a3540a, 0 0 12px rgba(255, 200, 60, .85);
  pointer-events: none;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  animation: moneyPop 1.5s cubic-bezier(.2, .8, .3, 1) forwards;
}
@keyframes moneyPop {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(.4); }
  12% { opacity: 1; transform: translate(-50%, -62%) scale(1.3); }
  30% { transform: translate(-50%, -80%) scale(1.05); }
  70% { opacity: 1; transform: translate(-50%, -115%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -175%) scale(.95); }
}

/* 合成爆点：粒子 + 冲击环 */
.burst {
  position: absolute;
  width: 0; height: 0;
  z-index: 6;
  pointer-events: none;
}
.burst span {
  position: absolute;
  left: 0; top: 0;
  animation: fly .55s ease-out forwards;
}
@keyframes fly {
  0% { transform: translate(-50%, -50%) scale(.4); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.05) rotate(30deg); opacity: 0; }
}
.burst .ring {
  position: absolute;
  left: 0; top: 0;
  width: 12px; height: 12px;
  border: 6px solid #ffb84d;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: ringx .4s ease-out forwards;
}
@keyframes ringx {
  0% { width: 12px; height: 12px; opacity: .95; border-width: 7px; }
  100% { width: var(--cellpx, 110px); height: var(--cellpx, 110px); opacity: 0; border-width: 2px; }
}

.overlay[hidden] { display: none; }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(253, 245, 230, .9);
  backdrop-filter: blur(2px);
  border-radius: 16px;
  animation: fadeIn .35s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.overlay h2 { font-size: clamp(24px, 6vw, 34px); letter-spacing: 0; text-align: center; }
.overlay.win h2 { color: var(--accent); text-shadow: 0 0 18px rgba(240, 140, 30, .5); }
.overlay.lose h2 { color: #a04545; }
.overlay p {
  font-size: 15px;
  color: #7a4a12;
  background: #fff8ea;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  padding: 12px 16px;
  max-width: 88%;
  text-align: center;
  line-height: 1.6;
}
.overlay-btns { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 4px; }
.overlay-btns button { padding: 9px 10px; font-size: 13px; }
.overlay p { font-size: 14px; line-height: 1.4; padding: 8px 10px; }
#keep-going { background: #c9524a; }
#share-btn { background: #b8860b; }

.ladder {
  margin-top: 14px;
  text-align: center;
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-light);
}
.ladder strong { color: var(--accent); }

/* === 大橘榜弹窗 === */
.lb[hidden] { display: none; }
.lb {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(80, 40, 30, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn .25s ease;
}
.lb-card {
  width: min(92vw, 420px);
  max-height: 82vh;
  background: #fdf7ec;
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
}
.lb-head { display: flex; justify-content: space-between; align-items: center; }
.lb-head h3 { font-size: 22px; letter-spacing: 0; color: #a03a30; }
.lb-x { background: none; color: var(--ink-light); font-size: 24px; padding: 0 8px; box-shadow: none; }
.lb-me { font-size: 14px; color: var(--ink-light); min-height: 1.3em; }
.lb-rename { display: flex; gap: 8px; }
.lb-rename input {
  flex: 1;
  min-width: 0;
  border: 1px solid #dcc9a8;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
}
.lb-rename button { padding: 8px 12px; font-size: 14px; }
.lb-list { list-style: none; overflow-y: auto; flex: 1; }
.lb-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-bottom: 1px dashed #e5d2b8;
  font-size: 14px;
}
.lb-list li.me { background: #ffefd8; border-radius: 8px; }
.lb-rank { width: 34px; text-align: center; font-weight: 700; color: var(--ink-light); flex: none; }
.lb-rank.top { color: var(--accent); }
.lb-n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-realm { color: var(--accent); font-size: 13px; flex: none; }
.lb-score { font-weight: 700; min-width: 56px; text-align: right; flex: none; }
.lb-empty { text-align: center; color: var(--ink-light); padding: 18px 0; }

/* === 战报海报预览 === */
.poster[hidden] { display: none; }
.poster {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(60, 20, 14, .6);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn .25s ease;
}
.poster-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 92vw;
}
.poster-card img {
  max-width: min(86vw, 400px);
  max-height: 70vh;
  border-radius: 14px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, .45);
}
.poster-btns { display: flex; gap: 10px; }
.poster-btns .ghost { background: rgba(255, 255, 255, .22); }
.poster-tip { text-align: center; font-size: 13px; color: #ffd9c4; }
