:root {
  --bg: #15171c;
  --panel: #1d2027;
  --panel-2: #252932;
  --line: #333845;
  --text: #e6e8ee;
  --muted: #8b92a3;
  --accent: #4fa3ff;
  --rec: #ff4757;
  --solo: #f5c542;
  --mute: #ff9f43;
  --ok: #2ed573;
  --row-h: 64px;
  --ruler-h: 28px;
  --header-w: 330px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  font-size: 13px;
}

button, select, input { font: inherit; color: inherit; }
button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #0b1220; font-weight: 600; }
select { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; }
label { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }
.muted { color: var(--muted); }
.spacer { flex: 1; }

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 18px; letter-spacing: 0.5px; }
.brand span { color: var(--accent); }

.modes { display: flex; gap: 4px; background: var(--bg); padding: 3px; border-radius: 8px; }
.mode { border: none; background: transparent; padding: 6px 14px; }
.mode.active { background: var(--accent); color: #0b1220; font-weight: 600; }

.transport { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.transport button { width: 40px; height: 34px; font-size: 15px; padding: 0; }
.transport .rec { color: var(--rec); }
.transport .rec.on { background: var(--rec); color: #fff; animation: blink 1s infinite; }
.transport #btn-play.on { background: var(--ok); color: #0b1220; }
@keyframes blink { 50% { opacity: 0.6; } }
.clock {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 18px;
  background: #0c0d10;
  padding: 5px 12px;
  border-radius: 6px;
  min-width: 150px;
  text-align: center;
}

.setup, .toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}
.setup { background: var(--panel); }

.notice {
  padding: 8px 16px;
  background: #3a2d10;
  color: #ffd98a;
  border-bottom: 1px solid #5a4516;
}
.notice.error { background: #3a1418; color: #ffb3ba; border-color: #5a1e24; }

.tracks-area {
  flex: 1;
  display: flex;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}
.headers { width: var(--header-w); flex: none; border-right: 1px solid var(--line); background: var(--panel); }
.ruler-spacer {
  height: var(--ruler-h);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  color: var(--muted);
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}
.master-strip {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #0c0d10;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
}
.master-top { display: flex; align-items: center; gap: 8px; }
.master-label { font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.master-top input { flex: 1; min-width: 0; }
.master-meter { display: flex; align-items: center; gap: 8px; }
#master-meter { width: 260px; height: 34px; display: block; cursor: pointer; }
.master-db {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 34px;
  width: 40px;
  text-align: right;
  font: 11px ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--muted);
}
.master-db .clip { color: var(--rec); font-weight: 700; }

.track-header {
  height: var(--row-h);
  border-bottom: 1px solid var(--line);
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}
.track-header .row1, .track-header .row2 { display: flex; align-items: center; gap: 6px; }
.track-header .num { width: 20px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.track-header .name {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 6px;
}
.track-header button { padding: 2px 0; width: 26px; font-size: 11px; font-weight: 700; }
.track-header .arm.on { background: var(--rec); border-color: var(--rec); color: #fff; }
.track-header .mute.on { background: var(--mute); border-color: var(--mute); color: #111; }
.track-header .solo.on { background: var(--solo); border-color: var(--solo); color: #111; }
.track-header.no-input .name { opacity: 0.5; }
.track-header .meter { width: 128px; height: 12px; background: #0c0d10; border-radius: 2px; flex: none; cursor: pointer; }
.track-header .db {
  width: 36px;
  flex: none;
  text-align: right;
  font: 11px ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--muted);
  cursor: pointer;
}
.track-header .db.clip { color: var(--rec); font-weight: 700; }
.track-header .vol { width: 70px; min-width: 0; }
.track-header .pan { width: 50px; }

.timeline { flex: 1; overflow-x: auto; overflow-y: hidden; position: relative; min-width: 0; }
.timeline-content { position: relative; }
#timeline-canvas { position: sticky; left: 0; display: block; }

@media (max-width: 760px) {
  :root { --header-w: 230px; }
  .topbar { flex-wrap: wrap; gap: 10px; }
  .master-strip { width: 100%; }
  #master-meter { width: auto; flex: 1; min-width: 0; }
  .track-header .meter { width: 70px; }
  .track-header .pan { display: none; }
}

/* ---------- Live mode ---------- */
[hidden] { display: none !important; }
.live-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.live-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}
.go-live { font-weight: 700; padding: 6px 16px; }
.go-live.on { background: var(--rec); border-color: var(--rec); color: #fff; }
label.check { cursor: pointer; }
.console {
  flex: 1;
  display: flex;
  gap: 4px;
  padding: 10px 16px;
  overflow: auto;
  min-height: 0;
}
.strip {
  flex: none;
  width: 92px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.strip.no-input { opacity: 0.5; }
.strip-head { display: flex; gap: 4px; align-items: baseline; min-width: 0; }
.strip-num { color: var(--muted); font-size: 11px; }
.strip-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.knob { display: flex; flex-direction: column; gap: 1px; }
.knob-top { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); }
.knob-top output { font-variant-numeric: tabular-nums; color: var(--text); }
.knob input { width: 100%; margin: 0; }
.strip button { padding: 3px 0; font-size: 11px; font-weight: 700; }
.fader-area { display: flex; justify-content: center; gap: 2px; flex: 1; min-height: 160px; max-height: 420px; }
.vmeter { width: 10px; height: 100%; border-radius: 2px; }
.fader-scale { width: 22px; height: 100%; }

/* Console-style faders: a dark slot with a metal cap. */
.fader {
  -webkit-appearance: none;
  appearance: none;
  writing-mode: vertical-lr;
  direction: rtl;
  height: 100%;
  width: 32px;
  margin: 0;
  background: transparent;
  cursor: ns-resize;
}
.fader::-webkit-slider-runnable-track {
  width: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, #050608, #1a1d23 50%, #050608);
  box-shadow: inset 0 0 2px #000, 0 0 0 1px #2a2e37;
}
.fader::-moz-range-track {
  width: 6px;
  border-radius: 3px;
  background: #0a0b0e;
  box-shadow: 0 0 0 1px #2a2e37;
}
.fader::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 30px;
  height: 46px;
  margin-left: -12px;
  border-radius: 4px;
  border: 1px solid #0b0c0f;
  background:
    linear-gradient(#e9ecf2, #e9ecf2) center / 100% 2px no-repeat,
    repeating-linear-gradient(180deg, rgba(0,0,0,0.0) 0 3px, rgba(0,0,0,0.18) 3px 4px),
    linear-gradient(180deg, #8d939e 0%, #d4d8df 18%, #6f7580 50%, #c3c8d0 82%, #7b818c 100%);
  box-shadow: 0 3px 6px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.5);
}
.fader::-moz-range-thumb {
  width: 30px;
  height: 46px;
  border-radius: 4px;
  border: 1px solid #0b0c0f;
  background:
    linear-gradient(#e9ecf2, #e9ecf2) center / 100% 2px no-repeat,
    linear-gradient(180deg, #8d939e 0%, #d4d8df 18%, #6f7580 50%, #c3c8d0 82%, #7b818c 100%);
  box-shadow: 0 3px 6px rgba(0,0,0,0.6);
}
.fader:focus-visible { outline: none; }
.fader:focus-visible::-webkit-slider-thumb { border-color: var(--accent); }

/* Horizontal versions for track volume and master. */
.hfader {
  -webkit-appearance: none;
  appearance: none;
  height: 22px;
  background: transparent;
  cursor: ew-resize;
}
.hfader::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 3px;
  background: linear-gradient(180deg, #050608, #1a1d23 50%, #050608);
  box-shadow: inset 0 0 2px #000, 0 0 0 1px #2a2e37;
}
.hfader::-moz-range-track { height: 5px; border-radius: 3px; background: #0a0b0e; }
.hfader::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 20px;
  margin-top: -8px;
  border-radius: 3px;
  border: 1px solid #0b0c0f;
  background:
    linear-gradient(#e9ecf2, #e9ecf2) center / 2px 100% no-repeat,
    linear-gradient(90deg, #8d939e 0%, #d4d8df 20%, #6f7580 50%, #c3c8d0 80%, #7b818c 100%);
  box-shadow: 0 2px 4px rgba(0,0,0,0.6);
}
.hfader::-moz-range-thumb {
  width: 14px;
  height: 20px;
  border-radius: 3px;
  border: 1px solid #0b0c0f;
  background: linear-gradient(90deg, #8d939e 0%, #d4d8df 20%, #6f7580 50%, #c3c8d0 80%, #7b818c 100%);
}
.fader-db { text-align: center; font: 11px ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.strip-btns { display: flex; gap: 4px; }
.strip-btns button { flex: 1; }
.strip .mute.on { background: var(--mute); border-color: var(--mute); color: #111; }
.strip .solo.on { background: var(--solo); border-color: var(--solo); color: #111; }

/* plugin inserts */
.live-view { position: relative; }
.inserts { display: flex; flex-direction: column; gap: 3px; min-height: 128px; }
.insert-list { display: flex; flex-direction: column; gap: 3px; }
.insert {
  background: #23344f;
  border-color: #35507a;
  font-size: 11px;
  text-align: left;
  padding: 3px 6px !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.insert.bypassed { background: var(--panel-2); border-color: var(--line); color: var(--muted); text-decoration: line-through; }
.insert.editing { outline: 2px solid var(--accent); }
.add-plugin { font-size: 11px; padding: 3px 4px; width: 100%; color: var(--muted); }
.plugin-panel {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 320px;
  max-width: calc(100% - 32px);
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 5;
}
.pp-head { display: flex; align-items: center; gap: 8px; }
.pp-head strong { flex: 1; }
.pp-head button { padding: 2px 8px; }
.pp-params { display: flex; flex-direction: column; gap: 8px; }
.pp-param { display: grid; grid-template-columns: 110px 1fr 70px; align-items: center; gap: 8px; font-size: 12px; }
.pp-param span { color: var(--muted); }
.pp-param output { text-align: right; font-variant-numeric: tabular-nums; }
.pp-param input { width: 100%; }
.pp-actions { display: flex; gap: 6px; }
#pp-bypass.on { background: var(--mute); border-color: var(--mute); color: #111; }

/* Third-party (Web Audio Module) plugin editors bring their own interface. */
.plugin-panel.wide { width: auto; min-width: 320px; max-height: calc(100% - 32px); }
.pp-gui { overflow: auto; max-width: calc(100vw - 64px); max-height: 65vh; background: #000; border-radius: 6px; }
.pp-msg { margin: 0; font-size: 12px; }
