/* Loop Lab.

   The look (Kalle's brief, 11 October 2026): a clean, restrained practice tool. A light neutral
   page, white surfaces, purple as the one colour of action. Whitespace and thin separators
   divide things, not boxes inside boxes. The player is the centre: waveform, play, speed and
   pitch. Everything else is a quiet row under it that opens when asked.

   One size of control (40 px, 44 on touch), one corner radius (10 px; 14 for surfaces), one
   font. Labels are small and grey, values are dark, and only the play button is loud.

   Layouts: 900 px and wider is the full layout; narrower stacks speed over pitch and the
   transport; under 560 px is the phone layout, with a play bar that sticks to the bottom. */

:root {
  color-scheme: light;
  --bg: #F4F4F7;
  --surface: #FFFFFF;
  --surface2: #EFEFF4;        /* the fill of quiet controls */
  --surface3: #E4E4EC;        /* the same, pressed or hovered */
  --border: #E6E6EE;          /* separators */
  --text: #17181F;
  --text-dim: #6B6F80;
  --accent: #6C5CFF;
  --accent-strong: #5A4AE8;   /* the accent, hovered */
  --accent-dim: #ECEAFE;      /* a tint of the accent: the loop, what is selected */
  --accent-text: #5546D6;     /* the accent as text on a light surface */
  --strong: #D93F4C;          /* danger only: deleting */
  --wave: #B9BCCB;
  --wave-bg: #F7F7FA;
  --shadow: 0 1px 2px rgba(23, 24, 31, 0.04), 0 4px 16px rgba(23, 24, 31, 0.04);

  --radius: 10px;
  --radius-lg: 14px;
  --control: 40px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0C0C12;
  --surface: #15151D;
  --surface2: #21212D;
  --surface3: #2B2B3A;
  --border: #262633;
  --text: #EEEFF7;
  --text-dim: #9296AC;
  --accent: #7C6FFF;
  --accent-strong: #8F84FF;
  --accent-dim: #26244A;
  --accent-text: #A9A2FF;
  --strong: #FF6B7F;
  --wave: #565A72;
  --wave-bg: #101017;
  --shadow: none;
}

/* --- Base ------------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--bg); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.4;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
button { margin: 0; padding: 0; border: 0; background: none; cursor: pointer; }
button, summary, .wave, .overview, .footer { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button:disabled { cursor: default; opacity: 0.4; }
svg { display: block; }
p { margin: 0; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.app {
  display: flex;
  flex-direction: column;
  gap: 16px;
  /* As wide as the window, with margins that grow with it, up to a width past which the
     controls would only get stretched. */
  max-width: 1800px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 16px) calc(var(--safe-right) + clamp(20px, 3vw, 56px)) calc(var(--safe-bottom) + 12px) calc(var(--safe-left) + clamp(20px, 3vw, 56px));
}

/* Until the app's script has run (see the top of index.html). */
.loading .app, .loading .mini-bar { visibility: hidden; }

.surface { border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow); }

/* Small grey words above or beside a control. */
.label { display: block; margin: 0; color: var(--text-dim); font-size: 12px; font-weight: 600; }
.sub-title { color: var(--text-dim); font-size: 12px; font-weight: 600; }
.hint-line { color: var(--text-dim); font-size: 13px; }
.hint-line b { color: var(--text); font-weight: 600; }

/* --- Buttons ------------------------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--control);
  padding: 0 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-icon { display: contents; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-quiet { background: var(--surface2); color: var(--text); }
.btn-ghost, .btn-dim { color: var(--text-dim); }
.btn-danger { background: var(--strong); color: #fff; }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: 13px; }
.btn-md, .btn-lg { min-height: 44px; }
.btn-lg { padding: 0 22px; }
.btn-xl { width: 100%; min-height: 48px; text-decoration: none; }
@media (hover: hover) {
  .btn-accent:hover:not(:disabled) { background: var(--accent-strong); }
  .btn-quiet:hover:not(:disabled) { background: var(--surface3); }
  .btn-ghost:hover:not(:disabled), .btn-dim:hover:not(:disabled) { background: var(--surface2); color: var(--text); }
}

.icon-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: var(--control);
  height: var(--control);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 12px;
  transition: background 0.12s, color 0.12s;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn-sm { width: 32px; height: 32px; }
.icon-btn-sm svg { width: 16px; height: 16px; }
@media (hover: hover) { .icon-btn:hover:not(:disabled) { background: var(--surface2); color: var(--text); } }

/* Words that act: reset, remove. */
.link-btn { min-height: 32px; padding: 0 8px; border-radius: 8px; color: var(--text-dim); font-size: 13px; font-weight: 600; }
@media (hover: hover) { .link-btn:hover:not(:disabled) { background: var(--surface2); color: var(--text); } }

/* A choice among a few: speed presets, equalizer presets. */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn {
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--surface2);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.12s, color 0.12s;
}
.chip-btn[aria-pressed="true"] { background: var(--accent-dim); color: var(--accent-text); }
@media (hover: hover) { .chip-btn:hover:not([aria-pressed="true"]) { background: var(--surface3); color: var(--text); } }

.theme-toggle {
  position: relative;
  flex: none;
  width: 44px;
  height: 24px;
  border-radius: 12px;
  background: var(--surface3);
  transition: background 0.2s;
}
.theme-toggle::before { content: ""; position: absolute; inset: -10px -4px; }
.theme-toggle[aria-checked="true"] { background: var(--accent); }
.theme-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  color: #4C4F69;
  transition: transform 0.2s;
}
.theme-thumb svg { width: 12px; height: 12px; }
.theme-toggle[aria-checked="true"] .theme-thumb { transform: translateX(20px); }
.theme-moon { display: none; }
.theme-toggle[aria-checked="true"] .theme-sun { display: none; }
.theme-toggle[aria-checked="true"] .theme-moon { display: block; }

/* --- Fields ------------------------------------------------------------------------------- */

.input, .text-input, .select {
  display: block;
  width: 100%;
  height: var(--control);
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.input:focus-visible, .text-input:focus-visible, .select:focus-visible { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 1px; }
.input::placeholder, .text-input::placeholder { color: var(--text-dim); font-weight: 400; }
.input:disabled { opacity: 0.5; }
.text-input { height: 44px; margin: 0 0 20px; font-size: 16px; font-weight: 400; }

.select-wrap { position: relative; min-width: 0; }
.select-wrap::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 12px;
  width: 8px;
  height: 6px;
  margin-top: -3px;
  background: var(--text-dim);
  clip-path: polygon(0 0, 0 33%, 50% 100%, 100% 33%, 100% 0, 50% 67%);
  pointer-events: none;
}
.select { -webkit-appearance: none; appearance: none; padding-right: 30px; cursor: pointer; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-inline { flex-direction: row; align-items: center; gap: 12px; }
.field-inline .select-wrap { flex: 1; max-width: 360px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.row-fields { align-items: flex-end; }
.row-fields > .field { flex: 1 1 120px; max-width: 200px; }

input[type="range"] { width: 100%; height: 28px; margin: 0; accent-color: var(--accent); cursor: pointer; }

.check { display: flex; align-items: center; gap: 10px; min-height: 36px; cursor: pointer; }
.check input { flex: none; width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }

/* An on/off switch: a real checkbox underneath. */
.switch { display: inline-flex; align-items: center; gap: 10px; min-height: 32px; font-weight: 600; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { position: relative; flex: none; width: 36px; height: 20px; border-radius: 10px; background: var(--surface3); transition: background 0.15s; }
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* A small "more" inside a section: fine tuning, custom bands. */
.more > summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}
.more > summary::-webkit-details-marker { display: none; }
.more > summary::before, .section > summary::before {
  content: "";
  flex: none;
  width: 8px;
  height: 6px;
  background: currentColor;
  clip-path: polygon(0 0, 0 33%, 50% 100%, 100% 33%, 100% 0, 50% 67%);
  transform: rotate(-90deg);
  transition: transform 0.15s;
}
.more[open] > summary::before, .section[open] > summary::before { transform: none; }
.more-note { color: var(--text); }
@media (hover: hover) { .more > summary:hover { color: var(--text); } }

/* --- Head --------------------------------------------------------------------------------- */

.head { display: flex; align-items: center; gap: 16px; min-height: 44px; }
.brand { display: flex; flex: none; align-items: center; gap: 10px; font-size: 15px; font-weight: 700; }
.brand img { border-radius: 24%; }
.track-name {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--text-dim);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.track-name::before { content: "/"; margin-right: 16px; opacity: 0.4; }
.no-track .track-name { visibility: hidden; }
.head-actions { display: flex; flex: none; align-items: center; gap: 6px; }
.head-actions .theme-toggle { margin-left: 8px; }

/* --- Player ------------------------------------------------------------------------------- */

.player { display: flex; flex-direction: column; gap: 10px; padding: 16px 20px 20px; }

.wave-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 32px; }
.tool-group { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.readout-bar { color: var(--text-dim); font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

.overview {
  position: relative;
  flex: none;
  height: 26px;
  overflow: hidden;
  border-radius: 6px;
  background: var(--wave-bg);
  cursor: pointer;
  touch-action: none;
}
.overview canvas, .wave canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }

.wave {
  position: relative;
  flex: none;
  height: 190px;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--wave-bg);
  cursor: crosshair;
  touch-action: none;
}
.wave.over-handle { cursor: ew-resize; }
.wave.over-move { cursor: grab; }
.wave.is-empty { height: auto; background: none; cursor: default; touch-action: auto; }
.wave.is-empty:focus-visible { outline: none; }
.wave.is-empty canvas, .no-track .overview, .no-track .wave-bar, .no-track .deck, .no-track .sections, .no-track .footer .shortcuts { display: none; }
.drop-target .player { outline: 2px dashed var(--accent); outline-offset: -2px; }

.wave-empty { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 56px 16px 40px; text-align: center; }
.empty-title { max-width: 480px; margin: 0; font-size: 22px; font-weight: 700; line-height: 1.25; }
.empty-hint { max-width: 440px; color: var(--text-dim); }
.recent { width: min(440px, 100%); margin-top: 20px; text-align: left; }
.recent .sub-title { display: block; margin: 0 0 6px 12px; }
.recent-list { max-height: 196px; margin: 0 0 10px; padding: 0; overflow-y: auto; list-style: none; }
.recent-list li + li { border-top: 1px solid var(--border); }
.recent-open {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 4px 12px;
  border-radius: 8px;
  text-align: left;
}
@media (hover: hover) { .recent-open:hover { background: var(--surface2); } }
.recent-name { min-width: 0; overflow: hidden; font-weight: 600; white-space: nowrap; text-overflow: ellipsis; }
.recent-meta { flex: none; color: var(--text-dim); font-size: 13px; }

.wave-status {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 190px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--wave-bg);
  color: var(--text-dim);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
}
.wave.is-empty .wave-status { position: static; }
.wave-status.is-error { color: var(--strong); }
.wave-status.is-busy::before {
  content: "";
  width: 22px;
  height: 22px;
  border: 3px solid var(--surface3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.deck { display: flex; flex-direction: column; gap: 20px; margin-top: 10px; }

/* Transport: the time on the left, play in the middle, the volume on the right. */
.transport { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; }
.time { display: flex; align-items: baseline; gap: 8px; font-variant-numeric: tabular-nums; }
.time b { font-size: 26px; font-weight: 700; line-height: 1; }
.time-total { color: var(--text-dim); font-size: 14px; }
.transport-main { display: flex; align-items: center; gap: 14px; }
.play-btn {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  transition: background 0.12s, transform 0.1s;
}
.play-btn svg { width: 28px; height: 28px; }
.play-btn .play-icon svg { margin-left: 3px; } /* a triangle looks off-centre otherwise */
.play-btn:active { transform: scale(0.96); }
@media (hover: hover) { .play-btn:hover { background: var(--accent-strong); } }
.pause-icon { display: none; }
.playing .play-icon { display: none; }
.playing .pause-icon { display: block; }

.round-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--text-dim);
  transition: background 0.12s, color 0.12s;
}
.round-btn svg { width: 20px; height: 20px; }
@media (hover: hover) { .round-btn:hover { background: var(--surface2); color: var(--text); } }
.loop-btn[aria-pressed="true"] { background: var(--accent-dim); color: var(--accent-text); }

.volume { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.volume input { width: 130px; }

/* Speed and pitch: two columns under a thin line. */
.adjust { display: grid; grid-template-columns: 1fr 1fr; gap: 0 40px; padding-top: 18px; border-top: 1px solid var(--border); }
.adjust-block { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.adjust-head { display: flex; align-items: center; justify-content: space-between; min-height: 32px; }
.adjust-note { color: var(--text-dim); font-size: 12px; font-variant-numeric: tabular-nums; }
.stepper { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; }
.stepper .icon-btn { background: var(--surface2); color: var(--text); }
.value { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; text-align: center; }
.adjust .more { margin-top: -2px; }

/* --- Sections: Loop, Equalizer, Speed trainer ------------------------------------------------ */

.sections { padding: 0 20px; }
.section + .section { border-top: 1px solid var(--border); }
.section > summary {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  color: var(--text-dim);
  list-style: none;
  cursor: pointer;
}
.section > summary::-webkit-details-marker { display: none; }
.section-title { color: var(--text); font-size: 15px; font-weight: 700; }
.section-note {
  min-width: 0;
  margin-left: auto;
  overflow: hidden;
  color: var(--accent-text);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.section-body { display: flex; flex-direction: column; gap: 14px; padding: 0 0 20px 20px; }

/* Loop */
.loop-ends { display: flex; flex-direction: column; gap: 8px; }
.end-row { display: grid; grid-template-columns: 76px auto auto; justify-content: start; align-items: center; gap: 12px; }
.end-label { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.ab-key {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}
.end-edit { display: flex; align-items: center; gap: 2px; }
.end-time { width: 108px; text-align: center; }
.end-step { height: var(--control); }
/* With no loop there is nothing to adjust yet: only "Set A here" and "Set B here" show. */
.no-loop .end-edit, .no-loop .when-loop { display: none; }
.no-loop .end-row { grid-template-columns: 76px auto; }

.saved { display: flex; flex-direction: column; gap: 6px; }
.saved-head { display: flex; align-items: center; justify-content: space-between; min-height: 32px; }
.loop-list { max-height: 228px; margin: 0; padding: 0; overflow-y: auto; list-style: none; }
.loop-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; border-radius: var(--radius); }
.loop-row.selected { background: var(--accent-dim); }
@media (hover: hover) { .loop-row:not(.selected):hover { background: var(--surface2); } }
.loop-main { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; align-items: center; gap: 10px; min-height: 44px; padding: 0 8px 0 10px; border-radius: var(--radius); text-align: left; }
.loop-num { color: var(--text-dim); font-size: 13px; font-weight: 600; text-align: center; }
.loop-row.selected .loop-num { color: var(--accent-text); }
.loop-name { overflow: hidden; font-weight: 600; white-space: nowrap; text-overflow: ellipsis; }
.chip { color: var(--text-dim); font-size: 13px; font-variant-numeric: tabular-nums; }
.chip b { font-weight: 600; }
.row-actions { display: flex; padding-right: 4px; }
.row-btn { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; color: var(--text-dim); }
.row-btn svg { width: 16px; height: 16px; }
.row-btn.danger { color: var(--strong); }
@media (hover: hover) { .row-btn:hover { background: var(--surface3); } }
.empty { padding: 2px 0; color: var(--text-dim); font-size: 13px; }

/* Equalizer */
.eq-top { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; }
.eq-bands { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 2px; max-width: 520px; transition: opacity 0.15s; }
.eq-bands.off { opacity: 0.45; }
.eq-band { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.eq-band input[type="range"] { writing-mode: vertical-lr; direction: rtl; width: 28px; height: 124px; }
.eq-band label, .eq-band output { color: var(--text-dim); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.eq-band output { color: var(--text); }

/* Speed trainer */
.trainer-fields { display: grid; grid-template-columns: repeat(4, minmax(0, 150px)); gap: 12px; }
.running .trainer-fields, .running .section-body > .hint-line { display: none; }
.running #trainerStatus { color: var(--text); font-size: 15px; }

/* Bars and tempo */
.tempo-body { display: flex; flex-direction: column; gap: 14px; }
.more > .row { margin-top: 8px; }

/* --- Footer ------------------------------------------------------------------------------- */

.footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: auto; padding: 0 4px; color: var(--text-dim); font-size: 12px; }
.footer-actions { display: flex; align-items: center; gap: 12px; margin-left: auto; }
/* Narrow screens: the footer's links wrap and sit in the middle instead of running off the edge. */
@media (max-width: 760px) {
  .footer { flex-wrap: wrap; justify-content: center; }
  .footer-actions { flex-wrap: wrap; justify-content: center; gap: 4px 8px; margin-left: 0; }
  .footer-actions .btn { padding: 0 10px; }
}
.support-btn svg { color: var(--accent); }
.modal-message + .btn-xl { text-decoration: none; }
@media not all and (hover: hover) { .shortcuts { display: none; } }

/* --- Mini bar: play controls that stick to the bottom on phones ----------------------------- */

.mini-bar {
  position: fixed;
  left: calc(var(--safe-left) + 12px);
  right: calc(var(--safe-right) + 12px);
  bottom: calc(var(--safe-bottom) + 12px);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 520px;
  margin: 0 auto;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  opacity: 0;
  transform: translateY(calc(100% + 30px));
  transition: transform 0.2s ease, opacity 0.2s ease;
  pointer-events: none;
}
.mini-bar.visible { opacity: 1; transform: none; pointer-events: auto; }
.modal-open .mini-bar { display: none; }
/* Only where the page is one long column. On a wide screen it sat on top of the footer. */
@media (min-width: 761px) { .mini-bar { display: none; } }
.mini-info { flex: 1; min-width: 0; line-height: 1.2; }
.mini-time { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.mini-meta { overflow: hidden; color: var(--text-dim); font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }
.mini-nav { display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: 50%; color: var(--text-dim); }
.mini-nav svg { width: 20px; height: 20px; }
.mini-nav[aria-pressed="true"] { background: var(--accent-dim); color: var(--accent-text); }
.mini-play { display: grid; place-items: center; flex: none; width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: #fff; }
.mini-play svg { width: 22px; height: 22px; }

/* --- Windows: the modal and what goes in it ------------------------------------------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: calc(var(--safe-top) + 16px) calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 16px) calc(var(--safe-left) + 16px);
  background: rgba(12, 12, 18, 0.45);
}
.modal-card {
  width: min(var(--modal-width, 420px), 100%);
  padding: 24px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
  animation: modal-in 0.16s ease-out;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px); } }
.modal-title { margin: 0 0 16px; font-size: 17px; font-weight: 700; }
.modal-title svg { display: none; }
.modal-title-danger { margin-bottom: 8px; }
.modal-message { margin: 0 0 24px; color: var(--text-dim); font-size: 15px; line-height: 1.45; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 8px; }
.modal-close-wide { width: 100%; margin-top: 12px; }
.modal-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.more-card { padding: 16px 0; border-top: 1px solid var(--border); }
.more-card h3 { margin: 0 0 4px; font-size: 15px; font-weight: 700; }
.more-card p { margin: 0 0 12px; color: var(--text-dim); line-height: 1.45; }
.more-links { display: flex; flex-wrap: wrap; gap: 8px; }
.more-links .btn { text-decoration: none; }
.hint-line a { color: var(--accent-text); }

.modal-card.modal-settings { display: flex; flex-direction: column; max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 32px); padding: 0; }
.settings-scroll { overflow-y: auto; overscroll-behavior: contain; padding: 24px 24px 4px; }
.settings-title { margin: 0; font-size: 18px; font-weight: 700; }
.settings-subtitle { margin: 4px 0 8px; color: var(--text-dim); }
.settings-card { padding: 18px 0; border-top: 1px solid var(--border); }
.settings-card h3 { margin: 0 0 6px; font-size: 14px; font-weight: 700; }
.settings-card > p { margin: 0 0 12px; color: var(--text-dim); }
.settings-card a { color: var(--accent-text); }
.settings-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.settings-footer { display: flex; justify-content: flex-end; padding: 16px 24px 24px; }
.hint { margin: 8px 0 0; color: var(--text-dim); font-size: 13px; }
.track-rows { margin: 0; padding: 0; list-style: none; }
.track-rows li { display: flex; align-items: center; gap: 8px; min-height: 44px; border-top: 1px solid var(--border); }
.track-rows li:first-child { border-top: 0; }
.track-rows .recent-name { flex: 1; }

.keys-columns { columns: 2 260px; column-gap: 32px; }
.keys-group { margin: 0 0 18px; break-inside: avoid; }
.keys-group h3 { margin: 0 0 8px; color: var(--text-dim); font-size: 12px; font-weight: 600; }
.keys-list { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 14px; margin: 0; }
.keys-list dt { justify-self: start; }
.keys-list dd { margin: 0; align-self: center; }
kbd {
  display: inline-block;
  min-width: 28px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--surface2);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
}

.install-steps { margin: 0 0 16px; padding-left: 22px; line-height: 1.5; }
.install-steps li { margin-bottom: 10px; padding-left: 4px; }
.install-note { margin: -4px 0 16px; }
.inline-icon { display: inline-block; width: 17px; height: 17px; vertical-align: -3px; color: var(--accent-text); }
.inline-icon svg { width: 100%; height: 100%; }

/* Export */
.export-what { margin: 0 0 14px; color: var(--text-dim); }
.export-what b { color: var(--text); font-weight: 600; }
.export-choice { display: flex; align-items: center; gap: 12px; min-height: 52px; margin-bottom: 8px; padding: 8px 14px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.export-choice:has(input:checked) { border-color: var(--accent); background: var(--accent-dim); }
.export-choice:has(input:disabled) { opacity: 0.5; cursor: default; }
.export-choice input { flex: none; width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.export-choice b { display: block; font-weight: 600; }
.export-choice span span { color: var(--text-dim); font-size: 13px; }
.export-formats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.export-formats .export-choice { margin-bottom: 0; }
.export-progress { display: block; width: 100%; height: 8px; margin: 14px 0 6px; accent-color: var(--accent); }
.export-status { min-height: 20px; margin: 12px 0 16px; color: var(--text-dim); font-size: 13px; }

/* --- Toast and the update notice ------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 24px);
  z-index: 150;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--text);
  color: var(--surface);
  font-weight: 600;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

.install-hint {
  position: fixed;
  left: calc(var(--safe-left) + 12px);
  right: calc(var(--safe-right) + 12px);
  bottom: calc(var(--safe-bottom) + 12px);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 520px;
  margin: 0 auto;
  padding: 12px 12px 12px 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
}
.install-hint img { flex: none; border-radius: 24%; }
.install-text { flex: 1; line-height: 1.4; }
.install-hint-open .app { padding-bottom: calc(var(--safe-bottom) + 100px); }

/* --- A tall window: the waveform takes the spare height -------------------------------------- */

@media (min-width: 900px) and (min-height: 860px) {
  .wave:not(.is-empty) { height: clamp(190px, 100dvh - 640px, 360px); }
}

/* --- Narrower: the transport stacks, speed sits over pitch ----------------------------------- */

@media (max-width: 760px) {
  .adjust { grid-template-columns: 1fr; gap: 20px; }
  .adjust-block + .adjust-block { padding-top: 16px; border-top: 1px solid var(--border); }
  .trainer-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .head-btn-label { display: none; }
  .head-btn { width: var(--control); padding: 0; }
  .head-btn svg { width: 18px; height: 18px; }
}

/* --- Touch screens: every control is at least 44 px ------------------------------------------ */

@media (pointer: coarse) {
  :root { --control: 44px; }
  .btn-sm, .icon-btn-sm, .chip-btn, .link-btn { min-height: 44px; }
  .icon-btn-sm { width: 44px; height: 44px; }
  .chip-btn { padding: 0 14px; }
  .row-btn { width: 44px; height: 44px; }
  .more > summary, .switch, .check { min-height: 44px; }
  input[type="range"] { height: 44px; }
  .input, .select { font-size: 16px; } /* iOS zooms into fields with text under 16 px */
  .theme-toggle::before { inset: -10px -4px; }
  /* The equalizer stands up here as well, as an equalizer does (Kalle, 11 October 2026: lying
     down "is weird"). Ten bands share the width, so each is narrower than 44 px on a phone;
     they are taller instead, and each band's whole column takes the finger. */
  .eq-bands { max-width: none; }
  .eq-band input[type="range"] { width: 100%; height: 168px; }
}

/* --- Phones ------------------------------------------------------------------------------- */

@media (max-width: 560px) {
  .app { gap: 12px; padding: calc(var(--safe-top) + 10px) calc(var(--safe-right) + 12px) calc(var(--safe-bottom) + 96px) calc(var(--safe-left) + 12px); }
  .head { flex-wrap: wrap; gap: 4px 8px; }
  .brand span { display: none; }
  .head-actions { margin-left: auto; gap: 2px; }
  .track-name { order: 3; flex: 1 1 100%; color: var(--text); font-size: 16px; }
  .track-name::before { content: none; }
  .player { padding: 12px 14px 16px; }
  .wave { height: 150px; }
  .transport { grid-template-columns: 1fr; justify-items: center; gap: 12px; }
  .time { order: -1; }
  .volume { justify-content: center; width: 100%; }
  .volume input { flex: 1; width: auto; max-width: 260px; }
  .sections { padding: 0 14px; }
  .section-body { padding-left: 0; }
  .end-row { grid-template-columns: 70px minmax(0, 1fr); }
  .end-edit { justify-self: start; }
  .end-row .btn { grid-column: 1 / -1; }
  .no-loop .end-row { grid-template-columns: 70px minmax(0, 1fr); }
  .no-loop .end-row .btn { grid-column: auto; }
  .field-inline { flex-direction: column; align-items: stretch; gap: 6px; }
  .modal-card { padding: 20px; }
  .settings-scroll { padding: 20px 20px 4px; }
  .settings-footer { padding: 16px 20px 20px; }
  .modal-buttons .btn, .settings-footer .btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
  .wave-status.is-busy::before { animation: none; border-top-color: var(--surface3); }
}
