:root {
  color-scheme: dark;
  --bg: #12181b;
  --panel: #171d1f;
  --panel-2: #20282a;
  --line: #344145;
  --text: #f1f5f3;
  --muted: #9db0ac;
  --accent: #3fd0a0;
  --accent-2: #e2b34f;
  --accent-3: #70a8ff;
  --danger: #ff7d72;
  --edge-rgb: 255, 255, 255;
  --card-fill: rgba(23, 29, 31, .88);
  --control-fill: #141a1b;
  --input-fill: #0f1415;
  --inset-fill: #101719;
  --plot-fill: #0b1011;
  --on-accent: #0a241c;
  --accent-hover: #75e5bf;
  --signal-text-mix: 0%;
  --shadow: 0 18px 50px rgba(0, 0, 0, .32);
}

:root[data-theme="black"] {
  --bg: #09090b;
  --panel: #111114;
  --panel-2: #1c1c21;
  --line: #35353d;
  --text: #f4f4f6;
  --muted: #aaaab4;
  --card-fill: #111114;
  --control-fill: #151519;
  --input-fill: #0d0d10;
  --inset-fill: #0d0d10;
  --plot-fill: #09090b;
}

:root[data-theme="white"] {
  color-scheme: light;
  --bg: #f7f9fa;
  --panel: #fff;
  --panel-2: #ecf1f3;
  --line: #bfcdd1;
  --text: #19272c;
  --muted: #495d65;
  --accent: #0c6c52;
  --accent-2: #805513;
  --accent-3: #275f9b;
  --danger: #a42c29;
  --edge-rgb: 28, 57, 69;
  --card-fill: #fff;
  --control-fill: #f4f7f8;
  --input-fill: #fff;
  --inset-fill: #f2f6f7;
  --plot-fill: #f6f9fa;
  --on-accent: #fff;
  --accent-hover: #095740;
  --signal-text-mix: 56%;
  --shadow: 0 10px 24px rgba(32, 53, 61, .08);
}

/* The wiring and scopes keep their instrument palette so traces and labels stay legible. */
[data-theme="white"] :is(.link-panel, .scope-wrap) {
  --text: #f1f5f3;
  --muted: #9db0ac;
  --accent: #3fd0a0;
  --accent-2: #e2b34f;
  --accent-3: #70a8ff;
  --edge-rgb: 255, 255, 255;
  --plot-fill: #0b1011;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.shell {
  width: min(1420px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.workspace {
  display: grid;
  gap: 18px;
}

.topbar,
.controls,
.protocol-section,
.breakdown-section,
.guide-section,
.signal-section {
  border: 1px solid rgba(var(--edge-rgb), .08);
  background: var(--card-fill);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 22px;
  border-radius: 8px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.55rem, 2.8vw, 2.45rem);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: 1rem;
  letter-spacing: 0;
}

.topbar p,
.section-head span {
  color: var(--muted);
  margin-top: 6px;
}

.status-pill {
  min-width: 190px;
  text-align: center;
  border: 1px solid rgba(63, 208, 160, .45);
  color: var(--accent);
  background: rgba(63, 208, 160, .1);
  border-radius: 999px;
  padding: 9px 12px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}

.status-pill[data-tone="live"] {
  border-color: rgba(226, 179, 79, .5);
  color: var(--accent-2);
  background: rgba(226, 179, 79, .12);
}

.status-pill[data-tone="done"] {
  border-color: rgba(112, 168, 255, .5);
  color: var(--accent-3);
  background: rgba(112, 168, 255, .12);
}

.btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--control-fill);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .1s ease;
}

/* A link wearing the button's clothes, for the navigation between the two
   pages. Buttons are already flex-height by default; an anchor is not. */
a.btn {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.btn:hover {
  border-color: var(--accent);
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  border-color: rgba(63, 208, 160, .55);
  background: rgba(63, 208, 160, .16);
  color: var(--accent);
}

.btn.primary.is-playing {
  border-color: rgba(226, 179, 79, .55);
  background: rgba(226, 179, 79, .16);
  color: var(--accent-2);
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 12px;
  padding: 14px;
  border-radius: 8px;
}

.message-field {
  margin-inline-end: 8px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: .82rem;
  font-weight: 700;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--input-fill);
  color: var(--text);
  padding: 0 12px;
  font: inherit;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(63, 208, 160, .14);
}

select:disabled {
  opacity: .45;
  cursor: not-allowed;
}

/* ---------- connection diagram ---------- */

.signal-section,
.protocol-section,
.breakdown-section,
.guide-section {
  border-radius: 8px;
  overflow: hidden;
}

.link-panel {
  padding: 6px 10px 12px;
  background: radial-gradient(circle at 50% 0%, rgba(63, 208, 160, .06), transparent 60%), #0e1314;
}

#linkSvg {
  display: block;
  width: 100%;
  height: auto;
}

.dev-box {
  fill: rgba(32, 40, 42, .9);
  stroke: rgba(var(--edge-rgb), .12);
}

.dev-chip {
  fill: #151a1b;
  stroke: rgba(var(--edge-rgb), .16);
  stroke-width: 2;
}

.dev-pin {
  stroke: rgba(var(--edge-rgb), .28);
  stroke-width: 2.5;
  stroke-linecap: round;
}

.dev-kicker {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  fill: var(--accent);
}

.dev-name {
  font-size: 20px;
  font-weight: 700;
  fill: var(--text);
}

.dev-role {
  font-size: 16px;
  fill: var(--muted);
}

/* Message buffers inside the device boxes */
.buf-caption {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  fill: var(--muted);
}

.buf-cell rect {
  fill: rgba(var(--edge-rgb), .03);
  stroke: rgba(var(--edge-rgb), .14);
  stroke-width: 1;
  transition: fill .15s ease, stroke .15s ease;
}

.buf-cell text {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 16px;
  font-weight: 700;
  fill: var(--text);
}

.buf-more {
  font-size: 14px;
  font-weight: 700;
  fill: var(--muted);
}

.buf-waiting {
  display: none;
  fill: var(--muted);
  font-size: 14px;
}

.buf-row.is-waiting .buf-cell,
.buf-row.is-waiting .buf-more {
  opacity: 0;
}

.buf-row.is-waiting .buf-waiting {
  display: block;
}

/* Queued to go out: visible from the start, dimming as each one leaves. */
.buf-row[data-kind="out"] .buf-cell.is-active rect {
  fill: rgba(226, 179, 79, .22);
  stroke: var(--accent-2);
}

.buf-row[data-kind="out"] .buf-cell.is-done {
  opacity: .75;
}

/* Arriving: the cell stays empty until the character has fully landed. */
.buf-row[data-kind="in"] .buf-cell text {
  opacity: 0;
  transition: opacity .12s ease;
}

.buf-row[data-kind="in"] .buf-cell.is-active rect {
  fill: rgba(226, 179, 79, .18);
  stroke: var(--accent-2);
}

.buf-row[data-kind="in"] .buf-cell.is-done rect {
  fill: rgba(63, 208, 160, .2);
  stroke: var(--accent);
}

.buf-row[data-kind="in"] .buf-cell.is-done text {
  opacity: 1;
  fill: var(--accent);
}

.wire {
  stroke-width: 3;
  stroke-linecap: round;
  opacity: .68;
}

.wire-row.is-high .pin-name {
  fill: #ffd166;
}

.wire-flow {
  stroke-width: 5;
  stroke-linecap: round;
  opacity: 0;
}

.pin-pad {
  stroke: rgba(0, 0, 0, .5);
  stroke-width: 1;
  transition: fill .07s linear;
}

.pin-name {
  font-size: 17px;
  font-weight: 800;
  fill: var(--text);
}

.wire-label {
  font-size: 20px;
  font-weight: 800;
}

.wire-note-inline {
  font-size: 15px;
  font-weight: 600;
  fill: var(--muted);
}

.wire-row[data-live] .wire {
  opacity: .32;
}

.wire-plot {
  fill: #101c1e;
  stroke: #263a3d;
}

.wire-guide {
  fill: none;
  stroke: #304447;
  stroke-dasharray: 3 5;
}

[data-theme="black"] .link-panel {
  background: #0b0b0e;
}

[data-theme="black"] :is(.dev-box, .dev-chip) {
  fill: var(--panel-2);
}

[data-theme="black"] .wire-plot {
  fill: #111114;
  stroke: var(--line);
}

[data-theme="black"] .wire-guide {
  stroke: var(--line);
}

.wire-signal {
  fill: none;
  stroke-width: 3.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.wire-playhead {
  stroke: #f1f5f3;
  stroke-width: 1.5;
}

.wire-digits text {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 16px;
  font-weight: 700;
  text-anchor: middle;
  opacity: .9;
}

.wire-volt {
  font-size: 15px;
  font-weight: 800;
}

.wire-bit {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 18px;
  font-weight: 800;
}

.wire-count {
  font-size: 15px;
  fill: var(--muted);
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.gnd-mark {
  stroke-width: 2.5;
  stroke-linecap: round;
  fill: none;
}

.flow-dot {
  opacity: 0;
  transition: opacity .2s ease;
  filter: drop-shadow(0 0 5px currentColor);
}

/* ---------- protocol notes ---------- */

.protocol-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: start;
  gap: clamp(16px, 4vw, 48px);
  padding: 20px;
  border-top: 1px solid rgba(var(--edge-rgb), .08);
}

.protocol-card h3 {
  font-size: 1.3rem;
  line-height: 1.25;
}

.protocol-card p {
  max-width: 56ch;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.6;
}

.facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin: 0;
  border: 1px solid rgba(var(--edge-rgb), .12);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(var(--edge-rgb), .12);
}

.facts > div {
  min-width: 0;
  padding: 10px 14px;
  background: var(--inset-fill);
}

.facts dt {
  color: var(--muted);
  font-size: .76rem;
  font-weight: 650;
}

.facts dd {
  margin: 3px 0 0;
  font-size: .9rem;
  font-weight: 650;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.facts .frame-model {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
}

.frame-model dd {
  margin: 0;
}

.frame-model dd::first-letter {
  text-transform: uppercase;
}

/* ---------- scope ---------- */

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(var(--edge-rgb), .08);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 700;
}

.chip {
  width: 14px;
  height: 14px;
  border: 1px solid;
  border-radius: 4px;
}

.scope-panel + .scope-panel {
  border-top: 1px solid rgba(var(--edge-rgb), .08);
}

.scope-panel[hidden] {
  display: none;
}

.panel-title {
  padding: 10px 18px;
  font-size: .95rem;
  color: var(--text);
}

.scope-wrap {
  background: var(--plot-fill);
  overflow-x: auto;
}

.scope-inner {
  position: relative;
  display: inline-block;
  min-width: 100%;
}

.scope-inner canvas {
  display: block;
}

.scope-tooltip {
  position: absolute;
  z-index: 3;
  display: grid;
  gap: 2px;
  max-width: 240px;
  padding: 9px 11px;
  border: 1px solid rgba(var(--edge-rgb), .16);
  border-radius: 7px;
  background: rgba(12, 17, 18, .96);
  box-shadow: var(--shadow);
  pointer-events: none;
  font-size: .78rem;
}

.scope-tooltip[hidden] {
  display: none;
}

.scope-tooltip strong {
  color: var(--accent);
  font-size: .84rem;
}

.scope-tooltip span {
  color: var(--text);
}

.scope-tooltip em {
  color: var(--muted);
  font-style: normal;
  line-height: 1.3;
}

.tip-lane {
  display: flex;
  gap: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .74rem;
}

.tip-lane i {
  flex: 0 0 62px;
  font-style: normal;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Anything the receiver drives is marked so a reply is easy to spot. */
.guide-row.is-reply th,
.tl-block.is-reply {
  background:
    repeating-linear-gradient(135deg, rgba(var(--edge-rgb), .05) 0 6px, transparent 6px 12px),
    var(--inset-fill);
}

.guide-row.is-reply th strong::after,
.tl-block.is-reply header strong::after {
  content: " <-";
  opacity: .6;
}

/* ---------- step mode ---------- */

.btn.step {
  min-width: 44px;
  padding: 0 12px;
}

.step-readout {
  margin: 10px 18px;
  padding: 12px 14px;
  border: 1px solid rgba(var(--edge-rgb), .1);
  border-left: 3px solid var(--field, var(--accent));
  border-radius: 8px;
  background: var(--inset-fill);
}

.step-readout[hidden] {
  display: none;
}

.step-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 12px;
}

.step-head strong {
  color: color-mix(in srgb, var(--field, var(--accent)), var(--text) var(--signal-text-mix));
  font-size: .95rem;
}

.step-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 800;
  font-size: 1rem;
}

.step-group,
.step-time {
  color: var(--muted);
  font-size: .78rem;
}

.step-time {
  color: var(--accent-3);
  font-weight: 700;
}

.step-readout p {
  margin: 8px 0 0;
  color: var(--text);
  font-size: .86rem;
  line-height: 1.5;
}

.step-levels {
  color: var(--muted) !important;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .78rem !important;
}

.scope-hint {
  padding: 10px 18px 14px;
  color: var(--muted);
  font-size: .82rem;
}

@media (hover: none) {
  .scope-hover-hint {
    display: none;
  }
}

/* ---------- per-protocol header fields ---------- */

.options-section {
  border: 1px solid rgba(var(--edge-rgb), .08);
  background: var(--card-fill);
  box-shadow: var(--shadow);
  border-radius: 8px;
  overflow: hidden;
}

.options-section[hidden] {
  display: none;
}

.options-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 14px 18px;
}

.option-field {
  min-width: 170px;
}

.option-field input,
.option-field select {
  min-height: 40px;
}

.option-field input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .04em;
}

.option-button {
  min-height: 40px;
}

/* ---------- encapsulation ---------- */

.layer-section {
  border: 1px solid rgba(var(--edge-rgb), .08);
  background: var(--card-fill);
  box-shadow: var(--shadow);
  border-radius: 8px;
  overflow: hidden;
}

.layer-section[hidden] { display: none; }

.layer-body { padding: 16px 18px; }

.layer-stack {
  display: grid;
  gap: 8px;
}

.layer-row {
  margin-left: calc(var(--depth) * 14px);
  width: var(--width);
  min-width: 190px;
}

.layer-bar {
  display: flex;
  align-items: stretch;
  border: 1px solid rgba(112, 168, 255, .4);
  border-radius: 6px;
  background: rgba(112, 168, 255, .1);
  overflow: hidden;
  font-size: .8rem;
}

.layer-row.is-payload .layer-bar {
  border-color: rgba(63, 208, 160, .55);
  background: rgba(63, 208, 160, .16);
}

.layer-head,
.layer-tail {
  padding: 6px 8px;
  background: rgba(112, 168, 255, .22);
  color: var(--accent-3);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .72rem;
  font-weight: 800;
}

.layer-tail { margin-left: auto; }

.layer-name {
  padding: 6px 10px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.layer-pad {
  padding: 6px 8px;
  margin-left: auto;
  color: var(--accent-2);
  font-size: .72rem;
  font-weight: 700;
}

.layer-detail {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: .76rem;
  line-height: 1.4;
}

.layer-sums {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 26px;
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid rgba(var(--edge-rgb), .08);
}

.layer-sums div { display: grid; gap: 2px; }

.layer-sums dt {
  color: var(--muted);
  font-size: .68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.layer-sums dd {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
  color: var(--text);
}

.layer-sums dd.is-poor { color: var(--accent-2); }

/* ---------- CAN arbitration ---------- */

.arb-section {
  border: 1px solid rgba(var(--edge-rgb), .08);
  background: var(--card-fill);
  box-shadow: var(--shadow);
  border-radius: 8px;
  overflow: hidden;
}

.arb-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin: 0 18px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.arb-tools p {
  max-width: 54ch;
  color: var(--muted);
  line-height: 1.45;
}

.arb-tools .field {
  max-width: 100%;
}

.arb-body {
  padding: 16px 18px;
}

.arb-grid {
  display: grid;
  gap: 4px;
  grid-template-columns: minmax(max-content, 1fr);
  overflow-x: auto;
  padding-bottom: 6px;
}

.arb-row {
  display: grid;
  grid-template-columns: 150px max-content minmax(120px, 1fr);
  gap: 12px;
  align-items: center;
  padding: 4px 8px;
}

.arb-row.is-winner {
  background: rgba(63, 208, 160, .07);
  border-radius: 6px;
}

.arb-row.is-bus {
  border-top: 1px solid rgba(var(--edge-rgb), .12);
  margin-top: 4px;
  padding-top: 8px;
}

.arb-name {
  display: grid;
  line-height: 1.25;
}

.arb-name strong {
  color: color-mix(in srgb, var(--node, var(--text)), var(--text) var(--signal-text-mix));
  font-size: .84rem;
}

.arb-name em {
  color: var(--muted);
  font-style: normal;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .72rem;
}

.arb-bits {
  display: flex;
  gap: 3px;
}

.arb-cell {
  width: 30px;
  min-width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(var(--edge-rgb), .1);
  border-radius: 5px;
  background: rgba(var(--edge-rgb), .03);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .8rem;
  font-weight: 700;
  color: var(--muted);
}

.arb-cell.is-dominant {
  color: var(--text);
  background: rgba(63, 208, 160, .18);
  border-color: rgba(63, 208, 160, .45);
}

.arb-cell.is-lost {
  color: var(--danger);
  background: rgba(255, 125, 114, .18);
  border-color: var(--danger);
}

.arb-cell.is-silent {
  opacity: .25;
  border-style: dashed;
}

.arb-cell.arb-head {
  border: 0;
  background: none;
  font-size: .6rem;
  font-weight: 800;
  letter-spacing: .02em;
  text-transform: uppercase;
}

.arb-verdict {
  color: var(--muted);
  font-size: .76rem;
}

.arb-row.is-winner .arb-verdict {
  color: var(--accent);
  font-weight: 800;
  text-transform: uppercase;
  font-size: .72rem;
  letter-spacing: .04em;
}

.arb-story {
  margin: 16px 0 0;
  padding-left: 20px;
  display: grid;
  gap: 8px;
}

.arb-story li {
  color: var(--muted);
  font-size: .84rem;
  line-height: 1.55;
}

.arb-story li::marker {
  color: var(--accent);
  font-weight: 800;
}

.field.inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field.inline span {
  white-space: nowrap;
}

.field.inline select {
  width: auto;
  min-height: 38px;
}

/* ---------- field guide ---------- */

#guideFilter {
  width: 240px;
  max-width: 100%;
  min-height: 38px;
}

.guide-grid {
  padding: 4px 18px 14px;
}

.guide-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: .9rem;
}

.guide-table thead th {
  position: sticky;
  top: 0;
  text-align: left;
  padding: 10px 12px;
  color: var(--muted);
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  background: var(--control-fill);
  border-bottom: 1px solid rgba(var(--edge-rgb), .12);
  white-space: nowrap;
}

.guide-table thead th:first-child {
  width: 20%;
}

.guide-table thead th:nth-child(2) {
  width: 25%;
}

.guide-row {
  border-bottom: 1px solid rgba(var(--edge-rgb), .06);
  cursor: pointer;
  transition: background .12s ease;
}

.guide-row:hover {
  background: rgba(var(--edge-rgb), .04);
}

.guide-row:focus-within {
  background: rgba(var(--edge-rgb), .04);
}

.guide-table td,
.guide-table tbody th {
  padding: 10px 12px;
  vertical-align: top;
  text-align: left;
}

.guide-table tbody th {
  border-left: 3px solid var(--field, var(--accent));
}

.guide-jump {
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  color: color-mix(in srgb, var(--field, var(--accent)), var(--text) var(--signal-text-mix));
  font: inherit;
  font-weight: 800;
  text-align: left;
  cursor: pointer;
}

.guide-jump:hover {
  text-decoration: underline;
}

.guide-table tbody th em {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-style: normal;
  font-size: .72rem;
  font-weight: 600;
  line-height: 1.3;
}

.bit-count {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: .76rem;
  font-weight: 700;
}

.guide-bits {
  margin-top: 5px;
}

.guide-bits summary {
  width: fit-content;
  color: var(--muted);
  font-size: .8rem;
  cursor: pointer;
}

.guide-wire-bits {
  display: grid;
  gap: 10px;
  max-height: 240px;
  margin-top: 8px;
  overflow-y: auto;
}

.guide-reference {
  margin-top: 8px;
  color: var(--muted);
  font-size: .8rem;
}

.lane-bits {
  display: flex;
  align-items: baseline;
  gap: 8px;
  line-height: 1.5;
}

.lane-bits i {
  color: color-mix(in srgb, var(--lane-color), var(--text) var(--signal-text-mix));
  flex: 0 0 54px;
  font-style: normal;
  font-size: .66rem;
  font-weight: 800;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lane-bits code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .78rem;
  letter-spacing: .06em;
  color: var(--text);
  overflow-wrap: anywhere;
}

.cell-value {
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .86rem;
  font-weight: 600;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.cell-what {
  color: var(--text);
  line-height: 1.5;
}

@media (max-width: 740px) {
  .guide-grid {
    padding-inline: 12px;
  }

  .guide-table,
  .guide-table tbody,
  .guide-table tbody th,
  .guide-table td {
    display: block;
  }

  .guide-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    clip-path: inset(50%);
    overflow: hidden;
  }

  .guide-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
    padding: 11px 12px;
    border-left: 3px solid var(--field, var(--accent));
  }

  .guide-table tbody th,
  .guide-table td {
    padding: 0;
    border-left: 0;
  }
}

.guide-empty,
.guide-foot {
  padding: 0 18px 16px;
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.5;
}

/* ---------- breakdown ---------- */

.timeline {
  display: flex;
  gap: 14px;
  padding: 14px 18px 18px;
  overflow-x: auto;
}

.tl-block {
  flex: 0 0 auto;
  border: 1px solid rgba(var(--edge-rgb), .08);
  border-top: 3px solid var(--field, var(--accent));
  border-radius: 8px;
  background: var(--inset-fill);
  padding: 10px;
}

.tl-block header {
  display: grid;
  gap: 2px;
  margin-bottom: 8px;
}

.tl-block header strong {
  color: color-mix(in srgb, var(--field, var(--accent)), var(--text) var(--signal-text-mix));
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}

.tl-block header span {
  color: var(--muted);
  font-size: .72rem;
  white-space: nowrap;
}

.tl-bits {
  display: flex;
  gap: 6px;
}

.bit-card {
  flex: 0 0 78px;
  min-height: 92px;
  border: 1px solid rgba(var(--edge-rgb), .08);
  border-radius: 7px;
  background: var(--input-fill);
  padding: 8px;
  transition: border-color .12s ease, background .12s ease;
}

.bit-card.is-live {
  border-color: var(--accent);
  background: rgba(63, 208, 160, .12);
}

.bit-card span {
  display: block;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.bit-card strong {
  display: block;
  margin-top: 4px;
  font-size: 1.45rem;
}

.bit-card small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: .68rem;
  line-height: 1.25;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.tl-block.is-more {
  align-self: center;
  border-top-color: var(--muted);
}

/* ---------- ASCII chart: floating, draggable window ---------- */

.ascii-window {
  position: fixed;
  top: 90px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  width: min(760px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 32px));
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(var(--edge-rgb), .14);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.ascii-window[hidden] {
  display: none;
}

.ascii-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(var(--edge-rgb), .08);
  background: var(--panel-2);
}

.ascii-titletext {
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.ascii-titletext.is-dragging {
  cursor: grabbing;
}

.ascii-titletext h2 {
  pointer-events: none;
}

.ascii-titletext span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: .8rem;
  pointer-events: none;
}

.modal-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

#asciiFilter {
  width: 220px;
  min-height: 36px;
}

.ascii-body {
  overflow: auto;
  flex: 1;
}

.ascii-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .84rem;
}

.ascii-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  padding: 8px 12px;
  color: var(--muted);
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  background: var(--control-fill);
  border-bottom: 1px solid rgba(var(--edge-rgb), .12);
  white-space: nowrap;
}

.ascii-row {
  border-bottom: 1px solid rgba(var(--edge-rgb), .06);
  cursor: pointer;
  transition: background .12s ease;
}

.ascii-row:hover {
  background: rgba(var(--edge-rgb), .05);
}

.ascii-row.is-picked {
  background: rgba(63, 208, 160, .16);
}

.ascii-table td {
  padding: 6px 12px;
  vertical-align: middle;
}

.ascii-glyph-cell {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .95rem;
  font-weight: 800;
  color: var(--accent);
  white-space: nowrap;
}

.ascii-name-cell {
  color: var(--muted);
  font-size: .76rem;
  white-space: nowrap;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .78rem;
  color: var(--text);
  white-space: nowrap;
}

.ascii-signal-cell {
  width: 100%;
}

.ascii-wave {
  display: block;
  width: 130px;
  height: 26px;
  overflow: visible;
}

.ascii-wave path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
}

.ascii-foot {
  padding: 10px 16px;
  color: var(--muted);
  font-size: .8rem;
  border-top: 1px solid rgba(var(--edge-rgb), .08);
}

@media (max-width: 900px) {
  .shell {
    padding: 14px;
  }

  .topbar,
  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .legend {
    justify-content: flex-start;
  }

  .controls,
  .protocol-card {
    grid-template-columns: 1fr;
  }

  .status-pill {
    min-width: 0;
  }

  .ascii-window {
    top: 0;
    left: 0;
    transform: none;
    width: 100%;
    max-height: 100%;
    height: 100%;
    border-radius: 0;
  }

  .ascii-titlebar {
    flex-direction: column;
    align-items: stretch;
  }

  #asciiFilter {
    width: 100%;
  }
}

/* Simulator navigation and setup. */
.serial-lab.shell {
  width: min(1220px, 100%);
}

.serial-lab .workspace {
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

.site-credit {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .85rem;
  line-height: 1.6;
  text-align: center;
}

.site-credit a {
  color: var(--accent);
  overflow-wrap: anywhere;
}

.lab-header {
  padding: 15px 4px 8px;
  border: 0;
  background: none;
  box-shadow: none;
}

.lab-header h1 {
  font-size: clamp(1.85rem, 4.5vw, 3rem);
}

.lab-header p {
  line-height: 1.5;
}

.brand-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-heading img {
  flex: none;
}

.theme-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-left: 4px;
  color: var(--muted);
  font-size: .88rem;
  font-weight: 700;
}

.theme-control select {
  width: auto;
}

.send-card {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 12px 18px;
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: 9px;
  background: var(--panel);
}

.lab-group-title {
  font-size: 1.2rem;
}

.send-controls,
.advanced-fields {
  display: grid;
  gap: 12px;
}

.advanced-fields > [hidden] {
  display: none;
}

.send-controls {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr) minmax(0, 1.12fr) minmax(0, .72fr);
  align-items: end;
}

.send-controls > .message-field {
  grid-column: 3;
}

.send-controls > .rate-field {
  grid-column: 4;
}

.arinc-label-field[hidden],
.identifier-entry > [hidden],
.arinc-value-field[hidden],
.message-entry[hidden] {
  display: none;
}

#arincValue[aria-invalid="true"],
#canIdentifier[aria-invalid="true"] {
  border-color: var(--danger);
}

.identifier-entry:has(#canIdentifier:not([hidden])) {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 6px;
}

.facts .frame-model-note {
  flex-basis: 100%;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 400;
}

.frame-model-note a {
  color: var(--accent);
}

.message-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.ascii-trigger {
  padding: 0 10px;
  font-size: .82rem;
  white-space: nowrap;
}

.advanced-fields {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 4px 0 14px;
}

.scope-legend,
.scope-controls,
.playback-controls,
.step-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.scope-legend .status-pill {
  min-width: 0;
  max-width: 100%;
  padding: 4px 9px;
  text-align: left;
  font-size: .8rem;
}

.scope-model-note {
  color: var(--muted);
  font-size: .8rem;
}

.scope-controls .btn {
  min-height: 38px;
  padding-inline: 12px;
  font-size: .85rem;
}

.scope-controls #transmitBtn:not(.is-playing) {
  background: var(--accent);
  color: var(--on-accent);
}

.scope-controls #transmitBtn:not(.is-playing):hover {
  background: var(--accent-hover);
}

.lab-disclosure > summary {
  padding: 14px 18px;
  font-weight: 700;
  cursor: pointer;
}

.lab-disclosure > summary::marker {
  color: var(--accent);
}

.lab-disclosure > summary:hover {
  color: var(--accent);
}

.send-card > .lab-disclosure {
  border-top: 1px solid var(--line);
}

.send-card > .lab-disclosure > summary {
  padding-inline: 0;
  padding-bottom: 0;
}

.send-card > .lab-disclosure[open] > summary {
  padding-bottom: 12px;
}

.send-card .options-section {
  box-shadow: none;
}

.serial-lab .link-panel {
  padding-block: 4px 6px;
  overflow-x: auto;
}

.connection-hint {
  display: none;
}

.serial-lab #linkSvg {
  width: max(780px, 100%);
  margin-inline: auto;
}

.scope-legend {
  justify-content: space-between;
  padding: 6px 18px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.lab-group {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

.frame-summary {
  padding: 6px 18px 0;
  color: var(--muted);
  font-size: .82rem;
}

.lab-group .section-head h3 {
  font-size: 1rem;
}

.lab-group .guide-section:not([open]) {
  border-bottom-color: transparent;
}

@media (min-width: 1010px) {
  .serial-lab.shell {
    padding-top: 14px;
  }

  .lab-header {
    padding-block: 2px;
  }

  .lab-header h1 {
    font-size: 2.35rem;
  }

  .send-card:not(:has(> details[open]:not([hidden]))) {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
  }

  .send-card:not(:has(> details[open]:not([hidden]))) > .lab-disclosure {
    grid-column: 2;
    grid-row: 1;
    border-top: 0;
  }

  .send-card > .lab-disclosure:not([open]) > summary {
    min-height: 44px;
    display: list-item;
    align-content: center;
    padding: 0 8px;
  }

  .signal-section > .section-head {
    padding-block: 8px;
  }
}

@media (min-width: 1010px) and (max-height: 920px) {
  .serial-lab #linkSvg {
    width: max(780px, 89%);
  }
}

@media (min-width: 1010px) and (max-height: 820px) {
  .serial-lab.shell {
    padding-top: 8px;
  }

  .serial-lab .workspace {
    gap: 8px;
  }

  .send-card {
    padding-block: 8px;
  }

  .serial-lab #linkSvg {
    width: max(780px, 85%);
  }

  .scope-legend {
    padding-block: 4px;
  }
}

@media (max-width: 740px) {
  .lab-header {
    padding-top: 12px;
  }

  .brand-heading img {
    width: 44px;
    height: 44px;
  }

  .send-controls,
  .advanced-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .send-controls > :is(.protocol-field, .message-field) {
    grid-column: 1 / -1;
  }

  .send-controls > .message-field {
    margin-inline-end: 0;
  }

  .send-controls:has(> .arinc-label-field:not([hidden]) ~ .message-field > .arinc-value-field:not([hidden])) > .message-field {
    grid-column: 2;
  }

  .send-controls:has(.message-entry:not([hidden])) > .rate-field {
    grid-row: 2;
  }

  .send-controls > .rate-field {
    grid-column: 2;
  }

  .lab-group .field.inline {
    flex-wrap: wrap;
  }

  .lab-group .field.inline select {
    max-width: 100%;
  }
}

@media (max-width: 835px) {
  .connection-hint {
    display: block;
    padding: 8px 18px;
    color: var(--muted);
    font-size: .82rem;
  }
}
