  /* ---- Material Design 3 dark color roles — a vibrant "cool blue" primary (BOiNK's original
     accent, #049cfd) with surfaces tinted cool/blue-gray to match, rather than neutral MD3 gray.
     Hand-rolled tokens, no MD3 web-component dep — stays a single self-contained file, same as the
     rest of this repo's /tools pages. Structure (fixed single-pane shell, top bar, bottom nav with
     a primary-colour active indicator) takes its cue from chainDRiVE's ui.css (cd-menubar/cd-nav-bar). ---- */
  :root {
    --md-primary: #049cfd; --md-on-primary: #00223a; --md-primary-container: #004a78; --md-on-primary-container: #cce8ff;
    --md-secondary: #a9c6e0; --md-secondary-container: #27465f; --md-on-secondary-container: #cce8ff; --md-tertiary: #c2b6e8;
    --md-surface: #0b0f14; --md-surface-dim: #090c10; --md-surface-bright: #343c46;
    --md-surface-container-lowest: #060809; --md-surface-container-low: #11161c;
    --md-surface-container: #151b22; --md-surface-container-high: #1f2731; --md-surface-container-highest: #2a333f;
    --md-on-surface: #e4e8ee; --md-on-surface-variant: #b4c0cf;
    --md-outline: #7d8a9a; --md-outline-variant: #3a4452;
    --md-error: #ffb4ab; --md-success: #6dd58c; --md-warn: #f0b429;
    /* MD3's real elevation system: a surface doesn't just get a shadow as it "lifts" off the
       baseline, it also mixes in a touch of the primary tone (tonal elevation) — level 1 ≈ 5%,
       level 2 ≈ 8%. Flat solid panels + a hard border/shadow with no tint is the Holo-era look;
       this is the actual difference. */
    --md-elevation-1: 0 1px 2px rgba(0,0,0,.45), 0 1px 3px 1px rgba(0,0,0,.3);
    --md-elevation-2: 0 1px 2px rgba(0,0,0,.5), 0 2px 6px 2px rgba(0,0,0,.35);
    --md-elevation-3: 0 1px 3px rgba(0,0,0,.5), 0 4px 8px 3px rgba(0,0,0,.3);
    --md-surface-tint-1: color-mix(in srgb, var(--md-surface-container-low) 95%, var(--md-primary) 5%);
    --md-surface-tint-2: color-mix(in srgb, var(--md-surface-container-low) 92%, var(--md-primary) 8%);
    /* MD3's shape scale, applied by component role rather than one-size pill: extra-small (8dp) for
       chips, small/medium (12/16dp) for cards & menus, large (16dp) for drawer corners, full only
       for pill buttons and the nav active-indicator. */
    --md-shape-xs: 8px; --md-shape-sm: 12px; --md-shape-md: 16px; --md-shape-lg: 28px; --md-shape-full: 999px;
    /* Named state-layer opacities (hover/pressed/focus-ring), applied consistently everywhere
       instead of inlining color-mix() per selector — chainDRiVE's --md-sys-state-* pattern. */
    --md-state-hover: color-mix(in srgb, var(--md-on-surface) 8%, transparent);
    --md-state-pressed: color-mix(in srgb, var(--md-on-surface) 12%, transparent);
    --md-state-focus: color-mix(in srgb, var(--md-primary) 16%, transparent);
    --topbar-h: 56px; --navbar-h: 80px;
  }
  * { box-sizing: border-box; }
  .material-symbols-outlined {
    font-family: 'Material Symbols Outlined'; font-weight: normal; font-style: normal;
    font-size: 20px; line-height: 1; letter-spacing: normal; text-transform: none;
    display: inline-block; white-space: nowrap; word-wrap: normal; direction: ltr;
    -webkit-font-smoothing: antialiased; vertical-align: middle;
  }
  html, body { height: 100%; }
  body {
    margin: 0; background: var(--md-surface); color: var(--md-on-surface);
    font: 400 14px/1.45 Roboto, system-ui, -apple-system, "Segoe UI", sans-serif; letter-spacing: .009em;
    -webkit-font-smoothing: antialiased;
    position: fixed; inset: 0; overflow: hidden; overscroll-behavior: none;   /* app shell, not a scrolling page */
  }
  /* ---- top app bar: slim and fixed, hamburger + logo — like chainDRiVE's cd-menubar. Everything
     else that used to live here (description, totals, progress, A/B-all) scrolls with its own
     screen's content instead of being pinned; settings live in the hamburger's drawer. ---- */
  .topbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 20; height: var(--topbar-h);
    display: flex; align-items: center; gap: 4px;
    background: var(--md-surface-tint-1); box-shadow: var(--md-elevation-1);
    padding: 0 8px 0 4px;
  }
  .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; }
  .topbar-spacer { flex: 1; }
  .icon-btn {
    display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px;
    background: transparent; color: var(--md-on-surface); border-radius: 50%; font-size: 18px; padding: 0; min-height: 0;
  }
  .icon-btn:hover { background: var(--md-state-hover); }
  .icon-btn:active { background: var(--md-state-pressed); }
  .icon-btn:focus-visible { outline: 2px solid var(--md-primary); outline-offset: 2px; }
  /* ---- Settings drawer: left-sliding, same structure/behaviour as chainDRiVE's cd-drawer —
     rounded trailing corners + shadow carry the separation (no hard border line). ---- */
  .drawer-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.55); opacity: 0; transition: opacity .2s ease; pointer-events: none; }
  .drawer-backdrop--visible { opacity: 1; pointer-events: auto; }
  .drawer {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 50; width: min(100%, 340px); max-width: calc(100vw - 48px);
    display: flex; flex-direction: column; background: var(--md-surface-tint-2);
    border-radius: 0 var(--md-shape-lg) var(--md-shape-lg) 0; box-shadow: 4px 0 24px rgba(0,0,0,.35);
    transform: translateX(-105%); transition: transform .24s cubic-bezier(.2,0,0,1);
  }
  .drawer--open { transform: translateX(0); }
  .drawer-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 56px; padding: 8px 8px 8px 20px; border-bottom: 1px solid var(--md-outline-variant); }
  .drawer-title { margin: 0; font-size: 18px; font-weight: 500; }
  .drawer-body { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 20px; }
  /* ---- Logo badge, styled after chainDRiVE's cd-logo-badge: a two-tone wordmark in a tinted pill,
     right-aligned in the top bar via the spacer before it. ---- */
  .logo-badge {
    flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
    max-width: 52%; height: 22px; padding: 0 10px; border-radius: 4px;
    border: 1px solid color-mix(in srgb, var(--md-primary) 55%, transparent);
    background:
      linear-gradient(105deg, color-mix(in srgb, var(--md-primary) 14%, transparent) 0%, color-mix(in srgb, var(--md-primary) 6%, transparent) 48%, color-mix(in srgb, var(--md-primary) 18%, transparent) 100%),
      var(--md-surface-container);
    box-shadow: inset 0 1px 0 color-mix(in srgb, var(--md-primary) 22%, transparent), 0 1px 2px rgba(0,0,0,.22);
  }
  .logo-text { display: inline-flex; align-items: baseline; white-space: nowrap; font-size: .8125rem; line-height: 1; }
  .logo-boink {
    color: var(--md-primary); font-weight: 800; letter-spacing: .02em;
    text-shadow: 0 0 10px color-mix(in srgb, var(--md-primary) 45%, transparent), 0 0 1px color-mix(in srgb, var(--md-primary) 80%, transparent);
  }
  .logo-sub { color: color-mix(in srgb, var(--md-on-surface-variant) 90%, var(--md-primary)); font-weight: 500; letter-spacing: .04em; margin-left: .3em; }
  /* ---- Sounds screen's own header block (scrolls with the list, not fixed) ---- */
  .sounds-head { margin-bottom: 14px; }
  .source-row { margin-bottom: 14px; }
  .device-row { margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--md-outline-variant); }
  /* ---- Queued sounds list: just names, confirming what Synthesize will convert — the full card
     with spectrograms/score only exists in Output, once a sound's actually been synthesized. ---- */
  .queue-list { display: grid; gap: 1px; margin-top: 8px; border-radius: var(--md-shape-sm); overflow: hidden; }
  .queue-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px;
    background: var(--md-surface-container-low); font-size: 13px; color: var(--md-on-surface);
  }
  .queue-item .material-symbols-outlined { font-size: 18px; color: var(--md-on-surface-variant); flex: none; }
  .queue-item span.name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .queue-item .queue-remove {
    flex: none; width: 30px; height: 30px; margin: -4px -4px -4px 0; border-radius: 50%;
    background: transparent; color: var(--md-on-surface-variant); padding: 0; min-height: 0;
  }
  .queue-item .queue-remove .material-symbols-outlined { font-size: 17px; color: inherit; }
  .queue-item .queue-remove:hover { background: color-mix(in srgb, var(--md-error) 14%, transparent); color: var(--md-error); }
  /* ---- MD3 FAB: fixed to the viewport (not the scrolling screen content) above the bottom nav,
     bottom-right — shown only while the Sounds screen is active (toggled in JS alongside it). ---- */
  .fab {
    position: fixed; right: 20px; bottom: calc(var(--navbar-h) + 20px); z-index: 15;
    background: var(--md-primary-container); color: var(--md-on-primary-container);
    font-weight: 700; padding: 0 20px 0 16px; min-height: 56px; border-radius: var(--md-shape-lg);
    box-shadow: var(--md-elevation-2); transition: bottom .2s ease;
  }
  .fab[hidden] { display: none; }
  .fab:hover { background: color-mix(in srgb, var(--md-primary-container) 88%, #fff 12%); box-shadow: var(--md-elevation-3); }
  .fab:focus-visible { outline: 2px solid var(--md-primary); outline-offset: 2px; }
  .fab .material-symbols-outlined { font-size: 22px; }
  /* ---- MD3 tonal FAB variant: muted surface colour instead of the primary brand colour, for a
     secondary/destructive action (Clear) that shouldn't compete visually with Synthesize ---- */
  .fab-left { right: auto; left: 20px; }
  .fab-tonal { background: var(--md-surface-container-highest); color: var(--md-on-surface); }
  .fab-tonal:hover { background: color-mix(in srgb, var(--md-surface-container-highest) 88%, var(--md-on-surface) 12%); }
  /* ---- Output screen's own header block: run-all action + build progress ---- */
  .output-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 16px; }
  .totals { color: var(--md-on-surface-variant); font-variant-numeric: tabular-nums; font-size: 12px; flex: 1 1 auto; min-width: 160px; }
  .totals b { color: var(--md-primary); font-weight: 500; }
  /* ---- MD3 linear progress indicator ---- */
  .progress { width: 100%; height: 3px; background: var(--md-surface-container-highest); border-radius: var(--md-shape-full); overflow: hidden; }
  .progress[hidden] { display: none; }
  .progress-fill { height: 100%; width: 0; background: var(--md-primary); border-radius: var(--md-shape-full); transition: width .12s linear; }
  /* ---- single-pane screens: exactly one visible at a time, each scrolls on its own ---- */
  .screen { position: fixed; top: var(--topbar-h); left: 0; right: 0; bottom: var(--navbar-h); overflow-y: auto; display: none; }
  .screen.active { display: block; }
  .screen-inner { max-width: 1100px; margin: 0 auto; padding: 16px 20px 32px; }
  /* ---- bottom navigation (MD3 style, per chainDRiVE's cd-nav-bar) ---- */
  .navbar-wrap { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--md-surface-tint-1); box-shadow: var(--md-elevation-2); }
  .navbar { display: flex; max-width: 480px; margin: 0 auto; height: var(--navbar-h); }
  .nav-item {
    flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    background: transparent; border: 0; border-radius: 0; color: var(--md-on-surface-variant);
    font: 500 12px/1 Roboto, inherit; letter-spacing: .2px; padding: 8px 4px; min-height: var(--navbar-h);
    transition: color .15s ease;
  }
  /* ---- MD3 NavigationBar active state: a pill-shaped indicator sits BEHIND the icon only (not a
     border-line under the whole item, and not spanning the label) — the icon itself carries the
     pill so it works regardless of label width. ---- */
  .nav-item .nav-icon {
    font-size: 20px; line-height: 1; padding: 6px 20px; border-radius: var(--md-shape-full);
    background: transparent; transition: background-color .2s cubic-bezier(.2,0,0,1), color .15s ease;
  }
  .nav-item--active { color: var(--md-on-surface); }
  .nav-item--active .nav-icon { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
  .nav-item:focus-visible { outline: 2px solid var(--md-primary); outline-offset: -2px; }
  /* ---- MD3 filled select: boxed (rounded all corners, 1px outline, custom chevron) rather than
     the old underline-only "filled text field" style — matches chainDRiVE's cd-select. ---- */
  .bar-inner { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; }
  .bar-inner label { color: var(--md-on-surface-variant); display: inline-flex; flex-direction: column; gap: 4px; align-items: flex-start; font-size: 13px; font-weight: 500; letter-spacing: .006em; }
  .bar-inner label[hidden] { display: none; }
  /* ---- Icon-punctuated labels, chainDRiVE's cd-label--icon/cd-field-icon pattern: a small
     primary-coloured glyph in front of a field's caption, used liberally throughout. ---- */
  .label-text { display: inline-flex; align-items: center; gap: 6px; }
  .label-icon { font-size: 1.125rem; color: var(--md-primary); flex-shrink: 0; }
  /* MD3 Outlined Text Field: a 2px border is reserved at rest (not added on focus, which would
     jog the layout by a pixel) — focus is signalled by the border itself thickening in weight of
     COLOR to primary, not by an outside glow ring (that's the Bootstrap `.form-select:focus`
     signature, not MD3's). */
  select {
    font: 500 14px/1 Roboto, inherit; color: var(--md-on-surface); background-color: var(--md-surface-container-high);
    border: 2px solid var(--md-outline); border-radius: var(--md-shape-xs);
    padding: 11px 35px 11px 13px; min-height: 44px; appearance: none; -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23b4c0cf' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center; background-size: 18px;
    transition: background-color .15s ease, border-color .15s ease;
  }
  select:hover { background-color: var(--md-surface-container-highest); border-color: var(--md-on-surface); }
  select:focus-visible { outline: none; border-color: var(--md-primary); }
  .bar-inner label:has(input[type="checkbox"]), .bar-inner label:has(input[type="range"]) { flex-direction: row; align-items: center; font-size: 13px; }
  /* ---- MD3-ish grouped control clusters (Source / Analysis / Playback) ---- */
  .ctrl-group { display: flex; flex-direction: column; gap: 8px; padding: 14px 0; }
  .ctrl-group-label { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--md-primary); }
  .ctrl-group-label .label-icon { font-size: 14px; }
  .ctrl-group-row { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; }
  .ctrl-group-row[hidden] { display: none; }
  /* ---- MD3 switch (52×32 track, 16dp handle growing to 24dp when on) — not a bare checkbox ---- */
  input[type="checkbox"] {
    appearance: none; -webkit-appearance: none; margin: 0; padding: 0; cursor: pointer; flex: none;
    width: 52px; height: 32px; border-radius: var(--md-shape-full);
    background: var(--md-surface-container-highest); border: 2px solid var(--md-outline); position: relative;
    transition: background-color .2s cubic-bezier(.2,0,0,1), border-color .2s cubic-bezier(.2,0,0,1);
  }
  input[type="checkbox"]::before {
    content: ""; position: absolute; top: 50%; left: 8px; width: 16px; height: 16px; border-radius: 50%;
    background: var(--md-outline); transform: translateY(-50%);
    transition: transform .2s cubic-bezier(.2,0,0,1), width .15s cubic-bezier(.2,0,0,1), height .15s cubic-bezier(.2,0,0,1), left .15s cubic-bezier(.2,0,0,1), background-color .2s ease;
  }
  input[type="checkbox"]:checked { background: var(--md-primary); border-color: var(--md-primary); }
  input[type="checkbox"]:checked::before { width: 24px; height: 24px; left: 4px; transform: translate(20px, -50%); background: var(--md-on-primary); }
  input[type="checkbox"]:focus-visible { outline: 2px solid var(--md-primary); outline-offset: 2px; }
  /* ---- MD3 slider: 4px track, 20px circular thumb, focus/hover halo ---- */
  input[type="range"] { -webkit-appearance: none; appearance: none; background: transparent; width: 140px; height: 20px; margin: 0; flex: none; }
  input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: var(--md-shape-full); background: var(--md-outline-variant); }
  input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; width: 20px; height: 20px; margin-top: -8px; border-radius: 50%;
    background: var(--md-primary); border: none; cursor: pointer; transition: box-shadow .15s ease;
  }
  input[type="range"]:hover::-webkit-slider-thumb, input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 8px var(--md-state-focus); }
  input[type="range"]::-moz-range-track { height: 4px; border-radius: var(--md-shape-full); background: var(--md-outline-variant); }
  input[type="range"]::-moz-range-progress { height: 4px; border-radius: var(--md-shape-full); background: var(--md-primary); }
  input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: var(--md-primary); border: none; cursor: pointer; }
  input[type="range"]:focus-visible { outline: none; }
  #noiseLevelVal { font-variant-numeric: tabular-nums; color: var(--md-on-surface-variant); font-size: 12.5px; min-width: 34px; }
  /* ---- MD3 buttons: plain <button> = Tonal, .primary = Filled (brand colour), .outlined = Outlined ---- */
  button {
    font: 500 14px/1 Roboto, inherit; letter-spacing: .006em; color: var(--md-on-surface); cursor: pointer;
    background: var(--md-surface-container-highest); border: none; border-radius: var(--md-shape-full);
    display: inline-flex; align-items: center; gap: 8px; justify-content: center;
    padding: 10px 20px; min-height: 40px; transition: background-color .15s ease, box-shadow .15s ease, opacity .15s ease;
  }
  button .material-symbols-outlined { font-size: 1.125rem; }
  button:hover { background: color-mix(in srgb, var(--md-surface-container-highest) 92%, var(--md-on-surface) 8%); }
  button:active { background: color-mix(in srgb, var(--md-surface-container-highest) 88%, var(--md-on-surface) 12%); }
  button:disabled { opacity: .38; cursor: default; }
  button:focus-visible { outline: 2px solid var(--md-primary); outline-offset: 2px; }
  button.primary { background: var(--md-primary); color: var(--md-on-primary); font-weight: 500; box-shadow: var(--md-elevation-1); }
  button.primary:hover { background: color-mix(in srgb, var(--md-primary) 92%, #fff 8%); box-shadow: var(--md-elevation-2); }
  button.primary:active { background: color-mix(in srgb, var(--md-primary) 88%, #fff 12%); }
  button.outlined { background: transparent; color: var(--md-primary); border: 1px solid var(--md-outline); }
  button.outlined:hover { background: color-mix(in srgb, var(--md-primary) 8%, transparent); }
  button.outlined:active { background: color-mix(in srgb, var(--md-primary) 12%, transparent); }
  /* ---- MD3 text button (chainDRiVE's cd-btn-text): no fill, no border — for a low-emphasis
     action like resetting a panel's fields back to their defaults. ---- */
  button.text-btn { background: transparent; color: var(--md-primary); padding: 0 12px; }
  button.text-btn:hover { background: var(--md-state-hover); }
  button.text-btn:active { background: var(--md-state-pressed); }
  /* ---- MD3 full-screen modal: blocks the rest of the app while synthesis runs ---- */
  .modal-backdrop {
    position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.55);
    display: flex; align-items: center; justify-content: center; padding: 20px;
  }
  .modal-backdrop[hidden] { display: none; }
  .modal {
    width: min(100%, 360px); background: var(--md-surface-tint-2); border-radius: var(--md-shape-lg);
    box-shadow: var(--md-elevation-3); padding: 24px;
  }
  .modal h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; font-size: 18px; font-weight: 500; }
  .modal h2 .material-symbols-outlined { color: var(--md-primary); font-size: 1.25rem; }
  .modal p { margin: 0 0 16px; color: var(--md-on-surface-variant); font-size: 13px; }
  .modal .progress { margin-bottom: 20px; }
  .modal button { width: 100%; }
  /* ---- MD3 elevated card per sound ---- */
  #list { display: grid; gap: 12px; }
  /* ---- MD3 Elevated card: tonal surface + shadow carries the separation, no border line ---- */
  .row {
    background: var(--md-surface-tint-1);
    border-radius: var(--md-shape-md); padding: 16px; display: grid; grid-template-columns: 190px 1fr; gap: 16px;
    box-shadow: var(--md-elevation-1); transition: box-shadow .15s ease, background-color .15s ease;
  }
  .row:hover { box-shadow: var(--md-elevation-2); background: var(--md-surface-tint-2); }
  .meta h2 { margin: 0; font-size: 15px; font-weight: 500; word-break: break-all; color: var(--md-on-surface); }
  /* ---- MD3 assist chip: 8dp (small) corner radius, not a full pill ---- */
  .meta .kind { display: inline-block; margin-top: 8px; font-size: 11px; font-weight: 500; color: var(--md-on-surface-variant); border: 1px solid var(--md-outline); border-radius: var(--md-shape-xs); padding: 4px 10px; }
  .btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
  .btns button { padding: 8px 14px; min-height: 36px; font-size: 12.5px; gap: 6px; }
  .btns button .material-symbols-outlined { font-size: 1rem; }
  .specs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; min-width: 0; }
  .spec { min-width: 0; }
  .spec span { display: block; font-size: 11px; font-weight: 500; letter-spacing: .3px; text-transform: uppercase; color: var(--md-on-surface-variant); margin-bottom: 4px; }
  canvas { width: 100%; height: 110px; display: block; background: var(--md-surface-container-lowest); border-radius: var(--md-shape-sm); border: 1px solid var(--md-outline-variant); }
  .status { color: var(--md-warn); }
  @media (max-width: 720px) {
    :root { --topbar-h: 52px; --navbar-h: 64px; }
    .topbar { padding: 0 8px; }
    h1 { font-size: 16px; }
    .output-head { flex-direction: column; align-items: stretch; }
    .screen-inner { padding: 12px 16px 24px; }
    .row { grid-template-columns: 1fr; padding: 12px; gap: 10px; border-radius: var(--md-shape-sm); }
    .meta h2 { font-size: 14px; }
    .btns { margin-top: 8px; }
    .btns button { padding: 7px 12px; }
    canvas { height: 64px; }
    .nav-item { font-size: 10px; }
  }
