:root {
  --bg: #14161c; --panel: #1d2029; --panel2: #262a36; --line: #333848;
  --text: #eceef4; --muted: #9aa1b4; --dim: #4b5266; --accent: #6ea8ff; --accent-ink: #0b1220;
  --on: #ffffff;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f5f8; --panel: #ffffff; --panel2: #eceef4; --line: #d4d8e3;
  --text: #1a1d27; --muted: #5d6479; --dim: #c3c8d6; --accent: #2f6fe0; --accent-ink: #ffffff;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Pretendard", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  line-height: 1.5; font-size: 16px;
}
.hidden { display: none !important; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
code { background: var(--panel2); padding: 0 .3em; border-radius: 4px; }

.screen { min-height: 100%; }
#home { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }

/* 공통 버튼 */
.primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px; font-weight: 700; padding: .7em 1.2em; }
.primary:disabled { opacity: .4; cursor: not-allowed; }
.primary.big { width: 100%; font-size: 1.2rem; padding: .9em; margin: 20px 0; }
.primary.round { width: 64px; height: 64px; border-radius: 50%; font-size: 1.5rem; padding: 0; }
.ghost { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: .55em .9em; }
.ghost.small { padding: .35em .7em; font-size: .9rem; }
.ghost:active, .seg button:active { filter: brightness(1.2); }
.linkbtn { color: var(--text); text-decoration: none; display: inline-block; }

/* 메인 */
.top { display: flex; align-items: baseline; gap: 12px; padding: 8px 0 4px; }
.top h1 { margin: 0; font-size: 1.8rem; letter-spacing: -.02em; }
.top .sub { margin: 0; color: var(--muted); flex: 1; }
section { margin-top: 22px; }
h2 { font-size: 1rem; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
h3 { font-size: .95rem; margin: 18px 0 8px; color: var(--muted); }
.step { background: var(--accent); color: var(--accent-ink); width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; font-size: .8rem; font-weight: 700; }
.hint { color: var(--muted); font-size: .88rem; margin: 6px 0; }
.row-actions { margin-top: 8px; }

.songs { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.song { text-align: left; background: var(--panel); border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; min-height: 64px; }
.song .num { color: var(--muted); font-size: .8rem; }
.song .ttl { font-weight: 600; display: block; word-break: keep-all; }
.song.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--panel)); }
.song.off { opacity: .45; cursor: not-allowed; }
.song .tag { font-size: .75rem; color: var(--muted); }

.partBtns { display: flex; flex-wrap: wrap; gap: 8px; }
.partBtns button { flex: 1 1 90px; background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: .7em .4em; font-weight: 600; border-left-width: 6px; border-left-color: var(--pc, var(--line)); }
.partBtns button.on { background: color-mix(in srgb, var(--pc, var(--accent)) 28%, var(--panel)); border-color: var(--pc, var(--accent)); }
.partBtns .empty { color: var(--muted); font-size: .9rem; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; background: var(--panel); border: 0; padding: .7em .3em; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; }

.chk { display: flex; align-items: center; gap: 8px; margin: 10px 0 2px; }
.chk input { width: 20px; height: 20px; accent-color: var(--accent); }
.slider { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.slider > span { min-width: 4.5em; color: var(--muted); font-size: .9rem; }
.slider input[type=range] { flex: 1; accent-color: var(--accent); }
.slider select { flex: 1; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .4em; }
.slider output { min-width: 3.5em; text-align: right; color: var(--muted); font-size: .9rem; }

.guide { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px; margin-top: 12px; }
.guide summary { cursor: pointer; font-weight: 700; padding: 10px 0; }
.guide ol, .guide ul { padding-left: 1.3em; margin: 0 0 10px; }
.guide li { margin: 6px 0; }
.guide ul ul { margin: 2px 0; color: var(--muted); font-size: .92rem; }

/* 연습 화면 */
#practice { display: flex; flex-direction: column; height: 100dvh; min-height: 0; overflow: hidden; }
#practice.hidden { display: none; }
.pbar { display: flex; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 12px 6px; }
.ptitle { flex: 1; min-width: 0; display: flex; gap: 10px; align-items: baseline; }
#pTitle { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.barno { color: var(--accent); font-variant-numeric: tabular-nums; font-size: .95rem; white-space: nowrap; }

.rows { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 6px; padding: 4px 12px; }
.lrow { flex: 1 1 0; min-height: 0; position: relative; background: var(--panel); border-radius: 14px; border-left: 6px solid var(--pc);
  display: flex; flex-direction: column; justify-content: center; padding: 6px 14px 6px 12px; overflow: hidden; }
.lrow.mine { background: color-mix(in srgb, var(--pc) 14%, var(--panel)); }
.lrow.big { flex-grow: 3.4; }
.lrow.small { flex-grow: .8; opacity: .8; }
/* 글자 크기는 각 파트 줄(container)의 가로·세로 크기에 맞춰 자동 조절 */
.lrow { container-type: size; }
.lrow.big .cur { font-size: calc(max(13px, min(27cqh, 7cqw)) * var(--fs, 1)); }
.lrow.big .nxt { font-size: calc(max(12px, min(14cqh, 4cqw)) * var(--fs, 1)); }
.lrow.big .beat { font-size: calc(max(22px, min(40cqh, 9cqw)) * var(--fs, 1)); }
.lrow.big.hasbeat .cur, .lrow.big.hasbeat .nxt { padding-inline: calc(max(22px, min(40cqh, 9cqw)) * var(--fs, 1) * 1.15); }
.lrow.mid .cur { font-size: calc(max(13px, min(31cqh, 6cqw)) * var(--fs, 1)); }
.lrow.mid .nxt { font-size: calc(max(12px, min(17cqh, 3cqw)) * var(--fs, 1)); }
.lrow.mid .beat { font-size: calc(max(22px, min(50cqh, 7cqw)) * var(--fs, 1)); }
.lrow.mid.hasbeat .cur, .lrow.mid.hasbeat .nxt { padding-inline: calc(max(22px, min(50cqh, 7cqw)) * var(--fs, 1) * 1.15); }
.lrow.small .cur { font-size: calc(max(13px, min(40cqh, 4.6cqw)) * var(--fs, 1)); }
.lrow.small .beat { font-size: calc(max(22px, min(60cqh, 5cqw)) * var(--fs, 1)); }
.lrow.small.hasbeat .cur, .lrow.small.hasbeat .nxt { padding-inline: calc(max(22px, min(60cqh, 5cqw)) * var(--fs, 1) * 1.15); }
@media (orientation: portrait) {
.lrow.big .cur { font-size: calc(max(13px, min(15cqh, 10.5cqw)) * var(--fs, 1)); }
.lrow.big .nxt { font-size: calc(max(12px, min(9cqh, 6.4cqw)) * var(--fs, 1)); }
.lrow.big .beat { font-size: calc(max(22px, min(30cqh, 14cqw)) * var(--fs, 1)); }
.lrow.big.hasbeat .cur, .lrow.big.hasbeat .nxt { padding-inline: calc(max(22px, min(30cqh, 14cqw)) * var(--fs, 1) * 1.15); }
.lrow.mid .cur { font-size: calc(max(13px, min(27cqh, 8.4cqw)) * var(--fs, 1)); }
.lrow.mid .nxt { font-size: calc(max(12px, min(15cqh, 4.6cqw)) * var(--fs, 1)); }
.lrow.mid .beat { font-size: calc(max(22px, min(50cqh, 11cqw)) * var(--fs, 1)); }
.lrow.mid.hasbeat .cur, .lrow.mid.hasbeat .nxt { padding-inline: calc(max(22px, min(50cqh, 11cqw)) * var(--fs, 1) * 1.15); }
.lrow.small .cur { font-size: calc(max(13px, min(38cqh, 6.6cqw)) * var(--fs, 1)); }
.lrow.small .beat { font-size: calc(max(22px, min(60cqh, 8cqw)) * var(--fs, 1)); }
.lrow.small.hasbeat .cur, .lrow.small.hasbeat .nxt { padding-inline: calc(max(22px, min(60cqh, 8cqw)) * var(--fs, 1) * 1.15); }
}
.lab { position: absolute; top: 4px; left: 12px; font-size: .75rem; color: var(--pc); font-weight: 700; letter-spacing: .02em; }
.lab .me { background: var(--pc); color: var(--bg); border-radius: 6px; padding: 0 .4em; margin-left: 4px; }
.cur, .nxt { text-align: center; word-break: keep-all; overflow-wrap: anywhere; line-height: 1.35; padding-top: .5em; }
.cur { font-weight: 700; min-height: 1.35em; }
.nxt { color: var(--muted); opacity: .8; font-weight: 600; font-size: 1rem; margin-top: 4px; min-height: 1.2em; padding-top: 0; }
.lrow.small .nxt { display: none; }
.syl { color: var(--dim); transition: none; }
.syl.sp { margin-right: .35em; }
.syl.done { color: var(--pc); }
.syl.act { background: linear-gradient(90deg, var(--pc) calc(var(--p, 0) * 100%), var(--dim) calc(var(--p, 0) * 100%)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lrow.wait .cur .syl { color: var(--muted); opacity: .75; }
.beat { position: absolute; left: 18px; top: 50%; transform: translateY(-50%); font-weight: 800; color: var(--pc); line-height: 1; font-variant-numeric: tabular-nums; pointer-events: none; }
.beat.pop { animation: pop .35s ease-out; }
@keyframes pop { from { transform: translateY(-50%) scale(1.5); opacity: .4; } to { transform: translateY(-50%) scale(1); opacity: 1; } }
.cd { position: absolute; top: 4px; right: 12px; font-size: .85rem; font-weight: 700; color: var(--muted); }
.cd.flash { color: var(--on); background: var(--pc); border-radius: 8px; padding: 0 .6em; animation: blink .5s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }

.ctrl { padding: 6px 14px calc(10px + env(safe-area-inset-bottom)); }
.seek { display: flex; align-items: center; gap: 10px; font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.seek input { flex: 1; height: 28px; accent-color: var(--accent); }
.quick { display: flex; align-items: center; gap: 12px; padding: 0 14px 4px; font-size: .9rem; }
.quick .chk { margin: 0; white-space: nowrap; }
.quick input[type=range] { flex: 1; max-width: 360px; height: 32px; accent-color: var(--accent); }
.quick output { min-width: 2.2em; color: var(--muted); font-variant-numeric: tabular-nums; }
.btns { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 4px; }
.btns .ghost { min-width: 48px; height: 44px; }
#btnLoop.on { background: var(--accent); color: var(--accent-ink); }

.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet-body { background: var(--bg); width: min(560px, 100%); max-height: 88dvh; overflow: auto; border-radius: 18px 18px 0 0; padding: 14px 16px calc(24px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet section { margin-top: 14px; }
.sheet .step { display: none; }
.loop { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.loop input[type=number] { width: 4.5em; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .3em .4em; }
.loop .chk { margin: 0; }

@media (orientation: portrait) and (max-width: 600px) {
  .lrow.big { flex-grow: 2.4; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .pbar { padding-top: 4px; padding-bottom: 2px; }
  .ctrl { padding-top: 2px; }
  .btns { margin-top: 0; }
  .primary.round { width: 48px; height: 48px; font-size: 1.2rem; }
  .btns .ghost { height: 36px; }
  .lrow { padding-top: 2px; padding-bottom: 2px; }
  .cur { padding-top: .6em; }
}

/* 오프라인 저장 */
.song-actions { margin-top: 10px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; font-size: .92rem; }
.sa-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.song.saved .tag { color: var(--accent); font-weight: 600; }
.dl { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 20; padding: 16px; }
.dl-box { background: var(--bg); border: 1px solid var(--line); border-radius: 16px; padding: 18px; width: min(420px, 100%); }
.dl-box progress { width: 100%; height: 14px; margin: 10px 0 6px; accent-color: var(--accent); }
.dl-row { display: flex; justify-content: space-between; align-items: center; }

.upd { position: sticky; top: 0; z-index: 5; margin: 0 0 8px; padding: 8px 12px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-size: .9rem; font-weight: 600; text-align: center; }
