/* PURPLE concept lab — the engine dashboard (concept/lab/engine-panel.js, docs/concept/DASHBOARD.md). On top of lab/lab.css and
   concept-lab.css (tokens, type roles, buttons, badges, deltas, the leaderboard rows). A full view under the 40 px header:
   tabs + Start/Stop · stage timings strip · controls | 3D car + chart | leaderboard + car / iterations. Dark only. */
.top .engine-btn { flex: none; border-color: var(--purple); color: var(--purple); }
.top .engine-btn.on { background: var(--purple-dim); color: var(--text); }
.engine { position: fixed; top: 40px; left: 0; right: 0; bottom: 0; z-index: 15; display: flex; flex-direction: column; background: var(--bg); }
.engine[hidden] { display: none; }
body.engine-open .clab { visibility: hidden; }

.eng-head { flex: none; display: flex; align-items: center; gap: 10px; padding: 8px 12px 6px; }
.eng-head .spacer { flex: 1 1 0; }
.eng-title { color: var(--purple); letter-spacing: .14em; }
.eng-tabs { display: flex; gap: 4px; }
.eng-tab { padding: 6px 12px; border: 1px solid var(--line); border-radius: var(--r); background: #141418; color: var(--muted); font: 600 12px/1.2 var(--sans); }
.eng-tab:hover { color: var(--text); }
.eng-tab.on { color: var(--text); border-color: var(--purple); background: var(--purple-dim); }
#tab-auto.on { border-color: var(--mubit); background: rgba(255, 69, 0, .14); }
.eng-go { min-width: 220px; padding: 9px 18px; border: 1px solid var(--purple); border-radius: var(--r); background: var(--purple); color: #0a0a0c; font: 700 14px/1.1 var(--sans); letter-spacing: .04em; text-transform: uppercase; }
.eng-go:hover:not(:disabled) { filter: brightness(1.12); }
.eng-go.stop { background: var(--red); border-color: var(--red); color: #fff; }
.eng-go[hidden] { display: none; }

.eng-stripw { flex: none; padding: 0 12px 8px; }
.eng-strip { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 6px; }
.eng-chip { display: flex; flex-direction: column; gap: 1px; padding: 5px 8px; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); min-width: 0; cursor: help; }
.eng-chip.off { opacity: .55; }
.eng-chip .en { font: 600 10px/1.2 var(--sans); letter-spacing: .05em; text-transform: uppercase; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eng-chip .ev { font: 600 16px/1.15 var(--mono); color: var(--text); white-space: nowrap; }
.eng-chip .ev i { font: 500 10px var(--sans); color: var(--muted); font-style: normal; }
.eng-chip .ep { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eng-how { margin-top: 5px; font-size: 11px; line-height: 1.35; }
.eng-how b { color: var(--text); font-weight: 600; }

.eng-body { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(300px, 25fr) minmax(0, 46fr) minmax(280px, 29fr); gap: 12px; padding: 0 12px 6px; }
.eng-body[hidden] { display: none; }
.eng-left, .eng-right, .eng-mid { display: flex; flex-direction: column; gap: 10px; min-height: 0; min-width: 0; }
.eng-left { overflow: hidden auto; scrollbar-width: thin; }
.eng-lform, .eng-llive { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.eng-lform:has(.garage) { flex: 1 1 auto; }
.eng-card { display: flex; flex-direction: column; min-height: 0; }
.eng-card .pad { padding: 6px 12px; }
.eng-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 5px; padding: 8px 12px; }
.ef { display: grid; grid-template-columns: 118px minmax(0, 1fr); align-items: center; gap: 8px; font: 500 11px/1.2 var(--sans); color: var(--muted); }
.ef.chk { display: flex; align-items: center; gap: 6px; color: var(--text); }
.ef-h { margin-top: 4px; color: var(--muted); }
.ef .inl { display: flex; align-items: center; gap: 4px; }
.eng-form input, .eng-form select, .gtable input[type=number], .gmat { background: #1a1a20; border: 1px solid var(--line); border-radius: var(--r); padding: 3px 6px; font: 500 12px/1.2 var(--mono); color: var(--text); min-width: 0; }
.eng-form input[type=number] { width: 96px; }
.eng-form input.w-wide { width: 100%; }
.eng-form input.w-lap { width: 84px; }
.eng-form select { width: 100%; }
.eng-form input[type=checkbox] { width: auto; accent-color: var(--purple); }
.eng-trained { display: flex; flex-direction: column; gap: 5px; padding: 6px 8px; border: 1px solid var(--mubit); border-radius: var(--r); background: rgba(255, 69, 0, .06); font-size: 11px; font-family: var(--sans); }
.eng-budget { padding: 4px 12px 6px; font-size: 11px; font-family: var(--sans); }
.eng-budget b { color: var(--text); }
.mubit-c { color: var(--mubit) !important; }
.eng-kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 10px; padding: 8px 12px 10px; }
.ekpi { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ekv { font: 600 19px/1.1 var(--mono); white-space: nowrap; }
.ekv.purple, .big.purple { color: var(--purple); }
.ekv.faster { color: var(--purple); } .ekv.slower { color: var(--red); } .ekv.flat { color: var(--muted); }

.eng-hero { position: relative; flex: 1 1 auto; min-height: 240px; overflow: hidden; background: radial-gradient(120% 90% at 50% 40%, #16161c 0%, var(--panel) 60%); }
.eng-view { position: absolute; inset: 0; }
.eng-view canvas { display: block; width: 100%; height: 100%; }
.eng-hero-tl { position: absolute; top: 10px; left: 12px; right: 42%; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; pointer-events: none; }
.eng-hero-tl > * { pointer-events: auto; }
.eng-vm { display: inline-flex; gap: 4px; align-items: center; margin-left: 6px; }
.eng-vm .btn { white-space: nowrap; }
.eng-hero-bl { position: absolute; left: 12px; right: 12px; bottom: 10px; pointer-events: none; }
.eng-hero-bl > * { pointer-events: auto; }
.fcard, .gcard { display: inline-flex; flex-direction: column; gap: 3px; max-width: 100%; padding: 8px 11px; background: rgba(10, 10, 12, .82); border: 1px solid var(--line); border-radius: var(--r); }
.fcard { border-color: var(--purple); }
.fcard .fbig { display: flex; align-items: baseline; gap: 6px; }
.fcard .pm { font: 600 13px var(--mono); color: var(--text); }
.gcard .kpis { gap: 16px; }
.gcard .kpi .big { font-size: 22px; }
.gverd { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.eng-midb { flex: 0 0 210px; display: flex; flex-direction: column; overflow: hidden; }
.segs { flex: 1 1 auto; min-height: 0; overflow: hidden auto; padding: 4px 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: 16px; column-gap: 14px; scrollbar-width: thin; }
.sg { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(40px, 1fr) 50px; gap: 6px; align-items: center; padding: 0 12px; font-size: 10.5px; cursor: help; }
.sg .sgn { font: 500 10.5px/1 var(--sans); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sg.c .sgn { color: var(--text); }
.sg .sgb { position: relative; height: 7px; background: #1a1a20; border-radius: 2px; }
.sg .sgb::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--line); }
.sg .sgb i { position: absolute; top: 0; bottom: 0; border-radius: 2px; }
.sg .sgb i.f { background: var(--purple); } .sg .sgb i.sl { background: var(--red); }
.sg .sgv { text-align: right; font-size: 10.5px; }

.eng-board { flex: 1 1 55%; min-height: 180px; }
.eng-right .carp, .eng-right .feedp { flex: 1 1 45%; min-height: 150px; overflow: hidden; }
.chl { flex: 1 1 auto; overflow: hidden auto; padding: 4px 0; scrollbar-width: thin; }
.chr { display: flex; justify-content: space-between; gap: 8px; padding: 1px 12px; font-size: 11px; }
.chr .num { white-space: nowrap; }
.carp .ok, .carp .warn { padding: 5px 12px 7px; font-size: 10.5px; border-top: 1px solid var(--line); }
.ok { color: var(--green); }
.eng-feed { flex: 1 1 auto; overflow: hidden auto; scrollbar-width: thin; }
.efr { padding: 5px 12px; border-bottom: 1px solid var(--line); border-left: 2px solid transparent; font-size: 11px; }
.efr.kept { border-left-color: var(--purple); }
.efr.rej { opacity: .85; }
.efr1 { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.efr1 .rid { font-size: 9.5px; color: var(--muted); max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.efr2 { margin-top: 2px; font-family: var(--sans); line-height: 1.35; }
.efr2 .hypq { color: var(--muted); font-style: italic; }

/* garage */
.garage { flex: 1 1 auto; }
.gtools { display: flex; gap: 6px; padding: 6px 12px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.mubit-b { border-color: var(--mubit) !important; color: var(--mubit); }
.gtable { flex: 1 1 auto; min-height: 0; overflow: hidden auto; padding: 2px 0 6px; scrollbar-width: thin; }
.gp { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 12px 2px; font: 600 10.5px/1.2 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.gmat { max-width: 58%; font: 500 10.5px/1.2 var(--sans) !important; text-transform: none; letter-spacing: 0; padding: 1px 4px !important; }
.gr { display: grid; grid-template-columns: 92px minmax(50px, 1fr) 64px 26px 66px; gap: 5px; align-items: center; padding: 1px 12px; font-size: 11px; }
.gr .gn { font: 500 11px/1.2 var(--sans); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gr.ch .gn { color: var(--amber); }
.gr.out .gn, .gr.out .gnum { color: var(--red); }
.gr .gnum { width: 100%; padding: 1px 4px !important; font-size: 11px !important; }
.gr .gu, .gr .glim { font-size: 9.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gr .glim { text-align: right; }
.gr input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 3px; margin: 0; cursor: pointer;
  background: linear-gradient(to right, transparent calc(var(--bp) - 1px), rgba(232, 232, 236, .9) calc(var(--bp) - 1px) calc(var(--bp) + 1px), transparent calc(var(--bp) + 1px)),
              linear-gradient(to right, #24242a 0 var(--lo), rgba(178, 108, 255, .5) var(--lo) var(--hi), #24242a var(--hi) 100%); }
.gr input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 11px; height: 11px; border-radius: 50%; background: var(--text); border: 2px solid var(--purple); }
.gr input[type=range]::-moz-range-thumb { width: 9px; height: 9px; border-radius: 50%; background: var(--text); border: 2px solid var(--purple); }
.gr.out input[type=range]::-webkit-slider-thumb { border-color: var(--red); }

/* car sheet */
.eng-sheet { flex: 1 1 auto; min-height: 0; overflow: auto; display: grid; grid-template-columns: minmax(0, 52fr) minmax(0, 48fr); gap: 12px; padding: 0 12px 8px; align-items: start; }
.eng-sheet[hidden] { display: none; }
.stw { overflow: auto; }
.stab { width: 100%; border-collapse: collapse; font-size: 11px; table-layout: fixed; }
.stab td { overflow-wrap: anywhere; }
.stab th { position: sticky; top: 0; background: var(--panel); text-align: left; font: 600 10px/1.2 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 5px 8px; border-bottom: 1px solid var(--line); }
.stab td { padding: 3px 8px; border-bottom: 1px solid #1c1c22; vertical-align: top; }
.stab td.num { white-space: nowrap; }
.stab td.src { font-size: 10px; line-height: 1.3; }
.stab tr.sgrp td { padding-top: 8px; font: 600 10.5px/1.2 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--purple); border-bottom: 1px solid var(--line); }
.stab.cpl td { font-size: 10.5px; }
.stab.cpl td .src, .stab.cpl td.src { font-size: 10px; }

.eng-foot { flex: none; padding: 4px 12px 6px; border-top: 1px solid var(--line); font-size: 10px; line-height: 1.35; }
.one { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 1200px) {
  .engine { overflow: auto; }
  .eng-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .eng-body { grid-template-columns: minmax(0, 1fr); }
  .eng-hero { min-height: 320px; }
  .eng-sheet { grid-template-columns: minmax(0, 1fr); }
  .eng-go { min-width: 0; }
}
.stab.cs td.num { white-space: normal; }
