/* S3 Lab — oscilloscope-bench theme.
   One memorable element: the phosphor-green CRT console. Everything else
   stays quiet: graphite panels, amber accents, hairline rails. */

:root {
  --bench: #101216;
  --panel: #171a20;
  --panel-2: #1d2129;
  --rail: #262b35;
  --ink: #d6dbe3;
  --dim: #8b93a1;
  --faint: #5b6370;
  --line: #2b313c;
  --phosphor: #a7e8bd;
  --phosphor-dim: #5f8a6e;
  --crt: #070b08;
  --amber: #e8a33d;
  --amber-wash: rgba(232, 163, 61, 0.14);
  --blue: #6aa8ff;
  --blue-wash: rgba(106, 168, 255, 0.12);
  --red: #c14a4a;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1100px 320px at 70% -80px, rgba(106, 168, 255, 0.07), transparent 60%),
    var(--bench);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Masthead ── */
.mast {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 18, 22, 0.9);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  margin-right: auto;
}
.chip {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: var(--amber);
  stroke-width: 2;
}
.chip .die { fill: var(--amber); stroke: none; opacity: 0.85; }
.chip .pins { stroke-width: 1.6; }
.brand-text { font-size: 20px; font-weight: 650; letter-spacing: 0.01em; }
.brand-text small {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--dim);
  letter-spacing: 0.04em;
}
.mast-nav { display: flex; gap: 4px; flex-shrink: 0; }
@media (max-width: 700px) {
  .mast { flex-wrap: wrap; row-gap: 10px; }
  .brand { margin-right: 0; flex: 1 1 auto; min-width: 0; }
  .battery-pill { margin-left: auto; }
  .mast-nav { order: 3; width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .mast-nav a { white-space: nowrap; }
}
.mast-nav a {
  color: var(--dim);
  text-decoration: none;
  font-size: 13.5px;
  padding: 6px 12px;
  border-radius: 6px;
}
.mast-nav a:hover { color: var(--ink); background: var(--panel-2); }
.mast-nav a.active, .mast-nav a[aria-current="page"] {
  color: var(--amber);
  background: var(--amber-wash);
}
.battery-pill {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--phosphor);
  border: 1px solid var(--phosphor-dim);
  border-radius: 999px;
  padding: 3px 12px;
  white-space: nowrap;
  background: rgba(167, 232, 189, 0.06);
  flex-shrink: 0;
}
.gh-link {
  display: inline-flex;
  align-items: center;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 7px;
  background: var(--panel);
  flex-shrink: 0;
}
.gh-link svg { width: 16px; height: 16px; fill: currentColor; display: block; }
.gh-link:hover { color: var(--amber); border-color: var(--amber); }

/* ── Setup rail: three labelled groups ── */
.setup {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 0;
  margin: 14px 18px 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.setup-group {
  padding: 10px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.setup-group + .setup-group { border-left: 1px solid var(--line); }
.rail-caption {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
}
.load-group { flex-direction: row; align-items: end; gap: 14px; flex-wrap: wrap; }
.load-group .rail-caption { display: none; }
.file input[type="file"], .gallery select { min-width: 0; }
.gallery { min-width: 0; flex: 1 1 auto; }
/* MicroPython REPL preset: URL box + boot button share one label row, so
   the rail stays one line on wide screens and wraps under 700 px. The
   label is a wide block (not squeezed beside Gallery) so the URL box is
   clickable: cramped grid items let neighboring rails overlap it and
   swallow pointer events (proven by Playwright click interception). */
.mp { min-width: 0; flex: 1 1 100%; margin-top: 2px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--dim); }
.mp-caption { font-size: 13px; color: var(--dim); }
.mp-row { display: flex; gap: 6px; align-items: center; }
.mp-url {
  flex: 1 1 auto;
  min-width: 120px;
  font-family: var(--mono);
  font-size: 11.5px;
}
.mp-btn { white-space: nowrap; }
@media (max-width: 700px) {
  .load-group { flex-wrap: wrap; }
  .gallery { flex: 1 1 100%; }
  .mp { flex: 1 1 100%; }
}
.setup label { font-size: 13px; color: var(--dim); display: flex; flex-direction: column; gap: 4px; }
.file input[type="file"], .gallery select, .serial-port select, .mp-url {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  padding: 6px 8px;
  font-size: 12.5px;
  max-width: 100%;
}
.run-row { display: flex; gap: 8px; }
button {
  background: var(--amber);
  color: #161006;
  font-weight: 650;
  border: none;
  border-radius: 6px;
  padding: 7px 16px;
  font-size: 13px;
  cursor: pointer;
}
button:disabled { background: #333945; color: #9aa1ad; cursor: not-allowed; opacity: 0.7; }
button#stop { background: var(--red); color: #fff; }
button#stop:disabled { background: #333945; color: #9aa1ad; }
.steps { display: flex; flex-direction: row !important; align-items: center; gap: 8px; }
.steps input[type="range"] { flex: 1; accent-color: var(--amber); }
.meter-group { justify-content: center; }
.status {
  font-size: 12.5px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mips {
  font-family: var(--mono);
  font-size: 15px;
  color: var(--amber);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ── Bench: scope + sidebar ── */
.bench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 348px;
  gap: 14px;
  padding: 14px 18px 18px;
  flex: 1;
  min-height: 0;
}
@media (max-width: 960px) {
  .setup { grid-template-columns: 1fr; }
  .setup-group + .setup-group { border-left: none; border-top: 1px solid var(--line); }
  .bench { grid-template-columns: 1fr; }
}

/* ── Scope console (the memorable element) ── */
.scope {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.console-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
}
.console-toolbar h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
  white-space: nowrap;
}
.console-actions { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.tb-btn {
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 400;
  cursor: pointer;
}
.tb-btn:hover { border-color: var(--faint); }
.tb-btn.sm { padding: 2px 7px; font-size: 11px; }
.search-input {
  background: var(--crt);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  padding: 4px 9px;
  font-size: 12px;
  width: 130px;
}
.search-input:focus { border-color: var(--phosphor-dim); outline: none; }
.search-status { font-size: 11px; color: var(--dim); min-width: 42px; }
.auto-scroll-toggle {
  font-size: 11.5px;
  color: var(--dim);
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.console {
  background:
    repeating-linear-gradient(0deg, transparent 0 2px, rgba(167, 232, 189, 0.018) 2px 3px),
    var(--crt);
  margin: 0;
  padding: 14px 16px;
  flex: 1;
  min-height: 320px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--phosphor);
  text-shadow: 0 0 9px rgba(167, 232, 189, 0.28);
  white-space: pre-wrap;
  word-break: break-word;
}
.console:empty::after {
  content: "Pick a gallery example or load a merged.bin, then press Run.";
  color: var(--faint);
  text-shadow: none;
}
.console mark { background: #6b5a1e; color: #fff; border-radius: 2px; padding: 0 1px; }
.console mark.current { background: var(--amber); color: #161006; text-shadow: none; }

/* ── Serial input row ── */
.serial-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  align-items: end;
}
.serial-port { font-size: 12px; color: var(--dim); display: flex; flex-direction: column; gap: 4px; }
.serial-input {
  flex: 1;
  background: var(--crt);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  padding: 7px 11px;
  font-size: 12.5px;
  font-family: var(--mono);
}
.serial-input:focus { border-color: var(--amber); outline: none; }
.tb-btn.send { background: var(--amber); color: #161006; border: none; font-weight: 650; }

/* ── Sidebar ── */
.sidebar { display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.gpio-wrap, .vdev-wrap, .net-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.gpio-wrap h2, .vdev-wrap h2, .net-wrap h2 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 0 0 8px;
}
.gpio-wrap h2 small, .gpio-head h2 small, .net-wrap h2 small { letter-spacing: 0; text-transform: none; font-weight: 400; }
.gpio-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.gpio-head h2 { margin: 0; }
.gpio-controls { display: flex; gap: 5px; }
.gpio-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 5px;
  /* A 40-pin header reads as hardware: chunk the grid into banks of 10. */
  row-gap: 9px;
}
.gpio-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  border: 1px solid var(--line);
  padding: 5px 2px;
  font-size: 9px;
  color: var(--dim);
  cursor: default;
  line-height: 1.35;
  position: relative;
}
.gpio-cell .pin-num { font-weight: 600; font-size: 10.5px; }
.gpio-cell .pin-state { font-weight: 700; font-size: 11.5px; font-family: var(--mono); }
.gpio-cell.out-hi {
  background: var(--amber-wash);
  border-color: var(--amber);
  color: var(--amber);
}
.gpio-cell.out-lo { background: #14171d; border-color: var(--line); color: var(--faint); }
.gpio-cell.input {
  background: var(--blue-wash);
  border-color: var(--blue);
  color: var(--blue);
}
.hint { font-size: 11.5px; color: var(--faint); margin: 8px 0 0; }
.vdev-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.vdev {
  background: var(--crt);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
  flex: 1;
  min-height: 64px;
  max-height: 210px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}
.vdev-line, .net-line { line-height: 1.45; }
/* ── Live-IP bridge panel ── */
.net-wrap { display: flex; flex-direction: column; gap: 8px; }
.net-controls { display: flex; gap: 6px; align-items: center; }
.net-url {
  flex: 1 1 auto;
  min-width: 120px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  padding: 6px 8px;
  font-family: var(--mono);
  font-size: 11.5px;
}
.net-url:focus { border-color: var(--amber); outline: none; }
.net-status { font-size: 11.5px; color: var(--dim); }
.netlog {
  background: var(--crt);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
  min-height: 48px;
  max-height: 150px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}
.gpio-cell[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  background: #232833;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 9px;
  font-size: 11px;
  color: var(--ink);
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
  margin-top: 2px;
}

/* ── Footer ── */
.foot {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 22px 18px;
  color: var(--faint);
  font-size: 12.5px;
}
.foot a { color: var(--dim); }
.foot a:hover { color: var(--amber); }

/* ── Prose pages (about / docs / coverage) ── */
.prose {
  max-width: 880px;
  margin: 0 auto;
  padding: 30px 22px 60px;
  width: 100%;
}
.prose h1 { font-size: 30px; margin: 6px 0 4px; letter-spacing: -0.01em; }
.prose .lede { color: var(--dim); font-size: 16px; line-height: 1.55; max-width: 68ch; }
.prose h2 {
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--amber);
  margin: 34px 0 10px;
}
.prose p, .prose li { font-size: 14.5px; line-height: 1.65; color: var(--ink); max-width: 76ch; }
.prose p code, .prose li code, .prose td code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}
.prose pre {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  background: var(--crt);
  color: var(--phosphor);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow: auto;
}
.prose a { color: var(--blue); }

/* Coverage matrix */
.matrix-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table.matrix { border-collapse: collapse; width: 100%; font-size: 13px; min-width: 720px; }
.matrix th, .matrix td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.matrix thead th {
  background: var(--panel-2);
  font-size: 11.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
  white-space: nowrap;
}
.matrix tbody tr:last-child th, .matrix tbody tr:last-child td { border-bottom: none; }
.matrix td:first-child { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 10px;
  white-space: nowrap;
}
.badge.yes { color: var(--phosphor); border: 1px solid var(--phosphor-dim); background: rgba(167, 232, 189, 0.07); }
.badge.no { color: var(--dim); border: 1px solid var(--line); }
.badge.partial { color: var(--amber); border: 1px solid var(--amber); background: var(--amber-wash); }
.matrix td.remark { color: var(--dim); font-size: 12.5px; line-height: 1.5; }

.toc { display: flex; gap: 8px; flex-wrap: wrap; margin: 18px 0 6px; }
.toc a {
  font-size: 13px;
  color: var(--ink);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 13px;
  background: var(--panel);
}
.toc a:hover { border-color: var(--amber); color: var(--amber); }

/* Focus + motion restraint */
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
