:root {
  --bg:       #08080f;
  --surface:  #111118;
  --border:   #1c1c28;
  --text:     #d8d8e8;
  --muted:    #50506a;
  --track:    #1a1a26;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  min-height: 100dvh;
}

/* ── Header ─────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.brand {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--muted);
  white-space: nowrap;
}

/* ── Tab navigation ──────────────────────────────────────────────── */
.tab-nav {
  display: flex;
  gap: 4px;
  flex: 1;
  justify-content: center;
}

.tab {
  padding: 5px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-decoration: none;
  color: var(--muted);
  border: 1px solid transparent;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.tab:hover { color: var(--text); background: var(--surface); }
.tab.active { color: var(--text); background: var(--surface); border-color: var(--border); }

/* ── WS status ───────────────────────────────────────────────────── */
.ws-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 3px 8px;
  border-radius: 8px;
  white-space: nowrap;
}
.ws-badge.connecting { background: #1e1400; color: #c87800; }
.ws-badge.connected  { background: #001e0a; color: #22c55e; }
.ws-badge.error      { background: #1e0006; color: #ef4444; }

/* ── Page layout ─────────────────────────────────────────────────── */
main {
  padding: 16px;
  max-width: 1024px;
  margin: 0 auto;
}

[hidden] { display: none !important; }
.page { display: flex; flex-direction: column; gap: 12px; }

/* ── Gauges ──────────────────────────────────────────────────────── */
.gauges {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.gauge-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 12px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.gauge-wrap {
  position: relative;
  width: 120px;
  height: 120px;
}
.gauge-wrap svg { display: block; width: 100%; height: 100%; }

.gauge-track {
  fill: none;
  stroke: var(--track);
  stroke-width: 10;
  stroke-linecap: round;
}

.gauge-fill {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dasharray 0.18s ease;
}

.gauge-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.gauge-val  { font-size: 26px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.gauge-unit { font-size: 10px; color: var(--muted); text-transform: lowercase; margin-top: 3px; }
.gauge-label { margin-top: 8px; font-size: 10px; font-weight: 700; letter-spacing: 0.12em; color: var(--muted); }

/* ── Indicators row ──────────────────────────────────────────────── */
.indicators {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
}

.turn {
  padding: 8px 20px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
  transition: background 0.08s, border-color 0.08s, color 0.08s, box-shadow 0.08s;
}
.turn.active {
  background: #1a1000;
  border-color: #f59e0b;
  color: #f59e0b;
  box-shadow: 0 0 14px rgba(245,158,11,0.25);
}

.gear-badge {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0;
  color: var(--muted);
  transition: color 0.15s, border-color 0.15s;
}
.gear-badge.reverse { color: #f87171; border-color: #f87171; }
.gear-badge.drive   { color: #4ade80; border-color: #4ade80; }

/* ── Lower panels ────────────────────────────────────────────────── */
.panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  overflow: hidden;
}

.panel-header {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-hint { font-size: 10px; font-weight: 400; color: var(--muted); letter-spacing: 0; }
.fps        { font-size: 10px; font-weight: 400; color: var(--muted); letter-spacing: 0; }
.now-playing { font-size: 11px; font-weight: 600; color: #818cf8; letter-spacing: 0; }

/* DTC */
#dtc-list { list-style: none; }
.dtc-empty { font-size: 12px; color: var(--muted); }

.dtc-entry {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.dtc-entry:last-child { border-bottom: none; }
.dtc-code { font-family: ui-monospace, monospace; font-size: 12px; font-weight: 700; color: #fb923c; }
.dtc-desc { font-size: 11px; color: var(--text); line-height: 1.4; }

/* Frame inspector */
#frame-log { font-family: ui-monospace, monospace; font-size: 11px; overflow-y: auto; max-height: 200px; }
.frame-row { display: flex; align-items: center; gap: 10px; padding: 3px 0; border-bottom: 1px solid var(--border); }
.frame-row:last-child { border-bottom: none; }
.frame-ts   { color: var(--muted); min-width: 36px; font-size: 10px; }
.frame-id   { color: #38bdf8; font-weight: 600; min-width: 44px; }
.frame-data { color: var(--muted); letter-spacing: 0.03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Media page ──────────────────────────────────────────────────── */
.media-section { margin-bottom: 0; }

/* Audio sources */
.audio-sources {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.audio-src {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: default;
  transition: border-color 0.15s, background 0.15s;
}

.audio-src.active {
  border-color: #818cf8;
  background: #10102a;
}

.audio-icon-box {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--muted);
  transition: color 0.15s, border-color 0.15s;
}

.audio-src.active .audio-icon-box {
  border-color: #818cf8;
  color: #818cf8;
}

.audio-name {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  transition: color 0.15s;
}
.audio-src.active .audio-name { color: var(--text); }

/* Camera feeds */
.cameras {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.cam-card {
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
  transition: border-color 0.15s;
}

.cam-card.active { border-color: #22c55e; }

.cam-feed {
  aspect-ratio: 16 / 9;
  background: #040408;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  position: relative;
}

.cam-label-tag {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--muted);
  background: rgba(0,0,0,0.6);
  padding: 2px 6px;
  border-radius: 4px;
}

.cam-state {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--muted);
  transition: color 0.15s;
}

.cam-card.active .cam-state {
  color: #22c55e;
}

.cam-card.active .cam-state::before {
  content: "● ";
}

.cam-trigger {
  padding: 5px 10px;
  font-size: 10px;
  color: var(--muted);
  background: var(--surface);
  text-align: center;
}

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 680px) {
  .gauges { grid-template-columns: repeat(2, 1fr); }
  .panels { grid-template-columns: 1fr; }
  .audio-sources { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 420px) {
  .gauge-wrap { width: 96px; height: 96px; }
  .gauge-val  { font-size: 20px; }
  header { flex-wrap: wrap; }
  .tab-nav { order: 3; width: 100%; justify-content: flex-start; }
}
