: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; background: none; }

#app { position: relative; height: 100%; max-width: 480px; margin: 0 auto; user-select: none; -webkit-user-select: none; }
.screen { position: absolute; inset: 0; display: none; flex-direction: column; padding: max(14px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom)); }
.screen.active { display: flex; }

/* select */
#select { overflow-y: auto; }
.home { color: var(--muted); text-decoration: none; font-size: 14px; }
h1 { margin: 8px 0 4px; font-size: 32px; letter-spacing: 4px; color: var(--accent); text-shadow: 0 3px 0 #7a3a1a; }
.sub { margin: 0; color: var(--muted); font-size: 14px; }
.sub b { color: var(--accent); }
.levels { display: flex; gap: 6px; margin: 14px 0; }
.levels button { flex: 1; padding: 9px 4px; border-radius: 999px; background: rgba(255,255,255,.08); font-size: 14px; }
.levels button.on { background: var(--accent); color: #3b1d05; font-weight: 800; }
.pet-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pet-list button { position: relative; width: 100%; padding: 0; border-radius: 14px; overflow: hidden; background: var(--card); box-shadow: 0 3px 0 rgba(0,0,0,.35); }
.pet-list img { display: block; width: 100%; aspect-ratio: 2 / 3; object-fit: cover; }
.pet-list span { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 4px 5px; font-size: 13px; font-weight: 800; background: linear-gradient(transparent, rgba(0,0,0,.75)); }
.pet-list button.done::after { content: "✓"; position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--good); color: #1b1420; font-weight: 900; font-size: 14px; }

/* play */
.hud { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.round { width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,.1); 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; }
.peek { margin-left: auto; padding: 8px 14px; border-radius: 999px; background: rgba(255,255,255,.1); font-size: 13px; touch-action: none; }
.peek:active { background: var(--accent); color: #3b1d05; }
.board-wrap { flex: 1; min-height: 0; display: grid; place-items: center; }
.board { position: relative; border-radius: 12px; overflow: hidden; background: #000; touch-action: none; box-shadow: 0 6px 24px rgba(0,0,0,.5); }
.board.peeking .piece { opacity: 0; }
.board .ghost-full { position: absolute; inset: 0; background-size: cover; }
.piece {
  position: absolute; left: 0; top: 0; background-repeat: no-repeat;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.35); transition: transform .18s ease-out, opacity .15s, box-shadow .2s;
  will-change: transform;
}
.piece.sel { box-shadow: inset 0 0 0 3px var(--accent); z-index: 2; }
.piece.drag { transition: none; z-index: 3; box-shadow: 0 8px 20px rgba(0,0,0,.5), inset 0 0 0 2px var(--accent); }
.piece.ok { box-shadow: none; }
.piece.flash { animation: okflash .45s; }
@keyframes okflash { 50% { box-shadow: inset 0 0 0 3px var(--good); } }
.board.solved .piece { box-shadow: none; }
.caption { margin: 10px 0 0; min-height: 1.4em; text-align: center; color: var(--muted); font-size: 14px; }

/* win */
.win { position: absolute; inset: auto 0 0; display: none; padding: 0 12px max(14px, env(safe-area-inset-bottom)); z-index: 5; }
.win.show { display: block; animation: rise .35s ease-out; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.win .card { text-align: center; padding: 16px 18px 18px; border-radius: 22px; background: rgba(42,32,48,.96); box-shadow: 0 -4px 24px rgba(0,0,0,.4); }
.win h2 { margin: 0; color: var(--accent); font-size: 20px; }
.stars { font-size: 28px; letter-spacing: 6px; color: var(--accent); }
.stars .off { color: rgba(255,255,255,.18); }
.lyric { margin: 6px 0 2px; font-size: 18px; font-weight: 800; }
.primary, .ghost { display: block; width: 100%; margin-top: 8px; padding: 12px; border-radius: 999px; font-weight: 800; }
.primary { background: var(--accent); color: #3b1d05; }
.ghost { background: rgba(255,255,255,.1); }

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