:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --ink: #1d1b26;
  --muted: #6b6878;
  --line: #e3dfd5;
  --accent: #2f3e8f;
  --accent-ink: #ffffff;
  --gold: #c08a1e;
  --mine: #2f3e8f;
  --mine-soft: rgba(47, 62, 143, 0.08);
  --bar-hi: rgba(192, 138, 30, 0.16);
  --loop: rgba(47, 62, 143, 0.10);
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14131b; --surface: #1d1c26; --ink: #ecebf2; --muted: #9b98ab; --line: #2e2c3a;
    --accent: #8d9cf0; --accent-ink: #14131b; --gold: #e2b04a; --mine: #9fb0ff;
    --mine-soft: rgba(141,156,240,.10); --bar-hi: rgba(226,176,74,.18); --loop: rgba(141,156,240,.12);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14131b; --surface: #1d1c26; --ink: #ecebf2; --muted: #9b98ab; --line: #2e2c3a;
  --accent: #8d9cf0; --accent-ink: #14131b; --gold: #e2b04a; --mine: #9fb0ff;
  --mine-soft: rgba(141,156,240,.10); --bar-hi: rgba(226,176,74,.18); --loop: rgba(141,156,240,.12);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.top {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; flex: 1; min-width: 0; }
.brand #title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.star { color: var(--gold); font-size: 20px; }
.who { display: flex; gap: 12px; align-items: center; color: var(--muted); font-size: 14px; }
.link { color: var(--accent); text-decoration: none; }
.icon-btn {
  border: 0; background: transparent; padding: 8px; border-radius: 10px; cursor: pointer;
  display: inline-flex; color: var(--ink);
}
.icon-btn:hover { background: var(--mine-soft); }

/* home */
#home { max-width: 760px; width: 100%; margin: 0 auto; padding: 24px 16px 48px; }
.intro h1 { font-family: Georgia, "Times New Roman", serif; font-weight: 500; font-size: 34px; margin: 8px 0 4px; }
.intro p { color: var(--muted); margin: 0 0 20px; }
.my-part { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.label { color: var(--muted); font-size: 14px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 14px; cursor: pointer; font-size: 15px;
}
.chip[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.set-title { font-family: Georgia, "Times New Roman", serif; font-weight: 500; font-size: 22px; margin: 28px 0 10px; }
.set-title:first-child { margin-top: 4px; }
.pieces { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.piece {
  display: flex; align-items: center; gap: 16px; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px 18px; cursor: pointer; box-shadow: var(--shadow);
}
.piece:hover { border-color: var(--accent); }
.piece .n { font-family: Georgia, serif; font-size: 26px; color: var(--gold); width: 28px; text-align: center; }
.piece .t { font-family: Georgia, serif; font-size: 20px; }
.piece .c { color: var(--muted); font-size: 14px; }
.piece .p { margin-left: auto; color: var(--muted); font-size: 13px; text-align: right; }

/* adding a piece (admins) */
.admin-row { margin-top: 28px; padding-top: 16px; border-top: 1px dashed var(--line); }
.add-link { color: var(--accent); text-decoration: none; font-weight: 600; }
.add-link:hover { text-decoration: underline; }
#add { max-width: 760px; width: 100%; margin: 0 auto; padding: 24px 16px 64px; }
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer;
  border: 2px dashed var(--line); border-radius: 14px; background: var(--surface); padding: 36px 16px; text-align: center;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--mine-soft); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.drop-main { font-weight: 600; color: var(--accent); }
.drop-sub, .muted, .note { color: var(--muted); font-size: 14px; }
.note { margin: 4px 0 12px; }
.form-err { color: #a3302a; font-size: 14px; margin: 12px 0 0; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .form-err { color: #f08a80; } }
#add-form, #added { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px; box-shadow: var(--shadow); margin-top: 16px; }
#add-form label:not(.check) { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
#add-form input:not([type=checkbox]), #add-form select {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 0;
}
#add-form input:focus, #add-form select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.sub { font-family: Georgia, "Times New Roman", serif; font-weight: 500; font-size: 20px; margin: 24px 0 4px; }
#add-form .sub:first-of-type { margin-top: 20px; }
#added .sub { margin-top: 0; }
.staves { display: grid; gap: 8px; }
.staff-row { display: grid; grid-template-columns: 1fr 180px 160px; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.staff-name { font-weight: 600; }
#f-marks-wrap { margin: 6px 0 12px; font-size: 15px; }
.actions { display: flex; gap: 10px; margin-top: 22px; }
.primary { border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-ink); padding: 10px 18px; font-weight: 600; cursor: pointer; }
.primary:disabled { opacity: .6; cursor: progress; }
.ghost { border: 1px solid var(--line); border-radius: 10px; background: transparent; padding: 10px 16px; cursor: pointer; }
.added { list-style: none; padding: 0; margin: 8px 0 0; }
.added li { display: flex; gap: 12px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.added li a { color: var(--accent); text-decoration: none; font-weight: 600; }
.added li .row-actions { margin-left: auto; display: flex; gap: 6px; }
.replace-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 4px 0 0; }
.file-btn { position: relative; overflow: hidden; display: inline-block; font-size: 14px; color: var(--accent); }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.bpm-set { display: inline-flex; align-items: center; gap: 6px; }
.bpm-set input {
  width: 4.2em; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 3px 6px; font-variant-numeric: tabular-nums;
}
.bpm-set input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
#edit-link[hidden] { display: none; }
@media (max-width: 640px) {
  .grid2 { grid-template-columns: 1fr; }
  .staff-row { grid-template-columns: 1fr 1fr; }
  .staff-row > div:first-child { grid-column: 1 / -1; }
}

/* practice */
#practice { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.part-bar {
  display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.presets { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; font-size: 14px; color: var(--muted); }
.seg + .seg { border-left: 1px solid var(--line); }
.seg.on { background: var(--mine-soft); color: var(--accent); font-weight: 600; }

.score-wrap { position: relative; flex: 1; overflow: auto; background: #fff; min-height: 0; }
.score { padding: 8px 0 40vh; color: #111; }
.score svg { display: block; margin: 0 auto; max-width: 100%; height: auto; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: #666; background: #fff; }
.score g.staff.mine { color: var(--mine); fill: var(--mine); }
:root .score g.staff.mine * { fill: #2f3e8f; stroke: #2f3e8f; }
.score g.staff.other { opacity: 0.55; }
.score g.measure { cursor: pointer; }
.cursor { position: absolute; pointer-events: none; border-radius: 3px; }
.cursor .bar { position: absolute; inset: 0; background: rgba(192,138,30,.16); border-radius: 4px; }
.cursor .line { position: absolute; top: 0; bottom: 0; width: 2px; background: #c08a1e; border-radius: 1px; }
.loop-mark { position: absolute; pointer-events: none; background: rgba(47,62,143,.10); border-radius: 4px; }

.words {
  min-height: 52px; padding: 10px 16px; background: var(--surface); border-top: 1px solid var(--line);
  font-family: Georgia, serif; font-size: 22px; white-space: nowrap; overflow: hidden;
  display: flex; align-items: center; gap: 0; scroll-behavior: smooth;
}
.words > * { flex-shrink: 0; }
.words .w { color: var(--muted); transition: color .1s; }
.words .w.now { color: var(--ink); text-decoration: underline var(--gold) 3px; text-underline-offset: 6px; }
.words .w.past { color: var(--ink); opacity: .55; }
.words .gap { width: .32em; display: inline-block; }
.words .hy { color: var(--muted); padding: 0 .08em; }
.words .empty { color: var(--muted); font-family: system-ui, sans-serif; font-size: 14px; }

.mixer { background: var(--surface); border-top: 1px solid var(--line); padding: 10px 16px; }
.opts { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 14px; color: var(--muted); }
.short-only { display: none; }
.credit-note { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.credit-note a { color: inherit; }
.mixer h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 6px; }
.channel { display: grid; grid-template-columns: 120px 1fr auto auto; gap: 10px; align-items: center; padding: 4px 0; }
.channel .name { font-size: 15px; }
.channel.mine .name { color: var(--accent); font-weight: 600; }
.channel input[type=range] { width: 100%; accent-color: var(--accent); }
.mini { border: 1px solid var(--line); background: transparent; border-radius: 8px; padding: 3px 9px; cursor: pointer; font-size: 13px; color: var(--muted); }
.mini.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.transport {
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); position: relative;
}
.transport .row { display: flex; align-items: center; gap: 12px; }
.transport .row.small { gap: 16px; font-size: 14px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.play {
  width: 52px; height: 52px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
}
.play .i-pause { display: none; }
.play.playing .i-play { display: none; }
.play.playing .i-pause { display: block; }
.pos { flex: 1; min-width: 0; }
.bar-no { font-weight: 600; font-variant-numeric: tabular-nums; }
.bar-sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toggle {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line);
  background: transparent; border-radius: 10px; padding: 7px 11px; cursor: pointer; font-size: 14px;
}
.toggle[aria-pressed="true"] { background: var(--mine-soft); color: var(--accent); border-color: var(--accent); }
.tempo { display: inline-flex; align-items: center; gap: 8px; }
.tempo input { width: 140px; accent-color: var(--accent); }
.tempo output { font-variant-numeric: tabular-nums; width: 3.2em; color: var(--ink); }
.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.check input { accent-color: var(--accent); }
.progress { width: 100%; margin: 8px 0 0; accent-color: var(--gold); }

.toast {
  position: fixed; left: 50%; bottom: 150px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 10px; font-size: 14px;
  z-index: 20; box-shadow: var(--shadow);
}

@media (max-width: 640px) {
  .who #user-name { display: none; }
  .piece .voices { display: none; }
  .piece .p br:first-of-type { display: none; }
  .piece { padding: 14px 14px; gap: 12px; }
  .part-bar { padding: 6px 12px; flex-wrap: nowrap; overflow-x: auto; gap: 8px; scrollbar-width: none; }
  .part-bar .chips { flex-wrap: nowrap; }
  .chip { padding: 5px 11px; font-size: 14px; white-space: nowrap; }
  .presets { flex-shrink: 0; }
  .presets .seg { padding: 5px 8px; font-size: 13px; white-space: nowrap; }
  .long { display: none; }
  .short-only { display: inline; }
  .top { padding: 6px 12px; }
  .play { width: 46px; height: 46px; }
  .transport { padding-top: 6px; }
  .transport .row.small { margin-top: 2px; }
  .progress { margin-top: 4px; }
  .mixer { max-height: 45vh; overflow: auto; }
  .words { font-size: 19px; }
  .channel { grid-template-columns: 90px 1fr auto auto; }
  .toggle span { display: none; }
  .tempo input { width: 100px; }
}
