/* n-cartpole dashboard — served by the ESP32-S3 (firmware/web/, embedded in the app image).
   The look is the personal site's (tsmorz.github.io, assets/css/main.css): its tokens are copied verbatim
   below, defined three times (bare :root, prefers-color-scheme dark guarded by :root:not([data-theme="light"]),
   and :root[data-theme="dark"]) so the theme toggle works in both directions. No build step.

   ---------------------------------------------------------------
   Tokens
   --------------------------------------------------------------- */
:root {
  color-scheme: light;
  --bg: #f5f5f6;
  --bg-soft: #ebebed;
  --surface: #ffffff;
  --border: #dcdde1;
  --border-strong: #c3c5cc;
  --text: #1d1e23;
  --text-muted: #5a5c67;
  --accent: #6459d3;
  --accent-soft: rgba(100, 89, 211, 0.07);
  --lav: #9b90ee;        /* lavender outlines */
  --lime: #5fae16;       /* outlines, markers */
  --lime-text: #3f7a0a;  /* small text */
  --nn-act-neg: #5fae16;  /* negative activations: lime, with violet for positive */
  --bad: #8a0f0f;  /* errors and failed checks */
  --nn-act-zero: #e6e7ea;
  --nn-act-pos: #5a4fd6;
  /* Data-viz series palette: violet / gold / red / teal. Chosen by search so that every pair stays at least
     CIEDE2000 24 apart under normal vision, deuteranopia, protanopia and tritanopia (Machado 2009 simulation), in
     light and dark, with at least 3:1 contrast against the background, and differs in lightness as well as hue.
     Used by every controls plot. Labels, dashes and marks always accompany the color, so identity is never color-alone. red doubles as the "problem" color. */
  --viz-1: #5a4fd6;  /* violet */
  --viz-2: #a58d12;  /* gold   */
  --viz-3: #8a0f0f;  /* red    */
  --viz-4: #12a599;  /* teal   */
  --viz-7: #556070;  /* slate — the simulated mass; kept off the series colors */
  --viz-total: #556070;  /* neutral gray — aggregate / total lines */
  --marker: rgba(170, 236, 56, .42);       /* hero highlighter ink: translucent, so overlapping passes read darker */
  --mass: #5fae16;       /* the simulated mass on /controls/ (the site's lime) */
  --mass-edge: #3f7a0a;
  --pend-cart: #9aa3af;
  --pend-rod: #556070;
  --pend-1: #8576f0;
  --pend-2: #5fae16;  /* double pendulum: gray cart, violet upper bob, lime lower bob, gray rods */
  --logo-ground: #4b505e;
  --logo-cart: #5d6373;
  --logo-rod: #2f3340;
  --logo-b1: #5a4fd6;
  --logo-b2: #35a02a;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --shadow-lift: 0 2px 4px rgba(16, 24, 40, .06), 0 16px 40px rgba(16, 24, 40, .12);
  --radius: 14px;
  --wrap: 1080px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --serif: "STIX Two Text", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #1b1c1f;
    --bg-soft: #242529;
    --surface: #242529;
    --border: #34363b;
    --border-strong: #4a4c53;
    --text: #ececef;
    --text-muted: #a2a4ad;
    --accent: #c8c0ff;
    --accent-soft: rgba(200, 192, 255, 0.10);
  --lav: #a798ff;
  --lime: #adf45d;
  --lime-text: #adf45d;
    --nn-act-neg: #adf45d;  /* negative activations: lime, with violet for positive */
    --bad: #eb4763;  /* errors and failed checks */
    --nn-act-zero: #2c2d32;
    --nn-act-pos: #c8c0ff;
    --viz-1: #a798ff;
    --viz-2: #fbe160;
    --viz-3: #eb4763;
    --viz-4: #88fce9;
    --viz-7: #9aa7b6;
    --viz-total: #9aa7b6;
    --marker: rgba(173, 244, 93, .20);
    --mass: #adf45d;
    --mass-edge: #7bbf2e;
    --pend-cart: #6b7686;
    --pend-rod: #9aa7b6;
    --pend-1: #a798ff;
    --pend-2: #adf45d;
    --logo-ground: #aab0c0;
    --logo-cart: #c4c9d6;
    --logo-rod: #f1efff;
    --logo-b1: #b3a8ff;
    --logo-b2: #b8ff6a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-lift: 0 2px 4px rgba(0, 0, 0, .45), 0 16px 40px rgba(0, 0, 0, .5);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1b1c1f;
  --bg-soft: #242529;
  --surface: #242529;
  --border: #34363b;
  --border-strong: #4a4c53;
  --text: #ececef;
  --text-muted: #a2a4ad;
  --accent: #c8c0ff;
  --accent-soft: rgba(200, 192, 255, 0.10);
  --lav: #a798ff;
  --lime: #adf45d;
  --lime-text: #adf45d;
  --nn-act-neg: #adf45d;  /* negative activations: lime, with violet for positive */
  --bad: #eb4763;  /* errors and failed checks */
  --nn-act-zero: #2c2d32;
  --nn-act-pos: #c8c0ff;
  --viz-1: #a798ff;
  --viz-2: #fbe160;
  --viz-3: #eb4763;
  --viz-4: #88fce9;
  --viz-7: #9aa7b6;
  --viz-total: #9aa7b6;
  --marker: rgba(173, 244, 93, .20);
  --mass: #adf45d;
  --mass-edge: #7bbf2e;
  --pend-cart: #6b7686;
  --pend-rod: #9aa7b6;
  --pend-1: #a798ff;
  --pend-2: #adf45d;
  --logo-ground: #aab0c0;
  --logo-cart: #c4c9d6;
  --logo-rod: #f1efff;
  --logo-b1: #b3a8ff;
  --logo-b2: #b8ff6a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  --shadow-lift: 0 2px 4px rgba(0, 0, 0, .45), 0 16px 40px rgba(0, 0, 0, .5);
}

/* The site's signature overrides (figure-frame look), plus the dashboard's own few tokens. */
:root { --radius: 3px; --serif: "Fraunces", "STIX Two Text", "Iowan Old Style", Georgia, serif; --grid: rgba(100, 100, 140, .09); --wrap: 1240px; }
:root[data-theme="dark"] { --grid: rgba(199, 192, 255, .09); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --grid: rgba(199, 192, 255, .09); } }

/* ---------------------------------------------------------------
   Base (main.css)
   --------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 16px; line-height: 1.55; -webkit-font-smoothing: antialiased;
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
}
body > main { flex: 1 0 auto; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.2; letter-spacing: -0.01em; margin: 0 0 .5em; }
h1 { font-family: var(--serif); font-optical-sizing: auto; font-weight: 500; font-size: clamp(1.8rem, 4vw, 2.5rem); }
h3 { font-size: 1rem; font-weight: 600; }
code { font-family: var(--mono); font-size: .88em; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 3px; padding: .05em .3em; }
button, input, select, textarea { font-family: var(--mono); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 3px; }
[hidden] { display: none !important; }
.wrap { max-width: var(--wrap); margin-inline: auto; padding-inline: 1.25rem; }
.mono { font-family: var(--mono); }
.muted { color: var(--text-muted); }
.skip-link { position: absolute; left: -9999px; top: 0; z-index: 100; background: var(--accent); color: #fff; padding: .6rem 1rem; }
.skip-link:focus { left: 0; }

/* the site's plot-paper grid, edge to edge behind the page */
main { position: relative; z-index: 0; }
main::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 48px 48px; background-position: center top;
  -webkit-mask-image: radial-gradient(ellipse 75% 85% at 50% 45%, #000 30%, transparent 100%);
  mask-image: radial-gradient(ellipse 75% 85% at 50% 45%, #000 30%, transparent 100%);
}

/* ---------------------------------------------------------------
   Header: sticky, blurred (main.css .site-header / .nav)
   --------------------------------------------------------------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg); background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(12px); backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.nav { max-width: var(--wrap); margin-inline: auto; padding: .7rem 1.25rem; display: flex; align-items: center; gap: .9rem; }
.nav-brand {
  display: flex; align-items: center; gap: .6rem; margin-right: .4rem; min-width: 0;
  color: var(--text); font-family: var(--mono); font-size: .8rem; font-weight: 500; letter-spacing: .02em;
}
.nav-brand:hover { text-decoration: none; color: var(--accent); }
.nav-brand .brand-host { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-brand .brand-sub { color: var(--text-muted); font-weight: 400; }
.nav-brand svg.logo-cartpole { width: 38px; height: 38px; margin: -3px; flex-shrink: 0; display: block; }
.logo-ground { stroke: var(--logo-ground); }
.logo-cart { fill: var(--logo-cart); }
.logo-rod { stroke: var(--logo-rod); }
.logo-b1 { fill: var(--logo-b1); }
.logo-b2 { fill: var(--logo-b2); }

.nav-chips { display: flex; align-items: center; gap: .4rem; min-width: 0; }

/* Section tabs in the header (Live / Health / Record / Settings). */
.tabs { display: flex; gap: .15rem; margin-right: auto; min-width: 0; }
.tab {
  position: relative; font-family: var(--mono); font-size: .78rem; letter-spacing: .02em; line-height: 1;
  padding: .55rem .8rem; border: 0; border-radius: 3px; background: transparent; color: var(--text-muted); cursor: pointer;
}
.tab:hover { color: var(--text); background: var(--bg-soft); }
.tab[aria-selected="true"] { color: var(--text); background: var(--bg-soft); box-shadow: inset 0 -2px 0 var(--lime); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* Something on a hidden tab wants attention (over budget, setup mode). */
.tab[data-alert]::after { content: ""; position: absolute; top: .3rem; right: .25rem; width: 6px; height: 6px; border-radius: 50%; background: var(--viz-2); }
.tab[data-alert="bad"]::after { background: var(--bad); }
.chip {
  display: inline-flex; align-items: center; gap: .4rem; height: 26px; padding: 0 .55rem;
  border: 1px solid var(--lav); border-radius: 3px; white-space: nowrap;
  font-family: var(--mono); font-size: .72rem; letter-spacing: .02em; color: var(--text-muted);
  max-width: 22rem; overflow: hidden; text-overflow: ellipsis;
}
.chip b { font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; }
.chip-conn[data-state="live"] { border-color: var(--lime); color: var(--text); }
.chip-conn[data-state="live"] .dot { background: var(--lime); animation: pulse 2s ease-in-out infinite; }
.chip-conn[data-state="reconnecting"], .chip-conn[data-state="rebooting"] { border-color: var(--viz-2); color: var(--text); }
.chip-conn[data-state="reconnecting"] .dot, .chip-conn[data-state="rebooting"] .dot { background: var(--viz-2); animation: blink 1s steps(2) infinite; }
/* the controller state, on every tab; click to disarm */
.chip-run { background: transparent; cursor: pointer; font-weight: 600; letter-spacing: .08em; }
.chip-run:hover { background: var(--bg-soft); }
.chip-run[data-run="armed"] { border-color: var(--lime); color: var(--text); box-shadow: 0 0 0 1px var(--lime) inset; }
.chip-run[data-run="armed"] .dot { background: var(--lime); animation: pulse 1.2s ease-in-out infinite; }
.chip-run[data-run="fault"] { border-color: var(--bad); color: var(--bad); }
.chip-run[data-run="fault"] .dot { background: var(--bad); animation: blink 1s steps(2) infinite; }
.chip-run[data-run="maint"] { border-color: var(--viz-2); color: var(--text); }
.chip-run[data-run="maint"] .dot { background: var(--viz-2); }
.chip-run:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.chip-model { max-width: 17rem; }
.chip-model:hover { text-decoration: none; border-color: var(--accent); }
.chip-backend { font-weight: 600; letter-spacing: .08em; color: var(--accent); }
.chip-backend[data-backend="rig"] { border-color: var(--lime); color: var(--lime-text); box-shadow: 0 0 0 1px var(--lime) inset; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes blink { 50% { opacity: .2; } }
@media (prefers-reduced-motion: reduce) { .chip .dot, .arm-dot, .run-dot { animation: none !important; } }

/* Theme toggle: the site's two-cell segmented switch, a lime-outlined marker slides to the active theme. */
.theme-toggle {
  position: relative; display: inline-grid; grid-template-columns: 1fr 1fr; align-items: stretch;
  padding: 0; border: 1px solid var(--lav); border-radius: 3px; background: transparent;
  cursor: pointer; flex-shrink: 0; color: var(--text-muted);
}
.theme-toggle::before {
  content: ""; position: absolute; top: -1px; bottom: -1px; left: -1px; width: calc(50% + 1px);
  border: 1.5px solid var(--lime); border-radius: 3px; background: var(--accent-soft);
  transition: transform .22s cubic-bezier(.3, .7, .2, 1); pointer-events: none;
}
.tt-opt { position: relative; z-index: 1; display: grid; place-items: center; width: 24px; height: 24px; transition: color .2s; }
.tt-opt svg { display: block; }
.tt-light { color: var(--text); }
:root[data-theme="dark"] .theme-toggle::before { transform: translateX(100%); }
:root[data-theme="dark"] .tt-light { color: var(--text-muted); }
:root[data-theme="dark"] .tt-dark { color: var(--text); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle::before { transform: translateX(100%); }
  :root:not([data-theme="light"]) .tt-light { color: var(--text-muted); }
  :root:not([data-theme="light"]) .tt-dark { color: var(--text); }
}
.theme-toggle:hover .tt-opt { color: var(--text); }
.theme-toggle:focus-visible { outline: 2px solid var(--lime); outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) { .theme-toggle::before { transition: none; } }

/* ---------------------------------------------------------------
   Page head
   --------------------------------------------------------------- */
.page-head { padding: clamp(.9rem, 2vw, 1.3rem) 1.25rem .8rem; display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem 2rem; flex-wrap: wrap; }
.eyebrow { display: block; font-family: var(--mono); font-size: .76rem; letter-spacing: .03em; color: var(--lime-text); margin: 0 0 .3rem; }
.eyebrow::before { content: "// "; opacity: .6; }
.page-title { margin: 0 0 .15rem; font-size: clamp(1.5rem, 2.4vw, 1.95rem); }
.page-sub { color: var(--text-muted); font-size: .92rem; margin: 0; max-width: 62ch; text-wrap: pretty; }
.tab-head { padding: clamp(.9rem, 2vw, 1.3rem) 0 .2rem; }
.tab-title { margin: 0 0 .15rem; font-size: clamp(1.5rem, 2.4vw, 1.95rem); }
.tab-sub { color: var(--text-muted); font-size: .92rem; margin: 0; }
.head-facts { display: flex; gap: 1.5rem; margin: 0; padding: 0; list-style: none; font-family: var(--mono); font-size: .74rem; color: var(--text-muted); }
.head-facts li { display: flex; flex-direction: column; gap: .1rem; }
.head-facts b { font-weight: 500; font-size: 1.05rem; color: var(--text); letter-spacing: -.01em; }
.head-facts b.bad { color: var(--bad); }

/* ---------------------------------------------------------------
   Live sim: canvas stack + controller panel (main.css .sim-layout / .su-layout)
   --------------------------------------------------------------- */
.sim-layout { display: flex; gap: 1.25rem; align-items: stretch; flex-wrap: wrap; }
.sim-canvas-wrap { flex: 1 1 480px; min-width: 0; }
.sim-stack { display: grid; grid-template-rows: minmax(0, 1.45fr) minmax(0, 1fr); gap: .6rem; min-height: clamp(480px, calc(100vh - 235px), 700px); min-height: clamp(480px, calc(100dvh - 235px), 700px); }
.sim-cell { position: relative; min-height: 0; }
.sim-cell > canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.sim-canvas { border-radius: 3px; border: 1px solid var(--border); background: var(--bg-soft); }
.sim-states { border-radius: 3px; border: 1px solid var(--border); background: var(--bg); cursor: crosshair; }

/* run state over the scene, top-left; time to target, top-right */
.scene-overlay { position: absolute; top: 12px; left: 14px; right: 14px; display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; pointer-events: none; }
.run-block { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.run-badge {
  display: inline-flex; align-items: center; gap: .5rem; align-self: flex-start;
  padding: .28rem .6rem; border: 1px solid var(--lav); border-radius: 3px; background: color-mix(in srgb, var(--bg-soft) 80%, transparent);
  font-family: var(--mono); font-size: .8rem; font-weight: 600; letter-spacing: .12em; color: var(--text-muted);
}
.run-dot { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid currentColor; }
.run-badge[data-run="armed"] { border-color: var(--lime); box-shadow: 0 0 0 1px var(--lime); color: var(--text); }
.run-badge[data-run="armed"] .run-dot { background: var(--lime); border-color: var(--lime); animation: pulse 1.2s ease-in-out infinite; }
.run-badge[data-run="fault"] { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad); color: var(--bad); }
.run-badge[data-run="fault"] .run-dot { background: var(--bad); border-color: var(--bad); animation: blink 1s steps(2) infinite; }
.run-badge[data-run="maint"] { border-color: var(--viz-2); color: var(--text); }
.run-badge[data-run="maint"] .run-dot { background: var(--viz-2); border-color: var(--viz-2); }
.run-badge .run-reason { font-weight: 400; letter-spacing: .02em; text-transform: none; }
.run-sub { font-size: .8rem; font-weight: 600; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.run-sub .muted { font-weight: 400; font-family: var(--mono); font-size: .72rem; }
.reach { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: .15rem; }
.reach-val { font-family: var(--mono); font-weight: 700; font-size: 1.7rem; line-height: 1; color: var(--accent); }
.reach-lbl { font-size: .68rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
.reach-state { font-family: var(--mono); font-size: .7rem; color: var(--lime-text); min-height: 1em; }
.reach[hidden] { display: none; }
.reach-val.running { color: var(--text-muted); font-weight: 500; }
.run-last { font-family: var(--mono); font-size: .68rem; color: var(--bad); opacity: .8; min-height: 0; }
.run-last:empty { display: none; }

/* Remote device: the bar on a copy of the page served from somewhere other than the device. */
.device-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .4rem 1rem;
  font-family: var(--mono); font-size: .74rem; color: var(--text-muted); border-bottom: 1px solid var(--border);
}
.device-bar[hidden] { display: none; }
.device-bar input {
  flex: 0 1 16rem; min-width: 8rem; padding: .15rem .45rem; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: 3px;
}
.device-bar .banner-btn { margin-left: 0; border-color: var(--border-strong); }
.device-bar .device-note { flex: 1 1 18rem; }

/* Stale: the connection dropped or the device went quiet. Live values fade; a banner says since when. */
.stale-banner {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .4rem 1rem; font-family: var(--mono); font-size: .74rem; color: var(--text);
  background: color-mix(in srgb, var(--viz-2) 22%, var(--bg)); border-bottom: 1px solid var(--viz-2);
}
.stale-banner[hidden] { display: none; }
.stale-banner .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--viz-2); animation: blink 1s steps(2) infinite; }
body.stale .head-facts, body.stale .readout, body.stale #ro-kv, body.stale #tab-health .card,
body.stale #rec-kv, body.stale .sim-states, body.stale #run-chip, body.stale .nn-meta { opacity: .45; transition: opacity .3s; }

/* the controller panel (.sim-panel) */
.sim-panel {
  flex: 0 0 272px; display: flex; flex-direction: column; gap: .55rem; min-width: 0;
  padding: .9rem 1rem 1rem; border: 1px solid var(--border); border-radius: 3px; background: var(--surface);
}
.sim-panel h3 { margin: .35rem 0 0; font-size: .92rem; }
.sim-panel h3:first-child { margin-top: 0; }
.h3-tag { font-family: var(--mono); font-weight: 400; font-size: .68rem; color: var(--text-muted); }
.sim-panel .panel-push { margin-top: auto; padding-top: .35rem; display: flex; align-items: baseline; justify-content: space-between; }

/* the state readout: estimate / encoders / true, decimal points aligned */
.readout { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: .72rem; font-variant-numeric: tabular-nums; }
.readout th, .readout td { padding: .12rem .3rem; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
.readout thead th { font-weight: 500; font-size: .64rem; letter-spacing: .04em; color: var(--text-muted); }
.readout tbody th { text-align: left; font-weight: 500; color: var(--text); }
.readout tbody th span { font-weight: 400; font-size: .6rem; color: var(--text-muted); }
.readout td { color: var(--text); }
.readout td:nth-of-type(2) { color: var(--text-muted); }
.readout tr:last-child th, .readout tr:last-child td { border-bottom: 0; }
.kv.kv-tight { font-size: .7rem; padding: .4rem .55rem; gap: .1rem .6rem; }
.panel-hint { font-size: .72rem; line-height: 1.4; color: var(--text-muted); margin: 0; }
.panel-hint strong { color: var(--text); font-weight: 600; }
.panel-msg { font-family: var(--mono); font-size: .72rem; line-height: 1.4; margin: 0; min-height: 1.4em; color: var(--text-muted); }
.panel-msg.bad { color: var(--bad); }
.panel-msg.good { color: var(--lime-text); }
.panel-hint.bad { color: var(--bad); }

/* Arm / Disarm: the one prominent control */
.arm-btn {
  position: relative; display: flex; align-items: center; gap: .6rem; width: 100%; min-height: 50px; padding: .55rem .8rem;
  border: 1px solid var(--lav); border-radius: 3px; background: var(--surface); color: var(--text);
  font-size: .95rem; font-weight: 600; letter-spacing: .04em; cursor: pointer; text-align: left;
  transition: background .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.arm-btn:hover { background: var(--accent-soft); }
.arm-btn .arm-dot { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--lav); flex-shrink: 0; }
.arm-btn .arm-label { flex: 1; }
.arm-btn .arm-key { font-size: .66rem; font-weight: 400; color: var(--text-muted); letter-spacing: .02em; border: 1px solid var(--border); border-radius: 3px; padding: 0 .3rem; }
.arm-btn.armed { border-color: var(--lime); box-shadow: 0 0 0 1px var(--lime), 0 0 0 4px color-mix(in srgb, var(--lime) 18%, transparent); background: color-mix(in srgb, var(--lime) 10%, var(--surface)); }
.arm-btn.armed .arm-dot { background: var(--lime); border-color: var(--lime); animation: pulse 1.2s ease-in-out infinite; }
.arm-btn.fault { border-color: var(--bad); }
.arm-btn.fault .arm-dot { border-color: var(--bad); background: var(--bad); }
.arm-btn:disabled { opacity: .5; cursor: not-allowed; }

.mode-toggle { display: flex; gap: .4rem; }
.mode-btn {
  flex: 1; padding: .35rem .3rem; font-size: .85rem; font-weight: 550; white-space: nowrap;
  border: 1px solid var(--lav); border-radius: 3px; background: var(--surface); color: var(--text-muted); cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.mode-btn:hover { background: var(--bg-soft); }
.mode-btn.active { background: transparent; border-color: var(--lime); color: var(--text); box-shadow: 0 0 0 1px var(--lime); }
.mode-btn:disabled { opacity: .45; cursor: not-allowed; }

/* goal grid (swingup.md) */
.goal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .25rem; }
.goal-btn {
  display: flex; align-items: center; justify-content: center; gap: .35rem; padding: .1rem .4rem; font: inherit;
  border: 1px solid var(--lav); border-radius: 3px; background: var(--surface); color: var(--text); cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.goal-btn:hover { background: var(--bg-soft); }
.goal-btn.active { background: transparent; border-color: var(--lime); box-shadow: 0 0 0 1px var(--lime); }
.goal-btn.pending { border-style: dashed; border-color: var(--lime); }
.goal-btn:disabled { opacity: .45; cursor: not-allowed; }
.goal-btn-random { grid-column: 1 / -1; padding: .25rem .4rem; }
.goal-icon { flex: 0 0 auto; display: flex; align-items: center; justify-content: center; }
.goal-icon svg { display: block; width: 22px; height: 34px; }
.goal-label { font-family: var(--mono); font-weight: 700; font-size: .86rem; }
.gi-rail { stroke: var(--border-strong); stroke-width: 1.5; }
.gi-cart { fill: var(--pend-cart); }
.gi-rod { stroke: var(--pend-rod); stroke-width: 2; stroke-linecap: round; }
.gi-bob-0 { fill: var(--pend-1); }
.gi-bob-1 { fill: var(--pend-2); }
.pose-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: .25rem; }
.pose-row .goal-btn { flex-direction: column; gap: 0; padding: .2rem .1rem .25rem; }
.pose-row .goal-icon svg { width: 16px; height: 25px; }
.pose-row .goal-label { font-size: .7rem; font-weight: 500; }

/* slider group (main.css .pid-group + the site's hairline slider) */
.pid-group { display: grid; grid-template-columns: minmax(0, 1fr); row-gap: .1rem; align-items: center; }
.pid-group > label { display: flex; align-items: baseline; font-family: var(--mono); font-size: .78rem; font-weight: 500; color: var(--text-muted); }
.pid-group > label span { margin-left: auto; font-family: var(--mono); font-size: .82rem; color: var(--accent); font-weight: 400; }
.range-scale { display: flex; justify-content: space-between; font-family: var(--mono); font-size: .64rem; color: var(--text-muted); }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; background: transparent; height: 22px; margin: 0; cursor: pointer; accent-color: var(--lime); }
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: var(--lav); border: 0; border-radius: 0; }
input[type="range"]::-moz-range-track { height: 2px; background: var(--lav); border: 0; border-radius: 0; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 12px; height: 18px; margin-top: -8px; box-sizing: border-box; background: var(--bg); border: 1.5px solid var(--lime); border-radius: 3px; transition: background .12s ease; }
input[type="range"]::-moz-range-thumb { width: 12px; height: 18px; box-sizing: border-box; background: var(--bg); border: 1.5px solid var(--lime); border-radius: 3px; }
input[type="range"]:hover::-webkit-slider-thumb, input[type="range"]:active::-webkit-slider-thumb { background: var(--accent-soft); }
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 2px var(--lav); }
input[type="range"]:disabled { opacity: .45; cursor: default; }

.sim-btn {
  width: 100%; padding: .4rem .6rem; border-radius: 3px; font-size: .8rem; font-weight: 600;
  border: 1px solid var(--lav); background: var(--surface); color: var(--text); cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.sim-btn:hover { background: var(--bg-soft); }
.sim-btn:disabled { opacity: .45; cursor: not-allowed; }
.sim-btn.primary { border: 1.5px solid var(--lime); }
.sim-btn.primary:hover { background: var(--accent-soft); }
.sim-btn.danger { border-color: var(--bad); color: var(--bad); }
.btn-row { display: flex; gap: .4rem; }
.btn-row .sim-btn { width: auto; flex: 1; white-space: nowrap; }

/* ---------------------------------------------------------------
   The network (main.css .nn-netviz / .su-net)
   --------------------------------------------------------------- */
.nn-netviz { margin-top: 1.25rem; padding: 1rem 1.1rem 1.05rem; border: 1px solid var(--border); border-radius: 3px; background: var(--surface); }
.nn-netviz-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem 1rem; margin-bottom: .6rem; }
.nn-netviz-head h3 { margin: 0; font-size: 1rem; }
.nn-meta { font-family: var(--mono); font-size: .72rem; color: var(--text-muted); margin-right: auto; }
.nn-meta .ok { color: var(--lime-text); }
.nn-legend { display: flex; align-items: center; gap: .4rem; }
.nn-legend-bar { width: 120px; height: 12px; border-radius: 3px; border: 1px solid var(--border); background: linear-gradient(90deg, var(--nn-act-neg) 0%, var(--nn-act-zero) 50%, var(--nn-act-pos) 100%); }
.nn-legend-cap { font-family: var(--mono); font-size: .85rem; color: var(--text-muted); line-height: 1; width: 1ch; text-align: center; }
.nn-legend-txt { font-size: .74rem; color: var(--text-muted); margin-left: .1rem; }
.su-net-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 3px; }
/* The diagram is drawn in a ~720 x 300 design space and scaled to fit the canvas, so the box follows
   the diagram's aspect ratio: a fixed height left it height-limited, ~60 % of the width, with empty
   margins on a wide screen. */
.su-net { display: block; width: 100%; aspect-ratio: 12 / 5; max-height: 660px; border: 1px solid var(--border); border-radius: 3px; background: var(--bg-soft); }
.su-net-hint { display: none; margin: .4rem 0 0; font-size: .76rem; color: var(--text-muted); }
.eqn-note { margin: .55rem 0 0; font-size: .74rem; color: var(--text-muted); font-style: italic; }
.eqn-note code { font-style: normal; }

/* ---------------------------------------------------------------
   Cards: figure frames with corner brackets on hover (main.css .card)
   --------------------------------------------------------------- */
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.1rem; margin: .9rem 0 2rem; align-items: start; }
.card {
  position: relative; display: flex; flex-direction: column; gap: .8rem; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 3px; padding: 1rem 1.1rem 1.1rem;
  transition: border-color .15s ease;
}
.card.span-2 { grid-column: span 2; }
.card.span-3 { grid-column: 1 / -1; }
.card.row-2 { grid-row: span 2; }
.card::before, .card::after { content: ""; position: absolute; width: 12px; height: 12px; border: 0 solid var(--lime); pointer-events: none; opacity: 0; transition: opacity .15s ease; }
.card::before { top: -1px; left: -1px; border-top-width: 2px; border-left-width: 2px; }
.card::after { bottom: -1px; right: -1px; border-bottom-width: 2px; border-right-width: 2px; }
@media (hover: hover) { .card:hover { border-color: var(--lav); } }
.card:hover::before, .card:hover::after, .card:focus-within::before, .card:focus-within::after { opacity: 1; }
.card-head { display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 1rem; }
.card-label { font-family: var(--mono); font-size: .7rem; letter-spacing: .04em; color: var(--accent); }
.card-label::before { content: "// "; opacity: .6; }
.tag {
  margin-left: auto; font-family: var(--mono); font-size: .68rem; letter-spacing: .03em; white-space: nowrap;
  padding: .05rem .45rem; border: 1px solid var(--lav); border-radius: 3px; color: var(--text-muted);
}
.tag.ok { border-color: var(--lime); color: var(--lime-text); }
.tag.warn { border-color: var(--viz-2); color: var(--text); }
.tag.bad { border-color: var(--bad); color: var(--bad); }
.card-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.1rem; }
.card-split > .kv { align-self: start; }

/* key/value grids (main.css .telemetry) */
.kv {
  margin: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .2rem .9rem;
  font-family: var(--mono); font-size: .76rem; color: var(--text-muted);
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 3px; padding: .6rem .75rem;
}
.kv dt { color: var(--text-muted); white-space: nowrap; }
.kv dd { margin: 0; color: var(--text); text-align: right; overflow-wrap: anywhere; }
.kv dd.accent { color: var(--accent); }
.kv dd.good { color: var(--lime-text); }
.kv dd.bad { color: var(--bad); }
.kv .kv-head { grid-column: 1 / -1; color: var(--text); font-weight: 500; margin-top: .25rem; }
.kv .kv-head:first-child { margin-top: 0; }

/* meters */
.meter { display: flex; flex-direction: column; gap: .3rem; }
.meter-top { display: flex; align-items: baseline; justify-content: space-between; gap: .6rem; font-family: var(--mono); font-size: .74rem; color: var(--text-muted); }
.meter-top b { font-weight: 500; color: var(--text); font-size: .9rem; }
.meter-track { position: relative; height: 14px; border: 1px solid var(--border-strong); border-radius: 3px; background: var(--bg-soft); overflow: visible; }
.meter-fill { position: absolute; top: 0; bottom: 0; left: 0; width: 0; background: var(--viz-1); transition: width .35s ease; }
.meter-fill.seg-est { background: var(--viz-4); }
.meter-fill.seg-rest { background: var(--viz-7); opacity: .55; }
.meter-max { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: var(--viz-2); transition: left .35s ease; }
.meter-budget { position: absolute; top: -6px; bottom: -6px; width: 0; border-left: 1.5px dashed var(--lime); }
.meter-budget::after { content: attr(data-label); position: absolute; top: -1.15rem; left: 0; transform: translateX(-50%); font-family: var(--mono); font-size: .62rem; color: var(--lime-text); white-space: nowrap; }
.meter-legend { display: flex; flex-wrap: wrap; gap: .25rem .8rem; font-family: var(--mono); font-size: .68rem; color: var(--text-muted); }
.meter-legend i { display: inline-block; width: 8px; height: 8px; margin-right: .3rem; border-radius: 1px; vertical-align: -1px; }
.meter.over .meter-fill { background: var(--bad); }
.core-meter .meter-fill { background: var(--viz-1); }
.core-meter .meter-sub { font-family: var(--mono); font-size: .66rem; color: var(--text-muted); }
.spark { position: relative; height: 70px; }
.spark-long { height: 96px; }
.spark canvas { position: absolute; inset: 0; width: 100%; height: 100%; border: 1px solid var(--border); border-radius: 3px; background: var(--bg); }

/* task table */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 3px; }
table.tasks { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: .74rem; }
.tasks th, .tasks td { padding: .32rem .6rem; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
.tasks th { font-weight: 500; color: var(--text-muted); background: var(--bg-soft); font-size: .68rem; letter-spacing: .03em; }
.tasks th:first-child, .tasks td:first-child { text-align: left; }
.tasks tr:last-child td { border-bottom: 0; }
.tasks td { color: var(--text); }
.tasks tr.hl td { background: var(--accent-soft); }
.tasks tr.idle td { color: var(--text-muted); }
.tasks tr.misplaced td:first-child { color: var(--bad); }
.core-badge { display: inline-block; min-width: 2.6em; text-align: center; padding: 0 .3rem; border: 1px solid var(--lav); border-radius: 3px; font-size: .66rem; }
.core-badge.c1 { border-color: var(--lime); color: var(--lime-text); }
.cpu-cell { display: inline-flex; align-items: center; gap: .45rem; justify-content: flex-end; }
.cpu-bar { display: inline-block; width: 48px; height: 6px; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 1px; position: relative; overflow: hidden; }
.cpu-bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--viz-1); }
.check-line { display: flex; align-items: center; gap: .45rem; font-family: var(--mono); font-size: .72rem; color: var(--text-muted); margin: 0; }
.check-line .ok { color: var(--lime-text); }
.check-line .bad { color: var(--bad); }
.check-line .warn { color: var(--viz-2); font-weight: 700; }
.check-line .muted { color: var(--text-muted); }
#model-check { align-items: flex-start; line-height: 1.45; font-family: var(--font); font-size: .74rem; }
#model-check:empty { display: none; }
.nowrap { white-space: nowrap; }

/* update: one drop zone for firmware images and model blobs */
.dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .35rem;
  min-height: 132px; padding: 1rem; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--lav); border-radius: 3px; background: var(--bg-soft);
  transition: border-color .12s ease, background .12s ease;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); }
.dropzone.over { border-color: var(--lime); border-style: solid; background: var(--accent-soft); }
.dropzone.locked { cursor: not-allowed; opacity: .8; }
.dz-icon { width: 30px; height: 30px; color: var(--accent); }
.dz-title { font-weight: 600; font-size: .92rem; }
.dz-sub { font-family: var(--mono); font-size: .7rem; color: var(--text-muted); }
.dz-sub code { font-size: .95em; }
.file-panel { display: flex; flex-direction: column; gap: .6rem; padding: .75rem .8rem; border: 1px solid var(--lav); border-radius: 3px; }
.file-panel.bad { border-color: var(--bad); }
.file-title { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; font-weight: 600; font-size: .9rem; }
.file-title .mono { font-weight: 400; font-size: .74rem; color: var(--text-muted); overflow-wrap: anywhere; }
.notice { margin: 0; font-size: .76rem; line-height: 1.45; padding: .5rem .65rem; border-left: 2px solid var(--viz-2); background: var(--bg-soft); color: var(--text); }
.notice.bad { border-left-color: var(--bad); }
.notice.good { border-left-color: var(--lime); }
.progress { height: 8px; border: 1px solid var(--border-strong); border-radius: 3px; background: var(--bg-soft); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--lime); transition: width .15s linear; }
.progress-row { display: flex; align-items: center; gap: .6rem; font-family: var(--mono); font-size: .72rem; color: var(--text-muted); }
.progress-row .progress { flex: 1; }
.releases { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .3rem; }
.releases li { display: flex; align-items: baseline; gap: .6rem; font-family: var(--mono); font-size: .74rem; padding: .3rem 0; border-bottom: 1px solid var(--border); }
.releases li.rel-hint { display: block; font-family: var(--font); line-height: 1.5; }
.releases li:last-child { border-bottom: 0; }
.releases .rel-tag { color: var(--text); font-weight: 500; }
.releases .rel-date { color: var(--text-muted); }
.releases .rel-get { margin-left: auto; white-space: nowrap; }
.rel-badge { font-size: .64rem; padding: 0 .35rem; border: 1px solid var(--lime); border-radius: 3px; color: var(--lime-text); }
.link-arrow { font-family: var(--mono); font-size: .78rem; }
.link-arrow::after { content: " →"; }

/* small conveniences: copy on click, fix-it buttons, "go there" highlight */
code.copy { cursor: copy; position: relative; }
code.copy:hover { outline: 1px dashed var(--lav); }
code.copy.copied::after {
  content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 4px); transform: translateX(-50%);
  padding: .05rem .35rem; border-radius: 3px; font-size: .64rem; color: var(--bg); background: var(--text); white-space: nowrap;
}
.notice-btn {
  margin-left: .4rem; padding: .1rem .55rem; font: inherit; font-size: .74rem; font-weight: 600; cursor: pointer;
  border: 1px solid var(--lime); border-radius: 3px; background: var(--surface); color: var(--text);
}
.notice-btn:hover { background: var(--accent-soft); }
.banner-btn { margin-left: .6rem; padding: .05rem .5rem; font: inherit; cursor: pointer; border: 1px solid var(--viz-2); border-radius: 3px; background: var(--bg); color: var(--text); }
.flash-hl { outline: 2px solid var(--lime); outline-offset: 3px; transition: outline-color .3s; }
.kv dd a, .events a { color: var(--accent); }

/* sensors & drive, event log */
.io-table td:nth-child(4) { white-space: normal; text-align: left; }
.io-table th:nth-child(4) { text-align: left; }
.io-table td.good { color: var(--lime-text); }
.io-table td.bad { color: var(--bad); }
.io-table td.accent { color: var(--accent); }
#io-body { display: flex; flex-direction: column; gap: .7rem; }
.events { list-style: none; margin: 0; padding: 0; max-height: 330px; overflow-y: auto; border: 1px solid var(--border); border-radius: 3px; font-family: var(--mono); font-size: .72rem; }
.events li { display: flex; gap: .8rem; padding: .3rem .6rem; border-bottom: 1px solid var(--border); border-left: 2px solid transparent; }
.events li:last-child { border-bottom: 0; }
.events li.muted { color: var(--text-muted); font-family: var(--font); }
.events time { flex: 0 0 4.2rem; color: var(--text-muted); text-align: right; font-variant-numeric: tabular-nums; }
.events span { color: var(--text); overflow-wrap: anywhere; }
.events .ev-warn { border-left-color: var(--viz-2); }
.events .ev-error { border-left-color: var(--bad); }
.events .ev-error span { color: var(--bad); }
.events .ev-sep { display: block; padding: .25rem .6rem; font-size: .66rem; letter-spacing: .04em; color: var(--text-muted); background: var(--bg-soft); }
.events .ev-prev span { opacity: .8; }

/* forms */
.col { display: flex; flex-direction: column; gap: .6rem; min-width: 0; }
.form-inline { display: flex; align-items: flex-end; gap: .5rem; }
.form-inline .field { flex: 1; min-width: 0; }
.form-inline .sim-btn { width: auto; flex: 0 0 auto; padding-block: .45rem; }
.input-suffix { display: flex; align-items: stretch; }
.input-suffix input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-suffix span { display: flex; align-items: center; padding: 0 .5rem; font-family: var(--mono); font-size: .76rem; color: var(--text-muted);
  border: 1px solid var(--lav); border-left: 0; border-radius: 0 3px 3px 0; background: var(--bg-soft); }
.form { display: grid; gap: .55rem; }
.field { display: grid; gap: .2rem; }
.field label { font-family: var(--mono); font-size: .72rem; color: var(--text-muted); }
.field input, .field select {
  width: 100%; padding: .45rem .6rem; font-size: .85rem; color: var(--text);
  background: var(--bg); border: 1px solid var(--lav); border-radius: 3px;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--lime); box-shadow: 0 0 0 1px var(--lime); }
.rssi { display: inline-flex; align-items: flex-end; gap: 2px; height: 11px; margin-right: .35rem; vertical-align: -1px; }
.rssi i { width: 3px; background: var(--border-strong); border-radius: 1px; }
.rssi i.on { background: var(--lime); }

/* record card: the controls a preset needs, then the presets */
.rec-ctrl { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; padding-bottom: .8rem; border-bottom: 1px solid var(--border); }
.rec-ctrl .arm-btn-sm { width: auto; min-height: 36px; flex: 0 0 15rem; font-size: .85rem; white-space: nowrap; }
.rec-ctrl .mode-toggle { flex: 0 0 12rem; }
.rec-ctrl-note { font-family: var(--mono); font-size: .72rem; color: var(--text-muted); }
.rec-plot { position: relative; height: 190px; }
.rec-plot canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
/* record card */
.preset-row { display: flex; flex-wrap: wrap; gap: .35rem; }
.preset-row .mode-btn { flex: 1 1 auto; font-size: .8rem; }
.rec-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: .5rem .6rem; }
.rec-fields .field[hidden] { display: none; }
.chip-rec { border-color: var(--bad); color: var(--bad); font-weight: 600; letter-spacing: .06em; }
.chip-rec b { color: var(--bad); font-weight: 500; letter-spacing: 0; }
.chip-rec .dot { background: var(--bad); animation: blink 1s steps(2) infinite; }
.progress i.rec-on { background: var(--bad); }

/* ---------------------------------------------------------------
   Footer
   --------------------------------------------------------------- */
.site-footer { border-top: 1px solid var(--lav); background: var(--bg-soft); }
.footer-inner { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; align-items: center; justify-content: space-between; padding-block: 1.1rem; font-family: var(--mono); font-size: .74rem; color: var(--text-muted); }
.footer-inner p { margin: 0; }

/* ---------------------------------------------------------------
   Responsive
   --------------------------------------------------------------- */
@media (max-width: 1100px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card.span-2 { grid-column: 1 / -1; }
  .card.row-2 { grid-row: auto; }
}
@media (max-width: 900px) {
  .chip-hide-md { display: none; }
}
@media (max-width: 760px) {
  .nav { flex-wrap: wrap; row-gap: .35rem; }
  .tabs { order: 5; flex-basis: 100%; margin-right: 0; overflow-x: auto; }
  .tab { flex: 1 0 auto; text-align: center; }
  .sim-panel { flex-basis: 100%; order: 2; }
  /* The stack's cells become items of .sim-layout so the controls sit between the scene and the plot. */
  .sim-stack { display: contents; }
  .sim-stack > .sim-cell { flex: 1 1 100%; }
  .sim-stack > .sim-cell:first-child { order: 1; height: 330px; }
  .sim-stack > .sim-cell:last-child { order: 3; height: 300px; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .card-split { grid-template-columns: minmax(0, 1fr); }
  .su-net { min-width: 940px; height: 300px; aspect-ratio: auto; max-height: none; }
  .su-net-hint { display: block; }
  .site-header { background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .head-facts { display: none; }
}
@media (max-width: 560px) {
  .nav { gap: .5rem; padding-inline: 1rem; }
  .wrap { padding-inline: 1rem; }
  .page-head { padding-inline: 1rem; }
  .nav-brand .brand-sub { display: none; }
  .chip-hide-sm { display: none; }
  .nav-chips { gap: .3rem; }
  .chip { padding: 0 .45rem; }
  .chip-conn #conn-text { display: none; }
  .chip-rec b { display: none; }
  .rec-ctrl .arm-btn-sm, .rec-ctrl .mode-toggle { flex: 1 1 100%; }
  .sim-stack > .sim-cell:first-child { height: 300px; }
  .reach-val { font-size: 1.3rem; }
  .reach-lbl { font-size: .6rem; }
  .run-badge { font-size: .72rem; }
}
@media (pointer: coarse) {
  button, input, a { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
  .mode-btn, .sim-btn, .goal-btn { min-height: 44px; }
  .field input { font-size: 16px; min-height: 40px; }
  input[type="range"] { min-height: 32px; }
}
