:root {
  --bg: rgba(14, 16, 20, 0.78);
  --bg2: rgba(22, 25, 31, 0.92);
  --line: rgba(255, 255, 255, 0.10);
  --fg: #e9ecf1;
  --muted: #98a0ad;
  --accent: #35d0ff;
  --warn: #ffb020;
  --bad: #ff4d4d;
  --ok: #3ddc84;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b0d10; color: var(--fg); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button { font: inherit; color: inherit; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; cursor: pointer; }
button:hover { background: rgba(255, 255, 255, 0.08); }
button.active { background: var(--accent); color: #05131a; border-color: transparent; font-weight: 600; }
.pill { border-radius: 999px; }
.pill.hot { border-color: var(--bad); color: var(--bad); }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
code { font-family: var(--mono); font-size: 12.5px; }
a { color: var(--accent); }

#top { position: fixed; top: 0; left: 0; right: 0; height: 52px; display: flex; align-items: center; justify-content: space-between; padding: 0 14px; background: linear-gradient(180deg, rgba(8, 10, 14, 0.85), rgba(8, 10, 14, 0.35)); backdrop-filter: blur(8px); z-index: 5; gap: 12px; }
#top .brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
#top .logo { width: 26px; height: 26px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff 0 18%, #0b0d10 19% 100%); box-shadow: 0 0 0 2px var(--fg); }
#top .name { font-weight: 700; letter-spacing: 0.04em; }
#top .sub { color: var(--muted); }
#top .mid { display: flex; align-items: center; gap: 12px; }
#top .right { display: flex; align-items: center; gap: 8px; }
#top .cams { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
#top .cams button { border: 0; border-radius: 0; padding: 5px 12px; }
#clock { font-family: var(--mono); font-size: 15px; }
#conn { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; padding: 2px 8px; border-radius: 999px; border: 1px solid; }
#conn.ok { color: var(--ok); border-color: var(--ok); }
#conn.bad { color: var(--warn); border-color: var(--warn); }

aside { position: fixed; top: 60px; background: var(--bg); backdrop-filter: blur(12px); border: 1px solid var(--line); border-radius: 14px; z-index: 4; overflow: auto; }
#fleet { left: 12px; width: 280px; max-height: calc(100% - 290px); padding: 12px; transform: translateX(-320px); transition: transform 0.25s; }
#fleet.open { transform: none; }
#fleet h3 { margin: 4px 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
#fleet .hint { color: var(--muted); font-size: 12px; }
.fleet-row { display: grid; grid-template-columns: 14px 1fr auto auto; gap: 8px; align-items: center; width: 100%; text-align: left; border: 0; border-radius: 8px; padding: 6px 8px; }
.fleet-row.selected { background: rgba(53, 208, 255, 0.18); }
.fleet-row .swatch { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.3); }
.fleet-row .plate { font-family: var(--mono); color: var(--muted); }
.fleet-row .status { font-size: 11px; color: var(--muted); min-width: 40px; text-align: right; }
.fleet-row .status.off { color: var(--warn); }
.fleet-row .status.crashed { color: var(--bad); }
em { font-style: normal; font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--warn); margin-left: 4px; }

#vehicle { right: 12px; width: 380px; max-height: calc(100% - 72px); padding: 14px 16px 18px; transform: translateX(420px); transition: transform 0.25s; }
#vehicle.open { transform: none; }
#close-vehicle, .close { position: absolute; top: 8px; right: 8px; border: 0; width: 28px; height: 28px; border-radius: 50%; padding: 0; color: var(--muted); }
.vhead { display: flex; gap: 12px; align-items: center; }
.vhead h2 { margin: 0; font-size: 22px; }
.vhead .tag { color: var(--muted); }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.35); flex: none; }
.proto { font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; background: var(--warn); color: #201400; padding: 2px 6px; border-radius: 4px; vertical-align: middle; }
.ident { margin: 12px 0; display: grid; gap: 4px; }
.ident > div { display: flex; gap: 10px; align-items: baseline; }
.ident .k { color: var(--muted); width: 44px; font-size: 12px; }
.ident code { cursor: pointer; }
.telemetry { display: flex; align-items: center; gap: 12px; padding: 8px 10px; background: rgba(0, 0, 0, 0.3); border-radius: 10px; }
#t-speed { font-family: var(--mono); font-size: 20px; }
#t-flags { flex: 1; color: var(--muted); }
#t-flags.aeb { color: var(--bad); font-weight: 700; }
#t-flags.crashed { color: var(--bad); }
.routebar { margin: 10px 0; }
.routebar label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.routebar input { display: none; }
#v-route { font-size: 12px; margin-top: 4px; }

.fgroup { margin: 12px 0 6px; }
.fgroup h4 { margin: 0 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); display: flex; justify-content: space-between; }
.lock { color: var(--warn); }
.feature { display: grid; grid-template-columns: 38px 1fr; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); cursor: pointer; align-items: start; }
.feature input { display: none; }
.switch { display: inline-block; width: 34px; height: 20px; border-radius: 999px; background: #3a4150; position: relative; transition: background 0.2s; margin-top: 2px; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
input:checked + .switch { background: var(--ok); }
input:checked + .switch::after { transform: translateX(14px); }
input:disabled + .switch { opacity: 0.45; }
.feature.off .fname { color: var(--muted); text-decoration: line-through; }
.fname { font-weight: 600; }
.fdesc { color: var(--muted); font-size: 12px; }
.fstatus { font-size: 11px; color: var(--ok); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 2px; }
.feature.off .fstatus { color: var(--bad); }
.feature.degraded .fstatus { color: var(--warn); text-transform: none; letter-spacing: 0; }
.actions { margin: 8px 0 14px; }
#vehicle h4 { margin: 14px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.inc-row { display: block; width: 100%; text-align: left; margin: 4px 0; font-size: 12.5px; }
.curl { background: rgba(0, 0, 0, 0.4); padding: 10px; border-radius: 8px; font-size: 11.5px; white-space: pre-wrap; cursor: pointer; margin: 0; }

#feed { position: fixed; left: 12px; bottom: 12px; width: 460px; max-height: 190px; overflow: auto; z-index: 3; font-size: 12.5px; padding: 8px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; backdrop-filter: blur(10px); }
.ev { display: flex; gap: 10px; padding: 2px 0; }
.ev .t { color: var(--muted); font-family: var(--mono); flex: none; }
.ev-aeb .txt { color: #ff9a9a; }
.ev-crash .txt { color: var(--bad); font-weight: 700; }
.ev-hazard .txt { color: var(--warn); }
.ev-config .txt { color: var(--accent); }
.ev-slide .txt, .ev-fault .txt, .ev-evade .txt { color: #ffd27a; }
.ev-tow .txt, .ev-respawn .txt, .ev-recover .txt { color: var(--muted); }

#chip { position: fixed; top: 60px; right: 12px; display: none; align-items: center; gap: 8px; padding: 8px 10px; background: var(--bg); border: 1px solid var(--accent); border-radius: 999px; backdrop-filter: blur(10px); z-index: 4; font-weight: 600; }
#chip.show { display: flex; }
#chip .swatch { width: 16px; height: 16px; border-width: 1px; }
#chip button { padding: 3px 9px; font-size: 12px; font-weight: 500; }
#chip button.active { background: var(--accent); color: #05131a; }
.engbar .muted { font-weight: 400; font-size: 12px; }

#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 8; }
.toast { background: var(--bg2); border: 1px solid var(--line); padding: 10px 14px; border-radius: 10px; opacity: 0; transform: translateY(8px); transition: all 0.3s; max-width: 380px; }
.toast.show { opacity: 1; transform: none; }
.toast.hot { border-color: var(--bad); cursor: pointer; }

.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); display: none; align-items: center; justify-content: center; z-index: 9; }
.modal.open { display: flex; }
.modal-box { position: relative; width: min(760px, 92vw); max-height: 86vh; overflow: auto; background: var(--bg2); border: 1px solid var(--line); border-radius: 16px; padding: 20px 24px; }
.modal-box .close { position: sticky; float: right; top: 0; margin: -8px -12px 0 8px; background: var(--bg2); z-index: 2; width: 36px; height: 36px; font-size: 18px; }
.modal-box h3 { padding-right: 40px; }
.toast .dismiss { margin-left: 10px; color: var(--muted); font-weight: 700; cursor: pointer; }
.modal-box h3 { margin: 0 0 10px; }
.inc-meta { color: var(--muted); margin-bottom: 8px; }
.inc-narrative { margin: 6px 0; }
.inc-table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 13px; }
.inc-table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.inc-table td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.inc-flags h4 { margin: 12px 0 6px; }
.flag { display: flex; gap: 10px; align-items: center; padding: 8px 10px; background: rgba(61, 220, 132, 0.1); border: 1px solid rgba(61, 220, 132, 0.35); border-radius: 10px; margin: 6px 0; }
.flag .ftitle { font-weight: 700; min-width: 120px; }
.flag code { flex: 1; color: var(--ok); }
.flag .copy { padding: 3px 8px; }

body.dusk #top { background: linear-gradient(180deg, rgba(20, 12, 22, 0.85), rgba(20, 12, 22, 0.3)); }

@media (max-width: 900px) {
  #top .sub { display: none; }
}

/* Phones: the top bar wraps into two rows, the fleet list is a sheet from the
   left, the vehicle panel a bottom sheet, and the feed makes room for it. */
@media (max-width: 760px) {
  html, body { height: 100dvh; }
  #top { height: auto; flex-wrap: wrap; padding: 6px 8px 8px; gap: 6px 8px; row-gap: 6px; }
  #top .brand { gap: 8px; }
  #top .brand .name { font-size: 13px; }
  #top .mid { margin-left: auto; gap: 8px; }
  #top .mid #conn { display: inline-block; }
  #top .right { flex-basis: 100%; justify-content: space-between; gap: 6px; }
  #top button { padding: 4px 9px; font-size: 12px; }
  #top .cams button { padding: 4px 9px; }
  #world-id { display: none; }
  #clock { font-size: 13px; }
  aside { top: 104px; }
  #fleet { left: 0; width: min(320px, 86vw); max-height: calc(100dvh - 210px); border-radius: 0 14px 14px 0; transform: translateX(-100%); }
  #vehicle { left: 0; right: 0; top: auto; bottom: 0; width: 100%; max-height: 56dvh; padding: 12px 14px 20px; border-radius: 16px 16px 0 0; transform: translateY(110%); }
  #vehicle.open { transform: none; }
  #vehicle::before { content: ''; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 10px; }
  .vhead h2 { font-size: 19px; }
  #feed { left: 8px; right: 8px; width: auto; bottom: 8px; max-height: 92px; font-size: 11.5px; padding: 6px 8px; }
  body.panel-open #feed { display: none; }
  #chip { position: fixed; top: 60px; right: 12px; display: none; align-items: center; gap: 8px; padding: 8px 10px; background: var(--bg); border: 1px solid var(--accent); border-radius: 999px; backdrop-filter: blur(10px); z-index: 4; font-weight: 600; }
#chip.show { display: flex; }
#chip .swatch { width: 16px; height: 16px; border-width: 1px; }
#chip button { padding: 3px 9px; font-size: 12px; font-weight: 500; }
#chip button.active { background: var(--accent); color: #05131a; }
.engbar .muted { font-weight: 400; font-size: 12px; }

#toasts { left: 8px; right: 8px; bottom: 8px; }
  .toast { max-width: none; }
  .modal { align-items: flex-end; }
  .modal-box { width: 100vw; max-height: 88dvh; padding: 14px 16px 24px; border-radius: 16px 16px 0 0; }
  .modal-box::before { content: ''; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 10px; }
  .inc-table { font-size: 12px; }
  .inc-table th, .inc-table td { padding: 5px 4px; }
  .flag { flex-wrap: wrap; }
  .flag code { flex-basis: 100%; word-break: break-all; }
}
