/* Bravura is vendored under assets/fonts (SIL OFL 1.1). The canvas font stack
   names it directly; there is no fallback that would render music, so the
   metrics loader waits for it before the first paint. */
@font-face {
  font-family: "Bravura";
  src: url("../assets/fonts/Bravura.woff2") format("woff2");
  font-weight: normal;
  font-style: normal;
  font-display: block;
}

:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #16161a;
  --ink-muted: #6b6b76;
  --line: #dedcd6;
  --accent: #d2542a;
  --shadow: 0 1px 3px rgba(0, 0, 0, .07), 0 12px 28px rgba(0, 0, 0, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14141a;
    --panel: #1c1c24;
    --ink: #ececf0;
    --ink-muted: #9a9aa8;
    --line: #2c2c38;
    --accent: #ff7a4d;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 12px 28px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

/* The `hidden` attribute has to beat the layout rules below.  The user agent
   gives `[hidden]` `display: none`, but any author rule setting `display` at
   all — `.adjustbar { display: flex }` is the one that bit — wins over it, and
   the element stays on screen with its `hidden` attribute set.  Every bar in
   this page is a flex row that is hidden until its mode is on, so this is not
   a corner case. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
}

body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  /* Top bar, stage, then the fingerboard and the transport. A hidden
     fingerboard generates no box, so its row is empty and takes no height. */
  grid-template-rows: auto auto 1fr auto auto;
  grid-template-areas: "top" "sync" "stage" "board" "transport";
  min-width: 0;
  height: 100vh;
}

/* A vertical fingerboard stands beside the stage instead, in a column of its
   own — empty, and no width, while the fingerboard is hidden. */
body.fingerboard-vertical {
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto 1fr auto;
  grid-template-areas: "top top" "sync sync" "stage board" "transport transport";
}

.topbar { grid-area: top; }
.syncpanel { grid-area: sync; }
.stage { grid-area: stage; }
.fingerboard { grid-area: board; }
.transport { grid-area: transport; }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 600;
  letter-spacing: -0.01em;
}

.spacer { flex: 1; }

.file span,
select,
button {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 11px;
  cursor: pointer;
}

.file span:hover,
select:hover { border-color: var(--ink-muted); }

.ctl {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ink-muted);
  font-size: 13px;
  white-space: nowrap;
}

/* The mode picker: at most one of Adjust and Edit XML is ever on, so they are
   drawn as one segmented control rather than as two independent switches.  A
   pair of checkboxes would say the two can be combined, and they cannot — each
   mode owns the pointer, and a click on the score means a different thing in
   each.  Buttons rather than radios because the third position is *neither*,
   and a radio cannot be un-picked. */
.modes {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.modes button {
  border: 0;
  border-radius: 0;
  font-size: 13px;
  padding: 5px 12px;
  color: var(--ink-muted);
}

/* A hairline between the segments, and none before the first: the control has
   its own outer border already. */
.modes button + button { border-left: 1px solid var(--line); }

.modes button:hover { color: var(--ink); }

/* Adjust and Edit XML in horizontal scroll, which offers neither. */
.modes button:disabled { opacity: .4; cursor: default; }
.modes button:disabled:hover { color: var(--ink-muted); }

/* The active mode is filled rather than merely outlined.  It has to be legible
   at a glance across the room from the score it changes the meaning of every
   click on. */
.modes button[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
}

input[type="range"] { accent-color: var(--accent); }

/* The staff picker: a summary like a select, opening onto a list of parts,
   each with its staves under it when it has more than one. */
.staves { position: relative; font-size: 13px; }
.staves > summary {
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 11px;
  cursor: pointer;
  white-space: nowrap;
}
.staves > summary::-webkit-details-marker { display: none; }
.staves > summary::after { content: " \25BE"; color: var(--ink-muted); }
.staves > summary:hover { border-color: var(--ink-muted); }
.staves-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  min-width: 190px;
  max-height: 60vh;
  overflow: auto;
  padding: 6px 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .12);
}
.staves-menu label {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 12px;
  white-space: nowrap;
  cursor: pointer;
}
.staves-menu label.staff { padding-left: 32px; color: var(--ink-muted); }
.staves-menu label:hover { background: rgba(127, 127, 127, .1); }
.staves-menu .actions { display: flex; gap: 6px; padding: 6px 12px 2px; }
.staves-menu .actions button { font-size: 12px; padding: 2px 8px; }

/* The experiment knob for SPACING.AFTER_NOTE_PAD_SP.  Narrower than the size
   slider on purpose: at the browser's default range width this control is the
   one that pushes the bar past 1240px and wraps "Open MusicXML…" onto two
   lines, and 0.1-1.5 sp is a short enough travel to read at this size. */
#notePad { width: 100px; }

/* A number read off a slider, sitting next to it.  Tabular figures and a fixed
   width so the controls beside it do not shuffle as the value changes. */
.ctl .num {
  font-variant-numeric: tabular-nums;
  min-width: 30px;
  text-align: right;
}

.range-values {
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
}

/* ---------- stage ---------- */

/* The stage is a row: the score on the left, and — in edit mode only — the XML
   on the right.  The scrolling lives on the panes rather than here, so the two
   sides scroll independently: reading down the XML must not drag the engraving
   out from under the highlight. */
.stage {
  display: flex;
  flex-direction: row;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.scorepane {
  flex: 1 1 auto;
  min-width: 0;
  overflow: auto;
  padding: 26px 0 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* The two canvases are stacked in a positioned container, exactly as the
   architecture requires: the score is painted once, the cursor layer is
   repainted per frame and never touches the engraved pixels. */
.notationland {
  /* The score is always engraved on light paper, whatever the system scheme.
     Notation is designed for black ink on white: inverted, stems and beams
     bloom and the hairline staff lines go muddy.  These live here rather than
     on :root so the surrounding chrome still follows prefers-color-scheme —
     theme() in main.js reads the canvas colours off this element. */
  --panel: #ffffff;
  --ink: #16161a;
  --ink-muted: #6b6b76;
  --accent: #d2542a;
  /* The validation flag. Far enough round from --accent that a flagged measure
     and the one the XML caret is in are never confused for each other, which is
     the whole point of them being two colours — they routinely land on the same
     bar. Fixed like the rest of these: it is painted on the paper. */
  --flag: #b4232c;
  /* The extra fingerings. Their row is allowed to land on other ink, so it is a
     colour the engraving never uses, which is what keeps "A1" readable when it
     sits across a dynamic or the next system's measure number. */
  --fingering: #1f5fae;

  position: relative;
  background: var(--panel);
  box-shadow: var(--shadow);
  border-radius: 3px;
}

.layer {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
}

.layer:first-child { position: relative; }   /* first one establishes the size */

#score  { z-index: 0; cursor: pointer; }
/* The extra fingerings are ink: over the engraving, under everything that marks
   it up. Same stacking level as #score, later in the document. */
#fingering { z-index: 0; pointer-events: none; }
#cursor { z-index: 1; pointer-events: none; }
/* The handle layer sits on top but never takes the pointer: hit-testing is done
   against layout coordinates on #score, which already owns the click. */
#adjust { z-index: 2; pointer-events: none; }
/* Under the handles, over the cursor: an adjustment handle must stay grabbable
   while a measure is highlighted. Same rule about the pointer. */
#highlight { z-index: 1; pointer-events: none; }

/* ---------- horizontal scroll ---------- */

/* In vertical scroll the two wrappers generate no box at all, so the page lays
   out as it did before they existed. */
.hscroll,
.hspacer { display: contents; }

/* The viewport onto the strip: a plain native scroller, carrying the paper's
   card look since the canvases inside it fill it edge to edge.  `contain` stops
   a sideways swipe at either end from turning into the browser's back gesture.
   The scrollbar is thin and invisible until the view moves or the pointer is
   over it. */
.scorepane.horizontal .hscroll {
  display: block;
  align-self: stretch;
  margin: 0 16px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  background: #fff;
  box-shadow: var(--shadow);
  border-radius: 3px;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}
.scorepane.horizontal .hscroll:hover,
.scorepane.horizontal .hscroll.has-horizbar {
  scrollbar-color: rgba(22, 22, 26, .35) transparent;
}
/* Safari, which reads neither property above. */
.scorepane.horizontal .hscroll::-webkit-scrollbar { height: 8px; }
.scorepane.horizontal .hscroll::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 4px;
}
.scorepane.horizontal .hscroll:hover::-webkit-scrollbar-thumb,
.scorepane.horizontal .hscroll.has-horizbar::-webkit-scrollbar-thumb {
  background: rgba(22, 22, 26, .35);
}
/* Playing: the view belongs to the playhead.  `hidden` refuses the wheel,
   touch, the keyboard and the scrollbar at once, and still lets the page turns
   write `scrollLeft`. */
.scorepane.horizontal .hscroll.locked { overflow-x: hidden; }

.scorepane.horizontal .hspacer { display: block; }

.scorepane.horizontal .notationland {
  position: sticky;
  left: 0;
  box-shadow: none;
  border-radius: 0;
}

/* The gutter's shadow, cast rightwards onto the music passing under it —
   darkest against the gutter.  Only once something is passing under it: at
   scroll 0 the gutter is the strip's own opening prefix, and a shadow there
   would split a clef from the music it heads. */
.scorepane.horizontal .notationland::before,
.scorepane.horizontal .notationland::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 3;
  pointer-events: none;
}
.scorepane.horizontal .notationland::before {
  left: var(--gutter-w, 0px);
  width: var(--gutter-shadow-w, 10px);
  background: linear-gradient(to left, rgba(0, 0, 0, 0),
                              rgba(0, 0, 0, var(--gutter-shadow-alpha, .1)));
  opacity: 0;
  transition: opacity .15s;
}
.scorepane.horizontal .hscroll.scrolled .notationland::before { opacity: 1; }
/* The right edge fades the incoming music in rather than guillotining it —
   and not quite to white, so a hint of the next symbol stays visible. */
.scorepane.horizontal .notationland::after {
  right: 0;
  width: var(--fade-w, 5%);
  background: linear-gradient(to right, rgba(255, 255, 255, 0),
                              rgba(255, 255, 255, var(--fade-alpha, .925)));
}

/* ---------- adjust mode ---------- */

.adjustbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 0;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: var(--shadow);
  font-size: 13px;
  /* Wide enough for the readout to stay on two or three lines with a curve
     selected: the anchor, its offset at each of the two stages, which of its
     two layouts is being edited, and whether the other one holds something of
     its own.  It grew when the stage control landed beside the others. */
  max-width: min(1240px, 96vw);
  /* A safety net for a narrow window rather than the normal case: with no wrap
     the controls stay put and the readout is squeezed to one word a line, which
     is the one part of this bar anybody actually reads. */
  flex-wrap: wrap;
}

/* Takes the slack, but never below a width the readout is legible at — past
   that the whole row wraps instead. */
.adjustbar .hint { color: var(--ink-muted); flex: 1 1 auto; min-width: 260px; }
.adjustbar .count { color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.adjustbar button { padding: 4px 9px; font-size: 12px; white-space: nowrap; }
.adjustbar button:disabled { opacity: .4; cursor: default; }
.adjustbar .warn { color: var(--accent); }
/* The file picker sits among the buttons, so it has to read as one of them. */
.adjustbar .file span { padding: 4px 9px; font-size: 12px; border-radius: 6px; }

.status {
  margin: 18px;
  color: var(--ink-muted);
}

.status.error { color: var(--accent); }
/* The validation summary, appended to the same line. Named after the canvas
   colour it is reporting on, and set to the same value, so the sentence and the
   wash on the page read as one thing. */
.status .flag { color: #b4232c; }
/* " \u00b7 \u25b2 " — the escapes are written with explicit \0020s because a
   space after a hex escape terminates it and is then eaten, which would run
   the separator, the marker and the count together. */
.status .flag::before { content: "\0020\00B7\0020\25B2\0020"; font-size: 11px; }

/* ---------- transport ---------- */

/* The controls wrap onto a second row rather than being squeezed: flex would
   otherwise shrink them all at once, and a segmented control crushed to a
   sliver — or pushed past the right edge — is a control nobody can find. Only
   the scrub gives up width; everything else keeps the size it needs. */
.transport {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 14px;
  padding: 10px 16px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}

.transport > * { flex: 0 0 auto; }

.play {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border-color: var(--line);
  flex: 0 0 auto;
}

.play:hover { border-color: var(--accent); }

/* Reset-to-crop-start, sitting by the play button; shown only in Sync with a
   crop. A smaller round button so the pair reads as a group. `[hidden]` has to be
   restated because `display` here would otherwise win over the UA hidden rule. */
.crop-reset {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border-color: var(--line);
  font-size: 15px;
  line-height: 1;
}
.crop-reset:hover { border-color: var(--accent); }
.crop-reset[hidden] { display: none; }

.icon-play {
  width: 0; height: 0;
  border-left: 11px solid currentColor;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  margin-left: 3px;
}

.play.playing .icon-play {
  border: 0;
  width: 11px;
  height: 13px;
  margin: 0;
  background:
    linear-gradient(currentColor, currentColor) left / 4px 100% no-repeat,
    linear-gradient(currentColor, currentColor) right / 4px 100% no-repeat;
}

/* Wide enough for the clock, and no wider than the row can spare: a long title
   is cut rather than allowed to push the controls off the end. The one control
   besides the scrub that gives up width, so the play button keeps its company
   on the first row however narrow the window gets. */
.meta { flex: 0 1 auto; min-width: 120px; max-width: 34ch; }
.title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.clock-row { display: flex; align-items: center; gap: 6px; }
.clock {
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

/* Waiting for data: the audio or the video seeking or buffering. A ring with
   one bright quarter, turning. With reduced motion it pulses instead, which
   still says "working" without the spin. */
.spinner {
  display: inline-block;
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  box-sizing: border-box;
  border: 2px solid rgb(127 127 127 / .3);    /* before color-mix: Safari 16.2 */
  border: 2px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.spinner[hidden] { display: none; }
.spinner.large { width: 36px; height: 36px; border-width: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: pulse 1.2s ease-in-out infinite; }
}

/* The one control that takes up the slack — and the first to move to a row of
   its own, since below its basis the whole row wraps. The wrapper carries the
   flex so the scrub still takes the slack; it is the positioning context for the
   crop markers. */
.scrub-wrap {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 200px;
  min-width: 120px;
}
.scrub-wrap > .scrub { flex: 1 1 auto; width: 100%; min-width: 0; }
.scrub { flex: 1 1 200px; min-width: 120px; }

/* Ticks marking the crop start/end over the scrub track. Inset a thumb-radius
   each side so they sit on the thumb's travel, and non-interactive so the scrub
   still takes every pointer event. Shown only in Sync with a crop (JS toggles
   [hidden] and sets each tick's `left`). */
.scrub-marks {
  position: absolute;
  left: 8px; right: 8px; top: 0; bottom: 0;
  pointer-events: none;
}
.scrub-marks[hidden] { display: none; }
.scrub-mark {
  position: absolute;
  top: 50%;
  width: 2px;
  height: 16px;
  transform: translate(-50%, -50%);
  background: var(--accent);
  border-radius: 1px;
  box-shadow: 0 0 0 1px var(--panel);
}

.tempo span {
  font-variant-numeric: tabular-nums;
  min-width: 46px;
  display: inline-block;
  text-align: right;
}

/* A fixed width, not a minimum: text that changes every frame must not be able
   to change the row's layout. */
.drift {
  color: var(--ink-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  width: 13ch;
  white-space: nowrap;
  overflow: hidden;
  text-align: right;
}

.volume input[type="range"] { width: 80px; }

/* Each video on or off: switches drawn like mode segments on their own. */
.video-toggles { display: flex; gap: 6px; }
.video-toggles[hidden] { display: none; }
.video-toggle {
  font-size: 13px;
  padding: 5px 12px;
  color: var(--ink-muted);
  border-color: var(--line);
  border-radius: 7px;
}
.video-toggle:hover { color: var(--ink); }
.video-toggle[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------- the video panel ---------- */

/* Floating over the score, like picture-in-picture: fixed to the viewport, so
   the score scrolls under it and its layout never changes for it. Moved by its
   bar and resized from its corner (main.js places it, in px, and keeps it on
   screen). Above the page and the transport, under the dialogs, which are in
   the top layer. */
.video-panel {
  position: fixed;
  z-index: 30;
  left: 16px;
  top: 72px;
  width: 360px;
  min-width: 160px;
  max-width: calc(100vw - 16px);
  display: flex;
  flex-direction: column;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgb(0 0 0 / .25);
  overflow: hidden;
  touch-action: none;
}
.video-panel[hidden] { display: none; }
.video-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px 3px 10px;
  background: var(--panel);
  color: var(--ink-muted);
  font-size: 12px;
  cursor: move;
  user-select: none;
  -webkit-user-select: none;
}
.video-title { flex: 1 1 auto; }
.video-close {
  border: 0;
  background: none;
  font-size: 18px;
  line-height: 1;
  padding: 2px 8px;
  color: var(--ink-muted);
  cursor: pointer;
}
.video-close:hover { color: var(--ink); }
.video-frame { position: relative; flex: 1 1 auto; display: grid; place-items: center; }
.video-frame video { display: block; width: 100%; height: auto; max-height: 100%; background: #000; }
.video-frame .spinner { position: absolute; }
.video-note {
  position: absolute;
  inset: auto 8px 8px;
  margin: 0;
  padding: 6px 8px;
  border-radius: 4px;
  background: rgb(0 0 0 / .7);
  color: #fff;
  font-size: 12px;
}
.video-note[hidden] { display: none; }
/* A corner handle: bigger than it looks, so a finger can find it. */
.video-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 22px;
  height: 22px;
  cursor: nwse-resize;
  background:
    linear-gradient(135deg, transparent 50%, rgb(255 255 255 / .55) 50%, rgb(255 255 255 / .55) 60%,
                    transparent 60%, transparent 72%, rgb(255 255 255 / .55) 72%, rgb(255 255 255 / .55) 82%,
                    transparent 82%);
}

.recording-files { font-size: 13px; padding: 5px 10px; flex: 0 0 auto; }

/* The fingerboard's tick box, while an editing mode has it off. */
.ctl:has(input:disabled) { opacity: .45; }

/* ---------- the fingerboard ---------- */

/* A dark instrument on a dark ground, whatever the colour scheme, like the score
   pinning its paper: an ebony board, pale strings, a bone nut, blue tapes, and
   the note being played in yellow and red, where the eye finds it at once.

   The SVG is positioned rather than in flow, so the panel's size comes from the
   grid alone and main.js fits the board to it — the board can never hold a row
   or column open while the window shrinks. `--fb-thickness` and `--fb-pad` are
   set from `FINGERBOARD` in constants.js, so the numbers are written once. */
.fingerboard {
  --fb-bg: #141418;
  --fb-board: #060607;
  --fb-edge: rgba(255, 255, 255, .12);
  --fb-string: #eeebe4;
  --fb-nut: #dcc9ae;
  --fb-tape: #4b50f5;
  --fb-lit: #ffe14a;
  --fb-dot: #e3112f;
  --fb-digit: #ffe14a;
  --fb-suspect: #ff8a1f;
  --fb-name: #8e8e9a;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--fb-bg);
}

.fingerboard:not(.vertical) {
  height: calc(var(--fb-thickness) + 2 * var(--fb-pad) + 1px);
  border-top: 1px solid var(--line);
}

.fingerboard.vertical {
  width: calc(var(--fb-thickness) + 2 * var(--fb-pad) + 1px);
  border-left: 1px solid var(--line);
}

.fingerboard svg {
  position: absolute;
  left: var(--fb-pad);
  top: var(--fb-pad);
  display: block;
}

.fingerboard text { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif; }
.fingerboard .fb-board { fill: var(--fb-board); stroke: var(--fb-edge); stroke-width: 1; }
.fingerboard .fb-guide { stroke: #fff; stroke-opacity: .08; stroke-width: 1; }
.fingerboard .fb-guide.octave { stroke-opacity: .3; }
.fingerboard .fb-tape { stroke: var(--fb-tape); }
.fingerboard .fb-nut { fill: var(--fb-nut); }
.fingerboard .fb-string { stroke: var(--fb-string); stroke-opacity: .9; }
.fingerboard .fb-name { fill: var(--fb-name); font-size: 11px; font-weight: 600; }
.fingerboard .fb-name.lit { fill: var(--fb-lit); }
.fingerboard .fb-name.suspect { fill: var(--fb-suspect); }
.fingerboard .fb-sounding { stroke: var(--fb-lit); }
.fingerboard .fb-dot { fill: var(--fb-dot); }
.fingerboard .fb-digit { fill: var(--fb-digit); font-weight: 700; }
/* An open string: a ring rather than a dot, since no finger is down. */
.fingerboard .fb-note.open .fb-dot { fill: var(--fb-board); stroke: var(--fb-dot); stroke-width: 2; }
/* A fingering its pitch contradicts: orange, so it reads as a question. */
.fingerboard .fb-note.suspect .fb-sounding { stroke: var(--fb-suspect); }
.fingerboard .fb-note.suspect .fb-dot { fill: var(--fb-suspect); }
.fingerboard .fb-note.suspect .fb-digit { fill: var(--fb-bg); }
.fingerboard .fb-note.open.suspect .fb-dot { fill: var(--fb-board); stroke: var(--fb-suspect); }
.fingerboard .fb-note.open.suspect .fb-digit { fill: var(--fb-suspect); }
.fingerboard .fb-message {
  fill: var(--fb-name);
  font-size: 12px;
  stroke: var(--fb-board);
  stroke-width: 6px;
  paint-order: stroke;
}

/* ---------- the recording dialog ---------- */

.recording-dialog {
  width: min(460px, calc(100vw - 32px));
  padding: 18px 20px 16px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.recording-dialog::backdrop { background: rgba(0, 0, 0, .3); }

.recording-dialog h2 { margin: 0 0 4px; font-size: 15px; font-weight: 600; }

.recording-dialog .hint { margin: 0 0 14px; color: var(--ink-muted); font-size: 13px; }

.recording-dialog code { font-size: 12px; }

.recording-dialog .field {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr);
  column-gap: 10px;
  align-items: center;
  margin-bottom: 10px;
  font-size: 13px;
}

.recording-dialog .label { color: var(--ink-muted); }

/* The file already in use, which an empty input keeps. */
.recording-dialog .now {
  grid-column: 2;
  color: var(--ink-muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}
.recording-dialog .now:empty { display: none; }

.recording-dialog .error { margin: 4px 0 0; color: #b4232c; font-size: 13px; }

.recording-dialog .actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.recording-dialog button.primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.recording-dialog button:disabled { opacity: .5; cursor: default; }

/* ---------- edit mode: the XML pane ---------- */

/* Set by the splitter drag; the initial value is a little under half, which
   keeps a full measure of music readable next to a full line of XML. */
.stage { --xml-w: 44%; }

.splitter {
  flex: 0 0 7px;
  cursor: col-resize;
  background: var(--line);
  border: 0;
  /* A 7px target is thin for a pointer, so the visible line is drawn inside a
     wider hit area rather than the whole strip being painted. */
  background-clip: content-box;
  padding: 0 3px;
  background-color: var(--line);
}

.splitter:hover,
.splitter.dragging { background-color: var(--accent); }

.xmlpane {
  flex: 0 0 var(--xml-w);
  min-width: 240px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-left: 1px solid var(--line);
}

.xmlbar,
.xmlstatus,
.findbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

/* Where the caret is, in the music's own terms. Monospaced digits so a number
   changing does not shift the words after it as the caret moves. */
.xmlstatus {
  padding: 5px 10px;
  font-size: 12px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  min-height: 27px;
}

.xmlstatus .where { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* The measure and the note read in the same two colours the engraving is
   highlighted in, so the two panes are saying the same thing twice. */
.xmlstatus .measure { color: var(--ink); }
.xmlstatus .note { color: var(--accent); font-weight: 600; }

.xmlbar button,
.findbar button { padding: 4px 9px; font-size: 12px; }
.xmlbar button:disabled,
.findbar button:disabled { opacity: .4; cursor: default; }
.xmlbar .hint,
.findbar .count {
  color: var(--ink-muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.xmlbar .hint.warn,
.findbar .count.warn { color: var(--accent); }
/* Unsaved edits: the one piece of state worth colouring, since it is the one
   that is lost by closing the tab. */
.xmlbar .hint.dirty { color: var(--accent); }

.findbar input {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  font-size: 13px;
  color: inherit;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
}

.findbar input:focus { outline: none; border-color: var(--accent); }

/* The body is the gutter and the text sharing one scroll position: the gutter
   is scrolled from the textarea's scroll event, which is the only way to keep
   them locked without putting the numbers inside the editable text. */
.xmlbody {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  /* Both halves are laid out with these exact metrics. Changing either here
     changes both, which is what stops the numbers drifting from the lines. */
  font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  tab-size: 2;
}

.gutter,
.backdrop,
.xmltext {
  font: inherit;
  padding: 8px 0;
  margin: 0;
  border: 0;
  background: transparent;
  color: inherit;
}

.gutter {
  flex: 0 0 auto;
  min-width: 3.4em;
  padding-right: 8px;
  text-align: right;
  color: var(--ink-muted);
  opacity: .65;
  overflow: hidden;              /* scrolled from the textarea, never by itself */
  white-space: pre;
  user-select: none;
  border-right: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

/* The backdrop and the textarea are the same box, stacked: identical font,
   identical padding, identical wrapping, so a character is at the same pixel in
   both. Anything that changes one metric and not the other shows up
   immediately as the colouring sliding off the text it is colouring. */
.xmlfield {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

.backdrop,
.xmltext {
  position: absolute;
  inset: 0;
  padding-left: 10px;
  white-space: pre;
  overflow: auto;
}

.backdrop {
  /* Scrolled programmatically from the textarea's scroll event; it must never
     be scrollable on its own, or the two drift apart. */
  overflow: hidden;
  pointer-events: none;
  color: var(--ink);
}

/* Colour, and only colour. No weight change and no background on a run of
   text: a bolder face is not guaranteed to have the same advance width even in
   a monospace family, and one pixel of drift here puts every caret position on
   the line under the wrong glyph.

   The current measure is picked out by dimming everything that is not it,
   rather than by tinting it: the measure being edited then reads in the
   document's ordinary ink, which is what you want to be reading. `.focused` is
   set only while there is something to highlight, so a document with the caret
   nowhere in particular is not dimmed for no reason. */
.backdrop.focused { color: var(--ink-muted); }
.backdrop .measure { color: var(--ink); }
.backdrop .note { color: var(--accent); }

.xmltext {
  resize: none;
  outline: none;
  /* The glyphs are the backdrop's; this layer contributes the caret, the
     selection and the editing. */
  color: transparent;
  caret-color: var(--ink);
}

/* A textarea greys its selection out when focus moves to the find box, which
   would hide the very match being stepped through. */
.xmltext::selection,
.xmltext.showsel::selection {
  background: color-mix(in srgb, var(--accent) 45%, transparent);
}

@media (max-width: 720px) {
  /* Side by side stops being side by side: below this there is not enough width
     for a system and a line of XML, so the pane takes the full stage. */
  .stage.editing { flex-direction: column; }
  .stage.editing .xmlpane {
    flex: 1 1 50%;
    width: 100%;
    min-width: 0;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
  .stage.editing .splitter { display: none; }

  /* Every transport control the row cannot hold costs a whole row of the score,
     so the spacing tightens before anything wraps. */
  .transport { gap: 10px 12px; padding: 8px 12px; }
}

/* --------------------------------------------------------------------------
   The list of scores: pick one to open, and tick what stays on this device.
   One control for both, because they are the same list read twice.  Also the
   two states the top bar can report — no server to edit against, and an update
   waiting.  See docs/offline-tablet.md.
   -------------------------------------------------------------------------- */

/* Wider than the staves menu it borrows from: each row carries a name, two
   tick boxes and a size, and wrapping those would make the list unreadable. */
.offline-menu { min-width: 340px; padding: 10px 0 6px; }
.offline-hint { margin: 0 12px 8px; font-size: 12px; color: var(--ink-muted); }
.offline-list { display: flex; flex-direction: column; }
.sample-row {
  display: grid;
  /* name | score | audio | video | size.  Fixed tick columns, so they line up
     down the list, and everything left over goes to the name — which is the
     only cell whose content the reader cannot guess from its column. */
  grid-template-columns: 1fr 46px 46px 46px 64px;
  align-items: center;
  gap: 6px;
  padding: 3px 12px;
}
/* With no manifest nothing can be kept, so the row is a name and nothing
   else — and the name should have the whole width rather than three empty
   columns beside it. */
.sample-row.bare { grid-template-columns: 1fr; }
.sample-row:hover:not(.head) { background: rgba(127, 127, 127, .1); }
.sample-row.head {
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding-bottom: 5px;
}
.sample-row.head span { text-align: center; }
.sample-row.head span:last-child { text-align: right; }
/* A group heading: one cell across the whole row, left-aligned like the names
   it introduces, and ruled off from the group above it.  After the rule above,
   because its one cell is also the last one. */
.sample-row.head.group {
  grid-template-columns: 1fr;
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}
.sample-row.head.group span { text-align: left; }
.sample-row label { justify-content: center; }
/* The name is the button that opens the score, and has to read as a name
   rather than as a control: the row it lives in is the hit area. */
.sample-row .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 5px;
  padding: 2px 4px;
  margin-left: -4px;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.sample-row .name:hover { text-decoration: underline; }
.sample-row .name:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.sample-row.kept .name { font-weight: 600; }
/* The score that is open, which is what the summary above is naming. */
.sample-row.current .name { color: var(--accent); font-weight: 600; }
.sample-row label { display: flex; align-items: center; gap: 4px; cursor: pointer; font-size: 12px; }
.sample-row label.off { opacity: .35; cursor: default; }
.sample-row .size {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--ink-muted);
}
.sample-row .working { color: var(--accent); }
.offline-total {
  margin: 8px 12px 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-muted);
}

/* "Reclaim 3.4 MB" — the leftovers of an interrupted download. Quiet rather
   than alarming: nothing is wrong, and a reader who never presses it loses only
   space they will get back the next time a sync completes. */
.offline-sweep {
  display: block;
  margin: 6px 12px 2px;
  font-size: 12px;
  padding: 3px 9px;
}

.netstate {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(210, 84, 42, .12);
  color: var(--accent);
  white-space: nowrap;
}
/* The same badge saying nothing is wrong, after a check was asked for. Quiet,
   because "everything answered" is not news the bar should shout. */
.netstate.ok { background: rgba(127, 127, 127, .12); color: var(--ink-muted); }

/* Ask the network again. A glyph, because it sits in a bar that is already
   full and the title says the rest. */
.netrefresh {
  font-size: 14px;
  line-height: 1;
  padding: 4px 8px;
}
.netrefresh.working { color: var(--accent); border-color: var(--accent); }
.update {
  font-size: 12px;
  padding: 4px 10px;
  border-color: var(--accent);
  color: var(--accent);
}

/* "Open MusicXML…" with no server to convert it. The input is disabled, which
   stops the click; this is what says so. */
.topbar label.file.disabled { opacity: .4; cursor: default; }

/* Save draft / Publish, and the one-line status beside them. */
.authoring-btn { font-size: 13px; padding: 5px 10px; flex: 0 0 auto; }
.authoring-state {
  font-size: 12px;
  color: var(--muted, #667);
  align-self: center;
  max-width: 36ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.signed-in { display: inline-flex; gap: 6px; align-items: baseline; }
.linklike {
  background: none; border: 0; padding: 0; font: inherit;
  color: inherit; text-decoration: underline; cursor: pointer;
}
.publish-modes { border: 0; margin: 8px 0; padding: 0; display: grid; gap: 6px; }
.publish-modes label { display: flex; gap: 8px; align-items: baseline; font-size: 14px; }

/* ---------------------------------------------------------------------------
   Editing on and off

   Off is the reader's app.  `display: none` rather than `disabled`, because a
   greyed-out Adjust button on a tablet is an invitation to press it and learn
   nothing — and because the bar has to fit a narrow screen, where five
   controls nobody can use are five controls in the way.

   The rule is on `body` rather than on each control so that anything added to
   the editing group later is covered by being marked, not by being remembered.
   --------------------------------------------------------------------------- */
body:not(.editing) .editing-only { display: none !important; }

/* The toggle itself: greyed where editing cannot work, with the reason in the
   title.  Kept visible rather than hidden, so a reader who has been told the
   desktop app can edit is not left hunting for a control that is not there. */
.editing-toggle { white-space: nowrap; }
.editing-toggle:has(input:disabled) { cursor: not-allowed; }

/* The update prompt reuses the recording dialog's frame; only the version line
   is its own. */
.update-versions {
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
}

/* The list's per-score Update button. A reader who declined an edition
   is not asked again until there is a newer one, so this is the way back to a
   choice they have already made once. */
.offline-update {
  font-size: 11px;
  padding: 1px 7px;
  border-color: var(--accent);
  color: var(--accent);
  white-space: nowrap;
  justify-self: end;
}

/* ---------- Sync workspace ---------- */
/* A dark editor shell between the controls and the score, with a light,
   canvas-rendered timeline. The toolbar is deliberately dense; the timeline is
   its own layer. See docs/sync-ui.md. Hidden until Sync mode is on, so its
   grid row collapses to nothing. */

.syncpanel {
  --sync-bg: #23242a;
  --sync-accent: var(--accent);
  --sync-canvas: #faf9f6;
  --sync-note: rgba(0, 0, 0, .82);
  --sync-note-muted: rgba(0, 0, 0, .4);
  background: var(--sync-bg);
  color: #f2f2f4;
  border: 1px solid rgba(255, 255, 255, .08);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  margin: 0 12px;
  font-size: 13px;
}

.sync-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 10px;
  flex-wrap: wrap;
}

.sync-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.sync-btn {
  font: 600 13px -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  height: 25px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #e9e9ee;
  background: #32333b;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: color .25s, background .25s, border-color .25s;
}

.sync-btn:hover:not(:disabled) {
  border-color: var(--sync-accent);
  color: var(--sync-accent);
}

.sync-btn[aria-pressed="true"] {
  color: var(--sync-accent);
  border-color: var(--sync-accent);
  background: color-mix(in srgb, var(--sync-accent) 18%, #32333b);
}

.sync-btn.primary {
  color: #fff;
  background: var(--sync-accent);
  border-color: var(--sync-accent);
}

.sync-btn.primary:hover:not(:disabled) { color: #fff; filter: brightness(1.08); }

.sync-btn:disabled { opacity: .45; cursor: default; }

.sync-btn.sync-icon { padding: 0 8px; font-size: 15px; line-height: 1; }

.sync-btn kbd {
  font: 600 11px ui-monospace, Menlo, monospace;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .12);
}

.sync-beta {
  font: 700 9px -apple-system, sans-serif;
  letter-spacing: .04em;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .14);
}

.sync-armed {
  font-size: 12px;
  color: #c9c9d2;
  white-space: nowrap;
  padding-right: 4px;
}

.sync-now {
  font-size: 12px;
  color: #a9a9b4;
  max-width: 16ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The light canvas and the things that float over it. */
/* Whole-workspace scroll in Sync mode. The page becomes one scroll region: the
   top bar and the transport are pinned, and the waveform panel and the full score
   flow and scroll between them — so a short window never crushes the score (it is
   shown whole and reached by scrolling), and the two never overlap. The score's
   own inner scroll steps aside here (`.scorepane` shows its full height); the
   playhead is followed by scrolling the page instead (see `revealScoreInPage`). */
/* Outside Sync the wrapper is transparent: the panel and stage lay out in the body
   grid exactly as if it were not there (same trick as the hscroll wrappers). */
#syncScrollWrap { display: contents; }

/* In Sync the wrapper is the one scroll region, filling the sync + stage rows
   between the fixed top bar and transport (ordinary grid rows, so no sticky games).
   The waveform panel pins at the top of this region and the full score scrolls
   beneath it. The score's own inner scroll steps aside here; the playhead is
   followed by scrolling this wrapper (see `revealScoreInPage`). */
body.sync-scroll #syncScrollWrap {
  display: block;
  grid-column: 1 / -1;
  grid-row: sync-start / stage-end;
  overflow-y: auto;
  min-height: 0;
}
body.sync-scroll #syncPanel { position: sticky; top: 0; z-index: 20; }
body.sync-scroll .stage { display: block; overflow: visible; min-height: 0; }
body.sync-scroll .scorepane {
  display: block; height: auto; overflow: visible; flex: none;
}

.sync-stage {
  position: relative;
  padding: 0 10px 8px;
}

/* Horizontal scroller for the timeline. The spacer sets the scroll width (the
   zoomed recording); the canvas is the viewport, stuck to the left and redrawn as
   it scrolls past. */
.sync-scroller {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  touch-action: pan-x;
  border-radius: 4px;
}

.sync-spacer {
  height: 1px;
  width: 100%;                    /* set to viewport × zoom in JS */
}

#syncCanvas {
  display: block;
  position: sticky;
  left: 0;
  margin-top: -1px;               /* sit over the 1px spacer, not below it */
  width: 100%;
  height: 196px;
  border-radius: 4px;
  background: var(--sync-canvas);
  touch-action: none;             /* pointer drags, not page scroll */
}

/* A slim horizontal scrollbar that matches the dark panel. */
.sync-scroller::-webkit-scrollbar { height: 9px; }
.sync-scroller::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, .22);
  border-radius: 5px;
}
.sync-scroller::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, .34); }

.sync-pill {
  position: absolute;
  top: 34px;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .78);
  color: #23242a;
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
  transition: opacity .2s;
}

.sync-hint {
  position: absolute;
  left: 14px;
  bottom: 10px;
  max-width: 70%;
  font-size: 12px;
  color: #23242a;
  background: rgba(255, 255, 255, .8);
  border-radius: 4px;
  padding: 1px 6px;
  pointer-events: none;
}
.sync-hint:empty { display: none; }

.sync-popover {
  position: absolute;
  top: 6px;
  left: 10px;
  right: 10px;
  max-width: 520px;
  margin: 0 auto;
  z-index: 5;
  background: #fff;
  color: #23242a;
  border-radius: 6px;
  padding: 12px 16px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .3);
}
.sync-popover h3 { margin: 0 0 6px; font-size: 14px; }
.sync-popover p { margin: 6px 0; font-size: 12.5px; line-height: 1.45; }
.sync-popover kbd, .sync-popover code {
  font: 600 11px ui-monospace, Menlo, monospace;
  background: #eee; border-radius: 3px; padding: 1px 4px;
}

.sync-overflow {
  position: absolute;
  z-index: 6;
  min-width: 160px;
  background: #2a2b33;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 6px;
  padding: 4px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .4);
  display: flex;
  flex-direction: column;
}
/* The overflow menu anchors to its trigger at the top right of the stage. */
#syncMenu { top: 6px; right: 10px; }

.sync-overflow button {
  font: 13px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-align: left;
  color: #e9e9ee;
  background: transparent;
  border: none;
  border-radius: 4px;
  padding: 6px 10px;
  cursor: pointer;
}
.sync-overflow button:hover { background: rgba(255, 255, 255, .1); color: #fff; }

.sync-div {
  height: 1px;
  margin: 4px 6px;
  background: rgba(255, 255, 255, .12);
}

.sync-sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* Narrow: shorten the two long labels and let the toolbar stack rather than
   wrap mid-control. */
@media (max-width: 680px) {
  .sync-beta { display: none; }
}
@media (max-width: 550px) {
  #syncBeats { display: none; }
}
