:root {
  color-scheme: light;
  --ink: #172d32;
  --muted: #65777b;
  --line: #e1e8e6;
  --paper: #ffffff;
  --canvas: #f4f7f6;
  --teal: #087d73;
  --teal-dark: #103c3b;
  --lime: #c9e779;
  --coral: #bd563d;
  --amber: #a96b12;
  --mono: "IBM Plex Mono", "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  --sans: "Avenir Next", "Segoe UI Variable", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
}

.topbar {
  min-height: 56px;
  padding: 0 clamp(18px, 5vw, 72px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--teal-dark);
  color: #fff;
  border-bottom: 3px solid var(--lime);
  box-shadow: 0 2px 10px #102d2b18;
}

.wordmark { display: flex; gap: 12px; align-items: center; color: inherit; text-decoration: none; }
.wordmark > span:last-child { display: flex; flex-direction: column; gap: 2px; }
.brand-meta { display: flex; align-items: baseline; gap: 0 6px; color: #b6d1ca; font: 10px/1.4 var(--mono); white-space: nowrap; }
.wordmark small { font: inherit; }
.wordmark small::after { content: "\00b7"; margin-left: 6px; }
.wordmark strong { font-size: 18px; font-weight: 650; }
.mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--lime);
  color: var(--teal-dark);
  font: 700 13px var(--mono);
}

.connection { display: flex; align-items: center; flex-wrap: wrap; justify-content: end; gap: 6px 9px; font: 600 12px var(--mono); }
.connection-light, .status-mark { width: 9px; height: 9px; border-radius: 50%; background: #e2b04c; }
.connection[data-state="connected"] .connection-light { background: #b9e86b; box-shadow: 0 0 0 4px #b9e86b24; }
.connection[data-state="disconnected"] .connection-light { background: #ff927b; }

main { max-width: 1480px; margin: 0 auto; padding: 20px clamp(20px, 4vw, 60px) 28px; }
.page-heading, .section-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 28px; line-height: 1.15; font-weight: 680; letter-spacing: -0.035em; }
h2 { margin: 0; font-size: 18px; font-weight: 650; letter-spacing: -0.02em; }
h2 span { margin-left: 9px; color: var(--muted); font: 500 12px var(--mono); }
.sample-time { color: #b6d1ca; font: 12px var(--mono); }
.sample-time::before { content: "\00b7"; margin-right: 9px; }
.sample-time[data-stale="true"] { color: #ffca80; }
.page-heading + section { margin-top: 16px; }
.host-version { overflow-wrap: anywhere; }
.host-version::before { content: "App v"; }

.summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  margin: 8px 0 20px;
  padding: 1px;
  overflow: hidden;
  background: var(--line);
  border: 1px solid var(--line);
  border-top: 3px solid var(--teal);
  border-radius: 10px;
  box-shadow: 0 3px 12px #17332e08;
}
.summary-item { min-height: 72px; padding: 12px 14px; display: grid; align-content: space-between; gap: 6px; background: var(--paper); }
.summary-item span { color: var(--muted); font-size: 12px; }
.summary-item strong { font: 600 16px var(--mono); overflow-wrap: anywhere; min-width: 0; letter-spacing: -0.025em; }
.identity-summary .summary-item { min-height: 62px; padding-block: 10px; }
.identity-summary strong, .runtime-summary strong { font-size: 14px; }

.section-heading { margin-bottom: 8px; align-items: center; }
.actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 7px;
  font: 600 12px var(--sans);
  cursor: pointer;
}
.button:focus-visible { outline: 3px solid var(--lime); outline-offset: 2px; }
.button:disabled { cursor: wait; opacity: 0.55; }
.button-secondary { background: var(--teal); color: #fff; box-shadow: 0 2px 4px #087b7026; }
.button-secondary:hover:not(:disabled) { background: var(--teal-dark); }
.button-led { min-width: 136px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--paper); border-color: #cbd6d3; color: var(--ink); }
.button-led::before { content: ""; width: 7px; height: 7px; flex-shrink: 0; border-radius: 50%; background: #a7b4b0; }
.button-led[data-state="on"]::before { background: var(--teal); }
.button-led[data-state="unknown"]::before { background: transparent; border: 1px solid var(--muted); }
.button-led:hover:not(:disabled) { background: #e8eeeb; }
.button-led[data-state="on"] { border-color: var(--teal); }
.button-led[data-state="unknown"] { color: var(--muted); border-style: dashed; }
.button-danger { background: #fff; border-color: #dbb5aa; color: var(--coral); }
.button-danger:hover:not(:disabled) { background: #fff3ef; }

.table-scroll { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); border-top: 3px solid var(--ink); border-radius: 10px; box-shadow: 0 4px 16px #17332e0a; }
table { width: 100%; min-width: 1040px; border-collapse: collapse; text-align: left; }
th { height: 40px; padding: 0 16px; background: #f0f4f2; color: #53666a; font: 600 11px var(--mono); text-transform: uppercase; letter-spacing: 0.055em; }
td { height: 64px; padding: 10px 16px; border-top: 1px solid var(--line); vertical-align: middle; }
tbody tr { transition: background-color 120ms ease; }
tbody tr:nth-child(even) { background: #fbfcfc; }
tbody tr:hover { background: #f0f7f5; }
.port-name { display: flex; align-items: center; gap: 10px; font: 600 13px var(--mono); }
.port-index { width: 28px; height: 28px; display: grid; place-items: center; background: #e7f2ed; color: var(--teal-dark); border-radius: 7px; }
.state { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 650; text-transform: capitalize; }
.state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #a7b4b0; }
.state-ready::before { background: var(--teal); }
.state-attention { color: var(--coral); }
.state-attention::before { background: var(--coral); }
.state-initializing { color: var(--amber); }
.state-initializing::before { background: var(--amber); }
.cdc-state, .overflow { font: 12px var(--mono); }
.overflow-heading, .overflow { width: 136px; min-width: 136px; padding-inline: 20px; border-left: 1px solid var(--line); text-align: right; white-space: nowrap; }
.cdc-open { color: var(--teal-dark); }
.cdc-closed { color: var(--muted); }
.traffic-metrics { display: grid; grid-template-columns: 7ch minmax(8ch, 1fr) calc(7ch + 16px) minmax(8ch, 1fr); gap: 6px 12px; color: #53666a; font: 12px var(--mono); }
.traffic-metrics > span { display: contents; }
.traffic-metrics > span:nth-child(even) .traffic-label { padding-left: 16px; border-left: 1px solid var(--line); }
.traffic-label { white-space: nowrap; }
.uart-configuration { font: 13px var(--mono); white-space: nowrap; }
.uart-configuration small { display: block; margin-top: 6px; color: var(--muted); font: 12px var(--sans); }
.state-idle { color: var(--muted); }
.traffic b { color: var(--ink); font-weight: 650; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.traffic-note { margin: 12px 2px 0; color: var(--muted); font-size: 11px; }
.traffic-note[data-incomplete="true"] { color: var(--coral); }
.health-flags { display: block; min-width: 170px; max-width: 220px; margin-top: 3px; color: #53666a; font: 12px/1.5 var(--mono); }
.status-line { min-height: 46px; margin-top: 22px; padding: 0 14px; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; background: #eaf0ee; border: 1px solid var(--line); border-radius: 8px; }
.status-mark { width: 7px; height: 7px; background: var(--teal); }
.status-line[data-error="true"] .status-mark { background: var(--coral); }

@media (max-width: 960px) {
  .summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .topbar { padding: 8px 18px; flex-wrap: wrap; gap: 8px 16px; }
  .connection { margin-left: auto; }
  main { padding: 18px 18px 24px; }
  .page-heading { align-items: start; flex-direction: column; gap: 10px; }
  .sample-time { margin-bottom: 0; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 8px 0 18px; }
  .summary-item { min-height: 68px; padding: 10px; }
  .section-heading { align-items: start; flex-direction: column; gap: 8px; }
  .actions { width: 100%; }
  .button { flex: 1; padding-inline: 9px; }
}

@media (prefers-reduced-motion: no-preference) {
  main { animation: arrive 260ms ease-out both; }
  @keyframes arrive { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
}