/* Tailwave: the page around the timeline canvas. Tokens match the converters. */

/* ---- Tokens ------------------------------------------------------------- */

:root {
  color-scheme: light;
  --bg: #eef0f6;
  --glow-1: rgba(8, 145, 178, 0.11);
  --glow-2: rgba(124, 58, 237, 0.1);
  --surface: #ffffff;
  --surface-2: #f5f6fa;
  --surface-3: #e5e8f0;
  --hover: rgba(15, 23, 42, 0.05);
  --press: rgba(15, 23, 42, 0.09);
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.15);
  --text: #0f172a;
  --text-2: #4f5a70;
  --text-3: #636978;
  --accent-a: #0891b2;
  --accent-b: #7c3aed;
  --accent-soft: rgba(124, 58, 237, 0.1);
  --on-accent: #ffffff;
  --focus: rgba(124, 58, 237, 0.5);
  --ok: #047b56;
  --warn: #a35905;
  --danger: #dc2626;
  --solo: #d97706;
  --mute: #e11d48;
  --meter-low: #059669;
  --meter-mid: #d97706;
  --meter-high: #dc2626;
  --shadow-1: 0 1px 2px rgba(15, 23, 42, 0.05), 0 6px 20px rgba(15, 23, 42, 0.05);
  --shadow-2: 0 2px 6px rgba(15, 23, 42, 0.08), 0 24px 48px rgba(15, 23, 42, 0.14);
  --pill: #ffffff;
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --top: 56px; /* the canvas's overview + ruler, beside the headers' top bar */
  --heads: 236px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0a0c11;
    --glow-1: rgba(34, 211, 238, 0.09);
    --glow-2: rgba(167, 139, 250, 0.12);
    --surface: #12151c;
    --surface-2: #171b24;
    --surface-3: #242a37;
    --hover: rgba(255, 255, 255, 0.05);
    --press: rgba(255, 255, 255, 0.09);
    --border: rgba(255, 255, 255, 0.07);
    --border-strong: rgba(255, 255, 255, 0.13);
    --text: #e9ecf3;
    --text-2: #a0a8bc;
    --text-3: #848b9c;
    --accent-a: #22d3ee;
    --accent-b: #a78bfa;
    --accent-soft: rgba(167, 139, 250, 0.14);
    --on-accent: #0a0c11;
    --focus: rgba(167, 139, 250, 0.6);
    --ok: #34d399;
    --warn: #fbbf24;
    --danger: #f87171;
    --solo: #fbbf24;
    --mute: #fb7185;
    --meter-low: #34d399;
    --meter-mid: #fbbf24;
    --meter-high: #f87171;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    --shadow-2: 0 2px 8px rgba(0, 0, 0, 0.4), 0 28px 56px rgba(0, 0, 0, 0.5);
    --pill: #262c3a;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0c11;
  --glow-1: rgba(34, 211, 238, 0.09);
  --glow-2: rgba(167, 139, 250, 0.12);
  --surface: #12151c;
  --surface-2: #171b24;
  --surface-3: #242a37;
  --hover: rgba(255, 255, 255, 0.05);
  --press: rgba(255, 255, 255, 0.09);
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.13);
  --text: #e9ecf3;
  --text-2: #a0a8bc;
  --text-3: #848b9c;
  --accent-a: #22d3ee;
  --accent-b: #a78bfa;
  --accent-soft: rgba(167, 139, 250, 0.14);
  --on-accent: #0a0c11;
  --focus: rgba(167, 139, 250, 0.6);
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --solo: #fbbf24;
  --mute: #fb7185;
  --meter-low: #34d399;
  --meter-mid: #fbbf24;
  --meter-high: #f87171;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  --shadow-2: 0 2px 8px rgba(0, 0, 0, 0.4), 0 28px 56px rgba(0, 0, 0, 0.5);
  --pill: #262c3a;
}

/* ---- Base --------------------------------------------------------------- */

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

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
}

body {
  color: var(--text);
  font: 13px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

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

input {
  user-select: text;
  -webkit-user-select: text;
}

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

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

svg.i {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- Layout ------------------------------------------------------------- */

.app {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* never wider than the window, whatever the bars hold */
  grid-template-rows: 44px 52px minmax(0, 1fr) 38px;
  height: 100vh;
  height: 100dvh;
}

.bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 10px 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 3;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  z-index: 2;
}

.workspace {
  display: grid;
  grid-template-columns: var(--heads) minmax(0, 1fr);
  min-height: 0;
}

.selbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  overflow: hidden;
}

.spacer {
  flex: 1;
}

/* ---- Brand and logo ----------------------------------------------------- */

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  letter-spacing: -0.01em;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 22px;
  padding: 0 4px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
}

.logo i {
  width: 2.5px;
  height: calc(var(--h, 10) * 1px * 0.62);
  border-radius: 2px;
  background: var(--on-accent);
  opacity: 0.92;
  transform-origin: center;
}

.logo i:nth-child(1) { --h: 10; animation-delay: -0.2s; }
.logo i:nth-child(2) { --h: 20; animation-delay: -0.5s; }
.logo i:nth-child(3) { --h: 14; animation-delay: -0.1s; }
.logo i:nth-child(4) { --h: 24; animation-delay: -0.7s; }
.logo i:nth-child(5) { --h: 12; animation-delay: -0.35s; }

.logo.big {
  height: 56px;
  gap: 5px;
  padding: 0 12px;
  border-radius: 18px;
  box-shadow: var(--shadow-2);
}

.logo.big i {
  width: 6px;
  height: calc(var(--h) * 1.5px);
  border-radius: 3px;
}

body.playing .bar .logo i,
.boot .logo i {
  animation: bounce 0.9s ease-in-out infinite alternate;
}

@keyframes bounce {
  from { transform: scaleY(0.45); }
  to { transform: scaleY(1); }
}

@media (prefers-reduced-motion: reduce) {
  body.playing .bar .logo i,
  .boot .logo i {
    animation: none;
  }
}

/* ---- Menus -------------------------------------------------------------- */

.menus {
  display: flex;
  gap: 2px;
  min-width: 0;
}

.menus button {
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text-2);
  cursor: pointer;
}

.menus button:hover,
.menus button[aria-expanded="true"] {
  background: var(--hover);
  color: var(--text);
}

.menu-pop {
  position: fixed;
  z-index: 50;
  min-width: 240px;
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  animation: pop 0.12s ease-out;
}

@keyframes pop {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: none;
  text-align: left;
  cursor: pointer;
}

.menu-item .mi-label {
  flex: 1;
  white-space: nowrap;
}

.menu-item .mi-key {
  color: var(--text-3);
  font-size: 12px;
  white-space: nowrap;
}

.menu-item .mi-check {
  width: 16px;
  color: var(--accent-b);
}

.menu-item:hover:not(:disabled),
.menu-item:focus-visible {
  background: var(--accent-soft);
  outline: none;
}

.menu-item:disabled {
  color: var(--text-3);
  cursor: default;
}

.menu-sep {
  height: 1px;
  margin: 5px 8px;
  background: var(--border);
}

.menu-head {
  padding: 6px 10px 2px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ---- Title -------------------------------------------------------------- */

.title {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
}

.title-input {
  min-width: 60px;
  max-width: 420px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  font-weight: 600;
  text-align: center;
  text-overflow: ellipsis;
}

.title-input:hover {
  border-color: var(--border);
}

.title-input:focus {
  border-color: var(--border-strong);
  background: var(--surface-2);
  outline: none;
}

.saved {
  color: var(--text-3);
  font-size: 12px;
  transition: opacity 0.3s;
}

.saved.saving {
  color: var(--text-2);
}

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

.chip {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chip:empty {
  display: none;
}

/* ---- Buttons ------------------------------------------------------------ */

.icon-btn,
.tool {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.icon-btn:hover:not(:disabled),
.tool:hover:not(:disabled) {
  background: var(--hover);
  color: var(--text);
}

.icon-btn:active:not(:disabled),
.tool:active:not(:disabled) {
  background: var(--press);
}

.tool:disabled {
  color: var(--text-3);
  opacity: 0.45;
  cursor: default;
}

.tool[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent-b);
}

.tool.play {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  color: var(--on-accent);
  box-shadow: var(--shadow-1);
}

.tool.play:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  color: var(--on-accent);
  filter: brightness(1.08);
}

.tool.play svg.i {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.tool.rec svg.i {
  fill: var(--mute);
  stroke: none;
}

.tool.rec.on {
  background: color-mix(in srgb, var(--mute) 18%, transparent);
  animation: rec-pulse 1.2s ease-in-out infinite;
}

@keyframes rec-pulse {
  50% { background: color-mix(in srgb, var(--mute) 32%, transparent); }
}

.speed select {
  height: 28px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: none;
  color: var(--text-2);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.speed select:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.speed.changed select {
  border-color: var(--accent-b);
  color: var(--accent-b);
}

.store-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--surface-3);
}

.store-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-a), var(--accent-b));
}

.tool.caret {
  width: 18px;
  margin-left: -4px;
}

.tool.caret svg.i {
  width: 12px;
  height: 12px;
}

body.recording .clock output {
  color: var(--mute);
}

body.recording .meter-bar .rms,
body.recording .meter-bar .peak {
  filter: hue-rotate(-20deg);
}

.group {
  display: flex;
  align-items: center;
  gap: 2px;
  padding-right: 10px;
  border-right: 1px solid var(--border);
}

.group:last-of-type {
  border-right: 0;
}

.sep {
  width: 1px;
  height: 18px;
  margin: 0 4px;
  background: var(--border);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, filter 0.12s, transform 0.08s;
}

.btn:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn.primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  color: var(--on-accent);
  box-shadow: var(--shadow-1);
}

.btn.primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  filter: brightness(1.08);
}

.btn.danger {
  border-color: transparent;
  background: var(--danger);
  color: #fff;
}

.btn.danger:hover:not(:disabled) {
  background: var(--danger);
  filter: brightness(1.08);
}

.btn.ghost {
  border-color: transparent;
  background: none;
  color: var(--text-2);
}

.btn.ghost:hover:not(:disabled) {
  background: var(--hover);
  color: var(--text);
}

.btn.small {
  height: 28px;
  padding: 0 9px;
  gap: 5px;
  font-size: 12px;
}

.btn.small svg.i {
  width: 15px;
  height: 15px;
}

.btn.big {
  height: 44px;
  padding: 0 20px;
  border-radius: 12px;
  font-size: 14px;
}

/* ---- Clock and meter ---------------------------------------------------- */

.clock {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 128px;
  height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  line-height: 1.1;
}

.clock output {
  font: 600 17px/1.1 var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.clock span {
  color: var(--text-3);
  font-size: 10.5px;
  letter-spacing: 0.02em;
}

body.playing .clock output {
  color: var(--accent-a);
}

.meter {
  display: grid;
  gap: 3px;
  width: 190px;
}

.meter-row {
  display: grid;
  grid-template-columns: 10px 1fr;
  align-items: center;
  gap: 5px;
  color: var(--text-3);
  font-size: 9px;
  font-weight: 600;
}

.meter-bar {
  position: relative;
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--surface-3);
}

.meter-bar i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
}

.meter-bar .peak {
  width: 100%;
  background: linear-gradient(90deg, var(--meter-low) 0 72%, var(--meter-mid) 72% 88%, var(--meter-high) 88%);
  opacity: 0.45;
  clip-path: inset(0 calc(100% - var(--p, 0%)) 0 0);
}

.meter-bar .rms {
  width: 100%;
  background: linear-gradient(90deg, var(--meter-low) 0 72%, var(--meter-mid) 72% 88%, var(--meter-high) 88%);
  clip-path: inset(0 calc(100% - var(--r, 0%)) 0 0);
}

.meter-bar .hold {
  left: var(--h, 0%);
  width: 2px;
  background: var(--text-2);
  opacity: var(--ho, 0);
}

.meter.clip .meter-bar .hold {
  background: var(--meter-high);
}

.volume {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-3);
}

.volume input {
  width: 84px;
}

/* ---- Range sliders ------------------------------------------------------ */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 18px;
  margin: 0;
  background: none;
  cursor: pointer;
  --fill: 50%;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent-b) var(--fill), var(--surface-3) var(--fill));
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  margin-top: -4.5px;
  border: 0;
  border-radius: 50%;
  background: var(--pill);
  box-shadow: 0 0 0 1px var(--border-strong), 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.1s;
}

input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.15);
}

input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--surface-3);
}

input[type="range"]::-moz-range-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--accent-b);
}

input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border: 0;
  border-radius: 50%;
  background: var(--pill);
  box-shadow: 0 0 0 1px var(--border-strong), 0 1px 3px rgba(0, 0, 0, 0.3);
}

input[type="range"].centered::-webkit-slider-runnable-track {
  background: linear-gradient(90deg, var(--surface-3) min(50%, var(--fill)), var(--accent-b) min(50%, var(--fill)),
    var(--accent-b) max(50%, var(--fill)), var(--surface-3) max(50%, var(--fill)));
}

input[type="range"].centered::-moz-range-progress {
  background: none;
}

/* ---- Track headers ------------------------------------------------------ */

.heads {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.heads-top {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 4px;
  height: var(--top);
  padding: 0 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.heads-list {
  position: absolute;
  inset: 0;
  clip-path: inset(var(--top) 0 0 0);
}

.head {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px 10px 8px 14px;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  cursor: default;
}

.head::before {
  content: "";
  position: absolute;
  inset: 6px auto 6px 0;
  width: 4px;
  border-radius: 0 3px 3px 0;
  background: var(--track);
  opacity: 0.85;
}

.head.selected {
  background: var(--surface-2);
}

.head.selected::before {
  opacity: 1;
  box-shadow: 0 0 10px var(--track);
}

.head.dragging {
  z-index: 2;
  box-shadow: var(--shadow-2);
  opacity: 0.96;
}

.head-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.head-name {
  flex: 1;
  min-width: 0;
  height: 24px;
  padding: 0 6px;
  margin-left: -6px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  font-weight: 600;
  text-overflow: ellipsis;
}

.head-name:hover {
  border-color: var(--border);
}

.head-name:focus {
  border-color: var(--border-strong);
  background: var(--surface);
  outline: none;
}

.head .icon-btn {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  color: var(--text-3);
}

.head .icon-btn svg.i {
  width: 15px;
  height: 15px;
}

.toggle {
  min-width: 26px;
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: none;
  color: var(--text-2);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.toggle:hover {
  background: var(--hover);
}

.toggle.mute[aria-pressed="true"] {
  border-color: transparent;
  background: var(--mute);
  color: #fff;
}

.toggle.solo[aria-pressed="true"] {
  border-color: transparent;
  background: var(--solo);
  color: #1a1206;
}

.head-meta {
  margin-left: auto;
  color: var(--text-3);
  font-size: 11px;
  white-space: nowrap;
}

.head-slider {
  display: grid;
  grid-template-columns: 30px 1fr 44px;
  align-items: center;
  gap: 6px;
  color: var(--text-3);
  font-size: 11px;
}

.head-slider output {
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.head-slider input {
  width: 100%;
}

.head.h-small .head-slider.pan,
.head.h-tiny .head-slider,
.head.h-tiny .head-meta {
  display: none;
}

.head.h-tiny {
  padding-top: 4px;
  gap: 2px;
}

.head-grip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -3px;
  height: 7px;
  cursor: ns-resize;
}

.heads-empty {
  position: absolute;
  top: calc(var(--top) + 18px);
  left: 14px;
  right: 14px;
  color: var(--text-3);
  font-size: 12px;
}

/* ---- Stage -------------------------------------------------------------- */

.stage {
  position: relative;
  min-width: 0;
  background: var(--bg);
}

#canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

/* ---- Labels ------------------------------------------------------------- */

.labels-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  clip-path: inset(var(--top) 0 0 0);
}

.label-chip {
  position: absolute;
  display: flex;
  align-items: center;
  max-width: 260px;
  height: 24px;
  padding: 0 9px 0 8px;
  border-radius: 0 7px 7px 0;
  background: color-mix(in srgb, var(--track) 22%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--track) 55%, transparent);
  border-left: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: auto;
  cursor: grab;
  user-select: none;
}

.label-chip:empty::before {
  content: "Untitled";
  color: var(--text-3);
  font-weight: 500;
}

.label-chip.selected {
  background: color-mix(in srgb, var(--track) 38%, var(--surface));
  border-color: var(--track);
}

.label-chip.dragging {
  cursor: grabbing;
  box-shadow: var(--shadow-1);
}

.label-chip input {
  width: 180px;
  height: 20px;
  padding: 0 4px;
  border: 0;
  border-radius: 4px;
  background: var(--surface);
  font: inherit;
  outline: 2px solid var(--focus);
}

.head.is-labels .head-slider,
.head.is-labels .toggle {
  display: none;
}

/* ---- Selection bar ------------------------------------------------------ */

.sel-field {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-3);
  font-size: 12px;
}

.time-input {
  width: 116px;
  height: 26px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-2);
  font: 12.5px var(--mono);
  font-variant-numeric: tabular-nums;
}

.time-input:focus {
  border-color: var(--accent-b);
  outline: none;
}

.time-input.bad {
  border-color: var(--danger);
}

.status {
  color: var(--text-3);
  font-size: 12px;
  white-space: nowrap;
}

.jobs {
  display: flex;
  gap: 10px;
}

.job {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  font-size: 12px;
  white-space: nowrap;
}

.job-bar {
  width: 90px;
  height: 4px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--surface-3);
}

.job-bar i {
  display: block;
  height: 100%;
  width: var(--p, 0%);
  background: linear-gradient(90deg, var(--accent-a), var(--accent-b), var(--accent-a));
  background-size: 200% 100%;
  transition: width 0.15s;
  animation: job-sheen 1.4s linear infinite;
}

/* Before the first progress report: a segment sliding along. */
.job.waiting .job-bar i {
  width: 30%;
  transition: none;
  animation: job-slide 1.1s ease-in-out infinite alternate;
}

.job-spin {
  width: 12px;
  height: 12px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--surface-3);
  border-top-color: var(--accent-a);
  border-right-color: var(--accent-b);
  animation: job-spin 0.8s linear infinite;
}

@keyframes job-sheen {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

@keyframes job-slide {
  from { transform: translateX(0); }
  to { transform: translateX(233%); }
}

@keyframes job-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .job-bar i,
  .job-spin {
    animation: none;
  }
}

.job .icon-btn {
  width: 22px;
  height: 22px;
}

.job .icon-btn svg.i {
  width: 13px;
  height: 13px;
}

/* ---- Segmented controls, fields, selects -------------------------------- */

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--surface-3);
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label {
  padding: 5px 12px;
  border-radius: 8px;
  color: var(--text-2);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}

.segmented label:hover {
  color: var(--text);
}

.segmented input:checked + label {
  background: var(--pill);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.segmented input:focus-visible + label {
  outline: 2px solid var(--focus);
}

.segmented input:disabled + label {
  opacity: 0.45;
  cursor: default;
}

.segmented.small {
  padding: 2px;
  border-radius: 8px;
}

.segmented.small label {
  padding: 2px 9px;
  border-radius: 6px;
  font-size: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
}

.field-row .field {
  flex: 1;
  min-width: 150px;
}

.label {
  display: flex;
  justify-content: space-between;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}

.label output {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.hint {
  margin: 0;
  color: var(--text-3);
  font-size: 13px;
}

.hint.small {
  font-size: 12px;
}

.select {
  position: relative;
}

.select::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 12px;
  width: 7px;
  height: 7px;
  margin-top: -5px;
  border-right: 1.6px solid var(--text-3);
  border-bottom: 1.6px solid var(--text-3);
  transform: rotate(45deg);
  pointer-events: none;
}

.select select {
  width: 100%;
  height: 34px;
  padding: 0 30px 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--surface);
  appearance: none;
  cursor: pointer;
}

.name-input {
  display: flex;
  align-items: center;
  height: 36px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--surface);
  overflow: hidden;
}

.name-input:focus-within {
  border-color: var(--accent-b);
}

.name-input input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 11px;
  border: 0;
  background: none;
  outline: none;
}

.name-input span {
  padding: 0 12px;
  color: var(--text-3);
  font-family: var(--mono);
}

/* ---- Export tags --------------------------------------------------------- */

.tags summary {
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.tag-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
  margin-top: 10px;
}

.tag-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--text-3);
  font-size: 11.5px;
}

.tag-grid input {
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
}

.tag-grid input:focus {
  border-color: var(--accent-b);
  outline: none;
}

/* ---- Effect dialog ------------------------------------------------------ */

.fx-fields {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.fx-range {
  display: grid;
  grid-template-columns: 1fr 92px;
  align-items: center;
  gap: 12px;
}

.num {
  display: flex;
  align-items: center;
  height: 32px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.num:focus-within {
  border-color: var(--accent-b);
}

.num input {
  width: 100%;
  min-width: 0;
  height: 100%;
  padding: 0 4px 0 9px;
  border: 0;
  background: none;
  font-variant-numeric: tabular-nums;
  outline: none;
  -moz-appearance: textfield;
}

.num input::-webkit-inner-spin-button {
  display: none;
}

.num span {
  padding-right: 9px;
  color: var(--text-3);
  font-size: 12px;
}

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
}

.check input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent-b);
}

.fx-presets {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.fx-presets .select {
  flex: 1;
}

.fx-presets .select select {
  height: 30px;
  font-size: 12.5px;
}

/* ---- Analysis ----------------------------------------------------------- */

.ana-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.ana-table th,
.ana-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
}

.ana-table th:first-child,
.ana-table td:first-child {
  text-align: left;
}

.ana-table th {
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ana-table td.warn {
  color: var(--warn);
  font-weight: 600;
}

.ana-plot {
  position: relative;
  height: 300px;
  border-radius: 12px;
  background: var(--surface-2);
}

.ana-plot canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.ana-readout {
  position: absolute;
  top: 10px;
  right: 12px;
  color: var(--text-2);
  font: 12px var(--mono);
}

/* ---- Start screen ------------------------------------------------------- */

.start {
  position: absolute;
  inset: 44px 0 0 0;
  z-index: 4;
  display: grid;
  overflow-y: auto;
  background: var(--bg);
}

.app:not([data-screen="start"]) .start {
  display: none;
}

.app[data-screen="start"] .menus button:not([data-menu="file"]):not([data-menu="help"]),
.app[data-screen="start"] .chip {
  display: none;
}

.app[data-screen="start"] .title {
  visibility: hidden;
}

.backdrop {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 520px at 8% -12%, var(--glow-1), transparent 62%),
    radial-gradient(820px 520px at 100% -6%, var(--glow-2), transparent 60%);
}

.start-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 40px;
  width: min(760px, 100% - 32px);
  margin: 0 auto;
  padding: 9vh 0 48px;
}

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.hero h1 {
  margin: 8px 0 0;
  font-size: 40px;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.hero p {
  max-width: 520px;
  margin: 0;
  color: var(--text-2);
  font-size: 15px;
}

.hero .hint {
  font-size: 13px;
  color: var(--text-3);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: 10px 0 2px;
}

.lost {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--warn) 9%, var(--surface));
  color: var(--text-2);
  font-size: 13px;
}

.lost p {
  margin: 0;
}

.lost-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.recent {
  width: 100%;
}

.recent h2 {
  margin: 0 0 10px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.recent-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.recent-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 12px 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  cursor: pointer;
  transition: border-color 0.12s, transform 0.12s;
}

.recent-item:hover,
.recent-item:focus-visible {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.recent-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-b);
}

.recent-text {
  flex: 1;
  min-width: 0;
}

.recent-text strong {
  display: block;
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-text span {
  color: var(--text-3);
  font-size: 12px;
}

/* ---- Boot, drop zone ---------------------------------------------------- */

.boot {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--bg);
  color: var(--text-2);
  transition: opacity 0.25s, visibility 0s;
}

.app:not([data-screen="boot"]) .boot {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s, visibility 0s 0.25s;
}

.boot.error p {
  max-width: 480px;
  color: var(--danger);
  text-align: center;
}

.dropzone {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(3px);
  animation: fade 0.12s ease-out;
}

@keyframes fade {
  from { opacity: 0; }
}

.dropzone-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 36px 56px;
  border: 2px dashed var(--accent-b);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  color: var(--text-2);
}

.dropzone-card strong {
  color: var(--text);
  font-size: 18px;
}

.dropzone-card svg.i {
  width: 30px;
  height: 30px;
  color: var(--accent-b);
}

/* ---- Dialogs ------------------------------------------------------------ */

.dialog {
  width: min(560px, 100vw - 32px);
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-2);
}

.dialog.wide {
  width: min(760px, 100vw - 32px);
}

.dialog[open] {
  animation: pop 0.16s ease-out;
}

.dialog::backdrop {
  background: rgba(5, 7, 12, 0.45);
  backdrop-filter: blur(2px);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 0 22px;
}

.dialog-head h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 22px 20px;
}

.dialog-body p {
  margin: 0;
  color: var(--text-2);
}

.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 18px 18px;
}

.keys {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 4px 28px;
}

.keys h3 {
  grid-column: 1 / -1;
  margin: 10px 0 2px;
  color: var(--text-3);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.keys h3:first-child {
  margin-top: 0;
}

.dialog-body .keys-hint {
  margin: 0 0 4px;
}

.dialog-body .keys-note {
  min-height: 18px;
  margin: 0 0 10px;
  color: var(--accent-b);
  font-size: 12.5px;
}

.key-keys {
  display: flex;
  align-items: center;
  gap: 4px;
}

.key-bind {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 26px;
  padding: 2px 6px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: none;
  color: var(--text-2);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.key-bind:hover,
.key-bind:focus-visible {
  border-color: var(--border-strong);
  background: var(--hover);
  outline: none;
}

.key-bind.changed kbd {
  border-color: var(--accent-b);
}

.key-bind.capturing {
  border-color: var(--accent-b);
  background: var(--accent-soft);
  color: var(--text);
}

.key-or {
  color: var(--text-3);
  font-size: 11px;
}

.key-reset {
  width: 26px;
  height: 26px;
}

.key-info {
  padding: 2px 7px;
}

.key-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
}

kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text);
  font: 11.5px var(--mono);
  text-align: center;
}

/* ---- Tooltip and toasts ------------------------------------------------- */

.tip {
  position: fixed;
  z-index: 60;
  max-width: 280px;
  padding: 5px 9px;
  border-radius: 7px;
  background: #0f172a;
  color: #e9ecf3;
  font-size: 12px;
  pointer-events: none;
  box-shadow: var(--shadow-1);
  animation: fade 0.1s ease-out;
}

.tip kbd {
  margin-left: 6px;
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #e9ecf3;
}

.toasts {
  position: fixed;
  right: 16px;
  bottom: 52px;
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 420px;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  pointer-events: auto;
  animation: toast-in 0.2s ease-out;
}

.toast.leaving {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s, transform 0.2s;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
}

.toast .dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--accent-a);
}

.toast.ok .dot { background: var(--ok); }
.toast.warn .dot { background: var(--warn); }
.toast.error .dot { background: var(--danger); }

.toast .link {
  border: 0;
  background: none;
  color: var(--accent-b);
  font-weight: 600;
  cursor: pointer;
}

/* ---- Narrow windows ----------------------------------------------------- */

@media (max-width: 1180px) {
  .meter { width: 120px; }
  .volume input { width: 64px; }
}

@media (max-width: 980px) {
  :root { --heads: 190px; }
  .menus button { padding: 0 7px; }
  .chip { display: none; }
  .group[aria-label="Zoom"],
  .volume { display: none; }
  .selbar .segmented { display: none; }
}

@media (max-width: 720px) {
  .brand b,
  .meter,
  .group[aria-label="History"] { display: none; }
  .time-input { width: 96px; }
  .sel-field:nth-child(3) { display: none; }
  /* The menus and the tools scroll sideways rather than leave the screen. */
  .menus,
  .toolbar {
    overflow-x: auto;
    scrollbar-width: none;
    touch-action: pan-x;
  }
  .menus::-webkit-scrollbar,
  .toolbar::-webkit-scrollbar { display: none; }
  .menus button,
  .toolbar > * { flex-shrink: 0; }
}

@media (max-width: 560px) {
  /* Phones: slim track headers (the sliders without their words and values,
     no remove button: it is in the track's menu), icon-only buttons above. */
  :root { --heads: 124px; }
  .head { padding: 6px 6px 6px 12px; }
  .head-slider { grid-template-columns: 1fr; }
  .head-slider span,
  .head-slider output,
  .head .head-meta,
  .head [data-act="remove"] { display: none; }
  .heads-top .btn { font-size: 0; gap: 0; }
  .bar .title { display: none; } /* the name is in the window title and on the start screen */
  .selbar { gap: 8px; padding: 0 8px; }
  .time-input { width: 84px; }
}

/* Touch screens: controls large enough for a finger, and the headers pan in
   script (the page itself does not scroll). */
#heads {
  touch-action: none;
}

@media (pointer: coarse) {
  .icon-btn,
  .tool {
    width: 40px;
    height: 40px;
  }

  .head .icon-btn {
    width: 34px;
    height: 34px;
  }

  .toggle {
    min-width: 34px;
    height: 30px;
  }

  .menus button,
  .menu-item {
    height: 40px;
  }

  .btn {
    height: 42px;
  }

  .segmented label {
    padding: 9px 14px;
  }
}

.crash-details {
  max-height: 200px;
  margin: 8px 0 0;
  padding: 10px 12px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-2);
  font: 11.5px/1.5 var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
}

.tips {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0 0 0 18px;
  color: var(--text-2);
  line-height: 1.55;
}

.tips li::marker {
  color: var(--accent-b);
}
