/* chirp web — an instrument panel: square working surfaces, mono-first type, the beat
   ruler as the recurring motif. Themes mirror `chirp watch` (ember, ice, paper). */

:root,
[data-theme="ember"] {
  --ground: #12110f;
  --panel: #1a1816;
  --raise: #24211e;
  --line: #302c29;
  --text: #ece6de;
  --dim: #8a827d;
  --faint: #3a3634;
  --beat: #4e4a50;
  --bar: #aaa096;
  --playhead: #4a4256;
  --accent: #ffc45c;
  --accent-ink: #1a1408;
  --ok: #78c878;
  --warn: #e8684a;
  --error: #ff5c5c;
  --pending: #5ab4dc;
  --sel: rgba(255, 196, 92, 0.18);
  --t0: #e8684a;
  --t1: #f0b446;
  --t2: #78c878;
  --t3: #5ab4dc;
  --t4: #aa82e6;
  --t5: #e678b4;
  --t6: #64d2be;
  --t7: #c8c86e;
  --t8: #96a0ff;
  --t9: #dc966e;
  color-scheme: dark;
}

[data-theme="ice"] {
  --ground: #0c121a;
  --panel: #111a24;
  --raise: #18232f;
  --line: #22303e;
  --text: #dcecf6;
  --dim: #6e8496;
  --faint: #24303c;
  --beat: #3c4e60;
  --bar: #96b6ce;
  --playhead: #2c4660;
  --accent: #78e6ff;
  --accent-ink: #061820;
  --ok: #78dca0;
  --warn: #ff9678;
  --error: #ff606e;
  --pending: #aaa0ff;
  --sel: rgba(120, 230, 255, 0.16);
  --t0: #6ec8ff;
  --t1: #8cf0d2;
  --t2: #aaa0ff;
  --t3: #5aa0e6;
  --t4: #c8e6ff;
  --t5: #78dca0;
  --t6: #e6aaff;
  --t7: #50d2dc;
  --t8: #b4c8f0;
  --t9: #96fff0;
  color-scheme: dark;
}

[data-theme="paper"] {
  --ground: #f2ede2;
  --panel: #ebe5d8;
  --raise: #e0d9c8;
  --line: #d6cfc0;
  --text: #26221e;
  --dim: #786e62;
  --faint: #d6cfc0;
  --beat: #c4bcac;
  --bar: #5a5248;
  --playhead: #ded4bc;
  --accent: #1e5caa;
  --accent-ink: #f2ede2;
  --ok: #34823f;
  --warn: #c46e14;
  --error: #c81e28;
  --pending: #964696;
  --sel: rgba(30, 92, 170, 0.14);
  --t0: #c44020;
  --t1: #2868aa;
  --t2: #348240;
  --t3: #964696;
  --t4: #be8214;
  --t5: #1e8282;
  --t6: #aa325a;
  --t7: #5a5ab4;
  --t8: #786e1e;
  --t9: #3c3c3c;
  color-scheme: light;
}

:root {
  --mono:
    ui-monospace, "JetBrains Mono", "SF Mono", "Cascadia Mono", Menlo, Consolas,
    monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --r: 2px;
  --deck: 48px;
  --fs: 13px;
  --lh: 19px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--ground);
  color: var(--text);
  font: var(--fs) / var(--lh) var(--mono);
  overflow: hidden;
}

body {
  display: grid;
  grid-template-rows: var(--deck) minmax(0, 1fr) var(
      --console-h,
      minmax(150px, 30vh)
    );
}

::selection {
  background: var(--sel);
}

* {
  scrollbar-color: var(--faint) transparent;
  scrollbar-width: thin;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

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

svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 0;
  flex: none;
}

svg use[href="#i-loop"],
svg use[href="#i-lib"],
svg use[href="#i-wav"],
svg use[href="#i-share"],
svg use[href="#i-sel"],
svg use[href="#i-up"],
svg use[href="#i-x"],
svg use[href="#i-conf"] {
  fill: none;
}

/* ── deck ─────────────────────────────────────────────── */

.deck {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.mark {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
}

.mark span {
  color: var(--accent);
  margin-left: 1px;
}

.transport {
  display: flex;
  gap: 2px;
}

.key {
  width: 34px;
  height: 30px;
  display: grid;
  place-items: center;
  background: var(--raise);
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--dim);
}

.key:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--beat);
}

.key:disabled {
  opacity: 0.4;
  cursor: default;
}

.key-play {
  color: var(--accent);
}

body.playing .key-play {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.toggle[aria-pressed="true"] {
  color: var(--accent);
  border-color: var(--beat);
}

.field {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.field span,
.label {
  font: 600 10px/1 var(--sans);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
}

select,
input[type="number"],
input[type="search"] {
  height: 26px;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 0 6px;
}

select {
  max-width: 190px;
}

/* The deck's one flexible control: the source picker gives way before anything overlaps. */
.source {
  flex: 0 1 auto;
  min-width: min-content;
}

.source select {
  flex: 0 1 190px;
  min-width: 84px;
}

.tempo,
.clock,
.meter,
.tools {
  flex: none;
}

select option,
select optgroup {
  background: var(--panel);
  color: var(--text);
}

.tempo input {
  width: 58px;
  font-variant-numeric: tabular-nums;
}

.clock {
  display: flex;
  align-items: center;
  gap: 8px;
}

.beats {
  display: flex;
  gap: 3px;
}

.beats i {
  width: 7px;
  height: 14px;
  background: var(--faint);
  border-radius: 1px;
}

.beats i.on {
  background: var(--accent);
}

.beats i.down {
  height: 18px;
}

.pos {
  min-width: 64px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.meter {
  display: flex;
  align-items: center;
  gap: 6px;
}

.meter canvas {
  width: 96px;
  height: 20px;
}

.xruns[hidden] {
  display: none;
}

.xruns {
  display: flex;
  align-items: baseline;
  gap: 3px;
  font-variant-numeric: tabular-nums;
}

.xruns output {
  color: var(--dim);
  min-width: 1ch;
  text-align: right;
}

.xruns i {
  font: 600 9px/1 var(--sans);
  font-style: normal;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
}

.lufs {
  display: flex;
  align-items: baseline;
  gap: 3px;
  min-width: 8.5ch;
  font-variant-numeric: tabular-nums;
}

.lufs output {
  color: var(--text);
  min-width: 5ch;
  text-align: right;
}

.lufs i {
  font: 600 9px/1 var(--sans);
  font-style: normal;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
}

.load output {
  color: inherit;
}

.load.warm {
  color: var(--text);
}

.load.hot {
  color: var(--warn);
}

.mic {
  font: 600 9px/1 var(--sans);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 3px 5px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--dim);
}

.mic.on {
  color: var(--accent);
  border-color: var(--accent);
}

.mic.bad {
  color: var(--error);
  border-color: var(--error);
}

.mic[hidden] {
  display: none;
}

.target {
  width: 64px;
  height: 26px;
  margin-right: 2px;
  font-variant-numeric: tabular-nums;
  color: var(--dim);
}

.xruns.bad output,
.xruns.bad i {
  color: var(--error);
}

.tools {
  display: flex;
  gap: 2px;
}

.icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r);
  color: var(--dim);
}

.icon:hover,
.icon[aria-expanded="true"] {
  color: var(--text);
  background: var(--raise);
  border-color: var(--line);
}

/* ── work area ─────────────────────────────────────────── */

.work {
  display: grid;
  grid-template-columns: minmax(320px, 42fr) minmax(0, 58fr);
  min-height: 0;
  position: relative;
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.editor-pane {
  border-right: 1px solid var(--line);
}

.bar {
  height: 32px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.grow {
  flex: 1;
}

.doc {
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lamp {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
  flex: none;
}

.editor[data-state="ok"] ~ * .lamp,
.lamp.ok {
  background: var(--ok);
}

.lamp.error {
  background: var(--error);
}

.chip {
  height: 24px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  background: var(--raise);
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--dim);
  white-space: nowrap;
}

.chip:hover {
  color: var(--text);
  border-color: var(--beat);
}

.tag {
  font-size: 11px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.tag.pending {
  color: var(--pending);
}

.bar .tag {
  flex: none;
  white-space: nowrap;
}

.cpu-toggle {
  height: 22px;
  padding: 0 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r);
  white-space: nowrap;
}

.cpu-toggle:hover {
  color: var(--text);
  border-color: var(--line);
}

.cpu-toggle[aria-pressed="true"],
.cpu-toggle[aria-pressed="true"]:hover {
  color: var(--accent);
}

.cpu-toggle output {
  color: inherit;
}

/* editor */

.doc-tabs {
  flex: none;
  display: flex;
  gap: 2px;
  padding: 3px 6px 0;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  scrollbar-width: thin;
}

.doc-tab {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: none;
  color: var(--dim);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.doc-tab:hover {
  color: var(--text);
}

.doc-tab.cur {
  color: var(--text);
  background: var(--ground);
  border-color: var(--line);
}

.doc-tab.other {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 4px;
}

.doc-tab .play {
  color: var(--accent);
}

.doc-tab small {
  color: var(--faint);
}

.doc-tab .x {
  color: var(--faint);
  font-style: normal;
  padding: 0 2px;
}

.doc-tab .x:hover {
  color: var(--error);
}

.editors {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
}

.editors.side {
  grid-template: minmax(0, 1fr) / minmax(0, 1fr) minmax(0, 1fr);
}

.editors.stack {
  grid-template: minmax(0, 1fr) minmax(0, 1fr) / minmax(0, 1fr);
}

.editors .second {
  border-left: 1px solid var(--line);
}

.editors.stack .second {
  border-left: none;
  border-top: 1px solid var(--line);
}

.editor {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  background: var(--ground);
}

.gutter {
  margin: 0;
  padding: 10px 8px 10px 10px;
  text-align: right;
  color: var(--faint);
  overflow: hidden;
  user-select: none;
  font: inherit;
  min-width: 40px;
  border-right: 1px solid var(--line);
}

.gutter .bad {
  color: var(--error);
  font-style: normal;
  font-weight: 700;
}

.text {
  position: relative;
  min-width: 0;
  min-height: 0;
}

.text .hl,
.text textarea {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 10px 12px 40px;
  font: inherit;
  white-space: pre;
  overflow: auto;
  tab-size: 2;
}

.text .hl {
  color: var(--text);
  pointer-events: none;
  overflow: hidden;
}

.text textarea {
  background: transparent;
  color: transparent;
  caret-color: var(--accent);
  border: 0;
  outline: none;
  resize: none;
}

.hl .yk {
  color: var(--bar);
  font-weight: 400;
}

.hl .yd {
  color: var(--accent);
  font-weight: 400;
}

.hl .yr {
  color: var(--pending);
  font-weight: 400;
}

.hl .yn {
  color: var(--t1);
  font-weight: 400;
}

.hl .yc {
  color: var(--dim);
  font-weight: 400;
  font-style: italic;
}

.note {
  position: absolute;
  left: 52px;
  right: 10px;
  bottom: 10px;
  text-align: left;
  padding: 6px 10px;
  background: var(--raise);
  border: 1px solid var(--error);
  border-left-width: 3px;
  border-radius: var(--r);
  color: var(--text);
  white-space: pre-wrap;
}

.note b {
  color: var(--error);
  margin-right: 6px;
}

/* live view: ribbons over lanes, the mix strip beside them, analysis and knobs below */

.lv {
  --mix: 236px;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) clamp(64px, 16vh, 120px);
}

.lv-head,
.lv-body {
  display: grid;
  grid-template-columns: var(--mix) minmax(0, 1fr);
}

.lv-head {
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.lv-keys {
  display: flex;
  flex-direction: column;
  padding: 0 10px;
  border-right: 1px solid var(--line);
  font: 600 9px/1 var(--sans);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
}

.lv-keys span {
  display: flex;
  align-items: center;
  height: 18px;
}

.lv-keys span:first-child {
  height: 16px;
}

.lv-keys .k-chords {
  height: 16px;
}

.lv-keys .k-energy {
  height: 20px;
}

.lv:not(.has-chords) .k-chords,
.lv:not(.has-energy) .k-energy {
  display: none;
}

.lv-strips {
  width: 100%;
  height: 34px;
  display: block;
}

.lv.has-chords .lv-strips {
  height: 50px;
}

.lv.has-energy .lv-strips {
  height: 54px;
}

.lv.has-chords.has-energy .lv-strips {
  height: 70px;
}

.lv-body {
  overflow-y: auto;
  overflow-x: hidden;
  align-content: start;
  position: relative;
}

.lv-lanes {
  width: 100%;
  display: block;
}

.lv-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--faint);
  font-size: 28px;
  pointer-events: none;
}

.lv-empty[hidden] {
  display: none;
}

.lv-mix {
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.strip {
  height: var(--row, 34px);
  display: grid;
  grid-template-columns: 4px minmax(0, 1fr) 24px 24px 40px;
  grid-template-rows: 1fr 4px;
  align-items: center;
  column-gap: 6px;
  padding: 3px 8px 3px 0;
}

.strip:nth-child(even) {
  background: var(--ground);
}

.strip .sw {
  grid-row: 1 / 3;
  align-self: stretch;
  background: var(--c, var(--dim));
}

.strip .nm {
  padding-left: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.strip.silenced .nm {
  opacity: 0.4;
}

/* Each lane's CPU share (render time ÷ real time this pass), shown with the cpu toggle. */
.strip .cpu {
  display: none;
  font-size: 10px;
  color: var(--dim);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* The strip widens for the shares rather than squeezing the names. */
.lv.show-cpu {
  --mix: 272px;
}

.lv.show-cpu .strip {
  grid-template-columns: 4px minmax(0, 1fr) 4.5ch 24px 24px 40px;
}

.lv.show-cpu .strip .cpu {
  display: block;
}

.strip .cpu.top {
  color: var(--text);
}

.strip .cpu.hot {
  color: var(--warn);
}

.strip .gain {
  height: 20px;
  line-height: 20px;
  text-align: right;
  font-size: 11px;
  color: var(--dim);
  cursor: ew-resize;
  user-select: none;
  font-variant-numeric: tabular-nums;
  border-radius: var(--r);
  touch-action: none;
}

.strip .gain:hover,
.strip .gain:focus-visible {
  color: var(--text);
  background: var(--raise);
}

.strip .lvl {
  grid-column: 2 / -1;
  position: relative;
  height: 3px;
  margin-left: 4px;
  background: var(--faint);
}

.strip .lvl i {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--c, var(--accent));
}

.strip .lvl b {
  position: absolute;
  top: -1px;
  bottom: -1px;
  width: 2px;
  background: var(--text);
}

.ms {
  height: 20px;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: var(--r);
  color: var(--dim);
  font-size: 11px;
  padding: 0;
}

.ms:disabled {
  opacity: 0.35;
  cursor: default;
}

.ms[aria-pressed="true"] {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.ms.solo[aria-pressed="true"] {
  background: var(--pending);
  border-color: var(--pending);
}

.lv-foot {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto;
  border-top: 1px solid var(--line);
  min-height: 0;
}

.lv-spectrum,
.lv-scope {
  width: 100%;
  height: 100%;
  display: block;
  min-height: 0;
}

.lv-scope {
  border-left: 1px solid var(--line);
}

.lv-knobs {
  display: flex;
  gap: 4px;
  padding: 6px 10px;
  border-left: 1px solid var(--line);
  overflow-x: auto;
  max-width: 340px;
  align-items: center;
}

.lv-knobs:empty {
  display: none;
}

.knob {
  width: 58px;
  flex: none;
  display: grid;
  justify-items: center;
  gap: 1px;
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
  border-radius: var(--r);
}

.knob.off {
  cursor: default;
  opacity: 0.55;
}

.knob svg {
  width: 36px;
  height: 36px;
}

.knob .trk {
  fill: var(--raise);
  stroke: var(--faint);
  stroke-width: 2;
}

.knob .arc {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
}

.knob .ptr {
  stroke: var(--text);
  stroke-width: 2;
  stroke-linecap: round;
}

.knob b {
  font: 600 9px/1.2 var(--sans);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
  max-width: 58px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.knob output {
  font-size: 11px;
  line-height: 1.2;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.zoom {
  display: flex;
  gap: 2px;
}

.icon.sm {
  width: 22px;
  height: 22px;
  font-size: 14px;
  line-height: 1;
}

/* library drawer */

.drawer {
  position: absolute;
  inset: 0 auto 0 0;
  width: min(440px, 100%);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  z-index: 5;
  box-shadow: 8px 0 24px rgba(0, 0, 0, 0.25);
}

.drawer[hidden] {
  display: none;
}

.drawer input[type="search"] {
  flex: 1;
  min-width: 0;
}

.groups {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}

.groups button {
  height: 22px;
  padding: 0 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r);
  color: var(--dim);
  font-size: 11px;
}

.groups button[aria-selected="true"] {
  color: var(--text);
  border-color: var(--line);
  background: var(--raise);
}

.groups button b {
  font-weight: 400;
  color: var(--faint);
  margin-left: 4px;
}

.items {
  list-style: none;
  margin: 0;
  padding: 4px 0;
  overflow: auto;
  flex: 1;
}

.items li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  padding: 5px 12px;
  cursor: pointer;
}

.items li:hover,
.items li[aria-selected="true"] {
  background: var(--raise);
}

.items .n {
  color: var(--text);
}

.items .n.user::after {
  content: " ●";
  color: var(--pending);
  font-size: 9px;
}

.items .a {
  grid-column: 1 / -1;
  color: var(--dim);
  font: 12px/16px var(--sans);
}

.items .rm {
  width: 22px;
  height: 22px;
  padding: 0;
}

/* console */

.console {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-top: 1px solid var(--line);
  background: var(--ground);
}

.tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 10px 0;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.tabs button {
  height: 24px;
  padding: 0 12px;
  background: transparent;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: var(--r) var(--r) 0 0;
  color: var(--dim);
  margin-bottom: -1px;
}

.tabs button[aria-selected="true"] {
  color: var(--text);
  background: var(--ground);
  border-color: var(--line);
}

.tabs .tag {
  margin-left: auto;
}

.agent {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.agent[hidden],
.log[hidden],
.prompt[hidden] {
  display: none;
}

.agent-head {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
}

.agent-head #agent-clear {
  margin-left: auto;
}

/* The composer sits at the bottom, like a chat; the conversation scrolls above it. */
.composer {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: flex-end;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
}

.composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 26px;
  max-height: 9.5em;
  resize: none;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 4px 8px;
  font: inherit;
  color: inherit;
  line-height: 1.4;
}

.composer .editing {
  flex-basis: 100%;
  color: var(--warn);
  font-size: 11px;
}

.composer .editing[hidden] {
  display: none;
}

.composer.is-editing textarea {
  border-color: var(--warn);
}

.key-run {
  color: var(--accent);
  border-color: var(--beat);
}

.agent.running .key-run {
  background: var(--accent);
  color: var(--accent-ink);
}

.agent-conf {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.agent-conf[hidden] {
  display: none;
}

.agent-conf label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.agent-conf input {
  height: 24px;
  width: 200px;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 0 6px;
}

.warn {
  color: var(--warn);
}

.agent-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
}

.thread {
  margin: 0;
  padding: 8px 12px;
  list-style: none;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.thread li.step {
  display: grid;
  grid-template-columns: 3ch 13ch minmax(0, 1fr);
  gap: 0 10px;
  padding: 1px 0;
  font-size: 12px;
}

.thread li.user {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-top: 10px;
  padding: 6px 10px;
  border-left: 2px solid var(--accent);
  background: var(--panel);
  border-radius: var(--r);
}

.thread li.user:first-child {
  margin-top: 0;
}

.thread li.user .msg,
.thread li.assistant {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.thread li.user .msg {
  flex: 1;
}

.thread li.user button {
  visibility: hidden;
  height: 20px;
  padding: 0 6px;
  font-size: 11px;
}

.thread li.user:hover button,
.thread li.user:focus-within button {
  visibility: visible;
}

.thread li.assistant {
  padding: 4px 10px 6px;
  color: var(--text);
}

.thread .n {
  color: var(--faint);
  text-align: right;
}

.thread .t {
  color: var(--accent);
}

.thread .a {
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread .o {
  grid-column: 3;
  color: var(--text);
}

.thread li.err .o {
  color: var(--error);
}

.thread li.err .t {
  color: var(--error);
}

.versions {
  margin: 0;
  padding: 6px 10px;
  list-style: none;
  overflow: auto;
  border-left: 1px solid var(--line);
}

.versions li {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 24px;
}

.versions li b {
  font-weight: 400;
  color: var(--faint);
  min-width: 3ch;
}

.versions li span {
  flex: 1;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.versions li.cur span {
  color: var(--text);
}

.versions button {
  height: 20px;
  padding: 0 6px;
  font-size: 11px;
}

.log {
  flex: 1;
  overflow: auto;
  padding: 8px 12px 4px;
  white-space: pre-wrap;
  word-break: break-word;
}

.log .cmd {
  color: var(--dim);
}

.log .cmd::before {
  content: "› ";
  color: var(--accent);
}

.log .err {
  color: var(--error);
}

.log .ok {
  color: var(--ok);
}

.log .muted {
  color: var(--dim);
}

.log .kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0 14px;
  margin: 2px 0 4px 2ch;
}

.log .kv b {
  font-weight: 400;
  color: var(--dim);
}

.log .cols {
  columns: 22ch auto;
  column-gap: 2ch;
  margin: 2px 0 4px 2ch;
}

.prompt {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.prompt label {
  color: var(--accent);
}

.prompt .line {
  position: relative;
  flex: 1;
  height: 100%;
}

.prompt input,
.prompt .ghost {
  position: absolute;
  inset: 0;
  border: 0;
  background: transparent;
  outline: none;
  padding: 0;
  line-height: 34px;
  white-space: pre;
}

.prompt .ghost {
  color: var(--faint);
  pointer-events: none;
}

/* narrow: stack the panes */

/* The deck needs about 1050 px on one row: below that it wraps rather than overlapping. */
@media (max-width: 1080px) {
  :root {
    --deck: auto;
  }
  .deck {
    flex-wrap: wrap;
    padding: 6px 10px;
    row-gap: 6px;
  }
}

@media (max-width: 900px) {
  :root {
    --deck: auto;
  }
  body {
    grid-template-rows: auto minmax(0, 1fr) var(
        --console-h,
        minmax(140px, 32vh)
      );
  }
  .deck {
    flex-wrap: wrap;
    padding: 6px 10px;
    row-gap: 6px;
  }
  .lv {
    --mix: 172px;
  }
  .lv.show-cpu {
    --mix: 224px;
  }
  .work {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }
  .editor-pane {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

.editor[hidden],
.doc-tabs[hidden] {
  display: none;
}

.fork {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--dim);
  font-size: 11px;
  margin-left: 6px;
}

/* Branch switchers stay visible (the edit chip shows on hover). */
.thread li.user .fork button {
  visibility: visible;
  height: 20px;
  padding: 0 5px;
}

.editing label {
  margin-left: 8px;
  color: var(--dim);
}

/* The editor folds to a strip with its expand button. */
.work.editor-collapsed {
  grid-template-columns: 30px minmax(0, 1fr);
}

.work.editor-collapsed .editor-pane > :not(.bar) {
  display: none;
}

.work.editor-collapsed .editor-pane .bar {
  flex-direction: column;
  height: auto;
  padding: 6px 0;
  border-bottom: none;
}

.work.editor-collapsed .editor-pane .bar > :not(#editor-collapse) {
  display: none;
}

.icon.collapse {
  width: 22px;
  height: 22px;
  font-size: 15px;
  line-height: 1;
}

.agent-summary {
  color: var(--dim);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-conf select {
  font: inherit;
}

/* /loop and /goal: what keeps the agent going. */
.agent-auto {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding: 4px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--text);
}

.agent-auto[hidden] {
  display: none;
}

.agent-auto .goal.done {
  color: var(--dim);
  text-decoration: line-through;
}

.agent-auto .auto-loop {
  color: var(--accent);
}

.agent-auto .auto-state {
  margin-left: auto;
  color: var(--faint);
}

/* Passing notes over the composer; they fade (click dismisses). */
.agent-toasts {
  position: relative;
  height: 0;
}

.agent-toasts .toast {
  position: absolute;
  bottom: 4px;
  left: 10px;
  right: 10px;
  z-index: 2;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--dim);
  font-size: 12px;
  white-space: pre-wrap;
  cursor: pointer;
  transition: opacity 0.5s;
}

.agent-toasts .toast.gone {
  opacity: 0;
}

/* Messages waiting for the end of the agent's turn. */
.agent-queue {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  padding: 4px 10px 0;
  font-size: 12px;
}

.agent-queue[hidden] {
  display: none;
}

.agent-queue .label {
  color: var(--faint);
}

.agent-queue .queued {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 4px 1px 8px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--text);
}

.agent-queue .x {
  border: none;
  background: none;
  color: var(--faint);
  cursor: pointer;
  padding: 0 2px;
}

.composer .stop[hidden] {
  display: none;
}

/* The console/agent panel's top edge: drag to resize. */
.resize-handle {
  position: absolute;
  top: -4px;
  left: 0;
  right: 0;
  height: 8px;
  cursor: ns-resize;
  z-index: 3;
}

.resize-handle:hover {
  background: color-mix(in srgb, var(--accent) 35%, transparent);
}

.agent-auto .x,
.agent-auto .chip {
  margin-left: 4px;
}

.agent-auto .x {
  border: none;
  background: none;
  color: var(--faint);
  cursor: pointer;
  padding: 0 2px;
}

.agent-auto .x:hover {
  color: var(--error);
}

/* The album playing: a track picker beside the title. */
.album-track {
  max-width: 22ch;
  margin-left: 8px;
  font: inherit;
  color: var(--text);
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: 4px;
}

.album-track[hidden] {
  display: none;
}

/* A deep link has an album ready: play waits for a press. */
.key-play.ready {
  box-shadow: 0 0 0 2px var(--accent);
  animation: ready-pulse 1.4s ease-in-out infinite;
}

@keyframes ready-pulse {
  50% {
    box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 35%, transparent);
  }
}

@media (prefers-reduced-motion: reduce) {
  .key-play.ready {
    animation: none;
  }
}

/* Album view: the album's pane takes the editor's place while it plays. */
.work.album-mode {
  grid-template-columns: minmax(260px, 30fr) minmax(0, 70fr);
}

.work.album-mode .editor-pane {
  display: none;
}

.album-pane[hidden] {
  display: none;
}

.album-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
}

.album-head {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 12px;
}

/* A pixel per cell, as a terminal would draw it. */
.album-art {
  width: min(45%, 192px);
  aspect-ratio: 1;
  image-rendering: pixelated;
  border: 1px solid var(--line);
  flex: none;
}

.album-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.album-info b {
  font-size: 1.1em;
  color: var(--text);
}

.album-info span,
.album-progress {
  color: var(--dim);
}

.album-tracks {
  list-style: none;
  margin: 0;
  padding: 0;
}

.album-tracks li {
  display: grid;
  grid-template-columns: 3ch minmax(0, 1fr) auto;
  gap: 8px;
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text);
}

.album-tracks li:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.album-tracks li .n {
  text-align: right;
  color: var(--faint);
}

.album-tracks li .s {
  color: var(--faint);
}

.album-tracks li.played {
  color: var(--dim);
}

.album-tracks li.playing {
  color: var(--accent);
  font-weight: 600;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}

.album-tracks li.playing .s {
  color: var(--accent);
}

.album-tracks li.next .s {
  color: var(--dim);
}

.album-play {
  align-self: flex-start;
  margin-top: 6px;
}

.album-play[hidden] {
  display: none;
}

.album-tracks li.start {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.album-tracks li.start .s {
  color: var(--accent);
}

/* Original audio: the popover under the deck. */
.orig-pop[hidden] {
  display: none;
}

.orig-pop {
  position: fixed;
  top: 48px;
  right: 12px;
  z-index: 40;
  width: min(360px, calc(100vw - 24px));
  padding: 12px 14px;
  background: var(--raise);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  display: grid;
  gap: 8px;
  font-size: 13px;
}

.orig-pop h3 {
  margin: 0;
  font-size: 13px;
  color: var(--dim);
  font-weight: 600;
}

.orig-server {
  display: flex;
  gap: 8px;
  align-items: center;
}

.orig-server span,
.orig-mix span {
  color: var(--dim);
  font-size: 12px;
}

.orig-server input {
  flex: 1;
  min-width: 0;
}

.orig-status {
  font-size: 12px;
  color: var(--dim);
}

.orig-status.ok {
  color: var(--ok);
}

.orig-status.err {
  color: var(--warn);
}

.orig-song {
  display: grid;
  gap: 6px;
}

.orig-kinds {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.orig-kinds button {
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.orig-kinds button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.orig-sep {
  align-self: center;
  margin: 0 2px 0 6px;
  color: var(--dim);
  font-size: 11.5px;
}

.orig-kinds button.busy {
  opacity: 0.6;
  cursor: progress;
}

.orig-kinds button:disabled {
  opacity: 0.4;
  cursor: default;
}

.orig-mix {
  display: flex;
  gap: 8px;
  align-items: center;
}

.orig-mix input {
  flex: 1;
}

.orig-note {
  margin: 0;
  font-size: 11.5px;
  color: var(--dim);
  line-height: 1.4;
}

#orig[aria-pressed="true"] svg {
  color: var(--accent);
}

/* The visual pane (visual.js): a look drawn above the lanes, scaled up crisply. */
.visual {
  display: block;
  width: 100%;
  height: 42vh;
  min-height: 160px;
  background: #000;
  image-rendering: auto;
  border-bottom: 1px solid var(--faint, #333);
}
.visual[hidden] {
  display: none;
}
.visual-look {
  max-width: 10em;
}
