:root {
  --bg: #14161b;
  --bg2: #1b1e25;
  --bg3: #22262f;
  --panel: #1e2129;
  --border: #2e3340;
  --text: #dfe3ea;
  --muted: #8b93a5;
  --accent: #e0a04a;
  --accent2: #5fb3e0;
  --danger: #e06c8a;
  --topbar-h: 48px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden; user-select: none;
}
button, select, input { font: inherit; color: inherit; }
button {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 5px;
  padding: 4px 10px; cursor: pointer;
}
button:hover { background: #2b3040; }
button:disabled { opacity: 0.35; cursor: default; }
button.active { background: var(--accent); color: #1a1408; border-color: var(--accent); }
button.primary { background: var(--accent2); color: #08131a; border-color: var(--accent2); }
button.small { padding: 1px 7px; font-size: 12px; line-height: 1.4; }
button.del:hover { background: var(--danger); color: #fff; }
select {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 5px; padding: 3px 6px;
}
input[type=number] { background: var(--bg3); border: 1px solid var(--border); border-radius: 5px; padding: 3px 6px; width: 64px; }
input[type=range] { accent-color: var(--accent); height: 16px; }

/* ------------------------------------------------------------ top bar */
#topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: 14px; padding: 0 12px;
  background: linear-gradient(#232733, #1b1e25); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 18px; letter-spacing: 0.5px; color: var(--accent); }
.brand span { color: var(--text); font-weight: 600; }
.tabs { display: flex; gap: 2px; background: var(--bg); padding: 3px; border-radius: 7px; }
.tab { border: 0; background: transparent; padding: 5px 14px; color: var(--muted); }
.tab.active { background: var(--bg3); color: var(--text); }
.transport { display: flex; align-items: center; gap: 6px; margin-left: 8px; }
.transport button { min-width: 34px; }
#btn-play.active { background: #59d1c0; border-color: #59d1c0; }
.position { font-family: ui-monospace, Consolas, monospace; font-size: 14px; background: var(--bg); padding: 4px 10px; border-radius: 5px; min-width: 96px; text-align: center; }
.bpm-wrap { display: flex; align-items: center; gap: 5px; color: var(--muted); }
.mode { display: flex; gap: 0; }
.mode button { border-radius: 0; }
.mode button:first-child { border-radius: 5px 0 0 5px; }
.mode button:last-child { border-radius: 0 5px 5px 0; }
#topbar .right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.master { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.master input { width: 90px; }
.project-name { background: transparent; border-color: transparent; color: var(--muted); }
.export-status { color: var(--accent); font-size: 12px; }
.tuning-btn { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

.popover { position: fixed; z-index: 900; background: #262a35; border: 1px solid var(--border); border-radius: 8px; padding: 12px; width: 340px; box-shadow: 0 10px 40px rgba(0,0,0,0.55); display: flex; flex-direction: column; gap: 8px; }
.pop-title { font-weight: 700; margin-bottom: 2px; }
.pop-row { display: flex; align-items: center; gap: 8px; }
.pop-row label { flex: 1; color: var(--muted); font-size: 12px; }
.pop-row input[type=number] { width: 72px; }
.popover .hint { padding: 4px 0 0; }

/* --------------------------------------------------------------- pages */
main { height: calc(100% - var(--topbar-h)); }
.tab-page { display: none; height: 100%; }
.tab-page.active { display: flex; }

.side { width: 220px; flex: none; background: var(--bg2); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; font-weight: 600; color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: 0.6px; border-bottom: 1px solid var(--border); }
.side-list { overflow-y: auto; flex: 1; }
.side-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,0.03); }
.side-item:hover { background: rgba(255,255,255,0.04); }
.side-item.active { background: rgba(224,160,74,0.15); box-shadow: inset 3px 0 0 var(--accent); }
.side-item .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.side-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item .meta { color: var(--muted); font-size: 11px; }
.side-foot { padding: 8px 10px; border-top: 1px solid var(--border); }
.side-foot input { width: 56px; }
.hint { color: var(--muted); font-size: 11px; padding: 8px 10px; line-height: 1.5; }
.hint-inline { color: var(--muted); font-size: 11px; font-weight: normal; margin-left: 8px; white-space: nowrap; }
@media (max-width: 900px) { .hint-inline { display: none; } }

.roll-main { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.toolbar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--bg2); border-bottom: 1px solid var(--border); flex: none; }
.tb-label { color: var(--muted); font-size: 12px; }
.tb-spacer { flex: 1; }
.canvas-wrap { flex: 1; position: relative; min-height: 0; min-width: 0; }
.canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; }

/* arrangement */
.arr-body { flex: 1; display: flex; min-height: 0; }
.track-headers { width: 200px; flex: none; background: var(--bg2); border-right: 1px solid var(--border); overflow: hidden; }
.track-head-spacer { border-bottom: 1px solid var(--border); background: #1a1c22; }
.track-head { border-bottom: 1px solid var(--border); border-left: 4px solid #555; padding: 6px 8px; display: flex; flex-direction: column; gap: 6px; justify-content: center; }
.track-head .row { display: flex; align-items: center; gap: 4px; }
.track-head select { flex: 1; min-width: 0; font-size: 12px; padding: 2px 4px; }
.track-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: text; }
.lane-head { background: #171920; }
.lane-name { font-size: 11px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.lane-sub { font-size: 11px; color: var(--muted); }
.lane-value { font-family: ui-monospace, Consolas, monospace; color: var(--accent); }
.lane-interp { font-size: 10px; text-transform: uppercase; letter-spacing: 0.4px; }
.popover select { max-width: 200px; }
.ms { padding: 1px 6px; font-size: 11px; font-weight: 700; }
.ms.on-mute { background: var(--danger); color: #fff; border-color: var(--danger); }
.ms.on-solo { background: #e6d35c; color: #222; border-color: #e6d35c; }

/* -------------------------------------------------------- instruments */
.inst-head .inst-name { font-weight: 700; font-size: 15px; background: transparent; border-color: transparent; }
.inst-head .param { width: 200px; }
.scope { width: 220px; height: 30px; border-radius: 4px; background: #12141a; }
.inst-body { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.osc-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.global-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
@media (max-width: 1100px) { .osc-row, .global-row { grid-template-columns: 1fr; } }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.panel.disabled > *:not(.panel-title) { opacity: 0.35; pointer-events: none; }
.panel-title { font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.sub-title { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; margin-top: 6px; }
.row { display: flex; align-items: center; gap: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; }
.osc-toggle { font-weight: 700; }
.toggle { background: var(--bg3); }
.toggle.on { background: var(--accent); color: #1a1408; border-color: var(--accent); }
.wave-preview { width: 100%; height: 70px; border-radius: 5px; }
.partials { width: 100%; height: 110px; border-radius: 5px; cursor: crosshair; }
.partial-info { color: var(--muted); font-size: 11px; min-height: 16px; font-family: ui-monospace, Consolas, monospace; }
.env-canvas { width: 100%; height: 60px; border-radius: 5px; }
.wave-canvas { width: 100%; height: 120px; border-radius: 5px; }
.panel.sampler.drop { outline: 2px dashed var(--accent); }
.gradient-bar { width: 100%; height: 26px; border-radius: 5px; }
.panel.resynth.drop { outline: 2px dashed var(--accent); }
.rs-body { display: grid; grid-template-columns: 240px 1fr; gap: 10px; align-items: start; }
@media (max-width: 900px) { .rs-body { grid-template-columns: 1fr; } }
.heat-canvas { width: 100%; height: 160px; border-radius: 5px; }
.rs-notes { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; max-height: 130px; overflow-y: auto; }
.rs-note.active { background: var(--accent); color: #1a1408; border-color: var(--accent); }
.panel.gradient .pop-row input[type=number] { width: 70px; }
.panel.gradient select { min-width: 0; max-width: 260px; }

.param { display: grid; grid-template-columns: 76px 1fr 64px; align-items: center; gap: 6px; }
.param.compact { grid-template-columns: 52px 1fr 52px; }
.param-label { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.param-value { font-size: 11px; text-align: right; font-family: ui-monospace, Consolas, monospace; color: var(--text); white-space: nowrap; }
.param input[type=range] { width: 100%; min-width: 0; margin: 0; }
.param select { min-width: 0; }

.fx-section { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 10px; }
.fx-chain { display: flex; gap: 10px; overflow-x: auto; padding: 6px 0 2px; }
.fx-card { flex: none; width: 250px; background: var(--bg3); border: 1px solid var(--border); border-radius: 7px; padding: 8px; display: flex; flex-direction: column; gap: 3px; }
.fx-card.disabled .param { opacity: 0.4; }
.fx-head { margin-bottom: 4px; }
.fx-name { font-weight: 700; }
.fx-power { padding: 1px 7px; }

.test-keys { flex: none; height: 90px; width: 100%; background: var(--bg2); border-top: 1px solid var(--border); display: block; cursor: pointer; }

/* --------------------------------------------------------------- misc */
.tb-sep { width: 1px; height: 20px; background: var(--border); }

/* ---------------------------------------------------------- composer modal */
.modal-back { position: fixed; inset: 0; background: rgba(8, 9, 12, 0.6); z-index: 1200; display: grid; place-items: center; }
.modal { background: #20242e; border: 1px solid var(--border); border-radius: 10px; padding: 14px; width: min(620px, 94vw); max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.6); display: flex; flex-direction: column; gap: 9px; }
.modal-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.modal-actions { margin-top: 4px; gap: 8px; }
.gen-prompt { flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 9px 11px; font-size: 14px; }
.gen-prompt:focus { outline: none; border-color: var(--accent2); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { font-size: 11px; padding: 3px 8px; border-radius: 11px; color: var(--muted); }
.chip:hover { color: var(--text); border-color: var(--accent2); }
.gen-readout { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; font-size: 12px; }
.gen-heard { color: var(--muted); font-size: 11px; margin-top: 3px; }

.ctx-menu { position: fixed; z-index: 1000; background: #262a35; border: 1px solid var(--border); border-radius: 7px; padding: 4px; min-width: 180px; box-shadow: 0 8px 30px rgba(0,0,0,0.5); }
.ctx-item { padding: 6px 12px; border-radius: 4px; cursor: pointer; }
.ctx-item:hover { background: var(--accent); color: #1a1408; }
.ctx-item.disabled { opacity: 0.4; pointer-events: none; }
.ctx-sep { height: 1px; background: var(--border); margin: 4px 0; }

#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 1100; pointer-events: none; }
.toast { background: #262a35; border: 1px solid var(--border); padding: 8px 16px; border-radius: 7px; opacity: 0; transition: opacity 0.25s, transform 0.25s; transform: translateY(8px); box-shadow: 0 8px 30px rgba(0,0,0,0.5); }
.toast.show { opacity: 1; transform: none; }

#loading { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); color: var(--muted); z-index: 2000; font-size: 15px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #363b4a; border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

/* XIO colour + motion layer: <html data-xio="xdaw"> + /xio/motion/ (linked
   after this file, so its coral accent replaces the old amber). */
html[data-xio] {
  --bg: var(--x-bg);
  --bg2: var(--x-panel);
  --bg3: var(--x-panel-2);
  --panel: color-mix(in oklab, var(--accent) 5%, #0b0b0c);
  --border: color-mix(in oklab, var(--accent) 22%, #262626);
  --text: var(--x-text);
  --muted: var(--x-dim);
  --accent2: var(--accent-2);
}
html[data-xio] #topbar { background: color-mix(in oklab, var(--x-bg) 88%, transparent); }
html[data-xio] .brand span { color: var(--accent); }
.xd-opt { position: relative; width: 30px; height: 30px; padding: 0; display: inline-grid; place-items: center; background: none; border: 1px solid var(--border); color: var(--muted); cursor: pointer; }
.xd-opt:hover, .xd-opt[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); }
.xd-opt svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.4; }
