:root {
  --bg: #070b11;
  --bg2: #0b1119;
  --panel: #0f1620;
  --panel2: #131c28;
  --line: #1d2836;
  --line2: #273547;
  --text: #dbe6f3;
  --muted: #7d8da3;
  --dim: #4d5d72;
  --air: #3fc6ff;
  --hot: #ff9f43;
  --fuel: #ffb020;
  --exh: #a2826c;
  --spark: #ffe45c;
  --ok: #3ee07a;
  --warn: #ffc043;
  --bad: #ff4d5e;
  --info: #62a8ff;
  --cam: #b98cff;
  --accent: #2ee6c5;
  --radius: 14px;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(46, 230, 197, 0.07), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(98, 168, 255, 0.07), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button { font-family: inherit; color: inherit; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
kbd {
  font-family: var(--mono); font-size: 10.5px; padding: 1px 5px; border-radius: 4px;
  background: var(--panel2); border: 1px solid var(--line2); border-bottom-width: 2px; color: var(--text);
}
.hint { color: var(--muted); font-size: 11.5px; margin: 6px 0 0; }
.sub { color: var(--muted); font-weight: 500; font-size: 11.5px; margin-left: 6px; }

/* ================= TOP BAR ================= */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 20px; justify-content: space-between;
  padding: 10px 18px;
  background: rgba(7, 11, 17, 0.82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, #0f3b3a, #10243f);
  border: 1px solid #1f5452;
  box-shadow: 0 0 24px rgba(46, 230, 197, 0.25), inset 0 0 12px rgba(46, 230, 197, 0.15);
}
.logo svg { width: 26px; height: 26px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; }
.brand h1 { margin: 0; font-size: 17px; font-weight: 800; letter-spacing: -0.01em; }
.brand p { margin: 0; color: var(--muted); font-size: 11.5px; }
.top-right { display: flex; align-items: center; gap: 10px; }
.speed-wrap { display: flex; align-items: center; gap: 8px; }
.lbl { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }

/* segmented controls */
.seg {
  display: inline-flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 3px;
}
.seg button {
  border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; cursor: pointer; color: var(--muted);
  font-weight: 600; font-size: 12px; transition: background .2s, color .2s, box-shadow .2s;
}
.seg button:hover { color: var(--text); background: rgba(255, 255, 255, 0.03); }
.seg button.active {
  background: linear-gradient(180deg, #1a2838, #152131); color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line2), 0 4px 14px rgba(0, 0, 0, 0.35);
}
.seg.small button { padding: 5px 9px; font-size: 11.5px; }
.seg.wide { display: flex; }
.seg.wide button { flex: 1; }
.engine-seg button { display: flex; flex-direction: column; align-items: flex-start; padding: 7px 16px; min-width: 170px; }
.engine-seg .seg-title { font-size: 13px; }
.engine-seg .seg-sub { font-size: 10.5px; color: var(--dim); font-weight: 500; }
.engine-seg button.active .seg-sub { color: var(--muted); }
.engine-seg button[data-engine="na"].active { box-shadow: inset 0 0 0 1px rgba(63, 198, 255, .5), 0 0 18px rgba(63, 198, 255, .15); }
.engine-seg button[data-engine="turbo"].active { box-shadow: inset 0 0 0 1px rgba(255, 159, 67, .55), 0 0 18px rgba(255, 159, 67, .18); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line2); background: var(--panel2); color: var(--text);
  padding: 7px 12px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 12px;
  transition: transform .1s, background .2s, border-color .2s, box-shadow .2s;
}
.btn:hover { border-color: #38506a; background: #182334; }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; fill: currentColor; }
.btn.icon { padding: 7px 10px; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 9px; font-size: 11.5px; }
.btn.full { width: 100%; margin-top: 8px; }
.btn.primary {
  background: linear-gradient(180deg, #16c79f, #0f9f80); border-color: #1fe3b6; color: #03140f;
  box-shadow: 0 6px 20px rgba(46, 230, 197, 0.25);
}
.btn.primary:hover { background: linear-gradient(180deg, #1ed8ad, #12ad8b); }
.btn.hold.active, .btn.hold:active { background: #3a1419; border-color: var(--bad); color: #ffd2d6; box-shadow: 0 0 16px rgba(255, 77, 94, .3); }
#pauseBtn.paused { background: #2d2410; border-color: var(--warn); color: var(--warn); }

/* ================= LAYOUT ================= */
/* Shell = [sidebar | content]. The sidebar owns a full-height column, so its sticky
   panel travels the whole page without ever sliding over content cells. */
.shell {
  display: grid; column-gap: 14px; padding: 14px 18px 8px;
  grid-template-columns: 300px minmax(0, 1fr);
  align-items: start;
  transition: grid-template-columns .3s ease, column-gap .3s ease;
}
.controls { transition: opacity .2s ease, transform .3s ease; }
body.controls-collapsed .shell { grid-template-columns: 0 minmax(0, 1fr); column-gap: 0; }
body.controls-collapsed .controls { padding-left: 0; padding-right: 0; border-width: 0; overflow: hidden; opacity: 0; transform: translateX(-24px); pointer-events: none; visibility: hidden; transition: opacity .2s ease, transform .3s ease, visibility 0s .3s; }
.panel-toggle svg { fill: none; width: 18px; height: 18px; }
.panel-toggle.active { color: var(--accent); border-color: rgba(46, 230, 197, .45); }
.panel-toggle .pt-fill { fill: currentColor; opacity: .55; transition: opacity .2s; }
body.controls-collapsed .panel-toggle .pt-fill { opacity: 0; }
.collapse-btn { font-size: 15px; line-height: 1; padding: 3px 9px; }

.layout {
  display: grid; gap: 14px; min-width: 0;
  grid-template-columns: minmax(0, 1fr) 350px;
  grid-template-areas:
    "cluster sensors"
    "engine sensors"
    "wheels sensors"
    "scope scope"
    "maps maps"
    "dyno dyno"
    "diagram brain"
    "trends log"
    "actuators actuators";
  align-items: start;
}
.cluster { grid-area: cluster; }
.engine { grid-area: engine; }
.wheels { grid-area: wheels; }
.sensors { grid-area: sensors; align-self: stretch; }
.scope { grid-area: scope; }
.maps { grid-area: maps; }
.dyno { grid-area: dyno; }
.diagram { grid-area: diagram; }
.brain { grid-area: brain; align-self: stretch; }
.trends { grid-area: trends; }
.log { grid-area: log; align-self: stretch; }
.actuators { grid-area: actuators; }

@media (max-width: 1320px) {
  .shell { grid-template-columns: 290px minmax(0, 1fr); }
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "cluster" "engine" "wheels" "sensors" "scope" "maps" "dyno" "diagram" "brain" "trends" "log" "actuators";
  }
  .sensor-list { max-height: none !important; columns: 2; column-gap: 12px; }
}
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .engine-seg button { min-width: 0; }
  .speed-wrap .lbl { display: none; }
  .top-right { flex-wrap: wrap; }
  .shell, body.controls-collapsed .shell { padding: 12px 16px; grid-template-columns: minmax(0, 1fr); column-gap: 0; }
  .sensor-list { columns: 1; }
  /* controls become an off-canvas drawer (desktop collapse state doesn't apply here) */
  .controls, body.controls-collapsed .controls {
    position: fixed !important; top: 0; left: 0; bottom: 0; z-index: 48; width: min(330px, 88vw); max-height: none !important;
    border-radius: 0 16px 16px 0; padding: 14px; border-width: 1px; opacity: 1; visibility: visible; pointer-events: auto; overflow-y: auto;
    transform: translateX(-105%); transition: transform .3s cubic-bezier(.2, .9, .3, 1);
    box-shadow: 20px 0 60px rgba(0, 0, 0, .5);
  }
  body.drawer-open .controls { transform: none; }
  body.drawer-open .drawer-backdrop { display: block; }
  body.drawer-open .touch-pad { display: none; }
  body { padding-bottom: 104px; }
  body.lesson-open .touch-pad { display: none; }
}
.drawer-backdrop { display: none; position: fixed; inset: 0; z-index: 47; background: rgba(3, 6, 10, .6); backdrop-filter: blur(3px); }

/* ---------- floating touch driving controls (phones) ---------- */
@media (min-width: 861px) { .touch-pad { display: none !important; } }
.touch-pad {
  display: flex; position: fixed; left: 8px; right: 8px; bottom: 8px; z-index: 44; gap: 8px; align-items: stretch;
  padding: 8px; border-radius: 18px; background: rgba(10, 16, 24, .92); border: 1px solid var(--line2); backdrop-filter: blur(10px);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .45);
}
.tp-btn {
  border: 1px solid var(--line2); background: var(--panel2); color: var(--text); border-radius: 12px; font-weight: 800; cursor: pointer;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.tp-brake { flex: 1; font-size: 13px; }
.tp-brake.active { background: #3a1419; border-color: var(--bad); color: #ffd2d6; box-shadow: 0 0 16px rgba(255, 77, 94, .35); }
.tp-gas { flex: 1.4; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 15px; min-height: 72px;
  background: linear-gradient(180deg, #15352c, #0f241e); border-color: #1f5a4a; }
.tp-gas small { font-family: var(--mono); font-size: 11px; color: var(--muted); font-weight: 600; }
.tp-gas.active { background: linear-gradient(180deg, #1ec7a0, #0f9f80); color: #03140f; border-color: #1fe3b6; box-shadow: 0 0 20px rgba(46, 230, 197, .4); }
.tp-gas.active small { color: #06261d; }
.tp-mid { flex: 1.2; display: flex; flex-direction: column; gap: 6px; justify-content: center; }
.tp-start { padding: 8px 6px; font-size: 12px; background: linear-gradient(180deg, #16c79f, #0f9f80); color: #03140f; border-color: #1fe3b6; }
.tp-start[hidden] { display: none; }
.tp-gear { display: flex; align-items: center; gap: 6px; }
.tp-gear .tp-btn { flex: 1; padding: 8px 0; font-size: 18px; line-height: 1; }
.tp-gear b { font-family: var(--mono); font-size: 20px; min-width: 26px; text-align: center; }

.panel {
  background: linear-gradient(180deg, rgba(19, 28, 40, 0.92), rgba(13, 20, 29, 0.92));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.03);
}
.panel-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.panel-h h2 { margin: 0; font-size: 13.5px; font-weight: 700; letter-spacing: 0.01em; }
.canvas-wrap { position: relative; width: 100%; }
canvas { display: block; width: 100%; }

.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.turbo-only { display: none !important; }
body.is-turbo .turbo-only { display: revert !important; }
body.is-turbo .ctl.turbo-only { display: block !important; }
body.is-turbo .legend .turbo-only { display: inline-flex !important; }
body.is-turbo .diag .turbo-only { display: inline !important; }
body:not(.is-turbo) .diag .na-only { display: inline; }
body.is-turbo .diag .na-only { display: none; }

/* ================= CONTROLS ================= */
.controls { position: sticky; top: 76px; max-height: calc(100vh - 90px); overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line2) transparent; }
.ctl { padding: 12px 0; border-top: 1px solid var(--line); }
.ctl:first-of-type { border-top: 0; padding-top: 0; }
.ctl h3 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 700; display: flex; align-items: center; justify-content: space-between; }
.ctl h3 .sub { text-transform: none; letter-spacing: 0; margin-left: auto; margin-right: 0; font-weight: 500; }
.ctl h3 .val { color: var(--text); letter-spacing: 0; font-size: 12px; }
.slider-lbl { display: flex; justify-content: space-between; color: var(--muted); font-size: 11.5px; margin: 8px 0 4px; }
.slider-lbl .mono { color: var(--text); }
.row2 { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.row2 > * { flex: 1; }
.mini-stat { display: flex; flex-direction: column; align-items: flex-end; }
.mini-stat .mono { font-size: 15px; font-weight: 700; }

.range { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 6px; background: var(--line); outline: none; margin: 4px 0; --fill: 0%; background-image: linear-gradient(90deg, var(--accent), var(--accent)); background-size: var(--fill) 100%; background-repeat: no-repeat; }
.range::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: #e8fff9; border: 3px solid var(--accent); cursor: pointer; box-shadow: 0 0 10px rgba(46, 230, 197, .5); }
.range::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #e8fff9; border: 3px solid var(--accent); cursor: pointer; }
.range.big { height: 10px; }
.range.big::-webkit-slider-thumb { width: 22px; height: 22px; }
#pedal { background-image: linear-gradient(90deg, #1ec7a0, #ffc043 70%, #ff4d5e); }

.chips { display: flex; gap: 5px; margin-top: 8px; }
.chips button { flex: 1; border: 1px solid var(--line2); background: var(--bg2); border-radius: 7px; padding: 4px 0; font-size: 11px; font-weight: 600; cursor: pointer; color: var(--muted); }
.chips button:hover { color: var(--text); border-color: #38506a; }
.gears { display: flex; width: 100%; }
.gears button { flex: 1; font-family: var(--mono); font-size: 14px; font-weight: 700; }

.toggle { display: inline-flex; align-items: center; justify-content: center; gap: 7px; background: var(--bg2); border: 1px solid var(--line2); border-radius: 9px; padding: 7px 8px; font-weight: 600; font-size: 12px; cursor: pointer; color: var(--muted); }
.toggle .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); transition: all .2s; }
.toggle.on { color: var(--text); border-color: #2c6b5d; }
.toggle.on .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }

/* key dial */
.key-wrap { display: flex; gap: 12px; align-items: center; }
.keydial { position: relative; width: 128px; height: 128px; flex: none; }
.keydial svg { position: absolute; inset: 14px; width: 100px; height: 100px; }
.kd-ring { fill: #0a1018; stroke: var(--line2); stroke-width: 3; }
.kd-key { transform-origin: 60px 60px; transition: transform .35s cubic-bezier(.3, 1.5, .5, 1); }
.kd-key rect, .kd-key circle { fill: #b7c4d4; }
.kd-key .kd-hole { fill: #0a1018; }
.kpos {
  position: absolute; left: 50%; top: 50%; border: 0; background: transparent; font-size: 9.5px; font-weight: 800; letter-spacing: .04em;
  color: var(--dim); cursor: pointer; padding: 2px 3px; border-radius: 4px;
  transform: translate(-50%, -50%) rotate(var(--a)) translateY(-58px) rotate(calc(var(--a) * -1));
}
.kpos:hover { color: var(--text); }
.kpos.active { color: var(--accent); text-shadow: 0 0 8px rgba(46, 230, 197, .7); }
.kpos[data-key="START"].active { color: var(--warn); text-shadow: 0 0 8px rgba(255, 192, 67, .8); }
.key-side { flex: 1; min-width: 0; }
.key-side .btn { width: 100%; }

/* faults */
.fault-list { display: flex; flex-direction: column; gap: 4px; }
.fault {
  display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 9px;
  background: var(--bg2); border: 1px solid transparent; cursor: pointer; text-align: left; transition: border-color .2s, background .2s;
}
.fault:hover { border-color: var(--line2); }
.fault .sw { width: 28px; height: 16px; border-radius: 10px; background: var(--line2); position: relative; transition: background .2s; }
.fault .sw::after { content: ''; position: absolute; left: 2px; top: 2px; width: 12px; height: 12px; border-radius: 50%; background: #8b9bb0; transition: transform .2s, background .2s; }
.fault.on { background: rgba(255, 77, 94, 0.08); border-color: rgba(255, 77, 94, 0.35); }
.fault.on .sw { background: rgba(255, 77, 94, .5); }
.fault.on .sw::after { transform: translateX(12px); background: #ffe1e4; }
.fault .fn { font-size: 12px; font-weight: 600; line-height: 1.2; }
.fault .fh { font-size: 10.5px; color: var(--muted); line-height: 1.25; display: none; }
.fault.on .fh, .fault:hover .fh { display: block; }
.fault .fc { font-family: var(--mono); font-size: 10px; color: var(--dim); }
.fault.on .fc { color: var(--bad); }

/* ================= CLUSTER ================= */
.cluster {
  background: radial-gradient(120% 140% at 50% 0%, #111c2a 0%, #080d14 70%);
  padding: 10px 14px 12px;
}
.lamps { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 6px; }
.lamp {
  display: flex; align-items: center; gap: 5px; padding: 4px 8px 4px 6px; border-radius: 8px; background: #0a0f16; border: 1px solid #141d29;
  color: #2a3544; font-size: 10px; font-weight: 700; letter-spacing: .04em; transition: all .15s; cursor: help;
}
.lamp svg { width: 18px; height: 18px; fill: currentColor; }
.lamp.on { color: var(--c); border-color: color-mix(in srgb, var(--c) 45%, transparent); background: color-mix(in srgb, var(--c) 10%, #0a0f16); box-shadow: 0 0 14px color-mix(in srgb, var(--c) 35%, transparent); text-shadow: 0 0 6px var(--c); }
.lamp.on svg { filter: drop-shadow(0 0 4px var(--c)); }
.lamp.flash { animation: flash .5s steps(1) infinite; }
@keyframes flash { 50% { color: #2a3544; box-shadow: none; text-shadow: none; background: #0a0f16; } }

/* ================= ENGINE ================= */
.engine-foot { display: flex; gap: 14px; align-items: stretch; margin-top: 8px; }
.angle-readout { display: grid; grid-template-columns: auto auto; gap: 0 10px; align-items: baseline; padding: 8px 12px; background: var(--bg2); border-radius: 10px; border: 1px solid var(--line); }
.angle-readout .big { font-size: 20px; font-weight: 700; color: var(--accent); }
.now-box { flex: 1; padding: 8px 12px; background: var(--bg2); border-radius: 10px; border: 1px solid var(--line); color: var(--text); font-size: 12.5px; display: flex; align-items: center; min-height: 48px; }
.now-box b { color: var(--accent); }
.now-box .tag { display: inline-block; padding: 1px 6px; border-radius: 5px; font-size: 10.5px; font-weight: 700; margin-right: 6px; }

.sync-pill, .mode-pill {
  font-family: var(--mono); font-weight: 700; font-size: 11px; padding: 4px 10px; border-radius: 20px; background: var(--bg2); border: 1px solid var(--line2); color: var(--muted);
}
.sync-pill.s1 { color: var(--warn); border-color: rgba(255, 192, 67, .5); box-shadow: 0 0 12px rgba(255, 192, 67, .15); }
.sync-pill.s2 { color: var(--ok); border-color: rgba(62, 224, 122, .5); box-shadow: 0 0 12px rgba(62, 224, 122, .15); }

/* ================= SENSORS ================= */
.sensors { display: flex; flex-direction: column; }
.count { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.sensor-list { overflow-y: auto; max-height: calc(100vh - 150px); min-height: 0; flex: 1; padding-right: 4px; scrollbar-width: thin; scrollbar-color: var(--line2) transparent; }
.s-group { break-inside: avoid; margin-bottom: 10px; }
.s-group h4 { margin: 0 0 4px; font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--dim); font-weight: 700; }
.srow {
  display: grid; grid-template-columns: 10px 1fr auto; grid-template-rows: auto auto; column-gap: 8px; align-items: center;
  padding: 6px 8px; border-radius: 9px; cursor: pointer; border: 1px solid transparent; transition: background .15s, border-color .15s; break-inside: avoid;
}
.srow:hover { background: rgba(255, 255, 255, 0.03); border-color: var(--line); }
.srow.sel { background: rgba(46, 230, 197, 0.06); border-color: rgba(46, 230, 197, 0.35); }
.srow .led { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); grid-row: span 2; align-self: center; }
.srow .led.ok { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.srow .led.warn { background: var(--warn); box-shadow: 0 0 6px var(--warn); }
.srow .led.bad { background: var(--bad); box-shadow: 0 0 8px var(--bad); animation: flash 0.8s steps(1) infinite; }
.srow .led.live { background: var(--info); box-shadow: 0 0 6px var(--info); }
.srow .sn { font-weight: 600; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.srow .sn .ab { font-family: var(--mono); font-size: 10px; color: var(--muted); margin-right: 5px; font-weight: 500; }
.srow .sv { font-family: var(--mono); font-weight: 700; font-size: 12.5px; text-align: right; white-space: nowrap; }
.srow .sv small { color: var(--muted); font-weight: 500; font-size: 10px; margin-left: 2px; }
.srow .sbar { height: 3px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.srow .sbar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .15s linear; }
.srow .ssig { font-family: var(--mono); font-size: 10px; color: var(--muted); text-align: right; margin-top: 3px; white-space: nowrap; }
.srow.flashy .sv { color: var(--spark); }

/* ================= SCOPE ================= */
.scope-read { font-size: 11px; color: var(--muted); }
#scopeCanvas { cursor: crosshair; }

/* ================= DIAGRAM ================= */
.diagram-wrap { width: 100%; }
.diagram-wrap svg { width: 100%; height: auto; display: block; }
.diag text { font-family: var(--sans); }
.diag .lbl-s { font-size: 11px; fill: var(--muted); font-weight: 600; }
.diag .lbl-c { font-size: 12px; fill: var(--text); font-weight: 700; }
.diag .val { font-family: var(--mono); font-size: 11px; fill: var(--text); font-weight: 700; }
.diag .comp { fill: #121b27; stroke: #2a3a4e; stroke-width: 1.5; }
.diag .pipe { fill: none; stroke: #1a2533; stroke-linecap: round; stroke-linejoin: round; }
.diag .flow { fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 3 11; }
.diag .snode { cursor: pointer; }
.diag .snode circle.ring { fill: #0a1018; stroke-width: 2; transition: r .2s; }
.diag .snode:hover circle.ring { r: 11; }
.diag .snode.sel circle.ring { stroke: var(--accent) !important; filter: drop-shadow(0 0 6px var(--accent)); }
.diag .snode text.ab { font-family: var(--mono); font-size: 7.5px; font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.diag .tag-bg { fill: rgba(8, 12, 18, 0.85); stroke: #223044; }

/* ================= BRAIN ================= */
.brain-body { display: flex; flex-direction: column; gap: 6px; }
.bstep { padding: 8px 10px; border-radius: 10px; background: var(--bg2); border: 1px solid var(--line); position: relative; }
.bstep .bt { font-size: 10px; text-transform: uppercase; letter-spacing: .09em; font-weight: 700; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.bstep .bt .st { font-family: var(--mono); letter-spacing: 0; font-size: 10.5px; text-transform: none; }
.bstep .bb { font-size: 12px; margin-top: 3px; }
.bstep .calc { font-family: var(--mono); font-size: 11px; color: #a9bbd0; margin-top: 3px; word-break: break-word; }
.bstep .calc b { color: var(--text); }
.bstep::before { content: ''; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--c, var(--line2)); }
.mode-pill.run { color: var(--ok); border-color: rgba(62, 224, 122, .45); }
.mode-pill.warn { color: var(--warn); border-color: rgba(255, 192, 67, .45); }
.mode-pill.bad { color: var(--bad); border-color: rgba(255, 77, 94, .5); }

/* ================= LOG ================= */
.log { display: flex; flex-direction: column; }
.dtc-count { font-family: var(--mono); font-size: 11px; }
.dtc-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.dtc { display: flex; gap: 8px; align-items: center; padding: 6px 9px; border-radius: 8px; background: rgba(255, 77, 94, .08); border: 1px solid rgba(255, 77, 94, .3); font-size: 11.5px; animation: pop .35s ease; }
.dtc b { font-family: var(--mono); color: var(--bad); }
.log-list { overflow-y: auto; max-height: 300px; flex: 1; display: flex; flex-direction: column; gap: 2px; padding-right: 4px; scrollbar-width: thin; scrollbar-color: var(--line2) transparent; }
.lg { display: grid; grid-template-columns: 50px 1fr; gap: 8px; padding: 5px 8px; border-radius: 7px; font-size: 11.5px; border-left: 2px solid var(--c, var(--line2)); background: rgba(255, 255, 255, .015); animation: pop .35s ease; }
.lg .lt { font-family: var(--mono); font-size: 10.5px; color: var(--dim); padding-top: 1px; }
.lg.ok { --c: var(--ok); } .lg.warn { --c: var(--warn); } .lg.fault { --c: var(--bad); } .lg.info { --c: var(--info); }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }

/* ================= ACTUATORS ================= */
.act-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.act { padding: 9px 11px; border-radius: 10px; background: var(--bg2); border: 1px solid var(--line); cursor: pointer; transition: border-color .2s, box-shadow .2s; }
.act:hover { border-color: var(--line2); }
.act.on { border-color: color-mix(in srgb, var(--c, var(--ok)) 45%, transparent); box-shadow: 0 0 14px color-mix(in srgb, var(--c, var(--ok)) 12%, transparent); }
.act .an { font-weight: 700; font-size: 12px; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.act .an .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); flex: none; }
.act.on .an .dot { background: var(--c, var(--ok)); box-shadow: 0 0 8px var(--c, var(--ok)); }
.act .av { font-family: var(--mono); font-size: 11.5px; color: #a9bbd0; margin-top: 3px; }
.act .abar { height: 4px; border-radius: 3px; background: var(--line); margin-top: 6px; overflow: hidden; }
.act .abar i { display: block; height: 100%; background: var(--c, var(--ok)); width: 0; transition: width .12s linear; }

/* ================= DRAWER ================= */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); z-index: 50;
  background: linear-gradient(180deg, #111a26, #0b111a); border-left: 1px solid var(--line2);
  box-shadow: -20px 0 60px rgba(0, 0, 0, .5); transform: translateX(105%); transition: transform .35s cubic-bezier(.2, .9, .3, 1);
  padding: 22px 22px 30px; overflow-y: auto;
}
.drawer.open { transform: none; }
.drawer-x { position: absolute; right: 14px; top: 12px; width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line2); background: var(--panel2); font-size: 18px; cursor: pointer; color: var(--muted); }
.drawer-x:hover { color: var(--text); }
.drawer h2 { margin: 0 40px 2px 0; font-size: 19px; }
.drawer .tech { display: inline-block; font-size: 11px; color: var(--accent); border: 1px solid rgba(46, 230, 197, .35); border-radius: 6px; padding: 2px 8px; margin: 6px 0 14px; }
.drawer .live { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.drawer .live div { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.drawer .live .mono { font-size: 20px; font-weight: 700; display: block; }
.drawer canvas { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 14px; }
.drawer h4 { margin: 14px 0 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.drawer p { margin: 0; font-size: 13px; color: #c6d3e2; line-height: 1.55; }
.drawer .fail { background: rgba(255, 77, 94, .07); border: 1px solid rgba(255, 77, 94, .25); border-radius: 10px; padding: 10px 12px; }

.modal { position: fixed; inset: 0; z-index: 60; background: rgba(3, 6, 10, .7); backdrop-filter: blur(6px); display: none; place-items: center; padding: 16px; }
.modal.open { display: grid; }
.modal-card { position: relative; max-width: 620px; background: var(--panel); border: 1px solid var(--line2); border-radius: 16px; padding: 24px 26px; box-shadow: 0 30px 80px rgba(0, 0, 0, .6); }
.modal-card h2 { margin: 0 0 12px; }
.modal-card ol { padding-left: 18px; margin: 0; display: flex; flex-direction: column; gap: 8px; color: #c6d3e2; font-size: 13px; }
.modal-card b { color: var(--text); }

.foot { color: var(--dim); text-align: center; font-size: 11px; padding: 6px 16px 20px; }

/* ================= LESSONS ================= */
.lessons-btn { gap: 6px; border-color: rgba(46, 230, 197, .4); }
.lessons-btn:hover { box-shadow: 0 0 14px rgba(46, 230, 197, .2); }
.lesson-focus {
  outline: 2px solid var(--accent); outline-offset: 3px;
  animation: lessonPulse 1.6s ease-in-out infinite;
  position: relative; z-index: 2;
}
@keyframes lessonPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(46, 230, 197, .35), 0 10px 30px rgba(0, 0, 0, .25); }
  50% { box-shadow: 0 0 0 8px rgba(46, 230, 197, 0), 0 0 28px rgba(46, 230, 197, .25); }
}
.coach {
  position: fixed; right: 18px; bottom: 18px; z-index: 45; width: min(410px, calc(100vw - 32px));
  background: linear-gradient(180deg, #13202e, #0d1520); border: 1px solid rgba(46, 230, 197, .45); border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55), 0 0 30px rgba(46, 230, 197, .12);
  display: none; overflow: hidden;
}
.coach.open { display: block; animation: pop .3s ease; }
.coach-h { display: flex; align-items: center; gap: 8px; padding: 10px 10px 8px 14px; }
.coach-badge { font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); white-space: nowrap; }
.coach-title { flex: 1; font-size: 12.5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.coach-x { width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--line2); background: var(--panel2); color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; flex: none; }
.coach-x:hover { color: var(--text); }
.coach-prog { height: 3px; background: var(--line); }
.coach-prog i { display: block; height: 100%; background: var(--accent); transition: width .4s ease; }
.coach-body { padding: 12px 14px 4px; }
.coach-step { font-size: 10.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.coach-body p { margin: 6px 0 10px; font-size: 13px; line-height: 1.55; color: #d3dfec; }
.coach-body p b { color: var(--text); }
.coach-wait { display: inline-flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--warn); background: rgba(255, 192, 67, .08); border: 1px solid rgba(255, 192, 67, .3); padding: 4px 9px; border-radius: 8px; }
.coach-wait .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); animation: flash 1s steps(1) infinite; }
.coach-wait.ok { color: var(--ok); background: rgba(62, 224, 122, .08); border-color: rgba(62, 224, 122, .35); }
.coach-wait.ok .dot { display: none; }
.coach-f { display: flex; gap: 8px; align-items: center; padding: 10px 14px 12px; }
.coach.min .coach-body, .coach.min .coach-f { display: none; }
.lesson-modal { width: min(640px, 100%); }
.lesson-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.lesson-card {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: center; text-align: left; cursor: pointer;
  padding: 12px 14px; border-radius: 12px; background: var(--bg2); border: 1px solid var(--line); transition: border-color .2s, transform .1s;
}
.lesson-card:hover { border-color: rgba(46, 230, 197, .5); }
.lesson-card:active { transform: translateY(1px); }
.lesson-card .ln { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-family: var(--mono); font-weight: 700; color: var(--accent); background: rgba(46, 230, 197, .1); }
.lesson-card .lt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.lesson-card .lt b { font-size: 13px; }
.lesson-card .lt small { color: var(--muted); font-size: 11.5px; line-height: 1.4; }
.lesson-card .lm { font-family: var(--mono); font-size: 11px; color: var(--dim); white-space: nowrap; }
.lesson-card .lok { font-style: normal; color: var(--ok); margin-right: 6px; }
@media (max-width: 860px) {
  .coach { right: 8px; left: 8px; bottom: 8px; width: auto; }
  .lessons-btn span[data-i18n] { display: none; }
}

/* ================= CALIBRATION MAPS ================= */
.maps-body { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .maps-body { grid-template-columns: minmax(0, 1fr); } }
#mapCanvas { cursor: cell; border-radius: 8px; outline: none; touch-action: none; }
#mapCanvas:focus-visible { box-shadow: 0 0 0 2px rgba(46, 230, 197, .5); }
.map-side { display: flex; flex-direction: column; gap: 10px; font-size: 12px; }
.map-side .mdesc { margin: 0; color: #c6d3e2; line-height: 1.5; }
.mlive { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; gap: 3px; }
.mrow { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); }
.mrow b { font-family: var(--mono); color: var(--text); font-weight: 700; white-space: nowrap; }
.mrow.hl b { color: var(--accent); }
.mrow.bad b { color: var(--bad); }
.mrow.ok b { color: var(--ok); }
.mhover { font-family: var(--mono); font-size: 11px; color: var(--muted); min-height: 16px; }
.mhover b { color: var(--text); }
.medit { display: flex; flex-direction: column; gap: 6px; }
.medit .hint { margin: 0; }
.msel { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 11.5px; color: var(--muted); }
.msel b { color: var(--text); }
.mbtns { display: flex; gap: 6px; flex-wrap: wrap; }
.mbtns .btn { flex: 1; }
.mbtns .btn:disabled { opacity: .4; cursor: not-allowed; }
.mset { flex: 1; min-width: 70px; background: var(--bg2); border: 1px solid var(--line2); border-radius: 8px; color: var(--text); padding: 5px 8px; font-family: var(--mono); font-size: 12px; }
.mknock { display: flex; gap: 7px; align-items: flex-start; color: var(--muted); font-size: 11.5px; cursor: pointer; }
.mknock input { accent-color: #ff2e4d; margin-top: 2px; }
.mtip { margin: 0; font-size: 11.5px; color: #c6d3e2; background: rgba(255, 192, 67, .06); border: 1px solid rgba(255, 192, 67, .22); border-radius: 10px; padding: 8px 10px; line-height: 1.5; }
.mfoot { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); font-size: 11.5px; }
.mfoot .btn:disabled { opacity: .4; cursor: not-allowed; }
.mlock { font-size: 11.5px; color: var(--accent); background: rgba(46, 230, 197, .08); border: 1px solid rgba(46, 230, 197, .3); border-radius: 10px; padding: 7px 10px; }

/* ================= DYNO ================= */
.dyno-body { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .dyno-body { grid-template-columns: minmax(0, 1fr); } }
#dynoCanvas { border-radius: 8px; background: #0a1017; cursor: crosshair; }
.dyno-side { display: flex; flex-direction: column; gap: 8px; font-size: 12px; }
.dyno-side .slider-lbl { margin: 4px 0 0; }
.dyno-side .seg button small { color: var(--dim); font-family: var(--mono); font-size: 9.5px; }
.dyno-side .seg button:disabled { opacity: .45; cursor: not-allowed; }
.dbtn { width: 100%; padding: 9px 12px; font-size: 13px; }
.dbtn:disabled { opacity: .45; cursor: not-allowed; }
.dstatus { font-size: 11.5px; color: var(--muted); min-height: 16px; }
.druns-h { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; margin-top: 4px; }
.druns { display: flex; flex-direction: column; gap: 5px; }
.drun { display: grid; grid-template-columns: 26px 1fr 26px; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 9px; background: var(--bg2); border: 1px solid var(--line); }
.drun.off { opacity: .45; }
.dvis { width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--line2); background: transparent; cursor: pointer; display: grid; place-items: center; padding: 0; }
.dvis i { width: 12px; height: 4px; border-radius: 2px; display: block; }
.dlabel { display: flex; flex-direction: column; min-width: 0; }
.dlabel b { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dlabel span { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }

/* ================= DIAGNOSTIC CHALLENGE ================= */
.ctl.faults.locked { position: relative; }
.ctl.faults.locked .fault-list, .ctl.faults.locked #clearDtc { filter: blur(4px); opacity: .35; pointer-events: none; user-select: none; }
.ctl.faults.locked::after {
  content: attr(data-lock-msg); position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); text-align: center;
  font-size: 12px; font-weight: 700; color: var(--accent); background: rgba(10, 16, 24, .85); border: 1px solid rgba(46, 230, 197, .35);
  padding: 8px 10px; border-radius: 10px;
}
.dtc.masked { background: rgba(125, 141, 163, .08); border-color: var(--line2); }
.dtc.masked b { color: var(--muted); }
.challenge { border-color: rgba(255, 192, 67, .5); box-shadow: 0 24px 60px rgba(0, 0, 0, .55), 0 0 30px rgba(255, 192, 67, .12); }
.challenge .coach-badge { color: var(--warn); }
.ch-complaint { font-size: 13.5px; line-height: 1.5; color: var(--text); font-style: italic; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.ch-complaint span { display: block; font-style: normal; font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 3px; }
.ch-live { font-family: var(--mono); font-size: 11.5px; color: var(--muted); margin: 8px 0; }
.ch-hint { font-size: 12.5px; line-height: 1.5; color: #d3dfec; background: rgba(255, 192, 67, .06); border: 1px solid rgba(255, 192, 67, .22); border-radius: 10px; padding: 8px 10px; margin-top: 6px; }
.ch-hint b { color: var(--warn); margin-right: 4px; }
.ch-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-top: 8px; max-height: 240px; overflow-y: auto; }
.ch-opt { text-align: left; font-size: 11.5px; font-weight: 600; padding: 7px 9px; border-radius: 8px; border: 1px solid var(--line2); background: var(--bg2); color: var(--text); cursor: pointer; line-height: 1.25; }
.ch-opt:hover { border-color: rgba(46, 230, 197, .6); }
.ch-opt.wrong { opacity: .45; text-decoration: line-through; border-color: rgba(255, 77, 94, .5); cursor: not-allowed; }
.ch-note { font-size: 11px; color: var(--muted); margin-top: 6px; }
.ch-result { font-size: 16px; font-weight: 800; margin-bottom: 6px; }
.ch-result.ok { color: var(--ok); }
.ch-result.bad { color: var(--bad); }
.challenge .coach-body p { margin: 4px 0 6px; }
@media (max-width: 860px) { .ch-opts { grid-template-columns: 1fr; } }
