/* ═══════════════ Cadenza · 琴瀑 ═══════════════ */
:root {
  --bg: #0d1022;
  --bg2: #131735;
  --panel: rgba(255, 255, 255, 0.05);
  --panel-2: rgba(255, 255, 255, 0.09);
  --line: rgba(255, 255, 255, 0.10);
  --text: #eef0ff;
  --text-dim: #9aa1c9;
  --accent: #7c5cff;
  --accent-2: #38bdf8;
  --gold: #ffd166;
  --danger: #ff5d73;
  --radius: 14px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: radial-gradient(1200px 800px at 70% -10%, #1d2450 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
#app { height: 100dvh; display: flex; flex-direction: column; }

.hidden { display: none !important; }
.screen { height: 100%; display: flex; flex-direction: column; overflow: hidden; }

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
.btn {
  display: block; width: 100%; padding: 13px 18px; margin-top: 10px;
  border-radius: var(--radius); background: var(--panel-2);
  border: 1px solid var(--line); font-size: 16px; font-weight: 600;
  transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; color: #fff; box-shadow: 0 6px 24px rgba(124, 92, 255, .35); }
.btn.ghost { background: transparent; }
.btn.danger { background: rgba(255, 93, 115, .15); border-color: rgba(255, 93, 115, .4); color: var(--danger); }
.btn:disabled { opacity: .4; cursor: default; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; font-size: 19px;
  background: var(--panel); border: 1px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform .08s ease;
}
.icon-btn:active { transform: scale(.92); }

/* ═══════ 主菜单 ═══════ */
.menu-header {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 16, 34, .7); backdrop-filter: blur(10px);
}
.logo { display: flex; align-items: baseline; gap: 8px; }
.logo-main {
  font-size: 26px; font-weight: 800; letter-spacing: .5px;
  background: linear-gradient(120deg, #fff 20%, var(--accent-2) 60%, var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.logo-sub { font-size: 14px; color: var(--text-dim); letter-spacing: 6px; }
.player-chip { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 220px; }
.level-badge {
  padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
}
.exp-bar { flex: 1; max-width: 180px; height: 8px; border-radius: 99px; background: var(--panel-2); overflow: hidden; }
#exp-fill { height: 100%; width: 0%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .4s ease; }
.meta-counts { display: flex; gap: 12px; font-size: 14px; color: var(--text-dim); white-space: nowrap; }
.star-count b { color: var(--gold); }
.crown-count b { color: #ffe9a8; }
.header-actions { display: flex; gap: 8px; margin-left: auto; }

#collection-list { flex: 1; overflow-y: auto; padding: 14px 16px 40px; scroll-behavior: smooth; }
#collection-list::-webkit-scrollbar { width: 8px; }
#collection-list::-webkit-scrollbar-thumb { background: var(--panel-2); border-radius: 99px; }

.collection { margin-bottom: 22px; }
.collection-head {
  display: flex; align-items: center; gap: 10px; padding: 6px 4px 10px;
  position: sticky; top: 0; z-index: 2;
  background: linear-gradient(180deg, var(--bg) 60%, transparent);
}
.collection-icon { font-size: 20px; }
.collection-name { font-size: 17px; font-weight: 700; }
.collection-progress { font-size: 12px; color: var(--text-dim); margin-left: auto; }
.collection-lock {
  font-size: 12px; color: var(--gold); margin-left: auto;
  background: rgba(255, 209, 102, .12); padding: 4px 10px; border-radius: 99px;
}
.collection.locked .song-card { filter: grayscale(.7) brightness(.6); pointer-events: none; }

.song-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.song-card {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer; transition: transform .1s ease, background .15s ease;
  position: relative; overflow: hidden;
}
.song-card:hover { background: var(--panel-2); }
.song-card:active { transform: scale(.98); }
.song-card::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--card-accent, var(--accent));
}
.song-info { flex: 1; min-width: 0; }
.song-title { font-size: 15px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-composer { font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-meta { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.diff-dots { display: inline-flex; gap: 3px; }
.diff-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--panel-2); }
.diff-dot.on { background: var(--card-accent, var(--accent)); }
.pro-badge {
  font-size: 10px; font-weight: 800; letter-spacing: 1px; color: #ffb703;
  border: 1px solid rgba(255, 183, 3, .5); border-radius: 5px; padding: 1px 5px;
}
.song-right { text-align: right; flex-shrink: 0; }
.song-stars { color: var(--gold); font-size: 13px; letter-spacing: 1px; }
.song-stars .off { color: rgba(255, 255, 255, .15); }
.song-crowns { color: #ffe9a8; font-size: 12px; }
.song-best { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.menu-footer {
  padding: 10px; text-align: center; font-size: 12px; color: var(--text-dim);
  border-top: 1px solid var(--line);
}

/* ═══════ 游戏 ═══════ */
#screen-game { position: relative; background: #000; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 0;
  pointer-events: none;
}
#hud > * { pointer-events: auto; }
#hud-score {
  font-size: 44px; font-weight: 800; color: #fff;
  text-shadow: 0 2px 18px rgba(0, 0, 0, .5); font-variant-numeric: tabular-nums;
}
#hud-crowns { font-size: 20px; color: var(--gold); min-width: 42px; padding-top: 8px; text-shadow: 0 1px 8px rgba(0,0,0,.6); }
#btn-pause { background: rgba(255, 255, 255, .12); }

.game-overlay {
  position: absolute; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 8, 20, .72); backdrop-filter: blur(6px);
}
.overlay-card {
  width: min(320px, 86vw); padding: 26px 22px; text-align: center;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.overlay-card h2 { font-size: 22px; margin-bottom: 6px; }
.overlay-card p { color: var(--text-dim); font-size: 14px; margin-bottom: 10px; }
#countdown-num {
  font-size: 110px; font-weight: 800; color: #fff;
  text-shadow: 0 0 60px var(--accent);
  animation: pop .9s ease infinite;
}
@keyframes pop { 0% { transform: scale(1.25); opacity: .2; } 25% { transform: scale(1); opacity: 1; } 100% { opacity: 1; } }

/* ═══════ 结算 ═══════ */
#screen-results { align-items: center; justify-content: center; overflow-y: auto; }
.results-card {
  width: min(400px, 92vw); padding: 30px 26px; text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 24px;
  margin: 20px 0;
}
.res-label { font-size: 13px; letter-spacing: 4px; color: var(--text-dim); text-transform: uppercase; }
#res-song-title { font-size: 24px; margin-top: 6px; }
#res-song-composer { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
#res-stars { font-size: 44px; margin: 14px 0 4px; letter-spacing: 8px; }
.res-star { color: rgba(255, 255, 255, .14); transition: color .3s, text-shadow .3s; }
.res-star.lit { color: var(--gold); text-shadow: 0 0 24px rgba(255, 209, 102, .7); animation: starPop .45s ease both; }
@keyframes starPop { 0% { transform: scale(.3); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
#res-score { font-size: 52px; font-weight: 800; font-variant-numeric: tabular-nums; }
#res-newbest {
  display: inline-block; margin-top: 6px; padding: 4px 14px; border-radius: 99px;
  background: linear-gradient(135deg, var(--gold), #ff9e42); color: #3c2a00;
  font-size: 13px; font-weight: 800; animation: starPop .5s ease both;
}
.res-grid { margin: 18px 0 8px; border-top: 1px solid var(--line); }
.res-row {
  display: flex; justify-content: space-between; padding: 9px 6px;
  border-bottom: 1px solid var(--line); font-size: 14px; color: var(--text-dim);
}
.res-row b { color: var(--text); font-variant-numeric: tabular-nums; }
.res-row.perfect b { color: var(--gold); }
.res-row.great b { color: var(--accent-2); }

/* ═══════ 弹窗 ═══════ */
#modal-root {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 8, 20, .6); backdrop-filter: blur(5px);
}
.modal {
  width: min(440px, 92vw); max-height: 84dvh; display: flex; flex-direction: column;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 20px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .55);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { font-size: 18px; }
.modal-body { padding: 16px 18px 22px; overflow-y: auto; }
.set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px 2px; border-bottom: 1px solid var(--line); font-size: 15px;
}
.set-row input[type="range"] { width: 46%; accent-color: var(--accent); }
.set-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }
.set-row select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; font: inherit;
}
.keys-hint b { letter-spacing: 4px; color: var(--accent-2); }
.confirm-btns { display: flex; gap: 10px; }
.confirm-btns .btn { margin-top: 14px; }

#ach-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.ach-card {
  display: flex; gap: 12px; align-items: center; padding: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
}
.ach-card.locked { opacity: .45; filter: grayscale(1); }
.ach-icon { font-size: 26px; width: 40px; text-align: center; }
.ach-name { font-weight: 700; font-size: 14px; }
.ach-desc { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.ach-done { margin-left: auto; color: #6ee7a0; font-size: 18px; }

#stats-list .res-row { font-size: 15px; }

/* ═══════ 成就 Toast ═══════ */
#toast-root {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 14px); left: 50%;
  transform: translateX(-50%); z-index: 99;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg2); border: 1px solid var(--gold); border-radius: 99px;
  padding: 10px 20px; box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
  animation: toastIn .35s ease both, toastOut .4s ease 3.4s both;
  font-size: 14px; white-space: nowrap;
}
.toast .t-icon { font-size: 20px; }
.toast b { color: var(--gold); }
@keyframes toastIn { from { transform: translateY(-30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastOut { to { transform: translateY(-30px); opacity: 0; } }

@media (max-width: 560px) {
  .song-grid { grid-template-columns: 1fr; }
  #hud-score { font-size: 36px; }
  .menu-header { gap: 8px; }
  .player-chip { order: 3; min-width: 100%; }
}
