:root {
  --bg: #f4f4f1;
  --surface: #ffffff;
  --line: #e2e1dc;
  --text: #17181b;
  --muted: #6c6d72;
  --faint: #b9b8b2;
  --accent: #3b6ff5;
  --accent-soft: #3b6ff522;
  --shadow: 0 1px 2px #0000000d, 0 8px 30px #0000000a;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0d0e11;
  --surface: #16171b;
  --line: #26282e;
  --text: #ecedf0;
  --muted: #8e919a;
  --faint: #3a3d45;
  --accent: #6d95ff;
  --accent-soft: #6d95ff26;
  --shadow: 0 1px 2px #00000066, 0 10px 40px #00000059;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0e11;
    --surface: #16171b;
    --line: #26282e;
    --text: #ecedf0;
    --muted: #8e919a;
    --faint: #3a3d45;
    --accent: #6d95ff;
    --accent-soft: #6d95ff26;
    --shadow: 0 1px 2px #00000066, 0 10px 40px #00000059;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.4; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 24px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.mark {
  flex: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: conic-gradient(from 200deg, var(--accent), #20c997, #f5b301, #e56bb2, var(--accent));
}
.picker { position: relative; margin-left: auto; flex: 0 1 300px; min-width: 0; }
.picker-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 40px;
  padding: 0 14px 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-weight: 500;
  text-align: left;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.picker-button:hover:not(:disabled), .picker-button[aria-expanded="true"] { border-color: var(--faint); }
.picker-button[aria-expanded="true"] { box-shadow: 0 0 0 3px var(--accent-soft); }
.picker-button .mark { flex: none; width: 10px; height: 10px; }
#song-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chevron {
  flex: none;
  width: 12px;
  height: 12px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.15s;
}
.picker-button[aria-expanded="true"] .chevron { transform: rotate(180deg); }
.picker-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 10;
  margin: 0;
  padding: 6px;
  list-style: none;
  max-height: min(360px, 70vh);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow), 0 16px 40px #0000001f;
}
.picker-menu li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  cursor: pointer;
  outline: none;
}
.picker-menu li span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-menu li:hover, .picker-menu li:focus-visible { background: var(--bg); }
.picker-menu li[aria-selected="true"] { color: var(--accent); font-weight: 500; }
.picker-menu li svg { flex: none; width: 16px; height: 16px; fill: currentColor; visibility: hidden; }
.picker-menu li[aria-selected="true"] svg { visibility: visible; }
.icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.icon svg { width: 18px; height: 18px; fill: var(--text); }

.loading { height: 2px; background: var(--line); }
.loading i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(360px, 1fr);
  gap: 20px;
  padding: 8px 24px 12px;
  min-height: 0;
}
.stage {
  position: relative;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
  min-height: 420px;
  overflow: hidden;
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.caption {
  position: absolute;
  left: 20px;
  bottom: 16px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  max-width: 70%;
}

.deck {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 20px;
  min-width: 0;
}
.transport { display: flex; align-items: center; gap: 14px; }
.play {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 0;
  background: var(--text);
  display: grid;
  place-items: center;
}
.play svg { width: 20px; height: 20px; fill: var(--bg); }
.wave { flex: 1; min-width: 0; height: 48px; cursor: pointer; touch-action: none; }
.time { flex: none; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }

.controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.segmented button {
  border: 0;
  background: none;
  padding: 7px 16px;
  border-radius: 9px;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle .track {
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--faint);
  position: relative;
  transition: background 0.18s;
}
.toggle .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.18s;
}
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::after { transform: translateX(16px); }
.toggle input:disabled + .track { opacity: 0.4; }
.toggle input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.ghost {
  margin-left: auto;
  border: 1px solid var(--line);
  background: none;
  border-radius: 10px;
  padding: 6px 12px;
  color: var(--muted);
}

.stems { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.stem {
  display: grid;
  grid-template-columns: 28px 64px minmax(0, 1fr) 58px;
  grid-template-rows: auto 3px;
  align-items: center;
  column-gap: 10px;
  padding: 8px 6px;
  border-radius: 12px;
  transition: opacity 0.2s, background 0.2s;
}
.stem:hover { background: var(--bg); }
.stems.off .stem { opacity: 0.45; }
.stem .mute {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--c);
  background: var(--c);
  padding: 0;
  transition: background 0.15s;
}
.stem .mute[aria-pressed="false"] { background: transparent; }
.stem .name { font-weight: 500; }
.stem output { text-align: right; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.stem .meter {
  grid-column: 2 / -1;
  height: 3px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}
.stem .meter b {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--c);
  transform-origin: left;
  transform: scaleX(0);
}
input[type="range"] { width: 100%; accent-color: var(--c, var(--accent)); }
input[type="range"]:disabled { opacity: 0.5; }

.status { margin: auto 0 0; color: var(--muted); font-size: 12px; min-height: 18px; }

.hint { padding: 0 24px 14px; color: var(--muted); font-size: 12px; }
kbd {
  font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  background: var(--surface);
}

@media (max-width: 600px) {
  .bar { padding: 12px 16px; gap: 10px; }
  .brand-name { display: none; }
}
@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
  .stage { min-height: 340px; aspect-ratio: 1; }
  .hint { display: none; }
}

.jobs {
  list-style: none;
  margin: 0;
  padding: 12px 0 0;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
}
.job {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 10px;
  row-gap: 5px;
  font-size: 13px;
}
.job .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job .state { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.job .progress { grid-column: 1 / -1; height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.job .progress b { display: block; height: 100%; background: var(--accent); transition: width 0.6s; }
.job.done .progress b { background: #20c997; }
.job.failed .progress b { background: #e5484d; }
.job.failed .state, .job .error { color: #e5484d; }
.job .error {
  grid-column: 1 / -1;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.job .open {
  border: 1px solid var(--line);
  background: none;
  border-radius: 8px;
  padding: 2px 10px;
  color: var(--accent);
  font-size: 12px;
}

body.dropping main { outline: 2px dashed var(--accent); outline-offset: -6px; border-radius: 20px; }
