/* Layout: noir instrument. Nodes + buses | canvas with mood cards beneath | selected node's rack.
   Transport with Master knobs across the bottom. The interface is grayscale; only the visuals carry color. */
:root {
  color-scheme: dark;
  --bg: #08080a;
  --panel: #111114;
  --panel-hi: #19191d;
  --well: #040405;
  --line: rgba(232, 232, 242, .075);
  --line-hi: rgba(232, 232, 242, .17);
  --fg: #d8d8de;
  --muted: #8b8b94;
  --dim: #5c5c64;
  --silver: #f2f2f6;
  --font-ui: "Jost", "Futura", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-data: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --r: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font-ui); font-size: 14px; -webkit-font-smoothing: antialiased; overflow: hidden; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 1px solid var(--silver); outline-offset: 2px; }

.app { height: 100%; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 12px; padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px)); padding-block: env(safe-area-inset-top, 0px) calc(14px + env(safe-area-inset-bottom, 0px)); }
.top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; height: 54px; border-bottom: 1px solid var(--line); }
.mark { font-weight: 300; font-size: 21px; letter-spacing: .42em; color: var(--silver); padding-left: 2px; }
.tabs { display: flex; gap: 4px; }
.tab { background: none; border: 0; padding: 16px 16px 15px; color: var(--muted); letter-spacing: .03em; border-bottom: 1px solid transparent; }
.tab:hover { color: var(--fg); }
.tab[aria-current="page"] { color: var(--silver); border-bottom-color: var(--silver); }
.top-right { justify-self: end; display: flex; align-items: center; gap: 10px; }
.label { font-size: 11.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 400; }
.select { appearance: none; -webkit-appearance: none; background-color: var(--panel); border: 1px solid var(--line-hi); border-radius: 7px; padding: 6px 26px 6px 10px; font-family: var(--font-data); font-size: 12px; color: var(--fg);
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 13px) 52%, calc(100% - 9px) 52%; background-size: 4px 4px; background-repeat: no-repeat; max-width: 100%; }

/* Studio grid */
.studio { display: grid; grid-template-columns: 232px minmax(0, 1fr) 304px; grid-template-rows: minmax(0, 1fr) auto; grid-template-areas: "left stage rack" "left moods rack"; gap: 12px; min-height: 0; }
.left { grid-area: left; }
.stage-col { grid-area: stage; }
.moods { grid-area: moods; }
.rack { grid-area: rack; }
.panel { background: repeating-linear-gradient(90deg, rgba(255,255,255,.011) 0 1px, transparent 1px 3px), linear-gradient(180deg, var(--panel-hi), var(--panel)); border: 1px solid var(--line); border-radius: var(--r); box-shadow: inset 0 1px 0 rgba(255,255,255,.04); }
.side { min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; scrollbar-width: thin; scrollbar-color: #2a2a30 transparent; }
.head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 10px; border-bottom: 1px solid var(--line); }
.icon-btn { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 7px; border: 1px solid var(--line-hi); background: rgba(255,255,255,.03); color: var(--fg); flex: none; }
.icon-btn:hover { background: rgba(255,255,255,.07); }

/* Node + bus lists */
.list { list-style: none; margin: 0; padding: 6px; display: flex; flex-direction: column; gap: 2px; }
.row-item { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto auto; align-items: center; gap: 9px; padding: 7px 8px; border-radius: 7px; border: 1px solid transparent; cursor: pointer; }
.row-item:hover { background: rgba(255,255,255,.03); }
.row-item[aria-selected="true"] { background: rgba(255,255,255,.055); border-color: var(--line-hi); }
.swatch { width: 13px; height: 13px; border-radius: 50%; justify-self: center; box-shadow: 0 0 10px 1px var(--sw); background: radial-gradient(circle, #fff 0 18%, var(--sw) 55%); flex: none; }
.row-item.off .swatch { opacity: .25; box-shadow: none; }
.row-text { min-width: 0; display: flex; flex-direction: column; }
.row-name { font-size: 13.5px; color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { font-family: var(--font-data); font-size: 10.5px; color: var(--muted); border: 1px solid var(--line-hi); border-radius: 4px; padding: 1px 5px; min-width: 20px; text-align: center; }
.tag.empty { border-style: dashed; color: var(--dim); }
.bus-tag { width: 18px; height: 18px; border-radius: 4px; display: grid; place-items: center; font-family: var(--font-data); font-size: 11px; color: var(--bg); background: linear-gradient(180deg, #f1f1f5, #a9a9b1); justify-self: center; }
.eye { background: none; border: 0; color: var(--muted); padding: 2px; display: grid; }
.eye:hover { color: var(--silver); }
.list-foot { padding: 6px 14px 12px; color: var(--dim); font-size: 12px; line-height: 1.5; }

/* Stage */
.stage-col { display: flex; flex-direction: column; gap: 10px; min-height: 0; min-width: 0; }
.stage-area { flex: 1; min-height: 0; display: grid; place-items: center; position: relative; }
.stage { position: relative; background: var(--well); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; box-shadow: 0 30px 60px -30px rgba(0,0,0,.9); max-width: 100%; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#ui { touch-action: none; cursor: crosshair; }
.blend-pill { display: inline-flex; align-items: center; gap: 8px; background: none; border: 1px solid var(--line-hi); border-radius: 20px; padding: 4px 12px; font-size: 12.5px; color: var(--fg); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.blend-pill:hover { border-color: rgba(255,255,255,.3); }
.stage-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; font-size: 12.5px; color: var(--muted); }
.seg-mini { display: inline-flex; border: 1px solid var(--line-hi); border-radius: 7px; overflow: hidden; }
.seg-mini button { background: none; border: 0; padding: 5px 11px; color: var(--muted); font-size: 12.5px; }
.seg-mini button[aria-pressed="true"] { background: linear-gradient(180deg, #4a4a52, #2b2b31); color: var(--silver); box-shadow: inset 0 1px 0 rgba(255,255,255,.15); }
.tool-check { display: inline-flex; align-items: center; gap: 8px; }
.hint { margin-left: auto; color: var(--dim); font-size: 12px; }

/* Mood cards */
.moods { display: grid; grid-template-columns: repeat(6, minmax(118px, 1fr)); gap: 8px; overflow-x: auto; scrollbar-width: thin; scrollbar-color: #2a2a30 transparent; }
.mood { padding: 8px; display: flex; flex-direction: column; gap: 7px; transition: border-color .2s; }
.mood.on { border-color: rgba(255,255,255,.32); }
.mood-top { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 8px; align-items: center; background: none; border: 0; padding: 0; text-align: left; }
.mood-top canvas { grid-column: 1 / -1; width: 100%; height: 30px; border-radius: 4px; border: 1px solid var(--line-hi); display: block; }
.mood-name { font-size: 13px; color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.check { width: 17px; height: 17px; border-radius: 50%; border: 1px solid var(--line-hi); display: grid; place-items: center; color: transparent; }
.mood.on .check { background: var(--silver); color: #0b0b0d; border-color: transparent; }
.mood-ctl { display: grid; grid-template-columns: 1fr; gap: 5px; opacity: .45; transition: opacity .2s; }
.mood.on .mood-ctl { opacity: 1; }
.mood-ctl .select { padding-block: 3px; font-size: 11px; width: 100%; }
.op-row { display: grid; grid-template-columns: 1fr 34px; gap: 6px; align-items: center; }
.op-row output { font-family: var(--font-data); font-size: 10.5px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

/* Rack */
.rsec { padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.rack-title { display: flex; align-items: center; gap: 10px; }
.rack-title strong { font-weight: 400; font-size: 15px; color: var(--silver); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.chips.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.chip { background: none; border: 1px solid var(--line-hi); border-radius: 20px; padding: 5px 10px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chips.grid3 .chip, .chips.grid2 .chip { border-radius: 7px; padding: 6px 6px; }
.chip:hover { color: var(--fg); border-color: rgba(255,255,255,.3); }
.chip[aria-pressed="true"] { color: #0b0b0d; background: linear-gradient(180deg, #f3f3f6, #b8b8bf); border-color: transparent; }
.desc { margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.row { display: grid; grid-template-columns: 64px 1fr 40px; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.row output { font-family: var(--font-data); font-size: 11.5px; color: var(--fg); text-align: right; font-variant-numeric: tabular-nums; }
.row.wide { grid-template-columns: 64px 1fr; }
.empty-rack { color: var(--muted); font-size: 13px; line-height: 1.6; }
details > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: ""; width: 7px; height: 7px; border-right: 1px solid var(--muted); border-bottom: 1px solid var(--muted); transform: rotate(45deg); margin-right: 4px; transition: transform .2s; }
details[open] > summary::after { transform: rotate(-135deg); }
.details-body { display: flex; flex-direction: column; gap: 10px; padding-top: 12px; }
.pair { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.num-wrap { display: flex; flex-direction: column; gap: 4px; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); }
.num-in { width: 100%; background: var(--well); border: 1px solid var(--line-hi); border-radius: 6px; padding: 5px 7px; font-family: var(--font-data); font-size: 12px; }
.osc { display: flex; flex-direction: column; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.toggle-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--fg); }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 18px; background: transparent; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 2px; background: linear-gradient(90deg, var(--silver) var(--p, 50%), rgba(255,255,255,.12) var(--p, 50%)); border-radius: 2px; }
input[type=range]::-moz-range-track { height: 2px; background: rgba(255,255,255,.12); }
input[type=range]::-moz-range-progress { height: 2px; background: var(--silver); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 13px; height: 13px; margin-top: -5.5px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #a9a9b0 55%, #5d5d64); border: 1px solid #1a1a1e; box-shadow: 0 1px 3px rgba(0,0,0,.7); }
input[type=range]::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #a9a9b0 55%, #5d5d64); border: 1px solid #1a1a1e; }
input[type=range].hue::-webkit-slider-runnable-track { height: 4px; background: linear-gradient(90deg, hsl(0 85% 55%), hsl(60 85% 55%), hsl(120 85% 50%), hsl(180 85% 50%), hsl(240 85% 60%), hsl(300 85% 58%), hsl(360 85% 55%)); }
input[type=range].hue::-moz-range-track { height: 4px; background: linear-gradient(90deg, hsl(0 85% 55%), hsl(60 85% 55%), hsl(120 85% 50%), hsl(180 85% 50%), hsl(240 85% 60%), hsl(300 85% 58%), hsl(360 85% 55%)); }
input[type=range].hue::-webkit-slider-thumb { margin-top: -4.5px; }
.switch { position: relative; width: 34px; height: 18px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 10px; background: var(--well); border: 1px solid var(--line-hi); transition: background .2s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #8d8d94); transition: transform .2s; }
.switch input:checked + span { background: #3a3a40; }
.switch input:checked + span::after { transform: translateX(16px); }
.btn-quiet { background: none; border: 1px solid var(--line-hi); border-radius: 7px; padding: 6px 10px; color: var(--muted); font-size: 12.5px; }
.btn-quiet:hover { color: var(--silver); border-color: rgba(255,255,255,.3); }

/* Knobs */
.shape-text { display: grid; gap: 6px; margin-top: 12px; }
.shape-text textarea { width: 100%; resize: vertical; background: var(--well); color: var(--fg); border: 1px solid var(--line-hi); border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 13px; line-height: 1.4; }
.knobs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 4px; justify-items: center; padding-top: 4px; }
.knob-wrap { display: flex; flex-direction: column; align-items: center; gap: 5px; user-select: none; -webkit-user-select: none; }
.knob { --s: 50px; position: relative; width: var(--s); height: var(--s); touch-action: none; cursor: ns-resize; border-radius: 50%; }
.knob.lg { --s: 62px; }
.knob.sm { --s: 40px; }
.knob svg { position: absolute; inset: -9px; width: calc(100% + 18px); height: calc(100% + 18px); overflow: visible; pointer-events: none; }
.knob .track { fill: none; stroke: rgba(255,255,255,.08); stroke-width: 2; }
.knob .arc { fill: none; stroke: var(--silver); stroke-width: 2; stroke-linecap: round; filter: drop-shadow(0 0 3px rgba(255,255,255,.45)); }
.knob .ticks { stroke: rgba(255,255,255,.18); stroke-width: 1; }
.knob .rim { position: absolute; inset: 0; border-radius: 50%; background: repeating-conic-gradient(#1c1c20 0 4deg, #3b3b41 4deg 8deg); box-shadow: 0 6px 14px -4px rgba(0,0,0,.9), 0 0 0 1px #000; }
.knob .cap { position: absolute; inset: 11%; border-radius: 50%;
  background: radial-gradient(circle at 50% 30%, rgba(255,255,255,.35), transparent 55%),
    conic-gradient(from 10deg, #6b6b72, #e6e6eb 10%, #77777e 22%, #cfcfd5 35%, #6a6a71 48%, #dcdce2 60%, #737379 73%, #e1e1e6 86%, #6b6b72);
  box-shadow: inset 0 1px 1px rgba(255,255,255,.6), inset 0 -2px 4px rgba(0,0,0,.45); }
.knob .needle { position: absolute; inset: 11%; transform: rotate(var(--a, 0deg)); }
.knob .needle::after { content: ""; position: absolute; left: 50%; top: 9%; width: 2px; height: 26%; margin-left: -1px; border-radius: 1px; background: #17171a; box-shadow: 0 1px 0 rgba(255,255,255,.5); }
.knob:focus-visible { outline: none; box-shadow: 0 0 0 1px var(--silver); }
.knob-label { font-size: 12px; color: var(--fg); letter-spacing: .02em; white-space: nowrap; }
.knob-val { font-family: var(--font-data); font-size: 10px; color: var(--dim); font-variant-numeric: tabular-nums; margin-top: -3px; }

/* Transport */
.transport { display: grid; grid-template-columns: minmax(180px, 1fr) auto auto auto; align-items: center; gap: 18px; padding: 8px 14px; }
.np { display: flex; align-items: center; gap: 12px; min-width: 0; }
.np-art { width: 40px; height: 40px; flex: none; border-radius: 6px; border: 1px solid var(--line-hi); background: radial-gradient(circle at 40% 35%, #3a3a40, #0b0b0d 70%); display: grid; place-items: center; color: var(--muted); }
.np-text { min-width: 0; }
.np-title { color: var(--silver); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sources { display: flex; flex-wrap: wrap; gap: 8px; }
.src { display: inline-flex; align-items: center; gap: 8px; background: linear-gradient(180deg, #232328, #151518); border: 1px solid var(--line-hi); border-radius: 22px; padding: 7px 13px; color: var(--fg); font-size: 13px; box-shadow: inset 0 1px 0 rgba(255,255,255,.06); white-space: nowrap; }
.src:hover { border-color: rgba(255,255,255,.3); }
.src[aria-pressed="true"] { background: linear-gradient(180deg, #f4f4f7, #b9b9c0); color: #0b0b0d; border-color: transparent; }
.src input { display: none; }
.master { display: flex; align-items: flex-end; gap: 14px; padding-inline: 14px; border-inline: 1px solid var(--line); }
.master .knob-val { display: none; }
.meter { display: flex; align-items: center; gap: 12px; }
#spec { width: 140px; height: 32px; display: block; }
.beat { width: 9px; height: 9px; border-radius: 50%; background: #2a2a2f; box-shadow: 0 0 0 1px #000; }

.tabbar { display: none; }
.mobile-only { display: none; }
.mseg { display: none; }
.toast { position: fixed; left: 50%; top: calc(6px + env(safe-area-inset-top, 0px)); transform: translate(-50%, -10px); display: flex; align-items: center; gap: 14px; background: #1b1b1f; border: 1px solid var(--line-hi); color: var(--fg); padding: 9px 14px; border-radius: 10px; font-size: 13px; max-width: min(92vw, 480px); opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 50; line-height: 1.45; }
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { background: none; border: 1px solid var(--line-hi); border-radius: 6px; padding: 3px 10px; color: var(--silver); font-size: 12.5px; }

.exit-perform { position: fixed; top: calc(14px + env(safe-area-inset-top, 0px)); right: 16px; z-index: 40; background: rgba(10,10,12,.6); }
body.perform .top, body.perform .side, body.perform .stage-tools, body.perform .transport, body.perform .tabbar, body.perform .mseg, body.perform .moods, body.perform .blend-pill { display: none !important; }
body.perform .app { padding: 0; grid-template-rows: 1fr; height: 100%; }
body.perform .studio { grid-template-columns: 1fr; grid-template-rows: 1fr; grid-template-areas: "stage"; }
body.perform .stage { border: 0; border-radius: 0; }

@media (max-width: 1180px) and (min-width: 900px) {
  .studio { grid-template-columns: 208px minmax(0, 1fr) 284px; }
  .moods { grid-template-columns: repeat(6, 128px); }
  #spec { width: 90px; }
}
@media (max-width: 899px) {
  body { overflow: auto; }
  .app { height: auto; display: flex; flex-direction: column; gap: 12px; padding-block: env(safe-area-inset-top, 0px) calc(84px + env(safe-area-inset-bottom, 0px)); }
  .top { grid-template-columns: 1fr auto; height: 50px; }
  .top .tabs { display: none; }
  .top-right .label { display: none; }
  .mark { font-size: 19px; }
  .studio { display: flex; flex-direction: column; gap: 12px; }
  .stage-col { order: 1; }
  .mseg { order: 2; display: block; }
  .left { order: 3; overflow: visible; }
  .rack { order: 4; overflow: visible; }
  .moods { order: 5; grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; }
  .stage-area { height: 46vh; min-height: 260px; flex: none; }
  .hint { display: none; }
  .mseg .seg-mini { display: flex; width: 100%; }
  .mseg .seg-mini button { flex: 1; padding: 9px 6px; font-size: 13px; }
  [data-seg] { display: none !important; }
  body[data-mg="nodes"] [data-seg="nodes"],
  body[data-mg="shape"] [data-seg="shape"],
  body[data-mg="tune"] [data-seg="tune"],
  body[data-mg="mood"] [data-seg="mood"] { display: flex !important; }
  body[data-mg="mood"] .moods[data-seg="mood"] { display: grid !important; }
  .transport { grid-template-columns: minmax(0, 1fr) auto; gap: 10px 12px; }
  .sources { grid-column: 1 / -1; order: 3; }
  .master { order: 2; border: 0; padding: 0; gap: 8px; }
  .meter { order: 4; grid-column: 1 / -1; }
  #spec { width: 100%; height: 26px; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px)); background: rgba(13,13,16,.94); border-top: 1px solid var(--line); }
  .tabbar .tab { padding: 8px 0 4px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11.5px; border: 0; }
  .toast { top: calc(4px + env(safe-area-inset-top, 0px)); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.save-pop { position: fixed; top: calc(60px + env(safe-area-inset-top, 0px)); right: 16px; width: min(340px, calc(100vw - 32px)); z-index: 45; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: linear-gradient(180deg, #1c1c21, #121215); box-shadow: 0 24px 60px -20px rgba(0,0,0,.9); }
.save-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.save-form .num-in { font-family: var(--font-ui); font-size: 14px; padding: 8px 10px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.saved { padding: 0; max-height: 44vh; overflow-y: auto; }
.saved li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center; padding: 7px 0; border-top: 1px solid var(--line); }
.saved .row-name { font-size: 13.5px; }
.saved .empty { color: var(--dim); font-size: 12.5px; border: 0; display: block; }
