/* Base reset. The hosted artifact got this from its page wrapper; standalone pages need it here. */
:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); color-scheme: light; }
body { margin: 0; font-size: 14px; }
img { max-width: 100%; }
a { color: var(--accent); }
.alt-link { margin: 6px 0 0; font-size: 13px; }

/* Layout: instrument bench. Test-range viewport on the left, gauge column on the right,
   setup / report / flight log on the bench below, telemetry strip at the foot. */
:root {
  --bg: #E7EBE9; --panel: #F5F7F6; --ink: #18232C; --muted: #59666E; --line: #CBD3D1;
  --accent: #D4470E; --accent-soft: #F6DCCF; --on-accent: #FFFFFF;
  --sky-top: #D2DDE1; --sky-bot: #EBEEEB; --hill: #CBD3D0; --ground: #C9BFAB; --ground-line: #8E8471;
  --steel: #97A3AA; --steel-dark: #5C6870; --car: #D4470E; --glass: #22313C; --tyre: #1C2227; --rim: #BAC4CA;
  --plume: #8E9FA9; --good: #2E7A45; --warn: #A86E12; --bad: #BE3328; --cold: #2B67A8; --force: #2B67A8;
  --font-display: "Big Shoulders Display", "Arial Narrow", "Roboto Condensed", sans-serif;
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Martian Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1519; --panel: #151D22; --ink: #E1E7EA; --muted: #8E9BA3; --line: #27333A;
    --accent: #FF7B3F; --accent-soft: #3A2318; --on-accent: #1A0E08;
    --sky-top: #0A1014; --sky-bot: #162026; --hill: #1B252B; --ground: #2B2A25; --ground-line: #5D5848;
    --steel: #4C5960; --steel-dark: #75828A; --car: #FF7B3F; --glass: #0A0F13; --tyre: #090C0E; --rim: #909BA2;
    --plume: #D3DEE4; --good: #5DC17E; --warn: #E2A84B; --bad: #F2725F; --cold: #82B6F0; --force: #82B6F0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0F1519; --panel: #151D22; --ink: #E1E7EA; --muted: #8E9BA3; --line: #27333A;
  --accent: #FF7B3F; --accent-soft: #3A2318; --on-accent: #1A0E08;
  --sky-top: #0A1014; --sky-bot: #162026; --hill: #1B252B; --ground: #2B2A25; --ground-line: #5D5848;
  --steel: #4C5960; --steel-dark: #75828A; --car: #FF7B3F; --glass: #0A0F13; --tyre: #090C0E; --rim: #909BA2;
  --plume: #D3DEE4; --good: #5DC17E; --warn: #E2A84B; --bad: #F2725F; --cold: #82B6F0; --force: #82B6F0;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 14px; line-height: 1.5; }
.app {
  max-width: 1440px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 20px 40px;
  display: flex; flex-direction: column; gap: 16px;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* header */
.top { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px 24px; }
.brand { min-width: 0; max-width: 70ch; }
.brand h1 {
  font-family: var(--font-display); font-weight: 800; font-size: clamp(30px, 4.4vw, 46px);
  line-height: 0.95; letter-spacing: 0.01em; margin: 0; text-transform: uppercase; text-wrap: balance;
}
.brand h1 span { color: var(--accent); }
.brand p { margin: 8px 0 0; color: var(--muted); max-width: 66ch; }
.tabs { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--panel); flex-wrap: wrap; }
.tabs button {
  border: 0; background: transparent; padding: 9px 16px; font-weight: 600; font-size: 14px;
  border-right: 1px solid var(--line); min-height: 40px;
}
.tabs button:last-child { border-right: 0; }
.tabs button[aria-selected="true"] { background: var(--ink); color: var(--bg); }

/* bench */
.bench { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: stretch; }
/* the gauge column scrolls inside the height of the stage, so the bench below starts right under the view */
.side { position: relative; min-width: 0; }
.side .gauges { position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; padding-right: 2px; }
.stage { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.viewport {
  position: relative; width: 100%; aspect-ratio: 16 / 9.6; border-radius: 6px; overflow: hidden;
  border: 1px solid var(--line); background: var(--sky-bot); touch-action: none;
}
.viewport canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hud-top {
  position: absolute; top: 10px; left: 10px; right: 10px; display: flex; justify-content: space-between;
  align-items: start; gap: 8px; pointer-events: none;
}
.phases { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.phases li {
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 600;
  padding: 3px 8px; border-radius: 3px; background: color-mix(in srgb, var(--panel) 80%, transparent);
  color: var(--muted); border: 1px solid var(--line);
}
.phases li.done { color: var(--ink); }
.phases li.now { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.clock {
  font-family: var(--font-mono); font-size: 12px; padding: 3px 8px; border-radius: 3px;
  background: color-mix(in srgb, var(--panel) 80%, transparent); border: 1px solid var(--line);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.banner {
  position: absolute; left: 50%; top: 22%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--muted);
  border-radius: 4px; padding: 10px 16px; text-align: left; max-width: min(92%, 420px);
}
.banner strong { font-family: var(--font-display); font-size: 26px; text-transform: uppercase; letter-spacing: 0.02em; display: block; line-height: 1; }
.banner span { color: var(--muted); font-size: 13px; }
.banner.good { border-left-color: var(--good); } .banner.good strong { color: var(--good); }
.banner.warn { border-left-color: var(--warn); } .banner.warn strong { color: var(--warn); }
.banner.bad { border-left-color: var(--bad); } .banner.bad strong { color: var(--bad); }
.keys {
  position: absolute; left: 10px; bottom: 10px; font-size: 12px; color: var(--muted);
  background: color-mix(in srgb, var(--panel) 85%, transparent); padding: 4px 8px; border-radius: 3px; border: 1px solid var(--line);
}
.keys kbd { font-family: var(--font-mono); font-size: 11px; border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; background: var(--panel); color: var(--ink); }
.pad { position: absolute; inset: auto 10px 10px 10px; display: flex; justify-content: space-between; gap: 8px; pointer-events: none; }
.pad .grp { display: flex; gap: 6px; pointer-events: auto; }
.pad button {
  width: 52px; height: 52px; border-radius: 8px; border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 88%, transparent); font-weight: 600; font-size: 15px;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.pad button.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 5px; padding: 7px 14px;
  font-weight: 600; min-height: 38px; display: inline-flex; align-items: center; gap: 8px;
}
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); min-width: 104px; justify-content: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; background: var(--panel); }
.seg button { border: 0; background: transparent; padding: 7px 11px; min-height: 36px; font-size: 13px; font-weight: 500; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.toolbar .sep { flex: 1 1 auto; }
.note { color: var(--muted); margin: 0; max-width: 80ch; font-size: 13.5px; }

/* panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px; min-width: 0; }
.panel h2 {
  font-family: var(--font-display); font-weight: 800; font-size: 19px; text-transform: uppercase;
  letter-spacing: 0.04em; margin: 0 0 10px; line-height: 1.1;
}
.panel h2 small { font-family: var(--font-body); font-weight: 500; font-size: 12px; color: var(--muted); text-transform: none; letter-spacing: 0; margin-left: 6px; }
.label { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.gauges { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.tank { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 4px 12px; align-items: center; }
.tank h2 { grid-column: 1 / -1; }
.tank canvas { width: 150px; height: 120px; display: block; }
.tankstats { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.tankstats .v { font-family: var(--font-mono); font-size: 18px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tankstats .v small { font-size: 11px; color: var(--muted); margin-left: 2px; }
.airbar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.airbar i { display: block; height: 100%; background: var(--ink); width: 100%; }
.frost { color: var(--cold); }

.readouts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; }
.readouts h2 { grid-column: 1 / -1; margin-bottom: 0; }
.ro { min-width: 0; }
.ro .v { font-family: var(--font-mono); font-size: 19px; font-variant-numeric: tabular-nums; line-height: 1.25; white-space: nowrap; }
.ro .v small { font-size: 11px; color: var(--muted); margin-left: 3px; }
.ro .v.warn { color: var(--warn); } .ro .v.bad { color: var(--bad); }

.nozzles canvas { width: 100%; height: 96px; display: block; }
.nz-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.nz-list li { display: grid; grid-template-columns: 96px minmax(0, 1fr) 58px; gap: 8px; align-items: center; font-size: 12.5px; }
.nz-list .bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.nz-list .bar i { display: block; height: 100%; width: 0; background: var(--accent); }
.nz-list .kn { font-family: var(--font-mono); font-size: 11.5px; text-align: right; font-variant-numeric: tabular-nums; }
.nz-foot { display: flex; justify-content: space-between; margin-top: 8px; font-size: 12.5px; color: var(--muted); gap: 8px; flex-wrap: wrap; }
.nz-foot b { font-family: var(--font-mono); font-weight: 500; color: var(--ink); }

.lower { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) minmax(0, 0.9fr); gap: 16px; align-items: start; }
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* setup */
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 5px 12px; font-size: 13px; min-height: 32px; }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
#sliders { columns: 2 250px; column-gap: 28px; }
.group { break-inside: avoid; margin: 0 0 14px; }
.group > .label { display: block; margin-bottom: 6px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.slider { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; align-items: baseline; padding: 6px 0; }
.slider label { font-weight: 500; }
.slider output { font-family: var(--font-mono); font-size: 13px; font-variant-numeric: tabular-nums; }
.slider input[type=range] { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); height: 22px; margin: 0; }
.slider .hint { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.slider.changed label::after { content: " •"; color: var(--accent); }
.worldrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 6px 0; }
.setup-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.setup-foot p { margin: 0; color: var(--muted); font-size: 12.5px; }

/* report */
.badge { display: inline-block; font-family: var(--font-display); font-weight: 800; font-size: 24px; text-transform: uppercase; letter-spacing: 0.02em; line-height: 1; }
.badge.good { color: var(--good); } .badge.warn { color: var(--warn); } .badge.bad { color: var(--bad); } .badge.live { color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 14px; margin: 12px 0 0; }
.stats div { min-width: 0; }
.stats dt { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.stats dd { margin: 0; font-family: var(--font-mono); font-size: 15px; font-variant-numeric: tabular-nums; }
.tip { margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13.5px; }

.napkin dl { margin: 0; display: flex; flex-direction: column; gap: 10px; }
.napkin .row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 12px; }
.napkin dt { font-weight: 500; }
.napkin dd { margin: 0; font-family: var(--font-mono); font-size: 14px; text-align: right; font-variant-numeric: tabular-nums; }
.napkin .why { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); }

.log ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 420px; overflow-y: auto; }
.log li { display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 8px; font-size: 13px; line-height: 1.4; }
.log time { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); padding-top: 1px; font-variant-numeric: tabular-nums; }
.log li.warn span { color: var(--warn); } .log li.bad span { color: var(--bad); font-weight: 500; } .log li.good span { color: var(--good); font-weight: 600; }
.log .empty { color: var(--muted); font-size: 13px; }

.telemetry .charts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.chart { min-width: 0; }
.chart .head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chart canvas { width: 100%; height: 120px; display: block; margin-top: 4px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); align-items: center; flex-wrap: wrap; }
.legend i { display: inline-block; width: 18px; height: 0; border-top: 2px solid var(--accent); vertical-align: middle; margin-right: 6px; }
.legend i.prev { border-top: 2px dashed var(--muted); }
.telemetry h2 { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }

footer.fine { color: var(--muted); font-size: 12.5px; max-width: 92ch; }
footer.fine p { margin: 0 0 6px; }

@media (max-width: 1100px) {
  .lower { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .lower .log { grid-column: 1 / -1; }
  .telemetry .charts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
  .bench { grid-template-columns: minmax(0, 1fr); }
  .side .gauges { position: static; overflow: visible; }
  .gauges { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .gauges .nozzles { grid-column: 1 / -1; }
}
@media (max-width: 680px) {
  .viewport { aspect-ratio: 4 / 3.6; }
  .gauges { display: flex; }
  .lower { grid-template-columns: minmax(0, 1fr); }
  .tank { grid-template-columns: 130px minmax(0, 1fr); }
  .tank canvas { width: 130px; height: 104px; }
  .tabs { width: 100%; }
  .tabs button { flex: 1 1 auto; padding: 9px 10px; }
  .toolbar .sep { display: none; }
  .phases li:not(.now) { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
