/* Listening, Fast and Slow — shares the lab's palette (#f4f4f1 / #16161a, accent
   #5566aa) so the app does not read as a different site from the index. */

:root {
  color-scheme: light dark;
  --bg: #f4f4f1;
  --panel: #fff;
  --ink: #1c1c1c;
  --dim: #777;
  --faint: #8a8a82;
  --line: #e6e6e0;
  --line-strong: #cfcfc6;
  --accent: #5566aa;
  --accent-soft: #eef0f8;
  --rec: #c0392b;
  --wave: #9aa3c4;
  --wave-active: #5566aa;
  --region: rgba(85, 102, 170, .12);
  --bar: rgba(244, 244, 241, .94);

  /* A default good enough for first paint; app.js measures the real bar and
     overwrites it, so anything anchored to the bar cannot drift from it. */
  --bar-h: calc(3.9rem + env(safe-area-inset-bottom));
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --panel: #202027;
    --ink: #ececec;
    --dim: #9a9aa2;
    --faint: #888;
    --line: #2d2d36;
    --line-strong: #3d3d49;
    --accent: #8b9bd9;
    --accent-soft: #262633;
    --rec: #e05c4a;
    --wave: #4d5470;
    --wave-active: #8b9bd9;
    --region: rgba(139, 155, 217, .14);
    --bar: rgba(22, 22, 26, .94);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  overflow: hidden;                /* Home is exactly one screen; nothing scrolls it */
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ── Home ────────────────────────────────────────────────────────────────────
   A full-height flex column. Everything but the waveform is its natural size and
   the waveform takes the remainder, so the space is spent rather than budgeted:
   collapse the disclosures and the canvas grows, open one and it shrinks. Home
   cannot scroll by construction, which is the condition `touch-action: none` on
   the canvas depends on. */
#home {
  height: 100vh;
  height: 100dvh;                  /* follows Safari's chrome as it collapses */
  display: flex; flex-direction: column;
  padding: .5rem .75rem 0;
}

.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: .5rem;
  max-width: 46rem; width: 100%; margin: 0 auto .4rem;
}
.topbar .btn { flex: 0 0 auto; }
h1 {
  flex: 1 1 auto; min-width: 0; margin: 0; text-align: center;
  font-size: clamp(13px, 3.2vw, 17px); letter-spacing: -.01em; font-weight: 600;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.h1-em { font-style: italic; color: var(--accent); }

main {
  flex: 1 1 auto; min-height: 0;
  max-width: 46rem; width: 100%; margin: 0 auto;
  display: flex; flex-direction: column; gap: .45rem;
}

h2, h3 { margin: 0; font-size: 1rem; font-weight: 600; }
h3 { font-size: .88rem; }

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

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }
.meta { color: var(--faint); font-size: .76rem; }
.note { margin: .4rem 0 0; color: var(--dim); font-size: .78rem; line-height: 1.5; }

/* ── buttons ─────────────────────────────────────────────────────────────── */
.row { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.btn {
  font: inherit; font-size: .88rem; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .7rem 1rem; min-height: 44px;   /* thumb-sized: this is an iPad app first */
  border-radius: 10px; cursor: pointer;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line-strong);
  -webkit-tap-highlight-color: transparent;
  /* manipulation kills double-tap-to-zoom on iOS. Without it, tapping a button
     twice quickly — which the tap-tempo pads invite — zooms the page instead. */
  touch-action: manipulation;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: default; }
.btn--bar { font-size: .82rem; padding: .5rem .6rem; min-height: 46px; }
.btn--xs { font-size: .72rem; padding: .4rem .45rem; min-height: 34px; border-radius: 8px; }
.btn--icon { width: 34px; padding: 0; font-size: 1.1rem; }
/* round, because an (i) in a rounded rectangle reads as a button with a letter
   in it rather than as an info affordance */
.btn--round {
  width: 28px; height: 28px; min-height: 28px;
  padding: 0; border-radius: 50%; font-size: .8rem; font-weight: 600;
  color: var(--dim);
}
.info__head .btn--round { width: 32px; height: 32px; min-height: 32px; font-size: 1rem; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn--primary:disabled { background: var(--line-strong); border-color: var(--line-strong); }
.btn--toggle[aria-pressed="true"]:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn--danger { color: var(--rec); border-color: var(--line); }
.btn--danger:hover:not(:disabled) { border-color: var(--rec); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── the workbench ───────────────────────────────────────────────────────── */
.cliphead { flex: 0 0 auto; display: flex; gap: .5rem; align-items: baseline; }
/* the name gives way, not the meta: a wrapped "44 kHz" costs the waveform a line */
.cliphead .meta { flex: 0 0 auto; white-space: nowrap; }
.clipname {
  flex: 1 1 auto; min-width: 0;
  font: inherit; font-size: .92rem; font-weight: 600;
  background: transparent; color: var(--ink);
  border: 1px solid transparent; border-radius: 8px; padding: .25rem .3rem;
}
.clipname:hover:not(:disabled) { border-color: var(--line); }
.clipname:focus { border-color: var(--accent); outline: none; }
.clipname:disabled { opacity: .5; }

/* the one element that grows: whatever the rest does not use is waveform */
/* Inset from the window, not just from the page. A sits at x=0 and B at the far
   edge, and iOS reserves roughly the outer 20pt of the screen for its own back
   and forward swipes — so at the page's 12px padding the handles are inside that
   zone and dragging them navigates instead. 12px more puts both handles clear of
   it. A mitigation, not a cure: a finger that starts further out still belongs
   to Safari. */
.wavewrap { flex: 3 1 0; min-height: 6rem; position: relative; margin-inline: .75rem; }
.times { margin-inline: .75rem; }   /* the ruler stays aligned with its canvas */
#wave {
  display: block; width: 100%; height: 100%;
  border-radius: 10px; background: var(--accent-soft);
  touch-action: none;              /* the canvas owns drags; the page must not scroll */
  cursor: pointer;
}
.note--over {
  position: absolute; inset: auto .6rem .5rem; margin: 0;
  text-align: center; pointer-events: none;
}
#emptyNote { inset: 0; display: flex; align-items: center; justify-content: center; padding: 1rem; }
#emptyNote[hidden] { display: none; }

.times { flex: 0 0 auto; display: flex; justify-content: space-between; gap: .5rem; font-size: .74rem; color: var(--dim); }
.times__mid { color: var(--accent); }
.row--markers { flex: 0 0 auto; }

/* Disclosures take their natural height up to half the column, then scroll
   inside themselves — so opening one can never crowd the waveform out. */
.slider { width: 100%; margin: .5rem 0 0; accent-color: var(--accent); height: 28px; touch-action: pan-y; }

.levels { flex: 0 0 auto; display: flex; flex-direction: column; gap: .1rem; }
.gainrow { display: flex; align-items: center; gap: .6rem; }
.gainrow label { flex: 0 0 2.1rem; font-size: .78rem; font-weight: 600; color: var(--dim); }
.gainrow .slider { flex: 1 1 auto; margin: 0; min-width: 0; }
.gainrow output { flex: 0 0 3.4rem; text-align: right; font-size: .76rem; color: var(--dim); }
.gainrow .slider { height: 26px; }

.meter { flex: 0 0 auto; display: flex; align-items: center; gap: .6rem; }
/* an author `display` beats the UA's [hidden] rule, so hiding has to be said
   again here or the meter shows before anything is being recorded */
.meter[hidden] { display: none; }
/* Capture phase: the play/edit half of the app steps back while the recorder is
   running, so the meter and the stop button are what is left to look at. */
body[data-phase="capture"] .times,
body[data-phase="capture"] .wavewrap,
body[data-phase="capture"] .row--markers,
body[data-phase="capture"] .libwrap,
body[data-phase="capture"] .cliphead { opacity: .35; pointer-events: none; }
.meter__track { flex: 1 1 auto; height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.meter__bar { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .06s linear; }
/* boost is applied before the recorder, so a pegged meter means the file itself
   is clipping — worth shouting about while there is still time to turn it down */
.meter.hot .meter__bar { background: var(--rec); }
.meter .mono { font-size: .8rem; color: var(--dim); }

/* ── tap tempo ───────────────────────────────────────────────────────────── */
.bar {
  flex: 0 0 auto;
  margin: .4rem -.75rem 0;
  padding: .5rem .6rem calc(.5rem + env(safe-area-inset-bottom));
  background: var(--bar);
  border-top: 1px solid var(--line);
}
.bar[hidden] { display: none; }
.bar__row { max-width: 46rem; margin: 0 auto; display: flex; align-items: center; gap: .4rem; }
/* Evened out: skip-to-start was a sliver next to a button that took half the bar.
   Both fixed controls get a real target and Play takes what is left. */
.btn--wide { flex: 0 0 auto; min-width: 3.5rem; }
.btn--play { flex: 1 1 auto; min-width: 4.5rem; gap: .45rem; }

/* CSS glyphs rather than characters: the play and pause code points render as
   colour emoji on iOS often enough that a shape drawn here is the safer signal. */
.glyph { flex: 0 0 auto; display: block; }
.glyph--play {
  width: 0; height: 0;
  border-style: solid; border-width: 6px 0 6px 10px;
  border-color: transparent transparent transparent currentColor;
}
.btn--play.is-playing .glyph--play {
  width: 11px; height: 12px; border: 0;
  background:
    linear-gradient(currentColor 0 0) left / 4px 100% no-repeat,
    linear-gradient(currentColor 0 0) right / 4px 100% no-repeat;
}
/* The fill flips too, so the state is legible without reading the word — but not
   to the soft accent a pressed toggle uses, because Loop sits right next to it
   and "playing" would then look like a third toggle. Ink reads as engaged, and
   is the only other weight in the palette. */
.btn--play.is-playing {
  background: var(--ink); border-color: var(--ink); color: var(--bg);
}
.btn--play.is-playing:hover:not(:disabled) { filter: none; border-color: var(--ink); }

.glyph--start { position: relative; width: 13px; height: 12px; }
.glyph--start::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: currentColor;
}
.glyph--start::after {
  content: ''; position: absolute; right: 0; top: 0;
  width: 0; height: 0; border-style: solid; border-width: 6px 10px 6px 0;
  border-color: transparent currentColor transparent transparent;
}

.stepper {
  display: inline-flex; align-items: stretch; flex: 0 0 auto;
  border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden;
}
.stepbtn, .rateout {
  font: inherit; background: var(--panel); color: var(--ink);
  border: 0; cursor: pointer; min-height: 44px;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.stepbtn { width: 28px; font-size: 1rem; line-height: 1; color: var(--dim); }
.stepbtn:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent); }
.stepbtn:disabled, .rateout:disabled { opacity: .4; cursor: default; }
.rateout {
  min-width: 2.9rem; font-size: .78rem; font-weight: 600; color: var(--accent);
  border-left: 1px solid var(--line); border-right: 1px solid var(--line);
}

.recbtn {
  flex: 0 0 auto;
  width: 48px; height: 48px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--panel); border: 2px solid var(--line-strong);
  cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.recbtn__dot {
  width: 32px; height: 32px; border-radius: 50%; background: var(--rec);
  transition: border-radius .16s ease, width .16s ease, height .16s ease;
}
/* the stop affordance: the dot squares off while the recorder is running */
.recbtn.on { border-color: var(--rec); }
.recbtn.on .recbtn__dot { width: 20px; height: 20px; border-radius: 3px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

/* ── the clip list, always on screen ─────────────────────────────────────────
   Retiring tap tempo and the fine speed control paid for this. It shares the
   leftover with the waveform rather than either being fixed, so the split holds
   at any height. */
.libwrap {
  flex: 2 1 0; min-height: 5.5rem;
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  border-top: 1px solid var(--line); padding-top: .4rem;
}
.lib { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.lib li {
  display: flex; flex-wrap: wrap; align-items: center; gap: .45rem;
  padding: .3rem .4rem; border: 1px solid var(--line); border-radius: 9px;
}
.lib li.current { border-color: var(--accent); background: var(--accent-soft); }
.row__pick {
  flex: 1 1 auto; min-width: 0; text-align: left;
  font: inherit; background: none; border: 0; color: inherit;
  cursor: pointer; padding: .25rem; touch-action: manipulation;
}
.row__name { display: block; font-size: .84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__meta { display: block; color: var(--faint); font-size: .7rem; margin-top: .1rem; }
.row__sel {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 8px;
  font: inherit; font-size: .75rem; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line-strong); color: var(--dim);
  touch-action: manipulation;
}
.row__sel[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.row__more {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 8px;
  font: inherit; font-size: .9rem; line-height: 1; cursor: pointer;
  background: transparent; border: 1px solid transparent; color: var(--faint);
  touch-action: manipulation;
}
.row__more:hover, .row__more[aria-expanded="true"] { border-color: var(--line-strong); color: var(--ink); }
.row__extra { flex: 1 0 100%; display: flex; gap: .35rem; padding-top: .3rem; }
.row__extra[hidden] { display: none; }

.reel { flex: 0 0 auto; border-top: 1px solid var(--line); padding-top: .4rem; }
.reel[hidden] { display: none; }
.reel .row--actions { margin-top: 0; }

/* ── help + toast ────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--bar-h) + .75rem);
  transform: translateX(-50%);
  max-width: min(90vw, 28rem);
  background: var(--ink); color: var(--bg);
  font-size: .82rem; padding: .6rem .9rem; border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  z-index: 30;
  /* it sits over the transport; a status message must never eat a tap */
  pointer-events: none;
}
.toast[hidden] { display: none; }
@media (max-width: 380px) {
  .taps { grid-template-columns: 1fr; }
  .rateout { min-width: 2.6rem; font-size: .74rem; }
  .stepbtn { width: 26px; }
}

/* ── the info dialog ─────────────────────────────────────────────────────────
   "How this works" was a disclosure competing for room with the clip list. The
   instructions worth keeping moved behind (i), where they cost the layout
   nothing. <dialog> brings focus trapping, escape and a backdrop for free. */
.info {
  width: min(32rem, calc(100vw - 2rem)); max-height: min(80dvh, 40rem);
  padding: 0; border: 1px solid var(--line-strong); border-radius: 14px;
  background: var(--panel); color: var(--ink);
  overflow: hidden;
}
.info::backdrop { background: rgba(0, 0, 0, .45); }
.info__head {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .8rem 1rem; border-bottom: 1px solid var(--line);
}
.info__head h2 { font-size: .95rem; }
.info__body { padding: .3rem 1rem 1rem; overflow-y: auto; max-height: calc(min(80dvh, 40rem) - 4rem); }
.info__body p { margin: .8rem 0 0; font-size: .82rem; line-height: 1.6; color: var(--dim); }
.info__body kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .78em;
  border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 .3em;
}
.info__body code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }

/* Diagnostics: present but not offered. Closed it reads as one more line of the
   panel; open it is a wall of state, which is exactly what it should look like. */
.diag { margin-top: 1.2rem; border-top: 1px solid var(--line); padding-top: .6rem; }
.diag summary {
  font-size: .78rem; color: var(--dim); cursor: pointer; list-style: none;
  padding: .2rem 0;
}
.diag summary::-webkit-details-marker { display: none; }
.diag summary::before { content: '▸ '; }
.diag[open] summary::before { content: '▾ '; }
.diag__row { display: flex; gap: .4rem; margin-top: .6rem; }
.diag__out {
  margin: .6rem 0 0; padding: .5rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--dim);
  font-size: .68rem; line-height: 1.45; white-space: pre-wrap; word-break: break-word;
  max-height: 14rem; overflow: auto; -webkit-user-select: text; user-select: text;
}
.diag__out:empty { display: none; }

/* The live overlay. Deliberately plain and deliberately in the way: it is on
   screen because something is being investigated, and it should look like it. */
.hud {
  position: fixed; inset: 0 0 auto; z-index: 60;
  padding: calc(.4rem + env(safe-area-inset-top)) .6rem .5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line-strong); color: var(--ink);
  max-height: 70dvh; overflow: auto;
}
.hud__row { display: flex; align-items: center; gap: .4rem; }
.hud__title { flex: 1 1 auto; font-size: .72rem; color: var(--dim); }
.hud pre {
  margin: .4rem 0 0; font-size: .62rem; line-height: 1.4;
  white-space: pre-wrap; word-break: break-word;
  -webkit-user-select: text; user-select: text;
}

/* ── the clip list's own header ──────────────────────────────────────────── */
.libhead { flex: 0 0 auto; display: flex; align-items: center; gap: .4rem; }
.libhead h2 { flex: 0 0 auto; font-size: .88rem; }
.libhead #storageOut { flex: 1 1 auto; min-width: 0; overflow: hidden; white-space: nowrap; }

.topbar__spacer { flex: 0 0 28px; }

/* Set A / Set B / Whole clip are one idea; Reverse acts on the clip; Zoom only
   changes how you look at it. Future region actions join the middle group. */
.sep { flex: 0 0 auto; width: 1px; align-self: stretch; margin: .15rem .2rem; background: var(--line-strong); }

/* the chevron on the clip list's header */
.glyph--chev {
  width: 7px; height: 7px; margin-top: 2px;
  border-left: 2px solid currentColor; border-top: 2px solid currentColor;
  transform: rotate(45deg);
}
body[data-list="tall"] .glyph--chev { margin-top: -2px; transform: rotate(225deg); }
.libhead .btn--chev { width: 34px; padding: 0; }

/* Two sizes, not a drag: the list is a scroll container, so a vertical drag that
   starts on it is ambiguous. The waveform keeps its min-height either way, so
   the workbench never disappears. */
body[data-list="tall"] .wavewrap { flex: 1 1 0; }
body[data-list="tall"] .libwrap { flex: 7 1 0; }

/* ── the speed menu ──────────────────────────────────────────────────────── */
.speed { position: relative; flex: 0 0 auto; }
.ratemenu {
  position: absolute; bottom: calc(100% + .4rem); right: 0; z-index: 25;
  display: flex; flex-direction: column;
  min-width: 5.2rem; padding: .25rem;
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}
.ratemenu[hidden] { display: none; }
.ratemenu__item {
  font: inherit; font-size: .82rem; text-align: right;
  padding: .5rem .6rem; min-height: 38px; border: 0; border-radius: 7px;
  background: none; color: var(--ink); cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.ratemenu__item:hover { background: var(--accent-soft); color: var(--accent); }
.ratemenu__item[aria-checked="true"] { background: var(--accent); color: #fff; font-weight: 600; }
/* outside the range the stretcher is convincing in — offered, not recommended */
.ratemenu__item--far { color: var(--faint); }
.ratemenu__item--far[aria-checked="true"] { color: #fff; }
