:root {
  --bg: #121214;
  --panel: #1b1b1e;
  --tile: #2c2c30;
  --tile-empty: #1d1d20;
  --line: #34343a;
  --text: #ececf0;
  --dim: #9a9aa4;
  --faint: #5b5b64;
  --accent: #ffb000;
  --good: #87d787;
  --hot: #ff5f5f;
  --bus1: #5fafff;
  --bus2: #ff3b30;
  --bus3: #3ddc84;
  --bus4: #ffb300;
  --ink: #161618;
  --gap: 8px;
  --r: 12px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; overscroll-behavior: none; }
html { touch-action: pan-x pan-y; }
body { font: 15px/1.25 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; touch-action: pan-x pan-y; -webkit-user-select: none; user-select: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; touch-action: pan-x pan-y; }
small { color: var(--dim); font-size: .72em; letter-spacing: .08em; font-weight: 600; }
b { font-weight: 700; }
code { background: var(--tile); padding: 1px 6px; border-radius: 6px; }

/* ---- connect screen ---- */
.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; background: var(--bg); z-index: 5; overflow: auto; }
#connectForm { width: min(420px, 100%); display: grid; gap: 14px; }
#connectForm h1 { margin: 0; font-size: 44px; letter-spacing: -1px; color: var(--accent); }
#connectForm h1 span { color: var(--text); }
#connectForm p { margin: 0; color: var(--dim); }
#connectForm label { display: grid; gap: 6px; color: var(--dim); font-size: 13px; }
#connectForm input { font: inherit; font-size: 18px; padding: 14px; border-radius: var(--r); border: 1px solid var(--line); background: var(--panel); color: var(--text); -webkit-user-select: text; user-select: text; }
.err { color: var(--hot) !important; min-height: 1.2em; }

/* ---- app frame ---- */
#app { position: fixed; inset: 0; display: grid; gap: var(--gap);
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
#top { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 28px; }
.brand { font-weight: 800; font-size: 20px; color: var(--accent); letter-spacing: -.5px; }
.brand span { color: var(--text); }
.conn { display: flex; align-items: center; gap: 8px; color: var(--dim); font-size: 13px; }
.conn i { width: 10px; height: 10px; border-radius: 50%; background: var(--faint); }
#conn2 { display: none; }
.conn.ok i { background: var(--good); box-shadow: 0 0 8px var(--good); }
.conn.nounit i { background: var(--accent); }
.conn.bad i { background: var(--hot); }
.panel { background: var(--panel); border-radius: var(--r); padding: 10px; min-height: 0; min-width: 0; }

/* ---- buttons ---- */
.big { position: relative; display: grid; place-content: center; justify-items: center; gap: 2px; text-align: center; min-height: 56px; padding: 8px 6px;
  background: var(--tile); border-radius: var(--r); font-weight: 800; letter-spacing: .04em; cursor: pointer; transition: background .06s, transform .06s; }
.big small { font-weight: 500; letter-spacing: 0; text-transform: none; font-size: .78em; color: var(--dim); }
.big:active, .big.press { transform: scale(.965); background: #45454c; }
.big.on { background: var(--accent); color: var(--ink); }
.big.on small { color: rgba(0,0,0,.6); }
.big.hot { background: var(--hot); color: var(--ink); }
.big.hot small { color: rgba(0,0,0,.6); }
.big.good { background: var(--good); color: var(--ink); }
.big[disabled] { opacity: .4; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--hot); display: inline-block; }
#bRec { grid-auto-flow: column; gap: 10px; place-content: center; }
#bRec.hot .dot { background: var(--ink); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .15; } }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.pair .big { font-size: 12px; }

/* ---- rail ---- */
#rail { display: grid; gap: 10px; align-content: start; overflow: hidden; }
.bankbpm { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: end; }
.bankbpm b { font-size: 34px; line-height: 1; display: block; }
.bank b { color: var(--accent); font-size: 44px; }
.clock { display: flex; align-items: center; gap: 10px; flex: 1; justify-content: center; min-width: 0; }
#beats { display: grid; grid-template-columns: repeat(4, 22px); gap: 4px; }
#beats i { height: 10px; border-radius: 4px; background: var(--tile); transition: background .05s; }
#beats i.on { background: var(--good); }
#beats i.on:first-child { background: var(--hot); }
#beats.stopped i { opacity: .4; }
#bar { font-weight: 700; font-size: 13px; white-space: nowrap; }
.cue { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cue button { text-align: left; background: var(--tile); border-radius: 10px; padding: 6px 10px; min-height: 54px; display: grid; align-content: center; }
.cue button:active { background: #45454c; }
.cue b { font-size: 22px; display: block; }
#next { color: var(--bus1); }
.buttons { display: grid; gap: var(--gap); }

/* ---- pads ---- */
#pads { display: grid; place-items: center; min-height: 0; min-width: 0; container-type: size; position: relative; }
#waiting { position: absolute; inset: 0; display: grid; place-content: center; gap: 6px; text-align: center; background: #121214d9; border-radius: var(--r); z-index: 1; padding: 20px; }
#waiting span { color: var(--dim); }
#grid { display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); gap: var(--gap);
  width: min(100cqw, 100cqh); height: min(100cqw, 100cqh); }
.pad { position: relative; background: var(--tile); border-radius: var(--r); overflow: hidden; display: grid; grid-template-rows: auto 1fr; padding: 20px 9px 6px;
  touch-action: none; cursor: pointer; transition: background .08s; min-width: 0; min-height: 0; container-type: inline-size; }
.pad .n { font-weight: 800; font-size: 15px; color: var(--text); }
.pad .nm { align-self: center; font-weight: 700; font-size: clamp(11px, 13cqw, 22px); line-height: 1.12; overflow: hidden; word-break: break-word; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.pad .bars { position: absolute; bottom: 6px; right: 8px; font-size: 11px; color: var(--dim); }
.pad .bus { position: absolute; top: 18px; right: 6px; min-width: 28px; height: 24px; border-radius: 6px; display: none; place-items: center; font-weight: 800; font-size: 14px; color: var(--ink); }
.pad.b1 .bus { display: grid; background: var(--bus1); }
.pad.b2 .bus { display: grid; background: var(--bus2); }
.pad .lv { position: absolute; top: 0; left: 0; right: 0; height: 12px; margin: 0; background: rgba(255,255,255,.07); }
.pad .lv i { position: absolute; inset: 0 auto 0 0; background: var(--text); opacity: .85; }
.pad.empty { background: var(--tile-empty); color: var(--faint); }
.pad.empty .nm, .pad.empty .n { color: var(--faint); }
.pad.empty .lv, .pad.empty .bus { display: none; }
.pad.inPat { background: color-mix(in srgb, var(--tile) 80%, var(--accent)); }
.pad.heard { background: color-mix(in srgb, var(--tile) 55%, var(--good)); }
.pad.sel { box-shadow: inset 0 0 0 3px var(--accent); }
.pad.keep { box-shadow: inset 0 0 0 4px var(--good); background: color-mix(in srgb, var(--tile) 60%, var(--good)); }
.pad.dry { opacity: .45; }
/* A muted pad is unmistakable: red hazard stripes, a red frame, struck-through name and a MUTED label. */
.pad.muted, .pad.muted.heard, .pad.muted.inPat, .pad.muted.keep {
  background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--hot) 42%, #000) 0 9px, color-mix(in srgb, var(--hot) 16%, #000) 9px 18px);
  box-shadow: inset 0 0 0 3px var(--hot);
}
.pad.muted .n, .pad.muted .nm { color: #ffd9d9; text-decoration: line-through; opacity: .8; }
.pad.muted .lv, .pad.muted .bus { opacity: .35; }
.pad.muted::after { content: "MUTED"; position: absolute; left: 50%; bottom: 8%; transform: translateX(-50%); padding: 2px 8px; border-radius: 6px; background: var(--hot); color: var(--ink);
  font-size: clamp(10px, 13cqw, 16px); font-weight: 900; letter-spacing: .1em; pointer-events: none; }
.pad::before { content: ""; position: absolute; inset: 0; background: var(--hot); opacity: var(--glow, 0); pointer-events: none; transition: opacity .1s; }
.pad:active, .pad.hit { filter: brightness(1.25); }
.mixing .pad .lv { height: 18px; }
.mixing .pad .lv i { background: var(--accent); opacity: 1; }
.mixing .pad::after { content: attr(data-lv); position: absolute; right: 8px; bottom: 22px; font-size: 20px; font-weight: 800; color: var(--accent); inset: auto 8px 22px auto; display: block; font-size: clamp(14px, 22cqw, 28px); }
.mixing .pad.muted::after { content: "MUTED"; inset: auto auto 8% 50%; right: auto; display: block; font-size: clamp(10px, 13cqw, 16px); }

/* ---- motion ---- */
#motion { display: grid; gap: 10px; overflow: hidden; grid-template-rows: auto auto repeat(2, minmax(0, 1fr)); }
#buses { display: contents; }
.len { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.seg button { min-height: 48px; background: var(--tile); border-radius: 10px; font-weight: 800; font-size: 17px; }
.seg button:active { background: #45454c; }
.seg button.on { background: var(--accent); color: var(--ink); }
.dub { min-height: 48px; padding: 0 16px; font-size: 13px; }
.bm { display: grid; gap: 6px; grid-template-rows: auto minmax(0, 1fr); min-height: 0; }
.bushead { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bushead b { font-size: 17px; }
.bushead .fx { color: var(--dim); font-size: 13px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bushead .fx em { font-style: normal; color: var(--good); font-weight: 700; }
.knobs { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.knob { width: 36px; height: 10px; border-radius: 5px; background: var(--tile); position: relative; overflow: hidden; }
.knob i { position: absolute; inset: 0 auto 0 0; background: var(--c, var(--accent)); }
.slots { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); grid-template-rows: minmax(0, 1.25fr) minmax(0, 1fr); gap: 6px; min-height: 0; }
.slots .slot { grid-column: span 3; }
.slots .ctl { grid-column: span 4; }
.slot { min-height: 0; justify-content: stretch; align-content: space-between; padding: 8px 4px 6px; overflow: hidden; }
.slot b { font-size: 20px; line-height: 1; }
.slot .st { font-size: 11px; font-weight: 600; color: var(--dim); letter-spacing: 0; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.slot svg { width: 86%; height: 22px; display: block; }
.slot svg path { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.slot .pos { position: absolute; left: 0; bottom: 0; height: 5px; background: var(--ink); opacity: .7; }
.slot.sel { box-shadow: inset 0 0 0 3px var(--text); }
.slot.rec { background: var(--hot); color: var(--ink); }
.slot.play { background: var(--accent); color: var(--ink); }
.slot.wait { background: var(--accent); color: var(--ink); animation: pulse 0.8s ease-in-out infinite alternate; }
.slot.rec .st, .slot.play .st, .slot.wait .st { color: rgba(0,0,0,.65); }
.slot.filled:not(.play):not(.wait) { color: var(--text); }
@keyframes pulse { to { opacity: .55; } }
.ctl { min-height: 0; font-size: 12px; }
.ctl small { font-size: 12px; }
.ctl b { font-size: 16px; }

/* ---- punch: four snapshots of the four buses, held ---- */
#mpSw button { min-height: 38px; font-size: 13px; letter-spacing: .08em; }
#motion[data-mp="punch"], #motion[data-mp="lfo"] { grid-template-rows: auto minmax(0, 1fr); }
#motion[data-mp="punch"] .len, #motion[data-mp="punch"] #buses, #motion[data-mp="lfo"] .len, #motion[data-mp="lfo"] #buses { display: none; }
#motion:not([data-mp="punch"]) #punch, #motion:not([data-mp="lfo"]) #lfo { display: none; }
#lfo { display: grid; gap: 8px; grid-template-rows: auto auto auto minmax(0, 1fr); min-height: 0; }
#lfoSel button.run { background: var(--accent); color: var(--ink); }
#lfoSel button.sel { box-shadow: inset 0 0 0 3px var(--text); }
#lfoEd { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
#lfoEd .big { min-height: 52px; align-content: center; gap: 2px; padding: 4px 2px; }
#lfoEd .big small { font-size: 10px; letter-spacing: .08em; color: var(--dim); }
#lfoEd .big b { font-size: 16px; }
#lfoDepth { position: relative; min-height: 48px; background: var(--tile); border-radius: var(--r, 12px); overflow: hidden; touch-action: none; }
#lfoDepth i { position: absolute; inset: 0 auto 0 0; background: var(--faint); width: 0; }
#lfoDepth b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 15px; text-shadow: 0 0 4px #000a; }
#lfoOn { position: relative; overflow: hidden; }
#lfoOn i { position: absolute; inset: auto 0 0 0; height: 8px; background: var(--ink); opacity: .55; width: 0; }
#lfoOn.on { background: var(--accent); color: var(--ink); }
#optGrid, #presetList { touch-action: pan-y; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
#optGrid { display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); gap: 8px; overflow-y: auto; max-height: 70vh; }
#optGrid button { min-height: 56px; border-radius: 12px; background: var(--tile); font-weight: 800; font-size: 17px; }
#optGrid button.on { background: var(--accent); color: var(--ink); }
#lfoNote { color: var(--dim); font-size: 12px; text-align: center; }
#punch { display: grid; gap: 8px; grid-template-rows: auto auto minmax(0, 1fr); min-height: 0; }
#pnSlots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); gap: 8px; min-height: 0; }
#pnBar { min-height: 42px; display: grid; }
#pnBus { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
#pnBus .chip { min-height: 30px; font-size: 11px; font-weight: 700; background: var(--tile); border-radius: 8px; padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#pnBus .chip.unk { color: var(--hot); box-shadow: inset 0 0 0 1px var(--hot); }
#pnVals { display: none; }
#punch[data-edit="1"] { grid-template-rows: auto auto auto minmax(0, 1fr); }
#punch[data-edit="1"] #pnSlots { grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: 64px; }
#punch[data-edit="1"] .pn b { font-size: 22px; } #punch[data-edit="1"] .pn small, #punch[data-edit="1"] .pn .dots { display: none; }
#punch[data-edit="1"] #pnVals { display: grid; align-content: start; gap: 6px; overflow-y: auto; min-height: 0; }
.pv { background: var(--tile); border-radius: 10px; padding: 6px 8px; display: grid; gap: 4px; }
.pvh { display: flex; align-items: baseline; gap: 8px; font-size: 13px; } .pvh span { color: var(--text); flex: 1; } .pvh em { font-style: normal; font-weight: 800; color: var(--good); }
.pvk { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
.pvk span { display: grid; gap: 1px; min-width: 0; text-align: center; }
.pvk small { font-size: 9px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pvk b { font-size: 12px; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chg { color: var(--accent) !important; } .pvk .chg b { background: var(--accent); color: var(--ink); border-radius: 5px; }
.pvhint { color: var(--dim); font-size: 12px; text-align: center; padding: 4px; }
#pnTools { display: grid; grid-template-columns: minmax(0, 2.6fr) minmax(0, 0.9fr) minmax(0, 1.2fr); gap: 6px; }
#pnTools > * { min-width: 0; } #pnTools .seg { gap: 4px; }
#pnTools .big, #pnTools .seg button { min-height: 46px; font-size: 12px; padding: 0 2px; letter-spacing: 0; }
#pnMorph { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
#pnMorph[hidden], #pnTools[hidden] { display: none; }
#pnMorph .big { min-height: 56px; padding: 0 16px; font-size: 13px; }
#pnFader { position: relative; min-height: 56px; background: var(--tile); border-radius: var(--r, 12px); overflow: hidden; touch-action: none; }
#pnFader i { position: absolute; inset: 0 auto 0 0; background: var(--accent); width: 0; }
#pnFader b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 18px; color: var(--text); mix-blend-mode: normal; text-shadow: 0 0 4px #000a; }
.pn { min-height: 0; display: grid; align-content: space-between; justify-items: center; padding: 6px 2px; }
.pn b { font-size: 32px; line-height: 1; }
.pn { align-content: center; gap: 6px; }
.pn .dots { display: flex; gap: 4px; }
.pn .dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); }
.pn .dots i.on { background: var(--c); }
.pn small { font-size: 12px; letter-spacing: .06em; }
.pn .dots i { width: 12px; height: 12px; }
.pn.empty { color: var(--faint); }
.pn.held { background: var(--accent); color: var(--ink); }
.pn.held .dots i.on { background: var(--ink); }
.pn.arm { box-shadow: inset 0 0 0 3px var(--hot); }
#presetList { display: grid; gap: 8px; overflow-y: auto; max-height: 62vh; }
#presetList button { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 10px; text-align: left; background: var(--tile); border-radius: 12px; padding: 10px 14px; min-height: 56px; }
#presetList b { font-size: 17px; letter-spacing: .04em; } #presetList small { grid-column: 1; color: var(--dim); }
#presetList .dots { grid-column: 2; grid-row: 1 / span 2; display: flex; gap: 4px; }
#presetList .dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--faint); } #presetList .dots i.on { background: var(--c); }
.pstarget { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center; }
.pstarget .seg button.set { box-shadow: inset 0 0 0 2px var(--faint); }
#pnSave.arm { background: var(--hot); color: var(--ink); }

/* ---- pattern picker ---- */
#picker, .modal { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 8; padding: 12px; }
#picker .card, .modal .card { background: var(--panel); border-radius: 16px; padding: 14px; display: grid; gap: 10px; width: min(560px, 100%); max-height: 100%; }
.phead { display: flex; justify-content: space-between; align-items: center; font-size: 18px; }
.phead button { width: 48px; height: 40px; border-radius: 10px; background: var(--tile); font-size: 18px; }
#pickGrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
#pickGrid button { min-height: min(72px, 14vh); border-radius: 12px; background: var(--tile); font-weight: 800; font-size: 20px; display: grid; place-content: center; gap: 2px; }
#pickGrid button small { font-weight: 500; letter-spacing: 0; }
#pickGrid button:disabled { background: var(--tile-empty); color: var(--faint); }
#pickGrid button.now { background: var(--accent); color: var(--ink); }
#pickGrid button.next { background: var(--bus1); color: var(--ink); }
#pickGrid button.now small, #pickGrid button.next small { color: rgba(0,0,0,.65); }

/* ---- tabs, toast, lost ---- */
#tabs { display: none; }
#toast { position: fixed; left: 50%; top: max(10px, env(safe-area-inset-top)); transform: translate(-50%, -20px); background: #000d; color: var(--text); padding: 10px 16px; border-radius: 999px; font-size: 14px; max-width: 90vw; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 3; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#lost { position: fixed; inset: 0; background: #000b; display: grid; place-items: center; z-index: 9; }
#lost > div { background: var(--panel); border-radius: 16px; padding: 24px; display: grid; gap: 12px; text-align: center; min-width: 250px; }
#lost span { color: var(--dim); }
#lost button { background: var(--tile); padding: 14px; border-radius: var(--r); font-weight: 700; }

/* ---- landscape: three columns ---- */
@media (orientation: landscape) {
  #app { grid-template-columns: minmax(140px, 17%) minmax(0, 1fr) minmax(290px, 36%); grid-template-rows: auto 1fr; grid-template-areas: "top top top" "rail pads motion"; }
  #top { grid-area: top; min-height: 22px; }
  #rail { grid-area: rail; } #pads { grid-area: pads; } #motion { grid-area: motion; }
  .bank b { font-size: 36px; } .bankbpm b { font-size: 28px; }
  .big { min-height: 48px; }
}
@media (orientation: landscape) and (max-height: 430px) {
  :root { --gap: 6px; --r: 10px; }
  #top { min-height: 18px; } .brand { display: none; }
  #app { grid-template-rows: auto 1fr; grid-template-areas: "top top top" "rail pads motion"; }
  .panel { padding: 8px; }
  #rail { gap: 6px; }
  .cue b { font-size: 18px; }
  .big { min-height: 42px; padding: 4px; font-size: 13px; }
  .ctl { grid-auto-flow: column; gap: 8px; } .ctl b { font-size: 14px; }
  .slot b { font-size: 17px; } .slot svg { height: 16px; }
  .seg button { min-height: 40px; } .dub { min-height: 40px; }
  #mpSw button { min-height: 30px; } #lfoEd .big { min-height: 40px; } #lfoDepth { min-height: 36px; }
  .pad { padding: 14px 6px 4px; } .pad .lv { height: 9px; }
  .bankbpm { gap: 10px; } .bank b { font-size: 30px; } .bankbpm b { font-size: 24px; }
}
@media (orientation: landscape) and (min-width: 1100px) {
  /* wide: a slim stage column, the pads as big as the height allows, the motion panel in a column of its own (not wide enough for one row of seven) */
  #app { grid-template-columns: minmax(190px, 15%) minmax(0, 1fr) minmax(400px, 30%); }
  #grid { --gap: 12px; }
  #rail { gap: 14px; }
}
@media (orientation: landscape) and (min-width: 1700px) {
  #app { grid-template-columns: minmax(220px, 14%) minmax(0, 1fr) minmax(480px, 28%); }
}

/* ---- narrow landscape (a small phone): the pads and one side panel, with two tabs ---- */
@media (orientation: landscape) and (max-width: 759px) {
  #app { grid-template-columns: minmax(0, 1fr) minmax(250px, 47%); grid-template-rows: auto auto 1fr; grid-template-areas: "top top" "pads tabs" "pads side"; }
  #pads { grid-area: pads; }
  #rail, #motion { grid-area: side; display: none; }
  #app[data-tab="pads"] #motion, #app[data-tab="motion"] #motion { display: grid; }
  #app[data-tab="rail"] #rail { display: grid; }
  #tabs { grid-area: tabs; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  #tabs button[data-tab="pads"] { display: none; }
  #tabs button { min-height: 36px; background: var(--panel); border-radius: var(--r); font-weight: 800; letter-spacing: .06em; color: var(--dim); font-size: 13px; }
  #app[data-tab="pads"] #tabs button[data-tab="motion"], #tabs button.on { background: var(--accent); color: var(--ink); }
  #motion { overflow-y: auto; grid-template-rows: auto auto auto auto auto; gap: 8px; align-content: start; }
  .slot { min-height: 56px; padding: 4px 2px 5px; gap: 0; align-content: center; } .slot svg { height: 13px; } .slot b { font-size: 16px; } .ctl { min-height: 38px; }
  .slots { grid-template-rows: auto auto; }
  .seg button, .dub { min-height: 38px; }
  #rail { overflow-y: auto; gap: 6px; padding: 8px; }
  #rail .big { min-height: 40px; padding: 2px; } #rail .big small { display: none; }
  .bank b { font-size: 28px; } .bankbpm b { font-size: 24px; } .cue b { font-size: 18px; }
  .buttons { gap: 6px; }
}
@container (max-width: 100px) { .pad .bars { display: none; } }

/* ---- portrait: tabs ---- */
@media (orientation: portrait) {
  #app { grid-template-rows: auto 1fr auto; grid-template-areas: "top" "main" "tabs"; }
  #top { grid-area: top; }
  #rail, #pads, #motion { grid-area: main; display: none; }
  #app[data-tab="pads"] #pads { display: grid; }
  #app[data-tab="motion"] #motion { display: grid; }
  #app[data-tab="rail"] #rail { display: grid; }
  #grid { width: 100cqw; height: 100cqh; }
  #rail { grid-template-rows: auto auto 1fr; }
  .buttons { grid-auto-rows: 1fr; min-height: 0; }
  .buttons .big { min-height: 64px; }
  #tabs { grid-area: tabs; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
  #tabs button { min-height: 52px; background: var(--panel); border-radius: var(--r); font-weight: 800; letter-spacing: .06em; color: var(--dim); }
  #tabs button.on { background: var(--accent); color: var(--ink); }
  .len { grid-template-columns: 1fr; }
  .dub { min-height: 52px; }
  .bankbpm b { font-size: 40px; } .bank b { font-size: 54px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.hint { color: var(--dim); font-size: 12px; text-align: center; padding: 2px 4px; }
.hint b { color: var(--text); }
.bankchip { font-size: 11px; font-weight: 800; letter-spacing: .08em; color: var(--dim); background: var(--panel); border-radius: 8px; padding: 2px 8px; white-space: nowrap; }
.bankchip b { font-size: 18px; color: var(--accent); letter-spacing: 0; margin-left: 2px; }
#top { min-width: 0; overflow: hidden; }
@media (max-width: 440px) { .brand { display: none; } #beats { grid-template-columns: repeat(4, 16px); } }

/* ---- the Looper ---- */
.viewbtn { background: var(--panel); color: var(--text); font-weight: 800; letter-spacing: .06em; font-size: 12px; border-radius: 8px; padding: 6px 12px; min-height: 30px; }
.viewbtn.on { background: var(--accent); color: var(--ink); }
@keyframes blink { 50% { opacity: .55; } }
#looper { display: none; gap: 10px; min-height: 0; min-width: 0; }
#app[data-view="looper"] #looper { display: grid; }
#app[data-view="looper"] #rail, #app[data-view="looper"] #pads, #app[data-view="looper"] #motion { display: none; }
.lpctl { display: grid; gap: 8px; align-content: start; grid-auto-rows: max-content; min-height: 0; overflow-y: auto; }
.lpstatus { background: var(--tile); border-radius: var(--r); padding: 10px 12px; display: grid; gap: 2px; }
.lpstatus b { font-size: 26px; letter-spacing: .04em; }
.lpstatus span { color: var(--dim); font-size: 13px; }
.lpstatus[data-phase="armed"] b, .lpstatus[data-phase="starting"] b { color: var(--bus1); }
.lpstatus[data-phase="recording"] { background: var(--hot); color: var(--ink); }
.lpstatus[data-phase="recording"] span { color: rgba(0,0,0,.65); }
.lpstatus[data-phase="saving"] b { color: var(--good); }
.lparm { min-height: 76px; font-size: 22px; background: var(--good); color: var(--ink); }
.lparm.on { background: var(--hot); }
.lparm:disabled { opacity: .5; }
.lprow { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr); gap: 8px; align-items: stretch; }
.lprow .big { font-size: 22px; }
.lpmid { display: grid; place-content: center; justify-items: center; background: var(--tile); border-radius: var(--r); }
.lpmid small { color: var(--dim); font-weight: 700; letter-spacing: .08em; font-size: 11px; }
.lpmid b { font-size: 22px; white-space: nowrap; }
.lpctl .big:disabled { opacity: .4; }
.lpctl .big.warn small { color: var(--accent); }
.lpctl .big.danger { background: var(--hot); color: var(--ink); }
.lpctl .big.danger small { color: rgba(0,0,0,.65); }
#lpgrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(4, minmax(0, 1fr)); gap: var(--gap); min-height: 0; min-width: 0; }
.lpad { background: var(--tile-empty); border-radius: var(--r); padding: 6px 8px; display: grid; grid-template-rows: auto minmax(0, 1fr); min-width: 0; min-height: 0; overflow: hidden; border: 3px solid transparent; touch-action: none; }
.lpad b { font-size: 15px; color: var(--faint); }
.lpad span { align-self: center; font-weight: 700; font-size: clamp(10px, 2.6vmin, 14px); line-height: 1.1; overflow: hidden; overflow-wrap: anywhere; color: var(--dim); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.lpad.has { background: var(--tile); } .lpad.has b { color: var(--text); } .lpad.has span { color: var(--text); }
.lpad.target { border-color: var(--accent); } .lpad.target span { color: var(--accent); }
.lpad.sel { border-color: var(--text); }
@media (orientation: landscape) {
  #looper { grid-column: 1 / -1; grid-row: 2; grid-template-columns: minmax(250px, 34%) minmax(0, 1fr); }
  #lpgrid { width: min(100%, calc((100vh - 70px) * 1.0)); justify-self: center; }
}
@media (orientation: landscape) and (max-height: 430px) {
  #looper { grid-template-columns: minmax(300px, 42%) minmax(0, 1fr); }
  .lpctl, .lpgroup { gap: 6px; } .lpgroup { grid-template-columns: 1fr 1fr; }
  .lpgroup > .lparm, .lpgroup > .lpinfo, #lpPat { grid-column: 1 / -1; }
  .lpstatus { padding: 6px 10px; } .lpstatus b { font-size: 19px; } .lparm { min-height: 46px; font-size: 18px; }
  .lpctl .big, .lprow .big { min-height: 38px; font-size: 14px; } .lpctl .big small { display: none; }
  .lpsw, .lpsw button { min-height: 32px; font-size: 13px; }
  .lpmid { min-height: 38px; } .lpmid small { display: none; } .lpmid b { font-size: 17px; }
  #lpgrid { aspect-ratio: auto; width: 100%; }
}
@media (orientation: landscape) and (max-width: 759px) {
  #looper { grid-row: 2 / 4; } #app[data-view="looper"] #tabs { display: none; }
  #tabs button[data-tab="looper"] { display: none; }
}
@media (orientation: portrait) {
  #looper { grid-area: main; grid-template-rows: auto 1fr; }
  .lpgroup { grid-template-columns: 1fr 1fr; }
  .lpgroup > .lparm, .lpgroup > .lpinfo, #lpPat { grid-column: 1 / -1; }
  .viewbtn { display: none; }
  #tabs { grid-template-columns: repeat(4, 1fr); }
  #tabs button { font-size: 12px; }
}
@media (orientation: portrait) {
  #looper { overflow-y: auto; grid-template-rows: auto minmax(230px, 1fr); }
}
@media (orientation: portrait) and (max-height: 760px) {
  .lparm { min-height: 54px; font-size: 19px; } .lpstatus { padding: 6px 12px; } .lpstatus b { font-size: 21px; }
  .lpctl .big { min-height: 46px; } .lpctl .big small { display: none; }
  .lpctl { gap: 6px; }
}
@media (orientation: portrait) { .lpctl { overflow: visible; min-height: max-content; } #looper { grid-template-rows: max-content minmax(230px, 1fr); } }
.lpbtn { border: 0; color: var(--text); font: inherit; touch-action: manipulation; }
.lpbtn.on { background: var(--accent); color: var(--ink); } .lpbtn.on small { color: rgba(0,0,0,.6); }
.lprow2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lprow2 > .lparm { grid-column: auto; }
@media (orientation: portrait) { .lprow2 { grid-column: 1 / -1; } }

.lpgroup { display: grid; gap: 8px; align-content: start; }
.lpsw { min-height: 40px; flex-shrink: 0; } .lpsw button { min-height: 40px; font-size: 14px; }
.lpinfo { color: var(--dim); font-size: 12px; line-height: 1.35; padding: 2px 4px; }
.lpinfo b { color: var(--text); }
#looper[data-lp="loop"] #lpSlice { display: none; }
#looper[data-lp="slice"] #lpMain, #looper[data-lp="slice"] #lpStatus { display: none; }
#looper[data-lp="slice"] .lpgroup { grid-template-columns: 1fr 1fr; }
#looper[data-lp="slice"] .lpgroup > .lprow, #looper[data-lp="slice"] .lpgroup > .lprow2, #looper[data-lp="slice"] .lpgroup > .lpstatus, #looper[data-lp="slice"] .lpgroup > .lpinfo { grid-column: 1 / -1; }

#lvPop { position: fixed; z-index: 20; pointer-events: none; transform: translateX(-50%); background: var(--accent); color: var(--ink); border-radius: 12px;
  padding: 4px 14px; display: grid; justify-items: center; line-height: 1.05; box-shadow: 0 4px 18px rgba(0,0,0,.5); }
#lvPop[hidden] { display: none; }
#lvPop b { font-size: 28px; } #lvPop small { font-size: 11px; font-weight: 700; letter-spacing: .08em; }

/* ---- level meter ---- */
.meter { display: grid; gap: 3px; background: var(--tile); border-radius: var(--r); padding: 6px 8px; }
.mrow { display: grid; grid-template-columns: 12px 1fr; gap: 6px; align-items: center; font-size: 10px; font-weight: 800; color: var(--dim); }
.mbar { position: relative; height: 9px; border-radius: 4px; background: rgba(255,255,255,.07); overflow: hidden; }
.mbar i { position: absolute; inset: 0 auto 0 0; background: var(--good); width: 0; transition: width .06s linear; }
.mbar i[data-l="warn"] { background: #ffd75f; } .mbar i[data-l="hot"] { background: var(--hot); }
.mbar u { position: absolute; top: 0; bottom: 0; width: 3px; background: var(--text); opacity: .9; }
.minfo { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--dim); }
.minfo em { font-style: normal; font-weight: 800; letter-spacing: .06em; padding: 1px 6px; border-radius: 5px; background: rgba(255,255,255,.07); color: var(--faint); }
.minfo em.on { background: var(--hot); color: var(--ink); }
.meter.off .mbar { opacity: .4; }
@media (orientation: landscape) and (max-height: 430px) { .meter { padding: 4px 6px; gap: 2px; } .mbar { height: 7px; } }
.minfo b { white-space: nowrap; }
.lpgroup > .meter { grid-column: 1 / -1; }

#slReady[hidden] { display: none; }
@media (orientation: portrait) {
  .lpctl, .lpgroup { gap: 6px; }
  .lpctl .big { min-height: 38px; font-size: 14px; }
  .lpctl .lprow .big { font-size: 16px; }
  .lpctl .lparm { min-height: 44px; font-size: 18px; }
  .lpsw, .lpsw button { min-height: 36px; font-size: 13px; }
  .lpstatus { padding: 5px 10px; } .lpstatus b { font-size: 18px; } .lpstatus span { font-size: 12px; }
  .lpmid b { font-size: 18px; }
  .lpmid small { font-size: 10px; }
  #lpPat { grid-column: auto; }
  #looper { grid-template-rows: max-content minmax(190px, 1fr); }
  #lpgrid { gap: 6px; }
  .lpad { padding: 4px 6px; border-width: 2px; }
  .lpad b { font-size: 13px; }
  #lpSlice .lpinfo { display: none; }
  .lpgroup > .meter { padding: 4px 8px; gap: 2px; }
  .slbanks .lprow { gap: 4px; }
}
.meter { min-width: 0; }
.minfo b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.minfo { min-width: 0; }

button.bankchip { border: 0; font-family: inherit; touch-action: manipulation; }
.bankchip i { font-style: normal; font-size: 10px; color: var(--dim); }
.modal[hidden] { display: none; }
#bankGrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
#bankGrid button { min-height: min(72px, 14vh); border-radius: 12px; background: var(--tile); font-weight: 800; font-size: 22px; display: grid; place-content: center; gap: 2px; }
#bankGrid button small { font-weight: 500; font-size: 11px; color: var(--dim); }
#bankGrid button.now { background: var(--accent); color: var(--ink); } #bankGrid button.now small { color: rgba(0,0,0,.6); }
.lpad.del { background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--hot) 40%, #000) 0 8px, color-mix(in srgb, var(--hot) 16%, #000) 8px 16px); border-color: var(--hot); }
.lpad.del span { text-decoration: line-through; }
.lpmid.pick { cursor: pointer; } .lpmid.pick b::after { content: " ▾"; font-size: 11px; color: var(--dim); }

.lpad.muted { background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--hot) 42%, #000) 0 9px, color-mix(in srgb, var(--hot) 16%, #000) 9px 18px); box-shadow: inset 0 0 0 2px var(--hot); }
.lpad.muted b, .lpad.muted span { color: #ffd9d9; text-decoration: line-through; }

#mangleRows { display: grid; gap: 8px; }
.dicerow { display: grid; grid-template-columns: 1fr 48px 74px 48px; align-items: center; gap: 6px; }
.dicerow span { font-weight: 800; letter-spacing: .04em; font-size: 14px; }
.dicerow small { grid-column: 1; color: var(--dim); font-size: 11px; margin-top: -4px; }
.dicerow button { height: 42px; border-radius: 10px; background: var(--tile); font-weight: 800; font-size: 18px; }
.dicerow b { text-align: center; font-size: 17px; } .dicerow b.on { color: var(--accent); }
.mnote { color: var(--dim); font-size: 12px; line-height: 1.35; }
#mangleReset { min-height: 42px; }
#rail .buttons { align-content: start; grid-auto-rows: max-content; }
#rail #bRec { min-height: 84px; }

/* ---- the Patterns page ---- */
#patterns { display: none; gap: 10px; min-height: 0; min-width: 0; grid-template-rows: auto 1fr; }
#app[data-view="patterns"] #patterns { display: grid; }
#app[data-view="patterns"] #rail, #app[data-view="patterns"] #pads, #app[data-view="patterns"] #motion, #app[data-view="patterns"] #looper { display: none; }
#ptnGrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(4, minmax(0, 1fr)); gap: var(--gap); min-height: 0; min-width: 0; }
#ptnGrid button { border-radius: var(--r); background: var(--tile); color: var(--text); display: grid; place-content: center; gap: 2px; font-weight: 800; font-size: clamp(20px, 7vmin, 34px);
  min-height: 0; min-width: 0; touch-action: manipulation; border: 3px solid transparent; }
#ptnGrid button small { font-weight: 600; font-size: 12px; color: var(--dim); letter-spacing: .02em; }
#ptnGrid button:disabled { background: var(--tile-empty); color: var(--faint); } #ptnGrid button:disabled small { color: var(--faint); }
#ptnGrid button.now { background: var(--accent); color: var(--ink); } #ptnGrid button.now small { color: rgba(0,0,0,.65); }
#ptnGrid button.next { border-color: var(--bus1); animation: ptnblink .7s steps(2) infinite; } #ptnGrid button.next small { color: var(--bus1); }
@keyframes ptnblink { 50% { background: color-mix(in srgb, var(--bus1) 55%, var(--tile)); } }
#ptnGrid button:not(:disabled):active { filter: brightness(1.25); }
@media (orientation: landscape) { #patterns { grid-column: 1 / -1; grid-row: 2; } }
@media (orientation: landscape) and (max-width: 759px) {
  #patterns { grid-row: 2 / 4; } #app[data-view="patterns"] #tabs { display: none; }
  #tabs button[data-tab="patterns"] { display: none; }
}
@media (orientation: portrait) {
  #patterns { grid-area: main; }
  #tabs { grid-template-columns: repeat(5, 1fr); } #tabs button { font-size: 11px; letter-spacing: .02em; }
}

/* ---- the Slicer on a phone: small controls, the settings three to a row, each chosen from a list ---- */
.lprow3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
#looper[data-lp="slice"] .lpgroup > .lprow3 { grid-column: 1 / -1; }
#lpSlice { gap: 6px; }
#lpSlice .big { min-height: 38px; padding: 2px 4px; font-size: 12px; letter-spacing: 0; }
#lpSlice .lparm { min-height: 44px; font-size: 16px; }
#lpSlice .lprow .big { font-size: 15px; }
#lpSlice .lpmid { min-height: 38px; } #lpSlice .lpmid small { display: none; } #lpSlice .lpmid b { font-size: 16px; }
#lpSlice .lpstatus { padding: 5px 10px; } #lpSlice .lpstatus b { font-size: 17px; }
#lpSlice .lpstatus span { font-size: 12px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
#lpSlice .lpinfo { display: none; }
#lpSlice .big small { display: none; }
#optGrid button small { display: block; font-weight: 500; font-size: 12px; color: var(--dim); margin-top: 2px; }
#optGrid button.on small { color: rgba(0,0,0,.6); }

/* ---- the hosted page: no server, so no Looper, Slicer, recording or level ---- */
#app.local #tabs button[data-tab="looper"], #app.local #bRec, #app.local [data-meter] { display: none; }
#start { display: grid; place-items: center; }
.startbox { display: grid; gap: 12px; max-width: 420px; padding: 24px 16px; text-align: center; }
.startbox h1 { margin: 0; font-size: 44px; } .startbox h1 span { color: var(--accent); }
.startbox p { color: var(--dim); margin: 0; } .startbox small { color: var(--dim); line-height: 1.4; }
.startbox .big { min-height: 56px; font-size: 16px; }
#start[hidden] { display: none; }
#app.local .pad .lv { display: none; } #app.local .pad { padding-top: 8px; }

/* ---- the Tools page (a frame) ---- */
#tools { display: none; min-height: 0; min-width: 0; padding: 0; overflow: hidden; }
#tools iframe { width: 100%; height: 100%; min-height: 70vh; border: 0; background: var(--bg); display: block; }
#app[data-view="tools"] #tools { display: block; }
#app[data-view="tools"] #rail, #app[data-view="tools"] #pads, #app[data-view="tools"] #motion, #app[data-view="tools"] #looper, #app[data-view="tools"] #patterns { display: none; }
@media (orientation: landscape) { #tools { grid-column: 1 / -1; grid-row: 2; } }
@media (orientation: landscape) and (max-width: 759px) { #tools { grid-row: 2 / 4; } #app[data-view="tools"] #tabs { display: none; } #tabs button[data-tab="tools"] { display: none; } }
@media (orientation: portrait) { #tools { grid-area: main; } #tabs { grid-template-columns: repeat(5, 1fr); } #tabs button { font-size: 11px; letter-spacing: .02em; } }
.lpsw { display: none !important; }


/* the demo's play and stop (a real unit is started on the unit) */
#demoPlay:not([hidden]) { display: block; flex: none; min-width: 36px; min-height: 30px; padding: 2px 8px; font-size: 14px; letter-spacing: 0; background: var(--accent); color: var(--ink); }

/* ---- wide landscape (a computer): the sections at the bottom, as on a phone. The pads, the stage and the motion panel are on one page here,
   so the bar has three: Perform, Patterns, Tools. The button in the top bar is not needed any more. ---- */
@media (orientation: landscape) and (min-width: 760px) {
  #app { grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "top top top" "rail pads motion" "tabs tabs tabs"; }
  #tabs { grid-area: tabs; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
  #tabs button { min-height: 46px; background: var(--panel); border-radius: var(--r); font-weight: 800; letter-spacing: .06em; color: var(--dim); font-size: 14px; }
  #tabs button.on { background: var(--accent); color: var(--ink); }
  #tabs button[data-tab="motion"], #tabs button[data-tab="rail"] { display: none; }
  #viewBtn { display: none; }
}
@media (orientation: landscape) and (min-width: 760px) and (max-height: 430px) { #tabs button { min-height: 34px; font-size: 12px; } }

/* the popup while the tools load */
#tools { position: relative; }
#toolsLoad { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); background: var(--panel); border: 1px solid var(--accent); border-radius: 16px; padding: 22px 28px; display: grid; gap: 8px; justify-items: center; text-align: center; max-width: 86%; box-shadow: 0 8px 40px #000a; z-index: 2; }
#toolsLoad b { font-size: 18px; color: var(--text); }
#toolsLoad span { color: var(--dim); font-size: 14px; }
#toolsLoad { min-width: min(420px, 86%); }
#toolsLoad em { display: block; width: 100%; height: 8px; border-radius: 4px; background: var(--tile); overflow: hidden; margin-top: 4px; }
#toolsLoad i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width .25s; }
#toolsLoad.wait i { background: repeating-linear-gradient(45deg, var(--accent) 0 12px, #ffb00066 12px 24px); background-size: 34px 34px; animation: tstripe .8s linear infinite; }
@keyframes tstripe { to { background-position: 34px 0; } }
#tools.loading iframe { visibility: hidden; }
