:root {
  --paper: #E3E5E0;
  --paper-2: #ECEEE9;
  --ink: #1A1E22;
  --ink-2: #59616A;
  --rule: #C3C8C1;
  --face: #1B2025;
  --face-ink: #E9ECE6;
  --face-dim: #6E777F;
  --needle: #F25C19;
  --amber: #B67C00;
  --teal: #2B7466;
  --red: #C7361F;
  --focus: #1F6FD1;
  --wide: 125%;
  --narrow: 70%;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1D2226; --paper-2: #242A2F; --ink: #E6E9E4; --ink-2: #9BA4AB;
    --rule: #353C42; --face: #111417; --face-ink: #E9ECE6; --face-dim: #5E676F;
    --amber: #E0A73A; --teal: #55A794; --red: #E9593E; --focus: #6AA8F0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #1D2226; --paper-2: #242A2F; --ink: #E6E9E4; --ink-2: #9BA4AB;
  --rule: #353C42; --face: #111417; --face-ink: #E9ECE6; --face-dim: #5E676F;
  --amber: #E0A73A; --teal: #55A794; --red: #E9593E; --focus: #6AA8F0;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Archivo", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Masthead: the car is the headline */
.masthead {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 24px;
  max-width: 1180px; margin: 0 auto; padding: 40px 32px 20px;
}
.car h1 {
  margin: 0;
  font-size: clamp(40px, 7vw, 76px);
  line-height: 0.92;
  font-stretch: var(--wide);
  font-weight: 800;
  letter-spacing: -0.02em;
}
.car p { margin: 8px 0 0; color: var(--ink-2); font-size: 17px; }
.link-state {
  display: flex; align-items: center; gap: 10px;
  font-size: 16px; color: var(--ink-2); text-align: right;
}
.link-state .lamp { width: 10px; height: 10px; border-radius: 50%; background: var(--rule); flex: none; }
.link-state[data-state="ok"] .lamp { background: var(--teal); }
.link-state[data-state="sim"] .lamp { background: var(--amber); }
.link-state[data-state="err"] .lamp { background: var(--red); }
.link-state strong { color: var(--ink); font-weight: 600; }

/* Tabs */
.tabs {
  display: flex; gap: 28px; max-width: 1180px; margin: 0 auto; padding: 0 32px;
  border-bottom: 1px solid var(--rule); overflow-x: auto; scrollbar-width: none;
}
.tabs a {
  padding: 12px 0 11px; color: var(--ink-2); text-decoration: none; white-space: nowrap;
  font-weight: 500; border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--needle); }

main { max-width: 1180px; margin: 0 auto; padding: 32px; }
.view-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; margin-bottom: 24px; }
.view-head h2, .view h2 {
  margin: 0; font-size: 28px; font-stretch: var(--wide); font-weight: 700; letter-spacing: -0.01em;
}
.btn {
  font: inherit; font-weight: 600; font-size: 15px; color: var(--ink);
  background: transparent; border: 1.5px solid var(--ink); border-radius: 999px;
  padding: 8px 18px; cursor: pointer;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn[disabled] { opacity: 0.5; cursor: progress; }

/* Live: the dial is the one bold object */
.live { display: block; }
/* The 996 cluster: five round dials overlapping, the tach in front */
.cluster { display: flex; align-items: center; justify-content: center; margin: 0 auto 36px; max-width: 1180px; }
.dial { margin: 0; aspect-ratio: 1; position: relative; flex: none; }
.dial svg { display: block; width: 100%; height: 100%; }
.dial-md { width: 23.5%; z-index: 2; }
.dial-sm { width: 16.5%; z-index: 1; }
.dial-l1 { margin-right: -2.2%; }
.dial-r1 { margin-left: -2.2%; }
.dial-l2 { margin-right: -1.6%; transform: translateY(6%); }
.dial-r2 { margin-left: -1.6%; transform: translateY(6%); }
.tach-wrap { position: relative; margin: 0; aspect-ratio: 1; width: 38%; flex: none; z-index: 3; }
.d-num { fill: var(--face-ink); font-family: "Archivo", sans-serif; font-stretch: 70%; font-weight: 600; font-size: 22px; }
.d-label { fill: var(--face-dim); font-family: "Archivo", sans-serif; font-size: 17px; }
.d-value { fill: var(--face-ink); font-family: "Archivo", sans-serif; font-stretch: 70%; font-weight: 600; font-size: 40px; }
.d-unit { fill: var(--face-dim); font-family: "Archivo", sans-serif; font-size: 16px; }
.d-needle { stroke-width: 4; }
.lcd { margin-top: 10px; padding: 4px 10px; border-radius: 4px; background: #0B0E10; color: #F2A06B;
  font-size: 15px; font-stretch: 85%; letter-spacing: 0.02em; white-space: nowrap; min-height: 1.4em; }
.lcd:empty { visibility: hidden; }
#tach { width: 100%; height: 100%; display: block; }
.tach-wrap figcaption {
  position: absolute; left: 0; right: 0; bottom: 21%;
  display: flex; flex-direction: column; align-items: center; color: var(--face-ink); pointer-events: none;
}
.rpm { font-size: clamp(34px, 6vw, 54px); font-weight: 600; font-stretch: var(--narrow); line-height: 1; }
.rpm-unit { font-size: 16px; color: var(--face-dim); margin-top: 4px; }

.t-face { fill: var(--face); }
.t-bezel { fill: none; stroke: var(--rule); stroke-width: 2; }
.t-tick { stroke: var(--face-ink); }
.t-num { fill: var(--face-ink); font-family: "Archivo", sans-serif; font-stretch: 70%; font-weight: 600; font-size: 30px; }
.t-x { fill: var(--face-dim); font-family: "Archivo", sans-serif; font-size: 15px; }
.t-red { fill: none; stroke: var(--red); stroke-width: 10; opacity: 0.85; }
.t-red.hot { opacity: 1; stroke: var(--needle); filter: drop-shadow(0 0 6px var(--needle)); }
.t-band { stroke-width: 1.2; }
.t-band[data-sev="none"] { fill: none; stroke: var(--face-dim); }
.t-band[data-sev="ok"] { fill: var(--face-ink); stroke: var(--face-ink); opacity: 0.55; }
.t-band[data-sev="caution"] { fill: var(--amber); stroke: var(--amber); }
.t-band[data-sev="serious"] { fill: var(--red); stroke: var(--red); }
.t-band-num { font-family: "Archivo", sans-serif; font-size: 13px; font-weight: 700; fill: var(--face-ink); }
.t-band-num[data-sev="ok"], .t-band-num[data-sev="caution"] { fill: var(--face); }
.t-needle { stroke: var(--needle); stroke-width: 5; stroke-linecap: round; }
.t-hub { fill: var(--face); stroke: var(--needle); stroke-width: 3; }

.readouts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); column-gap: 32px; }
.ro { padding: 14px 0 12px; border-top: 1px solid var(--rule); min-width: 0; }
.ro-label { font-size: 17px; color: var(--ink-2); }
.ro-value { display: flex; align-items: baseline; gap: 6px; }
.ro-num { font-size: 30px; font-weight: 600; font-stretch: var(--narrow); line-height: 1.1; }
.ro-unit { font-size: 16px; color: var(--ink-2); }
.ro svg { display: block; width: 100%; height: 28px; margin-top: 6px; overflow: visible; }
.ro .spark { fill: none; stroke: var(--ink); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.ro .band { fill: var(--teal); opacity: 0.14; }
.ro.wide { grid-column: 1 / -1; }
.live-note { color: var(--ink-2); font-size: 16px; max-width: 62ch; margin: 32px 0 0; }

/* Everything else the engine computer reports: a quiet two-column list */
.all-readings { margin-top: 40px; }
.all-readings h3 { margin: 0 0 6px; font-size: 16px; font-weight: 600; color: var(--ink-2); }
dl.all {  /* fixed label columns: changing values never move anything */
  display: grid; grid-template-columns: 16em minmax(0, 1fr) 16em minmax(0, 1fr);
  column-gap: 24px; margin: 0;
}
dl.all dt, dl.all dd { margin: 0; padding: 8px 0; border-top: 1px solid var(--rule); font-size: 17px; }
dl.all dt { color: var(--ink-2); }
dl.all dd { font-weight: 500; overflow-wrap: anywhere; }
dl.all.stale dd { opacity: 0.35; }

/* Porsche data: raw DME blocks; bytes that move stand out, static ones recede */
.dme-note { color: var(--ink-2); font-size: 16px; max-width: 64ch; margin: 0 0 20px; }
.lid { display: grid; grid-template-columns: 10rem minmax(0, 1fr); gap: 16px; padding: 12px 0; border-top: 1px solid var(--rule); }
.lid-name { font-weight: 700; font-stretch: var(--wide); }
.lid-name small { display: block; margin-top: 2px; font-size: 14px; font-weight: 400; font-stretch: 100%; color: var(--ink-2); }
.bytes {
  display: grid; grid-template-columns: repeat(16, 2.7ch); row-gap: 3px;
  font-size: 15px; font-stretch: var(--narrow); text-transform: uppercase;
}
.bytes span { color: var(--ink-2); opacity: 0.45; }
.bytes span.moved { color: var(--ink); opacity: 1; font-weight: 600; }
.bytes span.hot { color: var(--amber); opacity: 1; font-weight: 700; }

/* Report */
.verdict { display: grid; grid-template-columns: 14px 1fr; gap: 18px; margin: 0 0 32px; max-width: 70ch; }
.verdict::before { content: ""; border-radius: 7px; background: var(--teal); }
.verdict[data-sev="caution"]::before { background: var(--amber); }
.verdict[data-sev="serious"]::before { background: var(--red); }
.verdict p { margin: 0; }
.verdict .headline { font-size: clamp(22px, 3vw, 30px); line-height: 1.2; font-stretch: 110%; font-weight: 700; }
.verdict .sub { margin-top: 8px; color: var(--ink-2); }

.table-scroll { overflow-x: auto; }
table.ranges { width: 100%; border-collapse: collapse; }
.speed-m { display: none; font-size: 15px; font-weight: 400; font-stretch: 100%; color: var(--ink-2); white-space: nowrap; }
.ranges th { text-align: left; font-weight: 500; font-size: 16px; color: var(--ink-2); padding: 0 16px 10px 0; border-bottom: 1.5px solid var(--ink); }
.ranges td { padding: 14px 16px 14px 0; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.ranges .r { font-size: 22px; font-weight: 700; font-stretch: var(--wide); width: 3.5em; }
.ranges .count { width: 40%; }
.bar { display: flex; align-items: center; gap: 12px; }
.bar i { display: block; height: 10px; border-radius: 5px; background: var(--ink-2); min-width: 2px; }
.bar i[data-sev="caution"] { background: var(--amber); }
.bar i[data-sev="serious"] { background: var(--red); }
.bar b { font-weight: 600; min-width: 4ch; }
.zero { color: var(--ink-2); }
.explain { margin-top: 32px; max-width: 64ch; color: var(--ink-2); font-size: 15px; }
.explain p { margin: 0 0 10px; }
.sim-note {
  margin: 0 0 28px; padding: 12px 16px; border-left: 3px solid var(--amber);
  background: var(--paper-2); font-size: 14px; max-width: 70ch;
}

/* Colophon: quiet, one hairline, the maker's name the only emphasis */
.colophon {
  display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px 24px;
  max-width: 1180px; margin: 24px auto 0; padding: 18px 32px 40px;
  border-top: 1px solid var(--rule); font-size: 13px; color: var(--ink-2);
}
.colophon p { margin: 0; }
.colophon a {
  color: var(--ink); font-weight: 600; font-stretch: var(--wide); letter-spacing: 0.01em;
  text-decoration: none; border-bottom: 1px solid transparent;
}
.colophon a:hover { border-bottom-color: var(--needle); }

/* Codes */
.codes { list-style: none; margin: 0; padding: 0; }
.codes li { display: grid; grid-template-columns: 9rem 1fr; gap: 8px 24px; padding: 18px 0; border-top: 1px solid var(--rule); }
.codes li:last-child { border-bottom: 1px solid var(--rule); }
.code { font-size: 26px; font-weight: 700; font-stretch: var(--wide); line-height: 1.1; }
.code-text { font-size: 17px; }
.code-text.unknown { color: var(--ink-2); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip { font-size: 15px; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--rule); color: var(--ink-2); }
.chip.lamp { border-color: var(--amber); color: var(--ink); }
.chip.now { border-color: var(--red); color: var(--ink); }
.raw { font-size: 14px; color: var(--ink-2); }

/* Info */
dl.info { display: grid; grid-template-columns: max-content 1fr; gap: 0; margin: 0; max-width: 760px; }
.info dt, .info dd { padding: 12px 0; border-top: 1px solid var(--rule); margin: 0; }
.info dt { color: var(--ink-2); padding-right: 32px; }
.info dd { font-weight: 500; overflow-wrap: anywhere; }
.info dd.big { font-size: 22px; font-stretch: var(--wide); font-weight: 700; letter-spacing: 0.02em; }

/* States */
.state { padding: 40px 0; max-width: 60ch; }
.state h3 { margin: 0 0 8px; font-size: 20px; font-stretch: 110%; }
.state p { margin: 0 0 8px; color: var(--ink-2); }
.state details { margin-top: 12px; font-size: 13px; color: var(--ink-2); }
.wait { display: flex; align-items: center; gap: 12px; color: var(--ink-2); padding: 40px 0; }
.wait::before {
  content: ""; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--rule); border-top-color: var(--needle); animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(1turn); } }

@media (max-width: 860px) {
  .cluster { flex-wrap: wrap; row-gap: 12px; }
  .tach-wrap { width: 100%; max-width: 520px; order: 0; }
  .dial-md, .dial-sm { width: 46%; margin: 0 2%; transform: none; order: 1; }
  .readouts { grid-template-columns: 1fr 1fr; }
  .masthead { padding: 28px 16px 16px; flex-direction: column; align-items: flex-start; }
  .link-state { text-align: left; }
  .tabs { padding: 0 16px; gap: 22px; }
  main { padding: 24px 16px; }
  .colophon { padding: 16px 16px 32px; }
  .codes li { grid-template-columns: 1fr; }
  dl.all { grid-template-columns: 14em minmax(0, 1fr); }
  .lid { grid-template-columns: 1fr; gap: 6px; }
  .ranges .count { width: auto; }
  .ranges .when-full { display: none; }
}
@media (max-width: 600px) {
  .ranges .speed { display: none; }
  .speed-m { display: block; }
  .ranges .r { width: auto; }
  .readouts { column-gap: 20px; }
  .bytes { grid-template-columns: repeat(8, 2.7ch); }
}
@media (prefers-reduced-motion: reduce) {
  .wait::before { animation: none; }
}
@media print {
  :root { --paper: #fff; --paper-2: #f3f3f3; --ink: #000; --ink-2: #444; --rule: #bbb; }
  .tabs, .btn, .link-state, .view:not(#view-report) { display: none !important; }
  #view-report { display: block !important; }
  main, .masthead { padding: 0; max-width: none; }
  .masthead { margin-bottom: 24px; }
  .colophon { padding: 12px 0 0; margin-top: 32px; }
}

/* Stream lost: readings are old, not current. */
.live.stale .ro-value, .live.stale .spark, .live.stale figcaption, .live.stale .t-needle { opacity: 0.35; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-danger { color: var(--red); border-color: var(--red); }
#clear-result:not(:empty) { margin-bottom: 20px; }
