:root {
  --bg: #1b1420;
  --ink: #fff8ef;
  --muted: #c9b9c4;
  --accent: #ffb547;
  --card: #2a2030;
  --gap: 10px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; }
body { font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }

#app { position: relative; height: 100%; max-width: 480px; margin: 0 auto; display: flex; flex-direction: column; user-select: none; -webkit-user-select: none; touch-action: none; }

.hud { display: flex; align-items: center; gap: 14px; padding: max(12px, env(safe-area-inset-top)) 12px 4px; }
.home { width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,.1); color: var(--ink); text-decoration: none; display: grid; place-items: center; font-size: 22px; line-height: 1; }
.stat small { display: block; font-size: 11px; color: var(--muted); }
.stat b { font-size: 22px; font-variant-numeric: tabular-nums; }
.stat:nth-child(3) b { color: var(--accent); font-size: 17px; }
.restart { margin-left: auto; padding: 8px 14px; border-radius: 999px; background: rgba(255,255,255,.1); font-size: 13px; }
.tip { margin: 6px 16px 10px; font-size: 13px; color: var(--muted); text-align: center; }
.tip b { color: var(--accent); }

.board-wrap { flex: 1; min-height: 0; display: grid; place-items: center; padding: 0 12px; }
.board { position: relative; padding: var(--gap); border-radius: 18px; background: #2a2030; box-shadow: 0 6px 0 rgba(0,0,0,.35); }
.cell { position: absolute; border-radius: 14px; background: rgba(255,255,255,.05); }
.tile { position: absolute; left: 0; top: 0; border-radius: 14px; transition: transform .12s ease-out; will-change: transform; z-index: 1; }
.tile .face { width: 100%; height: 100%; border-radius: 14px; display: grid; place-items: center; position: relative; overflow: hidden; }
.tile img { width: 86%; height: 86%; border-radius: 50%; display: block; }
.tile span { position: absolute; right: 4px; bottom: 4px; padding: 1px 6px; border-radius: 8px; font-size: 10px; font-weight: 900; color: #3b1d05; background: rgba(255,255,255,.88); font-variant-numeric: tabular-nums; }
.tile.new .face { animation: appear .18s ease-out; }
.tile.merged { z-index: 2; }
.tile.merged .face { animation: bump .22s ease-out; }
@keyframes appear { from { transform: scale(.2); opacity: 0; } }
@keyframes bump { 50% { transform: scale(1.18); } }

.chain { list-style: none; margin: 10px 8px max(10px, env(safe-area-inset-bottom)); padding: 0; display: flex; justify-content: space-between; }
.chain li { flex: 1; text-align: center; }
.chain img { display: block; width: 26px; height: 26px; margin: 0 auto; border-radius: 50%; filter: grayscale(1) brightness(.35); transition: filter .3s; }
.chain li.seen img { filter: none; }
.chain small { display: block; font-size: 9px; color: var(--muted); font-variant-numeric: tabular-nums; }

.toast { position: absolute; left: 50%; top: 20%; transform: translateX(-50%); padding: 10px 18px; border-radius: 999px; background: rgba(0,0,0,.75); font-weight: 800; white-space: nowrap; opacity: 0; pointer-events: none; z-index: 4; }
.toast.show { animation: toast 2.2s ease-out; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, 10px); } 10%, 80% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }

.over { position: absolute; inset: 0; display: none; place-items: center; background: rgba(20,10,25,.8); z-index: 5; }
.over.show { display: grid; }
.over .card { width: min(320px, 86%); text-align: center; padding: 24px 20px; border-radius: 24px; background: var(--card); box-shadow: 0 6px 0 rgba(0,0,0,.4); }
.over h2 { margin: 0; color: var(--accent); }
.big { margin: 6px 0; font-size: 48px; font-weight: 900; font-variant-numeric: tabular-nums; }
.sub { margin: 0; color: var(--muted); }
.best { color: var(--accent); min-height: 1.2em; }
.primary, .ghost { display: block; width: 100%; margin-top: 10px; padding: 13px; border-radius: 999px; font-weight: 800; }
.primary { background: var(--accent); color: #3b1d05; }
.ghost { background: rgba(255,255,255,.1); }
.ghost[hidden] { display: none; }

.loading { position: absolute; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 6; }
.loading.hide { display: none; }
