:root {
  --bg: #1b1420;
  --ink: #fff8ef;
  --muted: #c9b9c4;
  --accent: #ffb547;
  --pink: #ff7aa8;
  --mint: #6fe3c1;
  --lane-line: rgba(255, 255, 255, 0.14);
}

* { 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; overflow: hidden; }
.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: flex; flex-direction: column; }

/* ---------- select ---------- */
#select { padding: max(24px, env(safe-area-inset-top)) 16px 16px; overflow-y: auto; }
.home { color: var(--muted); text-decoration: none; font-size: 14px; }
.hero h1 { margin: 8px 0 4px; font-size: 34px; letter-spacing: 4px; color: var(--accent); text-shadow: 0 3px 0 #7a3a1a; }
.hero p { margin: 0 0 16px; color: var(--muted); }
.difficulty { display: flex; gap: 8px; margin-bottom: 16px; }
.difficulty button { flex: 1; padding: 10px; border-radius: 999px; background: rgba(255,255,255,.08); }
.difficulty button.on { background: var(--accent); color: #3b1d05; font-weight: 700; }
#pet-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
#pet-list li button {
  width: 100%; padding: 0; border-radius: 18px; overflow: hidden; background: #2a2030; text-align: left;
  box-shadow: 0 4px 0 rgba(0,0,0,.35); transition: transform .1s;
}
#pet-list li button:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
#pet-list img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; object-position: 50% 28%; }
#pet-list .meta { padding: 8px 10px 10px; }
#pet-list .meta b { display: block; font-size: 17px; }
#pet-list .meta span { font-size: 13px; color: var(--muted); }
#pet-list .meta em { float: right; font-style: normal; color: var(--accent); font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; text-align: center; margin-top: 20px; }

/* ---------- play ---------- */
#play { touch-action: none; user-select: none; -webkit-user-select: none; }
.stage { position: absolute; inset: 0; overflow: hidden; }
.stage img {
  width: 100%; height: 100%; object-fit: cover; object-position: 50% 20%;
  transform-origin: 50% 35%; transition: transform .12s ease-out, filter .2s;
}
.stage img.sing { transform: scale(1.045) rotate(-.6deg); }
.stage img.sing.alt { transform: scale(1.045) rotate(.6deg); }
.stage img.sour { filter: grayscale(.6) brightness(.8); }
.stage::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,.45) 0, transparent 14%, transparent 40%, rgba(20,10,25,.82) 62%, rgba(20,10,25,.92) 100%);
}

.hud { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 10px; padding: max(12px, env(safe-area-inset-top)) 12px 0; z-index: 3; }
#quit { width: 34px; height: 34px; border-radius: 50%; background: rgba(0,0,0,.4); }
.song-meta { flex: 1; min-width: 0; line-height: 1.2; }
.song-meta b { display: block; }
.song-meta span { font-size: 12px; color: var(--muted); }
.score { text-align: right; line-height: 1.1; }
.score span { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.score small { display: block; font-size: 12px; color: var(--accent); min-height: 1em; }
.progress { position: absolute; top: calc(max(12px, env(safe-area-inset-top)) + 44px); left: 12px; right: 12px; height: 3px; background: rgba(255,255,255,.15); border-radius: 2px; z-index: 3; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 2px; }

.lyric {
  position: absolute; left: 8px; right: 8px; bottom: calc(1.5% + env(safe-area-inset-bottom)); z-index: 3; text-align: center;
  pointer-events: none; font-size: 22px; font-weight: 800; letter-spacing: 2px; min-height: 1.4em;
  text-shadow: 0 2px 6px rgba(0,0,0,.8);
}
.lyric span { color: rgba(255,255,255,.5); transition: color .1s; }
.lyric span.hit { color: var(--accent); }
.lyric span.perfect { color: #ffe27a; }
.lyric span.miss { color: rgba(140,130,140,.6); text-decoration: line-through; }
.judge {
  position: absolute; left: 0; right: 0; top: 50%; z-index: 4; text-align: center; font-size: 28px; font-weight: 900;
  opacity: 0; pointer-events: none;
}
.judge.show { animation: pop .45s ease-out; }
@keyframes pop { 0% { opacity: 0; transform: scale(.6); } 20% { opacity: 1; transform: scale(1.15); } 100% { opacity: 0; transform: translateY(-14px); } }

.field { position: absolute; left: 0; right: 0; top: 48%; bottom: 0; display: flex; z-index: 2; }
.lane { flex: 1; position: relative; border-left: 1px solid var(--lane-line); }
.lane:first-child { border-left: 0; }
.lane.press { background: linear-gradient(to top, rgba(255,181,71,.28), transparent 60%); }
.hitline { position: absolute; left: 6px; right: 6px; bottom: calc(14% + env(safe-area-inset-bottom)); height: 4px; border-radius: 2px; background: rgba(255,255,255,.75); box-shadow: 0 0 12px var(--accent); pointer-events: none; }
.note {
  position: absolute; left: 50%; top: 0; width: 56px; height: 56px; margin: -28px 0 0 -28px;
  border-radius: 50%; display: grid; place-items: center; font-size: 24px; font-weight: 800; color: #3b1d05;
  background: radial-gradient(circle at 35% 30%, #fff3d4, var(--accent) 65%); box-shadow: 0 3px 0 #b86b12, 0 0 14px rgba(255,181,71,.5);
  pointer-events: none; will-change: transform;
}
.lane[data-lane="0"] .note { background: radial-gradient(circle at 35% 30%, #ffe1ec, var(--pink) 65%); box-shadow: 0 3px 0 #b8456c, 0 0 14px rgba(255,122,168,.5); }
.lane[data-lane="2"] .note { background: radial-gradient(circle at 35% 30%, #e0fff5, var(--mint) 65%); box-shadow: 0 3px 0 #2e9c7c, 0 0 14px rgba(111,227,193,.5); }
.note.gone { opacity: 0; transition: opacity .15s, transform .15s; }
.burst { position: absolute; left: 50%; width: 80px; height: 80px; margin-left: -40px; border-radius: 50%; border: 4px solid #fff; pointer-events: none; animation: burst .35s ease-out forwards; }
@keyframes burst { from { transform: scale(.4); opacity: 1; } to { transform: scale(1.4); opacity: 0; } }

.countdown { position: absolute; inset: 0; display: grid; place-items: center; font-size: 96px; font-weight: 900; z-index: 5; pointer-events: none; text-shadow: 0 4px 12px rgba(0,0,0,.6); }
.loading { position: absolute; inset: 0; display: none; place-items: center; background: rgba(0,0,0,.6); z-index: 6; }
.loading.show { display: grid; }

/* ---------- result ---------- */
#result { align-items: center; justify-content: center; padding: 16px; background: radial-gradient(circle at 50% 20%, #3a2540, var(--bg)); }
.card { width: 100%; text-align: center; }
.card img { width: 150px; height: 150px; border-radius: 50%; object-fit: cover; object-position: 50% 26%; border: 4px solid var(--accent); }
.card h2 { margin: 12px 0 4px; }
.stars { font-size: 36px; letter-spacing: 6px; color: var(--accent); }
.stars .off { color: rgba(255,255,255,.18); }
.rank { font-size: 56px; font-weight: 900; color: var(--accent); line-height: 1.1; }
.stats { display: grid; grid-template-columns: auto auto; gap: 6px 16px; justify-content: center; margin: 12px 0; }
.stats dt { color: var(--muted); text-align: right; }
.stats dd { margin: 0; text-align: left; font-weight: 700; font-variant-numeric: tabular-nums; }
.best { color: var(--accent); min-height: 1.2em; }
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.actions button { padding: 14px; border-radius: 999px; background: var(--accent); color: #3b1d05; font-weight: 800; font-size: 17px; }
.actions button.ghost { background: rgba(255,255,255,.1); color: var(--ink); }
