/* Bench theme for the micro:bit v2.2 emulator.
   Subject: the micro:bit itself — matte black PCB, red power LED,
   screen-printed white legend. The page is the board's bench double:
   near-black silkscreen surfaces, signal-red reserved for live state
   (the matrix, the Run key, fault flags), tabular numerals for the
   readouts. One memorable thing: the DUT slab. Everything else quiet. */

:root {
  --pcb: #101315;            /* matte black soldermask */
  --pcb-2: #171b1e;          /* raised slab face */
  --slab-line: #2b3237;      /* silkscreen hairline */
  --paper: #e8e9e6;          /* bench paper behind the slab */
  --panel: #ffffff;          /* instrument cards */
  --ink: #16191b;            /* near-black text */
  --ink-soft: #565d62;       /* secondary text */
  --legend: #f2f3f1;         /* silkscreen white on pcb */
  --legend-dim: #a7b0b5;     /* dim legend */
  --red: #d42a20;            /* signal red: live state only */
  --red-deep: #a51f16;
  --amber: #b26a00;          /* warnings, pending states */
  --green: #1e7e3a;          /* pass states */
  --trace: #394246;          /* unlit LED wells, console face */
  --focus: #1a73e8;
}

html {
  box-sizing: border-box;
  -webkit-text-size-adjust: 100%;
}

*,
*::before,
*::after {
  box-sizing: inherit;
}

body {
  margin: 0;
  font-family: "Archivo", "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
}

h1,
h2,
h3 {
  line-height: 1.2;
  letter-spacing: -0.015em;
  margin: 0 0 0.5rem;
}

h1 {
  font-size: clamp(1.9rem, 3.4vw, 2.6rem);
  font-weight: 800;
}

h2 {
  font-size: 1.18rem;
  font-weight: 700;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 0.75rem;
}

h3 {
  font-size: 1rem;
  font-weight: 700;
}

p {
  margin: 0 0 0.7rem;
  max-width: 68ch;
}

code,
.mono {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.88em;
}

a {
  color: var(--ink);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--red-deep);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}

.skip {
  position: absolute;
  left: 0.75rem;
  top: -3rem;
  z-index: 20;
  background: var(--panel);
  color: var(--ink);
  padding: 0.5rem 0.9rem;
  border: 2px solid var(--ink);
  border-radius: 6px;
  transition: top 0.15s ease-out;
}

.skip:focus {
  top: 0.75rem;
}

/* Masthead: black instrument strip, red index tab */

.topbar {
  background: var(--pcb);
  color: var(--legend);
  border-bottom: 1px solid #000;
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.8rem 1.4rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-right: auto;
}

.mark {
  display: grid;
  grid-template-columns: repeat(5, 6px);
  gap: 3px;
  padding: 8px;
  background: #000;
  border: 1px solid var(--slab-line);
  border-radius: 4px;
  line-height: 0;
}

.mark i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #3a4146;
}

.mark i.lit {
  background: var(--red);
  box-shadow: 0 0 5px rgba(230, 50, 41, 0.9);
}

.brand-name {
  margin: 0;
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
}

.brand-sub {
  margin: 0;
  font-size: 0.8rem;
  color: var(--legend-dim);
}

.nav {
  display: flex;
  gap: 0.15rem;
}

.nav a {
  color: var(--legend-dim);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
}

.nav a:hover {
  color: var(--legend);
  background: rgba(255, 255, 255, 0.07);
}

.nav a[aria-current="page"] {
  color: var(--legend);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 -2px 0 var(--red);
  border-radius: 6px 6px 0 0;
}

.meters {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  margin-left: auto;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}

.pill {
  font-size: 0.78rem;
  color: var(--legend-dim);
  max-width: 40ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.readout {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--legend);
  font-variant-numeric: tabular-nums;
  min-width: 20ch;
}

/* Page frame: paper, one slab, quiet cards */

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.4rem 1.25rem 3rem;
}

.panel {
  background: var(--panel);
  border: 1px solid #cfd3d1;
  border-radius: 8px;
  padding: 1.05rem 1.15rem 1.2rem;
}

.sub {
  color: var(--ink-soft);
  font-size: 0.9rem;
  margin-top: -0.3rem;
}

/* Bus tag: silkscreen chip label pinned to each section head */

.bustag {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-weight: 400;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
  border: 1px solid #cfd3d1;
  border-radius: 4px;
  padding: 0.1rem 0.45rem;
  vertical-align: 0.12em;
  white-space: nowrap;
  max-width: 100%;
}

/* h2 is flex: the tag is a flex item, so max-width alone cannot shrink
   it past its nowrap content — min-width:0 lets it wrap inside. */
h2 .bustag {
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
}

.board .bustag {
  color: var(--legend-dim);
  border-color: var(--slab-line);
}

/* Loader: fixed three-row grid — transport keys, preset rail, actions.
   Rows align even when the viewport wraps; the rail never jumps around. */

.loader {
  margin-bottom: 1.2rem;
}

.loader-grid {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.load-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  min-height: 2.6rem;
}

/* Staged readout: silkscreen pill, red-edged while staged-but-not-run. */

.staged-line {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.76rem;
  color: var(--ink-soft);
  border: 1px solid #cfd3d1;
  border-radius: 4px;
  padding: 0.12rem 0.5rem;
  white-space: nowrap;
}

.staged-line.hot {
  color: var(--red-deep);
  border-color: var(--red);
}

/* Preset rail: full-row select, never squeezed beside buttons. */

.load-row select#preset {
  flex: 1 1 100%;
  min-width: 0;
  text-overflow: ellipsis;
}

.hint {
  font-size: 0.86rem;
  color: var(--ink-soft);
  margin: 0.7rem 0 0;
  max-width: 78ch;
}

/* Bench grid: slab left, instruments right */

.bench {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 1.2rem;
  align-items: start;
}

.side {
  display: grid;
  gap: 1.2rem;
}

/* DUT slab: the one memorable thing — black PCB face, red glow only */

.board {
  background: var(--pcb-2);
  border: 1px solid #000;
  border-radius: 12px;
  color: var(--legend);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 12px 32px rgba(0, 0, 0, 0.25);
}

.board .sub {
  color: var(--legend-dim);
}

.board-tag {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--legend-dim);
  border-top: 1px solid var(--slab-line);
  border-bottom: 1px solid var(--slab-line);
  padding: 0.45rem 0;
  margin-bottom: 0.9rem;
}

#matrix {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  padding: 14px;
  background: #0a0c0d;
  border: 1px solid var(--slab-line);
  border-radius: 8px;
  margin: 0.4rem 0 1rem;
}

.led {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #2c3439, var(--trace) 72%);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.6);
}

.led.on {
  background: radial-gradient(circle at 40% 35%, #ff6b57, var(--red) 58%, #8e140d);
  box-shadow:
    0 0 14px rgba(230, 50, 41, 0.75),
    0 0 3px rgba(230, 50, 41, 0.9),
    inset 0 -2px 4px rgba(0, 0, 0, 0.35);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
}

.pin-note {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.74rem;
  color: var(--legend-dim);
}

.panel .pin-note {
  color: var(--ink-soft);
}

.board h3 {
  margin-top: 1.15rem;
  color: var(--legend);
}

.tilt {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.tilt label {
  display: grid;
  grid-template-columns: 4.5rem 1fr 4rem;
  align-items: center;
  gap: 0.7rem;
  font-size: 0.9rem;
  color: var(--legend);
}

.tilt output {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.8rem;
  color: var(--legend-dim);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Controls: legend-outline keys on the slab, quiet keys elsewhere */

button,
select {
  font: inherit;
  font-weight: 600;
  font-size: 0.93rem;
}

button {
  cursor: pointer;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid #b9bebb;
  border-radius: 6px;
  padding: 0.48rem 0.95rem;
}

button:hover {
  border-color: var(--ink);
  background: #f4f5f4;
}

button:active {
  transform: translateY(1px);
}

.board button {
  color: var(--legend);
  background: transparent;
  border-color: #4a5358;
}

.board button:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--legend);
}

button.primary {
  background: var(--red);
  border-color: var(--red-deep);
  color: #fff;
}

button.primary:hover {
  background: var(--red-deep);
}

select,
input[type="text"] {
  color: var(--ink);
  background: #fff;
  border: 1px solid #b9bebb;
  border-radius: 6px;
  padding: 0.48rem 0.65rem;
  max-width: 100%;
}

select:focus-visible,
input[type="text"]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

input[type="range"] {
  accent-color: var(--red);
  width: 100%;
}

/* Serial console: black instrument well, red cursor accent */

.console-panel {
  border-top: 3px solid var(--pcb);
}

.console-face {
  background: #0a0c0d;
  border-radius: 6px;
  padding: 0.8rem;
  border: 1px solid var(--pcb);
}

#uart {
  width: 100%;
  height: 190px;
  resize: vertical;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  color: #e8ecec;
  background: transparent;
  border: 0;
  padding: 0;
  caret-color: var(--red);
}

#uart:focus {
  outline: none;
}

.console-face:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.send-row {
  display: flex;
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.send-row input {
  flex: 1;
  min-width: 0;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}

#npminstall {
  width: 100%;
  resize: vertical;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  color: #e8ecec;
  background: transparent;
  border: 0;
  padding: 0;
  caret-color: var(--red);
}

#npminstall:focus {
  outline: none;
}

/* OLED scope */

#oled {
  width: 100%;
  max-width: 512px;
  height: auto;
  aspect-ratio: 2;
  background: #000;
  border: 1px solid var(--pcb);
  border-radius: 6px;
  image-rendering: pixelated;
}

/* BLE stack line: tabular readouts */

.stackline {
  font-variant-numeric: tabular-nums;
}

/* Prose pages */

.prose {
  background: var(--panel);
  border: 1px solid #cfd3d1;
  border-radius: 8px;
  padding: 1.6rem clamp(1.1rem, 3vw, 2.2rem) 2rem;
  max-width: 880px;
}

.prose .lede {
  font-size: 1.1rem;
  color: var(--ink);
  border-left: 4px solid var(--red);
  padding-left: 0.9rem;
  margin: 1rem 0 1.5rem;
  max-width: 62ch;
}

.prose h2 {
  margin-top: 2rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--ink);
}

.prose ul,
.prose ol {
  padding-left: 1.3rem;
  max-width: 68ch;
}

.prose li {
  margin-bottom: 0.4rem;
}

.table-scroll {
  overflow-x: auto;
  margin: 1rem -0.2rem;
  padding: 0 0.2rem 0.4rem;
  max-width: 100%;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 640px;
  font-size: 0.9rem;
  background: #fff;
  border: 1px solid #b9bebb;
}

/* Grid blowout guard: a wide table inside .table-scroll still forces
   the whole .side column wide (grid min-content), so isolate it. */
.side .table-scroll {
  contain: inline-size;
}

caption {
  text-align: left;
  font-weight: 700;
  padding: 0.5rem 0.2rem;
}

th,
td {
  text-align: left;
  vertical-align: top;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid #dfe2df;
}

thead th {
  background: var(--pcb);
  color: var(--legend);
  border-bottom: 2px solid #000;
  font-weight: 700;
}

tbody tr:nth-child(even) {
  background: #f3f4f3;
}

td code {
  white-space: nowrap;
}

.grade {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-weight: 600;
  white-space: nowrap;
}

.steps {
  counter-reset: run;
  list-style: none;
  padding-left: 0;
}

.steps li {
  counter-increment: run;
  position: relative;
  padding-left: 3rem;
  margin-bottom: 0.9rem;
  max-width: 68ch;
}

.steps li::before {
  content: counter(run, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 0.1rem;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--ink);
  border: 1px solid #b9bebb;
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  background: #fff;
}

/* Footer */

.colophon {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 1.25rem 2.5rem;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.colophon nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.2rem;
  margin-bottom: 0.5rem;
}

.colophon p {
  margin: 0.25rem 0;
  max-width: 80ch;
}

@media (max-width: 900px) {
  .bench {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Depth table keeps a 640px min-width for readability: its own
     scroller handles it, never the page. */
  .table-scroll {
    max-width: 100%;
  }

  table {
    min-width: 560px;
  }

  .meters {
    margin-left: 0;
    width: 100%;
  }

  .pill {
    max-width: 100%;
  }

  .tilt label {
    grid-template-columns: 4rem minmax(0, 1fr) 3.5rem;
  }

  .readout {
    min-width: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  .skip {
    transition: none;
  }
}

/* About-page figures: image + caption, same card language as panels. */
.prose figure {
  margin: 1.2rem 0;
  background: var(--panel);
  border: 1px solid #cfd3d1;
  border-radius: 8px;
  padding: 0.8rem;
  max-width: 100%;
}

.prose figure img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 4px;
  border: 1px solid var(--slab-line);
}

.prose figcaption {
  font-size: 0.86rem;
  color: var(--ink-soft);
  padding-top: 0.55rem;
}
