:root {
  color-scheme: light;
  --paper: #f3f0e8;
  --surface: #fffdf8;
  --ink: #17212b;
  --muted: #65707a;
  --line: #c9c7c0;
  --blue: #0b63e6;
  --blue-dark: #0748a8;
  --green: #087a55;
  --red: #b52b2b;
  --amber: #a15c00;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --display: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, transparent 0 49.9%, rgb(23 33 43 / 0.035) 50%, transparent 50.1%) 0 0 / 2rem 2rem,
    var(--paper);
  font-family: var(--mono);
  line-height: 1.45;
}
button, input { font: inherit; }
button {
  min-height: 2.75rem;
  padding: 0.68rem 1rem;
  border: 1px solid var(--ink);
  border-radius: 0.3rem;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, color 140ms ease;
}
button:hover:not(:disabled) { transform: translateY(-1px); background: #ece9e1; }
button:active:not(:disabled) { transform: translateY(0); }
button:disabled { cursor: not-allowed; opacity: 0.42; }
button.primary { border-color: var(--blue); color: white; background: var(--blue); }
button.primary:hover:not(:disabled) { background: var(--blue-dark); }
button.quiet { border-color: var(--line); }
button.small { min-height: 2rem; padding: 0.35rem 0.65rem; font-size: 0.78rem; }
:where(button, input, [tabindex]):focus-visible { outline: 3px solid #ffb000; outline-offset: 3px; }

.skip-link {
  position: fixed;
  z-index: 20;
  top: 0.75rem;
  left: 0.75rem;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  color: white;
  background: var(--ink);
}
.skip-link:focus-visible {
  width: auto;
  height: auto;
  padding: 0.65rem 0.9rem;
  clip-path: none;
}

.masthead, main, footer { width: min(92rem, calc(100% - 2rem)); margin-inline: auto; }
.masthead {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  padding: 3.5rem 0 2rem;
  border-bottom: 2px solid var(--ink);
  animation: enter 320ms ease both;
}
.eyebrow, .kicker {
  margin: 0 0 0.45rem;
  color: var(--blue);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.13em;
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0.3rem; font: 700 clamp(2.6rem, 7vw, 5.8rem)/0.92 var(--display); letter-spacing: -0.055em; }
h2 { margin-bottom: 0.25rem; font: 700 1.65rem/1 var(--display); }
h3 { margin-bottom: 0.65rem; font-size: 0.85rem; }
.lede { max-width: 64ch; margin-bottom: 0; color: var(--muted); }
.status {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: max-content;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 0.82rem;
}
.status-dot { width: 0.7rem; height: 0.7rem; border-radius: 50%; background: var(--muted); }
.status[data-tone="busy"] .status-dot { background: var(--amber); animation: pulse 1s ease-in-out infinite; }
.status[data-tone="ok"] .status-dot { background: var(--green); box-shadow: 0 0 0 4px rgb(8 122 85 / 0.13); }
.status[data-tone="error"] .status-dot { background: var(--red); }

main { padding-block: 1rem 3rem; }
.connect-strip {
  display: grid;
  grid-template-columns: minmax(14rem, 1fr) auto minmax(18rem, 1fr);
  align-items: center;
  gap: 1.5rem;
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--line);
  animation: enter 360ms 80ms ease both;
}
.connect-strip p { margin-bottom: 0; color: var(--muted); font-size: 0.82rem; }
.button-row { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
.calibration { display: grid; grid-template-columns: 1fr 5.2rem; gap: 0.35rem 0.75rem; align-items: center; }
.calibration label { font-size: 0.78rem; font-weight: 800; }
.calibration input[type="number"] { width: 100%; padding: 0.58rem; border: 1px solid var(--ink); border-radius: 0.25rem; background: var(--surface); }
.calibration span { grid-column: 1 / -1; color: var(--muted); font-size: 0.7rem; }
.calibration .check { grid-column: 1 / -1; display: flex; gap: 0.55rem; align-items: center; font-weight: 500; }
.calibration input[type="checkbox"] { width: 1rem; height: 1rem; accent-color: var(--blue); }

.video-source {
  display: grid;
  grid-template-columns: minmax(17rem, 0.7fr) minmax(18rem, 1.3fr);
  gap: 1.5rem;
  align-items: center;
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--line);
}
.video-copy { display: grid; gap: 0.65rem; align-content: center; }
.video-copy :where(h2, p) { margin-bottom: 0; }
.video-copy p:not(.kicker), .video-copy small { color: var(--muted); font-size: 0.75rem; }
.video-copy input[type="file"] { width: 100%; color: var(--muted); font-size: 0.75rem; }
.video-copy input[type="file"]::file-selector-button {
  margin-right: 0.75rem;
  padding: 0.58rem 0.75rem;
  border: 1px solid var(--ink);
  border-radius: 0.25rem;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
}
.video-copy .check { display: flex; gap: 0.55rem; align-items: center; font-size: 0.75rem; }
.video-copy input[type="checkbox"] { width: 1rem; height: 1rem; accent-color: var(--blue); }
.video-source video { width: 100%; max-height: 18rem; border: 1px solid var(--ink); background: #000; object-fit: contain; }

.metrics { display: grid; grid-template-columns: repeat(5, 1fr); border-bottom: 1px solid var(--line); animation: enter 400ms 120ms ease both; }
.metrics article { min-width: 0; padding: 1.15rem 1rem; border-right: 1px solid var(--line); }
.metrics article:first-child { padding-left: 0; }
.metrics article:last-child { border-right: 0; }
.metrics span, .metrics small { display: block; color: var(--muted); font-size: 0.68rem; }
.metrics strong { display: block; overflow: hidden; margin: 0.3rem 0 0.15rem; font: 700 clamp(1.05rem, 2vw, 1.5rem)/1.1 var(--display); text-overflow: ellipsis; white-space: nowrap; }

.workspace { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(18rem, 0.75fr); min-height: 33rem; border-bottom: 1px solid var(--line); animation: enter 440ms 160ms ease both; }
.log-panel { min-width: 0; padding: 1.5rem 1.5rem 1.5rem 0; border-right: 1px solid var(--line); }
.inspector { min-width: 0; padding: 1.5rem 0 1.5rem 1.5rem; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.section-actions { display: flex; align-items: center; gap: 0.65rem; color: var(--muted); font-size: 0.72rem; }
.log { height: 29rem; overflow: auto; border-top: 2px solid var(--ink); border-bottom: 1px solid var(--line); background: rgb(255 253 248 / 0.55); }
.empty { padding: 1.25rem; color: var(--muted); }
.event {
  display: grid;
  grid-template-columns: 4.7rem 2.4rem minmax(10rem, 1fr) auto;
  gap: 0.75rem;
  align-items: baseline;
  padding: 0.72rem 0.45rem;
  border-bottom: 1px solid var(--line);
  animation: event-in 180ms ease both;
}
.event time, .event .direction, .event .bytes { color: var(--muted); font-size: 0.68rem; }
.event .direction { font-weight: 800; }
.event[data-kind="rx"] .direction { color: var(--green); }
.event[data-kind="tx"] .direction { color: var(--blue); }
.event[data-kind="error"] .direction { color: var(--red); }
.event strong { font-size: 0.78rem; }
.event code { display: block; overflow-wrap: anywhere; color: var(--muted); font-size: 0.68rem; font-weight: 400; }
.event .bytes { white-space: nowrap; }

.facts { margin: 0; border-top: 2px solid var(--ink); }
.facts div { display: grid; grid-template-columns: 7rem minmax(0, 1fr); gap: 0.6rem; padding: 0.55rem 0; border-bottom: 1px solid var(--line); }
.facts dt { color: var(--muted); font-size: 0.7rem; }
.facts dd { overflow-wrap: anywhere; margin: 0; font-size: 0.72rem; text-align: right; }
.subsection { margin-top: 1.35rem; }
.inventory { max-height: 9rem; overflow: auto; margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.inventory li { padding: 0.5rem 0; border-bottom: 1px solid var(--line); font-size: 0.68rem; overflow-wrap: anywhere; }
.stacked-actions { display: grid; gap: 0.5rem; margin-top: 1.35rem; }
.packet-panel { padding: 1.5rem 0; animation: enter 480ms 200ms ease both; }
.packet-panel pre { min-height: 4rem; overflow: auto; margin: 0; padding: 1rem; border: 1px solid var(--line); color: #dbe7f5; background: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
footer { padding: 1rem 0 2rem; border-top: 2px solid var(--ink); color: var(--muted); font-size: 0.72rem; }
footer p { max-width: 80ch; margin-bottom: 0; }
.visually-hidden:where(:not(:focus-within, :active)) { position: absolute !important; clip-path: inset(50%) !important; overflow: hidden !important; width: 1px !important; height: 1px !important; margin: -1px !important; padding: 0 !important; border: 0 !important; white-space: nowrap !important; }

@keyframes enter { from { opacity: 0; transform: translateY(0.6rem); } }
@keyframes event-in { from { opacity: 0; transform: translateX(-0.4rem); } }
@keyframes pulse { 50% { opacity: 0.35; } }

@media (max-width: 64rem) {
  .connect-strip { grid-template-columns: 1fr 1fr; }
  .calibration { grid-column: 1 / -1; }
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .workspace { grid-template-columns: 1fr; }
  .log-panel { padding-right: 0; border-right: 0; }
  .inspector { padding-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 42rem) {
  .masthead { align-items: start; flex-direction: column; padding-top: 2rem; }
  .status { width: 100%; }
  .connect-strip { grid-template-columns: 1fr; }
  .button-row { justify-content: stretch; }
  .button-row button { flex: 1 1 10rem; }
  .calibration { grid-column: auto; }
  .video-source { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metrics article:first-child { padding-left: 1rem; }
  .metrics article:nth-child(2n) { border-right: 0; }
  .metrics article:last-child { grid-column: 1 / -1; border-top: 1px solid var(--line); }
  .event { grid-template-columns: 3.8rem 2rem minmax(0, 1fr); }
  .event .bytes { grid-column: 3; }
  .log { height: 24rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
