:root {
  --bg: #0a0618; --panel: #151030; --panel2: #1e1742; --line: rgba(167, 139, 250, 0.22);
  --text: #f1f5f9; --dim: #a5a3c4; --accent: #c084fc; --ok: #4ade80; --bad: #f87171; --gold: #facc15;
  --r: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh; min-height: 100dvh;
  background: radial-gradient(circle at 50% 10%, #1d1440 0%, #0a0618 60%, #030208 100%) fixed, var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
  overflow-x: hidden;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); max-width: 820px; margin: 0 auto; }
.back-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px;
  background: rgba(167, 139, 250, 0.12); border: 1px solid rgba(167, 139, 250, 0.3); color: #c4b5fd;
  text-decoration: none; font-size: 0.85rem; font-weight: 700; white-space: nowrap;
}
.back-btn:hover { background: rgba(167, 139, 250, 0.24); }
.title { font-size: 1.02rem; margin: 0 auto 0 4px; white-space: nowrap; }
.title span { background: linear-gradient(90deg, #c084fc, #67e8f9, #f472b6); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stars { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mini { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); font-weight: 800; flex: none; }
@media (max-width: 420px) { .back-txt { display: none; } .title { font-size: 0.95rem; } }

.modes { display: flex; gap: 4px; max-width: 820px; margin: 0 auto; padding: 0 12px 8px; }
.mode { flex: 1; padding: 9px 4px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-weight: 700; font-size: 0.86rem; white-space: nowrap; }
.mode.on { background: linear-gradient(135deg, rgba(192,132,252,0.32), rgba(103,232,249,0.2)); border-color: rgba(192,132,252,0.7); }

#app { max-width: 820px; margin: 0 auto; padding: 0 12px 24px; }
.panel { padding-top: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 8px 13px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2);
  font-weight: 700; font-size: 0.88rem; white-space: nowrap; touch-action: manipulation;
}
.btn:hover { border-color: rgba(192,132,252,0.6); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn.small { padding: 6px 10px; font-size: 0.82rem; }
.btn.icon { width: 40px; padding: 8px 0; }
.btn.primary { background: linear-gradient(135deg, #a855f7, #6366f1); border-color: transparent; }
.btn.ok { background: linear-gradient(135deg, #10b981, #0891b2); border-color: transparent; }
.btn.rec.on { background: linear-gradient(135deg, #f43f5e, #f97316); border-color: transparent; animation: blink 1s infinite; }
.btn.on { background: linear-gradient(135deg, #0ea5e9, #6366f1); border-color: transparent; }
@keyframes blink { 50% { filter: brightness(1.35); } }

.toolrow { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.sel { display: inline-flex; align-items: center; gap: 4px; font-size: 0.85rem; color: var(--dim); }
select { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; font-size: 0.85rem; color: var(--text); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 7px 10px; font-size: 0.82rem; font-weight: 700; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: rgba(192,132,252,0.32); }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 11px; font-size: 0.8rem; font-weight: 700; }
.chip.on { background: rgba(103,232,249,0.2); border-color: rgba(103,232,249,0.6); }
.rec-info { font-size: 0.8rem; color: var(--dim); font-variant-numeric: tabular-nums; }

/* ── 무대 ── */
#stage { position: relative; height: calc(100dvh - 210px); min-height: 380px; max-height: 760px; display: flex; flex-direction: column; justify-content: flex-end; }
body.playing #stage { height: calc(100dvh - 110px); }
#fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }
.judge { position: absolute; left: 0; right: 0; top: 30%; text-align: center; font-weight: 900; font-size: 1.6rem; letter-spacing: 0.04em; z-index: 4; pointer-events: none; opacity: 0; text-shadow: 0 0 14px currentColor; }
.judge.show { animation: pop 0.5s ease-out; }
@keyframes pop { 0% { opacity: 0; transform: scale(0.7); } 15% { opacity: 1; transform: scale(1.1); } 70% { opacity: 1; } 100% { opacity: 0; transform: translateY(-14px); } }

.kalimba {
  position: relative; z-index: 2; margin: 0 auto; width: 100%; max-width: 720px;
  background: linear-gradient(180deg, rgba(36, 24, 72, 0.85) 0%, rgba(20, 12, 45, 0.97) 100%);
  border: 2px solid rgba(167, 139, 250, 0.3); border-radius: 26px 26px 44px 44px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6), inset 0 0 30px rgba(167,139,250,0.15);
  padding: 30px 10px 70px; touch-action: none;
}
.bridge { position: absolute; top: 18px; left: 4%; width: 92%; height: 12px; border-radius: 6px; background: linear-gradient(180deg, #cbd5e1, #475569); box-shadow: 0 4px 10px rgba(0,0,0,0.7); z-index: 1; }
.hole { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); width: 64px; height: 50px; border-radius: 50%; background: radial-gradient(circle, #05030a 55%, #1e1338 100%); border: 3px solid rgba(167,139,250,0.4); display: flex; align-items: center; justify-content: center; font-size: 1.2rem; opacity: 0.75; pointer-events: none; }
.tines { display: flex; justify-content: center; align-items: flex-start; gap: 3px; position: relative; }
.tine {
  flex: 1 1 0; max-width: 36px; min-width: 0; height: var(--h, 160px);
  background: linear-gradient(180deg, #e2e8f0 0%, #cbd5e1 60%, #94a3b8 100%);
  border-radius: 3px 3px 12px 12px; position: relative;
  box-shadow: 0 8px 16px rgba(0,0,0,0.5), inset 0 1px 1px rgba(255,255,255,0.8);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding-bottom: 8px;
  transform-origin: top center; transition: transform 0.06s, filter 0.06s;
}
.tine::before { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 5px; border-radius: 0 0 12px 12px; background: var(--c); opacity: 0.75; }
.tine.hit { transform: scaleY(0.965) translateY(3px); background: linear-gradient(180deg, #fff 0%, var(--c) 75%, #94a3b8 100%); box-shadow: 0 0 22px var(--c), 0 2px 8px rgba(0,0,0,0.8); }
.tine.want { box-shadow: 0 0 0 2px var(--c), 0 0 18px var(--c); animation: want 0.8s infinite; }
@keyframes want { 50% { filter: brightness(1.25); } }
.tine .lab { pointer-events: none; text-align: center; line-height: 1; color: #1e1b4b; font-weight: 900; font-size: 0.82rem; }
.tine .dots { display: block; font-size: 0.5rem; letter-spacing: -1px; color: #4338ca; height: 0.6rem; }
.tine .nm { display: block; font-size: 0.6rem; color: #4338ca; font-weight: 800; }
@media (max-width: 520px) {
  .kalimba { padding: 26px 5px 58px; border-radius: 20px 20px 34px 34px; }
  .tines { gap: 2px; }
  .tine .lab { font-size: 0.7rem; }
  .tine .nm { font-size: 0.5rem; }
  .hole { width: 52px; height: 40px; font-size: 1rem; }
}
.foot { text-align: center; color: var(--dim); font-size: 0.78rem; margin: 8px 0 0; }
body.playing .foot, body.playing .modes { display: none; }

/* ── 연주 HUD ── */
#hud { margin-bottom: 4px; }
.hud-row { display: flex; align-items: center; gap: 8px; }
.hud-title { flex: 1; font-weight: 800; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-title small { color: var(--dim); font-weight: 600; }
.hud-score { text-align: right; line-height: 1.1; }
.hud-score b { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.hud-score small { display: block; color: var(--gold); font-weight: 800; font-size: 0.75rem; min-height: 0.9rem; }
.progress { height: 4px; border-radius: 4px; background: rgba(255,255,255,0.08); margin-top: 5px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #c084fc, #67e8f9); }

/* ── 목록 ── */
.chap { margin-bottom: 14px; }
.chap h2 { font-size: 1rem; margin: 6px 0 8px; display: flex; align-items: center; gap: 6px; }
.chap h2 small { color: var(--dim); font-weight: 600; font-size: 0.78rem; }
.chap.locked .songs { opacity: 0.45; pointer-events: none; }
.lockmsg { font-size: 0.8rem; color: var(--gold); margin: -4px 0 8px; }
.songs { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.song {
  text-align: left; border: 1px solid var(--line); background: var(--panel); border-radius: var(--r); padding: 10px 12px;
  display: flex; flex-direction: column; gap: 3px; min-width: 0;
}
.song:hover { border-color: rgba(192,132,252,0.6); }
.song .t { font-weight: 800; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song .f { color: var(--dim); font-size: 0.74rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song .m { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--dim); }
.song .st { color: var(--gold); letter-spacing: 1px; }
.song .st .off { color: rgba(255,255,255,0.18); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; margin-bottom: 10px; }
.card h3 { margin: 0 0 8px; font-size: 0.95rem; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.big { font-size: 1.25rem; font-weight: 900; }
.dim { color: var(--dim); font-size: 0.85rem; }
.sheet { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 0.82rem; line-height: 1.7; background: rgba(0,0,0,0.25); border-radius: 10px; padding: 8px 10px; max-height: 150px; overflow: auto; white-space: pre-wrap; word-break: break-word; color: #ddd6fe; margin: 8px 0; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 8px; }
.cal div { text-align: center; padding: 6px 0; border-radius: 8px; background: rgba(255,255,255,0.04); font-size: 0.75rem; color: var(--dim); }
.cal div.ok { background: rgba(74,222,128,0.2); color: #bbf7d0; }
.cal div.today { outline: 2px solid var(--accent); }
.statgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
.statgrid div { background: rgba(255,255,255,0.04); border-radius: 10px; padding: 8px; font-size: 0.78rem; color: var(--dim); }
.statgrid b { display: block; font-size: 1.05rem; color: var(--text); }
.achs { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.ach { display: flex; gap: 8px; align-items: center; padding: 8px; border-radius: 10px; background: rgba(255,255,255,0.04); opacity: 0.45; }
.ach.got { opacity: 1; background: rgba(250,204,21,0.1); }
.ach i { font-style: normal; font-size: 1.3rem; }
.ach b { display: block; font-size: 0.85rem; }
.ach small { color: var(--dim); font-size: 0.74rem; }

/* ── 모달 ── */
.modal { position: fixed; inset: 0; background: rgba(3, 2, 10, 0.72); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px; width: 100%; max-width: 440px; max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.6); }
.modal-box h2 { margin: 0 0 8px; font-size: 1.15rem; }
.modal-box p { margin: 6px 0; color: #d4d4e8; font-size: 0.9rem; line-height: 1.5; }
.modal-box .row { margin-top: 12px; justify-content: flex-end; }
.modal-box ul { padding-left: 18px; margin: 6px 0; font-size: 0.88rem; line-height: 1.6; color: #d4d4e8; }
.err { font-family: monospace; font-size: 0.75rem; background: rgba(0,0,0,0.4); padding: 8px; border-radius: 8px; white-space: pre-wrap; max-height: 160px; overflow: auto; }
.res-stars { font-size: 2.2rem; text-align: center; letter-spacing: 6px; color: var(--gold); }
.res-stars .off { color: rgba(255,255,255,0.15); }
.res-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; text-align: center; margin: 10px 0; }
.res-grid div { background: rgba(255,255,255,0.05); border-radius: 8px; padding: 6px 0; font-size: 0.72rem; color: var(--dim); }
.res-grid b { display: block; font-size: 1rem; color: var(--text); }
.slot { display: flex; gap: 6px; align-items: center; padding: 8px; border-radius: 10px; background: rgba(255,255,255,0.04); margin-bottom: 6px; }
.slot .nm { flex: 1; min-width: 0; font-size: 0.85rem; }
.slot .nm b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot .nm small { color: var(--dim); }
.modal-box input[type=text] { width: 100%; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); }
.modal-box input[type=range] { width: 100%; accent-color: var(--accent); }
.speedseg { margin-top: 6px; }

.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: rgba(30, 20, 66, 0.96); border: 1px solid rgba(250,204,21,0.5); border-radius: 14px; padding: 10px 16px; font-size: 0.88rem; font-weight: 700; z-index: 60; box-shadow: 0 10px 30px rgba(0,0,0,0.5); max-width: 92vw; text-align: center; }
@media (max-width: 520px) {
  #stage { height: calc(100dvh - 270px); min-height: 340px; }
  body.playing #stage { height: calc(100dvh - 100px); }
}
