  :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 { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: flex-end; padding: 6px 14px 8px; border-bottom: 1px solid var(--line); background: var(--panel); }
  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; }
  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; 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 .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 / 4; 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; }
  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; }
  #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; }
  /* Header: the transport stays in the first row; everything else lives in #more, which is inline on
     wide screens and folds behind the ☰ button on narrow ones. */
  h1 { order: -3; }
  #more { display: contents; }
  .songgrp { order: -2; }
  .primary { order: -1; }
  .patsel { order: 0; margin-right: -12px; }
  .patset { order: 0; }
  .patset::before { display: none; }
  .arrgrp { order: 1; }
  .keygrp { order: 2; }
  .entrygrp { order: 3; }
  .colgrp { order: 3; }
  .spacer { order: 4; }
  .outgrp { order: 5; }
  #menuToggle { display: none; }
  .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: 6px 8px; padding: 6px 8px; }
    h1 small, .full, .spacer { display: none; }
    .short { display: inline; }
    header > .group { gap: 4px; }
    #more .group { flex-wrap: wrap; }
    #title { flex: 1 1 8em; min-width: 0; }
    #menuToggle { display: inline-block; margin-left: auto; }
    #more { display: none; flex-basis: 100%; flex-wrap: wrap; gap: 8px 14px; padding-top: 6px; border-top: 1px solid var(--line); max-height: 55vh; overflow-y: auto; }
    #more .group { flex-basis: 100%; }
    .primary { padding-top: 0; }
    .primary::before { display: none; }
    .patsel { margin-right: 0; }
    .patset { padding-top: 13px; }
    .patset::before { display: block; }
    .primary label[title] { display: none; }
    #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); }
    header.open #more { display: flex; }
    footer { padding: 4px 8px calc(4px + env(safe-area-inset-bottom)); }
    body.padon footer { padding-bottom: 4px; }
    #selbar { gap: 3px; padding: 3px 6px; }
    #selbar button, #selbar select { min-height: 32px; padding: 2px 6px; font-size: 13px; }
    #selbar #selInfo { flex-basis: 100%; margin: 0; font-size: 12px; }
    #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; } }

/* Arranger chips */
#arranger { display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center; }
#arranger .chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 7px; border: 1px solid var(--line); border-radius: 3px; background: var(--field); cursor: grab; user-select: none; }
#arranger .chip.cur { border-color: var(--accent); color: var(--accent); }
#arranger .chip.next { border-style: dashed; border-color: var(--accent); }
#arranger .chip button, #arranger #arrAdd { padding: 0 5px; min-height: 0; line-height: 1.4; }
#arranger .chip i { font-style: normal; color: var(--dim); margin-left: 2px; }
#chainTable { border-collapse: collapse; margin-top: 8px; }
#chainTable th { color: var(--dim); font-weight: normal; text-align: left; padding: 2px 8px; }
#chainTable td { padding: 2px 8px; }
.dim { color: var(--dim); max-width: 46em; }
/* Tracks and mixer dialog */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; max-width: min(96vw, 900px); max-height: 90vh; overflow: auto; font: inherit; }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
.dlgHead, .dlgFoot { display: flex; gap: 8px; align-items: center; margin: 2px 0 8px; }
.dlgFoot { margin: 8px 0 0; }
#tracksTable { border-collapse: collapse; }
#tracksTable th { color: var(--dim); font-weight: normal; text-align: left; padding: 2px 6px; }
#tracksTable td { padding: 2px 6px; white-space: nowrap; }
#tracksTable input[type=range] { width: 80px; vertical-align: middle; }
#tracksTable td:first-child button { padding: 2px 5px; }

/* Sounds panel: dense, monospace, M8-flavoured */
dialog.m8 { font-family: var(--mono); font-size: 12px; background: #0E1226; border-color: #2A3258; max-width: min(96vw, 1040px); padding: 8px 10px 10px; }
dialog.m8 .dlgHead b { color: var(--accent); letter-spacing: .12em; }
dialog.m8 .mono { font-size: 11px; }
dialog.m8 .dlgHead button { padding: 1px 7px; font-size: 11px; }
.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; }
#soundsTable .status b { font-weight: 600; letter-spacing: .08em; }
#soundsTable .status .ok { color: #86B58F; } #soundsTable .status .warn { color: #E9A26B; } #soundsTable .status .dim { color: #6C7597; }
#soundsTable .arts { display: flex; gap: 4px; flex-wrap: wrap; }
#soundsTable .art { padding: 1px 6px; min-height: 0; line-height: 1.6; font-size: 11px; color: #6C7597; border-color: #1F2647; background: #0A0D1C; }
#soundsTable .art.real { color: var(--fam); border-color: var(--fam); }
#soundsTable .art i { font-style: normal; opacity: .7; margin-left: 2px; }
#soundsTable .art:hover { color: var(--accent); border-color: var(--accent); }
#soundsTable .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(6), #soundsTable td:nth-child(6), #soundsTable th:nth-child(8), #soundsTable td:nth-child(8) { display: none; } }

/* Phone screens: a tab bar switches between pattern, arrange, mixer and tracks */
#tabs { display: none; }
.view { flex: 1; min-width: 0; overflow-y: auto; padding: 10px 12px; background: var(--bg); }
.view h2 { font: 500 12px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--dim); margin: 0 0 10px; }
.view .viewBody { display: flex; flex-direction: column; gap: 14px; }
.view .group { flex-wrap: wrap; }
.view #tracksTable { width: 100%; }
.view #tracksTable td, .view #tracksTable th { white-space: nowrap; }
@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: 6px; }
  body.padon #tabs { padding-bottom: 4px; }
  #tabs button { flex: 1; min-height: 38px; color: var(--dim); border-color: transparent; background: none; font-size: 13px; }
  #tabs button.on { color: var(--accent); background: var(--field); border-color: var(--line); }
  body[data-view="mixer"] main, body[data-view="arrange"] main, body[data-view="tracks"] main { display: none; }
  body[data-view="mixer"] #mixer { position: static; width: auto; flex: 1; box-shadow: none; border-left: 0; }
  body[data-view="mixer"] #mixerClose { display: none; }
  body:not([data-view="pattern"]) #pad, body:not([data-view="pattern"]) #selbar { display: none !important; }
  .view #tracksTable input[type=range] { width: 60px; }
  .view #tracksTable td:nth-child(6), .view #tracksTable th:nth-child(6), .view #tracksTable td:nth-child(7), .view #tracksTable th:nth-child(7) { display: none; }
  .view #tracksTable td { padding: 3px 4px; }
  .view #tracksTable td:first-child { white-space: nowrap; }
  .view #tracksTable td:first-child button { padding: 2px 6px; min-height: 30px; }
  .view #tracksTable input[type=text] { width: 6.5em; }
  .view #tracksTable select { max-width: 8.5em; }
  .view #tracksTable input[type=number] { width: 3em !important; padding: 4px 4px; }
  .view #tracksTable input, .view #tracksTable select { min-height: 32px; font-size: 13px; }
  #tracksView { overflow: auto; }
}

/* 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; } }
