  :root {
    --bg: #151A2E;
    --panel: #1B2140;
    --field: #0F1327;
    --line: #2A3258;
    --text: #D7DBEA;
    --dim: #6C7597;
    --accent: #F2E8C6;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  }
  html { height: 100%; }
  body { height: 100vh; height: 100dvh; margin: 0; background: var(--bg); color: var(--text); font: 13px/1.4 var(--mono); }
  body { display: flex; flex-direction: column; }
  /* Header: two fixed rows. Row 1 is identity and the menu bar; row 2 is the transport. */
  /* On a phone with a notch the page runs under the status bar (viewport-fit=cover): the first thing on screen keeps clear of it. */
  header { display: flex; flex-direction: column; gap: 4px; padding: calc(6px + env(safe-area-inset-top)) 14px 8px; border-bottom: 1px solid var(--line); background: var(--panel); }
  header .bar { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: flex-end; }
  #topbar { align-items: center; gap: 6px 12px; }
  #topbar #title { flex: 0 1 18em; min-width: 6em; background: none; border-color: transparent; color: var(--accent); }
  #topbar #title:hover, #topbar #title:focus { border-color: var(--line); background: var(--field); }
  #menus { display: flex; gap: 4px; margin-left: auto; }
  #menus button, .tools button { color: var(--dim); background: none; border-color: transparent; padding: 3px 10px; }
  #menus button:hover, .tools button:hover { color: var(--text); border-color: var(--line); }
  #menus button.on, .tools button.on { color: var(--accent); background: var(--field); border-color: var(--line); }
  .tools { display: flex; gap: 2px; }
  .tools button { padding: 3px 8px; }
  h1 { font: italic 500 19px/1 "Iowan Old Style", "Palatino Linotype", Georgia, serif; margin: 0 6px 0 0; color: var(--accent); }
  h1 small { font: 12px/1 var(--mono); color: var(--dim); font-style: normal; margin-left: 8px; }
  .group { display: flex; gap: 6px; align-items: center; position: relative; padding-top: 13px; }
  .group::before { content: attr(data-label); position: absolute; top: 0; left: 0; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; color: var(--dim); }
  .group:not([data-label]) { padding-top: 13px; }
  .group .sep { width: 1px; height: 18px; background: var(--line); margin: 0 4px; }
  h1 { padding-bottom: 4px; }
  .group > label { color: var(--dim); }
  button, select, input { font: inherit; color: var(--text); background: var(--field); border: 1px solid var(--line); border-radius: 3px; padding: 3px 8px; }
  input[type=number] { width: 4.5em; }
  input[type=text] { width: 9em; }
  button { cursor: pointer; }
  button:hover { border-color: var(--accent); }
  button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
  button.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600; }
  .spacer { flex: 1; }
  #workspace { flex: 1; min-height: 0; display: flex; position: relative; }
  #emptyAdd { position: absolute; left: 110px; top: 64px; z-index: 3; padding: 8px 16px; }
  #emptyAdd[hidden] { display: none; }
  main { flex: 1; min-width: 0; min-height: 0; position: relative; }
  /* Mixer sidebar */
  #mixer { width: 250px; flex: none; border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; display: flex; flex-direction: column; }
  #mixer[hidden] { display: none; }
  .mixHead { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
  .mixHead button { padding: 1px 6px; }
  .strip { display: grid; grid-template-columns: 1fr auto auto auto; gap: 2px 6px; align-items: center; padding: 5px 8px; border-bottom: 1px solid var(--line); }
  .strip.cur { background: var(--field); }
  .strip .name { text-align: left; padding: 1px 6px; border-color: transparent; background: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .strip .name.silent { color: var(--num); }
  .strip .live { min-width: 3.2em; text-align: right; font-size: 11px; color: var(--accent); background: linear-gradient(to right, rgba(242,232,198,.22) var(--vel, 0%), transparent var(--vel, 0%)); border-radius: 2px; padding: 0 3px; }
  .strip .tog { padding: 0 6px; min-height: 0; line-height: 1.5; color: var(--dim); }
  .strip .tog.on { color: var(--bg); background: var(--accent); border-color: var(--accent); }
  .strip .sl { grid-column: 1 / 5; display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--dim); }
  .strip .sl input { flex: 1; min-width: 0; margin: 0; }
  .strip .sl span { width: 2.2em; text-align: right; color: var(--text); }
  canvas { display: block; width: 100%; height: 100%; outline: none; touch-action: none; }
  footer { border-top: 1px solid var(--line); background: var(--panel); padding: 6px 14px; font-size: 12px; }
  #status { display: flex; gap: 22px; flex-wrap: wrap; color: var(--dim); min-height: 1.4em; }
  #status b { color: var(--text); font-weight: 500; }
  #status .warn { color: #E9A26B; }
  #status a[data-panel] { cursor: pointer; }
  #status a[data-panel]:hover { color: var(--text); text-decoration: underline; }
  details summary { cursor: pointer; color: var(--dim); margin-top: 4px; }
  #version { float: right; color: var(--dim); font-size: 11px; }
  #helpLink { margin-left: 10px; color: var(--accent); text-decoration: none; }
  #helpLink:hover { text-decoration: underline; }
  #buildsLink { margin-left: 10px; color: var(--dim); text-decoration: none; }
  #buildsLink:hover { color: var(--text); text-decoration: underline; }
  #buildsLink[hidden] { display: none; }
  #help { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 4px 28px; margin-top: 8px; color: var(--dim); }
  #help p { margin: 2px 0; }
  #help kbd { color: var(--text); background: var(--field); border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; }
  #help h3 { font: inherit; color: var(--text); margin: 8px 0 3px; }
  #help table.keys { border-collapse: collapse; }
  #help table.keys td { padding: 1px 0; vertical-align: top; }
  #help table.keys td:first-child { white-space: nowrap; padding-right: 10px; }
  #help .alt { opacity: .7; }
  /* Panels: one open at a time, a sheet under the header on wide screens */
  #panels { flex: none; }
  .panel { border-bottom: 1px solid var(--line); background: var(--panel); padding: 6px 14px 10px; max-height: 60vh; overflow: auto; min-width: 0; box-sizing: border-box; }
  .panel[hidden] { display: none; }
  .panelHead { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; }
  .panelHead h2 { font: 500 12px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--accent); margin: 0; }
  .panelHead .dim { font-size: 11px; }
  .panelHead button { padding: 1px 7px; }
  .panelBody { display: flex; flex-wrap: wrap; gap: 8px 28px; align-items: flex-start; }
  .panelBody .group { flex-wrap: wrap; }
  .panelBody p.dim { flex-basis: 100%; margin: 0; font-size: 12px; }
  .patterngrp { flex-direction: column; align-items: flex-start; }
  .patterngrp .dim { font-size: 11px; max-width: 40em; }
  #patternsTable { border-collapse: collapse; }
  #patternsTable th { color: var(--dim); font-weight: normal; text-align: left; padding: 2px 6px; }
  #patternsTable td { padding: 2px 6px; white-space: nowrap; }
  #patternsTable tr.cur td { color: var(--accent); }
  #patternsTable button { padding: 1px 6px; margin-left: 4px; }
  .listen { margin-bottom: 6px; }
  .short { display: none; }
  #rec.on { background: #B23A3A; border-color: #B23A3A; color: #fff; }
  /* Selection toolbar */
  #selbar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 4px 8px; border-top: 1px solid var(--line); background: var(--panel); }
  #selbar[hidden] { display: none; }
  #selbar #selInfo { color: var(--accent); margin-right: 8px; }
  #selbar .sep { width: 1px; height: 18px; background: var(--line); margin: 0 4px; }
  #selbar button, #selbar select { padding: 2px 7px; }
  /* Touch pad under the grid */
  #pad { display: none; border-top: 1px solid var(--line); background: var(--panel); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); user-select: none; -webkit-user-select: none; }
  body.padon #pad { display: block; }
  .padrow { display: flex; gap: 4px; margin-top: 4px; }
  .padrow:first-child { margin-top: 0; }
  #padKeys { display: grid; grid-template-columns: repeat(var(--cols, 8), 1fr); grid-auto-rows: 40px; }
  #padKeys button { grid-column: span 2; }
  #padKeys button.black { grid-row: 1; }
  #padKeys button.white { grid-row: 2; }
  .padrow button { flex: 1 1 0; min-width: 0; min-height: 40px; padding: 0 2px; touch-action: manipulation; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .padrow button.black { background: #0A0D1C; color: var(--dim); }
  .padrow button.out { opacity: .4; }
  .padrow button.act { color: var(--accent); }
  .padrow button.small { font-size: 12px; }
  @media (pointer: coarse) {
    button, select, input { min-height: 36px; padding: 4px 10px; font-size: 14px; }
    input[type=checkbox] { width: 20px; height: 20px; min-height: 0; }
  }
  @media (max-width: 760px) {
    header { gap: 4px; padding: 4px 8px 6px; }
    header .bar { gap: 4px 8px; }
    h1 small, .full, .spacer, #menus { display: none; }
    .short { display: inline; }
    #topbar #title { flex: 1 1 6em; }
    .tools { margin-left: auto; }
    .primary { padding-top: 0; }
    .primary::before { display: none; }
    .phrasesel { padding-top: 0; }
    .phrasesel::before { display: none; }
    .primary label[title] { display: none; }
    /* An open panel replaces the grid, except View which stays a sheet over it */
    #panels { display: contents; }
    .panel { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); max-height: none; }
    .panel:not([data-panel="view"]) { flex: 1; min-height: 0; border-bottom: 0; }
    body[data-panel="files"] #workspace, body[data-panel="instruments"] #workspace, body[data-panel="level"] #workspace, body[data-panel="connect"] #workspace { display: none; }
    body[data-panel="files"] #pad, body[data-panel="instruments"] #pad, body[data-panel="level"] #pad, body[data-panel="connect"] #pad, body[data-panel="files"] #selbar, body[data-panel="instruments"] #selbar, body[data-panel="level"] #selbar, body[data-panel="connect"] #selbar { display: none !important; }
    .panelBody { flex-direction: column; gap: 12px; }
    .panelBody .group { width: 100%; }
    .panel { width: 100%; }
    #transportbar { flex-wrap: nowrap; gap: 4px; }
    #transportbar label[for="bpm"] { display: none; }
    #transportbar #bpm { width: 3.2em; padding-left: 6px; padding-right: 4px; }
    #transportbar button { padding-left: 8px; padding-right: 8px; }
    .phrasesel { margin-left: auto; }
    #mixer { position: absolute; right: 0; top: 0; bottom: 0; width: min(82vw, 320px); z-index: 5; box-shadow: -6px 0 18px rgba(0,0,0,.5); }
    footer { padding: 4px 8px calc(4px + env(safe-area-inset-bottom)); }
    body.padon footer { padding-bottom: 4px; }
    /* one scrolling row: a wrapped toolbar took the grid's height on a phone */
    #selbar { gap: 3px; padding: 3px 6px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
    #selbar::-webkit-scrollbar { display: none; }
    #selbar button, #selbar select { min-height: 32px; padding: 2px 8px; font-size: 13px; flex: none; }
    #selbar #selInfo { flex: none; margin: 0 6px 0 0; font-size: 12px; white-space: nowrap; }
    #selbar .sep { flex: none; }
    #status { display: block; white-space: nowrap; overflow-x: auto; }
    #status > span { margin-right: 18px; }
    #help { grid-template-columns: 1fr; }
  }
  @media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.dim { color: var(--dim); max-width: 46em; }
.dlgHead, .dlgFoot { display: flex; gap: 8px; align-items: center; margin: 2px 0 8px; }
.dlgFoot { margin: 8px 0 0; }

/* Sounds panel: dense, monospace, M8-flavoured */
.m8 { font-family: var(--mono); font-size: 12px; background: #0E1226; }
.m8 .panelHead h2 { letter-spacing: .12em; }
.m8 .mono { font-size: 11px; }
.m8 .panelHead button { padding: 1px 7px; font-size: 11px; }
.m8 .listen label { color: #6C7597; }
.scopes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 0 10px; }
.scope { background: #0A0D1C; border: 1px solid #1F2647; border-radius: 3px; height: 92px; position: relative; }
.scope canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.scopeLabel { position: absolute; top: 3px; left: 8px; z-index: 1; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: #6C7597; pointer-events: none; }
.scopeLabel b { font-weight: 500; }
#soundsTable { border-collapse: collapse; width: 100%; }
#soundsTable th { text-align: left; font-weight: normal; color: #6C7597; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; padding: 3px 6px; border-bottom: 1px solid #1F2647; }
#soundsTable td { padding: 3px 6px; border-bottom: 1px solid #161B36; vertical-align: middle; white-space: nowrap; }
#soundsTable tr:hover td { background: #131834; }
#soundsTable .name { color: var(--text); }
#soundsTable .name small { display: block; color: #6C7597; font-size: 10px; }
#soundsTable .swatch { display: inline-block; width: 6px; height: 22px; background: var(--fam); margin-right: 8px; vertical-align: middle; border-radius: 1px; }
.status b { font-weight: 600; letter-spacing: .08em; font-size: 11px; font-family: var(--mono); }
.status .ok { color: #86B58F; } .status .warn { color: #E9A26B; } .status .dim { color: #6C7597; }
#soundsTable .arts, .inst .arts { display: flex; gap: 4px; flex-wrap: wrap; }
#soundsTable .art, .inst .art { padding: 1px 6px; min-height: 0; line-height: 1.6; font-size: 11px; color: #6C7597; border-color: #1F2647; background: #0A0D1C; }
#soundsTable .art.real, .inst .art.real { color: var(--fam); border-color: var(--fam); }
#soundsTable .art i, .inst .art i { font-style: normal; opacity: .7; margin-left: 2px; }
#soundsTable .art:hover, .inst .art:hover { color: var(--accent); border-color: var(--accent); }
#soundsTable .play, .inst .play { padding: 1px 8px; min-height: 0; color: var(--accent); border-color: var(--accent); }
#soundsTable .num input { width: 4.2em; padding: 2px 4px; font-size: 12px; min-height: 0; text-align: right; }
#soundsTable .reset { padding: 1px 6px; min-height: 0; }
#soundsTable .reset:disabled { opacity: .3; }
@media (max-width: 760px) { .scopes { grid-template-columns: 1fr; } .scope { height: 70px; } #soundsTable th:nth-child(4), #soundsTable td:nth-child(4) { display: none; } }

/* Phone screens: a tab bar switches between the grid and the panels */
#tabs { display: none; }
@media (max-width: 760px) {
  #tabs { display: flex; border-top: 1px solid var(--line); background: var(--panel); padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); gap: 4px; }
  body.padon #tabs { padding-bottom: 4px; }
  #tabs button { flex: 1; min-height: 38px; color: var(--dim); border-color: transparent; background: none; font-size: 12px; padding: 4px 2px; }
  #tabs button.on { color: var(--accent); background: var(--field); border-color: var(--line); }
                  }

/* Banks in the Sounds panel */
#bankBar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 2px 0 8px; }
#bankBar .lbl { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: #6C7597; margin-right: 4px; }
#bankBar .bank { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border: 1px solid #1F2647; border-radius: 3px; background: #0A0D1C; font-size: 11px; color: #6C7597; cursor: pointer; }
#bankBar .bank.on { color: var(--accent); border-color: var(--accent); }
#bankBar .bank i { font-style: normal; opacity: .7; }
#bankBar .bank.busy { opacity: .6; }
#bankBar .bank.hidden { text-decoration: line-through; opacity: .55; }
#bankUrlForm { display: inline-flex; gap: 4px; margin-left: auto; }
#bankUrlForm input { width: 16em; font-size: 11px; min-height: 0; padding: 2px 6px; }
#bankUrlForm button { font-size: 11px; padding: 1px 7px; min-height: 0; }
#soundsTable .bankcell { color: #6C7597; font-size: 11px; }
@media (max-width: 760px) { #bankUrlForm { margin-left: 0; width: 100%; } #bankUrlForm input { flex: 1; } #soundsTable th:nth-child(2), #soundsTable td:nth-child(2) { display: none; } }

/* The map: song › section › phrase › pattern. The level you are at is lit; every crumb is a way back out. */
#map { display: flex; align-items: stretch; gap: 2px; padding: 3px 10px; border-bottom: 1px solid var(--line); background: #171C36; overflow-x: auto; scrollbar-width: none; }
#map::-webkit-scrollbar { display: none; }
#map .crumb { display: flex; align-items: baseline; gap: 6px; padding: 2px 9px; background: none; border-color: transparent; color: var(--dim); white-space: nowrap; }
#map .crumb small { font-size: 9px; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); }
#map .crumb b { font-weight: 500; color: var(--text); }
#map .crumb b i, .formChip i, #songBody .svSec i { font-style: normal; color: var(--dim); margin-left: 1px; }
#map .crumb span { font-size: 11px; color: var(--dim); }
#map .crumb:hover:not(:disabled) { border-color: var(--line); }
#map .crumb.on { background: var(--accent); border-color: var(--accent); }
#map .crumb.on small, #map .crumb.on b, #map .crumb.on span, #map .crumb.on b i { color: var(--bg); }
#map .crumb:disabled { opacity: .45; cursor: default; }
#map .sep { align-self: center; color: var(--dim); }
#map .now { align-self: center; font-size: 11px; color: var(--accent); white-space: nowrap; padding-left: 12px; }

/* The Song view: sections in playing order, their phrases, and what every instrument plays in each */
body[data-level="song"] main { display: none; }
body[data-level="song"] #pad, body[data-level="song"] #selbar { display: none !important; }
#songView { flex: 1; min-width: 0; min-height: 0; overflow: auto; background: var(--bg); outline: none; --svLeft: 250px; --svCell: 78px; }
#songView[hidden] { display: none; }
#songBody { min-width: min-content; padding-bottom: 24px; }
.svGrid { display: grid; grid-template-columns: var(--svLeft) repeat(var(--n), minmax(var(--svCell), 1fr)); }
.svRow, .svSec { display: contents; }
.svRow > *, .svSecIn { border-bottom: 1px solid #1C2244; }
.svLeft { position: sticky; left: 0; z-index: 2; background: var(--bg); display: flex; align-items: center; gap: 6px; padding: 3px 8px 3px 12px; border-right: 1px solid var(--line); min-height: 34px; box-shadow: inset 3px 0 0 var(--sec, transparent); }
.svInstruments > * { position: sticky; top: 0; z-index: 3; background: var(--panel); border-bottom: 1px solid var(--line); }
.svInstruments .svLeft { z-index: 4; background: var(--panel); flex-wrap: wrap; row-gap: 2px; }
.svFormLabel { font-size: 9px; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); }
.svForm { display: flex; flex-wrap: wrap; gap: 3px; }
.formChip { padding: 0 6px; min-height: 0; line-height: 1.5; font-size: 12px; border-color: var(--sec); color: var(--sec); background: none; }
.formChip.playing { background: var(--sec); color: var(--bg); }
.count { display: none; margin-left: 4px; padding: 0 5px; border-radius: 8px; background: var(--accent); color: var(--bg); font-weight: 700; font-size: 11px; white-space: nowrap; }
.count.on { display: inline-block; }
.formChip.playing i { color: var(--bg); }
.svInstrument { padding: 4px 6px 3px; font-size: 11px; color: var(--fam); box-shadow: inset 0 2px 0 var(--fam); display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.svInstrument b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.svInstrument .live { min-height: 1.2em; color: var(--accent); font-size: 11px; background: linear-gradient(to right, rgba(242,232,198,.22) var(--vel, 0%), transparent var(--vel, 0%)); border-radius: 2px; padding: 0 2px; }
.svSecIn { grid-column: 1 / -1; position: sticky; left: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 5px 8px 5px 12px; background: #1A2040; box-shadow: inset 3px 0 0 var(--sec); width: var(--svW, 100%); box-sizing: border-box; }
#songBody select { max-width: 9.5em; }
.svSec.again .svSecIn { background: #181D3A; }
.svSec.spare .svSecIn { opacity: .7; }
.svSecIn .swatch { width: 10px; height: 10px; border-radius: 2px; background: var(--sec); }
.svSecIn input[data-f="secName"] { font-weight: 600; color: var(--sec); background: none; border-color: transparent; width: 8em; }
.svSecIn input[data-f="secName"]:hover, .svSecIn input[data-f="secName"]:focus, .svLeft input[type=text]:hover, .svLeft input[type=text]:focus { border-color: var(--line); background: var(--field); }
.svSecIn label, .svLeft label { color: var(--dim); display: inline-flex; align-items: center; gap: 1px; }
#songBody input[type=number] { width: 3.1em; padding: 1px 3px; }
#songBody select, #songBody button { padding: 1px 6px; font-size: 12px; min-height: 0; }
.svSecIn .note { font-size: 11px; }
.svLeft input[type=text] { background: none; border-color: transparent; width: 5.2em; padding: 1px 4px; color: var(--text); }
.svLeft .meta { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.svLeft .acts { display: none; gap: 2px; margin-left: auto; }
.svPhrase:hover .acts, .svPhrase.cur .acts { display: inline-flex; }
.svPhrase:hover .meta, .svPhrase.cur .meta { display: none; }
.svCell { position: relative; min-height: 34px; border-right: 1px solid #1C2244; cursor: pointer; overflow: hidden; }
.svCell.empty::after { content: '·'; position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); opacity: .6; }
.svCell:hover { background: #1B2142; }
.svCell.cur { outline: 2px solid var(--accent); outline-offset: -2px; z-index: 1; }
.svPhrase.cur > .svLeft { background: #1B2142; }
.svPhrase.playing > * { background-image: linear-gradient(to right, rgba(242,232,198,.10), rgba(242,232,198,.10)); }
.svPhrase.playing > .svCell::before { content: ''; position: absolute; top: 0; bottom: 0; left: var(--pos, 0%); width: 2px; background: var(--accent); opacity: .8; z-index: 1; }
.thumb { position: absolute; inset: 3px 2px; width: calc(100% - 4px); height: calc(100% - 6px); }
.thumb rect { fill: var(--fam, #8FA6E6); }
.thumb rect.pl { opacity: .55; }
.svCell .chips { position: absolute; left: 2px; right: 2px; bottom: 1px; display: flex; gap: 2px; overflow: hidden; }
#songBody .ptn { padding: 0 4px; font-size: 10px; line-height: 1.35; border-radius: 2px; color: var(--accent); background: rgba(21,26,46,.86); border-color: rgba(242,232,198,.35); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
#songBody .ptn:hover { border-color: var(--accent); }
.svCell .pcount { display: none; position: absolute; right: 2px; bottom: 1px; font-size: 10px; color: var(--accent); background: rgba(21,26,46,.86); padding: 0 2px; border-radius: 2px; }
.secActs { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.svCell .more { font-size: 10px; color: var(--dim); background: rgba(21,26,46,.86); padding: 0 2px; }
.svAdd .svLeft { grid-column: 1 / -1; position: sticky; left: 0; width: var(--svW, 100%); box-sizing: border-box; border-right: 0; gap: 12px; }
.svPatterns { position: sticky; left: 0; width: var(--svW, 100%); box-sizing: border-box; padding: 14px 12px 0; }
.svPatterns h3 { font: 500 12px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--accent); margin: 0 0 8px; }
.svPatterns h3 .dim { text-transform: none; letter-spacing: 0; font-size: 11px; margin-left: 8px; }
.ptnList { display: flex; flex-wrap: wrap; gap: 8px; }
.ptnCard { position: relative; display: grid; grid-template-columns: 110px auto; grid-template-rows: auto auto; gap: 2px 8px; align-items: center; padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel); }
.ptnCard .thumb { position: static; grid-row: 1 / 3; width: 110px; height: 40px; background: var(--field); border-radius: 2px; }
.ptnCard .thumb rect { fill: var(--accent); }
.ptnCard input { grid-column: 2; background: none; border-color: transparent; color: var(--accent); width: 9em; padding: 1px 4px; }
.ptnCard input:hover, .ptnCard input:focus { border-color: var(--line); background: var(--field); }
.ptnCard .dim { grid-column: 2; font-size: 11px; }
.ptnCard button { grid-row: 3; }
@media (max-width: 760px) {
  #map { padding: 1px 6px; }
  #map .crumb { padding: 1px 6px; gap: 4px; min-height: 28px; font-size: 13px; }
  #map .crumb small { display: none; }
  #map .crumb span { display: none; }
  #map .crumb[data-level="song"] b { display: none; }               /* the title is right above; say where you can go */
  #map .crumb[data-level="song"] small { display: inline; font-size: 13px; letter-spacing: 0; text-transform: none; color: var(--text); }
  #map .crumb.on[data-level="song"] small { color: var(--bg); }
  #map .now { display: none; }
  #transportbar #rec { white-space: nowrap; }
  #transportbar #phrase { max-width: 5.6em; }
  .svInstruments .svLeft { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .svInstruments .svLeft::-webkit-scrollbar { display: none; }
  .svFormLabel { display: none; }
  .svForm { flex-wrap: nowrap; }
  .svSec:not(.cur) .secActs, .svSecIn .note { display: none; }
  .svSecIn { gap: 4px; padding: 3px 6px 3px 8px; }
  .svCell .chips { display: none; }
  .svCell .pcount { display: block; }
  #songView { --svLeft: 148px; --svCell: 58px; }
  .svLeft { flex-wrap: wrap; padding: 3px 4px 3px 8px; row-gap: 1px; }
  .svLeft input[type=text] { width: 4.4em; }
  .svLeft .acts { display: inline-flex; flex-basis: 100%; margin-left: 0; }
  .svLeft .meta { display: none; }
  .svPhrase:not(.cur) .acts { display: none; }
  #songBody select, #songBody button, #songBody input { min-height: 30px; font-size: 13px; }
  #songBody .ptn { min-height: 0; font-size: 10px; }
  .svCell { min-height: 44px; }
  .wide { display: none; }
  body[data-panel="files"] #workspace, body[data-panel="files"] #map, body[data-panel="instruments"] #map, body[data-panel="level"] #map, body[data-panel="connect"] #map { display: none; }
}

/* ---- Instruments panel: one row per player, details on demand; the sound browser below ---- */
#instList { display: flex; flex-direction: column; gap: 2px; width: 100%; }
.inst { border-left: 3px solid var(--fam); background: #141934; border-radius: 0 3px 3px 0; }
.inst.open { background: #181E3D; }
.instMain, .instMore { display: flex; align-items: center; gap: 8px; padding: 4px 8px; flex-wrap: wrap; }
.instMore { padding: 2px 8px 8px 14px; color: var(--dim); font-size: 12px; }
.inst .swatch { display: none; }
.inst input[data-f="name"] { width: 9.5em; font-weight: 500; background: none; border-color: transparent; }
.inst input[data-f="name"]:hover, .inst input[data-f="name"]:focus { border-color: var(--line); background: var(--field); }
.inst select[data-f="sound"] { max-width: 13em; }
.inst input[type=range] { width: 84px; }
.inst .slide { display: inline-flex; align-items: center; gap: 4px; color: var(--dim); font-size: 11px; }
.inst .ms { display: inline-flex; align-items: center; gap: 2px; color: var(--dim); font-size: 12px; }
.inst button { padding: 2px 8px; min-height: 0; }
.inst .status { min-width: 2.6em; }
.inst [data-act="more"] { margin-left: auto; display: inline-flex; gap: 6px; align-items: center; }
.inst .shape { color: var(--fam); font-family: var(--mono); font-size: 11px; }
.instMore label { display: inline-flex; align-items: center; gap: 4px; }
.instMore input[type=number] { width: 4.4em; padding: 2px 4px; text-align: right; }
.instMore .spacer { flex: 1; }
.instMore button:disabled { opacity: .3; }
/* order and remove sit in the row when the panel is wide enough for them, else with the details */
#instList { container-type: inline-size; }
.inst .roomy, .inst .tight { display: inline-flex; gap: 4px; align-items: center; }
.inst .roomy { display: none; }
.inst button:disabled { opacity: .3; }
@container (min-width: 960px) { .inst .roomy { display: inline-flex; } .inst .tight { display: none; } .inst [data-act="more"] { margin-left: 0; } .inst .roomy { margin-left: auto; } }
.instAdd { display: flex; gap: 8px; align-items: center; margin: 8px 0 4px; }
#soundBrowser { width: 100%; margin-top: 6px; font-family: var(--mono); font-size: 12px; }
#soundBrowser > summary { cursor: pointer; color: var(--dim); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; padding: 4px 0; }
#soundBrowser[open] > summary { color: var(--text); }
#soundsTable [data-act="add"] { padding: 1px 8px; min-height: 0; }
#soundsTable [data-act="add"] i { font-style: normal; color: var(--dim); }
#instrumentsPanel .panelBody { flex-direction: column; align-items: stretch; }
#levelPanel[data-scope="song"] .phraseset, #levelPanel[data-scope="section"] .phraseset, #levelPanel[data-scope="pattern"] .keygrp { display: none; }
#map .crumbWrap { display: inline-flex; align-items: stretch; }
#map .crumbSet { padding: 0 5px; min-height: 0; background: none; border-color: transparent; color: var(--dim); font-size: 10px; margin-left: -4px; }
#map .crumbSet:hover { color: var(--text); border-color: var(--line); }
@media (max-width: 760px) {
  .instMain { gap: 4px 5px; padding: 4px 6px; }
  .inst .slide { font-size: 10px; gap: 2px; }
  .inst .ms { gap: 0; }
  .inst button { padding: 2px 7px; }
  .inst input[data-f="name"] { width: 7em; }
  .inst select[data-f="sound"] { max-width: 9em; }
  .inst input[type=range] { width: 46px; }
  .inst input, .inst select, .inst button { min-height: 32px; font-size: 13px; }
  #map .crumbSet { padding: 0 8px; font-size: 12px; }
}

/* ---- Pocket view: one phone screen in the image of the M8 ---------------------------------------- */
body.pocket header, body.pocket #map, body.pocket #workspace, body.pocket #tabs, body.pocket footer, body.pocket #panels, body.pocket #selbar, body.pocket #pad, body.pocket #emptyAdd { display: none !important; }
body.pocket { overflow: hidden; }
#pocket { display: flex; flex-direction: column; height: 100dvh; background: #0B0E1C; color: var(--text); font-family: var(--mono); font-size: 15px; line-height: 1.35; outline: none; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
#pocket[hidden] { display: none; }
#pkTop { display: flex; align-items: center; gap: 6px; padding: calc(6px + env(safe-area-inset-top)) 8px 6px; border-bottom: 1px solid var(--line); background: #10142A; }
#pkLevels { display: flex; gap: 3px; }
#pkLevels button { padding: 4px 7px; min-height: 0; font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--dim); background: #171C36; border: 1px solid var(--line); border-radius: 3px; }
#pkLevels button.on { background: var(--accent); color: var(--bg); border-color: var(--accent); }
#pkNow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--accent); font-size: 12px; text-align: right; }
#pkMenuBtn { padding: 2px 9px; min-height: 0; font-size: 16px; line-height: 1; }
#pkBody { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 4px 8px; }
#pkMsg { min-height: 0; padding: 0 8px; color: var(--warn, #E9A26B); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#pkMsg:empty { display: none; }
#pkHint { padding: 3px 8px; color: var(--dim); font-size: 11px; line-height: 1.4; border-top: 1px solid var(--line); }
#pkHint b { color: var(--text); font-weight: 600; }
.pkLine { display: flex; gap: 8px; align-items: baseline; white-space: nowrap; padding: 1px 4px; border-radius: 3px; min-height: 22px; }
.pkLine.cur { background: #1B2145; }
.pkLine.playing { box-shadow: inset 3px 0 0 var(--accent); }
.pkRow.past { opacity: .45; }
.pkRow.past .pkNum { color: var(--accent); }
.pkLine.beat .pkNum { color: var(--text); }
.pkHead { color: var(--dim); border-bottom: 1px solid var(--line); margin-bottom: 3px; padding-bottom: 3px; }
.pkHead .pkName { color: var(--text); font-weight: 700; }
.pkBar { margin-top: 6px; color: var(--accent); font-weight: 700; letter-spacing: .05em; }
.pkBar.spare { color: var(--dim); }
.pkBar.cur { background: #2A2A40; }
.pkAdd { color: var(--dim); margin-top: 4px; }
.pkAdd.cur { color: var(--text); }
.pkName { width: 5.5ch; flex: none; overflow: hidden; text-overflow: ellipsis; }
.pkBar .pkName { width: auto; }
.pkName i { font-style: normal; color: var(--dim); }
.pkHead .pkName, .pkSong .pkName, .pkRow .pkName:only-child { width: auto; flex: 1; }
.pkRep, .pkKey { color: var(--dim); }
.pkNum { width: 2.5ch; flex: none; color: var(--dim); font-size: 12px; }
.pkCol { width: 7.5ch; flex: none; overflow: hidden; text-overflow: ellipsis; color: var(--dim); font-size: 12px; }
.pkCol.cur { color: var(--accent); }
.pkCell { width: 7.5ch; flex: none; color: var(--text); }
.pkCell.inside { color: var(--dim); }
.pkCell.cur { background: var(--accent); color: var(--bg); border-radius: 2px; padding: 0 2px; margin: 0 -2px; }
.pkRow[data-ai] .pkCell, .pkRow[data-ai] .pkCol { width: 3.5ch; }
.pkLabel { width: 9ch; flex: none; color: var(--dim); }
.pkVal { flex: 1; }
.pkVal.cur { color: var(--accent); }
.pkVal.cur::before { content: '◂ '; color: var(--dim); }
.pkVal.cur::after { content: ' ▸'; color: var(--dim); }
.pkSong .pkName { color: var(--text); }
#pkLive { display: flex; flex-wrap: wrap; gap: 2px 8px; padding: 4px 8px; border-top: 1px solid var(--line); background: #0E1226; font-size: 12px; color: var(--dim); min-height: 22px; }
#pkLive span { display: inline-flex; gap: 4px; align-items: center; }
#pkLive span b { font-weight: 500; color: var(--dim); }
#pkLive span.on { color: var(--text); background: linear-gradient(to right, rgba(242,232,198,.22) var(--vel), transparent var(--vel)); border-radius: 2px; padding: 0 3px; }
#pkPad { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #10142A; touch-action: none; }
#pkPad button { min-height: 0; font-family: var(--mono); font-weight: 700; color: var(--text); background: #1B2145; border: 1px solid #2A3160; border-radius: 8px; padding: 0; touch-action: none; -webkit-user-select: none; user-select: none; }
#pkPad button.held { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.pkDpad { display: grid; grid-template-columns: 52px 52px 52px; grid-template-rows: 52px 52px 52px; gap: 2px; justify-self: start; }
.pkDpad [data-btn="up"] { grid-column: 2; grid-row: 1; } .pkDpad [data-btn="left"] { grid-column: 1; grid-row: 2; } .pkDpad [data-btn="right"] { grid-column: 3; grid-row: 2; } .pkDpad [data-btn="down"] { grid-column: 2; grid-row: 3; }
.pkMid { display: flex; flex-direction: column; gap: 8px; }
.pkMid button { width: 58px; height: 30px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; border-radius: 15px; color: var(--dim); }
.pkAb { display: grid; grid-template-columns: 56px 56px; grid-template-rows: 34px 62px; gap: 6px; justify-self: end; align-items: end; }
.pkAb [data-btn="lb"], .pkAb [data-btn="rb"] { height: 34px; font-size: 12px; color: var(--text); }
.pkAb .pkB, .pkAb .pkA { height: 62px; border-radius: 50%; font-size: 20px; }
.pkAb .pkA { background: #2A2A40; }
@media (min-width: 761px) { #pocket { max-width: 430px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); } }

/* Sequencer: a line per pitch, a cell per row of the phrase, as many cells across as the screen holds */
#sequencer { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--bg); outline: none; --sqLabel: 112px; --sqCols: 16; --sqRow: 28px; --sqHit: #D98C8C; }
#sequencer[hidden] { display: none; }
body[data-seq="on"] main { display: none; }
body[data-seq="on"] #pad, body[data-seq="on"] #selbar { display: none !important; }
body[data-level="song"] #sequencer { display: none; }
#seqBtn.on { color: var(--accent); border-color: var(--accent); }
#sqBar { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--header, var(--panel)); min-height: 24px; }
#sqBar [hidden], #sqStrip [hidden] { display: none; }
#sqName { color: var(--sqHit); font-weight: normal; }
#sqPager { margin-left: auto; display: flex; gap: 8px; align-items: center; color: var(--dim); }
#sqPager button { padding: 1px 9px; }
#sqLines { position: relative; flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; padding: 0 10px 6px; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.sqLine { display: grid; grid-template-columns: var(--sqLabel) repeat(var(--sqCols), minmax(0, 1fr)); gap: 2px; margin-bottom: 2px; }
.sqRuler { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 4px 0 2px; margin-bottom: 0; }
.sqRuler span { font-size: 10px; line-height: 12px; color: var(--dim); overflow: hidden; white-space: nowrap; padding-left: 2px; }
.sqRuler span.bar { color: var(--accent); }
#sequencer .sqLabel { height: var(--sqRow); min-height: 0; padding: 0 6px 0 2px; background: none; border-color: transparent; color: var(--dim); text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; touch-action: manipulation; }
#sequencer .sqLabel.tonic { color: var(--text, #E6E3D6); }
#sequencer .sqLabel.out { opacity: .55; }
#sequencer .sqLabel.cur { color: var(--accent); opacity: 1; }
#sequencer .sqCell { position: relative; height: var(--sqRow); min-height: 0; min-width: 0; padding: 0; border: 1px solid transparent; border-radius: 3px; background: #1D2445; color: var(--bg); font: 600 11px/1 var(--mono); touch-action: manipulation; cursor: pointer; }
#sequencer .sqCell.alt { background: #171C36; }
#sequencer .sqCell.bar { border-left-color: #4A5590; }
#sequencer .sqCell.covered { background-image: linear-gradient(rgba(217,140,140,.07), rgba(217,140,140,.07)); }
#sequencer .sqCell.on::before { content: ""; position: absolute; inset: 2px; border-radius: 2px; background: var(--sqHit); opacity: calc(.35 + .65 * var(--v, 1)); }
#sequencer .sqCell.held::before { left: -5px; border-radius: 0 2px 2px 0; }
#sequencer .sqCell.on.placed::before { opacity: .28; }
#sequencer .sqCell.maybe::before { border: 2px dashed var(--bg); }
#sequencer .sqCell.held.maybe::before { border-left: 0; }
#sequencer .sqCell.early::after, #sequencer .sqCell.late::after { content: ""; position: absolute; top: 2px; bottom: 2px; width: 3px; background: var(--accent); }
#sequencer .sqCell.early::after { left: 0; }
#sequencer .sqCell.late::after { right: 0; }
#sequencer .sqCell i { position: relative; z-index: 1; font-style: normal; }
#sequencer .sqCell.play { background: #303A6E; }
#sequencer .sqCell.cur { border-color: var(--accent); }
#sequencer .sqCell:focus-visible, #sequencer .sqLabel:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }
#sqStrip { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; padding: 6px 10px; border-top: 1px solid var(--line); background: var(--panel); }
#sqWhat { color: var(--accent); font-weight: normal; min-width: 9em; }
.sqVal { display: inline-flex; align-items: center; gap: 4px; }
.sqVal output { min-width: 8.2em; text-align: center; }
.sqVal.off output { color: var(--dim); }
.sqVal button { padding: 1px 9px; }
@media (pointer: coarse) { #sequencer { --sqRow: 36px; } }
@media (max-width: 760px) {
  #sqLines { padding: 0 6px 6px; }
  #sequencer .sqLabel { font-size: 11px; padding: 0 2px 0 0; }
  #sqBar, #sqStrip { padding: 5px 6px; }
  #sqStrip { gap: 4px 8px; }
  #sqWhat { min-width: 100%; }
  .sqVal output { min-width: 6.6em; font-size: 12px; }
  .sqVal button { padding: 2px 10px; }
}
