/* songcode — design system and layout.
 *
 * Structure of this file:
 *   1. tokens          4. top bar + transport     7. editor stage
 *   2. base            5. shell, panels, library   8. menus, dialogs, toast
 *   3. components      6. composer                 9. small screens, motion
 *
 * Rules of the system: one accent, used only for the primary action and for
 * things that are live (playing, generating, focused). Selection is neutral.
 * Everything else is built from four surfaces and three text tiers.
 */

/* ————————————————————————————— 1. tokens ————————————————————————————— */

@property --rail-w {
  syntax: '<length>';
  inherits: true;
  initial-value: 0px;
}
@property --rail-div {
  syntax: '<length>';
  inherits: true;
  initial-value: 0px;
}

:root {
  color-scheme: dark;

  /* surfaces, darkest to lightest */
  --bg: #070708;
  --surface-0: #0d0d0f; /* content wells: the editor */
  --surface-1: #131315; /* panels */
  --surface-2: #1c1c1f; /* controls */
  --surface-3: #26262a; /* hover, raised */
  --surface-4: #333338; /* selected, thumbs */
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.13);

  /* text tiers */
  --text: #f4f4f6;
  --text-2: rgba(235, 235, 245, 0.64);
  --text-3: rgba(235, 235, 245, 0.4);

  /* accent: primary action and live state only */
  --accent: #b8ff2e;
  --accent-ink: #0d1300;
  --accent-soft: rgba(184, 255, 46, 0.12);
  --accent-line: rgba(184, 255, 46, 0.4);
  --danger: #ff5a4f;
  --warn: #ffb53d;

  /* categorical colors, one per stem role */
  --stem-kick: #ff5a4f;
  --stem-clap: #ff9f0a;
  --stem-hats: #ffd60a;
  --stem-perc: #c9a26b;
  --stem-bass: #409cff;
  --stem-chords: #bf5af2;
  --stem-lead: #ff5fa2;
  --stem-arp: #64d2ff;
  --stem-pad: #7d7aff;
  --stem-texture: #66d4cf;

  /* shape */
  --r-sm: 7px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --gap: 8px; /* gutter between panels */

  /* type */
  --font-sans: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', 'Segoe UI', Roboto, system-ui, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;

  /* motion */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-spring: cubic-bezier(0.3, 1.35, 0.5, 1);
  --dur-1: 0.12s;
  --dur-2: 0.2s;
  --dur-3: 0.34s;

  /* elevation */
  --shadow-pop: 0 0 0 1px var(--line-strong), 0 12px 40px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.3);
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);

  --topbar-h: 52px;

  /* names from the previous stylesheet, kept as aliases */
  --bg-raise: var(--surface-2);
  --panel: var(--surface-1);
  --panel-2: var(--surface-2);
  --hairline: var(--line);
  --hairline-strong: var(--line-strong);
  --text-dim: var(--text-2);
  --text-faint: var(--text-3);
  --acid: var(--accent);
  --acid-soft: var(--accent-soft);
  --acid-line: var(--accent-line);
  --radius: var(--r-lg);
  --radius-sm: var(--r-md);
  --mono: var(--font-mono);
  --sans: var(--font-sans);
}

/* ————————————————————————————— 2. base ————————————————————————————— */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  height: 100dvh;
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
em { font-style: normal; }
h1, h2, h3, p { margin: 0; }
::selection { background: rgba(184, 255, 46, 0.28); }

:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus); }

/* thin, quiet scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--surface-4) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--surface-4);
  border: 3px solid transparent;
  border-radius: 99px;
  background-clip: content-box;
}
::-webkit-scrollbar-track { background: transparent; }

.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.mark { width: 14px; height: 14px; flex: none; fill: currentColor; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

kbd {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  opacity: 0.55;
}

/* ————————————————————————————— 3. components ————————————————————————————— */

/* —— buttons —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  user-select: none;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease),
    transform var(--dur-1) var(--ease), opacity var(--dur-2) var(--ease);
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:active:not(:disabled) { transform: scale(0.97); background: var(--surface-4); }
.btn:disabled { opacity: 0.38; cursor: default; }
.btn .icon { color: var(--text-2); transition: color var(--dur-1) var(--ease); }
.btn:hover:not(:disabled) .icon { color: var(--text); }
.btn[aria-expanded='true'] { background: var(--surface-4); }

.btn-quiet { background: transparent; color: var(--text-2); }
.btn-quiet:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-icon { width: 32px; padding: 0; }
.btn-lg { height: 44px; padding: 0 18px; border-radius: 12px; font-size: 15px; font-weight: 600; }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: #c6ff52; }
.btn-primary:active:not(:disabled) { background: #a8ee1c; }
.btn-primary .icon, .btn-primary:hover:not(:disabled) .icon { color: inherit; }

.linklike {
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--text-2);
  font-size: 12px;
  transition: color var(--dur-1) var(--ease);
}
.linklike:hover { color: var(--text); }

/* —— fields —— */
.field { display: block; min-width: 0; }
.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 18px;
  margin-bottom: 8px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
}

input[type='text'], input[type='password'], select, textarea {
  border: 0;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text);
  transition: background var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
input[type='text'], input[type='password'] { height: 30px; padding: 0 10px; }
input::placeholder, textarea::placeholder { color: var(--text-3); }
input[type='text']:focus-visible, input[type='password']:focus-visible,
select:focus-visible, textarea:focus-visible {
  box-shadow: 0 0 0 2px var(--accent-line);
}
select {
  height: 30px;
  padding: 0 26px 0 10px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='14' fill='none' stroke='%23a0a0a8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 5l3-3 3 3M2 9l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  cursor: pointer;
  text-overflow: ellipsis;
}
select:hover { background-color: var(--surface-3); }
select option { background: var(--surface-2); color: var(--text); }

/* —— segmented control —— */
.segmented {
  position: relative;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  padding: 2px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  isolation: isolate;
}
.segmented button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-height: 30px;
  padding: 6px 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  transition: color var(--dur-2) var(--ease), background var(--dur-1) var(--ease);
}
.segmented button small {
  max-width: 100%;
  overflow: hidden;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color var(--dur-2) var(--ease);
}
.segmented button:hover { color: var(--text); }
.segmented button.active { color: var(--text); }
.segmented button.active small { color: var(--text-2); }
/* without the sliding thumb (no script yet), the active button paints itself */
.segmented:not(.has-thumb) button.active { background: var(--surface-4); }
.segmented.has-thumb::before {
  content: '';
  position: absolute;
  z-index: -1;
  top: 2px;
  bottom: 2px;
  left: 2px;
  width: calc((100% - 4px) / var(--n, 1));
  border-radius: 8px;
  background: var(--surface-4);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35), inset 0 0.5px 0 rgba(255, 255, 255, 0.08);
  transform: translateX(calc(var(--i, 0) * 100%));
  transition: transform var(--dur-3) var(--ease);
}
.segmented .mark { margin-bottom: 1px; }

/* —— chips —— */
.chip, .genre-chips button {
  height: 28px;
  padding: 0 11px;
  border: 0;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease),
    transform var(--dur-1) var(--ease);
}
.chip:hover, .genre-chips button:hover { background: var(--surface-3); color: var(--text); }
.chip:active, .genre-chips button:active { transform: scale(0.96); }
.chip.active, .genre-chips button.active { background: var(--text); color: #0a0a0c; }

/* —— switch —— */
.switch { position: relative; display: inline-flex; flex: none; cursor: pointer; }
.switch input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.switch-track {
  width: 34px;
  height: 20px;
  border-radius: 99px;
  background: var(--surface-4);
  transition: background var(--dur-2) var(--ease);
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 99px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transition: transform var(--dur-2) var(--ease-spring);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(14px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--focus); }

/* —— range —— */
input[type='range'] {
  --fill: 0%;
  --fill-color: rgba(255, 255, 255, 0.7);
  width: 100%;
  height: 20px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}
input[type='range']::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--fill-color) var(--fill), var(--surface-4) var(--fill));
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border-radius: 99px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5), 0 0 0 0.5px rgba(0, 0, 0, 0.2);
  transition: transform var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
input[type='range']:active::-webkit-slider-thumb { transform: scale(1.12); }
input[type='range']::-moz-range-track { height: 4px; border-radius: 4px; background: var(--surface-4); }
input[type='range']::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--fill-color); }
input[type='range']::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 0;
  border-radius: 99px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}
input[type='range']:focus-visible { box-shadow: none; }
input[type='range']:focus-visible::-webkit-slider-thumb { box-shadow: var(--focus); }
input[type='range']:focus-visible::-moz-range-thumb { box-shadow: var(--focus); }

/* —— skeleton —— */
/* A placeholder shaped like content that is still being written. `.skel` is
   one bone. `.skel-sweep` is a layer that holds nothing but bones and passes
   one band of light over all of them, so a group shimmers as one surface.
   The layer is drawn on black and composited with `lighten`, which makes the
   black disappear: the band can only ever brighten a bone, never the surface
   between them. Draw panel backgrounds and borders outside the layer. */
.skel {
  display: block;
  flex: none;
  border-radius: 4px;
  background: var(--skel, var(--surface-3));
}
/* quieter by color, not opacity: a see-through bone would sink below the
   surface in a sweep layer */
.skel.dim { background: color-mix(in srgb, var(--skel, var(--surface-3)) 60%, var(--surface-0)); }
.skel-sweep { position: relative; overflow: hidden; }
@supports (mix-blend-mode: color-dodge) {
  .skel-sweep { background: #000; mix-blend-mode: lighten; }
  .skel-sweep::after {
    content: '';
    position: absolute;
    z-index: 3;
    inset: 0 -100%;
    background: linear-gradient(90deg, #000 44%, #6a6a6a 50%, #000 56%);
    mix-blend-mode: color-dodge;
    pointer-events: none;
    /* --skel-t is a negative delay off the page clock, so layers that
       appear at different moments still sweep together */
    animation: skel-sweep 2s cubic-bezier(0.45, 0, 0.55, 1) var(--skel-t, 0s) infinite;
  }
}
@keyframes skel-sweep {
  from { transform: translateX(-24%); }
  75%, to { transform: translateX(24%); }
}
@media (prefers-reduced-motion: reduce) {
  .skel-sweep::after { display: none; }
}

/* —— tooltips (pointer devices only) —— */
@media (hover: hover) {
  [data-tip] { position: relative; }
  [data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    z-index: 80;
    top: calc(100% + 8px);
    left: 50%;
    padding: 5px 8px;
    border-radius: 7px;
    background: var(--surface-4);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    color: var(--text);
    font-size: 11.5px;
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, -3px);
    transition: opacity var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
  }
  [data-tip]:hover::after, [data-tip]:focus-visible::after {
    opacity: 1;
    transform: translate(-50%, 0);
    transition-delay: 0.45s;
  }
  [data-tip][aria-expanded='true']::after { display: none; }
  [data-tip][data-tip-align='end']::after { left: auto; right: 0; transform: translate(0, -3px); }
  [data-tip][data-tip-align='end']:hover::after,
  [data-tip][data-tip-align='end']:focus-visible::after { transform: none; }
  [data-tip][data-tip-align='start']::after { left: 0; transform: translate(0, -3px); }
  [data-tip][data-tip-align='start']:hover::after,
  [data-tip][data-tip-align='start']:focus-visible::after { transform: none; }
}

/* ————————————————————————— 4. top bar + transport ————————————————————————— */

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 0 10px;
  z-index: 30;
}
.topbar-left, .topbar-right, .track-actions, .topbar-sys { display: flex; align-items: center; gap: 6px; min-width: 0; }
.topbar-right { justify-content: flex-end; }
.topbar-sys { gap: 2px; }
.topbar-sep { width: 1px; height: 18px; margin: 0 4px; background: var(--line-strong); }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 4px 4px;
  border-radius: var(--r-sm);
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.brand-mark { width: 20px; height: 20px; flex: none; }

/* the transport: one capsule that says what is loaded, where the playhead is,
   and whether it is live */
.transport {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  width: clamp(320px, 38vw, 540px);
  height: 40px;
  padding: 4px;
  border-radius: 99px;
  background: var(--surface-1);
  box-shadow: inset 0 0 0 1px var(--line);
}
.btn-play {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 99px;
  background: var(--accent);
  color: var(--accent-ink);
  transition: transform var(--dur-1) var(--ease), background var(--dur-2) var(--ease),
    color var(--dur-2) var(--ease), opacity var(--dur-2) var(--ease);
}
.btn-play:hover:not(:disabled) { background: #c6ff52; }
.btn-play:active:not(:disabled) { transform: scale(0.92); }
.btn-play:disabled { background: var(--surface-3); color: var(--text-3); cursor: default; }
.btn-play .icon { position: absolute; fill: currentColor; stroke: none; transition: opacity var(--dur-1) var(--ease), transform var(--dur-2) var(--ease); }
.btn-play .icon-play { transform: translateX(0.5px); }
.btn-play .icon-pause { opacity: 0; transform: scale(0.6); }
.btn-play.playing .icon-play { opacity: 0; transform: scale(0.6); }
.btn-play.playing .icon-pause { opacity: 1; transform: none; }
/* stop sits beside play, quiet: it ends playback and returns to the start */
.btn-stop {
  display: grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 99px;
  background: transparent;
  color: var(--text-2);
  transition: transform var(--dur-1) var(--ease), background var(--dur-1) var(--ease),
    color var(--dur-1) var(--ease), opacity var(--dur-2) var(--ease);
}
.btn-stop .icon { width: 14px; height: 14px; fill: currentColor; stroke: none; }
.btn-stop:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-stop:active:not(:disabled) { transform: scale(0.9); }
.btn-stop:disabled { color: var(--text-3); opacity: 0.45; cursor: default; }
/* one soft pulse when a new track is ready */
.btn-play.invite { animation: invite 1.1s var(--ease) 2; }
@keyframes invite {
  0% { box-shadow: 0 0 0 0 rgba(184, 255, 46, 0.5); }
  100% { box-shadow: 0 0 0 10px rgba(184, 255, 46, 0); }
}

.lcd { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding: 0 6px 0 4px; }
.lcd-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.005em;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-title { padding: 0 6px; color: var(--text-3); font-weight: 500; }
.transport.busy .player-title {
  background: linear-gradient(90deg, var(--text-3) 30%, var(--text) 50%, var(--text-3) 70%) 0 0 / 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: sheen 1.6s linear infinite;
}
@keyframes sheen { to { background-position: -200% 0; } }
/* samples for the next bars are still arriving */
.transport.loading .btn-play { animation: pulse 1s ease-in-out infinite; }
input.lcd-title {
  height: 26px;
  padding: 0 6px;
  border-radius: 6px;
  background: transparent;
}
input.lcd-title:hover { background: var(--surface-2); }
input.lcd-title:focus-visible { background: var(--surface-2); box-shadow: 0 0 0 2px var(--accent-line); }
.lcd-readouts { display: flex; align-items: center; gap: 10px; flex: none; }
.readout {
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.lcd-meter {
  flex: none;
  width: 46px;
  height: 18px;
  color: var(--text-3);
  transition: color var(--dur-3) var(--ease);
}
.transport:has(.btn-play.playing) .lcd-meter { color: var(--accent); }
.readout-time { display: inline-flex; flex: none; }
.readout-total { color: var(--text-3); white-space: pre; }

/* The scrubber: the song's length drawn along the capsule's bottom edge, with
   the played part filled in. Under the pointer it thickens and grows a knob.
   Neutral while paused, the accent while it plays. */
.scrub {
  position: absolute;
  z-index: 2;
  right: 20px;
  bottom: -6px;
  left: 20px;
  height: 12px;
  cursor: pointer;
  touch-action: none;
}
.scrub::before, .scrub-fill {
  position: absolute;
  bottom: 6px;
  left: 0;
  height: 2px;
  border-radius: 2px;
  transition: height var(--dur-1) var(--ease), background var(--dur-2) var(--ease);
}
.scrub::before { content: ''; right: 0; background: var(--line-strong); }
.scrub-fill { width: calc(var(--p, 0) * 100%); background: var(--text-3); }
.transport:has(.btn-play.playing) .scrub-fill { background: var(--accent); }
.scrub-knob {
  position: absolute;
  bottom: 2px;
  left: calc(var(--p, 0) * 100%);
  width: 10px;
  height: 10px;
  margin-left: -5px;
  border-radius: 99px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: scale(0.4);
  transition: opacity var(--dur-1) var(--ease), transform var(--dur-2) var(--ease-spring);
}
.transport:hover .scrub::before, .scrub:focus-visible::before, .scrub.dragging::before { background: rgba(255, 255, 255, 0.22); }
.scrub:hover::before, .scrub:hover .scrub-fill,
.scrub:focus-visible::before, .scrub:focus-visible .scrub-fill,
.scrub.dragging::before, .scrub.dragging .scrub-fill { height: 3px; }
.scrub:hover .scrub-knob, .scrub:focus-visible .scrub-knob, .scrub.dragging .scrub-knob { opacity: 1; transform: none; }
.scrub:focus-visible { box-shadow: none; }
.scrub:focus-visible .scrub-knob { box-shadow: var(--focus); }
.scrub.dragging { cursor: grabbing; }
/* the time under the pointer, in the same dress as a tooltip */
.scrub-tip {
  position: absolute;
  z-index: 80;
  top: calc(100% + 10px);
  left: 0;
  padding: 5px 8px;
  border-radius: 7px;
  background: var(--surface-4);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-50%);
}

/* apply edits: on stage while playing, lit when there is something to apply */
.btn-update {
  display: none;
  flex: none;
  height: 28px;
  padding: 0 11px;
  border-radius: 99px;
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}
.transport:has(.btn-play.playing) .btn-update { display: inline-flex; animation: pop-in var(--dur-3) var(--ease-spring); }
.btn-update.dirty { background: var(--accent-soft); color: var(--accent); }
.btn-update.dirty:hover:not(:disabled) { background: rgba(184, 255, 46, 0.2); }
@keyframes pop-in { from { opacity: 0; transform: scale(0.8); } }

.share-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 11px 0 9px;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 11.5px;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
  animation: pop-in var(--dur-3) var(--ease-spring);
}
.share-pill:hover { background: var(--surface-2); color: var(--text); }

.key-open { position: relative; }
.key-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 7px;
  height: 7px;
  border: 1.5px solid var(--bg);
  border-radius: 99px;
  background: var(--warn);
  box-sizing: content-box;
}
.has-key .key-dot { display: none; }

/* ————————————————————————— 5. shell, panels, library ————————————————————————— */

.shell {
  --rail-w: 0px;
  --rail-div: 0px;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--rail-w) var(--rail-div) var(--side-w, 360px) var(--gap) minmax(0, 1fr);
  padding: 0 var(--gap) var(--gap);
  transition: --rail-w var(--dur-3) var(--ease), --rail-div var(--dur-3) var(--ease);
}
.shell.rail-open { --rail-w: var(--rail-size, 248px); --rail-div: var(--gap); }
.resizing .shell { transition: none; }
.resizing { cursor: col-resize; user-select: none; }

.panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--r-lg);
  background: var(--surface-1);
  box-shadow: inset 0 0 0 1px var(--line);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: none;
  height: 44px;
  padding: 0 8px 0 16px;
}
.panel-title { font-size: 13px; font-weight: 600; }

/* the gutter between two panels is the resize handle */
.divider { position: relative; z-index: 2; touch-action: none; }
.divider-v { cursor: col-resize; }
.divider::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 3px;
  height: 32px;
  border-radius: 3px;
  background: var(--text-3);
  opacity: 0;
  transform: translate(-50%, -50%) scaleY(0.6);
  transition: opacity var(--dur-2) var(--ease), transform var(--dur-2) var(--ease), background var(--dur-2) var(--ease);
}
.divider:hover::after, .divider:focus-visible::after { opacity: 1; transform: translate(-50%, -50%); }
.divider.dragging::after { opacity: 1; background: var(--accent); transform: translate(-50%, -50%) scaleY(1.3); }
.divider:focus-visible { box-shadow: none; }
#divider-rail { pointer-events: none; }
.shell.rail-open #divider-rail { pointer-events: auto; }

/* —— library —— */
.rail {
  display: flex;
  flex-direction: column;
  visibility: hidden;
  opacity: 0;
  transition: opacity var(--dur-2) var(--ease), visibility 0s linear var(--dur-3);
}
.shell.rail-open .rail { visibility: visible; opacity: 1; transition-delay: 0s; }
.rail-body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 6px 12px; }
.rail-empty { padding: 28px 10px; color: var(--text-3); font-size: 12.5px; text-align: center; }
.rail-empty .linklike { color: var(--text); font-size: inherit; text-decoration: underline; text-underline-offset: 3px; }

.timeline { margin: 0; padding: 0; list-style: none; }
.tl-link {
  display: block;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  transition: background var(--dur-1) var(--ease);
  animation: rise var(--dur-3) var(--ease) backwards;
}
.tl-link:hover { background: var(--surface-2); }
.tl-link.current { background: var(--surface-3); }
.tl-title {
  display: block;
  overflow: hidden;
  font-size: 13px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tl-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
  color: var(--text-3);
  font-size: 11.5px;
}
.tl-meta .mark { width: 10px; height: 10px; margin-left: auto; order: 3; opacity: 0.8; }
.tl-genre::after { content: '·'; margin-left: 5px; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* ————————————————————————————— 6. composer ————————————————————————————— */

.sidebar { display: flex; flex-direction: column; }
.side-scroll {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 20px;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 16px 20px;
  scrollbar-gutter: stable both-edges;
}

.prompt-wrap { position: relative; }
#prompt {
  display: block;
  width: 100%;
  min-height: 116px;
  max-height: 42vh;
  padding: 12px 14px 20px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
}
.prompt-count {
  position: absolute;
  right: 12px;
  bottom: 6px;
  color: var(--text-3);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.genre-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.genre-family {
  flex-basis: 100%;
  margin-top: 8px;
  color: var(--text-3);
  font-size: 11px;
  letter-spacing: 0.02em;
}
.genre-family:first-child { margin-top: 0; }
.genre-more { margin-top: 10px; }

/* which provider and key the model picker will use */
.key-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  margin: -2px -6px -2px 0;
  padding: 0 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 500;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.key-status:hover { background: var(--surface-2); color: var(--text); }
.key-status .mark { width: 11px; height: 11px; }
.key-status.missing { color: var(--text-2); }

/* —— advanced —— */
.advanced { margin: 0 -8px; }
.advanced-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 34px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.advanced-toggle:hover { background: var(--surface-2); color: var(--text); }
.advanced-toggle .icon, .adv-group summary .icon {
  width: 12px;
  height: 12px;
  color: var(--text-3);
  transition: transform var(--dur-2) var(--ease);
}
.advanced-toggle[aria-expanded='true'] .icon { transform: rotate(90deg); }
.adv-count, .adv-group-count {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 99px;
  background: var(--text);
  color: #0a0a0c;
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.adv-count { margin-left: auto; }
.adv-body { padding: 4px 0 0; animation: reveal var(--dur-3) var(--ease); }
@keyframes reveal { from { opacity: 0; transform: translateY(-4px); } }
.adv-groups { display: flex; flex-direction: column; gap: 2px; }

.adv-group { border-radius: var(--r-md); transition: background var(--dur-2) var(--ease), opacity var(--dur-2) var(--ease); }
.adv-group[open] { background: var(--surface-0); box-shadow: inset 0 0 0 1px var(--line); margin: 4px 0; }
.adv-group summary {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 8px;
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  list-style: none;
  cursor: pointer;
  user-select: none;
  transition: background var(--dur-1) var(--ease);
}
.adv-group summary::-webkit-details-marker { display: none; }
.adv-group:not([open]) summary:hover { background: var(--surface-2); }
.adv-group[open] summary .icon { transform: rotate(90deg); }
.adv-group-count { background: var(--surface-4); color: var(--text); }
.adv-group-count:empty { display: none; }
.adv-group .group-note { margin-left: auto; color: var(--text-3); font-size: 11.5px; font-weight: 400; }
.adv-group.disabled { opacity: 0.4; }
.adv-group.disabled .adv-group-body { pointer-events: none; }
.adv-group-body { padding: 2px 12px 10px; }

.adv-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 2px 12px;
  min-height: 38px;
  padding: 4px 0;
  transition: opacity var(--dur-2) var(--ease);
}
.adv-control + .adv-control { border-top: 1px solid var(--line); }
.adv-control.off { opacity: 0.4; pointer-events: none; }
.adv-control-head { display: flex; align-items: center; gap: 4px; min-width: 0; }
.adv-control-head label { overflow: hidden; color: var(--text-2); text-overflow: ellipsis; white-space: nowrap; }
.adv-control.dirty .adv-control-head label { color: var(--text); }
.adv-value { color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.adv-control.dirty .adv-value { color: var(--text); }
.adv-control input[type='range'] { grid-column: 1 / -1; }
.adv-control:not(.dirty) input[type='range'] { --fill-color: transparent; }
.adv-control:not(.dirty) input[type='range']::-webkit-slider-thumb { background: var(--text-3); }
.adv-control:not(.dirty) input[type='range']::-moz-range-thumb { background: var(--text-3); }
.adv-control select { max-width: 170px; }
.adv-control input[type='text'] { width: 170px; }
.adv-control:not(.dirty) select { color: var(--text-2); }
/* reset one control to auto */
.dirty-dot {
  display: grid;
  place-items: center;
  flex: none;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-3);
  opacity: 0;
  transform: scale(0.6);
  pointer-events: none;
  transition: opacity var(--dur-2) var(--ease), transform var(--dur-2) var(--ease-spring),
    background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.dirty-dot .icon { width: 12px; height: 12px; }
.dirty-dot:hover { background: var(--surface-3); color: var(--text); }
.adv-control.dirty .dirty-dot { opacity: 1; transform: none; pointer-events: auto; }
.adv-reset { display: block; margin: 10px 8px 0 auto; }

/* —— generate dock —— */
.generate-dock {
  flex: none;
  /* same gutters as the scrolling fields above, so the edges line up */
  overflow: hidden;
  scrollbar-gutter: stable both-edges;
  padding: 12px 16px 12px;
  border-top: 1px solid var(--line);
  background: var(--surface-1);
}
#generate-btn { position: relative; width: 100%; overflow: hidden; }
#generate-btn kbd { position: absolute; right: 16px; }
#generate-btn.busy { background: var(--surface-3); color: var(--text); }
#generate-btn.busy kbd { display: none; }
@media (hover: none) { #generate-btn kbd { display: none; } }
#generate-btn.busy::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  width: 40%;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  animation: indeterminate 1.3s var(--ease) infinite;
}
@keyframes indeterminate {
  from { transform: translateX(-100%); }
  to { transform: translateX(250%); }
}
.gate-hint {
  min-height: 16px;
  margin-top: 8px;
  overflow: hidden;
  color: var(--text-3);
  font-size: 11.5px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gate-hint.needs-key { color: var(--warn); }

/* ————————————————————————————— 7. editor stage ————————————————————————————— */

.stage { display: flex; flex-direction: column; background: var(--surface-0); }
.player { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.editor-shell { position: relative; flex: 1; min-height: 0; overflow: hidden; }

/* generation progress along the top edge of the stage */
.is-generating .editor-shell::before {
  content: '';
  position: absolute;
  z-index: 6;
  top: 0;
  left: 0;
  width: 30%;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  animation: indeterminate 1.3s var(--ease) infinite;
}

.stream-preview {
  height: 100%;
  margin: 0;
  /* text starts where the editor's will, so the hand-off does not jump */
  padding: 18px 24px 40px 41px;
  overflow-y: auto;
  color: #d5d7de;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  tab-size: 2;
}
.stream-preview .tok-comment { color: var(--text-3); }
.stream-preview .tok-string { color: #c5e88a; }
.stream-preview .tok-number { color: #8cc8ff; }
.stream-caret {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 1px;
  border-radius: 1.5px;
  background: var(--accent);
  vertical-align: -2px;
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* the song still to come: bones laid out like source, under the line being
   written. the stream covers them a line at a time (see placeCodeSkeleton) */
.code-skel {
  position: absolute;
  z-index: 1;
  inset: 0;
  /* bones start where the text will, so nothing jumps when it lands */
  padding: 18px 24px 0 41px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  clip-path: inset(var(--skel-top, 0px) 0 0 0);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur-3) var(--ease), visibility 0s linear var(--dur-3);
}
.code-skel.on { opacity: 1; visibility: visible; transition-delay: 0s; }
.code-skel:not(.on)::after { animation: none; }
/* a long song runs past the fold: fade out instead of ending on a hard row */
.code-skel::before {
  content: '';
  position: absolute;
  z-index: 4;
  right: 0;
  bottom: 0;
  left: 0;
  height: 96px;
  background: linear-gradient(to bottom, transparent, #000);
}
.code-skel-row { display: flex; align-items: center; gap: 1ch; height: 1.7em; overflow: hidden; }
.code-skel-row.cont { padding-left: 2ch; }
.code-skel-row .skel { --skel: var(--surface-2); flex: 0 1 auto; min-width: 0; height: 0.62em; border-radius: 3px; }
.code-skel-row .skel.name { --skel: var(--surface-3); }

/* the live editor (CodeMirror, mounted by the engine) */
.editor-host { height: 100%; }
.editor-host > div { height: 100%; background: transparent !important; }
.editor-host .cm-editor { height: 100%; background: transparent !important; }
.editor-host .cm-editor.cm-focused { outline: none !important; }
.editor-host .cm-scroller { padding: 14px 0 40px; line-height: 1.7 !important; overflow: auto; }
.editor-host .cm-gutters {
  padding-left: 8px;
  border: 0 !important;
  background: transparent !important;
  color: var(--text-3) !important;
}
.editor-host .cm-lineNumbers .cm-gutterElement { min-width: 28px; padding: 0 10px 0 0 !important; }
.editor-host .cm-activeLine, .editor-host .cm-activeLineGutter { background: rgba(255, 255, 255, 0.035) !important; }
.editor-host .cm-activeLineGutter { color: var(--text-2) !important; }
.editor-host .cm-line { padding: 0 20px 0 6px !important; background: transparent !important; }
.editor-host .cm-cursor { border-left: 2px solid var(--accent) !important; }
.editor-host .cm-selectionBackground { background: rgba(184, 255, 46, 0.16) !important; }

.empty-stage {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  animation: fadein var(--dur-3) var(--ease);
}
.empty-mark { width: 44px; height: 44px; margin-bottom: 10px; opacity: 0.9; }
.empty-line { color: var(--text-3); font-family: var(--font-mono); font-size: 12.5px; }
.empty-sub { max-width: 340px; color: var(--text-2); font-size: 15px; line-height: 1.45; }
.empty-ideas {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  max-width: 520px;
  margin-top: 18px;
}
.empty-ideas .chip { height: 30px; background: var(--surface-1); box-shadow: inset 0 0 0 1px var(--line); }
.empty-ideas .chip:hover { background: var(--surface-2); }

.engine-veil {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 13, 15, 0.72);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  animation: fadein var(--dur-3) var(--ease);
}
.engine-veil-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 36px;
  padding: 0 16px 0 12px;
  border-radius: 99px;
  background: var(--surface-2);
  box-shadow: var(--shadow-pop);
  color: var(--text-2);
  font-size: 12.5px;
}
/* while code is streaming, the stream is the thing to watch; the engine loads behind it */
.is-generating .engine-veil:not(.retry) { display: none; }
.engine-veil.retry { cursor: pointer; }
.engine-veil.retry .engine-veil-inner { color: var(--text); }
.engine-veil.retry .spinner { border-color: var(--danger); animation: none; }
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--surface-4);
  border-top-color: var(--text);
  border-radius: 99px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadein { from { opacity: 0; } }

.statusline {
  display: flex;
  align-items: center;
  flex: none;
  gap: 8px;
  height: 30px;
  padding: 0 16px;
  border-top: 1px solid var(--line);
  color: var(--text-2);
  font-size: 12px;
}
.status-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-dot { flex: none; width: 6px; height: 6px; border-radius: 99px; transition: background var(--dur-2) var(--ease); }
.status-dot.idle { background: var(--text-3); }
.status-dot.busy { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.status-dot.play { background: var(--accent); }
.status-dot.error { background: var(--danger); }
.statusline:has(.status-dot.error) .status-text { color: var(--danger); }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ————————————————————————— 8. menus, dialogs, toast ————————————————————————— */

.menu-wrap, .dl-wrap { position: relative; }
.menu {
  position: absolute;
  z-index: 40;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  padding: 5px;
  border-radius: 12px;
  background: rgba(34, 34, 38, 0.82);
  -webkit-backdrop-filter: blur(28px) saturate(1.6);
  backdrop-filter: blur(28px) saturate(1.6);
  box-shadow: var(--shadow-pop);
  transform-origin: top right;
  animation: menu-in var(--dur-2) var(--ease);
}
@keyframes menu-in { from { opacity: 0; transform: scale(0.94) translateY(-4px); } }
.menu-item, .dl-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  white-space: nowrap;
  transition: background var(--dur-1) var(--ease);
}
.menu-item:hover:not(:disabled), .dl-item:hover:not(:disabled),
.menu-item:focus-visible, .dl-item:focus-visible { background: rgba(255, 255, 255, 0.09); box-shadow: none; }
.menu-item:disabled, .dl-item:disabled { opacity: 0.4; cursor: default; }
.menu-item .icon { color: var(--text-2); }
.menu-sep, .dl-sep { height: 1px; margin: 5px 10px; background: var(--line-strong); }

.dl-menu { width: 248px; }
.dl-ext { font-family: var(--font-mono); font-size: 12.5px; }
.dl-note { margin-left: auto; color: var(--text-3); font-size: 11.5px; }
.dl-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 36px; padding: 0 6px 0 10px; }
.dl-row-label { color: var(--text-2); font-size: 12px; }
#dl-seconds { height: 26px; background-color: rgba(255, 255, 255, 0.08); font-variant-numeric: tabular-nums; }
.dl-foot { padding: 8px 10px 6px; color: var(--text-3); font-size: 11.5px; line-height: 1.4; }
.dl-foot.working { color: var(--accent); font-variant-numeric: tabular-nums; }

/* —— sheets (native dialogs) —— */
dialog.sheet {
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 0;
  overflow: hidden auto;
  border: 0;
  border-radius: var(--r-xl);
  background: var(--surface-2);
  box-shadow: var(--shadow-pop), 0 40px 120px rgba(0, 0, 0, 0.5);
  color: var(--text);
}
dialog.sheet[open] { animation: sheet-in var(--dur-3) var(--ease); }
dialog.sheet::backdrop {
  background: rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fadein var(--dur-3) var(--ease);
}
dialog.sheet.closing { animation: sheet-out 0.16s ease-in forwards; }
dialog.sheet.closing::backdrop { animation: fadeout 0.16s ease-in forwards; }
@keyframes sheet-in { from { opacity: 0; transform: translateY(10px) scale(0.97); } }
@keyframes sheet-out { to { opacity: 0; transform: translateY(6px) scale(0.98); } }
@keyframes fadeout { to { opacity: 0; } }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 12px 4px 22px;
}
.sheet-title { font-size: 15px; font-weight: 600; }
.sheet-body { display: flex; flex-direction: column; gap: 14px; padding: 12px 22px 22px; }
.sheet-note { color: var(--text-2); font-size: 12.5px; line-height: 1.5; }
.sheet-note a { color: var(--text); text-decoration: underline; text-decoration-color: var(--text-3); text-underline-offset: 3px; }
.sheet-close { position: absolute; top: 12px; right: 12px; }

/* —— api key —— */
.key-sheet .segmented { background: var(--surface-1); }
.provider-toggle button { flex-direction: row; gap: 8px; min-height: 34px; }
.key-combo, .key-set {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 4px 0 12px;
  border-radius: var(--r-md);
  background: var(--surface-1);
  transition: box-shadow var(--dur-1) var(--ease);
}
.key-combo:focus-within { box-shadow: 0 0 0 2px var(--accent-line); }
.key-combo.invalid { box-shadow: 0 0 0 2px var(--danger); animation: shake 0.3s var(--ease); }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
#key-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 12.5px;
}
#key-input:focus-visible { box-shadow: none; }
.key-combo .btn, .key-set .btn { height: 32px; border-radius: 7px; }
.key-set code { flex: 1; min-width: 0; overflow: hidden; color: var(--text); font-family: var(--font-mono); font-size: 12.5px; text-overflow: ellipsis; white-space: nowrap; }
.key-set .icon { color: var(--accent); }
.key-error { min-height: 0; color: var(--danger); font-size: 12px; }
.key-error:empty { display: none; }
.plan-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 2px -22px -22px;
  padding: 12px 22px;
  border-top: 1px solid var(--line);
  background: var(--surface-1);
  color: var(--text-3);
  font-size: 12px;
}
.plan-active { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.plan-active::before { content: ''; width: 6px; height: 6px; border-radius: 99px; background: var(--accent); }
.plan-soon { margin-left: auto; }
.plan-soon em { margin-left: 4px; padding: 2px 7px; border-radius: 99px; background: var(--surface-3); color: var(--text-2); font-size: 11px; }

/* —— about —— */
dialog.about-card { width: min(680px, calc(100vw - 32px)); }
.about-inner { padding: 36px 36px 28px; }
.about-kicker { margin-bottom: 14px; color: var(--text-3); font-family: var(--font-mono); font-size: 12px; }
.about-card h2 {
  margin-bottom: 30px;
  font-size: clamp(26px, 4.4vw, 38px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.08;
}
.about-card h2 em { color: var(--accent); }
.about-cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; padding-bottom: 26px; }
.about-cols h3 { margin-bottom: 6px; font-size: 13px; font-weight: 600; }
.about-cols p { color: var(--text-2); font-size: 13px; line-height: 1.55; }
.about-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  padding: 16px 0;
  border-top: 1px solid var(--line);
  color: var(--text-2);
  font-size: 12px;
}
.about-keys kbd {
  display: inline-block;
  min-width: 22px;
  margin-right: 6px;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--text);
  opacity: 1;
  text-align: center;
}
.about-foot { padding-top: 16px; border-top: 1px solid var(--line); color: var(--text-3); font-size: 12px; line-height: 1.6; }
.about-foot a { color: var(--text-2); text-decoration: underline; text-decoration-color: var(--text-3); text-underline-offset: 3px; }
.about-foot a:hover { color: var(--text); }

/* —— toast —— */
.toast {
  position: fixed;
  z-index: 90;
  /* just under the transport, next to the actions that raise it */
  inset: calc(var(--topbar-h) + 8px) auto auto 50%;
  margin: 0;
  border: 0;
  color: var(--text);
  max-width: calc(100vw - 32px);
  padding: 9px 16px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(44, 44, 48, 0.86);
  -webkit-backdrop-filter: blur(24px) saturate(1.6);
  backdrop-filter: blur(24px) saturate(1.6);
  box-shadow: var(--shadow-pop);
  font-size: 13px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
  transform: translateX(-50%);
  animation: toast-in var(--dur-3) var(--ease-spring);
  transition: opacity var(--dur-3) var(--ease), transform var(--dur-3) var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(-10px) scale(0.96); } }
.toast.out { opacity: 0; transform: translateX(-50%) translateY(-6px); }

/* ————————————————————————— 9. small screens, motion ————————————————————————— */

.tabbar { display: none; }
.rail-scrim { display: none; }

/* tight desktop: labels give way before layout does */
@media (max-width: 1180px) {
  .track-actions .btn-label { display: none; }
  .track-actions .btn:not(.btn-icon) { width: 32px; padding: 0; }
  .share-pill span { display: none; }
  .share-pill { padding: 0 8px; }
  .transport { width: clamp(280px, 36vw, 440px); }
}
@media (max-width: 960px) {
  .lcd-meter { display: none; }
  .brand-name { display: none; }
}

/* a phone has room for the title or the tempo, not both */
@media (max-width: 480px) {
  .lcd-readouts { display: none; }
}

/* phone and narrow tablet: one panel at a time, transport on its own row */
@media (max-width: 760px) {
  :root { --topbar-h: 100px; --tabbar-h: 60px; }
  body { grid-template-rows: var(--topbar-h) minmax(0, 1fr) calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: 48px 44px;
    gap: 0 8px;
    padding: 0 8px 8px;
  }
  .topbar-right { display: contents; }
  .topbar-left { grid-area: 1 / 1; }
  .topbar-sys { grid-area: 1 / 2; justify-self: end; }
  .transport { grid-area: 2 / 1; width: auto; }
  .track-actions { grid-area: 2 / 2; gap: 4px; }
  .topbar-sep { display: none; }
  .brand-name { display: inline; }
  .lcd-readouts .readout-time { display: none; }
  .scrub { bottom: -8px; height: 16px; }
  .scrub::before, .scrub-fill { bottom: 8px; }
  .scrub-knob { bottom: 4px; }
  .btn, .btn-icon { height: 36px; }
  .btn-icon, .track-actions .btn:not(.btn-icon) { width: 36px; }
  .share-pill { height: 36px; }

  .shell { display: block; position: relative; padding: 0 8px; }
  .divider { display: none; }
  .sidebar, .stage { position: absolute; inset: 0 8px; }
  .shell[data-view='compose'] .stage,
  .shell[data-view='track'] .sidebar { visibility: hidden; opacity: 0; pointer-events: none; }
  .sidebar, .stage { transition: opacity var(--dur-2) var(--ease), visibility 0s; }

  /* the library becomes a drawer */
  .rail {
    position: fixed;
    z-index: 50;
    top: 8px;
    bottom: 8px;
    left: 8px;
    width: min(320px, calc(100vw - 56px));
    background: var(--surface-2);
    box-shadow: var(--shadow-pop);
    transform: translateX(calc(-100% - 16px));
    transition: transform var(--dur-3) var(--ease), opacity var(--dur-2) var(--ease), visibility 0s linear var(--dur-3);
  }
  .shell.rail-open .rail { transform: none; transition-delay: 0s; }
  .rail-scrim {
    display: block;
    position: fixed;
    z-index: 49;
    inset: 0;
    border: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-3) var(--ease);
  }
  .shell.rail-open ~ .rail-scrim { opacity: 1; pointer-events: auto; }

  .tabbar {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 8px 8px 0;
  }
  .tabbar .segmented { width: min(280px, 100%); border-radius: 99px; background: var(--surface-1); box-shadow: inset 0 0 0 1px var(--line); }
  .tabbar .segmented button { min-height: 40px; border-radius: 99px; font-size: 14px; }
  .tabbar .segmented.has-thumb::before { border-radius: 99px; }

  #prompt { font-size: 16px; } /* stops iOS zooming the page on focus */
  input[type='text'], input[type='password'], select { font-size: 16px; }
  input.lcd-title { font-size: 14px; }
  .adv-control select, .adv-control input[type='text'] { font-size: 14px; }
  .stream-preview { padding: 16px; font-size: 12.5px; }
  .code-skel { padding: 16px 16px 0; font-size: 12.5px; }

  .about-inner { padding: 28px 22px 22px; }
  .about-cols { grid-template-columns: 1fr; gap: 18px; }
  .about-keys { display: none; }
  dialog.sheet {
    width: 100%;
    max-width: none;
    margin: auto 0 0;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  dialog.sheet[open] { animation-name: sheet-up; }
  @keyframes sheet-up { from { transform: translateY(100%); } }
  dialog.sheet.closing { animation-name: sheet-down; }
  @keyframes sheet-down { to { transform: translateY(100%); } }
  .menu { position: fixed; top: calc(var(--topbar-h) + 4px); right: 8px; left: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
  }
}
