:root {
  color-scheme: dark;
  --bg: #0c1014;
  --panel: #151b21;
  --panel-raised: #1b232b;
  --line: #2b3742;
  --text: #edf4f8;
  --muted: #9badb9;
  --blue: #54a8ff;
  --blue-deep: #183f62;
  --green: #55d6a3;
  --amber: #f4bc5d;
  --red: #ff6b70;
  --red-deep: #401e24;
  --radius: 14px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 0%, rgba(43, 116, 167, 0.22), transparent 34rem),
    var(--bg);
  color: var(--text);
}

button, input, select { font: inherit; }
img, video { max-width: 100%; height: auto; }
code { overflow-wrap: anywhere; }

.masthead, main, footer {
  width: min(1120px, calc(100% - 32px));
  margin-inline: auto;
}

.masthead {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  padding: 52px 0 28px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 12px; font-size: clamp(2rem, 6vw, 4rem); line-height: 0.98; letter-spacing: -0.045em; }
h2 { margin-bottom: 0; font-size: clamp(1.3rem, 3vw, 2rem); letter-spacing: -0.025em; }
h3 { font-size: 1rem; }

.eyebrow, .step-label {
  margin-bottom: 8px;
  color: var(--blue);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.lede { max-width: 720px; margin-bottom: 0; color: var(--muted); font-size: 1.05rem; line-height: 1.55; }
main { display: grid; gap: 20px; }

.panel {
  padding: clamp(20px, 4vw, 34px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(21, 27, 33, 0.94);
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.18);
}

.panel-danger { border-color: #65353a; }
.compact-panel p { max-width: 900px; margin: 16px 0 0; color: var(--muted); line-height: 1.65; }

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.button-row, .connection-footer, .monitor-options {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.button {
  min-height: 42px;
  padding: 9px 16px;
  border: 1px solid #496072;
  border-radius: 9px;
  background: #253340;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
}

.button:hover:not(:disabled) { border-color: var(--blue); background: #2e4050; }
.button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(84, 168, 255, 0.5); outline-offset: 2px; }
.button:disabled { cursor: not-allowed; opacity: 0.43; }
.button-primary { border-color: #3e91d7; background: #1263a5; }
.button-quiet { border-color: var(--line); background: transparent; }
.button-danger { border-color: #e95f68; background: #a82f3a; }
.button-danger:hover:not(:disabled) { border-color: #ff9ca0; background: #c53a46; }
.button-large { width: 100%; min-height: 54px; margin-top: 16px; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-raised);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}
.badge-ok { border-color: #257c60; color: var(--green); }
.badge-warn { border-color: #7a5e2b; color: var(--amber); }
.badge-error { border-color: #84353d; color: var(--red); }

.alert, .danger-copy, .recovery-box {
  margin-bottom: 20px;
  padding: 14px 16px;
  border-radius: 10px;
  line-height: 1.5;
}
.alert-info { border: 1px solid var(--blue-deep); background: #10273a; color: #b9dcfa; }
.alert-error { border-color: #79353d; background: var(--red-deep); color: #ffc4c7; }
.alert-success { border-color: #23624d; background: #12382d; color: #a9efd4; }
.danger-copy { border: 1px solid #73333a; background: var(--red-deep); color: #ffd1d3; }
.release-download { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 20px 0 16px; padding: 16px; border: 1px solid #285f86; border-radius: 10px; background: #10273a; }
.release-download div { display: grid; gap: 5px; }
.release-download span { color: var(--muted); font-size: 0.78rem; overflow-wrap: anywhere; }
.release-download .button { display: inline-flex; align-items: center; flex: 0 0 auto; text-decoration: none; }
.download-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }

.two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
label { display: grid; gap: 8px; color: #d9e5eb; font-size: 0.9rem; font-weight: 700; }
.hint, .muted { color: var(--muted); font-weight: 400; }
select, input[type="text"] {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid #3b4d5b;
  border-radius: 8px;
  background: #0f151a;
  color: var(--text);
}
.connection-footer { margin-top: 14px; }
.port-state { padding-right: 12px; color: var(--muted); font-size: 0.82rem; }
.connection-footer .button { margin-left: auto; }

.monitor-options { justify-content: space-between; margin-bottom: 18px; }
.check { display: flex; grid-template-columns: auto 1fr; align-items: flex-start; gap: 10px; font-weight: 500; line-height: 1.4; }
.check input { width: 17px; height: 17px; margin: 2px 0 0; accent-color: var(--blue); }

.channel-meter { display: grid; grid-template-columns: repeat(16, 1fr); gap: 5px; margin-bottom: 18px; }
.channel-cell {
  position: relative;
  overflow: hidden;
  min-height: 42px;
  padding: 7px 4px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0f151a;
  color: var(--muted);
  text-align: center;
  font-size: 0.68rem;
}
.channel-cell strong { position: relative; display: block; color: var(--text); font-size: 0.85rem; }
.channel-cell::before {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: var(--activity, 0%);
  background: linear-gradient(#227e76, #155047);
  transition: height 180ms ease;
}
.channel-cell.active { border-color: var(--green); }

.table-wrap { overflow: auto; max-height: 420px; border: 1px solid var(--line); border-radius: 9px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; font-size: 0.8rem; }
th { position: sticky; top: 0; z-index: 1; background: #202a33; color: #b9c9d3; text-align: left; }
th, td { padding: 9px 11px; border-bottom: 1px solid #26313a; vertical-align: top; }
td:last-child { color: #8395a2; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.72rem; }
.direction-in { color: var(--green); font-weight: 800; }
.direction-out { color: var(--blue); font-weight: 800; }
/* Cheat-sheet reference tables: fit the phone width, plain text. */
.table-wrap:has(.scale-table) { max-height: none; }
table.scale-table { min-width: 0; font-size: 0.82rem; }
table.scale-table td:last-child { color: inherit; font-family: inherit; font-size: inherit; }
.empty-row td { padding: 30px; color: var(--muted); text-align: center; }

.file-picker {
  margin: 24px 0 16px;
  padding: 20px;
  border: 1px dashed #536a7b;
  border-radius: 10px;
  background: #11181e;
}
.file-picker input { color: var(--muted); }
.firmware-details { min-height: 70px; margin-bottom: 20px; line-height: 1.6; }
.firmware-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.firmware-stat { padding: 10px; border-radius: 8px; background: #10171c; }
.firmware-stat span { display: block; color: var(--muted); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; }
.firmware-stat strong { display: block; overflow-wrap: anywhere; margin-top: 4px; font-size: 0.82rem; }
.hash-row { grid-column: 1 / -1; }

.recovery-box { border: 1px solid #4d4230; background: #282217; }
.recovery-box h3 { margin-bottom: 10px; color: var(--amber); }
.recovery-box ol { margin: 0; padding-left: 22px; color: #e7d8b9; line-height: 1.6; }
fieldset { display: grid; gap: 12px; margin: 0; padding: 18px; border: 1px solid var(--line); border-radius: 10px; }
fieldset:disabled { opacity: 0.48; }
legend { padding: 0 8px; font-weight: 800; }
.confirmation-label { margin-top: 8px; }
.confirmation-label strong { color: var(--amber); }
.hidden { display: none !important; }

.progress-block { margin-top: 22px; }
.progress-label { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 8px; color: var(--muted); font-size: 0.82rem; }
progress { width: 100%; height: 13px; accent-color: var(--blue); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.tools-reference-heading { margin-bottom: 16px; }
.tools-reference-hint { max-width: 280px; margin: 0; text-align: right; }
.tool-workflow {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.tool-workflow span {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #10171c;
  color: var(--muted);
  font-size: 0.76rem;
}
.tool-workflow strong { color: var(--text); }
.tool-note { margin-bottom: 20px; color: var(--muted); line-height: 1.55; }
.tool-cheatsheets { display: grid; gap: 16px; }
.tool-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #10171c;
}
.tool-card-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-end;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.tool-card-heading h3 { margin: 0; font-size: 1.08rem; }
.tool-card-heading > p { margin: 0; color: var(--muted); font-size: 0.76rem; }
.tool-kicker {
  margin: 0 0 3px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.tool-kicker-green { color: var(--green); }
.tool-kicker-magenta { color: #f183ed; }
.tool-kicker-blue { color: #72b7ff; }
.pad-grid-wrap { overflow-x: auto; padding: 14px; }
.pad-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(72px, 1fr));
  gap: 7px;
  min-width: 680px;
}
.pad {
  position: relative;
  display: flex;
  min-height: 62px;
  align-items: center;
  justify-content: center;
  padding: 17px 5px 7px;
  border: 1px solid #3a4853;
  border-radius: 8px;
  background: #182129;
  color: #c9d6dd;
  text-align: center;
}
.pad span {
  position: absolute;
  top: 4px;
  left: 6px;
  color: rgba(255, 255, 255, 0.57);
  font-size: 0.58rem;
  font-weight: 800;
}
.pad strong { font-size: 0.68rem; line-height: 1.12; }
.pad-off { border-color: #252f37; background: #0b1014; color: #56636c; }
.pad-white { border-color: #e6f0f5; background: #9ba8ae; color: #101519; }
.pad-green { border-color: #2f9d78; background: #174c3c; color: #c1ffe8; }
.pad-blue { border-color: #3b8dcc; background: #173f60; color: #d1eaff; }
.pad-cyan { border-color: #2f9da4; background: #174b50; color: #c7fbff; }
.pad-amber { border-color: #b68637; background: #59451f; color: #ffe2aa; }
.pad-yellow { border-color: #c9ac36; background: #5a501e; color: #fff1a8; }
.pad-red { border-color: #b84e55; background: #58252b; color: #ffd0d2; }
.pad-magenta { border-color: #ad51a9; background: #542652; color: #ffd1fc; }
.pad-grey { border-color: #3a444b; background: #1b2227; color: #9aa6ad; }
.pad-violet { border-color: #7a4fd0; background: #33215c; color: #e2d4ff; }
.pad-pink { border-color: #d0566f; background: #5c2331; color: #ffd6df; }
.pad-meter-low { opacity: 0.5; }
.pad-meter-mid { opacity: 0.67; }
.pad-meter-high { opacity: 0.88; }

footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 28px 0 42px;
  color: #71838f;
  font-size: 0.75rem;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto 20px;
}

.site-nav a {
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(21, 27, 33, 0.94);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-decoration: none;
}

.site-nav a:hover { color: var(--text); border-color: var(--blue); }
.site-nav a.active { color: var(--text); border-color: var(--blue); background: rgba(43, 116, 167, 0.18); }

.guide { line-height: 1.6; }
.guide h2 { margin: 34px 0 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.guide h2:first-of-type { margin-top: 8px; }
.guide h3 { margin: 24px 0 8px; color: var(--text); font-size: 1.05rem; }
.guide p, .guide li { color: var(--muted); }
.guide strong { color: var(--text); }
.guide table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.guide th, .guide td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.guide th { color: var(--text); font-size: 0.74rem; letter-spacing: 0.08em; text-transform: uppercase; }
.guide .table-wrap { margin: 10px 0 18px; overflow-x: auto; }
.guide ul, .guide ol { margin: 0 0 16px; padding-left: 22px; }
.guide li { margin-bottom: 6px; }

.guide-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.guide-toc a {
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.78rem;
  text-decoration: none;
}

.guide-toc a:hover { color: var(--text); border-color: var(--blue); }

@media (max-width: 760px) {
  .masthead, .section-heading { align-items: stretch; flex-direction: column; }
  .site-nav a { flex: 1 1 auto; display: flex; min-height: 40px; align-items: center; justify-content: center; text-align: center; }
  .tools-reference-hint { max-width: none; text-align: left; }
  .tool-card-heading { align-items: flex-start; flex-direction: column; gap: 6px; }
  .release-download { align-items: stretch; flex-direction: column; }
  .release-download .button { justify-content: center; }
  .download-actions { display: grid; }
  .masthead { padding-top: 34px; }
  .two-column, .firmware-grid { grid-template-columns: 1fr; }
  .hash-row { grid-column: auto; }
  .channel-meter { grid-template-columns: repeat(8, 1fr); }
  .section-heading .button-row { width: 100%; }
  .button-row .button { flex: 1; }
  footer { flex-direction: column; }
}

@media (max-width: 480px) {
  .masthead { padding: 22px 0 18px; }
  .lede { font-size: 0.98rem; }
  .section-heading { gap: 12px; margin-bottom: 18px; }
  .guide-toc a { padding: 6px 12px; }
  /* Shrink pad cells so more of the 8-wide hardware grid is visible before scrolling,
     while keeping the pad number + label readable. The grid still scrolls inside
     .pad-grid-wrap; the page body never scrolls sideways. */
  .pad-grid-wrap { padding: 10px; }
  .pad-grid { grid-template-columns: repeat(8, minmax(56px, 1fr)); gap: 6px; min-width: 500px; }
  .pad { min-height: 54px; padding: 15px 3px 6px; }
  .pad span { top: 3px; left: 4px; font-size: 0.55rem; }
  .pad strong { font-size: 0.62rem; }
  .channel-cell { font-size: 0.62rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}

/* Hardware checklist dialog */
.checklist-dialog {
  width: min(880px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 24px;
  border: 1px solid #2c3a44;
  border-radius: 14px;
  background: #0f161b;
  color: inherit;
}
.checklist-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.checklist-head { display: flex; gap: 16px; justify-content: space-between; align-items: flex-start; }
.checklist-section { margin-top: 20px; }
.checklist-section h3 { margin: 0 0 8px; }
.checklist-items { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.checklist-item { display: flex; font-weight: 400; font-size: 0.95rem; gap: 12px; align-items: flex-start; padding: 10px 12px; border: 1px solid #22303a; border-radius: 10px; cursor: pointer; line-height: 1.45; }
.checklist-item:has(input:checked) { border-color: #2f9d78; background: #10261f; }
.checklist-item input { margin-top: 4px; width: 18px; height: 18px; flex: none; }
.checklist-item ul { margin: 6px 0 0; padding-left: 18px; }
.checklist-key { color: #7d8c95; font-weight: 600; margin-right: 4px; }
.checklist-after { display: block; margin-top: 6px; }
.checklist-notes { width: 100%; box-sizing: border-box; margin-bottom: 12px; padding: 10px; border-radius: 10px; border: 1px solid #2c3a44; background: #0b1014; color: inherit; font: inherit; }
@media (max-width: 600px) {
  .checklist-dialog { padding: 16px; }
  .checklist-head { flex-direction: column; }
}

/* Phone widths: long MIDI port names must not widen the page. */
.panel, .two-column > *, label { min-width: 0; }
select { max-width: 100%; min-width: 0; }
.file-picker { max-width: 100%; box-sizing: border-box; }
.file-picker input, .file-picker span { max-width: 100%; min-width: 0; box-sizing: border-box; overflow-wrap: anywhere; }

/* record.html: input level meters and clip list */
.rec-meter { display: grid; gap: 0.4rem; margin: 1rem 0 0.5rem; }
.rec-meter-row { display: grid; grid-template-columns: 1.2rem 1fr; align-items: center; gap: 0.5rem; color: var(--muted); font-size: 0.85rem; }
.rec-meter-track { height: 0.7rem; border-radius: 999px; background: var(--panel-raised); border: 1px solid var(--line); overflow: hidden; }
.rec-meter-fill { height: 100%; width: 0; background: var(--green); transition: width 60ms linear; }
.rec-meter-fill.rec-meter-clip { background: var(--red); }
.rec-clips { display: grid; gap: 0.9rem; padding-left: 1.2rem; }
.rec-clips li { display: grid; gap: 0.35rem; }
.rec-clips audio { width: 100%; max-width: 32rem; }
