:root {
  --bg: #1b1420;
  --ink: #fff8ef;
  --muted: #c9b9c4;
  --accent: #ffb547;
  --wood: #e9c99a;
  --wood-dark: #b98a52;
}

* { 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; }

.hud { display: flex; align-items: center; gap: 12px; padding: max(10px, env(safe-area-inset-top)) 12px 6px; }
.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; }
.hud small { display: block; font-size: 11px; color: var(--muted); }
.hud b { font-size: 22px; font-variant-numeric: tabular-nums; }
.score { flex: 1; }
.best b { font-size: 16px; color: var(--accent); }
.next { text-align: center; }
.next canvas { width: 40px; height: 40px; display: block; margin: 0 auto; }

.board { position: relative; flex: 1; min-height: 0; margin: 0 8px; display: grid; place-items: center; }
#world { display: block; touch-action: none; border-radius: 0 0 20px 20px; }

.chain { list-style: none; margin: 6px 8px max(10px, env(safe-area-inset-bottom)); padding: 0; display: flex; justify-content: space-between; align-items: flex-end; }
.chain li { flex: 1; text-align: center; font-size: 9px; color: var(--muted); }
.chain img { display: block; width: 26px; height: 26px; margin: 0 auto 2px; border-radius: 50%; object-fit: cover; filter: grayscale(1) brightness(.35); transition: filter .3s; }
.chain li.seen img { filter: none; box-shadow: 0 0 0 2px var(--accent); }
.chain li:not(.seen) span { visibility: hidden; }

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

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

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