/* Jev the Driver — motorsport data-acquisition rig.
   Phosphor amber on near-black, engineering-drawing hairlines, tabular numerals. */

:root {
  --bg:        #07090a;
  --panel:     #0b0e10;
  --panel-2:   #0e1214;
  --rule:      #1b2225;
  --rule-soft: #141a1c;
  --ink:       #e8e4d9;
  --dim:       #737d82;
  --dimmer:    #4a5358;
  --amber:     #ffb000;
  --amber-dim: #6b4a00;
  --cyan:      #3fd0d4;
  --red:       #ff3b30;
  --green:     #7dd87d;

  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --cond: 'Saira Condensed', 'Helvetica Neue', sans-serif;

  --head-h: 68px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;   /* digits must not jitter while live */
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, select { font-family: inherit; color: inherit; }

/* ─────────────────────────────── header ─────────────────────────────── */

.head {
  height: var(--head-h);
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 20px;
  border-bottom: 1px solid var(--rule);
  background: linear-gradient(180deg, #0d1113, #080a0b);
  position: relative;
  z-index: 5;
}

.brand { display: flex; align-items: baseline; gap: 7px; flex: 0 0 auto; }
.brand .mark  { font-family: var(--cond); font-weight: 700; font-size: 25px; letter-spacing: .12em; color: var(--amber); }
.brand .slash { color: var(--dimmer); font-size: 20px; }
.brand .mark2 { font-family: var(--cond); font-weight: 700; font-size: 25px; letter-spacing: .12em; }
.brand .tag {
  font-family: var(--cond); font-size: 11px; letter-spacing: .22em;
  text-transform: uppercase; color: var(--dim); margin-left: 12px;
  padding-left: 12px; border-left: 1px solid var(--rule);
}

.head-metrics { display: flex; gap: 30px; margin-left: auto; }
.hm { text-align: right; min-width: 92px; }
.hm-val {
  font-size: 27px; font-weight: 500; line-height: 1;
  transition: color .18s ease;
}
.hm-val.amber { color: var(--amber); }
.hm-val.red   { color: var(--red); }
.hm-lab {
  font-family: var(--cond); font-size: 10px; letter-spacing: .18em;
  text-transform: uppercase; color: var(--dim); margin-top: 5px;
}
.hm-val.flash { color: #fff; }

.head-actions { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.state {
  font-family: var(--cond); font-size: 11px; letter-spacing: .18em;
  text-transform: uppercase; color: var(--dim); min-width: 62px;
}
.led {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--dimmer); box-shadow: 0 0 0 0 rgba(125,216,125,.5);
}
.led.on   { background: var(--green); animation: pulse 1.8s ease-out infinite; }
.led.err  { background: var(--red); }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(125,216,125,.45); }
  70%  { box-shadow: 0 0 0 7px rgba(125,216,125,0); }
  100% { box-shadow: 0 0 0 0 rgba(125,216,125,0); }
}

/* ──────────────────────────────── layout ────────────────────────────── */

.rig {
  display: grid;
  grid-template-columns: 1fr 430px;
  height: calc(100% - var(--head-h));
}

.scene { position: relative; overflow: hidden; background: #07090a; }
.scene canvas { width: 100%; height: 100%; display: block; }

/* Subtle grain so the black reads as a screen, not a void. */
.scene-grain {
  position: absolute; inset: 0; pointer-events: none; opacity: .32;
  background-image: repeating-linear-gradient(0deg, rgba(255,255,255,.018) 0 1px, transparent 1px 3px);
}

.hud {
  position: absolute; padding: 12px 14px;
  background: rgba(7,9,10,.74);
  border: 1px solid var(--rule);
  backdrop-filter: blur(3px);
}
.hud-tl { top: 16px; left: 16px; }
.hud-tr { top: 16px; right: 16px; text-align: right; }
.hud-row { display: flex; align-items: baseline; gap: 7px; }
.hud-tr .hud-row { justify-content: flex-end; }
.hud-row b { font-size: 30px; font-weight: 500; color: var(--amber); line-height: 1.15; }
.hud-row.sm b { font-size: 15px; color: var(--ink); }
.hud-row i {
  font-family: var(--cond); font-style: normal; font-size: 10px;
  letter-spacing: .16em; text-transform: uppercase; color: var(--dim);
}

.legend {
  position: absolute; left: 16px; bottom: 16px;
  display: flex; gap: 16px; align-items: center;
  padding: 8px 12px; background: rgba(7,9,10,.74);
  border: 1px solid var(--rule);
  font-family: var(--cond); font-size: 11px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--dim);
}
.sw { display: inline-block; width: 12px; height: 2px; margin-right: 6px; vertical-align: middle; }
.sw.amber { background: var(--amber); }
.sw.cyan  { background: var(--cyan); }
.sw.dim   { background: var(--dimmer); }
.sw.red   { background: var(--red); }
.sw.dash  { background: repeating-linear-gradient(90deg, var(--red) 0 3px, transparent 3px 6px); }

.crash-flash {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at center, rgba(255,59,48,.30), rgba(255,59,48,.06) 60%, transparent 75%);
  box-shadow: inset 0 0 0 3px var(--red);
}
.crash-flash.fire { animation: crash .5s ease-out; }
@keyframes crash {
  0%   { opacity: 1; }
  100% { opacity: 0; }
}
.scene.shake canvas { animation: shake .34s ease-out; }
@keyframes shake {
  0%,100% { transform: translate(0,0); }
  25% { transform: translate(4px,-3px); }
  50% { transform: translate(-4px,2px); }
  75% { transform: translate(2px,3px); }
}

/* ───────────────────────────── telemetry ────────────────────────────── */

.tele {
  border-left: 1px solid var(--rule);
  background: var(--panel);
  overflow-y: auto;
  overflow-x: hidden;
}
.tele::-webkit-scrollbar { width: 9px; }
.tele::-webkit-scrollbar-track { background: var(--bg); }
.tele::-webkit-scrollbar-thumb { background: #1d2427; }
.tele::-webkit-scrollbar-thumb:hover { background: #2a3337; }

.pan {
  padding: 16px 18px 20px;
  border-bottom: 1px solid var(--rule);
  position: relative;
  animation: rise .5s ease-out backwards;
}
.pan:nth-child(1) { animation-delay: .02s; }
.pan:nth-child(2) { animation-delay: .06s; }
.pan:nth-child(3) { animation-delay: .10s; }
.pan:nth-child(4) { animation-delay: .14s; }
.pan:nth-child(5) { animation-delay: .18s; }
.pan:nth-child(6) { animation-delay: .22s; }
.pan:nth-child(7) { animation-delay: .26s; }
@keyframes rise { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: none; } }

.pan h2 {
  margin: 0 0 14px;
  font-family: var(--cond); font-weight: 500; font-size: 12px;
  letter-spacing: .26em; text-transform: uppercase; color: var(--ink);
  display: flex; align-items: center; gap: 10px;
}
.pan h2 .num { color: var(--amber-dim); font-size: 11px; letter-spacing: .1em; }
.pan h2::after { content: ''; flex: 1; height: 1px; background: var(--rule); }

.big-row { display: flex; align-items: flex-end; gap: 26px; margin-bottom: 14px; }
.big b { display: block; font-size: 44px; font-weight: 500; line-height: .95; color: var(--amber); }
.big.sub b { font-size: 25px; color: var(--ink); }
.big i {
  font-family: var(--cond); font-style: normal; font-size: 10px;
  letter-spacing: .18em; text-transform: uppercase; color: var(--dim);
  display: block; margin-top: 6px;
}

/* Dotted-leader stat rows — the engineering-drawing tell. */
.rows { display: flex; flex-direction: column; gap: 1px; }
.r { display: flex; align-items: baseline; gap: 8px; font-size: 12px; padding: 3px 0; }
.r span { color: var(--dim); white-space: nowrap; font-size: 11.5px; }
.r::after { content: ''; flex: 1; height: 0; border-bottom: 1px dotted var(--rule); margin-bottom: 3px; order: 1; }
.r b { order: 2; font-weight: 500; white-space: nowrap; }
.r.muted b, .r.muted span { color: var(--dimmer); }
.r b.red { color: var(--red); }
.r b.green { color: var(--green); }
.r b.cyan { color: var(--cyan); }

.split { display: flex; height: 9px; margin: 16px 0 8px; background: var(--rule-soft); overflow: hidden; }
.seg { height: 100%; transition: width .3s ease; }
.seg.compute { background: var(--amber); }
.seg.network { background: #2b3439; }
.split-key { display: flex; justify-content: space-between; font-family: var(--cond); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--dim); }
.split-key b { color: var(--ink); margin-left: 5px; font-family: var(--mono); letter-spacing: 0; }

.chart { width: 100%; display: block; margin-top: 14px; }
.cap {
  font-family: var(--cond); font-size: 10px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--dimmer); margin-top: 5px;
}
.note { font-size: 11.5px; line-height: 1.55; color: var(--dim); margin: -4px 0 12px; }

.meter { height: 5px; background: var(--rule-soft); margin-top: 14px; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--amber); transition: width .3s ease; }

.bars { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.bar-row { display: grid; grid-template-columns: 96px 1fr 34px; align-items: center; gap: 9px; font-size: 11px; }
.bar-row span { color: var(--dim); font-family: var(--cond); letter-spacing: .1em; text-transform: uppercase; font-size: 10.5px; }
.bar-track { height: 7px; background: var(--rule-soft); }
.bar-fill { height: 100%; background: var(--amber); transition: width .3s ease; }
.bar-row b { text-align: right; font-size: 11px; }

.vs {
  display: grid; grid-template-columns: 1fr auto 1fr;
  gap: 10px; align-items: center; margin-top: 16px;
  padding: 13px; border: 1px solid var(--rule); background: var(--panel-2);
}
.vs-col { text-align: center; }
.vs-col b { display: block; font-size: 21px; color: var(--amber); }
.vs-col.cyan b { color: var(--cyan); }
.vs-col i {
  font-family: var(--cond); font-style: normal; font-size: 10px;
  letter-spacing: .18em; text-transform: uppercase; color: var(--dim);
  display: block; margin-top: 4px;
}
.vs-mid { font-family: var(--cond); font-size: 11px; letter-spacing: .16em; color: var(--dimmer); text-transform: uppercase; }
.vs-cap {
  grid-column: 1 / -1; text-align: center; margin-top: 8px;
  font-family: var(--cond); font-size: 10px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--dimmer);
}

.lasterr { margin-top: 10px; font-size: 11px; color: var(--red); line-height: 1.5; word-break: break-word; }

/* ───────────────────────────── controls ─────────────────────────────── */

.btn {
  background: transparent; border: 1px solid var(--rule);
  color: var(--ink); padding: 9px 16px; cursor: pointer;
  font-family: var(--cond); font-size: 12px; letter-spacing: .16em;
  text-transform: uppercase; transition: all .16s ease;
}
.btn:hover:not(:disabled) { border-color: var(--amber); color: var(--amber); }
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn.primary { background: var(--amber); border-color: var(--amber); color: #0a0a0a; font-weight: 700; }
.btn.primary:hover:not(:disabled) { background: #ffc233; border-color: #ffc233; color: #0a0a0a; }
.btn.small { padding: 6px 12px; font-size: 11px; }
.btn.wide { width: 100%; margin-top: 12px; }
.btn.ghost { color: var(--dim); }

.check {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  font-family: var(--cond); font-size: 11.5px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--dim); margin-top: 14px;
}
.check.tiny { margin: 0; font-size: 10.5px; }
.check input { accent-color: var(--amber); }

.notice {
  border: 1px solid var(--amber-dim);
  border-left: 2px solid var(--amber);
  background: rgba(255, 176, 0, .05);
  padding: 12px 14px;
  margin-bottom: 18px;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--dim);
}
.notice b { color: var(--ink); font-weight: 500; }

/* ───────────────────────────── the gate ─────────────────────────────── */

.gate {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4,5,6,.93);
  backdrop-filter: blur(7px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px; overflow-y: auto;
}
.gate.hidden { display: none; }

.gate-card {
  /* margin:auto rather than align-items:center: centred when it fits, and
     top-aligned and scrollable when it does not, instead of clipped above the
     viewport where no scroll can reach. */
  margin: auto;
  width: 100%; max-width: 600px;
  background: var(--panel); border: 1px solid var(--rule);
  padding: 30px 32px 26px;
  animation: rise .45s ease-out;
  position: relative;
}
/* Corner ticks — drafting-table detail. */
.gate-card::before, .gate-card::after {
  content: ''; position: absolute; width: 13px; height: 13px; border: 1px solid var(--amber);
}
.gate-card::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; }
.gate-card::after  { bottom: -1px; right: -1px; border-left: 0; border-top: 0; }

.gate-head { margin-bottom: 18px; }
.gate-title { font-family: var(--cond); font-weight: 700; font-size: 32px; letter-spacing: .14em; }
.gate-title span { color: var(--amber-dim); margin: 0 4px; }
.gate-sub {
  font-family: var(--cond); font-size: 11px; letter-spacing: .24em;
  text-transform: uppercase; color: var(--amber); margin-top: 6px;
}
.gate-blurb { font-size: 12.5px; line-height: 1.65; color: var(--dim); margin: 0 0 22px; }
.gate-blurb strong { color: var(--ink); font-weight: 500; }

.field { margin-bottom: 15px; }
.field label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-family: var(--cond); font-size: 10.5px; letter-spacing: .2em;
  text-transform: uppercase; color: var(--dim); margin-bottom: 6px;
}
.field label .val { color: var(--amber); font-family: var(--mono); letter-spacing: 0; font-size: 11px; }
.field input[type=text], .field input[type=password], .field select {
  width: 100%; background: var(--bg); border: 1px solid var(--rule);
  padding: 9px 11px; font-size: 13px; outline: none; transition: border-color .16s ease;
}
.field input:focus, .field select:focus { border-color: var(--amber); }
.field input[type=range] { width: 100%; accent-color: var(--amber); }
.field-note { font-size: 10.5px; color: var(--dimmer); margin-top: 6px; line-height: 1.5; }

.gate-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.gate-actions { display: flex; gap: 10px; margin-top: 20px; }
.gate-actions .btn { flex: 1; }
.gate-status {
  margin-top: 13px; font-size: 11.5px; color: var(--dim);
  min-height: 17px; line-height: 1.5;
}
.gate-status.ok  { color: var(--green); }
.gate-status.err { color: var(--red); }

/* ───────────────────────────── responsive ───────────────────────────── */

@media (max-width: 1080px) {
  html, body { overflow: auto; }
  .rig { grid-template-columns: 1fr; height: auto; }
  .scene { height: 62vh; }
  .tele { border-left: 0; border-top: 1px solid var(--rule); overflow: visible; }
  .head { flex-wrap: wrap; height: auto; padding: 12px 16px; gap: 14px; }
  .head-metrics { gap: 20px; width: 100%; margin-left: 0; justify-content: space-between; }
  .hm { min-width: 0; text-align: left; }
  .hm-val { font-size: 21px; }
}
@media (max-height: 820px) {
  .gate { padding: 14px 24px; }
  .gate-card { padding: 20px 26px 18px; }
  .gate-head { margin-bottom: 10px; }
  .gate-title { font-size: 26px; }
  .gate-blurb { margin-bottom: 12px; line-height: 1.5; }
  .notice { padding: 9px 12px; margin-bottom: 12px; line-height: 1.5; }
  .field { margin-bottom: 9px; }
  .field label { margin-bottom: 4px; }
  .field input[type=text], .field input[type=password], .field select { padding: 7px 10px; }
  .check { margin-top: 6px; }
  .gate-actions { margin-top: 12px; }
  .gate-status { margin-top: 8px; }
}
@media (max-height: 640px) {
  /* The title and subtitle already say what this is; on the shortest laptop
     screens the whole form fitting matters more than the intro paragraph. */
  .gate-blurb { display: none; }
}
@media (max-width: 620px) {
  .gate-card { padding: 22px 18px; }
  .gate-grid { grid-template-columns: 1fr; }
  .brand .tag { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
