:root {
  --bg: #f6f5f2; --panel: #ffffff; --fg: #1d1d1f; --muted: #6b6b70; --line: #d9d7d2;
  --accent: #c2410c; --accent-fg: #ffffff; --danger: #b42318; --warn-bg: #fff7e6;
  --roll-bg: #ffffff; --roll-black-row: rgba(0,0,0,0.045); --roll-grid: rgba(0,0,0,0.14); --roll-bar: rgba(0,0,0,0.28);
  --key-white: #ffffff; --key-black: #222226; --key-line: #9a9a9f;
  --s0: #2563eb; --s1: #16a34a; --s2: #c026d3; --s3: #d97706; --s4: #0891b2; --s5: #dc2626; --s6: #7c3aed; --s7: #65a30d;
  --radius: 8px;
  --sv-paper: #fffdf8; --sv-ink: #1a1a1a; --sv-soft: #9a9a9a; --sv-staff: #444444; --sv-mark: #d83a2e;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141416; --panel: #1d1d20; --fg: #ececee; --muted: #a0a0a8; --line: #34343a;
    --accent: #fb923c; --accent-fg: #1a1a1a; --danger: #f97066; --warn-bg: #2b2414;
    --roll-bg: #18181b; --roll-black-row: rgba(255,255,255,0.04); --roll-grid: rgba(255,255,255,0.12); --roll-bar: rgba(255,255,255,0.3);
    --key-white: #e9e9ec; --key-black: #0c0c0e; --key-line: #55555c;
    --s0: #60a5fa; --s1: #4ade80; --s2: #e879f9; --s3: #fbbf24; --s4: #22d3ee; --s5: #f87171; --s6: #a78bfa; --s7: #a3e635;
    --sv-paper: #16171c; --sv-ink: #ececec; --sv-soft: #808086; --sv-staff: #b8b8c0; --sv-mark: #ff6b5e;
  }
}
:root[data-theme="dark"] {
  --bg: #141416; --panel: #1d1d20; --fg: #ececee; --muted: #a0a0a8; --line: #34343a;
  --accent: #fb923c; --accent-fg: #1a1a1a; --danger: #f97066; --warn-bg: #2b2414;
  --roll-bg: #18181b; --roll-black-row: rgba(255,255,255,0.04); --roll-grid: rgba(255,255,255,0.12); --roll-bar: rgba(255,255,255,0.3);
  --key-white: #e9e9ec; --key-black: #0c0c0e; --key-line: #55555c;
  --sv-paper: #16171c; --sv-ink: #ececec; --sv-soft: #808086; --sv-staff: #b8b8c0; --sv-mark: #ff6b5e;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif; }
#app { display: flex; flex-direction: column; height: 100dvh; padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); gap: 8px; max-width: 1400px; margin: 0 auto; }
.bar { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.bar h1 { font-size: 18px; margin: 0; }
.ver { font: 12px ui-monospace, Consolas, monospace; color: var(--muted); }
.open, .transport, .controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--panel); color: var(--fg); font: inherit; cursor: pointer; user-select: none; white-space: nowrap; flex: none; }
.btn:hover { border-color: var(--muted); }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.small { min-height: 32px; padding: 0 10px; }
.btn.icon { min-width: 44px; padding: 0 8px; font-size: 17px; }
.btn:disabled { opacity: 0.45; cursor: default; }
select { min-height: 36px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); color: var(--fg); font: inherit; max-width: 100%; }
.chk { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.hint, .muted { color: var(--muted); font-size: 13px; }
.mono { font: 13px ui-monospace, Consolas, monospace; white-space: nowrap; }
.msg { padding: 8px 12px; border-radius: var(--radius); background: var(--warn-bg); border: 1px solid var(--line); }
.msg.err { border-color: var(--danger); color: var(--danger); }
.info { display: flex; flex-direction: column; gap: 2px; }
.info .title { font-size: 16px; }
.info ul { margin: 4px 0; padding-left: 20px; font-size: 13px; }
.stage { position: relative; flex: 1 1 auto; min-height: 140px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--roll-bg); }
#roll { width: 100%; height: 100%; display: block; touch-action: none; }
.zoom { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 6px; z-index: 2; }
/* 악보 화면 (조판) — 색은 PC 판 Palette 와 같은 값 */
.stage.v-score { background: var(--sv-paper); min-height: 45vh; }
.stage.v-score #roll, .stage.v-roll .score { display: none; }
.score { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; overflow-anchor: none; }
.sv-inner { position: relative; }
.sys { position: absolute; left: 0; }
.sys > svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.sv { color: var(--sv-ink); }
.sv .ti { color: var(--sv-ink); } .sv .ts { color: var(--sv-soft); } .sv .tf { color: var(--sv-staff); } .sv .tm { color: var(--sv-mark); }
.sv path, .sv use, .sv rect, .sv text { fill: currentColor; }
.sv line { stroke: currentColor; stroke-linecap: butt; }
.sv line.dash { stroke-dasharray: 0.5 0.4; }
.sv rect.reh { fill: none; stroke: currentColor; stroke-width: 0.12; }
.sv text { font-family: "Times New Roman", Times, "Liberation Serif", "Batang", serif; white-space: pre; }
.sv .s-TIME_SIG { font-weight: 700; }
.sv .s-DYNAMIC, .sv .s-PEDAL, .sv .s-TUPLET { font-weight: 700; font-style: italic; }
.sv .s-TEMPO, .sv .s-REHEARSAL, .sv .s-FINGERING { font-family: Arial, Helvetica, "Liberation Sans", "Malgun Gothic", sans-serif; font-weight: 700; }
.sv .s-WORDS, .sv .s-MEASURE_NO { font-style: italic; }
.sv .s-LABEL, .sv .s-LYRIC { font-family: Arial, Helvetica, "Liberation Sans", "Malgun Gothic", sans-serif; }
.stage.v-score .zoom .btn { opacity: 0.85; }
/* 줄 왼쪽 악기 표 (0.7.0) */
.chip { position: absolute; left: 3px; max-width: calc(100% - 6px); display: inline-flex; align-items: center; gap: 4px; padding: 0 5px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--fg); font: 12px/1 system-ui, sans-serif; cursor: pointer; overflow: hidden; white-space: nowrap; z-index: 1; touch-action: manipulation; }
.chip .ctx { overflow: hidden; text-overflow: ellipsis; }
.chip.picked { border-color: var(--accent); }
.chip.warn { border-color: var(--danger); color: var(--danger); }
.chip.muted { opacity: 0.55; }
.cdot { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; }
.staff-pop { position: fixed; z-index: 20; width: min(360px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); overflow-y: auto; padding: 10px 12px; border-radius: var(--radius);
  background: var(--panel); color: var(--fg); border: 1px solid var(--line); box-shadow: 0 8px 28px rgba(0,0,0,0.25); display: flex; flex-direction: column; gap: 8px; }
.staff-pop.sheet { left: 0; right: 0; bottom: 0; top: auto; width: 100%; max-height: 72dvh; border-radius: 12px 12px 0 0; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
.pop-head { display: flex; align-items: center; gap: 8px; } .pop-head b { flex: 1; }
.pop-note { font-size: 12px; color: var(--muted); }
.favs { display: flex; flex-wrap: wrap; gap: 6px; }
.btn.fav { min-height: 40px; } .btn.fav.on { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.pop-sel, .inst-sel { min-height: 40px; width: 100%; }
.pop-row { display: flex; flex-wrap: wrap; gap: 6px; }
.gain { display: flex; align-items: center; gap: 8px; } .gain input { flex: 1; min-width: 90px; } .gain .mono { width: 7.5em; }
.inst-panel { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; background: var(--panel); display: flex; flex-direction: column; gap: 6px; }
.inst-top { display: flex; flex-wrap: wrap; gap: 6px; }
.inst-rows { display: flex; flex-direction: column; gap: 4px; }
.inst-row { display: grid; grid-template-columns: minmax(7em, 1.2fr) minmax(10em, 2fr) auto minmax(10em, 2fr) auto; align-items: center; gap: 8px; }
.inst-name { display: inline-flex; align-items: center; gap: 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.warn-t { color: var(--danger); font-size: 12px; }
@media (max-width: 640px) {
  .inst-row { grid-template-columns: 1fr auto; grid-template-areas: "n m" "s s" "g o"; }
  .inst-row > :nth-child(1) { grid-area: n; } .inst-row > :nth-child(2) { grid-area: s; } .inst-row > :nth-child(3) { grid-area: m; }
  .inst-row > :nth-child(4) { grid-area: g; } .inst-row > :nth-child(5) { grid-area: o; }
  .inst-row { border-bottom: 1px solid var(--line); padding-bottom: 6px; }
}
.playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); opacity: 0.85; pointer-events: none; }
.sv-state { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); color: var(--muted); font-size: 14px; pointer-events: none; text-align: center; }
#svDefs { position: absolute; width: 0; height: 0; overflow: hidden; }
#pos { flex: 1 1 200px; min-width: 120px; }
.controls label { display: inline-flex; align-items: center; gap: 6px; }
#speed { width: 140px; } #vol { width: 100px; } #hlDelay { width: 64px; min-height: 32px; }
#hands { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.hand { display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 0 8px; border-radius: 16px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 13px; }
.hand .dot { width: 10px; height: 10px; border-radius: 50%; }
.hand.off { opacity: 0.45; text-decoration: line-through; }
#keys { width: 100%; height: 110px; flex: 0 0 auto; display: block; touch-action: none; border-radius: 4px; }
.status { font-size: 12px; color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; }
.ask { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border: 1px solid var(--accent); border-radius: var(--radius); background: var(--warn-bg); font-size: 13px; }
.credits { font-size: 12px; color: var(--muted); } .credits summary { cursor: pointer; } .credits div { margin: 2px 0 2px 14px; }
.drop #app { outline: 3px dashed var(--accent); outline-offset: -6px; }
@media (max-width: 640px) {
  #app { padding: 6px 16px calc(6px + env(safe-area-inset-bottom)); gap: 6px; height: auto; min-height: 100dvh; }
  .stage { flex: none; height: 40vh; }
  .stage.v-score { height: 52vh; }
  .bar h1 { font-size: 16px; }
  .hint { display: none; }
  #speed { width: 110px; }
  #keys { height: 90px; }
}
/* 폰: 재생 조작 줄은 늘 화면 아래에 붙어 보인다 (스크롤해도) */
@media (max-width: 640px), (max-height: 500px) {
  .transport { position: sticky; bottom: 0; z-index: 5; background: var(--bg); padding: 4px 0; flex-wrap: nowrap; }
  .transport #pos { min-width: 60px; }
  /* 마디·빠르기 글자가 길면 줄이고 넘치지 않게 — 넘치면 폰 화면 전체가 옆으로 넓어져 아래 창이 잘렸다 (0.7.0) */
  .transport .mono { min-width: 0; overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; }
  .transport #time { flex: none; }
}
/* 폰 가로 (높이 320~500): 판 번호·열기·롤·조작·건반이 한 화면에, 나머지 설정은 아래로 스크롤 */
@media (max-height: 500px) and (orientation: landscape) {
  .info, .bar h1, .hint, #dropHint { display: none; }
  #app { height: auto; min-height: 100dvh; padding: 2px 16px calc(4px + env(safe-area-inset-bottom)); gap: 4px; }
  .bar { line-height: 1; } .ver { font-size: 10px; }
  .open { flex-wrap: nowrap; overflow-x: auto; gap: 6px; }
  .open select { max-width: 30vw; min-height: 32px; }
  .btn { min-height: 34px; padding: 0 10px; } .btn.icon { min-width: 40px; }
  .stage { flex: none; min-height: 80px; height: calc(100dvh - 172px); }
  .transport .mono { font-size: 12px; }
  #keys { order: 1; height: 52px; }
  .controls { order: 2; font-size: 13px; }
  #status { order: 3; }
}
