:root {
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  /* dark (default: DAW feel) */
  --bg: #0e1015;
  --bg-panel: #151820;
  --bg-lane: #12151c;
  --bg-ruler: #191d26;
  --border: #262b36;
  --text: #e6e8ee;
  --muted: #8a91a0;
  --grid-faint: #1a1e27;
  --grid: #232834;
  --grid-strong: #313847;
  --shade: rgba(0, 0, 0, 0.32);
  --accent: #ff6a3d;
  --accent-soft: #ff6a3d66;
  --playhead: #ffffff;
  --wave-idle: #3a4150;
  --wave-low: #2f6fe4;
  --wave-mid: #f2a33a;
  --wave-high: #e9edf5d0;
  --kick: rgba(255, 255, 255, 0.75);
  --bass: #ff8a4c;
  --loop: #c4f25a;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f5f8;
    --bg-panel: #ffffff;
    --bg-lane: #fbfbfd;
    --bg-ruler: #eef0f4;
    --border: #dde0e7;
    --text: #1b1e26;
    --muted: #6a7180;
    --grid-faint: #f0f1f5;
    --grid: #e5e7ee;
    --grid-strong: #d2d6df;
    --shade: rgba(20, 30, 60, 0.08);
    --accent: #f0521f;
    --accent-soft: #f0521f55;
    --playhead: #111;
    --wave-idle: #c5cad4;
    --wave-low: #2b63d9;
    --wave-mid: #e08a17;
    --wave-high: #7c8596;
    --kick: rgba(20, 24, 32, 0.7);
    --bass: #e8662a;
    --loop: #5f8f00;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 var(--sans);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.dim { color: var(--muted); }
button { font: inherit; color: inherit; }
select {
  font: inherit; color: var(--text); background: var(--bg-lane);
  border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px;
}

/* ---- header / transport */
.top {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 16px; background: var(--bg-panel); border-bottom: 1px solid var(--border);
  min-height: 56px;
}
.brand { font-weight: 700; letter-spacing: 0.02em; }
.play {
  width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); display: grid; place-items: center; flex: none;
}
.play svg { width: 18px; height: 18px; fill: #fff; }
.play .i-pause, .play.on .i-play { display: none; }
.play.on .i-pause { display: block; }
.readout { font-family: var(--mono); font-variant-numeric: tabular-nums; line-height: 1.25; white-space: nowrap; flex: none; }
.readout b { font-size: 15px; }
.readout.big { display: flex; align-items: baseline; gap: 4px; }
.readout.big b { font-size: 18px; min-width: 2.6em; text-align: right; }
.title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.spacer { flex: 1; }
.tools { display: flex; gap: 4px; }
.tbtn {
  background: transparent; border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 10px; cursor: pointer; color: var(--muted);
}
.tbtn.on { color: var(--text); border-color: var(--muted); }
.tbtn:hover { color: var(--text); }

.banner { padding: 6px 16px; font-size: 12px; white-space: pre-wrap; border-bottom: 1px solid var(--border); }
.banner.info { background: color-mix(in srgb, #60a5fa 14%, var(--bg-panel)); }
.banner.warn { background: color-mix(in srgb, #fbbf24 18%, var(--bg-panel)); }
.banner.error { background: color-mix(in srgb, #f87171 22%, var(--bg-panel)); }

/* ---- layout */
main { flex: 1; display: flex; min-height: 0; }
.stage { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-y: auto; }
.ov-wrap { padding: 12px 16px 8px; background: var(--bg-panel); border-bottom: 1px solid var(--border); }
.ov-wrap canvas { display: block; cursor: pointer; touch-action: pan-y; }
.arr-wrap { position: relative; }
.arr-wrap canvas { display: block; touch-action: pan-y; }
.keys { display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 10px 16px; font-size: 11px; }
kbd {
  font: 10px var(--mono); border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 4px; padding: 0 4px; margin-right: 2px; background: var(--bg-panel);
}

aside {
  width: 340px; flex: none; display: flex; flex-direction: column;
  background: var(--bg-panel); border-left: 1px solid var(--border); min-height: 0;
}
#now { padding: 12px 14px 4px; display: flex; flex-direction: column; gap: 8px; min-height: 64px; }
.deckcard { display: flex; gap: 10px; align-items: stretch; }
.swatch { width: 4px; border-radius: 2px; flex: none; }
.dc-main { flex: 1; min-width: 0; }
.dc-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dc-title a { color: inherit; text-decoration: none; }
.dc-meta { color: var(--muted); font: 11px var(--mono); }
.meters { display: flex; gap: 4px; margin-top: 4px; }
.meter {
  position: relative; width: 22px; height: 26px; background: var(--bg-lane);
  border: 1px solid var(--border); border-radius: 3px; overflow: hidden;
}
.meter i { position: absolute; left: 0; right: 0; bottom: 0; background: var(--muted); opacity: 0.55; }
.meter i[data-p="low"] { background: #ff6b3d; }
.meter i[data-p="mid"] { background: #facc15; }
.meter i[data-p="high"] { background: #7dd3fc; }
.meter span { position: absolute; inset: 0; display: grid; place-items: center; font: 600 9px var(--mono); }
.nowregion { font-size: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.progress { flex-basis: 100%; height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; }

.tabs { display: flex; border-bottom: 1px solid var(--border); padding: 0 8px; margin-top: 6px; }
.tabs button {
  background: none; border: 0; padding: 8px 10px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.pane { overflow-y: auto; padding: 10px 14px 20px; flex: 1; }
.pane h3 { margin: 4px 0 2px; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.pane h4 { margin: 14px 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.sub { color: var(--muted); margin-bottom: 8px; }
.notes { font-style: italic; color: var(--muted); margin: 8px 0; }
.hint { color: var(--muted); font-size: 12px; }

.tracklist { list-style: none; margin: 0; padding: 0; }
.trow {
  display: grid; grid-template-columns: 10px 44px 1fr auto; gap: 8px; align-items: center;
  padding: 6px 6px; border-radius: 6px; cursor: pointer;
}
.trow:hover { background: var(--bg-lane); }
.trow.current { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.t-time, .t-meta { font: 11px var(--mono); color: var(--muted); }
.t-meta { text-align: right; }
.t-name { min-width: 0; overflow: hidden; }
.t-name b, .t-name small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: inline-block; max-width: 100%; }
.t-name small { color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.sq { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.tag { color: #0b0d12; font: 600 10px var(--sans); padding: 1px 6px; border-radius: 4px; }

.kv { display: grid; grid-template-columns: 96px 1fr; gap: 3px 10px; margin: 8px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
code { font: 11px var(--mono); }
.plink { color: var(--accent); text-decoration: none; }
.plink:hover { text-decoration: underline; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 2px 0; }
ul.warn { padding-left: 16px; color: #e8a33d; font-size: 12px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; }
.legend > span { display: inline-flex; align-items: center; gap: 5px; }
.btn {
  margin-top: 10px; background: var(--accent); color: #fff; border: 0; border-radius: 6px;
  padding: 6px 12px; cursor: pointer;
}
.planpath { margin-top: 16px; display: flex; gap: 8px; align-items: center; font-size: 11px; color: var(--muted); }
.planpath code { color: var(--text); background: var(--bg-lane); padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border); }
pre.json {
  font: 11px/1.45 var(--mono); background: var(--bg-lane); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; overflow-x: auto; margin: 6px 0 0; max-height: 280px;
}

.tip {
  position: fixed; left: 0; top: 0; z-index: 10; pointer-events: none;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 8px; font-size: 12px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3); max-width: 360px;
}

.stagebar:empty { display: none; }
.touchkeys { display: none; }
body { padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

/* ---- touch screens: bigger targets, touch hints instead of keyboard shortcuts */
@media (pointer: coarse) {
  .play { width: 46px; height: 46px; }
  .play svg { width: 20px; height: 20px; }
  .setbtn { min-height: 40px; }
  .tbtn { min-height: 36px; min-width: 40px; padding: 4px 12px; }
  .tabs button { padding: 12px 14px; }
  .trow { padding: 9px 6px; }
  .keys { display: none; }
  .touchkeys { display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 10px 16px; font-size: 11px; }
}

/* the header title repeats the set button: only show it when there is room */
@media (max-width: 1280px) { .title { display: none; } }

/* ---- narrow (phones, portrait tablets): one scrolling column, sticky transport */
@media (max-width: 900px) {
  body { overflow-x: hidden; overflow-y: auto; height: auto; min-height: 100%; }
  main { flex-direction: column; flex: none; }
  .stage { flex: none; overflow: visible; }
  aside { width: auto; border-left: 0; border-top: 1px solid var(--border); }
  .pane { overflow: visible; flex: none; }
  .top {
    position: sticky; top: 0; z-index: 5; flex-wrap: wrap; gap: 8px 14px;
    padding: 8px max(12px, env(safe-area-inset-left)); padding-top: max(8px, env(safe-area-inset-top));
  }
  .title, .spacer, #status:empty { display: none; }
  .keys { display: none; }
  .ov-wrap { padding: 10px 12px 6px; }
  .stagebar {
    display: flex; align-items: center; gap: 8px; padding: 6px 12px;
    background: var(--bg-panel); border-bottom: 1px solid var(--border);
  }
  .stagebar .tools { margin-left: auto; }
  #now { padding: 10px 12px 4px; }
  .pane { padding: 8px 12px 24px; }
}
/* phones: set button + play on the first row, readouts on the second */
@media (max-width: 600px) {
  .brand { display: none; }
  .setbtn { flex: 1 0 calc(100% - 60px); max-width: none; order: 1; } /* forces the readouts onto row 2 */
  .play { order: 2; }
  .readout { order: 3; }
  .readout:not(.big) { margin-right: auto; }
  .readout.big b { font-size: 16px; min-width: 0; }
  #status { order: 4; flex-basis: 100%; font-size: 11px; }
  .stagebar .tools { margin-left: 0; width: 100%; }
  .stagebar .tools { gap: 6px; }
  .stagebar .tbtn { flex: 0 0 44px; padding: 4px 6px; }
  .stagebar #auto, .stagebar #follow { flex: 1 1 auto; }
  .touchkeys { padding: 8px 12px; }
}

/* ---- set picker */
.setbtn {
  display: flex; align-items: center; gap: 8px; max-width: 260px; min-width: 0;
  background: var(--bg-lane); border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 10px; cursor: pointer;
}
.setbtn:hover { border-color: var(--muted); }
.sb-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-caret { color: var(--muted); font-size: 11px; }
dialog.picker {
  width: min(640px, calc(100vw - 32px)); max-height: min(640px, calc(100vh - 64px)); max-height: min(640px, calc(100dvh - 32px));
  margin: 8vh auto auto; padding: 0; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg-panel); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  display: none; flex-direction: column; overflow: hidden;
}
dialog.picker[open] { display: flex; }
dialog.picker::backdrop { background: rgba(5, 8, 14, 0.55); }
.pk-head { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border); }
.pk-head input {
  flex: 1; min-width: 0; font: inherit; font-size: 15px; color: var(--text); background: var(--bg-lane);
  border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; outline: none;
}
.pk-head input:focus { border-color: var(--accent); }
/* flex-basis auto: WebKit collapses a flex: 1 (basis 0) child of a max-height-only dialog */
.pk-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.pk-item { padding: 8px 10px; border-radius: 6px; cursor: pointer; border-left: 3px solid transparent; }
.pk-item.active { background: var(--bg-ruler); }
.pk-item.current { border-left-color: var(--accent); }
.pk-item.muted .pk-title { color: var(--muted); }
.pk-row { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.pk-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pk-name { font-family: var(--mono); font-size: 11px; margin-left: auto; flex: none; }
.pk-meta { font-size: 12px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pk-tag { font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em; border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; }
.pk-tag.err { color: #f87171; border-color: #f8717166; }
.pk-hits { display: flex; flex-direction: column; font-size: 12px; margin-top: 3px; padding-left: 8px; border-left: 2px solid var(--accent-soft); }
.pk-hits span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pk-empty { padding: 24px; text-align: center; }
.pk-foot { display: flex; justify-content: space-between; gap: 12px; padding: 8px 12px; border-top: 1px solid var(--border); font-size: 11px; }
@media (max-width: 600px) { .pk-foot span:last-child { display: none; } dialog.picker { margin-top: 16px; } }
/* iOS zooms the page when focusing a field under 16px */
@media (pointer: coarse) { .pk-head input, .pk-head select { font-size: 16px; } .pk-foot span:last-child { display: none; } }
