:root {
  --bg: #1b1420;
  --ink: #fff8ef;
  --muted: #c9b9c4;
  --accent: #ffb547;
  --card: #2a2030;
  --good: #6fe3c1;
}

* { 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: 14px; padding: max(12px, env(safe-area-inset-top)) 12px 8px; }
.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: 20px; font-variant-numeric: tabular-nums; }
.levels { margin-left: auto; display: flex; gap: 4px; padding: 3px; border-radius: 999px; background: rgba(255,255,255,.08); }
.levels button { background: none; padding: 6px 10px; border-radius: 999px; font-size: 13px; color: var(--muted); }
.levels button.on { background: var(--accent); color: #3b1d05; font-weight: 800; }

.board { flex: 1; min-height: 0; display: grid; gap: 8px; padding: 4px 12px max(14px, env(safe-area-inset-bottom)); align-content: center; justify-content: center; }

.tile { position: relative; perspective: 600px; padding: 0; background: none; }
.tile .inner { position: absolute; inset: 0; transition: transform .32s; transform-style: preserve-3d; }
.tile.up .inner, .tile.done .inner { transform: rotateY(180deg); }
.tile .face { position: absolute; inset: 0; border-radius: 14px; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; }
.tile .back {
  display: grid; place-items: center; background: radial-gradient(circle at 30% 25%, #4a3456, #2a2030 70%);
  box-shadow: inset 0 0 0 2px rgba(255,181,71,.35), 0 3px 0 rgba(0,0,0,.35);
}
.tile .back img { width: 46%; opacity: .85; }
.tile .front { transform: rotateY(180deg); background: var(--card); box-shadow: 0 3px 0 rgba(0,0,0,.35); }
.tile .front img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 28%; }
.tile .front span { position: absolute; left: 0; right: 0; bottom: 0; padding: 3px 2px; font-size: 11px; font-weight: 800; text-align: center; background: linear-gradient(transparent, rgba(0,0,0,.75)); white-space: nowrap; overflow: hidden; }
.tile.done .front { box-shadow: 0 0 0 3px var(--good); animation: bump .4s; }
@keyframes bump { 50% { transform: rotateY(180deg) scale(1.08); } }

.win { position: absolute; inset: 0; display: none; place-items: center; background: rgba(20,10,25,.8); z-index: 5; }
.win.show { display: grid; }
.win .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); }
.win h2 { margin: 0; color: var(--accent); }
.stars { font-size: 36px; letter-spacing: 6px; color: var(--accent); }
.stars .off { color: rgba(255,255,255,.18); }
.big { margin: 4px 0; font-size: 44px; 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; text-decoration: none; text-align: center; }
.primary { background: var(--accent); color: #3b1d05; }
.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; }
