:root {
  --bg: #1c1a17;
  --panel: #141210;
  --row: #201d19;
  --row-off: #181614;
  --line: #3a342c;
  --text: #ece6dc;
  --muted: #9a9084;
  --amber: #e0a43a;
  --amber-dim: #7a5a22;
  --play: #2e7d32;
  --stop: #b23a3a;
  --track-bg: #3a3530;     /* slider track and switch, off part */
  --knob: #8d847a;
  --thumb-bg: #ece6dc;
  --inner: #ffffff0a;      /* inset hairline around panels */
  --row-hover: #2a2620;
  --off-bg: #3a3a3a;       /* disabled rec button */
  --off-fg: #777;
  --shadow: #0007;
  /* tuner curtain */
  --curtain-top: #0f0d0b;  /* gradient from the top edge */
  --curtain-bottom: var(--panel);
  --pleat: #ffffff06;
  --curtain-shadow: #000a;
  --tn-dim: #6b490d;       /* tuner disks, off / lit; the centre disk is blue */
  --tn-lit: #ffd95e;
  --tn-mid-dim: #2a4a7f;
  --tn-mid-lit: #a8d2ff;
  --tn-ring: #fff;         /* nearest disk */
  --tn-yellow: #ffd95e;    /* Hz value, reference being captured */
  --tn-blue: #a8d2ff;      /* captured reference */
  color-scheme: dark;
}
/* Light theme (theme.js sets data-theme). The tuner curtain, its handle and the spectrogram stay dark displays. */
:root[data-theme="light"] {
  --bg: #e9e3d8;
  --panel: #fffdf9;        /* same tint as --row */
  --row: #fffdf9;
  --row-off: #e7e0d3;
  --line: #cdc2b0;
  --text: #2a241c;
  --muted: #574c3f;
  --amber: #8f5a00;
  --amber-dim: #e2c389;
  --track-bg: #d8cebd;
  --knob: #a39888;
  --thumb-bg: #ffffff;
  --inner: #0000000f;
  --row-hover: #f1ebe1;
  --off-bg: #d6cfc3;
  --off-fg: #8d847a;
  --shadow: #0003;
  --curtain-top: #ded5c4;
  --curtain-bottom: #ece5d8;
  --pleat: #00000008;
  --curtain-shadow: #0003;
  --tn-dim: #e6d5b2;
  --tn-lit: #e8a317;
  --tn-mid-dim: #cdd9ea;
  --tn-mid-lit: #2f7be6;
  --tn-ring: #2a241c;
  --tn-yellow: #8f5a00;
  --tn-blue: #2462c4;
  color-scheme: light;
}
/* tuner controls sit on the curtain: firmer border so the --row tint stands out from it */
:root[data-theme="light"] .curtain-inner { --line: #b8ac97; }
/* the disks container stays dark: dark-theme disk colours */
:root[data-theme="light"] :is(.tuner-disks, .cap-trace) {
  --tn-dim: #6b490d; --tn-lit: #ffd95e; --tn-mid-dim: #2a4a7f; --tn-mid-lit: #a8d2ff; --tn-ring: #fff;
}
/* field labels in black */
:root[data-theme="light"] :is(label, .harmonics-head > span, .notation legend, .seg label) { color: #000; }
/* fades are stronger on a light background: soften them so inactive controls stay readable */
:root[data-theme="light"] .sweep:not(.active) .field { opacity: .7; }
:root[data-theme="light"] :is(.row.off .pitch, .row.off .hz, .row.off .pct) { opacity: .6; }
:root[data-theme="light"] .row.off .vol { opacity: .6; }
:root[data-theme="light"] .spectro {
  --panel: #141210;
  --row: #201d19;
  --row-off: #181614;
  --line: #3a342c;
  --text: #ece6dc;
  --muted: #9a9084;
  --amber: #e0a43a;
  --amber-dim: #7a5a22;
  --track-bg: #3a3530;
  --knob: #8d847a;
  --thumb-bg: #ece6dc;
  --inner: #ffffff0a;
  --row-hover: #2a2620;
  color-scheme: dark;
  color: var(--text);
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.app {
  min-height: 100dvh;
  width: min(100%, 720px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 2dvh, 18px);
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
           max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

/* ---------- Top bar ---------- */
.top { display: flex; flex-direction: column; gap: 10px; }

.title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
}

.transport {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.temper-tag { display: flex; align-items: center; height: 40px; max-width: 34%; font-size: .78rem; line-height: 1.15; color: var(--amber); text-align: right; }
.temper-tag[hidden] { display: none; }
.temper-clear { flex: none; display: grid; place-items: center; width: 26px; height: 26px; margin-left: 6px; padding: 0; border: 1px solid var(--amber-dim); border-radius: 50%; background: none; color: var(--amber); cursor: pointer; }
.temper-clear:hover { background: color-mix(in srgb, var(--amber) 15%, transparent); }
.temper-clear[hidden] { display: none; }
.temper-clear svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

.field { display: flex; flex-direction: column; gap: 5px; }

label, .harmonics-head > span {
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
}

select {
  height: 40px;
  padding: 0 32px 0 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--row) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%239a9084' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 11px center / 10px;
  color: var(--text);
  font: 600 1rem system-ui, sans-serif;
  appearance: none;
  cursor: pointer;
}
select:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* Custom sliders: the thumb sits at the set value (--p, 0..1); the bright fill shows the
   live level (--lp, defaults to --p). While sweeping, the fill moves below the thumb. */
input[type="range"] {
  --p: 0.5;
  --lp: var(--p);
  --thumb: 18px;
  --at-p: calc(var(--thumb) / 2 + (100% - var(--thumb)) * var(--p));
  --at-lp: calc(var(--thumb) / 2 + (100% - var(--thumb)) * var(--lp));
  --track: linear-gradient(90deg,
             var(--amber) 0 var(--at-lp),
             var(--amber-dim) var(--at-lp) var(--at-p),
             var(--track-bg) var(--at-p));
  width: 100%;
  height: 26px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: var(--track);
}
input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: var(--track);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: var(--thumb);
  height: var(--thumb);
  margin-top: calc((6px - var(--thumb)) / 2);
  border-radius: 50%;
  background: var(--thumb-bg);
  border: 3px solid var(--amber);
  box-shadow: 0 1px 4px var(--shadow);
}
input[type="range"]::-moz-range-thumb {
  width: var(--thumb);
  height: var(--thumb);
  box-sizing: border-box;
  border-radius: 50%;
  background: var(--thumb-bg);
  border: 3px solid var(--amber);
  box-shadow: 0 1px 4px var(--shadow);
}
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--amber); outline-offset: 2px; }
input[type="range"]:focus-visible::-moz-range-thumb { outline: 2px solid var(--amber); outline-offset: 2px; }

.play {
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 0;
  background: var(--play);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 5px 16px var(--shadow);
  transition: background-color 150ms, transform 80ms;
}
.play:active { transform: scale(.95); }
.play:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }
.play { padding: 0; grid-template: minmax(0, 1fr) / minmax(0, 1fr); }   /* definite track + no default button padding, so the % sizes below are of the whole button */
.play svg { fill: currentColor; pointer-events: none; }
/* Uniform play/stop symbol, same in every app and at every size: its circumscribed circle is half the button's
   diameter and concentric with the button. Triangle: circle d = 15.45/24 of the icon box, centre (11.27, 12), so the
   box is 77.67% of the button, nudged right 3.04%. Square: d = 16.97/24, so the box is 70.71%. */
.play .icon-play { width: 77.67%; height: 77.67%; transform: translateX(3.04%); }
.play .icon-stop { width: 70.71%; height: 70.71%; }
.play .icon-stop { display: none; }
.play[aria-pressed="true"] { background: var(--stop); }
.play[aria-pressed="true"] .icon-play { display: none; }
.play[aria-pressed="true"] .icon-stop { display: block; }

.freq {
  margin: 0;
  font-size: .8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Sweep mode ---------- */
.sweep {
  display: grid;
  grid-template-columns: auto auto 1fr 1fr;
  align-items: end;
  gap: 8px 16px;
  padding: 10px 14px;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: inset 0 0 0 1px var(--inner);
}
.sweep-toggle { align-self: center; }
.sweep-title { font-weight: 600; font-size: .9rem; }
.sweep-title small { color: var(--muted); font-weight: 400; margin-left: 3px; }
.sweep output {
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  margin-left: 4px;
}
.sweep:not(.active) .field { opacity: .5; }
.sweep-from select { min-width: 76px; }
.sweep.swell { grid-template-columns: auto 1fr 1fr; }

/* ---------- Harmonics grid ---------- */
.harm-wrap { flex: 1 1 auto; display: flex; gap: 8px; align-items: stretch; }
.harm-wrap:has(.harmonics.collapsed) { flex: 0 0 auto; }
.harm-wrap:has(.harmonics.collapsed) .spectro { display: none !important; }
.spectro { display: none; flex: 0 0 auto; width: 84px; background: var(--row-off); border-radius: 14px; box-shadow: inset 0 0 0 1px var(--inner); }
.harm-wrap.listening .spectro { display: block; }
.harmonics {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 14px;
  padding: 10px;
  box-shadow: inset 0 0 0 1px var(--inner);
}

.harmonics-head {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px 8px;
}
.bulk { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.bulk button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 7px;
  padding: 4px 9px;
  font: .75rem system-ui, sans-serif;
  cursor: pointer;
}
.bulk button:hover { color: var(--text); border-color: var(--muted); }
.play.rec { background: var(--rec, #b8372f); }
.play.rec:disabled { background: var(--off-bg); color: var(--off-fg); box-shadow: none; cursor: not-allowed; }
.play.rec:disabled:active { transform: none; }
.play.rec .icon-rec { width: 70.71%; height: 70.71%; }   /* circle d = 16.97/24 like the stop square, so it is half the button's diameter */
.play.rec[aria-pressed="true"] { background: var(--rec, #b8372f); animation: recpulse 1.4s ease-in-out infinite; }
.play.rec[aria-pressed="true"] .icon-rec { display: none; }
@keyframes recpulse { 50% { filter: brightness(1.35); } }
@media (prefers-reduced-motion: reduce) { .play.rec[aria-pressed="true"] { animation: none; } }
.bulk select.instrument {
  height: auto;
  padding: 4px 22px 4px 9px;
  border-radius: 7px;
  background-position: right 7px center;
  background-size: 8px;
  background-color: transparent;
  color: var(--muted);
  font: .75rem system-ui, sans-serif;
}
.bulk select.instrument:hover { color: var(--text); border-color: var(--muted); }
.bulk select.instrument.chosen { color: var(--amber); border-color: var(--amber-dim); }

.rows {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.row {
  --level: 0;
  display: grid;
  grid-template-columns: 74px 92px 64px 1fr 36px;
  align-items: center;
  gap: 10px;
  height: clamp(34px, 5dvh, 42px);
  padding: 0 10px;
  border-radius: 9px;
  background: var(--row);
  position: relative;
  overflow: hidden;
  transition: background-color 150ms;
}
/* live level glow behind the row while sounding */
.row::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #e0a43a26, transparent 70%);
  opacity: var(--level);
  pointer-events: none;
  transition: opacity 400ms;
}
/* animated by JS while sweeping — no lag */
.rows.sweeping .row.swept::before { transition: none; }
.row.off { background: var(--row-off); }
.row.tail[hidden] { display: none; }   /* H14–H64 row: only while a recording left a tail */
.row.tail .h { font-size: .7rem; white-space: nowrap; }   /* longer label in the same column */
.row.off .pitch, .row.off .hz, .row.off .pct { opacity: .4; }
.row.off .vol { opacity: .45; }

/* toggle switch */
.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
}
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.track {
  width: 34px;
  height: 20px;
  border-radius: 10px;
  background: var(--track-bg);
  position: relative;
  flex: 0 0 auto;
  transition: background-color 150ms;
}
.knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--knob);
  transition: transform 150ms, background-color 150ms;
}
.switch input:checked + .track { background: var(--amber-dim); }
.switch input:checked + .track .knob { transform: translateX(14px); background: var(--amber); }
.switch input:focus-visible + .track { outline: 2px solid var(--amber); outline-offset: 2px; }

.h {
  font-weight: 700;
  font-size: .9rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.pitch { font-size: .85rem; white-space: nowrap; }
.pitch .cents { color: var(--muted); font-size: .75rem; margin-left: 3px; }
.hz, .pct {
  font-size: .75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pct { text-align: right; }

/* ---------- Narrow screens ---------- */
@media (max-width: 520px) {
  /* transport row: Base note, Octave, rec, play must stay on one line, so everything shrinks a little */
  /* grid: the temperament tag (if shown) takes its own line above the controls */
  .transport {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, max-content)) auto auto;
    justify-content: end;
    align-items: end;
    gap: 6px 8px;
  }
  .transport .field { min-width: 0; }
  .temper-tag { grid-column: 1 / -1; justify-self: end; justify-content: flex-end; height: auto; min-height: 26px; max-width: 100%; font-size: .72rem; }
  .transport select { height: 36px; padding: 0 24px 0 9px; font-size: .92rem; background-position: right 8px center; background-size: 9px; }
  .transport .play { width: 46px; height: 46px; }
  .row { grid-template-columns: 66px 74px 1fr 30px; gap: 8px; padding: 0 8px; }
  .hz { display: none; }
  .pitch { font-size: .8rem; }
  /* line 1: heading; line 2: all on … reset; line 3: instrument + presets (each line wraps if it must) */
  .harmonics-head { gap: 8px 5px; justify-content: flex-start; }
  .harm-toggle { flex: 1 1 100%; order: 0; }
  .bulk { display: contents; }
  .bulk button { order: 1; }
  .harmonics-head::after { content: ""; order: 2; flex-basis: 100%; height: 0; }
  .bulk select.instrument { order: 3; }
  .bulk select.instrument { padding-left: 7px; }
  .spectro { width: 44px; }
  .bulk button { padding: 4px 8px; }
  .sweep { grid-template-columns: 1fr 1fr; }
  .sweep.swell { grid-template-columns: 1fr 1fr; }
  .swell .sweep-toggle { grid-column: 1 / -1; }
  .sweep-from { justify-self: end; flex-direction: row; align-items: center; gap: 8px; }
}

@media (max-width: 360px) {
  .row { grid-template-columns: 62px 1fr 28px; }
  .pitch { display: none; }
}

/* Embedded in the home page: the tab already names the app */
.embedded .title { display: none; }

/* Touch screens: sliders are driven by JS (horizontal drags only), see touchSafeRange() */
.touch-host { touch-action: pan-y; }
.touch-range { pointer-events: none; }
.touch-range.dragging { filter: brightness(1.25); }

/* Collapsible harmonics panel: chevron button left of the title */
.harm-toggle {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px 2px 0;
  border: 0; background: none; cursor: pointer;
  font: inherit; font-size: .8rem; font-weight: 600; color: var(--muted);
}
.harm-toggle:hover { color: var(--text); }
.harm-toggle:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; border-radius: 4px; }
.harm-toggle svg { width: 16px; height: 16px; transition: transform 150ms; }
.harmonics.collapsed .harm-toggle svg { transform: rotate(-90deg); }
.harmonics.collapsed .bulk, .harmonics.collapsed .rows { display: none !important; }
.harmonics.collapsed .harmonics-head { padding-bottom: 0; }
.harmonics.collapsed .harmonics-head::after { display: none; }

/* ---------- Tuner: a curtain pulled down from the top edge ---------- */
.tuner { display: flex; flex-direction: column; align-items: center; margin-bottom: 10px; }
.curtain {
  display: grid; grid-template-rows: 1fr; width: 100%;
  transition: grid-template-rows 280ms ease;
}
.tuner.collapsed .curtain { grid-template-rows: 0fr; }
.curtain-inner {
  overflow: hidden; min-height: 0;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 54px 12px 58px;
  background: linear-gradient(var(--curtain-top), var(--curtain-bottom));
  border-radius: 0 0 18px 18px;
  box-shadow: inset 0 0 0 1px var(--inner), 0 8px 14px -8px var(--curtain-shadow);
  /* fold-like vertical pleats */
  background-image: repeating-linear-gradient(90deg, var(--pleat) 0 14px, transparent 14px 28px), linear-gradient(var(--curtain-top), var(--curtain-bottom));
}
.tuner.collapsed .curtain-inner { padding-block: 0; visibility: hidden; transition: visibility 0s 280ms, padding 280ms; box-shadow: none; }
.curtain-inner p { margin: 0; }
.tuner-handle {
  display: inline-flex; align-items: center; gap: 6px; padding: 15px 14px 16px;
  border: 1px solid #ffffff59; border-top: 0; border-radius: 0 0 12px 12px; cursor: pointer;   /* whiter in dark theme */
  background: var(--panel);
  font: inherit; font-size: .8rem; font-weight: 600; color: #fff;   /* black in light theme, see below */
}
:root[data-theme="light"] .tuner-handle { color: #000; border-color: var(--line); }
.tuner-handle:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.tuner-handle .fork { width: 18px; height: 18px; }
.tuner-handle .chev { width: 16px; height: 16px; transition: transform 280ms; transform: rotate(180deg); }
.tuner.collapsed .tuner-handle .chev { transform: none; }
.tuner-row { --d: min(46px, calc((100vw - 92px) / 11));   /* disk size (see .tuner-disks), also sizes the capture trace */
  display: flex; flex-direction: column; align-items: center; gap: 16px; width: min(100%, 520px); }
.tuner-id { display: flex; align-items: center; justify-content: center; height: 2.5rem; }   /* fixed: same height for the big note and the small "listening..." */
.tuner-note { font-size: 2.2rem; font-weight: 600; line-height: 1.1; }
.tuner-note .acc { height: .8em; width: auto; overflow: visible; vertical-align: -.08em; margin: 0 .06em; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tuner-note small { font-size: .45em; font-weight: 400; color: var(--muted); margin-left: .3em; }
.tuner-note.idle { font-size: 1.1rem; font-weight: 400; color: var(--muted); }
.tuner-hz b { font-weight: inherit; color: var(--tn-yellow); }
.tuner-hz { font-size: .96rem; color: var(--muted); font-variant-numeric: tabular-nums; min-height: 1.1em; }
.tuner-msg { font-size: .75rem; color: var(--muted); text-align: center; }
.tuner-msg.warn { color: var(--amber); }
/* Nine disks = nine 10-cent bins (-40…+40). Intensity falls off linearly with the distance from the bin centre. */
.tuner-disks {
  width: 100%; display: flex; justify-content: center;
  /* 9 disks + 8 gaps (.25 d) = 11 d must fit the width left by the page (2×14px), curtain (2×12px) and container (2×14px) padding, plus the outline ring */
  gap: calc(var(--d) * .25);
  /* rectangular dark container, like the beats panel of the metronome */
  padding: 16px 14px; border-radius: 14px;
  background: #141210; box-shadow: 0 8px 30px var(--shadow), inset 0 0 0 1px #ffffff0d;
}
.tuner-disks .disk {
  --i: 0; --dim: var(--tn-dim); --lit: var(--tn-lit);
  flex: 0 0 auto; width: var(--d); height: var(--d); border-radius: 50%;
  background: color-mix(in srgb, var(--lit) calc(var(--i) * 100%), var(--dim));
  box-shadow: 0 0 calc(var(--d) * .5) color-mix(in srgb, var(--lit) calc(var(--i) * 45%), transparent);
  outline: 2px solid transparent; outline-offset: 2px;
  transition: background-color 250ms linear, box-shadow 250ms linear, outline-color 150ms;
}
.tuner-disks .disk.top { outline-color: var(--tn-ring); }
.tuner-disks .disk.mid { --dim: var(--tn-mid-dim); --lit: var(--tn-mid-lit); }
/* Trace (recording the reference, or the plot view): the disks are hidden; the note name moves to the left third and the trace of the
   fundamental (#capTrace, drawn by capDraw) takes the right two thirds, on a dark display like the disks'. The row
   takes the disks' place, so the curtain keeps its height: note row (2.5rem) + row gap (16px) + disks (--d + 2×16px). */
.tuner-disks.trace { display: none; }
.tuner-id.trace { align-self: stretch; justify-content: space-between; gap: 10px; height: calc(2.5rem + 16px + var(--d) + 32px); }
.tuner-id.trace .tuner-note { flex: 1 1 0; min-width: 0; font-size: 1.5rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tuner-id.trace .tuner-note.idle { font-size: .95rem; white-space: normal; }
/* trace + progress bar (how long the current steady run has lasted, of CAP_STEADY_MS; set by capShow) */
.cap-box { flex: 0 0 66.67%; width: 66.67%; min-width: 0; height: 100%; display: flex; flex-direction: column; gap: 6px; }   /* explicit width: a canvas's own pixel size would push the note out */
.cap-box[hidden] { display: none; }
.cap-progress[hidden] { display: none; }
.cap-progress { flex: none; height: 4px; border-radius: 2px; background: var(--tn-dim); overflow: hidden; }
.cap-progress span { display: block; height: 100%; width: 0; background: var(--tn-lit); border-radius: inherit; }
.cap-trace { flex: 1 1 auto; min-height: 0; width: 100%;  border-radius: 10px; background: #141210; box-shadow: inset 0 0 0 1px #ffffff0d; }

.tuner-opts { display: flex; gap: 12px; align-items: flex-end; justify-content: center; margin-top: 14px; width: min(100%, 520px); }
.tuner-opts[hidden] { display: none; }
.tuner-opts + .tuner-opts { margin-top: 8px; }
.tuner-opts .field:first-child { flex: 1 1 auto; min-width: 0; }
.tuner-opts select { width: 100%; height: 36px; font-size: .92rem; }
.tuner-opts input {
  width: 76px; height: 36px; padding: 0 8px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--row); color: var(--text); font: 600 .95rem system-ui, sans-serif; text-align: center;
}
.tuner-opts input:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
/* Notation: a segmented radio group (Do / C / Both), app-wide setting */
.notation { margin: 0; padding: 0; border: 0; min-width: 0; }
.notation legend { padding: 0; margin-bottom: 5px; font-size: .8rem; font-weight: 600; color: var(--muted); }
.seg { display: flex; height: 36px; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--row); }
.seg label { flex: 1 1 0; position: relative; display: grid; place-items: center; font-size: .92rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg label + label { border-left: 1px solid var(--line); }
.tuner-opts .seg input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; border: 0; opacity: 0; cursor: pointer; }
.seg label:has(input:checked) { background: var(--amber-dim); color: var(--text); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--amber); outline-offset: -2px; }
.seg label:hover { color: var(--text); }
.label-row { display: flex; align-items: center; gap: 6px; }
.info-btn {
  width: 16px; height: 16px; padding: 0; border-radius: 50%; border: 1px solid var(--muted);
  background: none; color: var(--muted); font: italic 600 .66rem/1 Georgia, serif; cursor: pointer;
  position: relative;
}
.info-btn::after { content: ''; position: absolute; inset: -12px; }   /* larger touch target */
.info-btn:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* ---------- Presets dialog (same layout as the metronome's) ---------- */
.pdlg {
  width: min(420px, calc(100vw - 24px));
  max-height: none; height: fit-content; overflow: hidden;
  padding: 0; border: 1px solid var(--line); border-radius: 14px;
  background: var(--panel); color: var(--text);
}
.pdlg::backdrop { background: #000a; }
.pdlg form { display: flex; flex-direction: column; gap: 10px; padding: 18px; height: min(460px, calc(100dvh - 32px)); }
.pdlg .dlg-title { margin: 0; font-weight: 600; font-size: 1.05rem; }
.info-dlg form { height: auto; }
/* Reference capture: the label replaces the selector (same box), the rec button sits at its right. */
.ref-cap {
  display: flex; align-items: center; height: 36px; margin: 0; padding: 0 12px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--row); color: var(--tn-yellow);
  font: 600 .92rem system-ui, sans-serif; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ref-cap.done { color: var(--tn-blue); border-color: var(--tn-mid-dim); }
.ref-cap[hidden], .tuner-opts select[hidden] { display: none; }
.ref-rec {
  flex: 0 0 auto; width: 72px; height: 36px; padding: 0; border: 1px solid transparent; border-radius: 9px;   /* same height and corners as the select */
  display: grid; place-items: center; background: var(--rec, #b8372f); color: #fff; cursor: pointer;
}
.ref-rec svg { width: 18px; height: 18px; fill: currentColor; }
.ref-rec .i-trash { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ref-rec .i-stop, .ref-rec .i-trash, .ref-rec[data-state="listening"] .i-rec, .ref-rec[data-state="captured"] .i-rec { display: none; }
.ref-rec[data-state="listening"] .i-stop, .ref-rec[data-state="captured"] .i-trash { display: block; }
.ref-rec[data-state="listening"] { animation: recpulse 1.4s ease-in-out infinite; }
.ref-rec[data-state="captured"] { background: var(--row); border-color: var(--line); color: var(--text); }   /* same look as the selects */
.ref-rec[data-state="captured"]:hover { border-color: var(--muted); }
.ref-rec:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .ref-rec[data-state="listening"] { animation: none; } }
/* Display button right of the Notation radio: switches the tuner between disks and plot; shows the other view's icon */
.view-btn {
  flex: 0 0 auto; width: 48px; height: 36px; padding: 0; border: 1px solid var(--line); border-radius: 9px;   /* same height and corners as the radio */
  display: grid; place-items: center; background: var(--row); color: var(--text); cursor: pointer;
}
.view-btn:hover { border-color: var(--muted); }
.view-btn:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.view-btn svg { width: 20px; height: 20px; }
.view-btn .i-plot { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.view-btn .i-disks { width: 32px; fill: var(--tn-lit); }   /* the tuner disks' colours: amber outside, blue centre */
.view-btn .i-disks .mid { fill: var(--tn-mid-lit); }
.view-btn[data-view="plot"] .i-plot, .view-btn[data-view="disks"] .i-disks { display: none; }
.info-text { margin: 0; line-height: 1.45; color: var(--text); }
.pdlg .dlg-title small { color: var(--muted); font-weight: 400; font-size: .8rem; margin-left: .4em; }
.preset-save { display: flex; gap: 8px; }
.preset-save input {
  flex: 1 1 auto; min-width: 0; height: 40px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--row); color: var(--text); font: 1rem system-ui, sans-serif;
}
.preset-save input:focus-visible { outline: 2px solid var(--amber); outline-offset: 1px; }
.btn {
  height: 40px; padding: 0 16px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--row); color: var(--text); font: 600 .9rem system-ui, sans-serif; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--play); border-color: transparent; color: #fff; }
.btn:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
.pdlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: auto; }
.preset-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; flex: 1 1 0; min-height: 0; overflow-y: auto; }
.preset-list[hidden], .preset-empty[hidden] { display: none; }
.preset-list li { display: flex; gap: 6px; }
.preset-load {
  flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 5px; align-items: flex-start; text-align: left;
  padding: 8px 10px; border: 0; border-radius: 8px; background: var(--row); color: var(--text); font: .95rem system-ui, sans-serif; cursor: pointer;
}
.preset-load:hover { background: var(--row-hover); }
.preset-load:focus-visible, .preset-del:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
.preset-head { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 12px; max-width: 100%; }
.preset-name { font-weight: 600; overflow-wrap: anywhere; }
.preset-load small { color: var(--muted); }
.preset-bars { display: flex; align-items: flex-end; gap: 3px; height: 18px; }
.preset-bars i { width: 8px; background: var(--line); border-radius: 1px; }
.preset-bars i.on { background: var(--amber); }
.preset-del { flex: 0 0 auto; width: 40px; border: 0; border-radius: 8px; background: var(--row); color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.preset-del:hover { color: var(--text); background: var(--row-hover); }
.preset-del svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.preset-empty { margin: 0; color: var(--muted); font-size: .9rem; }

/* Collapsed harmonics: a small histogram (one bar per harmonic) replaces the controls */
.harm-hist { cursor: pointer; display: none; flex: 1 1 auto; max-width: 240px; height: 20px; margin-left: auto; align-items: flex-end; gap: 3px; }
.harm-hist i { flex: 1 1 0; background: var(--line); border-radius: 1px; }
.harm-hist i.on { background: var(--amber); }
.harmonics.collapsed .harm-hist { display: flex; }
.harmonics.collapsed .harm-toggle { flex: 0 0 auto; }
