/* Composer: a quiet listening room. Brushed-aluminium paper and ink by day,
   walnut by night; the piano roll is a lit display window in both. Michroma is
   the faceplate legend voice (wordmark, panel titles, readouts); Hanken Grotesk
   carries everything you read and type. Amber is the lamp: used only for
   "live" things (playhead, playing state, busy lamp). */

/* Self-hosted (latin subset, SIL OFL 1.1, licences in /fonts/): no third-party
   request can block rendering, and no visitor IP goes to a font CDN. */
@font-face {
  font-family: "Hanken Grotesk";
  src: url("/fonts/hanken-grotesk-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Michroma";
  src: url("/fonts/michroma-latin.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #e6e5e0;
  --paper-deep: #dad8d1;
  --surface: #f3f2ee;
  --surface-sunk: #ebe9e4;
  --ink: #1d1c19;
  --ink-soft: #46433d;
  --muted: #5f5b53;
  --line: #c9c5bb;
  /* Boundaries that carry meaning (fader tracks, field outlines): ≥ 3:1. */
  --line-strong: #86817a;
  --line-soft: #d8d5cd;
  --key: #1d1c19;
  --key-ink: #f3f2ee;
  --lamp: #e49c22;
  --lamp-glow: rgba(228, 156, 34, 0.45);
  --focus: #2b66a8;
  --danger: #a3372b;
  --warn: #7f5200;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 1px 2px rgba(40, 34, 24, 0.08), 0 8px 24px -12px rgba(40, 34, 24, 0.22);

  /* Display window (piano roll) */
  --roll-bg: #1d2023;
  --roll-grid: rgba(255, 255, 255, 0.055);
  --roll-band: rgba(255, 255, 255, 0.035);
  --roll-section: rgba(255, 255, 255, 0.18);
  --roll-text: #ece6da;
  --roll-muted: rgba(236, 230, 218, 0.55);
  --roll-playhead: #f2b33d;

  /* Track colours: tuned to glow on the dark display in both themes */
  --track-lead: #f2b33d;
  --track-chords: #5fc4b0;
  --track-bass: #b48be6;
  --track-pad: #6f9be8;
  --track-arp: #f08c7a;
  --track-drums: #d8d2c6;

  --font-ui: "Hanken Grotesk", "Helvetica Neue", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-legend: "Michroma", "Eurostile", "Microgramma", "Bank Gothic", "Arial Black", var(--font-ui);

  --radius-deck: 22px;
  --radius-control: 10px;
  --gutter: clamp(16px, 4vw, 44px);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #16120f;
    --paper-deep: #100d0b;
    --surface: #211b16;
    --surface-sunk: #1a1511;
    --ink: #efe7da;
    --ink-soft: #cfc4b4;
    --muted: #a0958a;
    --line: #3d342b;
    --line-strong: #7a6d5f;
    --line-soft: #2e2720;
    --key: #efe7da;
    --key-ink: #1a1511;
    --lamp: #f2ad38;
    --lamp-glow: rgba(242, 173, 56, 0.5);
    --focus: #8cbcff;
    --danger: #f08c7a;
    --warn: #f2ad38;
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 10px 30px -14px rgba(0, 0, 0, 0.7);

    --roll-bg: #0e0c0a;
    --roll-grid: rgba(255, 240, 220, 0.05);
    --roll-band: rgba(255, 240, 220, 0.03);
    --roll-section: rgba(255, 240, 220, 0.16);

    color-scheme: dark;
  }
}

*,
*::before,
*::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.55 var(--font-ui);
  font-feature-settings: "ss01", "tnum" 0;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.2em; }
a:hover { text-decoration-thickness: 2px; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

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

.skip-link {
  position: absolute; left: 12px; top: -60px;
  padding: 8px 14px; border-radius: 8px;
  background: var(--key); color: var(--key-ink);
  z-index: 10; text-decoration: none;
}
.skip-link:focus { top: 12px; }

/* ------------------------------------------------------------------ layout */

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding-inline: var(--gutter);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 300px);
  grid-template-areas:
    "mast mast"
    "main aside"
    "foot foot";
  column-gap: clamp(32px, 4vw, 64px);
}

.masthead { grid-area: mast; }
.main { grid-area: main; min-width: 0; }
.history { grid-area: aside; min-width: 0; }
.footer { grid-area: foot; }

@media (max-width: 1040px) {
  .page {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "mast" "main" "aside" "foot";
  }
}

/* ---------------------------------------------------------------- masthead */

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-block: 22px 8px;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  font-family: var(--font-legend);
  font-size: 1rem;
  letter-spacing: 0.06em;
}
.wordmark-mark { width: 30px; height: 30px; flex: none; }
.mark-plate { fill: var(--roll-bg); }
.mark-note { fill: var(--roll-text); }
.mark-head { fill: var(--lamp); }

.masthead-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

/* -------------------------------------------------------------------- hero */

.hero { padding-block: clamp(28px, 6vw, 64px) 8px; }

.hero h1 {
  margin: 0 0 clamp(24px, 4vw, 36px);
  max-width: 17ch;
  font-weight: 500;
  font-size: clamp(2.1rem, 1.3rem + 3.6vw, 3.9rem);
  line-height: 1.04;
  letter-spacing: -0.028em;
  text-wrap: balance;
}

.cue {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-deck);
  box-shadow: var(--shadow);
  padding: 18px 18px 14px clamp(18px, 2.5vw, 26px);
  transition: border-color 160ms ease;
}
.cue:focus-within { border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus), var(--shadow); }

.cue-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--muted);
}

.cue textarea {
  display: block;
  width: 100%;
  min-height: 3.6em;
  margin: 6px 0 10px;
  padding: 0;
  border: 0;
  background: transparent;
  resize: vertical;
  font-size: clamp(1.15rem, 1rem + 0.7vw, 1.45rem);
  line-height: 1.4;
  letter-spacing: -0.01em;
}
.cue textarea::placeholder { color: var(--muted); opacity: 1; }
.cue textarea:focus-visible { outline: none; }

.cue-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 18px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}

.cue-length {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--muted);
}

.cue-hint {
  margin: 0;
  flex: 1 1 auto;
  color: var(--muted);
  font-size: 0.8125rem;
}

/* Native selects, restyled as small faceplate selectors */
select {
  appearance: none;
  -webkit-appearance: none;
  min-height: 36px;
  padding: 6px 34px 6px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23888' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center,
    var(--surface-sunk);
  color: var(--ink);
  font-size: 0.9375rem;
  font-weight: 500;
  max-width: 100%;
}
select:hover { border-color: var(--ink-soft); }

/* The Compose key: a physical, lit button */
.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-left: auto;
  /* Wide enough for "Composing…" so the relabel never reflows the bar. */
  min-width: 10.5em;
  min-height: 52px;
  padding: 0 26px 0 20px;
  border: 0;
  border-radius: 14px;
  background: var(--key);
  color: var(--key-ink);
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: 0.005em;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.18) inset, 0 3px 0 0 color-mix(in srgb, var(--key) 70%, #000), 0 8px 18px -8px rgba(0, 0, 0, 0.45);
  transition: transform 80ms ease, box-shadow 80ms ease;
}
.key:hover { background: color-mix(in srgb, var(--key) 90%, var(--lamp)); }
.key:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.18) inset, 0 1px 0 0 color-mix(in srgb, var(--key) 70%, #000), 0 4px 10px -6px rgba(0, 0, 0, 0.45);
}
.key:disabled { opacity: 0.92; }

.lamp {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--lamp) 45%, var(--key));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--key-ink) 12%, transparent);
  transition: background 200ms ease, box-shadow 200ms ease;
}
.key:hover .lamp,
.key:focus-visible .lamp { background: var(--lamp); }
.key[aria-busy="true"] .lamp {
  background: var(--lamp);
  box-shadow: 0 0 10px 2px var(--lamp-glow);
  animation: lamp 1.1s ease-in-out infinite;
}
@keyframes lamp { 50% { opacity: 0.35; box-shadow: 0 0 2px 0 var(--lamp-glow); } }

/* Example scenes */
.examples { margin-top: 26px; }
.examples-title {
  margin: 0 0 10px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--muted);
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.chip {
  min-height: 36px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-size: 0.9375rem;
  text-align: left;
  transition: background 120ms ease, border-color 120ms ease;
}
.chip:hover { background: var(--surface); border-color: var(--ink-soft); }

.status {
  min-height: 1.55em;
  margin: 18px 0 0;
  color: var(--ink-soft);
  font-size: 0.9375rem;
}
.status:empty { display: none; }
.status[data-tone="error"] { color: var(--danger); }
.status[data-tone="warn"] { color: var(--warn); }
#status:empty { display: block; }
.result-status { margin: -22px 0 26px; }

/* ------------------------------------------------------------------ result */

.result {
  margin-top: clamp(24px, 4vw, 40px);
  padding-top: clamp(24px, 4vw, 36px);
  border-top: 1px solid var(--line);
  scroll-margin-top: 16px;
}

.piece-head { margin-bottom: 18px; }

.piece-title {
  display: block;
  width: 100%;
  margin: 0 0 0 -8px;
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: transparent;
  font-size: clamp(1.6rem, 1.1rem + 2vw, 2.4rem);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.022em;
  text-overflow: ellipsis;
}
.piece-title:hover { border-color: var(--line); }
/* Touch screens have no hover: always hint that the title can be renamed. */
@media (hover: none) { .piece-title { border-color: var(--line); } }
.piece-title:focus { border-color: var(--ink-soft); background: var(--surface); outline: none; }
.piece-title:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.piece-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  margin-top: 10px;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.tags li {
  padding: 2px 10px;
  border-radius: 6px;
  background: var(--paper-deep);
  color: var(--ink-soft);
  font-size: 0.875rem;
  font-weight: 500;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 500;
}
.badge::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
}
.badge[data-source="llm"]::before { background: var(--track-chords); }

.piece-prompt {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 10px 0 0;
  max-width: 70ch;
  color: var(--muted);
  font-size: 0.9375rem;
}
.piece-prompt:empty { display: none; }

/* The deck: display window + transport */
.deck {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-deck);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.display {
  position: relative;
  border-radius: 14px;
  background: var(--roll-bg);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35) inset, 0 2px 10px rgba(0, 0, 0, 0.35) inset;
  overflow: hidden;
}
/* A faint glass reflection over the display */
.display::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background: linear-gradient(170deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0) 38%);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset;
}

.roll-scroll {
  height: clamp(220px, 30vw, 300px);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}
.roll-scroll:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.roll-scroll canvas {
  display: block;
  cursor: pointer;
}

.loading {
  position: absolute;
  inset: auto 16px 16px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(14, 12, 10, 0.78);
  color: var(--roll-text);
  font-size: 0.875rem;
  backdrop-filter: blur(6px);
}
.loading progress {
  flex: 1;
  height: 6px;
  appearance: none;
  border: 0;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
}
.loading progress::-webkit-progress-bar { background: rgba(255, 255, 255, 0.14); }
.loading progress::-webkit-progress-value { background: var(--roll-playhead); border-radius: 3px; }
.loading progress::-moz-progress-bar { background: var(--roll-playhead); border-radius: 3px; }

.transport {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 14px 8px 6px 4px;
}

.play {
  display: grid;
  place-items: center;
  width: 56px; height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--key);
  color: var(--key-ink);
  box-shadow: 0 3px 0 0 color-mix(in srgb, var(--key) 70%, #000), 0 8px 16px -8px rgba(0, 0, 0, 0.5);
  transition: transform 80ms ease, box-shadow 160ms ease;
}
.play:active { transform: translateY(2px); box-shadow: 0 1px 0 0 color-mix(in srgb, var(--key) 70%, #000); }
.play svg { width: 24px; height: 24px; fill: currentColor; stroke: currentColor; }
.play .icon-pause,
.play .icon-wait { display: none; }
.play[data-state="playing"] { box-shadow: 0 0 0 3px var(--lamp), 0 0 18px 2px var(--lamp-glow); }
.play[data-state="playing"] .icon-play { display: none; }
.play[data-state="playing"] .icon-pause { display: block; }
.play[data-state="loading"] .icon-play { display: none; }
.play[data-state="loading"] .icon-wait { display: block; fill: none; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Seek bar: section bands sit behind a transparent range input */
.seek {
  position: relative;
  height: 34px;
  --pct: 0%;
}
.seek-bands {
  position: absolute;
  inset: 9px 0;
  display: flex;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface-sunk);
  box-shadow: 0 0 0 1px var(--line-soft) inset;
}
.seek-band {
  position: relative;
  height: 100%;
  border-left: 1px solid var(--paper);
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 16px;
  padding-left: 5px;
  white-space: nowrap;
  text-overflow: clip;
  overflow: hidden;
}
/* Clear the thumb, which rests over the first label at 0:00. */
.seek-band:first-child { border-left: 0; padding-left: 11px; }
.seek-band:nth-child(even) { background: color-mix(in srgb, var(--line) 35%, transparent); }
.seek-bands::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--pct);
  background: color-mix(in srgb, var(--lamp) 30%, transparent);
  pointer-events: none;
}

.seek input[type="range"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  background: transparent;
}
.seek input[type="range"]::-webkit-slider-runnable-track { height: 34px; background: transparent; }
.seek input[type="range"]::-moz-range-track { height: 34px; background: transparent; }
.seek input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 6px; height: 30px;
  margin-top: 2px;
  border-radius: 3px;
  background: var(--lamp);
  box-shadow: 0 0 0 2px var(--surface), 0 0 10px var(--lamp-glow);
}
.seek input[type="range"]::-moz-range-thumb {
  width: 6px; height: 30px;
  border: 0;
  border-radius: 3px;
  background: var(--lamp);
  box-shadow: 0 0 0 2px var(--surface), 0 0 10px var(--lamp-glow);
}

.readout {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  min-width: 7.5em;
}
.time {
  font-family: var(--font-legend);
  font-size: 0.8125rem;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.loop-flag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}
.loop-flag svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------------------------------------- range faders */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}
.fader { width: 100%; height: 28px; margin: 0; }
.fader::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--ink-soft) var(--fill, 50%), var(--line-strong) var(--fill, 50%));
}
.fader::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line-strong); }
.fader::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--ink-soft); }
.fader::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 22px;
  margin-top: -9px;
  border-radius: 4px;
  background: linear-gradient(var(--surface), var(--surface)) center / 8px 2px no-repeat, var(--key);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}
.fader::-moz-range-thumb {
  width: 14px; height: 22px;
  border: 0;
  border-radius: 4px;
  background: linear-gradient(var(--surface), var(--surface)) center / 8px 2px no-repeat, var(--key);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}
.fader:disabled { opacity: 0.35; cursor: default; }
.fader:disabled::-webkit-slider-thumb { visibility: hidden; }
.fader:disabled::-moz-range-thumb { visibility: hidden; }

/* ----------------------------------------------------------------- actions */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 18px 0 36px;
}

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  font-size: 0.9375rem;
  font-weight: 600;
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset, 0 1px 2px rgba(0, 0, 0, 0.06);
  transition: border-color 120ms ease, background 120ms ease;
}
.btn:hover:not(:disabled) { border-color: var(--ink-soft); }
.btn:active:not(:disabled) { background: var(--surface-sunk); }
.btn:disabled { color: var(--muted); }
.btn-label { position: relative; }
.btn-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--p, 0) * 100%);
  background: color-mix(in srgb, var(--lamp) 32%, transparent);
  transition: width 120ms linear;
}

/* ------------------------------------------------------------------ panels */

.panel { margin-bottom: 28px; }

.panel-title {
  margin: 0 0 14px;
  font-family: var(--font-legend);
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

/* Mixer */
.mix-rows {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  overflow: hidden;
}
.mix-row {
  display: grid;
  grid-template-columns: 26px 5.5rem minmax(0, 13rem) minmax(0, 1fr) 4.2rem auto;
  grid-template-areas: "sw role inst vol out mute";
  align-items: center;
  gap: 8px 14px;
  padding: 10px 14px;
  border-top: 1px solid var(--line-soft);
}
.mix-row:first-child { border-top: 0; }
.mix-row[data-empty="true"] .mix-role,
.mix-row[data-empty="true"] .mix-out { color: var(--muted); }
.mix-row[data-muted="true"] .mix-swatch i { opacity: 0.2; }

.mix-swatch {
  grid-area: sw;
  display: grid;
  place-items: center;
  width: 26px; height: 18px;
  border-radius: 5px;
  background: var(--roll-bg);
}
.mix-swatch i {
  display: block;
  width: 14px; height: 4px;
  border-radius: 2px;
  background: var(--swatch);
  box-shadow: 0 0 6px var(--swatch);
}
.mix-row[data-empty="true"] .mix-swatch i { opacity: 0.25; box-shadow: none; }

.mix-role { grid-area: role; font-weight: 600; font-size: 0.9375rem; }
/* Recordings that could not load play a synth stand-in. */
.mix-row[data-fallback="true"] .mix-role::after {
  content: " · synth";
  font-weight: 400;
  color: var(--warn);
}
.mix-row select { grid-area: inst; width: 100%; min-height: 34px; font-size: 0.875rem; }
.mix-row .fader { grid-area: vol; }
.mix-out {
  grid-area: out;
  text-align: right;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  white-space: nowrap;
}

.mute {
  grid-area: mute;
  min-width: 64px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-sunk);
  font-size: 0.8125rem;
  font-weight: 600;
}
.mute:hover:not(:disabled) { border-color: var(--ink-soft); }
.mute[aria-pressed="true"] {
  background: var(--key);
  border-color: var(--key);
  color: var(--key-ink);
}
.mute:disabled { opacity: 0.4; }

/* Fine-tune */
.finetune {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}
.finetune summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 16px;
  margin: 0;
  padding: 16px 18px;
  cursor: pointer;
  list-style: none;
  border-radius: 16px;
}
.finetune summary::-webkit-details-marker { display: none; }
.finetune summary::before {
  content: "";
  align-self: center;
  width: 8px; height: 8px;
  border-right: 1.6px solid currentColor;
  border-bottom: 1.6px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 160ms ease;
}
.finetune[open] summary::before { transform: rotate(45deg); }
.summary-note {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  letter-spacing: 0;
  color: var(--muted);
}

.finetune-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 6px 28px;
  padding: 4px 18px 20px;
  border-top: 1px solid var(--line-soft);
}

.ft-group {
  margin: 0;
  padding: 14px 0 0;
  border: 0;
  min-width: 0;
}
.ft-group legend {
  padding: 14px 0 6px;
  font-size: 0.875rem;
  font-weight: 700;
}

.ft-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 2px 12px;
  padding: 6px 0;
}
.ft-field label { font-size: 0.875rem; color: var(--ink-soft); }
.ft-field select,
.ft-field input[type="number"] { grid-column: 1 / -1; width: 100%; }
.ft-field .fader { grid-column: 1 / -1; }
.ft-field output {
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

input[type="number"] {
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface-sunk);
  font-variant-numeric: tabular-nums;
}

/* ----------------------------------------------------------------- history */

.history {
  align-self: start;
  position: sticky;
  top: 20px;
  padding-top: clamp(28px, 6vw, 64px);
  max-height: 100vh;
  overflow-y: auto;
  scrollbar-width: thin;
}

.history-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}
.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  border-bottom: 1px solid var(--line);
}
.history-open {
  display: block;
  width: 100%;
  padding: 12px 4px 12px 10px;
  border: 0;
  border-left: 2px solid transparent;
  background: transparent;
  text-align: left;
}
.history-open:hover { background: color-mix(in srgb, var(--surface) 70%, transparent); }
.history-open[aria-current="true"] { border-left-color: var(--lamp); }
.history-title {
  display: block;
  font-weight: 600;
  font-size: 0.9375rem;
  line-height: 1.3;
}
.history-prompt {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.4;
}
.history-time {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.75rem;
}
.history-delete {
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  margin: 8px 0 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}
.history-delete:hover { color: var(--danger); background: var(--surface); }
.history-delete svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.history-empty {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

@media (max-width: 1040px) {
  .history {
    position: static;
    max-height: none;
    overflow: visible;
    padding-top: 12px;
  }
}

/* ------------------------------------------------------------------ footer */

.footer {
  margin-top: 48px;
  padding-block: 24px 40px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.8125rem;
}
.footer p { margin: 0 0 6px; max-width: 78ch; }

/* --------------------------------------------------------------- narrow */

@media (max-width: 640px) {
  .masthead-note { display: none; }
  .cue { padding: 14px 14px 12px 16px; border-radius: 18px; }
  .cue-hint { display: none; }
  /* The key always has its own row on phones, so its relabel never reflows. */
  .key { flex: 1 1 100%; }
  .cue-length { flex: 1 1 auto; }

  .transport {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "play readout" "seek seek";
    gap: 10px 14px;
  }
  .play { grid-area: play; }
  .seek { grid-area: seek; }
  .readout { grid-area: readout; align-items: flex-end; }

  .actions .btn { flex: 1 1 auto; }

  .mix-row {
    grid-template-columns: 26px minmax(0, 1fr) auto;
    grid-template-areas:
      "sw role mute"
      "inst inst inst"
      "vol vol out";
    gap: 8px 12px;
  }
  /* A role without a part: keep only the instrument picker. */
  .mix-row[data-empty="true"] {
    grid-template-columns: 26px 5.5rem minmax(0, 1fr);
    grid-template-areas: "sw role inst";
  }
  .mix-row[data-empty="true"] :is(.fader, .mix-out, .mute) { display: none; }

  /* After the piece is shown, messages float above the bottom edge so they
     are seen wherever the page is scrolled. */
  .result-status:not(:empty) {
    position: fixed;
    inset: auto 16px calc(16px + env(safe-area-inset-bottom, 0px)) 16px;
    z-index: 20;
    margin: 0;
    padding: 10px 14px;
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
