:root {
  --bg: #0a0b14;
  --surface: #12152a;
  --surface-2: #1a1e38;
  --raised: #232849;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --ink: #f4f1ea;
  --dim: #a3a5bf;
  --faint: #6f7291;
  --accent: #ffb547;
  --accent-soft: rgba(255, 181, 71, 0.14);
  --accent-ink: #1f1400;
  --cool: #7cc6d6;
  --ok: #7ee0a1;
  --danger: #ff7a86;
  --radius: 20px;
  --display: "Space Grotesk", system-ui, sans-serif;
  --body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --i-mic: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><rect x='9' y='2' width='6' height='12' rx='3'/><path d='M5 10a7 7 0 0 0 14 0M12 17v4'/></svg>");
  --i-download: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M12 3v12M7 10l5 5 5-5M5 21h14'/></svg>");
  --i-share: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M4 12v7a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-7M16 6l-4-4-4 4M12 2v13'/></svg>");
  --i-refresh: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M21 12a9 9 0 1 1-2.6-6.4L21 8M21 3v5h-5'/></svg>");
  --i-send: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M22 2 11 13M22 2l-7 20-4-9-9-4z'/></svg>");
  --i-plus: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'><path d='M12 5v14M5 12h14'/></svg>");
  --i-menu: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'><path d='M4 6h16M4 12h16M4 18h10'/></svg>");
  --i-lock: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><rect x='4' y='11' width='16' height='10' rx='2'/><path d='M8 11V7a4 4 0 0 1 8 0v4'/></svg>");
  --i-play: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M7 4.5v15l13-7.5z'/></svg>");
  --i-pause: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><rect x='6' y='4' width='4' height='16' rx='1.2'/><rect x='14' y='4' width='4' height='16' rx='1.2'/></svg>");
  --i-check: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><path d='M5 12.5l4.5 4.5L19 7.5'/></svg>");
  color-scheme: dark;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(60rem 40rem at 10% -10%, rgba(255, 181, 71, 0.09), transparent 60%),
    radial-gradient(50rem 40rem at 110% 20%, rgba(124, 198, 214, 0.07), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font: 16px/1.55 var(--body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.view {
  max-width: 38rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

h1, h2, h3 { font-family: var(--display); letter-spacing: -0.02em; line-height: 1.15; }
h1 { font-size: 2rem; margin: 0 0 0.5rem; font-weight: 700; }
h2 { font-size: 1.2rem; margin: 0 0 0.75rem; font-weight: 700; }
.lead { font-size: 1.05rem; margin: 0; color: var(--ink); opacity: 0.9; }
.hint { color: var(--dim); font-size: 0.9rem; margin: 0.5rem 0; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Buttons: secondary by default; .primary / .btn-primary for the main action. */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font: 500 0.95rem/1.2 var(--body);
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 0.7rem 1.1rem;
  min-height: 46px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
button:hover:not(:disabled) { background: var(--raised); }
button:active:not(:disabled) { transform: scale(0.98); }
button:disabled { cursor: default; opacity: 0.45; }

.primary, .btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.primary:hover:not(:disabled), .btn-primary:hover:not(:disabled) { background: #ffc46e; }
.primary {
  width: 100%;
  margin-top: 1.75rem;
  padding: 1.05rem;
  min-height: 60px;
  font-size: 1.1rem;
  border-radius: 18px;
  box-shadow: 0 10px 30px -10px rgba(255, 181, 71, 0.55);
}
.primary:disabled { background: var(--surface-2); border-color: var(--line); color: var(--dim); box-shadow: none; opacity: 1; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--dim); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.link { background: none; border: 0; padding: 0; min-height: 0; color: var(--dim); text-decoration: underline; border-radius: 0; font-size: 0.9rem; }
.link:hover:not(:disabled) { background: none; color: var(--ink); }

/* Icons are drawn with CSS so that changing a button's text keeps its icon. */
.btn-icon::before {
  content: "";
  flex: none;
  width: 1.15em;
  height: 1.15em;
  background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}
#start { --icon: var(--i-mic); }
#save-track, #save-beat, #save-human, #save-log { --icon: var(--i-download); }
#share-track { --icon: var(--i-share); }
#retry-human, #retry-save { --icon: var(--i-refresh); }
#open-transfer { --icon: var(--i-send); }
#library-toggle { --icon: var(--i-menu); }

.row { display: flex; gap: 0.6rem; margin-top: 1rem; }
.row button { flex: 1; }
.wide { display: flex; width: 100%; }

/* Brand */
.brand { display: inline-flex; align-items: center; gap: 0.55rem; color: var(--ink); text-decoration: none; font: 700 1.1rem var(--display); letter-spacing: -0.02em; }
.brand-mark { width: 1.6rem; height: 1.6rem; color: var(--accent); }
.topbar { display: none; }

/* Home */
.hero { padding: 1.5rem 0 0.5rem; }
.kicker {
  display: inline-block;
  margin: 0 0 1rem;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.hero h1 { font-size: clamp(2.6rem, 11vw, 3.6rem); line-height: 1; margin-bottom: 1rem; letter-spacing: -0.035em; }
.hero h1 em { font-style: normal; color: var(--accent); }
.hero .lead { color: var(--dim); max-width: 32rem; }
.status-line { display: flex; align-items: center; gap: 0.5rem; margin: 0.9rem 0 0; color: var(--dim); font-size: 0.9rem; }
.status-line:empty { display: none; }
.panel { margin-top: 2.25rem; padding: 1.25rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel h2 { font-size: 1rem; }
.privacy {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.5rem;
  color: var(--faint);
  font-size: 0.85rem;
}
.privacy::before {
  content: "";
  flex: none;
  width: 1rem;
  height: 1rem;
  margin-top: 0.15rem;
  background: currentColor;
  -webkit-mask: var(--i-lock) center / contain no-repeat;
  mask: var(--i-lock) center / contain no-repeat;
}

.family-list { list-style: none; padding: 0; margin: 0.5rem 0; }
.family-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; padding: 0.45rem 0; border-bottom: 1px solid var(--line); }
.family-list li:last-child { border-bottom: 0; }
.family-list .swatch { width: 0.6rem; height: 0.6rem; border-radius: 50%; flex: none; }
.family-list .count { margin-left: auto; color: var(--dim); font-size: 0.85rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chips-list { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0; }
.chips-list li { padding: 0.4rem 0.8rem 0.4rem 0.65rem; gap: 0.45rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; font-size: 0.88rem; }
.chips-list li:last-child { border-bottom: 1px solid var(--line); }

/* Walking: as dark as possible. This screen is meant to be ignored. */
#walk {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  text-align: center;
  background: #000;
  max-width: none;
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
  touch-action: none;
  user-select: none;
}
.walk-top { display: flex; flex-direction: column; align-items: center; }
.walk-top .hint { color: #5d5f78; margin: 0.25rem 0; }
.rec-badge { display: inline-flex; align-items: center; gap: 0.5rem; margin: 1rem 0 0; color: #b0525c; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; }
.rec-dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: #e0505f; animation: blink 1.6s ease-in-out infinite; }
.clock { margin: 0.25rem 0 0.5rem; color: #7c7e99; font: 500 3.5rem/1 var(--display); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.live-notes { width: 100%; max-width: 32rem; text-align: center; }
.live-notes canvas { display: block; width: 100%; height: 176px; }
.live-notes .hint { color: #4b4d63; }
.hearing { min-height: 3rem; margin: 0; font-size: 0.95rem; color: var(--dim); }

.hold {
  position: relative;
  overflow: hidden;
  width: 100%;
  max-width: 20rem;
  padding: 1.1rem;
  min-height: 60px;
  color: #8a8ca6;
  background: #0d0e16;
  border-color: #23253a;
  border-radius: 999px;
}
.hold:hover:not(:disabled) { background: #0d0e16; }
.hold::before {
  content: "";
  position: absolute;
  inset: 0;
  background: #2a2c44;
  transform: scaleX(0);
  transform-origin: left;
}
.hold.holding::before { transform: scaleX(1); transition: transform 1.2s linear; }
.hold span { position: relative; }

/* Progress across the three stages: record → compress → beatbox. */
.pipeline {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(10, 11, 20, 0.82);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.pipeline ol { list-style: none; display: grid; grid-template-columns: repeat(3, 1fr); max-width: 38rem; margin: 0 auto; padding: 0.85rem 1rem 0.75rem; }
.pipeline li { position: relative; display: flex; flex-direction: column; align-items: center; gap: 0.35rem; min-width: 0; text-align: center; }
.pipeline li + li::before {
  content: "";
  position: absolute;
  top: 0.9rem;
  right: calc(50% + 1.15rem);
  width: calc(100% - 2.3rem);
  height: 2px;
  border-radius: 2px;
  background: var(--line-strong);
}
.pipeline li[data-state="done"] + li::before,
.pipeline li[data-state="done"] + li[data-state="active"]::before { background: var(--accent); }
.step-dot {
  position: relative;
  display: grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  color: var(--dim);
  font: 700 0.8rem var(--display);
}
.step-dot::after { content: attr(data-n); }
.step-text { display: flex; flex-direction: column; min-width: 0; max-width: 100%; }
.step-name { font-size: 0.8rem; font-weight: 600; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step-state { font-size: 0.72rem; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pipeline [data-state="active"] .step-dot { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); animation: pulse 1.8s ease-out infinite; }
.pipeline [data-state="active"] .step-name { color: var(--ink); }
.pipeline [data-state="active"] .step-state { color: var(--accent); }
.pipeline [data-state="done"] .step-dot { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.pipeline [data-state="done"] .step-dot::after { content: ""; width: 0.85rem; height: 0.85rem; background: currentColor; -webkit-mask: var(--i-check) center / contain no-repeat; mask: var(--i-check) center / contain no-repeat; }
.pipeline [data-state="done"] .step-name { color: var(--ink); }
.pipeline [data-state="failed"] .step-dot { border-color: var(--danger); color: var(--danger); }
.pipeline [data-state="failed"] .step-dot::after { content: "!"; }
.pipeline [data-state="failed"] .step-state { color: var(--danger); }
.pipeline [data-state="off"] .step-dot { border-style: dashed; color: var(--faint); }
.pipeline [data-state="off"] .step-name { color: var(--faint); }

/* Result cards follow the state of their step in the progress bar. */
.card {
  margin: 0 0 0.9rem;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 0.3s, box-shadow 0.3s, opacity 0.3s;
}
.card-head { display: flex; align-items: flex-start; gap: 0.85rem; margin-bottom: 0.6rem; }
.card-head h1, .card-head h2 { margin: 0; font-size: 1.25rem; }
.badge {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  color: var(--dim);
  font: 700 0.95rem var(--display);
}
.badge::after { content: attr(data-n); }
.eyebrow { display: flex; align-items: center; gap: 0.5rem; margin: 0 0 0.2rem; color: var(--dim); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.tag { padding: 0.1rem 0.5rem; border: 1px dashed var(--line-strong); border-radius: 999px; font-size: 0.65rem; letter-spacing: 0.06em; }
.card > .hint { margin-top: 0; }
.credit { margin: 0.9rem 0 0; color: var(--faint); font-size: 0.75rem; }
.card > button:not([hidden]) { margin-top: 0.75rem; width: 100%; }
.card.is-off { background: transparent; border-style: dashed; }
.card.is-off .badge { border-style: dashed; background: transparent; color: var(--faint); }
.card.is-off h2 { color: var(--dim); }

body:has(#step-record[data-state="done"]) [data-step="record"] .badge,
body:has(#step-beat[data-state="done"]) [data-step="beat"] .badge,
body:has(#step-human[data-state="done"]) [data-step="human"] .badge { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
body:has(#step-record[data-state="done"]) [data-step="record"] .badge::after,
body:has(#step-beat[data-state="done"]) [data-step="beat"] .badge::after,
body:has(#step-human[data-state="done"]) [data-step="human"] .badge::after { content: ""; width: 1rem; height: 1rem; background: currentColor; -webkit-mask: var(--i-check) center / contain no-repeat; mask: var(--i-check) center / contain no-repeat; }
body:has(#step-beat[data-state="active"]) [data-step="beat"],
body:has(#step-human[data-state="active"]) [data-step="human"] { border-color: rgba(255, 181, 71, 0.45); box-shadow: 0 0 0 4px var(--accent-soft); }
body:has(#step-beat[data-state="active"]) [data-step="beat"] .badge,
body:has(#step-human[data-state="active"]) [data-step="human"] .badge { border-color: var(--accent); color: var(--accent); animation: pulse 1.8s ease-out infinite; }
body:has(#step-beat[data-state="waiting"]) [data-step="beat"],
body:has(#step-human[data-state="waiting"]) [data-step="human"] { opacity: 0.6; }
body:has(#step-beat[data-state="failed"]) [data-step="beat"],
body:has(#step-human[data-state="failed"]) [data-step="human"] { border-color: rgba(255, 122, 134, 0.45); }
body:has(#step-beat[data-state="failed"]) [data-step="beat"] .badge,
body:has(#step-human[data-state="failed"]) [data-step="human"] .badge { border-color: var(--danger); color: var(--danger); }
body:has(#step-beat[data-state="failed"]) #beat-status,
body:has(#step-human[data-state="failed"]) #human-status { color: var(--danger); }
body:has(#step-beat[data-state="active"]) #beat-status::before,
body:has(#step-human[data-state="active"]) #human-status::before {
  content: "";
  flex: none;
  width: 0.9rem;
  height: 0.9rem;
  border: 2px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
body:has(#step-beat[data-state="active"]) #beat-status,
body:has(#step-human[data-state="active"]) #human-status { color: var(--ink); }

/* Side-by-side comparison of the four beatboxes: 2 × 2 on wider screens. */
.compare { display: grid; gap: 0.75rem; margin-top: 1rem; }
@media (min-width: 900px) { .compare-grid { grid-template-columns: repeat(2, 1fr); } }
.take { display: flex; flex-direction: column; min-width: 0; padding: 0.9rem; background: var(--bg); border: 1px solid var(--line); border-radius: 16px; transition: border-color 0.3s; }
.take-name { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin: 0; font: 700 0.95rem var(--display); }
.take .player { margin-top: 0.75rem; padding: 0.45rem 0.6rem 0.45rem 0.45rem; background: var(--surface); }
.take .play { width: 38px; height: 38px; min-height: 38px; }
.take .wave { height: 32px; }
.take .bars { gap: 1px; }
.take .player { gap: 0.5rem; }
.take .player-time { min-width: 2.2rem; }
.take > button:not([hidden]) { width: 100%; margin-top: 0.75rem; min-height: 40px; font-size: 0.85rem; }
.take .credit { margin-top: 0.6rem; }
.take-status { display: flex; align-items: center; gap: 0.45rem; margin: 0.6rem 0 0; margin-bottom: auto; color: var(--dim); font-size: 0.85rem; overflow-wrap: anywhere; }
.take[data-state="active"] { border-color: rgba(255, 181, 71, 0.45); }
.take[data-state="active"] .take-status { color: var(--ink); }
.take[data-state="active"] .take-status::before { content: ""; flex: none; width: 0.8rem; height: 0.8rem; border: 2px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
.take[data-state="failed"] { border-color: rgba(255, 122, 134, 0.4); }
.take[data-state="failed"] .take-status { color: var(--danger); }
.take[data-state="done"] .take-status { color: var(--ok); }
.take[data-state="waiting"] { opacity: 0.7; }
#retry-human:not([hidden]) { margin-top: 0.75rem; width: 100%; }
#save-beatbox-eleven1, #save-beatbox-eleven2, #save-beatbox-eleven3, #save-beatbox-mix { --icon: var(--i-download); }
.take-how { margin: 0.3rem 0 0; color: var(--dim); font-size: 0.82rem; }

/* Note strips: the walk above each beat, one dot per 16th step, bigger = louder. */
.notes { margin-top: 0.75rem; padding: 0.65rem 0.75rem; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.take .notes { background: var(--surface); }
.notes-row { display: grid; grid-template-columns: 4.8rem 1fr; align-items: center; gap: 0.5rem; }
.notes-row + .notes-row { margin-top: 0.3rem; }
.take .notes { padding: 0.55rem 0.6rem; }
.take .notes-row { grid-template-columns: 1fr; gap: 0.1rem; }
.take .notes-grid { height: 18px; }
.notes-label { font-size: 0.72rem; font-weight: 600; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notes-row:first-child .notes-label { color: var(--ink); }
.notes-grid { display: grid; grid-template-columns: repeat(16, minmax(0, 1fr)); min-width: 0; align-items: center; height: 24px; border-radius: 6px;
  background: linear-gradient(90deg, var(--line) 1px, transparent 1px) 0 0 / 25% 100%; }
.note { justify-self: center; width: min(calc(5px + 13px * var(--s)), 92%); aspect-ratio: 1; border-radius: 50%;
  opacity: calc(0.45 + 0.55 * var(--s)); transition: transform 0.08s, box-shadow 0.08s; }
.note[data-part="kick"], .notes-legend [data-part="kick"]::before { background: var(--accent); }
.note[data-part="snare"], .notes-legend [data-part="snare"]::before { background: var(--cool); }
.note[data-part="hat"], .notes-legend [data-part="hat"]::before { background: #e8e4f5; }
.note[data-part="rest"] { width: 3px; background: var(--line-strong); opacity: 1; }
.note.now { transform: scale(1.35); box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--ink); }
.note[data-part="rest"].now { width: 6px; background: var(--ink); }
.notes-match { margin: 0.55rem 0 0; font-size: 0.8rem; font-weight: 600; color: var(--ok); }
.notes-match[data-level="mid"] { color: var(--accent); }
.notes-match[data-level="low"] { color: var(--dim); }
.notes-caption { margin: 0.45rem 0 0; font-size: 0.75rem; color: var(--dim); }
.notes-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 0.7rem; margin: 0.5rem 0 0; font-size: 0.7rem; color: var(--faint); }
.notes-legend span { display: inline-flex; align-items: center; gap: 0.3rem; color: var(--dim); }
.notes-legend span::before { content: ""; width: 0.55rem; height: 0.55rem; border-radius: 50%; }

/* The neon stage: big lips that beatbox with the playing card. */
.stage { position: relative; display: grid; justify-items: center; margin-top: 1rem; padding: 0.6rem 0 0.9rem;
  background: radial-gradient(55% 65% at 50% 48%, rgba(124, 198, 214, 0.1), transparent 70%), #05060c;
  border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.stage-lips { width: min(520px, 100%); height: auto; overflow: visible; --glow: 0.3; filter: brightness(calc(0.8 + var(--glow) * 0.7)) saturate(1.2); }
.stage .stage-mouth { --lip: #f4f1ea; }
.stage .lip { fill: none; stroke: var(--lip); stroke-width: 3.5; stroke-linejoin: round; stroke-linecap: round; }
.stage .crease { fill: none; stroke: var(--lip); stroke-width: 1.4; stroke-linecap: round; opacity: 0.75; }
.stage .mouth { fill: rgba(3, 2, 8, 0.85); stroke: none; }
.stage .outline { fill: none; stroke: #f4f1ea; stroke-width: 2.2; stroke-linecap: round; opacity: 0.55; }
.stage .teeth { fill: none; stroke: #fff6fb; stroke-width: 4; stroke-linecap: round; }
.stage-name { margin: 0.4rem 0 0; color: var(--dim); font-size: 0.8rem; text-align: center; }
.stage[data-playing="true"] .stage-name { color: var(--ink); }

.actions { margin-top: 1.25rem; }
.actions .row { margin-top: 0.6rem; }

details { color: var(--dim); font-size: 0.9rem; }
summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; gap: 0.5rem; list-style: none; font-weight: 500; }
summary::-webkit-details-marker { display: none; }
summary::before { content: ""; width: 0.45rem; height: 0.45rem; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform 0.15s; flex: none; }
details[open] > summary::before { transform: rotate(45deg); }
.more { margin-top: 1.5rem; padding: 0.25rem 1.25rem; border: 1px solid var(--line); border-radius: var(--radius); }
.more h3 { margin: 1rem 0 0.25rem; color: var(--ink); font-size: 0.95rem; }
.more > button { margin: 1rem 0; }
#top-labels { padding-left: 1.2rem; }
#retry-save { margin-top: 0.75rem; }

/* Custom audio player (src/player.js). */
audio { width: 100%; margin-top: 1rem; }
.player { display: flex; align-items: center; gap: 0.75rem; margin-top: 1rem; padding: 0.6rem 0.9rem 0.6rem 0.6rem; background: var(--bg); border: 1px solid var(--line); border-radius: 16px; }
.play { flex: none; width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 50%; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.play:hover:not(:disabled) { background: #ffc46e; }
.play::before { content: ""; width: 1.1rem; height: 1.1rem; background: currentColor; -webkit-mask: var(--i-play) center / contain no-repeat; mask: var(--i-play) center / contain no-repeat; margin-left: 2px; }
.is-playing .play::before { -webkit-mask-image: var(--i-pause); mask-image: var(--i-pause); margin-left: 0; }
.is-empty .play { opacity: 0.4; pointer-events: none; }
.wave { position: relative; flex: 1; height: 40px; min-width: 0; }
.bars { position: absolute; inset: 0; display: flex; align-items: center; gap: 2px; }
.bars i { flex: 1; min-width: 0; border-radius: 2px; background: var(--line-strong); }
.bars.played i { background: var(--accent); }
.bars.played { clip-path: inset(0 100% 0 0); }
.wave input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.wave:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 6px; }
.player-time { flex: none; min-width: 2.6rem; text-align: right; color: var(--dim); font-size: 0.8rem; font-variant-numeric: tabular-nums; }

.error {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  margin: 0;
  padding: 0.9rem 1rem;
  max-height: 40dvh;
  overflow: auto;
  background: #3b1219;
  border-top: 1px solid var(--danger);
  color: #ffd7dc;
  font: 0.85rem/1.45 var(--body);
  white-space: pre-wrap;
}

/* Library: one session per folder; the five stages keep their order even when empty. */
.library { position: fixed; inset: 0 auto 0 0; width: 20rem; padding: 1.1rem 1rem 1.5rem; overflow-y: auto; background: #0d0f1c; border-right: 1px solid var(--line); z-index: 10; }
.library-heading { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; min-height: 46px; margin-bottom: 1rem; }
.library > h2 { margin: 0 0 0.25rem; font-size: 0.75rem; color: var(--dim); letter-spacing: 0.1em; text-transform: uppercase; font-family: var(--body); font-weight: 600; }
.library > #library-status { font-size: 0.8rem; color: var(--faint); }
.empty { margin: 1rem 0; padding: 1.25rem; border: 1px dashed var(--line-strong); border-radius: 16px; color: var(--dim); font-size: 0.9rem; text-align: center; }
.library-session { margin-top: 0.6rem; padding: 0.4rem 0.9rem 0.8rem; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.library-session[open] { border-color: var(--line-strong); }
.library-session > summary { color: var(--ink); font-weight: 600; }
.library-stage { margin-top: 0.35rem; padding-left: 0.75rem; border-left: 2px solid var(--line); }
.library-stage > summary { min-height: 38px; font-size: 0.85rem; overflow-wrap: anywhere; }
.library-stage .hint { font-size: 0.8rem; color: var(--faint); margin: 0 0 0.5rem; }
.library-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.library-actions button { min-height: 34px; padding: 0.35rem 0.75rem; font-size: 0.8rem; border-radius: 10px; }
.library-file { padding: 0.45rem 0 0.75rem; }
.library-file p { color: var(--ink); margin: 0 0 0.4rem; font-size: 0.85rem; overflow-wrap: anywhere; }
#library-playback { position: sticky; bottom: -1.5rem; margin: 1rem -1rem 0; padding: 0.75rem 1rem 1.5rem; background: #0d0f1c; border-top: 1px solid var(--line); }
#library-playing { overflow-wrap: anywhere; margin: 0; font-size: 0.8rem; }
#library-playback .player { margin-top: 0.5rem; }
.transfer-panel { margin-top: 1.5rem; padding: 0.25rem 0.9rem 0.5rem; border: 1px solid var(--line); border-radius: 16px; }
.transfer-panel > details > summary { color: var(--ink); }
.transfer-panel button { width: 100%; }
.transfer-panel label { display: block; margin: 1rem 0 0.4rem; color: var(--ink); font-weight: 500; }
.transfer-panel input[type="file"] { max-width: 100%; color: var(--dim); font-size: 0.85rem; }
.connection-input { width: 100%; padding: 0.8rem; margin-bottom: 0.8rem; background: var(--bg); color: var(--ink); border: 1px solid var(--line-strong); border-radius: 12px; font: inherit; }
#transfer-receipts { overflow-wrap: anywhere; padding-left: 1.2rem; }
.library-toggle, #library-close { display: none; }
.with-library { padding-left: 20rem; }
.with-library.is-recording { padding-left: 0; padding-top: 0; }

@media (max-width: 760px) {
  .with-library { padding-left: 0; }
  .topbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    padding-top: max(0.6rem, env(safe-area-inset-top));
  }
  .is-recording .topbar { display: none; }
  .library { width: min(22rem, 92vw); display: none; }
  .library.is-open { display: block; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.6); }
  .library-toggle { display: inline-flex; min-height: 40px; padding: 0.5rem 0.85rem; font-size: 0.85rem; border-radius: 12px; }
  #library-close { display: inline-flex; }
  .view { padding-top: 1rem; }
  .pipeline ol { padding: 0.7rem 0.5rem 0.6rem; }
}
@media (min-width: 761px) {
  .library-heading .brand { font-size: 1.2rem; }
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 181, 71, 0.45); }
  100% { box-shadow: 0 0 0 10px rgba(255, 181, 71, 0); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Home: two ways in. Recording is the main one. */
.choices { display: grid; gap: 0.7rem; margin-top: 1.4rem; }
.choice { display: grid; grid-template-columns: 48px 1fr; gap: 0.9rem; align-items: center; width: 100%; min-height: 78px; padding: 0.9rem 1rem;
  text-align: left; border-radius: 18px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); }
.choice-icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 14px; background: rgba(255, 255, 255, 0.06); }
.choice-icon::before { content: ""; width: 1.35rem; height: 1.35rem; background: currentColor; -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat; }
#start .choice-icon { --icon: var(--i-mic); }
#upload .choice-icon { --icon: var(--i-share); }
.choice-sample .choice-icon { --icon: var(--i-play); }
.choice-text b { display: block; font: 700 1.05rem var(--display); letter-spacing: -0.01em; }
.choice-text span { display: block; margin-top: 0.15rem; color: var(--dim); font-size: 0.82rem; line-height: 1.35; }
.choice-main { background: var(--accent); border-color: transparent; color: var(--accent-ink); box-shadow: 0 10px 30px rgba(255, 181, 71, 0.22); }
.choice-main:hover:not(:disabled) { background: #ffc46e; }
.choice-main .choice-text span { color: rgba(31, 20, 0, 0.75); }
.choice-main .choice-icon { background: rgba(31, 20, 0, 0.12); }

/* Results: the stage beside (desktop) or above (phone) one list of everything to hear. */
.view.results { max-width: 72rem; display: grid; gap: 1rem; align-items: start; }
@media (min-width: 900px) {
  .view.results { grid-template-columns: minmax(18rem, 0.85fr) minmax(24rem, 1.15fr); gap: 1.5rem; }
  .results-stage { position: sticky; top: 5.5rem; }
  .results .stage-lips { max-height: 52vh; }
}
.results-head h1 { margin: 0; font-size: 1.3rem; }
.results-lead { margin: 0.25rem 0 0; color: var(--dim); font-size: 0.88rem; }
.results .stage { margin-top: 0.8rem; padding: 0.4rem 0 0.6rem; }
.results .stage-lips { width: min(460px, 100%); max-height: 30vh; }
.results-stage .credit { font-size: 0.68rem; line-height: 1.45; }
.results-list > .status-line { margin: 0 0 0.6rem; }
.results-list > #retry-human:not([hidden]) { margin: 0 0 0.75rem; width: auto; }
.tracks { border: 1px solid var(--line); border-radius: 18px; overflow: hidden; background: var(--surface); }
.track { display: grid; grid-template-columns: 40px minmax(0, 1fr) minmax(0, 1.15fr) auto; grid-template-areas: "play text notes tools" "play wave wave time" "note note note note";
  gap: 0.15rem 0.75rem; align-items: center; padding: 0.6rem 0.8rem; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; position: relative; }
.track:last-child { border-bottom: 0; }
.track.take { padding: 0.6rem 0.8rem; }
.track-walk { background: rgba(255, 255, 255, 0.025); }
.track-text { grid-area: text; min-width: 0; }
.track .take-name { font-size: 0.9rem; }
.track .take-how { margin: 0.1rem 0 0; font-size: 0.72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track .tag { font-size: 0.58rem; padding: 0 0.4rem; white-space: nowrap; }
/* The player's parts (play button, waveform, time) sit straight in the row's grid. */
.track-player:not([hidden]), .track .player { display: contents; }
.track .play { grid-area: play; width: 40px; height: 40px; min-height: 40px; margin: 0; }
.track .wave { grid-area: wave; height: 18px; }
.track .player-time { grid-area: time; min-width: 2.2rem; font-size: 0.7rem; }
.track .notes { grid-area: notes; margin: 0; padding: 0; background: none; border: 0; }
.track .notes-row { grid-template-columns: 1fr; }
.track .notes > .notes-row:not(:last-of-type), .track .notes-label, .track .notes-legend, .track .notes-caption { display: none; }
.track .notes-grid { height: 18px; }
.track .notes-match { margin: 0.15rem 0 0; font-size: 0.68rem; text-align: right; }
.track-tools { grid-area: tools; display: flex; gap: 0.3rem; }
.track > .track-save, .track-tools .track-save { grid-area: tools; width: 34px; height: 34px; min-height: 34px; padding: 0; justify-content: center; border-radius: 10px; font-size: 0; gap: 0; }
.track .take-status { grid-area: note; margin: 0.2rem 0 0; font-size: 0.75rem; }
.track[data-state="done"] .take-status:not(.track-note) { display: none; }
.track .take-status:empty { display: none; }
.track #retry-save:not([hidden]) { grid-area: note; justify-self: start; margin-top: 0.4rem; }
.take.track[data-state="waiting"] { opacity: 0.6; }
.take.track[data-state="active"]::before, .take.track[data-state="failed"]::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--accent); }
.take.track[data-state="failed"]::before { background: var(--danger); }
.track:has(.player.is-playing) { background: rgba(255, 181, 71, 0.07); }
.tracks-legend { margin: 0.55rem 0.2rem 0; }
.results .actions { display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 0.5rem; margin-top: 1rem; }
.results .actions button { min-height: 44px; font-size: 0.85rem; padding: 0.5rem 0.6rem; }
.results .more { margin-top: 1rem; }
@media (max-width: 520px) {
  .track { grid-template-columns: 38px minmax(0, 1fr) auto; grid-template-areas: "play text tools" "play notes notes" "wave wave time" "note note note"; }
  .track .notes-match { text-align: left; }
  .results .actions { grid-template-columns: 1fr 1fr; }
}
.track-save.btn-icon::before { width: 18px; height: 18px; }

/* Surprise mix: the last row. */
.track-mix { background: linear-gradient(90deg, rgba(255, 181, 71, 0.08), transparent 60%); }
