:root {
  --bg: #161a19;
  --panel: #1d2322;
  --line: #34403d;
  --text: #e8efed;
  --muted: #8fa09b;
  --accent: #5fc9a0;
  --accent-dim: #2f6652;
  --play: #2e7d32;
  --stop: #b23a3a;
  --track-bg: #2b3633;     /* slider / switch / meter, empty part */
  --thumb-bg: #e8efed;     /* slider thumb and switch knob */
  --start: #5aa9ff;        /* start mark on the waveform */
  --mark: #f2c744;         /* playhead (waveform and mini-map) */
  --warn: #ff9a8a;
  --caution: #e0a43a;
  --danger-line: #7a3a3a;
  --backdrop: rgba(0, 0, 0, .65);
  color-scheme: dark;
}
/* Light theme (theme.js sets data-theme). The waveform and the mini-map are white; the normalize graph stays a
   dark display. The canvases read their colours from the canvas element, so they pick up the scope below. */
:root[data-theme="light"] {
  --bg: #e3ebe8;
  --panel: #f4f8f7;
  --line: #c2d0cb;
  --text: #15201d;
  --muted: #566762;
  --accent: #187a56;
  --accent-dim: #d6eee4;
  --track-bg: #cdd8d4;
  --thumb-bg: #ffffff;
  --warn: #b3261e;
  --caution: #a15c00;
  --danger-line: #e3a39d;
  --backdrop: rgba(0, 0, 0, .45);
  color-scheme: light;
}
:root[data-theme="light"] :is(.wave, .progress-track) {
  --panel: #fff;
  --accent-dim: #b4d6c8;   /* bars after the playhead */
  --mark: #b88a00;         /* playhead */
  --start: #1f6fd1;        /* start mark */
}
:root[data-theme="light"] #normCanvas {
  --bg: #161a19;
  --panel: #1d2322;
  --line: #34403d;
  --text: #e8efed;
  --muted: #8fa09b;
  --accent: #5fc9a0;
  --accent-dim: #2f6652;
  color-scheme: dark;
}
*, *::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: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  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));
}
.app.drag { outline: 2px dashed var(--accent); outline-offset: -8px; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.title { margin: 0; font-size: 1.05rem; font-weight: 600; color: var(--muted); }
.open, button {
  font: 600 .95rem system-ui, sans-serif;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  min-height: 40px;
  padding: 0 14px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, .open:focus-within, input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.open:has(+ input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.track-name { margin: 0; color: var(--muted); overflow-wrap: anywhere; }
.track-name.loaded { color: var(--text); font-weight: 600; font-size: 1.05rem; }

label, .lbl { font-size: .8rem; font-weight: 600; color: var(--muted); }
output { font-variant-numeric: tabular-nums; color: var(--text); margin-left: 6px; letter-spacing: 0; }

.times { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); }
.times output { margin: 0; color: var(--muted); }

.transport { display: flex; align-items: center; justify-content: center; gap: 18px; }
.skip { min-width: 64px; min-height: 48px; border-radius: 24px; }
.play {
  width: 72px; height: 72px; min-height: 0; padding: 0; border: 0; border-radius: 50%;
  background: var(--play); color: #fff; display: grid; place-items: center;
}
.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; }
/* Loop pause: the stop button shows the seconds left instead of the square (a click still stops) */
.play .count { display: none; grid-area: 1 / 1; font: 700 1.9rem/1 system-ui, sans-serif; font-variant-numeric: tabular-nums; pointer-events: none; }
.play.counting .count { display: block; }
.play.counting .icon-stop { display: none; }
/* Film-leader look: crosshair, inner ring and a radial wipe sweeping once per second (--n sweeps, set by countdown(),
   so the animation ends with the pause: no infinite animation, see "No infinite CSS animation" in ARCHITECTURE). */
@property --sweep { syntax: '<angle>'; inherits: false; initial-value: 0deg; }
@keyframes sweep { to { --sweep: 360deg; } }
.play .sweep {
  display: none; grid-area: 1 / 1; width: 100%; height: 100%; border-radius: 50%; pointer-events: none;
  background:
    linear-gradient(rgb(255 255 255 / .35), rgb(255 255 255 / .35)) center / 1px 100% no-repeat,
    linear-gradient(rgb(255 255 255 / .35), rgb(255 255 255 / .35)) center / 100% 1px no-repeat,
    radial-gradient(circle closest-side, transparent 72%, rgb(255 255 255 / .45) 73% 76%, transparent 77%),
    conic-gradient(rgb(0 0 0 / .28) var(--sweep), transparent 0);
}
.play.counting .sweep { display: block; animation: sweep 1s linear var(--n, 1); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; }
.steps, .loop-btns { display: flex; gap: 8px; }
.loop-btns button { flex: 1; white-space: nowrap; }
.loop-btns .toggle { flex: 0 0 auto; }   /* "Start Loop" / "Stop Loop": natural width, label never wraps */
@media (min-width: 601px) { .loop-btns .toggle .txt { display: inline-block; min-width: 10ch; text-align: center; } }   /* room for the longer label, so the button keeps its size when it toggles (text shown only above 600 px) */
.steps button { min-width: 44px; }
.hint { margin: 0; font-size: .78rem; color: var(--muted); }

input[type="range"] {
  --p: 0;
  width: 100%; height: 26px; margin: 0; background: transparent; cursor: pointer;
  -webkit-appearance: none; appearance: none;
  --track: linear-gradient(90deg, var(--accent) calc(var(--p) * 100%), var(--track-bg) calc(var(--p) * 100%));
}
input[type="range"]:disabled { opacity: .4; cursor: default; }
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: 18px; height: 18px; margin-top: -6px; border-radius: 50%;
  background: var(--thumb-bg); border: 3px solid var(--accent);
}
input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--thumb-bg); border: 3px solid var(--accent); }
input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.switch { display: inline-flex; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 44px; height: 26px; border-radius: 13px; background: var(--track-bg); position: relative; transition: background-color 150ms; }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--thumb-bg); transition: transform 150ms; }
.switch input:checked + .track { background: var(--accent-dim); }
.switch input:checked + .track .knob { transform: translateX(18px); background: var(--accent); }
.switch input:disabled + .track { opacity: .4; }

/* Waveform: canvas for display, transparent range input on top for pointer + keyboard seeking */
.wave { touch-action: pan-y; user-select: none; -webkit-user-select: none; position: relative; height: 96px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); overflow: hidden; }
.wave canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
/* Decoding: a row of bars pulsing in a wave, centred on the flat line */
.wave-loading { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; gap: 6px; pointer-events: none; }
.wave.loading .wave-loading { display: flex; }
.wave-loading i { width: 6px; height: 60%; max-height: 64px; border-radius: 3px; background: var(--accent); transform: scaleY(.15); animation: wave-load 1.1s ease-in-out infinite; }
.wave-loading i:nth-child(2) { animation-delay: .1s; }
.wave-loading i:nth-child(3) { animation-delay: .2s; }
.wave-loading i:nth-child(4) { animation-delay: .3s; }
.wave-loading i:nth-child(5) { animation-delay: .4s; }
.wave-loading i:nth-child(6) { animation-delay: .5s; }
.wave-loading i:nth-child(7) { animation-delay: .6s; }
@keyframes wave-load { 0%, 100% { transform: scaleY(.15); opacity: .5; } 50% { transform: scaleY(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .wave-loading i { animation-duration: 3s; } }
.wave input[type="range"] { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }   /* keyboard only; pointer input is handled in JS */
/* Full-track progress under the waveform: accent band = visible (zoomed) window, yellow round handle = playback position */
.progress { position: relative; height: 16px; margin-top: 2px; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; }   /* tall hit area around the thin track */
.progress-track { position: absolute; left: 0; right: 0; top: 6px; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.progress-handle { position: absolute; top: 2px; left: 0; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%; background: var(--mark); border: 2px solid var(--bg); box-sizing: border-box; box-shadow: 0 0 0 1px rgba(0, 0, 0, .25); }
.progress-track canvas { display: none; position: absolute; inset: 0; width: 100%; height: 100%; }
.progress-marks { position: absolute; left: 0; right: 0; top: 6px; height: 4px; pointer-events: none; }   /* same box as the track, so the dots are centred on it */
.pm { position: absolute; top: 50%; width: 10px; height: 10px; margin: -5px 0 0 -5px; background: #e040fb; clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }   /* diamond */
.pm-line { display: none; }   /* the A-B line, large displays only (below) */
.pm.loop { background: var(--text); }   /* loop ends: white like the A / B bars on the waveform (dark in light theme) */
/* Start mark (blue, as on the waveform), above the position handle: a diamond, a line on large displays */
.progress-start { position: absolute; top: 8px; width: 10px; height: 10px; margin: -5px 0 0 -5px; background: var(--start); clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); pointer-events: none; }
:root[data-theme="light"] .progress-start { --start: #1f6fd1; }
:root[data-theme="light"] .progress-handle { --mark: #b88a00; }   /* yellow playhead, readable on the white mini-map */
.pm.off { background: #6f7c78; }
.progress-view { position: absolute; top: 0; bottom: 0; left: 0; width: 100%; background: var(--accent); }
/* Large displays: the bar is a mini-map of the whole waveform; markers and loop ends become vertical lines */
@media (min-width: 601px) and (min-height: 560px) {
  .progress { height: 36px; margin-top: 6px; }
  .progress-track { top: 0; height: 100%; border-radius: 6px; background: var(--panel); border: 1px solid var(--line); }
  .progress-track canvas { display: block; }
  .progress-view { background: color-mix(in srgb, var(--accent) 28%, transparent); border-left: 1px solid var(--accent); border-right: 1px solid var(--accent); box-sizing: border-box; }
  .progress-marks { top: 0; height: 100%; }
  .pm { top: 0; width: 2px; height: 100%; margin: 0 0 0 -1px; clip-path: none; }
  .progress-handle { top: 0; width: 2px; height: 100%; margin-left: -1px; border: 0; border-radius: 0; background: var(--mark); box-shadow: none; }
  .progress-start { top: 0; width: 2px; height: 100%; margin: 0 0 0 -1px; clip-path: none; }
  .pm-line { display: block; position: absolute; top: 50%; height: 0; border-top: 1px dashed var(--text); }   /* A-B line, like on the waveform */
  .pm-line.off { border-top-color: #6f7c78; }
}
@media (min-width: 601px) and (min-height: 700px) { .progress { height: 44px; } }
.wave:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Recording */
.actions { display: flex; align-items: center; gap: 8px; }
.rec { gap: 8px; min-width: 76px; }
.rec .dot { width: 12px; height: 12px; border-radius: 50%; background: #e5484d; display: inline-block; }
.rec[aria-pressed="true"] { border-color: #e5484d; font-variant-numeric: tabular-nums; }
.rec[aria-pressed="true"] .dot { border-radius: 2px; animation: blink 1s steps(2, start) infinite; }
@keyframes blink { 50% { opacity: .3; } }
.transport { flex-wrap: wrap; gap: 12px; }
.btn { font: 600 .95rem system-ui, sans-serif; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 9px; min-height: 40px; padding: 0 14px; display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto; text-decoration: none; cursor: pointer; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
[hidden] { display: none !important; }

/* Recording dialog */
#recDialog, #confirmDialog, #infoDialog, #markerDialog, #normDialog { border: 1px solid #e5484d; border-radius: 14px; background: var(--panel); color: var(--text); padding: 0; width: min(88vw, 320px); }
#recDialog::backdrop, #confirmDialog::backdrop, #infoDialog::backdrop, #markerDialog::backdrop, #normDialog::backdrop { background: var(--backdrop); }
.rec-body { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 24px 20px; }
.rec-title { margin: 0; display: flex; align-items: center; gap: 10px; font-weight: 600; }
.rec-title .dot { width: 12px; height: 12px; border-radius: 50%; background: #e5484d; animation: blink 1s steps(2, start) infinite; }
.rec-time { margin: 0; font-size: 2.6rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.rec-stop { gap: 8px; min-height: 48px; min-width: 140px; border-radius: 24px; background: var(--stop); border-color: var(--stop); color: #fff; }
.rec-stop svg { width: 16px; height: 16px; fill: currentColor; }
#dlShare { background: var(--mark); border-color: var(--mark); color: #1a1400; }   /* Share in the Download dialog: like Download, yellow */
#dlOk { background: var(--start); border-color: var(--start); }   /* Download: blue */
.rec-stop .dlg-ico { width: 18px; height: 18px; flex: 0 0 auto; fill: none; }   /* Share / Download icons: before the label (icon only on small displays) */

.hint.warn { color: var(--warn); font-size: .85rem; }

.meter { position: relative; width: 100%; height: 14px; border-radius: 7px; background: var(--track-bg); overflow: hidden; }
.meter-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); transition: background-color 80ms; }
.meter-fill.hot { background: #e0a43a; }
.meter-fill.clip { background: #e5484d; }
.meter-peak { position: absolute; top: 0; bottom: 0; left: 0; width: 2px; background: var(--text); }

#confirmDialog { border-color: var(--line); }
.confirm-text { margin: 0; text-align: center; line-height: 1.4; }
.confirm-btns { display: flex; gap: 10px; width: 100%; }
.confirm-btns button { flex: 1; min-width: 0; }
/* Header actions: icon + label, icon only on small screens */
.actions .ico { width: 20px; height: 20px; flex: 0 0 auto; }
.open, .btn { gap: 8px; }
.actions .btn { flex: 0 0 auto; }
#normalize:disabled { opacity: .4; cursor: default; }
@media (min-width: 481px) { #takeDownload .ico-share { display: none; } }   /* large displays: download icon + label; small: download + share icons */

/* Normalize dialog */
#normDialog { border-color: var(--accent); width: min(92vw, 520px); }
#normDialog .rec-body { align-items: stretch; }
#normDialog .rec-title { justify-content: center; }
#normCanvas { width: 100%; height: 130px; display: block; border-radius: 8px; background: var(--bg); touch-action: none; }
.norm-info { margin: 0; text-align: center; font-size: .9rem; color: var(--muted); }
.norm-info.warn { color: var(--caution); }
@media (max-width: 480px) {
  .actions .label { display: none; }
  .actions .open, .actions .btn, .actions .rec, .actions #normalize { flex: 0 0 44px; width: 44px; height: 44px; min-width: 44px; min-height: 44px; padding: 0; border-radius: 50%; }   /* fixed round buttons, never shrink */
  .actions #takeDownload { flex: 0 0 auto; width: auto; padding: 0 12px; border-radius: 22px; gap: 6px; }   /* icon only (download + share): a fixed-height pill */
  .actions .rec[aria-pressed="true"] .label { display: inline; }   /* keep the timer visible while recording */
  .actions .rec[aria-pressed="true"] { flex: 0 0 auto; width: auto; border-radius: 22px; padding: 0 12px; }
}

/* Download dialog: each button as wide as its content (icon + label), Cancel on the left, Share and Download on the right */
#dlDialog .confirm-btns { flex-wrap: wrap; justify-content: flex-end; }
#dlDialog .confirm-btns button { flex: 0 0 auto; min-width: 0; padding: 0 16px; white-space: nowrap; }
#dlDialog #dlCancel { margin-right: auto; }
@media (max-width: 600px) {   /* phones: [Share (icon only, round)][Download (icon + label), the rest of the row], Cancel full width below */
  #dlDialog .confirm-btns { display: grid; grid-template-columns: 48px 1fr; }
  #dlDialog .confirm-btns #dlShare { width: 48px; padding: 0; }
  #dlDialog #dlShare .label { display: none; }
  #dlDialog #dlCancel { grid-column: 1 / -1; grid-row: 2; margin-right: 0; }
  #dlDialog #dlShare[hidden] + #dlOk { grid-column: 1 / -1; }   /* no share: Download full width */
}

/* Speed and loop panels: stacked on wide screens, one line on small ones */
.controls { display: flex; flex-direction: column; gap: inherit; }
.tune { display: contents; }   /* wide screens: panels stacked like any other */
.tab-open { display: none; }
/* tablet landscape: speed and transpose side by side, both fully expanded */
@media (min-width: 601px) and (orientation: landscape) {
  .tune { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: stretch; }
  .tune .panel { min-width: 0; }
  .tune .hint { display: none; }
  .app > .controls { width: max(min(100%, 720px), calc(100% - 172px)); }   /* same width as the waveform */
  .controls > .panel { width: fit-content; min-width: min(100%, 792px); max-width: 100%; margin-inline: auto; }   /* loop: column width + 10%, wider when its labels need it (fr, es), up to the waveform's width; centred */
}
/* tablets, portrait or landscape: the loop label sits on the same row as the buttons (saves a row of height); the pause slider takes the row below.
   Selected by id: the aria-label is translated. */
@media (min-width: 601px) {
  #loopPanel { display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 12px; }
  #loopPanel .row-head { min-height: 0; white-space: nowrap; }   /* "Loop A–B" on one line, left of the buttons */
  #loopPanel .loop-pause { grid-column: 1 / -1; }
}
@media (max-width: 600px) {
  .controls { display: flex; flex-direction: column; gap: inherit; }
  .controls .panel { padding: 10px; min-width: 0; }
  .controls .row-head { flex-wrap: wrap; gap: 6px; min-height: 0; }
  .controls .hint { display: none; }
  /* speed (slider) and transpose (compact fixed-width box) side by side */
  .tune { display: flex; gap: 8px; }
  .tune .panel { min-height: 109px; position: relative; }   /* = the speed panel, so both boxes are the same height */
  #speedPanel { flex: 1 1 0; display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 10px; row-gap: 6px; }
  #speedPanel .row-head { display: contents; }
  #speedPanel label { grid-column: 1; grid-row: 1; min-width: 0; }
  /* - / + as tiny buttons right of the value */
  #speedPanel .steps { grid-column: 2; grid-row: 1; gap: 4px; }
  #speedPanel .steps button:not(.reset) { min-width: 28px; min-height: 24px; height: 24px; padding: 0; border-radius: 6px; font-size: .9rem; line-height: 1; }
  #speedPanel input[type="range"] { grid-column: 1 / -1; grid-row: 2; }
  #speedPanel .reset { display: none; }   /* tap the value instead */
  /* the 100% tick under the slider is a button that resets the speed; the text stays aligned with the other ticks
     and the pill is drawn around it with the ::before (instead of the usual tick mark) */
  #speedPanel .tick-reset { cursor: pointer; pointer-events: auto; color: var(--text); }
  #speedPanel .tick-reset::before { left: -9px; right: -9px; top: 2px; bottom: -3px; width: auto; height: auto; background: none; border: 1px solid var(--line); border-radius: 8px; }
  #speedPanel .tick-reset:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  #speedPanel .ticks span:is(:nth-child(2), :nth-child(3), :nth-child(5)) { display: none; }   /* fewer labels: the panel is narrow */
  #speedPanel .ticks { grid-column: 1 / -1; grid-row: 3; margin-top: -2px; }   /* under the slider, not under the reset button */
  /* transpose: value on the left (room for "+12"), + above - on the right; no slider, no label */
  #transposePanel { flex: 0 0 124px; display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 6px; row-gap: 6px; }
  #transposePanel .row-head, #transposePanel .steps { display: contents; }
  #transposePanel label { grid-column: 1; grid-row: 1 / 3; text-align: center; }
  #transposePanel .interval { display: block; font-size: .8rem; font-weight: 400; }
  .interval .int-label { display: none; }
  .tune[data-open="speed"] #transposeOut::after { content: " " attr(data-short); }   /* compact box: no room for the full word */
  #transposePanel #transposeOut { display: block; font-size: 1.4rem; font-weight: 700; }   /* the semitones are the big label */
  #transposePanel #transposeOut::after { font-size: .8rem; font-weight: 400; }   /* small unit: "+11.5" must fit */
  #transposePanel .lt { display: block; position: absolute; top: 10px; left: 10px; }   /* "TR." in the corner, like the SPEED label */
  #transposePanel .lt .full { display: none; }
  #transposePanel .lt .abbr { display: inline; }
  #transposePanel .hint, #transposePanel input[type="range"], #transposePanel .ticks, #transposePanel .reset, #transposePanel .fine { display: none; }
  #transposePanel .steps button { min-width: 40px; min-height: 36px; padding: 0; grid-column: 2; }
  #transposePanel #transposeUp { grid-row: 1; }
  #transposePanel #transposeDown { grid-row: 2; }
  /* accordion: data-open on .tune says which box is expanded. Default "speed": speed open, transpose compact. */
  .tune[data-open="speed"] #transposePanel .tab-open, .tune[data-open="transpose"] #speedPanel .tab-open { display: block; position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; background: transparent; border: 0; border-radius: 12px; cursor: pointer; z-index: 1; }
  .tab-open:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
  #transposePanel .steps button { position: relative; z-index: 2; }   /* above the tap-to-expand overlay */
  /* "transpose": transpose expanded (label, then - + 0 and quarter-tone buttons), speed collapsed to a tab */
  .tune[data-open="transpose"] #speedPanel { flex: 0 0 auto; min-width: 84px; display: flex; flex-direction: column; justify-content: center; }
  .tune[data-open="transpose"] #speedPanel :is(input[type="range"], .ticks, .steps) { display: none; }
  .tune[data-open="transpose"] #speedPanel .row-head { display: block; }
  .tune[data-open="transpose"] #speedPanel label { display: flex; flex-direction: column; align-items: center; text-align: center; }
  /* expanded transpose: same label block as the compact box (but "TRANSPOSE" in full), then a 2x2 grid of buttons:
     0 over 1/4 on the left, + over - on the right */
  .tune[data-open="transpose"] #transposePanel { flex: 1 1 0; grid-template-columns: 1fr auto auto; }
  .tune[data-open="transpose"] #transposePanel .lt .full { display: inline; }
  .tune[data-open="transpose"] #transposePanel .lt .abbr { display: none; }
  .tune[data-open="transpose"] #transposePanel :is(#transposeReset, #transposeFine) { display: inline-flex; grid-column: 2; }
  .tune[data-open="transpose"] #transposePanel #transposeReset { grid-row: 1; }
  .tune[data-open="transpose"] #transposePanel #transposeFine { grid-row: 2; padding: 0; margin: 0; }
  .tune[data-open="transpose"] #transposePanel :is(#transposeUp, #transposeDown) { grid-column: 3; }
  .tune[data-open="transpose"] #transposePanel #transposeReset .ico { display: none; }
  .tune[data-open="transpose"] #transposePanel #transposeReset .txt { display: inline; }
  .controls .loop-btns { flex-wrap: wrap; gap: 6px; }
  .controls .loop-btns button { flex: 1 1 0; padding: 0 6px; }
}

/* small screens: drop the help texts (errors and warnings stay) */
@media (max-width: 600px) {
  .track-name.placeholder, #recMsg:not(.warn) { display: none; }
}

/* loop buttons: icon + text from 1100 px (the widest translations need ~1050 px on one row), text only in between,
   icon only on small screens; steps: text on wide screens, icon on small ones */
.loop-btns .ico, .steps .ico { display: none; flex: 0 0 auto; width: 20px; height: 20px; }
.loop-btns button { gap: 6px; }
@media (min-width: 1100px) { .loop-btns .ico { display: block; } }
@media (max-width: 600px) {
  .loop-btns .txt, .steps .txt { display: none; }
  .loop-btns .ico, .steps .ico { display: block; }
}

.zoom-reset { position: absolute; top: 6px; right: 6px; min-height: 0; height: 24px; padding: 0 8px; border-radius: 12px; font-size: .75rem; background: #000a; color: #fff; font-variant-numeric: tabular-nums; }

.skip .ico { width: 20px; height: 20px; display: block; }
#metroLink { flex-direction: column-reverse; gap: 4px; }   /* the tempo above the icon */
#metroLink .ico { width: 26px; height: 26px; margin: -3px; }   /* 30% bigger than the other transport icons; the margin keeps the button size */
#metroLink .bpm { font: 600 9px/1 system-ui, sans-serif; font-variant-numeric: tabular-nums; opacity: .8; }   /* the metronome tempo, above the icon */
#metroLink .icons { display: flex; align-items: center; }
#metroLink .ico.tap { display: none; }   /* while playing, clicks are taps: a hand left of the metronome */
#metroLink.live .ico.tap { display: inline; }
#metroLink .needle-l, #metroLink.swing .needle-r { display: none; }   /* tap tempo: the needle swings on each tap */
#metroLink.swing .needle-l { display: inline; }
/* tap tempo: each tap shows the button on, then it fades back to off in 1 s (LINK_TAP_MS); restarted by every tap */
@keyframes tapFade {
  from { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
  to { background: var(--panel); border-color: var(--line); color: var(--text); }
}
#metroLink.tapping { animation: tapFade 1s linear forwards; }
#metroLink[aria-pressed="true"] { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* toggle button: stays pressed (accent) while on */
.toggle { padding: 0 14px; }
.toggle .ico { width: 20px; height: 20px; }
.toggle[data-on="true"] { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

.wave.panning { cursor: grabbing; }

/* Info (i) button and help dialog */
.title-wrap { display: flex; align-items: center; gap: 8px; }
.info-btn { width: 26px; height: 26px; min-height: 0; padding: 0; border-radius: 50%; font: italic 700 .9rem Georgia, serif; color: var(--muted); }
.info-btn:hover { color: var(--text); }
.info-btn.blink { animation: infoBlink 1.2s ease-in-out infinite; }   /* until the help is opened the first time */
@keyframes infoBlink { 50% { color: #fff; background: #3b82f6; border-color: #3b82f6; } }
#infoDialog { border-color: var(--line); }
.info-body { align-items: stretch; }
.info-body .rec-title { justify-content: center; }
/* a two-column table: one row per gesture, horizontal rules only, cell content at the top */
.info-list { margin: 0; display: grid; grid-template-columns: 1fr 2fr; border-bottom: 1px solid var(--line); }   /* labels 1/3 (they wrap), how-to 2/3 */
.info-list dt, .info-list dd { margin: 0; padding: 8px 0; border-top: 1px solid var(--line); align-self: stretch; }   /* stretched, so each row's rule runs across both cells */
.info-list dt { overflow-wrap: anywhere; font-weight: 600; font-size: .8rem; color: var(--muted); padding-right: 14px; }
.info-list dd { line-height: 1.35; }
.info-list .new { color: #3b82f6; }   /* rows new or changed since the help was last opened */
.info-list .inline-ico { width: 1.15em; height: 1.15em; vertical-align: -.2em; margin: 0 .1em; }   /* a button icon inside the help text */
#infoDialog { width: min(92vw, 420px); }


/* Speed markers under the slider (--f is the position 0..1 along 25..150%) */
.lt .abbr { display: none; }
.steps .fine { padding: 0 23px; margin-right: 16px; }   /* gap to the - button: 8 + 16 = 3x the usual 8px */
.fine[aria-pressed="true"] { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
#transposeOut::after { content: " " attr(data-unit); }
#transposeOut { color: var(--accent); font-weight: 700; }
#transposeOut, .interval { white-space: nowrap; }
.interval { text-transform: none; color: var(--muted); font-weight: 400; font-family: Georgia, "Times New Roman", serif; }   /* roman numerals read best with serifs */
.interval:empty::before { content: "\00a0"; }
.ticks { display: block; position: relative; height: 22px; margin-top: -4px; font-size: .7rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.ticks span { position: absolute; top: 0; left: calc(9px + (100% - 18px) * var(--f)); transform: translateX(-50%); padding-top: 6px; }
.ticks span::before { content: ""; position: absolute; top: 0; left: 50%; width: 1px; height: 4px; background: var(--line); }

/* Layout: the controls sit at the bottom; the waveform takes the height left above them, up to 300px, and is
   centred vertically in that space. */
.seek { flex: 1 1 0; min-height: 124px; display: flex; flex-direction: column; justify-content: center; }
.wave { flex: 1 1 0; height: auto; min-height: 96px; max-height: 300px; }

/* small devices (phones, portrait or landscape): play button 30% smaller (72px -> ~50px) */
@media (max-width: 600px), (max-height: 480px) {
  .play { width: calc(72px * 0.7); height: calc(72px * 0.7); }
  .play .count { font-size: 1.35rem; }
}
/* phones: five transport buttons (metronome link, rewind, pause, play, marker) on one line, down to 320 px */
@media (max-width: 600px) {
  .transport { gap: 8px; }
  .skip { min-width: 52px; padding: 0 10px; }
}

/* Select (arm loop drag) button, touch devices only */
.arm[aria-pressed="true"], #loopSpeedUp[aria-pressed="true"] { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.wave.armed { box-shadow: inset 0 0 0 2px var(--accent); }

/* portable devices: no track title label (errors, which are not .loaded, stay visible) */
@media (max-width: 600px), (max-height: 480px) {
  .track-name.loaded { display: none; }
}

/* Loop pause: label + output on the left, slider on the right */
.loop-pause { display: flex; align-items: center; gap: 12px; }
.loop-pause label { flex: 0 0 auto; }
.loop-pause output { flex: 0 0 auto; min-width: 4.5ch; margin-left: -6px; text-align: left; font-variant-numeric: tabular-nums; }   /* close to the slider (6px), no extra room after it (just the row gap); fixed room for "10 s", so the slider does not resize */
.loop-pause input[type="range"] { flex: 1 1 auto; }
.loop-pause .intro { flex: 0 0 auto; min-height: 0; height: 28px; padding: 0 10px; font-size: .8rem; }   /* tiny toggle; the label is the same in every language */
.loop-pause .intro { width: var(--loop-toggle-w, auto); }   /* as wide as the Start/Stop Loop button, at every screen size (width measured in app.js) */
.intro[aria-pressed="true"] { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* Intro dialog: one section per mode, each opened by its radio; the other sections are dimmed and disabled */
#introDialog, #dlDialog, #speedUpDialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); padding: 0; width: min(92vw, 400px); }
#introDialog::backdrop, #dlDialog::backdrop, #speedUpDialog::backdrop { background: var(--backdrop); }
#dlDialog { width: min(92vw, 440px); }   /* room for Cancel + Share + Download on one row in every language */
#dlAudioHint { overflow-wrap: anywhere; }
.intro-body { align-items: stretch; }
.intro-body .rec-title { justify-content: center; }
.intro-opt { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.intro-opt:has(input[type="radio"]:checked) { border-color: var(--accent); }
.intro-opt:has(input[type="radio"]):not(:has(input[type="radio"]:checked)) > :not(label) { opacity: .4; }   /* unselected option (boxes without radios, like Speed-up, are never dimmed) */
.intro-opt .hint { margin: 0; }
.intro-row { display: flex; align-items: center; gap: 12px; }
.intro-row input[type="range"] { flex: 1 1 auto; }
.intro-row output { flex: 0 0 auto; min-width: 4ch; text-align: right; font-variant-numeric: tabular-nums; }
/* Speed-up dialog: two label / number rows */
.speedup-opt { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px 14px; padding: 14px; }
.speedup-opt > label { justify-self: start; text-align: left; font-size: .9rem; color: var(--text); font-weight: 500; }   /* labels on the left */
.speedup-field { justify-self: end; display: inline-flex; }   /* controls flush with the right edge */
/* stepper: one joined control, - | value | + */
.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); overflow: hidden; }
.stepper:focus-within { border-color: var(--accent); }
.speedup-step { min-width: 34px; min-height: 36px; padding: 0; border: 0; border-radius: 0; background: transparent; color: var(--muted); font-size: 1.15rem; line-height: 1; }
.speedup-step:hover { color: var(--text); background: var(--panel); }
.speedup-step:focus-visible { outline-offset: -2px; }
.stepper-value { display: inline-flex; align-items: center; justify-content: center; width: calc(5ch + 16px); border-inline: 1px solid var(--line); cursor: text; }   /* value + unit, same width in every stepper so they line up */
.stepper input { width: calc(3ch + 4px); min-width: 0; padding: 0 2px; border: 0; background: transparent; color: var(--text);
  font: 600 1.05rem system-ui, sans-serif; text-align: right; font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.stepper-unit { width: 1.6ch; font-size: .8rem; color: var(--muted); }   /* "%" after the value; empty for the loop count */
.stepper input:focus { outline: none; }
.stepper input::placeholder { color: var(--muted); opacity: 1; }   /* From, empty: the current speed */
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }   /* the -/+ buttons replace the spinner */
/* the staircase: the speed of the next steps from the current one (each bar = N loops) */
.speedup-ladder { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 6px; margin-top: 4px; padding-top: 12px; border-top: 1px solid var(--line); }
.ladder-bars { display: flex; align-items: flex-end; gap: 4px; height: 40px; }
.ladder-bars > span { flex: 1; display: flex; gap: 1px; min-height: 3px; }   /* one step (N loops) */
.ladder-bars i { flex: 1; border-radius: 2px 2px 1px 1px; background: var(--accent-dim); }   /* one loop */
.ladder-bars > span:first-child i { background: var(--line); }   /* the start speed */
.ladder-bars > span:last-child i { background: var(--accent); }
.ladder-ends { display: flex; justify-content: space-between; font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.ladder-ends span:last-child { color: var(--accent); }


/* Shift held: the pointer is a capital I with serifs (loop selector). Panning (grabbing) still wins while dragging the view. */
.wave.shift-select { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Cpath d='M12 3V21M7.5 3H16.5M7.5 21H16.5' fill='none' stroke='black' stroke-opacity='.75' stroke-width='4.5' stroke-linecap='square'/%3E%3Cpath d='M12 3V21M7.5 3H16.5M7.5 21H16.5' fill='none' stroke='white' stroke-width='2' stroke-linecap='square'/%3E%3C/svg%3E") 12 12, text; }
.wave.panning { cursor: grabbing; }

/* Width: everything stays in a 720px centred column, except the waveform block, which spans the window with at
   least a 100px margin on each side (never narrower than the column, so phones are unaffected). */
.app > * { width: min(100%, 720px); }
.app > .seek { width: max(min(100%, 720px), calc(100% - 172px)); }   /* window width minus 100px margins (172 = 200 - the 2x14px page padding), but never narrower than the 720px column */

/* No default help texts: the track label shows only a loaded track's name or an error, and the recording message
   only a microphone warning; both are hidden while empty. */
.track-name.placeholder, #recMsg:empty { display: none; }

/* Hovering or dragging a loop limit bar (mouse) */
.wave.over-limit, .wave.dragging-limit { cursor: ew-resize; }
/* Hovering or dragging the A-B line (moves the whole loop) */
.wave.over-line { cursor: grab; }
.wave.dragging-line { cursor: grabbing; }

/* Markers: labels sit in a strip above the waveform (outside it); their lines are drawn on the canvas */
.marker-strip { position: relative; height: 22px; flex: none; }
.marker-label {
  position: absolute; top: 0; transform: translateX(-50%);
  min-width: 20px; height: 20px; min-height: 0; padding: 0 6px; border: 0; border-radius: 10px;
  background: #e040fb; color: #1a0620; font: 700 .72rem system-ui, sans-serif; cursor: pointer;
}
.marker-tools { position: absolute; top: -26px; transform: translateX(-50%); z-index: 3; display: flex; gap: 4px; }
.marker-tools[hidden] { display: none; }
.marker-tool {
  width: 24px; height: 24px; min-height: 0; padding: 0; display: grid; place-items: center;
  border-radius: 50%; border: 0; background: #e040fb; color: #1a0620; cursor: pointer;
}
.marker-tool.edit { background: #3b82f6; color: #fff; }
.marker-tool.trash { background: #ff6b5a; color: #fff; }
.marker-tool svg { width: 14px; height: 14px; }
.marker-tool:hover { filter: brightness(1.2); }
.marker-label:hover { background: #ee82ff; }
.marker-label:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
.seek { min-height: 146px; }   /* the label strip adds 22px */

/* Marker name dialog */
#markerDialog { border-color: #e040fb; }
#markerName {
  width: 100%; height: 44px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: 600 1.05rem system-ui, sans-serif; text-align: center;
}
#markerName:focus-visible { outline: 2px solid #e040fb; outline-offset: 1px; }
.marker-label { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* marker labels are draggable (along the strip) */
.marker-label { cursor: grab; touch-action: none; }
.marker-label.dragging { cursor: grabbing; z-index: 1; }

/* Fixed first beat of the beat grid: a "1" disk above its tick, in the tick's colour (set inline) */

#markerRemove { color: var(--warn); border-color: var(--danger-line); }
#markerDialog .confirm-btns { flex-wrap: wrap; }
#markerOk { background: #e040fb; border-color: #e040fb; color: #1a0620; }
