:root {
  --bg: #f4f4f6;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #6c6c72;
  --line: #d8d8de;
  --field: #f7f7f9;
  --accent: #d63b2f;
  --accent-text: #ffffff;
  --ok: #2f8f4e;
  --sim: #6a4fd8;
  --warn-bg: #fff1ef;
  --warn: #b3261e;
  --on-warn: #ffffff;
  --pedal: #1c1c1e;
  --pedal-edge: #3a3a3c;
  --cap: #d1d1d6;
  --cap-down: #8e8e93;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161618;
    --card: #232326;
    --text: #ececf0;
    --muted: #9a9aa2;
    --line: #38383d;
    --field: #2c2c30;
    --accent: #ff5a4c;
    --accent-text: #1c0c0a;
    --ok: #5cc27d;
    --sim: #a592ff;
    --warn-bg: #3a1d1b;
    --warn: #ff8a80;
  --on-warn: #1c0c0a;
    --pedal: #0e0e10;
    --pedal-edge: #3a3a3c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* over the display rules below */

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1, h2, h3 { margin: 0; font-weight: 650; }
h2 { font-size: 20px; }
h3 { font-size: 15px; margin-bottom: 8px; }

button, select, input {
  font: inherit;
  color: inherit;
}

button {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }

select, input:not([type="checkbox"]) {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  min-height: 30px;
}
input.num { width: 76px; }
input.short { width: 96px; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }

.hint { color: var(--muted); font-size: 12.5px; }
.problem { background: var(--warn-bg); color: var(--warn); padding: 8px 16px; margin: 0; }
.problem.card { border-radius: 9px; padding: 12px 16px; margin: 12px 0; }
.problem.card p { margin: 6px 0 10px; }
.notice { position: relative; background: var(--warn-bg); color: var(--warn); padding: 10px 44px 10px 16px; }
.notice p { margin: 4px 0 0; max-width: 80ch; }
.notice .close { position: absolute; top: 6px; right: 10px; border: 0; background: none; color: inherit; font-size: 20px; min-height: 0; padding: 0 6px; cursor: pointer; }

header.top {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand h1 { font-size: 18px; letter-spacing: .2px; }
.brand .sub { color: var(--muted); }
.file { flex: 1; display: flex; gap: 12px; align-items: baseline; min-width: 0; }
#config-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { padding: 5px 10px; border-radius: 999px; background: var(--field); border: 1px solid var(--line); font-size: 13px; }
.pill.sim { border-color: var(--sim); }
.pill.ok.sim::before, .pill.sim::before { background: var(--sim); }
#connection { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pill.ok::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 7px; }

.toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
}
.toolbar .spacer { flex: 1; }

#busy {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--field);
  border-bottom: 1px solid var(--line);
}
#busy progress { flex: 1; max-width: 360px; }

nav#tabs {
  display: flex;
  gap: 2px;
  padding: 10px 16px 0;
  overflow-x: auto;
}
.tab {
  border: none;
  background: none;
  border-radius: 7px 7px 0 0;
  padding: 8px 14px;
  color: var(--muted);
  white-space: nowrap;
}
.tab.active { background: var(--card); color: var(--text); font-weight: 600; }

main { background: var(--card); margin: 0 16px 16px; border-radius: 0 10px 10px 10px; padding: 16px; min-height: 60vh; }

.card { border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 14px; background: var(--card); }
details.card > summary { cursor: pointer; font-weight: 600; }
details.card[open] > summary { margin-bottom: 10px; }

.welcome { max-width: 640px; margin: 40px auto; text-align: center; }
.welcome h2 { margin-bottom: 10px; }
.buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 18px 0; align-items: center; }
.firmware .buttons { justify-content: flex-start; }

.field { display: inline-flex; align-items: center; gap: 6px; margin: 0 12px 6px 0; }
.field-label { color: var(--muted); font-size: 12.5px; }
.check { display: inline-flex; align-items: center; gap: 6px; margin: 0 12px 6px 0; }
.fields { margin-bottom: 10px; }
.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0 8px; }
.presets .field-label { min-width: 26px; text-align: right; }
.map-part { display: inline-block; min-width: 72px; margin: 0 8px 6px 0; }
.inline { display: inline-flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.scene { display: inline-flex; flex-direction: column; font-size: 12px; color: var(--muted); align-items: center; }

/* Banks */
.banks { display: grid; grid-template-columns: 170px 1fr; gap: 16px; }
.bank-list { display: flex; flex-direction: column; gap: 2px; max-height: 78vh; overflow-y: auto; }
.bank-list button { text-align: left; border: none; background: none; padding: 5px 8px; display: flex; gap: 10px; }
.bank-list button .num { color: var(--muted); width: 20px; text-align: right; }
.bank-list button.active { background: var(--field); font-weight: 600; }
.bank-head { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin-bottom: 12px; }
.song-buttons { display: flex; gap: 8px; margin-left: auto; }

.pedal-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  background: var(--pedal);
  border: 1px solid var(--pedal-edge);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}
.pedal-button {
  background: #2c2c2e;
  color: #f2f2f7;
  border: 2px solid #3a3a3c;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 6px;
  min-height: 78px;
}
.pedal-button .id { font-size: 12px; color: #8e8e93; }
.pedal-button .label { font: 700 20px/1.1 ui-monospace, Menlo, monospace; letter-spacing: 1px; }
.pedal-button .sum { font-size: 11.5px; color: #aeaeb2; text-align: center; }
.pedal-button.active { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }

.subtabs { display: flex; gap: 6px; margin-bottom: 12px; }
.subtabs button.active { background: var(--text); color: var(--card); border-color: var(--text); }

.commands { display: flex; flex-direction: column; gap: 6px; }
.command { display: flex; gap: 8px; align-items: flex-start; padding: 6px; border-radius: 8px; background: var(--field); }
.command.empty { background: none; }
.command .slot { font-weight: 700; width: 18px; padding-top: 6px; color: var(--muted); }
.command select.type { width: 110px; }
.command select.device { width: 92px; }
.command .device-name { color: var(--ok); }
.command .params { display: flex; flex-wrap: wrap; align-items: center; flex: 1; }
.command .params .hint { margin-bottom: 6px; }

/* Global */
.global { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 14px; }
.global .card { margin: 0; }
.setting { display: grid; grid-template-columns: 190px auto; gap: 4px 10px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); }
.setting:first-of-type { border-top: none; }
.setting .hint { grid-column: 1 / -1; }
.setting > select, .setting > input { justify-self: start; }

table.grid { border-collapse: collapse; margin: 10px 0; }
table.grid th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12.5px; padding: 4px 8px; }
table.grid td { padding: 3px 8px; }
table.grid td.key { color: var(--muted); }
table.grid input:not([type="checkbox"]) { width: 100%; min-width: 60px; }
table.grid td:nth-child(2) input { min-width: 300px; }

/* Live pedal */
.live { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.pedal-body {
  background: var(--pedal);
  border: 1px solid var(--pedal-edge);
  border-radius: 16px;
  padding: 22px 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  max-width: 100%;
}
.pedal-body .row { display: flex; gap: 22px; }
.selftest-switches { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.selftest-switches li { border: 1px solid var(--line); border-radius: 6px; padding: 6px; font-size: 13px; text-align: center; }
.selftest-switches li.done { border-color: var(--ok); }
.selftest-switches li.down { background: var(--cap-down); }
.selftest-switches li.bad { border-color: var(--warn); color: var(--warn); }
.selftest-found li { margin: 4px 0; }
.pedal-body .row.bottom { flex-direction: row; }
.sw { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.row.bottom .sw { flex-direction: column-reverse; }
.footswitch {
  width: 68px; height: 68px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #f2f2f7, var(--cap) 60%, #9a9aa0);
  border: 5px solid #3a3a3c;
  color: #1c1c1e; font-weight: 700; font-size: 13px;
  touch-action: none; user-select: none;
}
.footswitch.down { background: var(--cap-down); transform: scale(.96); }
.led { width: 14px; height: 14px; border-radius: 50%; background: #2c2c2e; box-shadow: 0 0 6px rgba(0,0,0,.4) inset; }
/* Expression pedals and the monitor, under the live pedal */
.exp-controls, .monitor-card, .selftest { width: min(640px, 100%); margin: 0; }
.exp-controls h3, .monitor-card h3, .selftest h3 { margin: 0 0 6px; font-size: 15px; }
.exp { display: grid; grid-template-columns: 96px auto 1fr auto auto; align-items: center; gap: 8px; margin: 8px 0 0; }
.exp input[type="range"] { width: 100%; accent-color: var(--accent); }
.monitor-head { display: flex; align-items: center; gap: 12px; }
.monitor-head h3 { margin-right: auto; }
ol.monitor {
  list-style: none; margin: 8px 0 0; padding: 6px 8px; height: 220px; overflow-y: auto;
  background: var(--field); border: 1px solid var(--line); border-radius: 8px;
  font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
ol.monitor .port { display: inline-block; width: 44px; color: var(--muted); }
ol.monitor .port.din { color: var(--accent); }
ol.monitor .port.keys { color: var(--sim); }
canvas.screen { width: 384px; max-width: 100%; image-rendering: pixelated; border: 6px solid #0a0a0c; border-radius: 4px; background: #040506; }

/* Stage: the song large, for a tablet or a laptop on a stand; dark whatever the theme */
.stage-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
.stage {
  background: #000; color: #f4f4f6; border-radius: 12px; padding: clamp(14px, 3vw, 36px);
  display: flex; flex-direction: column; gap: clamp(6px, 1.5vh, 16px); min-height: 70vh;
}
.stage:fullscreen { border-radius: 0; min-height: 100vh; box-sizing: border-box; overflow-y: auto; }
.stage.covering { position: fixed; inset: 0; z-index: 50; border-radius: 0; box-sizing: border-box; overflow-y: auto; }
.stage-close { display: none; }
.stage.covering .stage-top { padding-right: 52px; }
.stage.covering .stage-close { display: block; position: absolute; top: 8px; right: 8px; font-size: 28px; line-height: 1; padding: 4px 12px; background: transparent; color: #a8a8b0; border: 1px solid #44444c; }
.stage.asleep { opacity: .45; }
.stage-top { display: flex; justify-content: space-between; gap: 16px; font-size: clamp(18px, 3vw, 34px); color: #a8a8b0; }
.stage-tempo { font-variant-numeric: tabular-nums; text-align: right; }
.stage-name { font-size: clamp(48px, min(17vw, 22vh), 260px); font-weight: 800; line-height: 1; letter-spacing: .02em; overflow-wrap: anywhere; }
.stage-info { font-size: clamp(24px, min(6vw, 8vh), 80px); font-weight: 600; color: #d8d8de; }
.stage-info:empty, .stage-preview:empty, .stage-note:empty, .stage-next:empty { display: none; }
.stage-preview { font-size: clamp(22px, 4vw, 48px); color: #ffd23f; }
.stage-note { font-size: clamp(20px, min(3.4vw, 4.6vh), 44px); line-height: 1.3; white-space: pre-wrap; border-left: 4px solid #ff5a4c; padding-left: .6em; }
.stage-next { font-size: clamp(18px, 3vw, 36px); color: #a8a8b0; }
.stage-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: clamp(6px, 1.2vw, 14px); margin-top: auto; }
.stage-tiles .tile {
  border: 2px solid #3a3a40; border-radius: 10px; padding: clamp(8px, 1.6vw, 18px);
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.stage-tiles .tile .id { font-size: clamp(12px, 1.6vw, 18px); color: #8a8a92; }
.stage-tiles .tile .label { font-size: clamp(20px, min(4.4vw, 6vh), 56px); font-weight: 700; white-space: nowrap; overflow: hidden; }
.stage-tiles .tile.on { background: #ff5a4c; border-color: #ff5a4c; color: #1c0c0a; }
.stage-tiles .tile.on .id { color: #3a120e; }
.stage-tiles .tile.empty { opacity: .35; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 10; max-width: min(460px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--card); padding: 10px 14px; border-radius: 9px; box-shadow: 0 4px 18px rgba(0,0,0,.25); }
.toast.error { background: var(--warn); color: var(--on-warn); display: flex; gap: 10px; align-items: flex-start; }
.toast.error span { flex: 1; }
.toast .close { background: none; border: none; color: inherit; font-size: 18px; line-height: 1; min-height: 0; padding: 0 2px; cursor: pointer; }

dialog.dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text); max-width: 480px; padding: 20px; }
dialog.dialog::backdrop { background: rgba(0,0,0,.4); }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.share-link { width: 100%; box-sizing: border-box; font: 12px/1.4 ui-monospace, monospace; word-break: break-all; resize: vertical; }
dialog.dialog .community-devices { width: 100%; margin: 4px 0 8px; }
.rig { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.rig-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rig-row select:first-child { flex: 1 1 160px; min-width: 0; }
.rig-row .check { margin: 0; font-size: 13px; }
.rig-head { color: var(--muted); font-size: 12.5px; }
.rig-head span:first-child { flex: 1 1 160px; }
ul.changes { max-height: 40vh; overflow-y: auto; margin: 8px 0; padding-left: 20px; font-size: 13px; }
ul.changes:empty { display: none; }

footer { color: var(--muted); font-size: 12.5px; padding: 0 16px 24px; }
footer a { color: inherit; }

@media (max-width: 760px) {
  .banks { grid-template-columns: 1fr; }
  .bank-list { flex-direction: row; overflow-x: auto; max-height: none; }
  .pedal-grid { grid-template-columns: repeat(2, 1fr); }
  main { margin: 0 8px 8px; padding: 12px; }
  .global { grid-template-columns: 1fr; }
  .setting { grid-template-columns: 1fr; }
  .footswitch { width: 48px; height: 48px; font-size: 10px; padding: 0; line-height: 1.1; }
  .pedal-body .row { gap: 10px; }
  .exp { grid-template-columns: auto 1fr auto; }
  .exp .hint { display: none; }
}
