:root {
  --room: #121317;
  --panel-hi: #d9dbde; --panel-lo: #b9bcc1;   /* aluminium */
  --module: #c9ccd0; --groove: #9da1a8;
  --ink: #1d1f24; --ink-soft: #4a4f58;
  --screen: #0d1117; --screen-ink: #e9edf3; --screen-dim: #7d8794;
  --accent: #e5533d; --ok: #3bb27a; --warn: #e2a33a;
  --knob: #2a2d33; --knob-hi: #444851;
  --p1: #e5533d; --p2: #f08a24; --p3: #e8c547; --p4: #4cc38a; --p5: #3d8fe5; --p6: #a46be5;
  --part: var(--p1);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--room); color: var(--ink); font: 13px/1.35 -apple-system, "SF Pro Text", system-ui, sans-serif; }
button, select, input { font: inherit; }

/* Top bar */
header { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 12px 20px; background: #1b1d22; color: #e9edf3; border-bottom: 1px solid #000; position: sticky; top: 0; z-index: 10; }
header h1 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: .02em; }
header .spacer { flex: 1; }
header select, header button { background: #2a2d33; color: #e9edf3; border: 1px solid #3a3e46; border-radius: 6px; padding: 6px 10px; }
header button:hover { border-color: var(--accent); }
#midiStatus { font-size: 12px; color: var(--screen-dim); }
#midiStatus.ok { color: var(--ok); } #midiStatus.err { color: var(--accent); }

/* Hexagon part buttons */
.parts { display: flex; gap: 6px; align-items: center; }
.parts span { color: var(--screen-dim); font-size: 12px; margin-right: 4px; }
.hex { width: 38px; height: 34px; border: 0; cursor: pointer; clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%); background: #33373f; color: #c9cfd8; font-weight: 600; display: grid; place-items: center; }
.hex.active { background: var(--c); color: #111; box-shadow: 0 0 12px var(--c); }

/* Panel */
main { padding: 20px; max-width: 1480px; margin: 0 auto; }
.panel { background: linear-gradient(180deg, var(--panel-hi), var(--panel-lo)); border-radius: 14px; padding: 18px; box-shadow: 0 10px 40px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.6); margin-bottom: 20px; }
.panel-title { display: flex; align-items: baseline; gap: 10px; margin: 0 0 12px 4px; }
.panel-title h2 { margin: 0; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-soft); }
.panel-title .tag { font-size: 11px; color: var(--ink-soft); }
.row { display: grid; gap: 14px; margin-bottom: 14px; }
.row:last-child { margin-bottom: 0; }
.r3 { grid-template-columns: 1.3fr .7fr 1.3fr; }
.r4 { grid-template-columns: repeat(4, 1fr); }
.r2 { grid-template-columns: 1fr 1fr; }
.r21 { grid-template-columns: 2fr 1fr; }
@media (max-width: 1100px) { .r3, .r4, .r2, .r21 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 700px) { .r3, .r4, .r2, .r21 { grid-template-columns: 1fr; } }

/* Module: milled relief look */
.module { background: var(--module); border-radius: 10px; padding: 12px 12px 14px; box-shadow: inset 0 2px 4px rgba(0,0,0,.18), inset 0 -1px 0 rgba(255,255,255,.5); }
.module h3 { margin: 0 0 10px; font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-soft); display: flex; align-items: center; gap: 8px; }
.module h3::before { content: ""; width: 8px; height: 8px; clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%); background: var(--part); }
.module.global h3::before { background: var(--ink-soft); }
.subhead { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); margin: 12px 0 6px; padding-top: 8px; border-top: 1px solid var(--groove); }
.controls { display: flex; flex-wrap: wrap; gap: 10px 8px; }

/* Tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 10px; flex-wrap: wrap; }
.tabs button { border: 0; background: var(--groove); color: var(--ink); border-radius: 5px; padding: 4px 9px; font-size: 11.5px; cursor: pointer; }
.tabs button.on { background: var(--knob); color: #fff; }

/* Controls */
.ctl { width: 74px; display: flex; flex-direction: column; align-items: center; gap: 3px; position: relative; }
.ctl.wide { width: 128px; }
.ctl .name { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink); text-align: center; line-height: 1.15; min-height: 24px; display: flex; align-items: flex-end; }
.ctl .val { font: 11px/1 ui-monospace, Menlo, monospace; background: var(--screen); color: var(--screen-ink); border-radius: 3px; padding: 3px 5px; min-width: 56px; text-align: center; }
.ctl.unsent .val { color: var(--screen-dim); }
.ctl.unsent svg .ind { opacity: .35; }
.knob { width: 46px; height: 46px; cursor: ns-resize; touch-action: none; }
.knob .body { fill: var(--knob); stroke: #111; }
.knob .track { fill: none; stroke: #8e939b; stroke-width: 3; }
.knob .arc { fill: none; stroke: var(--part); stroke-width: 3; stroke-linecap: round; }
.knob .ind { stroke: #fff; stroke-width: 2.5; stroke-linecap: round; }
.ctl select { width: 100%; background: var(--screen); color: var(--screen-ink); border: 1px solid #000; border-radius: 4px; padding: 4px; font-size: 11.5px; }
.ctl.unsent select { color: var(--screen-dim); }
.ctl .chk { position: absolute; top: -2px; right: 2px; width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--ink-soft); background: transparent; cursor: pointer; padding: 0; font-size: 10px; line-height: 12px; color: transparent; }
.ctl .chk.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.ctl.flag .name::after { content: " ?"; color: var(--warn); font-weight: 700; }
.note { font-size: 10px; color: var(--ink-soft); text-align: center; }
.hidden { display: none !important; }

/* Keyboard */
.kb-wrap { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.kb-tools { display: flex; flex-direction: column; gap: 8px; min-width: 180px; }
.kb-tools button { border: 1px solid var(--groove); background: var(--knob); color: #fff; border-radius: 6px; padding: 6px 10px; cursor: pointer; }
.kb-tools button.on { background: var(--part); color: #111; }
.kb-tools label { font-size: 11px; color: var(--ink-soft); display: flex; flex-direction: column; gap: 4px; }
.kb { position: relative; height: 130px; flex: 1; min-width: 420px; user-select: none; touch-action: none; }
.kb .w, .kb .b { position: absolute; top: 0; border-radius: 0 0 5px 5px; cursor: pointer; }
.kb .w { height: 130px; background: linear-gradient(#fafafa, #e7e7e7); border: 1px solid #777; }
.kb .b { height: 80px; background: linear-gradient(#333, #111); z-index: 2; border: 1px solid #000; }
.kb .down { background: var(--part) !important; }
.kb .lbl { position: absolute; bottom: 6px; width: 100%; text-align: center; font-size: 10px; color: #888; }
.kb .b .lbl { color: #777; bottom: 4px; }

/* Settings dialog */
dialog { border: 0; border-radius: 12px; padding: 20px; background: #1f2228; color: #e9edf3; min-width: 320px; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin: 0 0 12px; font-size: 15px; }
dialog .grid { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; align-items: center; }
dialog select { background: #2a2d33; color: #e9edf3; border: 1px solid #3a3e46; border-radius: 6px; padding: 4px 8px; }
dialog .actions { margin-top: 16px; display: flex; justify-content: flex-end; gap: 8px; }
dialog button { background: #2a2d33; color: #e9edf3; border: 1px solid #3a3e46; border-radius: 6px; padding: 6px 12px; cursor: pointer; }
footer { color: #6b7380; font-size: 11.5px; text-align: center; padding: 0 20px 24px; }
.r1 { grid-template-columns: 1fr; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 20px; background: #181a1f; border-bottom: 1px solid #000; }
.toolbar .tb-label { color: var(--screen-dim); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; margin-right: 4px; }
.toolbar .spacer { flex: 1; }
.toolbar button { background: #2a2d33; color: #e9edf3; border: 1px solid #3a3e46; border-radius: 6px; padding: 6px 12px; cursor: pointer; }
.toolbar button:hover { border-color: var(--accent); }
#speedDlg { max-width: 460px; }
#speedDlg ul { margin: 6px 0 12px; padding-left: 18px; line-height: 1.7; }
#stResult { color: var(--ok); min-height: 1.2em; }
.views { display: flex; border: 1px solid #3a3e46; border-radius: 7px; overflow: hidden; }
.views button { border: 0 !important; border-radius: 0 !important; padding: 6px 12px; }
.views button.on { background: var(--part) !important; color: #111 !important; }
.modwrap { display: grid; grid-template-columns: 1fr 340px; gap: 14px; align-items: start; }
@media (max-width: 1000px) { .modwrap { grid-template-columns: 1fr; } }
#modGraph { background: var(--screen); border-radius: 10px; padding: 6px; box-shadow: inset 0 2px 6px rgba(0,0,0,.5); overflow-x: auto; }
#modGraph svg { display: block; max-width: none; font-family: -apple-system, system-ui, sans-serif; }
.graph .colhead { fill: #6b7380; font-size: 11px; letter-spacing: .12em; }
.graph .node rect { fill: #1b2029; stroke: #343b47; stroke-width: 1.25; cursor: pointer; }
.graph .node.sel rect { stroke: var(--part); stroke-width: 2; }
.graph .node.math rect { fill: #1e2430; }
.graph .node.dest rect { fill: #232a35; }
.graph .node.other rect { fill: #20252e; }
.graph .nt { fill: #e9edf3; font-size: 13px; font-weight: 600; pointer-events: none; }
.graph .ns { fill: #9aa3b1; font-size: 11.5px; pointer-events: none; }
.graph .ns.small { font-size: 10.5px; }
.graph .wave { fill: none; stroke: var(--part); stroke-width: 1.75; pointer-events: none; }
.graph .phase { stroke: #fff; stroke-width: 1.5; opacity: .8; pointer-events: none; }
.graph .phase.blur { opacity: .25; stroke-width: 6; }
.graph .iconbg { fill: #11151c; }
.graph .icon { fill: none; stroke: #c9d1dc; stroke-width: 2.2; stroke-linejoin: round; }
.graph .jack { fill: #11151c; stroke: #6b7380; stroke-width: 1.5; }
.graph .jack.on, .graph .jack.out { fill: var(--part); stroke: var(--part); }
.graph .jl { fill: #c9d1dc; font-size: 11px; pointer-events: none; }
.graph .cable { fill: none; stroke-width: 2.25; }
.graph .cable.live { stroke: var(--part); opacity: .85; }
.graph .cable.dest { stroke: #f2f4f7; cursor: pointer; stroke-width: 2.5; }
.graph .cable.dest.todo { stroke-dasharray: 6 5; opacity: .75; }
.graph .cable.dest:hover { stroke: var(--part); }
.graph .amt { fill: #f2f4f7; font-size: 11.5px; font-weight: 600; }
.graph .amt.todo { fill: #9aa3b1; }
.graph .hint { fill: #6b7380; font-size: 12px; }
#modEditor { background: var(--module); border-radius: 10px; padding: 12px; box-shadow: inset 0 2px 4px rgba(0,0,0,.18); }
#modEditor h3 { margin: 0 0 10px; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-soft); }
#modEditor h3.sep { margin-top: 16px; padding-top: 10px; border-top: 1px solid var(--groove); }
#modEditor .help { font-size: 11.5px; color: var(--ink-soft); margin: 8px 0; }
#modEditor .gesture { font-size: 13px; font-weight: 600; background: var(--screen); color: var(--screen-ink); padding: 8px 10px; border-radius: 6px; }
.routes .route { display: grid; grid-template-columns: 18px 1fr 22px; gap: 6px; align-items: start; padding: 6px 0; border-bottom: 1px solid var(--groove); }
.routes .route .g { font-size: 11px; color: var(--ink-soft); margin-top: 2px; }
.routes .route.done b { color: #2a8a5c; }
.routes .del { border: 0; background: transparent; cursor: pointer; color: var(--ink-soft); }
.addform { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.addform label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--ink-soft); }
.addform select, .addform input { background: var(--screen); color: var(--screen-ink); border: 1px solid #000; border-radius: 4px; padding: 4px; }
.addform button { grid-column: 1 / -1; background: var(--knob); color: #fff; border: 0; border-radius: 6px; padding: 7px; cursor: pointer; }

/* ---------- Size settings (S = compact, M = medium, L = original) ---------- */
.sizes { display: flex; border: 1px solid #3a3e46; border-radius: 7px; overflow: hidden; }
.sizes button { border: 0 !important; border-radius: 0 !important; padding: 6px 10px; }
.sizes button.on { background: #e9edf3 !important; color: #111 !important; }
body.size-m main { padding: 14px; }
body.size-m .panel { padding: 14px; }
body.size-m .row { gap: 10px; margin-bottom: 10px; }
body.size-m .module { padding: 10px 10px 12px; }
body.size-m .ctl { width: 66px; }
body.size-m .ctl.wide { width: 112px; }
body.size-m .knob { width: 40px; height: 40px; }
body.size-m .controls { gap: 8px 6px; }

body.size-s { font-size: 12px; }
body.size-s main { padding: 10px 12px; max-width: none; }
body.size-s .panel { padding: 10px; border-radius: 10px; margin-bottom: 12px; }
body.size-s .panel-title { margin: 0 0 6px 2px; }
body.size-s .row { gap: 8px; margin-bottom: 8px; }
body.size-s .module { padding: 7px 8px 8px; border-radius: 8px; }
body.size-s .module h3 { margin: 0 0 5px; font-size: 10px; }
body.size-s .controls { gap: 5px 3px; }
body.size-s .ctl { width: 54px; gap: 1px; }
body.size-s .ctl.wide { width: 96px; }
body.size-s .ctl .name { font-size: 9px; min-height: 20px; letter-spacing: .03em; }
body.size-s .ctl .val { font-size: 9.5px; min-width: 46px; padding: 2px 3px; }
body.size-s .ctl select { font-size: 10px; padding: 2px; }
body.size-s .ctl .chk { width: 11px; height: 11px; font-size: 8px; line-height: 9px; top: 0; right: 0; }
body.size-s .knob { width: 32px; height: 32px; }
body.size-s .tabs { margin-bottom: 5px; }
body.size-s .tabs button { padding: 2px 7px; font-size: 10.5px; }
body.size-s .subhead { margin: 6px 0 4px; padding-top: 5px; font-size: 9.5px; }
body.size-s header { padding: 8px 12px; gap: 10px; }
body.size-s .toolbar { padding: 6px 12px; }
body.size-s .toolbar button, body.size-s header button, body.size-s header select { padding: 4px 8px; }
body.size-s .hex { width: 32px; height: 28px; }
body.size-s .kb { height: 100px; }
body.size-s .kb .w { height: 100px; } body.size-s .kb .b { height: 62px; }
/* compact layout: envelopes, LFOs, Math and Arp side by side on wide screens */
@media (min-width: 1500px) {
  body.size-s .row.r2, body.size-s .row.r21 { grid-template-columns: 1fr 1fr; }
  body.size-s .rowCD { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
  body.size-s .rowCD > .row { margin-bottom: 0; }
}

/* Modulation page follows the size switch: graph column sized to the drawing */
.modwrap { grid-template-columns: max-content 340px; justify-content: start; }
body.size-s .modwrap { grid-template-columns: max-content 290px; }
body.size-s #modEditor { padding: 8px; }
body.size-l .modwrap { grid-template-columns: max-content 380px; }
@media (max-width: 1000px) { .modwrap, body.size-s .modwrap, body.size-l .modwrap { grid-template-columns: 1fr; } }

/* ---------- floating hand-steps window ---------- */
.todo { position: fixed; right: 20px; bottom: 20px; width: 380px; max-height: 70vh; display: flex; flex-direction: column; z-index: 50;
  background: #2b2112; color: #fff3df; border: 2px solid var(--warn); border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.6); overflow: hidden; }
.todo-head { display: flex; align-items: center; gap: 8px; padding: 9px 10px 9px 12px; background: var(--warn); color: #1d1405; font-weight: 700; font-size: 13px; cursor: move; user-select: none; touch-action: none; }
.todo-icon { width: 20px; height: 20px; border-radius: 50%; background: #1d1405; color: var(--warn); display: grid; place-items: center; font-size: 13px; }
.todo-spacer { flex: 1; }
.todo-head button { border: 0; background: rgba(0,0,0,.18); color: #1d1405; border-radius: 5px; width: 24px; height: 22px; cursor: pointer; font-weight: 700; }
.todo-body { padding: 10px 12px 12px; overflow: auto; }
.todo-lead { font-size: 12px; color: #f3dcb6; margin-bottom: 8px; }
.todo-item { display: grid; grid-template-columns: 22px 1fr; gap: 8px; align-items: start; padding: 9px 8px; margin-bottom: 6px; background: rgba(226,163,58,.12); border: 1px solid rgba(226,163,58,.45); border-radius: 8px; cursor: pointer; }
.todo-item input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--ok); cursor: pointer; }
.todo-step { font-size: 13px; font-weight: 600; line-height: 1.35; }
.todo-why { font-size: 11px; color: #d8c29c; margin-top: 3px; }
.todo-foot, .todo-others { font-size: 11px; color: #d8c29c; margin-top: 6px; }
.todo.clear { border-color: var(--ok); background: #13261d; color: #dff5ea; }
.todo.clear .todo-head { background: var(--ok); color: #06150e; }
.todo.clear .todo-icon { background: #06150e; color: var(--ok); }
.todo.clear .todo-lead { color: #bfe6d2; }
.todo.min .todo-body { display: none; }
.todo.min { width: auto; }
.todo.pulse { animation: todoPulse 1.2s ease-out 2; }
@keyframes todoPulse { 0% { box-shadow: 0 0 0 0 rgba(226,163,58,.8), 0 12px 40px rgba(0,0,0,.6); } 100% { box-shadow: 0 0 0 18px rgba(226,163,58,0), 0 12px 40px rgba(0,0,0,.6); } }
body.size-s .todo { width: 330px; }
body.size-s .todo-step { font-size: 12px; }

/* ---------- compact keyboard under the patch (Modulation page) ---------- */
.modleft { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
#kbSlot .panel { margin: 0; padding: 8px 10px; border-radius: 10px; box-shadow: none; background: var(--module); }
.kb-compact .panel-title { margin: 0 0 6px; }
.kb-compact .panel-title h2 { font-size: 10px; }
.kb-compact .panel-title .tag { font-size: 10px; }
.kb-compact .kb-wrap { flex-direction: column; gap: 6px; }
.kb-compact .kb-tools { flex-direction: row; flex-wrap: wrap; align-items: flex-end; gap: 8px; min-width: 0; }
.kb-compact .kb-tools label { font-size: 10px; flex-direction: row; align-items: center; gap: 4px; }
.kb-compact .kb-tools button, .kb-compact .kb-tools select { font-size: 11px; padding: 3px 7px; }
.kb-compact .kb-tools input[type=range] { width: 80px; }
.kb-compact .kb { height: 70px !important; min-width: 0; width: 100%; flex: none; }
.kb-compact .kb .w { height: 70px !important; }
.kb-compact .kb .b { height: 44px !important; }
.kb-compact .kb .lbl { font-size: 8.5px; bottom: 3px; }

/* ---------- S size: pack modules by content instead of fixed columns ---------- */
body.size-s #main .panel { display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; }
body.size-s #main .panel-title { flex-basis: 100%; margin-bottom: 0; }
body.size-s #main .row, body.size-s #main .rowCD { display: contents; }
body.size-s #main .module { flex: 1 1 auto; min-width: 0; }
body.size-s #main .module .controls { flex-wrap: wrap; }
body.size-s #main .module.tabbed { min-width: 330px; }
.graph .cable.dest:hover, .graph .cable.live:hover { stroke-width: 4; }
.graph .cable.dest.todo { opacity: .7; }
.graph .node .stripe { pointer-events: none; }

/* ---------- Character strip ---------- */
.ctl.charstrip { width: 250px; }
body.size-s .ctl.charstrip { width: 210px; }
.cs-track { position: relative; width: 100%; height: 30px; margin-top: 16px; background: var(--screen); border-radius: 5px; cursor: ew-resize; touch-action: none; }
.cs-seg { position: absolute; top: 0; bottom: 0; border-left: 1px solid #3a4250; }
.cs-seg:first-child { border-left: 0; }
.cs-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--part); opacity: .22; border-radius: 5px 0 0 5px; pointer-events: none; }
.cs-mark { position: absolute; top: -3px; bottom: -3px; width: 3px; margin-left: -1.5px; background: #fff; border-radius: 2px; box-shadow: 0 0 6px var(--part); pointer-events: none; }
.cs-val { min-width: 100% !important; margin-top: 3px; }
.ctl.unsent .cs-mark { opacity: .4; }
.cs-lab { position: absolute; top: -19px; border: 0; background: transparent; padding: 0; font-size: 14px; line-height: 1; cursor: pointer; transform-origin: center bottom; transition: opacity .12s, filter .12s, transform .12s; }
.cs-lab:hover { opacity: 1 !important; filter: none !important; }

/* =================== Redshift hardware theme =================== */
:root {
  --room: #0b0b0c;
  --panel-hi: #2e2e31; --panel-lo: #262628;
  --module: #212124; --groove: #3c3c41;
  --ink: #ececee; --ink-soft: #a3a3aa;
  --screen: #050506; --screen-ink: #f4f4f4; --screen-dim: #6f6f76;
  --knob: #141416; --knob-hi: #2a2a2e;
  --led: #ff3b30; --led-soft: rgba(255, 59, 48, .55);
  --hw-blue: #3ea6ff;
  --silver: #8d898b; --char-blue: #1f4866; --drive-red: #6b1d29; --vcf-red: #651c2a;
}
body { background: var(--room); }
header, .toolbar { background: #0f0f10; border-bottom-color: #222; }
.panel { background: linear-gradient(180deg, var(--panel-hi), var(--panel-lo)); box-shadow: 0 10px 40px rgba(0,0,0,.7), inset 0 1px 0 rgba(255,255,255,.06); }
.panel-title h2 { color: #d9d9dd; }
.panel-title .tag { color: var(--hw-blue); }
.module { background: var(--module); border: 1px solid #3a3a3f; box-shadow: inset 0 1px 0 rgba(255,255,255,.04); }
.module h3, #modEditor h3 { color: #d9d9dd; letter-spacing: .14em; }
.module h3::before { background: var(--led); box-shadow: 0 0 6px var(--led); }
.module.global h3::before { background: var(--hw-blue); box-shadow: 0 0 6px var(--hw-blue); }
.subhead { color: var(--ink-soft); border-top-color: var(--groove); }

/* coloured sections, like the panel */
.module.m-dco { background: linear-gradient(180deg, #96928f, var(--silver)); border-color: #aaa6a4; }
.module.m-dco h3, .module.m-dco .ctl .name { color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,.35); }
.module.m-character-drive { background: linear-gradient(90deg, var(--char-blue) 0 58%, var(--drive-red) 58% 100%); border-color: #4a4a52; }
.module.m-vcf { background: var(--vcf-red); border-color: #82303d; }
.module.m-vcf .subhead { border-top-color: rgba(255,255,255,.18); color: #e8c9ce; }

/* knobs: black bodies, light caps on the big panel controls, red LED arcs */
.knob .body { fill: #151517; stroke: #000; }
.knob .track { stroke: #3a3a40; }
.knob .arc { stroke: var(--led); filter: drop-shadow(0 0 2px var(--led)); }
.knob .ind { stroke: #f2f2f2; }
.module.m-character-drive .knob .body, .module.m-vcf .controls > .ctl:nth-child(-n+2) .knob .body { fill: #d6d6d8; stroke: #8a8a8f; }
.module.m-character-drive .knob .ind, .module.m-vcf .controls > .ctl:nth-child(-n+2) .knob .ind { stroke: #1a1a1c; }
.module.m-dco .knob .track { stroke: #6b6866; }

/* screen-style readouts and dropdowns */
.ctl .val { background: #000; color: #f4f4f4; border: 1px solid #2a2a2e; letter-spacing: .02em; }
.ctl select, .addform select, .addform input { background: #000; color: #f4f4f4; border-color: #2a2a2e; }

/* hexagonal buttons with red LED outlines */
.tabs button { background: #2a2a2e; color: #e0e0e4; border: 1px solid #44444a; clip-path: polygon(8px 0, calc(100% - 8px) 0, 100% 50%, calc(100% - 8px) 100%, 8px 100%, 0 50%); padding: 4px 12px; }
.tabs button.on { background: #1a0d0d; color: var(--led); border-color: var(--led); box-shadow: inset 0 0 0 1px var(--led); text-shadow: 0 0 6px var(--led-soft); }
.toolbar button, header button, header select { background: #1d1d20; border-color: #3a3a40; }
.toolbar button:hover, header button:hover { border-color: var(--led); color: #fff; box-shadow: 0 0 8px var(--led-soft); }
.views button.on, .sizes button.on { background: var(--led) !important; color: #fff !important; }
.hex { background: #8e8e93; color: #1a1a1c; }
.hex.active { box-shadow: 0 0 14px var(--c); outline: 2px solid var(--c); }
.kb-tools button { background: #1d1d20; border-color: #3a3a40; }

/* Character strip sits on the blue half */
.cs-track { background: #000; }
.cs-mark { box-shadow: 0 0 6px #fff; }
.cs-fill { background: var(--hw-blue); }

/* Modulation page side panel and routing list on dark */
#modEditor { background: var(--module); border: 1px solid #3a3a3f; }
#modEditor .help, .routes .route .g { color: var(--ink-soft); }
.routes .route { border-bottom-color: var(--groove); }
.routes .route.done b { color: #4cd38a; }
.addform button { background: #1a0d0d; border: 1px solid var(--led); color: var(--led); }
dialog { background: #19191b; border: 1px solid #3a3a40; }
footer { color: #6f6f76; }
/* Character & Drive: exact 50/50 split, Character on the blue half and Drive on the red, each centred in its half */
.module.m-character-drive { background: linear-gradient(90deg, var(--char-blue) 0 50%, var(--drive-red) 50% 100%); }
.module.m-character-drive .controls { flex-wrap: nowrap; }
.module.m-character-drive .controls > .ctl { flex: 1 1 0; min-width: 0; }
.module.m-character-drive .controls > .ctl.charstrip { order: -1; padding: 0 12px; }
.module.m-character-drive .controls > .ctl:not(.charstrip) { min-width: 74px; }
.module.m-character-drive { min-width: 440px; }
/* Macro names */
.ctl.macro { width: 92px; }
body.size-s .ctl.macro { width: 78px; }
.macro-name { width: 100%; background: transparent; border: 0; border-bottom: 1px dashed #55555c; color: #fff; font: 600 11px/1.3 -apple-system, system-ui, sans-serif; text-align: center; padding: 1px 2px; }
.macro-name:focus { outline: none; border-bottom: 1px solid var(--hw-blue); }
.macro-name::placeholder { color: #66666d; font-weight: 400; }
.macro-what { font-size: 9.5px; line-height: 1.25; color: var(--hw-blue); text-align: center; min-height: 24px; max-width: 100%; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.macro-what.none { color: #5c5c63; }
.addknobs { display: flex; justify-content: space-around; align-items: flex-end; }
.addform .addknobs { grid-column: 2; }
.ctl.lk .name { min-height: 14px; }

/* ---------- Add routing form ---------- */
.rf { display: flex; flex-direction: column; gap: 10px; }
.rf-row { display: grid; grid-template-columns: 44px 1fr; align-items: center; gap: 8px; }
.rf-lab { font-size: 11px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .08em; }
.rf select { width: 100%; background: #000; color: #f4f4f4; border: 1px solid #2a2a2e; border-radius: 5px; padding: 5px 6px; }
.rf-via { display: flex; flex-direction: column; gap: 8px; padding: 8px; border: 1px dashed #3a3a40; border-radius: 8px; }
.rf-via.off .ls { opacity: .35; pointer-events: none; }
.ls-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 5px; }
.ls-label { font-size: 11px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .08em; }
.ls-val { font: 600 13px ui-monospace, Menlo, monospace; color: #fff; background: #000; padding: 2px 6px; border-radius: 4px; min-width: 52px; text-align: right; }
.ls.zero .ls-val { color: #77777e; }
.ls-track { position: relative; height: 14px; background: #000; border: 1px solid #2a2a2e; border-radius: 7px; cursor: ew-resize; touch-action: none; }
.ls-zero { position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: #66666d; }
.ls-fill { position: absolute; top: 2px; bottom: 2px; background: var(--led); border-radius: 4px; box-shadow: 0 0 6px var(--led-soft); }
.ls-thumb { position: absolute; top: -4px; width: 6px; height: 20px; margin-left: -3px; background: #f2f2f2; border-radius: 3px; box-shadow: 0 0 4px rgba(0,0,0,.6); pointer-events: none; }
.ls-ends { display: flex; justify-content: space-between; font-size: 9.5px; color: #5c5c63; margin-top: 3px; }
.rf-preview { display: flex; align-items: center; gap: 0; padding: 10px 6px; background: #050506; border-radius: 8px; }
.rf-chip { flex: none; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; font-weight: 600; padding: 4px 8px; border: 1.5px solid; border-radius: 6px; }
.rf-chip.dest { border-color: #8a93a3; color: #e6e9ee; }
.rf-wire { position: relative; flex: 1; height: 2.5px; margin: 0 4px; border-radius: 2px; }
.rf-wire::after { content: ''; position: absolute; right: -2px; top: -4px; border: 5px solid transparent; border-left-color: inherit; border-left: 7px solid #8a93a3; }
.rf-amt { position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%); font-size: 11px; font-weight: 700; white-space: nowrap; }
.rf-add { background: #1a0d0d; border: 1px solid var(--led); color: var(--led); border-radius: 7px; padding: 8px; cursor: pointer; font-weight: 600; }
.rf-add:disabled { opacity: .4; cursor: default; }
/* Character & Drive spacing */
.module.m-character-drive { min-width: 500px; padding-bottom: 12px; }
.module.m-character-drive .controls { align-items: center; padding-top: 4px; }
.module.m-character-drive .controls > .ctl.charstrip { padding: 0 22px 0 6px; gap: 0; }
.ctl.charstrip .name { min-height: 0; margin-bottom: 30px; }
.ctl.charstrip .cs-track { margin-top: 0; height: 34px; }
.ctl.charstrip .cs-lab { top: -26px; font-size: 16px; }
.ctl.charstrip .cs-val { margin-top: 8px; }
.module.m-character-drive .controls > .ctl:not(.charstrip) { gap: 6px; }
.module.m-character-drive .controls > .ctl:not(.charstrip) .name { min-height: 0; margin-bottom: 8px; }
body.size-s .module.m-character-drive { min-width: 440px; }
.ctl .val { cursor: text; }
.val-edit { width: 100%; min-width: 40px; background: #000; color: #fff; border: 0; outline: 1px solid var(--hw-blue); border-radius: 2px; font: inherit; text-align: center; padding: 0; }
.module.m-character-drive h3 { margin-left: -4px; letter-spacing: .1em; }
/* Group: hand-set on the Redshift */
.ctl.handset select { border: 1px dashed var(--warn); }
.ctl.handset .val { color: #8a8a90; }
.ctl.handset.pending .val { color: #1d1405; background: var(--warn); }
.hex { position: relative; }
.hex[data-group]:not([data-group=""])::after { content: attr(data-group); position: absolute; right: 7px; bottom: 3px; font-size: 9px; font-weight: 800; color: #fff; background: #111; border-radius: 3px; padding: 0 2px; line-height: 11px; }

dialog.ask input { width: 280px; background: #000; color: #fff; border: 1px solid #3a3a40; border-radius: 6px; padding: 7px 9px; font-size: 14px; }
dialog.ask .primary { border-color: var(--led); color: #fff; }
/* editing and removing routings */
.rf-remove { background: transparent; border: 1px solid #55555c; color: #c9c9ce; border-radius: 7px; padding: 6px; cursor: pointer; }
.rf-remove:hover { border-color: var(--led); color: var(--led); }
.routes .rt { cursor: pointer; }
.routes .route.sel { background: rgba(62,166,255,.08); }
.routes .route.removing b { color: var(--led); text-decoration: line-through; }
.graph .cable.dest.removing { stroke-dasharray: 2 5; opacity: .45; }

.todo-item { grid-template-columns: 22px 1fr auto !important; }
.todo-cancel { align-self: center; background: transparent; border: 1px solid rgba(255,255,255,.25); color: #f3dcb6; border-radius: 6px; padding: 3px 8px; font-size: 11px; cursor: pointer; }
.todo-cancel:hover { border-color: #fff; color: #fff; }
.todo.clear .todo-cancel { color: #bfe6d2; }

.editbox { border: 1.5px solid var(--hw-blue); border-radius: 10px; padding: 10px; margin: 10px 0 4px; background: rgba(62,166,255,.06); }
.editbox-title { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--hw-blue); margin-bottom: 8px; }

/* ---------- Audiowide for the app title and panel titles (font: SIL Open Font License, see fonts/OFL-Audiowide.txt) ---------- */
@font-face { font-family: 'Audiowide'; src: url('fonts/Audiowide-Regular.ttf') format('truetype'); font-weight: 400; font-display: block; }
header h1, .panel-title h2, .module h3, #modEditor h3 { font-family: 'Audiowide', -apple-system, system-ui, sans-serif; font-weight: 400; }
header h1 { font-size: 17px; letter-spacing: .03em; }
.panel-title h2 { letter-spacing: .1em; }
.module h3, #modEditor h3 { letter-spacing: .1em; }
.module.m-character-drive h3 { letter-spacing: .06em; white-space: nowrap; }
body.size-s .module h3 { font-size: 10px; }

header h1 .sub { font-family: -apple-system, system-ui, sans-serif; font-size: 11px; letter-spacing: .06em; color: var(--ink-soft); margin-left: 6px; font-weight: 500; }

/* header: title left, parts centred, MIDI and settings right */
header { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; }
header .hl, header .hc, header .hr { display: flex; align-items: center; gap: 10px; min-width: 0; }
header .hc { gap: 14px; }
header .hr { justify-content: flex-end; flex-wrap: wrap; }
header h1 { white-space: nowrap; }
#midiStatus { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
@media (max-width: 1350px) {
  header { grid-template-columns: 1fr; justify-items: center; }
  header .hl, header .hr { justify-content: center; }
}

/* MIDI in activity readout */
.midi-act { font: 11px/1.3 ui-monospace, Menlo, monospace; background: #000; color: #77777e; border: 1px solid #2a2a2e; border-radius: 5px; padding: 4px 8px; white-space: nowrap; transition: color .3s, border-color .3s; }
.midi-act b { color: #c9c9ce; font-weight: 600; }
.midi-act span { color: var(--hw-blue); }
.midi-act i { font-style: normal; color: #77777e; }
.midi-act.on { color: #e9e9ec; border-color: var(--hw-blue); transition: none; }
.midi-act.on b { color: #fff; }

/* thinner four-octave keyboard */
.kb, body.size-s .kb { height: 80px !important; }
.kb .w, body.size-s .kb .w { height: 80px !important; }
.kb .b, body.size-s .kb .b { height: 50px !important; }
.kb-compact .kb { height: 56px !important; }
.kb-compact .kb .w { height: 56px !important; }
.kb-compact .kb .b { height: 35px !important; }
.kb .lbl { font-size: 9px; bottom: 4px; }
/* keyboard controls in one row above the keys on both pages */
.kb-wrap { flex-direction: column; gap: 8px; }
.kb-tools { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; min-width: 0; }
.kb-tools label { flex-direction: row; align-items: center; gap: 5px; }
.kb-tools button, .kb-tools select { padding: 4px 8px; }
.kb-tools input[type=range] { width: 90px; }
.kb { width: 100%; min-width: 0; flex: none; }
/* MIDI activity readout: fixed size so the row never shifts */
.midi-act { box-sizing: border-box; width: 300px; height: 24px; flex: none; overflow: hidden; text-overflow: ellipsis; display: inline-flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.midi-act > * { flex: none; }

/* footer: tips in the middle, credit bottom right */
footer { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; text-align: center; }
footer .tips { grid-column: 2; }
footer .credit { grid-column: 3; justify-self: end; color: #77777e; text-decoration: none; font-size: 11px; letter-spacing: .03em; white-space: nowrap; }
footer .credit:hover { color: #fff; text-decoration: underline; }
@media (max-width: 1100px) { footer { grid-template-columns: 1fr; } footer .tips, footer .credit { grid-column: 1; justify-self: center; } }

header h1 .sub a { color: inherit; text-decoration: none; }
header h1 .sub a:hover { color: #fff; text-decoration: underline; }

/* ---------- more prominent part selector and page switch ---------- */
header .hc { gap: 22px; }
.parts { gap: 8px; }
.parts span { font-family: 'Audiowide', sans-serif; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: #c9c9ce; margin-right: 6px; }
.hex, body.size-s .hex {
  width: 50px; height: 44px; font-family: 'Audiowide', sans-serif; font-size: 16px;
  background: color-mix(in srgb, var(--c) 28%, #1d1d20); color: color-mix(in srgb, var(--c) 70%, #ffffff);
  transition: transform .12s, background .12s, box-shadow .12s;
}
.hex:hover { background: color-mix(in srgb, var(--c) 50%, #1d1d20); color: #fff; }
.hex.active { background: var(--c); color: #111; transform: scale(1.12); filter: drop-shadow(0 0 8px var(--c)); box-shadow: none; outline: none; }
.hex[data-group]:not([data-group=""])::after { right: 9px; bottom: 5px; }
.views { border-radius: 9px; border-color: #44444a; }
.views button { font-family: 'Audiowide', sans-serif; font-size: 13px; letter-spacing: .06em; padding: 10px 18px !important; background: #1d1d20 !important; color: #c9c9ce !important; }
.views button:hover { color: #fff !important; }
.views button.on { background: var(--led) !important; color: #fff !important; box-shadow: inset 0 0 10px rgba(0,0,0,.25); }
.views button:focus, .views button:focus-visible, .hex:focus { outline: none; }
.hex.active, body.size-s .hex.active { background: var(--c); color: #111; transform: scale(1.14); filter: drop-shadow(0 0 9px var(--c)); }
body.size-s .hex:hover:not(.active) { background: color-mix(in srgb, var(--c) 50%, #1d1d20); color: #fff; }

/* switched-off parts look dimmed in the part selector */
.hex.disabled:not(.active) { opacity: .4; }
.hex.disabled.active, body.size-s .hex.disabled.active { filter: none; opacity: .65; }   /* selected but switched off: no glow */

/* stacked title: app name centred above the subtitle, block stays top left */
header .hl { justify-content: flex-start; }
header h1 { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; margin: 0; line-height: 1.05; }
header h1, body.size-s header h1 { font-size: 34px; letter-spacing: .04em; }
header h1 .sub { margin-left: 0; font-size: 16.5px; letter-spacing: .03em; line-height: 1.2; }
header .hl { padding-left: 14px; }
/* copyright in Playfair Display (SIL Open Font License, see fonts/OFL-Playfair.txt) */
@font-face { font-family: 'Playfair Display'; src: url('fonts/PlayfairDisplay.ttf') format('truetype'); font-weight: 400 900; font-display: block; }
footer .credit { font-family: 'Playfair Display', Georgia, serif; font-size: 13px; letter-spacing: .02em; }

/* email and copyright side by side, bottom right */
footer .credits { grid-column: 3; justify-self: end; display: flex; align-items: baseline; gap: 10px; white-space: nowrap; }
footer .credits .sep { color: #55555c; font-family: 'Playfair Display', Georgia, serif; }
@media (max-width: 1100px) { footer .credits { grid-column: 1; justify-self: center; } }

/* tips live in the keyboard panel; the page footer is just contact info, bottom right */
.kb-tips { margin-left: auto; font-size: 11px; color: #77777e; text-align: right; }
.kb-compact .kb-tips { font-size: 10px; max-width: 60%; }
footer { display: flex; justify-content: flex-end; padding: 0 22px 18px; }
footer .credits { grid-column: auto; justify-self: auto; }
@media (max-width: 1100px) { footer { justify-content: center; } }
.kb-compact .kb-tips { max-width: none; min-width: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kb-compact .panel-title { display: flex; min-width: 0; }

/* sparse modules (e.g. Clock): controls centred both ways, larger knobs */
body.size-s #main .module.sparse { display: flex; flex-direction: column; }
body.size-s #main .module.sparse > .controls { flex: 1; justify-content: center; align-content: center; align-items: center; gap: 10px 22px; }
.module.sparse .ctl { width: 84px; gap: 4px; }
.module.sparse .knob, body.size-s .module.sparse .knob { width: 56px; height: 56px; }
.module.sparse .ctl .name, body.size-s .module.sparse .ctl .name { font-size: 11px; min-height: 0; }
.module.sparse .ctl .val, body.size-s .module.sparse .ctl .val { font-size: 12px; min-width: 64px; padding: 3px 6px; }
.module.sparse .ctl select { font-size: 12px; }

/* centre every panel's controls (Character & Drive keeps its own split layout) */
body.size-s #main .module:not(.m-character-drive) .controls { justify-content: center; }
body.size-s #main .module .tabs { justify-content: center; }
body.size-s #main .module .subhead { text-align: center; }
body.size-s #main .module.single { display: flex; flex-direction: column; }
body.size-s #main .module.single > .controls { flex: 1; align-content: center; align-items: flex-start; }
body.size-s #main .module.single.sparse > .controls { align-items: center; }

/* knob scale per panel (--ks set by fitKnobs; 1 = normal, up to 1.5) */
body.size-s #main .module:not(.sparse):not(.m-character-drive) .ctl { width: calc(54px * var(--ks, 1)); }
body.size-s #main .module:not(.sparse):not(.m-character-drive) .ctl.wide { width: calc(96px * var(--ks, 1)); }
body.size-s #main .module:not(.sparse):not(.m-character-drive) .ctl.macro { width: calc(78px * var(--ks, 1)); }
body.size-s #main .module:not(.sparse):not(.m-character-drive) .knob { width: calc(32px * var(--ks, 1)); height: calc(32px * var(--ks, 1)); }
body.size-s #main .module:not(.sparse):not(.m-character-drive) .ctl .name { font-size: calc(9px * min(var(--ks, 1), 1.22)); }
body.size-s #main .module:not(.sparse):not(.m-character-drive) .ctl .val { font-size: calc(9.5px * min(var(--ks, 1), 1.22)); min-width: calc(46px * min(var(--ks, 1), 1.22)); }
body.size-s #main .module:not(.sparse):not(.m-character-drive) .ctl select { font-size: calc(10px * min(var(--ks, 1), 1.2)); }

/* Modulation page: keep the right-hand editor visible at any window width.
   The graph column may shrink (the graph scales down to fit) instead of pushing the editor off-screen. */
.modwrap, body.size-s .modwrap, body.size-l .modwrap { grid-template-columns: minmax(0, max-content) 290px; }
#modGraph svg { max-width: 100%; height: auto; }
@media (max-width: 760px) {
  .modwrap, body.size-s .modwrap, body.size-l .modwrap { grid-template-columns: 1fr; }
}

/* ---------- Settings: channel map, channel test ---------- */
dialog.settings { width: 460px; max-height: 88vh; overflow-y: auto; }
dialog.settings h2 { font-family: 'Audiowide', sans-serif; font-weight: 400; letter-spacing: .06em; }
dialog.settings h3 { font-family: 'Audiowide', sans-serif; font-weight: 400; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: #d9d9dd; margin: 18px 0 6px; padding-top: 12px; border-top: 1px solid #3a3a40; }
dialog.settings h3:first-of-type { border-top: 0; padding-top: 0; margin-top: 4px; }
.set-lead { font-size: 12px; color: #a3a3aa; margin: 0 0 8px; line-height: 1.45; }
.set-mpe { font-size: 12px; background: #000; border: 1px solid #2a2a2e; border-radius: 6px; padding: 6px 9px; margin-bottom: 10px; color: #c9c9ce; }
dialog.settings .grid { grid-template-columns: 90px 70px; justify-content: center; background: #0d1530; border: 1px solid #2a3a6a; border-radius: 8px; padding: 10px 14px; gap: 6px 14px; }
.cg-lab { text-align: right; font-weight: 600; }
.cg-lab.clash { color: var(--led); }
dialog.settings select.clash { border-color: var(--led); color: var(--led); }
.chan-warn { margin-top: 8px; font-size: 12px; color: #ffd0cc; background: rgba(255,59,48,.12); border: 1px solid var(--led); border-radius: 6px; padding: 7px 9px; line-height: 1.45; }
.set-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.set-hint { font-size: 11px; color: #77777e; }
dialog.settings button:disabled { opacity: .5; cursor: default; }
dialog.settings button.primary { border-color: var(--led); color: #fff; }
#chanTest { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.ct-q { font-size: 13px; font-weight: 600; }
.ct-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.ct-note { font-size: 11px; color: #8a8a90; }
.ct-sum { font-size: 12px; border-radius: 6px; padding: 7px 9px; line-height: 1.5; }
.ct-sum.ok { background: rgba(76,211,138,.12); border: 1px solid #4cd38a; color: #c8f2da; }
.ct-sum.bad { background: rgba(226,163,58,.12); border: 1px solid var(--warn); color: #f3dcb6; }
.ct-sum span { color: #d8c29c; font-size: 11px; }
