/* Cantutti — styles (loaded by index.php) */
/* Colours follow the cantutti palette (.archive/cantutti-palette.svg):
   Purple #7B5CFF brand accent · Orange #F97316 solo / selected part · Pale blue #A6C8EB other parts ·
   Navy #0B1D3A text · Blue #3B82F6 controls, links · Teal #14B8A6 progress, positive ·
   Amber #FBBF24 cues, highlights · Mist #E8F3FF secondary panels · Cloud #F8FAFC background.
   The palette is light-only; the dark theme below is derived from the navy. */
:root {
  --bg: #f8fafc;            /* Cloud */
  --surface: #ffffff;
  --surface-2: #e8f3ff;     /* Mist */
  --border: #dce3ec;
  --text: #0b1d3a;          /* Navy */
  --muted: #475569;
  --accent: #3b82f6;        /* Blue */
  --accent-text: #ffffff;
  --brand: #7b5cff;         /* Purple */
  --brand-text: #ffffff;
  --solo: #f97316;          /* Orange */
  --solo-text: #ffffff;
  --positive: #0d9488;      /* Teal (a shade darker, to read on white) */
  --wordmark: #0b4da2;      /* the logo's wordmark */
  --played-tint: rgba(59, 130, 246, 0.12);
  --playhead: #f97316;
  --danger: #dc2626;
  --paper: #ffffff;
  --radius: 10px;
  --lead-w: 180px;
  --ctrl-w: 250px;
  --wave-h: 60px;
  --master-wave-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #071326;
    --surface: #0b1d3a;
    --surface-2: #132a4f;
    --border: #22406b;
    --text: #e8f3ff;
    --muted: #9fb3cc;
    --accent: #3b82f6;
    --accent-text: #ffffff;
    --brand: #9b85ff;
    --brand-text: #0b1d3a;
    --solo: #f97316;
    --solo-text: #0b1d3a;
    --positive: #14b8a6;
    --wordmark: #a6c8eb;
    --played-tint: rgba(59, 130, 246, 0.18);
    --playhead: #fb923c;
    --danger: #f87171;
    --paper: #f8fafc;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #071326;
  --surface: #0b1d3a;
  --surface-2: #132a4f;
  --border: #22406b;
  --text: #e8f3ff;
  --muted: #9fb3cc;
  --accent: #3b82f6;
  --accent-text: #ffffff;
  --brand: #9b85ff;
  --brand-text: #0b1d3a;
  --solo: #f97316;
  --solo-text: #0b1d3a;
  --positive: #14b8a6;
  --wordmark: #a6c8eb;
  --played-tint: rgba(59, 130, 246, 0.18);
  --playhead: #fb923c;
  --danger: #f87171;
  --paper: #f8fafc;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, select { font: inherit; color: inherit; }
svg { display: block; }

.app {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100%;
}

/* ---------- File selector ---------- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-toggle { display: none; }
/* Phone-only header parts (see the Mobile section): current piece title, Pieces / Corrections tabs */
.tcurrent, .m-tabs, .corr-slot { display: none; }
/* The speed icon is phone-only; on wider screens the slider shows in place */
.tempo-wrap { display: contents; }
.icon-btn.speed-btn { display: none; }
/* Logo at the top of the sidebar (beside the Pieces toggle on phones) */
.brand { margin: 0 8px 20px; color: var(--wordmark); }
.brand svg { width: 160px; height: auto; }
.brand .wordmark { fill: currentColor; }
.sidebar h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 0 8px 10px;
  font-weight: 600;
}
.pieces-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 10px; padding-right: 4px; }
.pieces-head h2 { margin-bottom: 0; }
.pieces-tools { display: flex; gap: 6px; margin-left: auto; }
.file-list li { display: flex; align-items: center; }
.file-list li > button[data-file] { flex: 1; min-width: 0; }
.file-list .rm-local {
  flex: none; width: auto; border: 0; background: none; color: var(--muted);
  cursor: pointer; padding: 6px 8px; border-radius: 6px; font-size: 13px;
}
.file-list .rm-local:hover { color: var(--danger); background: var(--surface-2); }
.user-badge {
  display: inline-block;
  margin: 0 8px 12px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--brand);
  color: var(--brand-text);
  font-size: 12px;
}
.user-badge[hidden] { display: none; }
/* A group with a password: the box to unlock it (above the list), or a link to lock this device again */
.group-lock { margin: 0 4px 12px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); font-size: 13px; }
.group-lock[hidden], .group-relock[hidden] { display: none; }
.group-lock p { margin: 0 0 8px; }
.group-lock .row-in { display: flex; gap: 6px; }
.group-lock input {
  flex: 1; min-width: 0; font: inherit; font-size: 14px; padding: 5px 8px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text);
}
.group-lock .warn { margin: 6px 0 0; min-height: 0; }
.group-relock { display: block; margin: 0 8px 10px; padding: 0; border: 0; background: none; color: var(--muted); font-size: 12px; cursor: pointer; text-decoration: underline; }
.file-list { list-style: none; margin: 0; padding: 0; }
.file-list button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 8px;
  padding: 9px 10px;
  cursor: pointer;
}
.file-list button:hover { background: var(--surface-2); }
.file-list button[aria-current="true"] { background: var(--accent); color: var(--accent-text); }
.file-list svg { flex: none; width: 16px; height: 16px; opacity: .7; }
.file-list .fname { flex: 1; min-width: 0; }
.file-list .badge { flex: none; font-size: 11px; opacity: .7; }
.file-list .empty { color: var(--muted); padding: 8px 10px; font-size: 14px; }

/* ---------- Main ---------- */
main { padding: 24px 28px 40px; min-width: 0; }
.piece-head { margin-bottom: 18px; }
.piece-head h1 { font-size: 22px; margin: 0; font-weight: 650; overflow-wrap: anywhere; }
.status { margin: 4px 0 0; color: var(--muted); font-size: 14px; min-height: 1.4em; }
.status.error { color: var(--danger); }

.mixer {
  --pos: 0%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 0;
}
.mixer[hidden] { display: none; }

.row {
  display: grid;
  grid-template-columns: var(--lead-w) minmax(0, 1fr) var(--ctrl-w);
  grid-template-areas: "lead wave ctrl";
  align-items: center;
  gap: 10px 14px;
  padding: 10px 16px;
}
.row.score-on .wave { display: none; }
.channels .row { border-top: 1px solid var(--border); }
.lead { grid-area: lead; min-width: 0; }
.wave { grid-area: wave; }
.ctrl { grid-area: ctrl; display: flex; align-items: center; gap: 8px; justify-content: flex-end; }

.master { padding-top: 12px; padding-bottom: 12px; }
.master .lead { display: flex; align-items: center; gap: 8px; }
.tempo { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tempo-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.tempo-label strong { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.tempo input { width: 80px; accent-color: var(--accent); cursor: pointer; }
.play-btn {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: var(--accent-text);
  display: grid; place-items: center;
  cursor: pointer;
  transition: transform .08s ease;
}
.play-btn:active { transform: scale(.95); }
.play-btn:disabled { opacity: .45; cursor: default; }
.play-btn svg { width: 24px; height: 24px; }
.time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; white-space: nowrap; }

/* Waveforms + playhead */
.wave {
  position: relative;
  height: var(--wave-h);
  border-radius: 6px;
  background: var(--surface-2);
  overflow: hidden;
  cursor: ew-resize;
  touch-action: pan-y;
  user-select: none;
}
.master .wave { height: var(--master-wave-h); }
.wave canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.wave .played {
  position: absolute; top: 0; bottom: 0; left: 0;
  width: var(--pos);
  background: var(--played-tint);
  pointer-events: none;
}
.wave .playhead {
  position: absolute; top: 0; bottom: 0;
  left: var(--pos);
  width: 2px;
  margin-left: -1px;
  background: var(--playhead);
  pointer-events: none;
}
.master .wave .playhead::before {
  content: "";
  position: absolute;
  top: 0; left: 50%;
  width: 14px; height: 14px;
  transform: translate(-50%, -50%) rotate(45deg);
  background: var(--playhead);
  border-radius: 2px;
}
.mixer.dragging .wave { cursor: grabbing; }
.wave:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Channel lead: name + instrument */
.ch-lead { display: flex; flex-direction: column; gap: 6px; }
.ch-name { display: flex; align-items: center; gap: 8px; font-weight: 600; min-width: 0; }
.ch-name .swatch { flex: none; width: 10px; height: 10px; border-radius: 3px; background: var(--ch-color); }
.ch-name .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Rename button: appears when hovering over (or focusing within) the part's row */
.rename-btn {
  flex: none; display: grid; place-items: center;
  width: 22px; height: 22px; padding: 0;
  border: 0; border-radius: 5px; background: none; color: var(--muted);
  cursor: pointer; opacity: 0; transition: opacity .12s ease;
}
.rename-btn svg { width: 14px; height: 14px; }
.row:hover .rename-btn, .row:focus-within .rename-btn { opacity: 1; }
.rename-btn:hover { background: var(--surface-2); color: var(--text); }
@media (hover: none) { .rename-btn { opacity: .6; } }   /* touch screens have no hover */
.lead-tools { display: flex; align-items: center; gap: 6px; min-width: 0; }
.inst {
  min-width: 0;
  flex: 0 1 auto;
  font-size: 13px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.row.muted .wave canvas { opacity: .15; }
.row.muted .ch-name .label { color: var(--muted); text-decoration: line-through; }

.vol {
  flex: 1;
  min-width: 70px;
  max-width: 150px;
  accent-color: var(--ch-color, var(--accent));
  height: 28px;
  cursor: pointer;
}
.icon-btn {
  flex: none;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.prio[aria-pressed="true"] { background: var(--solo); border-color: var(--solo); color: var(--solo-text); }
.icon-btn.mute[aria-pressed="true"] { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.icon-btn.small { width: 30px; height: 28px; border-radius: 6px; }
.icon-btn.small svg { width: 16px; height: 16px; }
.icon-btn.score-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
.icon-btn.clef-btn {
  font-family: "Segoe UI Symbol", "Noto Music", "Noto Sans Symbols 2", "Apple Symbols", "Bravura Text", serif;
  font-size: 19px; line-height: 1; padding: 0; overflow: hidden;
}
.icon-btn.clef-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
.icon-btn[hidden] { display: none; }
.channels .wave { cursor: grab; }
.master-vol { max-width: 140px; }
#exportBtn.recording { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.row.muted .vol { accent-color: var(--muted); filter: grayscale(1); opacity: .6; }
.icon-btn:focus-visible, .play-btn:focus-visible, .file-list button:focus-visible, .sidebar-toggle:focus-visible, .inst:focus-visible, .vol:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* Scrolling score strip (replaces the part's waveform when shown) */
.score {
  grid-area: wave;
  position: relative;
  overflow: hidden;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: none;
  cursor: grab;
  touch-action: pan-y;
  user-select: none;
}
.row.score-on .score { display: block; }
.mixer.dragging .score { cursor: grabbing; }
.score-track { position: absolute; left: 0; top: 0; height: 100%; will-change: transform; }
.score-track img { position: absolute; top: 0; display: block; max-width: none; pointer-events: none; -webkit-user-drag: none; }
.score-marker {
  position: absolute; top: 0; bottom: 0;
  left: 25%;
  width: 2px; margin-left: -1px;
  background: var(--playhead);
  opacity: .8;
  pointer-events: none;
}
.score-render { position: absolute; left: -100000px; top: 0; width: 1200px; visibility: hidden; }

/* Corrections bar + dialogs */
/* Title on the left, corrections panel on the right (stacked on phones) */
.head-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 520px);
  align-items: start;
  gap: 12px 20px;
  margin-bottom: 18px;
}
.head-row .piece-head { margin-bottom: 0; }
.edits-details[open] .edits-list { max-height: 260px; overflow-y: auto; }
.edits-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px;
  margin: 0; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); font-size: 14px;
}
.edits-bar[hidden] { display: none; }
.edits-bar .summary { flex: 1 1 240px; min-width: 0; }
.btn {
  font-size: 13px; padding: 6px 10px;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn:disabled { opacity: .5; cursor: default; }
.edits-details { flex-basis: 100%; font-size: 13px; }
/* Folded: "Corrections: …" with "› Show list" on the right */
.edits-details summary { display: flex; align-items: baseline; gap: 10px; cursor: pointer; list-style: none; font-size: 14px; color: var(--text); }
.edits-details summary::-webkit-details-marker { display: none; }
.edits-details .show-list { margin-left: auto; flex: none; color: var(--muted); font-size: 13px; white-space: nowrap; }
.edits-details .show-list::before { content: '› Show list'; }
.edits-details[open] .show-list::before { content: '⌄ Hide list'; }
.edits-details summary:hover .show-list { color: var(--text); }
/* Unfolded: the file tools first — which files to work from, then download (and, for the admin, upload) */
.edits-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.edits-tools .src-toggles { display: flex; gap: 4px; }
.edits-tools .src-btn {
  display: grid; place-items: center; width: 30px; height: 28px; padding: 0;
  border: 1px solid var(--border); border-radius: 6px; background: none; color: var(--muted); cursor: pointer;
}
.edits-tools .src-btn svg { width: 18px; height: 18px; }
.edits-tools .src-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.edits-tools .src-btn:disabled { opacity: .35; cursor: default; }
/* Download / upload buttons: icon + label, as wide as they need (beats the phone rule that fixes .icon-btn.small at 30px) */
.edits-tools .icon-btn.small.file-btn { width: auto; display: inline-flex; align-items: center; gap: 4px; padding: 0 8px; font-size: 12px; white-space: nowrap; }
.edits-tools .file-btn svg { flex: none; }
.edits-tools .tool-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.edits-tools .tool-gap { flex: 1; }
.edits-details .stale-note, .edits-details .edits-note { margin: 8px 0 0; font-size: 13px; }
.edits-details .stale-note .btn { margin-left: 6px; }
.edits-list { margin: 6px 0 0; padding: 0; list-style: none; }
.edits-list li { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.edits-list .rm { border: 0; background: none; color: var(--danger); cursor: pointer; font-size: 13px; padding: 0 4px; }
/* One shared grid for the whole list (rows use subgrid) so the columns line up from row to row:
   who · part · bar · change · file icons · ✕ · spare space */
.edits-list {
  display: grid;
  grid-template-columns: repeat(5, auto) 1fr;   /* part · bar · change · file icons · ✕ · spare space */
  column-gap: 12px;
}
.edits-list li.sect {
  grid-column: 1 / -1;
  display: block;
  margin-top: 6px; padding: 4px 6px 2px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text);
}
.edits-list li.sect .muted { text-transform: none; letter-spacing: 0; font-weight: 400; }
.edits-list li.corr.replaced .part, .edits-list li.corr.replaced .chg { opacity: .55; }
.edits-list li.corr {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  align-items: center;
  padding: 5px 6px; border-radius: 6px;
  cursor: pointer; color: var(--text);
}
.edits-list li.corr:hover { background: var(--surface-2); }
.edits-list li.corr:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.edits-list .part { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.edits-list .bar { color: var(--muted); white-space: nowrap; }
.edits-list .files { display: flex; gap: 4px; }
.edits-list .f { display: grid; color: var(--border); }
.edits-list .f.on { color: var(--accent); }
.edits-list .f svg { width: 18px; height: 18px; }
@media (max-width: 760px) {
  .edits-list { column-gap: 8px; }
  .head-row { grid-template-columns: minmax(0, 1fr); }
}
.warn { color: var(--danger); }
.muted { color: var(--muted); }
dialog.dlg {
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
  padding: 18px 20px; width: min(460px, calc(100vw - 32px));
}
dialog.dlg::backdrop { background: rgba(0, 0, 0, .35); }
/* Note editor: at the left, page not dimmed (so the part's notes stay visible), draggable by its title */
#noteDialog {
  position: fixed; margin: 0; inset: auto; left: 16px; top: 72px;
  max-height: calc(100vh - 32px); overflow: auto;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .25);
}
#noteDialog::backdrop { background: transparent; }
#noteDialog .drag-handle { cursor: move; touch-action: none; user-select: none; display: flex; align-items: center; gap: 6px; }
#noteDialog .drag-handle .grip { color: var(--muted); font-size: 14px; letter-spacing: -2px; margin-right: 6px; }
#noteDialog .dlg-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#noteDialog .part-sel {
  min-width: 4em; max-width: 14em; font: inherit; color: inherit; cursor: pointer;
  background: transparent; border: 1px solid var(--border); border-radius: 6px; padding: 1px 4px;
}
#noteDialog .part-sel:hover, #noteDialog .part-sel:focus { border-color: currentColor; }
#noteDialog .part-sel option { color: initial; }
#noteDialog .src-toggles { margin-left: auto; display: flex; gap: 4px; flex: none; }
#noteDialog .pin-btn, #noteDialog .src-btn {
  flex: none; display: grid; place-items: center; width: 30px; height: 30px; padding: 0;
  border: 1px solid var(--border); border-radius: 8px; background: none; color: var(--muted); cursor: pointer;
}
#noteDialog .pin-btn:hover, #noteDialog .src-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
#noteDialog .pin-btn[aria-pressed="true"], #noteDialog .src-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
#noteDialog .src-btn:disabled { opacity: .35; cursor: default; }
#noteDialog .pitch-box { margin-top: 8px; }
#noteDialog .discrepancy { margin: 0 0 8px; padding: 6px 10px; border-left: 3px solid var(--danger); background: var(--surface-2); border-radius: 4px; font-size: 13px; }
#noteDialog .edit-info { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
#noteDialog .stave-wrap { display: flex; align-items: center; gap: 8px; }
#noteDialog .new-pitch { font-size: 24px; font-weight: 700; color: var(--accent); }
/* Blue = as originally written, red = corrected by you, green = approved correction from the server
   (filled: the note being edited; outline: for reference) */
#noteDialog { --orig-blue: var(--accent); --corr-red: var(--danger); --appr-green: var(--positive); }
#noteDialog .new-pitch { color: var(--orig-blue); }
#noteDialog .new-pitch.corr { color: var(--corr-red); }
#noteDialog .new-pitch.appr { color: var(--appr-green); }
#noteDialog .acc-btns { display: flex; flex-direction: column; gap: 4px; flex: none; }
#noteDialog .acc-btns button {
  width: 38px; height: 34px; padding: 0; font-size: 19px; line-height: 1; cursor: pointer;
  font-family: "Segoe UI Symbol", "Noto Music", "Noto Sans Symbols 2", serif;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text);
}
#noteDialog .acc-btns button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
#noteDialog .note-nav .muted { text-align: center; }
#noteDialog.wide { width: min(700px, calc(100vw - 32px)); }
/* Editor: the bar */
#noteDialog .voice-pick { font-size: 13px; margin: 0 0 6px; display: flex; gap: 10px; align-items: center; }
#noteDialog .voice-pick label { display: inline-flex; gap: 4px; align-items: center; cursor: pointer; }
#noteDialog .voice-pick label.bad { color: var(--corr-red); }
#noteDialog .voice-pick { flex-wrap: wrap; }
#noteDialog .btn.small { padding: 2px 10px; font-size: 12px; }
/* The Note and Marks buttons, each opening a pop-up of choices (like the speed pop-up) */
#noteDialog .ed-pops { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
#noteDialog .pop { position: relative; }
#noteDialog .pop-btn { display: inline-flex; align-items: center; gap: 6px; }
#noteDialog .pop-btn .pop-cur { display: inline-flex; align-items: center; color: var(--muted); font-size: 12px; }
#noteDialog .pop-btn .pop-cur:empty { display: none; }
#noteDialog .pop-btn .pop-cur svg { width: 14px; height: 16px; }
#noteDialog .pop-btn .pop-dot { font-size: 16px; line-height: 0; margin-left: 1px; }
#noteDialog .pop-btn .caret { font-size: 10px; color: var(--muted); }
#noteDialog .pop-btn.open { border-color: var(--accent); }
#noteDialog .pop-btn.open .pop-cur { color: var(--accent); }
#noteDialog .pop-box {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; z-index: 30; flex-direction: column; gap: 6px;
  padding: 8px; width: max-content; max-width: min(340px, calc(100vw - 48px));
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}
#noteDialog .pop.open .pop-box { display: flex; }
#noteDialog .pop-row { display: flex; flex-wrap: wrap; gap: 4px; }
#noteDialog .pop-note { margin: 0; font-size: 11px; max-width: 260px; }
#noteDialog .pop-box button {
  min-width: 34px; height: 32px; padding: 0 6px; display: grid; place-items: center; cursor: pointer; font-size: 12px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text);
}
#noteDialog .dyn-row button { font: italic 700 14px Georgia, "Times New Roman", serif; }
#noteDialog .pop-box button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
#noteDialog .pop-box button.open:not([aria-pressed="true"]) { border-color: var(--accent); color: var(--accent); border-style: dashed; }   /* "end slur" etc. */
#noteDialog .pop-box button:disabled, #noteDialog .acc-btns button:disabled { opacity: .4; cursor: default; }
#noteDialog .bar-scroll {
  flex: 1; min-width: 0; overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
#noteDialog .bar-svg { display: block; max-width: none; touch-action: none; user-select: none; cursor: pointer; }
#noteDialog .bar-svg .ln, #noteDialog .bar-svg .ledger, #noteDialog .bar-svg .barline { stroke: var(--text); stroke-opacity: .55; stroke-width: 1; }
#noteDialog .bar-svg .barline { stroke-opacity: .8; stroke-width: 1.4; }
#noteDialog .bar-svg .bar-end { stroke: var(--corr-red); stroke-width: 1.6; stroke-dasharray: 4 3; }
#noteDialog .bar-svg .clef { fill: var(--text); stroke: var(--text); }
#noteDialog .bar-svg .clef8 { fill: var(--text); font-size: 10px; }
#noteDialog .bar-svg .tup { fill: var(--muted); font: italic 12px Georgia, serif; }
#noteDialog .bar-svg .acc { font-size: 17px; fill: var(--text); font-family: "Segoe UI Symbol", "Noto Music", "Noto Sans Symbols 2", serif; }
#noteDialog .bar-svg .cur-col { fill: var(--accent); opacity: .09; }
#noteDialog .bar-svg .bh, #noteDialog .bar-svg .bdot, #noteDialog .bar-svg .beam { fill: var(--text); }
#noteDialog .bar-svg .bh.hollow { fill: none; stroke: var(--text); stroke-width: 1.6; }
#noteDialog .bar-svg .stem, #noteDialog .bar-svg .flag, #noteDialog .bar-svg .tie, #noteDialog .bar-svg .slur { stroke: var(--text); stroke-width: 1.3; fill: none; }
#noteDialog .bar-svg .pin { stroke: var(--text); stroke-width: 1.2; fill: none; }
#noteDialog .bar-svg .slur.open, #noteDialog .bar-svg .pin.open { stroke: var(--accent); stroke-dasharray: 4 3; }
#noteDialog .bar-svg .dyn { fill: var(--text); font: italic 700 14px Georgia, "Times New Roman", serif; }
#noteDialog .bar-svg .rest { fill: var(--text); stroke: var(--text); }
#noteDialog .bar-svg .rest .rline { fill: none; }
#noteDialog .bar-svg .chg { fill: var(--corr-red); stroke: var(--corr-red); }
#noteDialog .bar-svg .bh.chg.hollow, #noteDialog .bar-svg .stem.chg, #noteDialog .bar-svg .flag.chg, #noteDialog .bar-svg .tie.chg { fill: none; }
#noteDialog .bar-svg .acc.chg { stroke: none; }
#noteDialog .bar-svg .selp { fill: var(--orig-blue); stroke: var(--orig-blue); }
#noteDialog .bar-svg .bh.selp.hollow { fill: none; stroke-width: 2.2; }
#noteDialog .bar-svg .acc.selp { stroke: none; }
#noteDialog .bar-svg .bh.other { fill: var(--muted); opacity: .45; }
#noteDialog .beats { font-weight: 650; color: var(--text); }
#noteDialog .beats.bad { color: var(--corr-red); }
/* Row under the stave: + Voice / + Verse, and the voice / verse pickers on the right */
#noteDialog .bar-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 6px 0 2px; font-size: 13px; }
#noteDialog .bar-tools .tools-left { display: flex; gap: 4px; flex-wrap: wrap; }
#noteDialog .bar-tools .tools-right { display: flex; gap: 12px; margin-left: 20px; align-items: center; flex-wrap: wrap; }
#noteDialog .bar-tools label { display: inline-flex; gap: 4px; align-items: center; color: var(--muted); }
/* Lyrics: syllables under the notes (tap to edit, drag to another note; tap an empty place to add one) */
#noteDialog .lyr-lane { position: relative; height: 30px; border-top: 1px dashed var(--border); cursor: text; }
#noteDialog .lyr {
  display: inline-block; padding: 2px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2);
  font-size: 13px; cursor: grab; touch-action: none; user-select: none; white-space: nowrap;
}
#noteDialog .lyr-lane .lyr { position: absolute; top: 4px; transform: translateX(-50%); }
#noteDialog .lyr.dragging { cursor: grabbing; z-index: 5; box-shadow: 0 3px 10px rgba(0, 0, 0, .25); }
#noteDialog .lyr.add { background: none; border-style: dashed; color: var(--muted); cursor: pointer; padding: 2px 8px; }
.dlg h3 { margin: 0 0 4px; font-size: 17px; }
.dlg .sub { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.dlg .note-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 0 12px; font-size: 13px; }
.dlg fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 0 0 12px; padding: 8px 12px 10px; }
.dlg legend { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0 4px; }
.dlg label.opt { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 14px; }
.dlg p { margin: 4px 0; font-size: 13px; }
.dlg .pitch-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.dlg select, .dlg input[type=number], .dlg input[type=text], .dlg textarea {
  font: inherit; font-size: 14px; padding: 5px 8px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text);
}
.dlg input[type=text], .dlg textarea { width: 100%; }
.dlg textarea { min-height: 80px; resize: vertical; }
.dlg .field-label { display: block; margin: 10px 0 4px; font-size: 13px; color: var(--muted); }
.dlg .new-pitch { font-weight: 650; font-size: 16px; margin-left: auto; }
.dlg .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.dlg .actions .spacer { flex: 1; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: var(--danger); color: var(--surface); }
.btn:disabled { opacity: .5; cursor: default; }
.dlg .tag { font-size: 11px; color: var(--accent); }
.icon-btn:disabled { opacity: .4; cursor: default; }

/* The footer sits at the bottom of the window when the page is short, and below the content (scrolling with it)
   when it's long: main fills at least the window height, and the gap before the footer takes up any spare room */
main { display: flex; flex-direction: column; }
main > .footer-gap { flex: 1 0 28px; }
.site-footer {
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--muted); font-size: 12px; line-height: 1.5;
}
.placeholder {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  :root { --wave-h: 52px; --master-wave-h: 56px; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    height: auto;
    max-height: 70vh;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 0;
    /* logo + current piece / the two tabs / whichever tab is unfolded */
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "brand title" "tabs tabs" "body body" "corr corr";
    align-items: center;
  }
  .brand { grid-area: brand; margin: 12px 0 14px 16px; }
  .brand svg { width: 72px; }
  .tcurrent {
    grid-area: title; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
    margin: 0 16px 0 14px; font-size: 17px; font-weight: 650; line-height: 1.25; overflow-wrap: anywhere;
  }

  /* Pieces / Corrections tabs, each with a chevron that turns when unfolded */
  .m-tabs { grid-area: tabs; display: flex; border-top: 1px solid var(--border); }
  .m-tab {
    flex: 1; min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px;
    background: none; border: 0; padding: 11px 16px; cursor: pointer; text-align: left; color: var(--muted);
  }
  .m-tab[hidden] { display: none; }
  .m-tab + .m-tab { border-left: 1px solid var(--border); }
  .m-tab .tlabel { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
  .m-tab svg { flex: none; width: 18px; height: 18px; transition: transform .15s ease; }
  .m-tab[aria-expanded="true"] { background: var(--surface-2); color: var(--text); }
  .m-tab[aria-expanded="true"] svg { transform: rotate(180deg); }
  .m-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

  .sidebar-body { grid-area: body; display: none; padding: 10px 8px 12px; overflow-y: auto; max-height: calc(70vh - 120px); border-top: 1px solid var(--border); }
  .sidebar.open .sidebar-body { display: block; }
  .sidebar h2 { display: none; }
  /* Corrections panel (moved here from beside the title by the page script) */
  .corr-slot { grid-area: corr; overflow-y: auto; max-height: calc(70vh - 120px); }
  .sidebar.corr-open .corr-slot { display: block; border-top: 1px solid var(--border); }
  .corr-slot .edits-bar { border: 0; border-radius: 0; background: none; padding: 10px 16px 12px; }
  .corr-slot .edits-details .show-list { display: none; }
  .corr-slot .edits-details[open] .edits-list { max-height: none; overflow: visible; }

  main { padding: 14px 12px 32px; }
  .piece-head h1 { display: none; }              /* the title is in the header, beside the logo */
  .head-row { margin-bottom: 12px; }
  .status { margin-top: 0; }

  /* Every waveform spans the full width so they all line up */
  .row { gap: 8px 10px; padding: 10px; }
  .row,
  .master {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "lead ctrl" "wave wave";
  }
  .play-btn { width: 46px; height: 46px; }
  .vol { width: 84px; flex: none; min-width: 0; }
  .master .lead { gap: 6px; }
  .master .vol.master-vol { width: 64px; }
  .master .time { font-size: 13px; }
  .icon-btn { width: 36px; height: 36px; }
  .icon-btn.small { width: 30px; height: 28px; }

  /* Speed: an icon that opens the slider in a pop-up */
  .tempo-wrap { display: block; position: relative; }
  .icon-btn.speed-btn { display: grid; }
  .icon-btn.speed-btn.changed { color: var(--accent); border-color: var(--accent); }
  .tempo-wrap .tempo {
    display: none; position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; gap: 6px;
    padding: 10px 14px 12px; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
  }
  .tempo-wrap.open .tempo { display: flex; }
  .tempo-wrap .tempo input { width: 180px; }

  /* Part rows: prioritise and mute at the small button size, one above the other beside the volume */
  .channels .ctrl {
    display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto;
    gap: 4px 8px; align-items: center; justify-content: end;
  }
  .channels .ctrl .vol { grid-column: 1; grid-row: 1 / 3; }
  .channels .ctrl .icon-btn { grid-column: 2; width: 30px; height: 28px; border-radius: 6px; }
  .channels .ctrl .icon-btn svg { width: 16px; height: 16px; }
}
