:root {
  --bg: #0b0c0e;
  --panel: #131418;
  --panel-2: #1a1c21;
  --line: #262931;
  --text: #e9eaec;
  --muted: #8a8f99;
  --accent: #f5b301;
  --accent-ink: #1a1300;
  --c-gearguard: #f5b301;
  --c-incident: #ff5a4f;
  --c-saved: #4fb3ff;
  --c-drive: #6f7a8c;
  --c-other: #9c7cff;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
kbd {
  font: 600 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 2px 5px;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pad { padding: 16px; }
.spacer { flex: 1; }
code { font: 12px ui-monospace, Menlo, monospace; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: #22252c; border-color: #343844; }
.btn:focus-visible, .chip:focus-visible, .event:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: #ffc22b; }
.btn.ghost { background: transparent; }
.btn.lg { height: 42px; padding: 0 20px; font-size: 15px; }
.btn.icon { width: 34px; padding: 0; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn.play { width: 42px; height: 42px; border-radius: 50%; background: var(--text); color: #000; border-color: var(--text); }
.btn.play:hover { background: #fff; }
.btn.play svg { width: 22px; height: 22px; }
.btn.toggle { color: var(--muted); font-size: 13px; }
.btn.toggle.on { color: var(--accent); border-color: rgba(245, 179, 1, .45); background: rgba(245, 179, 1, .08); }
#btnLayout { color: var(--text); }
.select {
  height: 32px; background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 0 8px; font: inherit; cursor: pointer;
}

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  height: 52px; padding: 0 14px; flex: none;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: .2px; }
.brand svg { width: 22px; height: 22px; fill: var(--accent); }
.brand svg .lens, .empty-icon .lens { fill: var(--panel); }
.vehicle {
  display: flex; align-items: center; gap: 8px; margin-left: 8px;
  padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; color: var(--muted);
}
.vehicle b { color: var(--text); }

/* ---- layout ---- */
.app { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 300px; flex: none; display: flex; flex-direction: column;
  border-right: 1px solid var(--line); background: var(--panel); min-height: 0;
}
.stage { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #000; position: relative; }

/* ---- filters & list ---- */
.filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px; border-bottom: 1px solid var(--line); }
.filters:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 999px; background: transparent; cursor: pointer; font-size: 12.5px; color: var(--muted);
}
.chip span { font-size: 11px; opacity: .8; font-variant-numeric: tabular-nums; }
.chip:hover { color: var(--text); }
.chip.on { background: var(--text); color: #000; border-color: var(--text); }
.chip.zero { opacity: .55; }

.events { flex: 1; overflow-y: auto; padding: 4px 8px 16px; }
.day-group {
  position: sticky; top: 0; z-index: 1;
  padding: 12px 6px 6px; font-size: 11.5px; font-weight: 650; letter-spacing: .6px; text-transform: uppercase;
  color: var(--muted); background: var(--panel);
}
.event {
  display: flex; gap: 10px; width: 100%; padding: 7px; margin: 2px 0; text-align: left;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius); cursor: pointer;
}
.event:hover { background: var(--panel-2); }
.event.on { background: var(--panel-2); border-color: rgba(245, 179, 1, .5); }
.thumb {
  position: relative; width: 96px; height: 77px; flex: none; border-radius: 7px;
  background: #050506 center / cover no-repeat; overflow: hidden;
}
.thumb:not(.loaded)::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255,255,255,.05) 50%, transparent 70%) #0d0e11;
  background-size: 200% 100%; animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.dur {
  position: absolute; right: 4px; bottom: 4px; padding: 1px 5px; border-radius: 4px;
  font: 600 10.5px/1.4 ui-monospace, Menlo, monospace; background: rgba(0,0,0,.72);
}
.info { min-width: 0; display: flex; flex-direction: column; gap: 4px; padding-top: 1px; }
.row1 { display: flex; align-items: center; gap: 6px; font-weight: 600; font-variant-numeric: tabular-nums; }
.row3 { font-size: 11.5px; }
.star svg { width: 14px; height: 14px; color: var(--accent); display: block; }
.badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600;
  border: 1px solid currentColor; line-height: 1.5;
}
.cat-gearguard { color: var(--c-gearguard); }
.cat-incident { color: var(--c-incident); }
.cat-saved { color: var(--c-saved); }
.cat-drive { color: #a6aebb; }
.cat-other { color: var(--c-other); }
.scanning { display: flex; align-items: center; gap: 10px; padding: 16px 8px; color: var(--muted); }
.spin-sm { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }

/* ---- empty state ---- */
.empty { flex: 1; display: grid; place-items: center; padding: 24px; background: radial-gradient(ellipse at 50% 30%, #17181d 0%, #000 70%); }
.empty-card { max-width: 460px; text-align: center; }
.empty-card h1 { font-size: 22px; margin: 14px 0 8px; }
.empty-card p { color: #b9bdc6; margin: 0 0 18px; }
.empty-card .muted { color: var(--muted); margin-top: 16px; }
.empty-icon { width: 56px; height: 56px; fill: var(--accent); }

/* ---- viewer ---- */
.viewer-wrap { flex: 1; position: relative; min-height: 0; display: flex; }
.viewer {
  flex: 1; display: grid; gap: 3px; padding: 3px; min-height: 0;
  grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
}
.viewer[data-layout="focus"] { grid-template-columns: minmax(0, 1fr) minmax(150px, 21%); }
.viewer[data-layout="focus"] .tile { grid-column: 2; }
.viewer[data-layout="focus"] .tile.focused { grid-column: 1; grid-row: 1 / span var(--others); }

.tile {
  position: relative; overflow: hidden; background: #000; border-radius: 6px; cursor: zoom-in;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.viewer[data-layout="focus"] .tile:not(.focused) { cursor: pointer; }
.viewer[data-layout="focus"] .tile.focused { cursor: zoom-out; }
.tile.zoomed { cursor: grab; }
.tile.panning { cursor: grabbing; }
.layer { position: absolute; inset: 0; transform-origin: 0 0; will-change: transform; }
.cam-video {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain;
  visibility: hidden; pointer-events: none;
}
.cam-video.active { visibility: visible; }
.tile.mirrored .cam-video { transform: scaleX(-1); }
.tile-label {
  position: absolute; left: 8px; top: 8px; display: flex; align-items: center; gap: 6px;
  padding: 3px 9px 3px 4px; border-radius: 999px; background: rgba(0,0,0,.6); backdrop-filter: blur(6px);
  font-size: 12px; font-weight: 600; pointer-events: none;
}
.tile-label kbd { background: rgba(255,255,255,.12); border: 0; padding: 2px 5px; }
.tile.mirrored .tile-label::after { content: "mirrored"; font-weight: 500; color: var(--muted); }
.tile-reset {
  position: absolute; right: 8px; top: 8px; display: flex; align-items: center; gap: 4px;
  height: 26px; padding: 0 8px; border: 0; border-radius: 999px; background: rgba(0,0,0,.65); cursor: pointer; font-size: 12px;
}
.tile-reset svg { width: 14px; height: 14px; }
.tile-missing {
  position: absolute; inset: 0; display: none; place-items: center; color: var(--muted); font-size: 13px;
  background: repeating-linear-gradient(135deg, #0a0a0c 0 12px, #0e0f12 12px 24px);
}
.tile.missing .tile-missing { display: grid; }

.hud {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; z-index: 2;
}
.hud-clock {
  font: 650 22px/1.1 ui-monospace, "SF Mono", Menlo, monospace; font-variant-numeric: tabular-nums;
  padding: 5px 14px; border-radius: 10px; background: rgba(0,0,0,.62); backdrop-filter: blur(8px);
  text-shadow: 0 1px 2px #000;
}
.hud-sub {
  display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 3px 10px; border-radius: 999px;
  background: rgba(0,0,0,.55); backdrop-filter: blur(8px); pointer-events: auto;
}
.hud-sub:empty { display: none; }
.hud-sub a { display: inline-flex; align-items: center; gap: 3px; color: var(--text); text-decoration: none; opacity: .85; }
.hud-sub a:hover { opacity: 1; text-decoration: underline; }
.hud-sub svg { width: 13px; height: 13px; }
.viewer[data-layout="focus"] ~ .hud { left: calc((100% - max(150px, 21%)) / 2); }
.viewer[data-layout="car"] ~ .hud { top: auto; bottom: calc(33.3% + 8px); }

.spinner {
  position: absolute; left: 50%; top: 50%; width: 42px; height: 42px; margin: -21px;
  border: 3px solid rgba(255,255,255,.15); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite; pointer-events: none; z-index: 3;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- controls ---- */
.controls { flex: none; background: var(--panel); border-top: 1px solid var(--line); padding: 4px 14px 12px; }
.scrub { position: relative; height: 26px; cursor: pointer; touch-action: none; display: flex; align-items: center; padding-top: 4px; }
.scrub-track { position: relative; width: 100%; height: 5px; border-radius: 999px; background: #2a2d35; transition: height .1s; }
.scrub:hover .scrub-track, .scrub.active .scrub-track { height: 7px; }
.scrub-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: inherit; background: var(--accent); }
.scrub-marks i { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: #0b0c0e; border-radius: 1px; }
.scrub-handle {
  position: absolute; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 3px rgba(245,179,1,.35); opacity: 0; transition: opacity .1s;
}
.scrub:hover .scrub-handle, .scrub.active .scrub-handle { opacity: 1; }
.scrub-tip {
  position: absolute; bottom: 24px; transform: translateX(-50%); white-space: nowrap; pointer-events: none;
  padding: 3px 8px; border-radius: 6px; background: #000; border: 1px solid var(--line);
  font: 600 12px ui-monospace, Menlo, monospace;
}
.bar { display: flex; align-items: center; gap: 14px; margin-top: 4px; flex-wrap: wrap; }
.group { display: flex; align-items: center; gap: 6px; }
.time { font: 600 13px ui-monospace, Menlo, monospace; color: var(--muted); font-variant-numeric: tabular-nums; }

.day { margin-top: 10px; }
.day-head { display: flex; align-items: baseline; gap: 10px; font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.day-head .muted { font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day-track { position: relative; height: 38px; border-radius: 8px; background: #0d0e11; border: 1px solid var(--line); overflow: hidden; }
.day-ticks span {
  position: absolute; top: 0; bottom: 0; padding: 2px 0 0 4px; border-left: 1px solid #1f2229;
  font-size: 10px; color: #5d626c; white-space: nowrap;
}
.day-blocks { position: absolute; left: 0; right: 0; top: 15px; bottom: 4px; }
.blk.lane-drive { top: 45%; }
.blk.lane-clip { bottom: 45%; min-width: 6px; z-index: 1; }
.blk {
  position: absolute; top: 0; bottom: 0; min-width: 4px; border: 0; padding: 0; border-radius: 3px;
  background: currentColor; opacity: .55; cursor: pointer;
}
.blk:hover { opacity: .85; }
.blk.on { opacity: 1; box-shadow: 0 0 0 1.5px #fff; }
.blk.cat-drive { color: #4b5363; }
.day-playhead { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: #fff; pointer-events: none; box-shadow: 0 0 6px rgba(255,255,255,.6); }

/* ---- modal / overlays ---- */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(0,0,0,.6); backdrop-filter: blur(3px); padding: 16px; }
.modal-card { width: min(460px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px; }
.modal-card h2 { margin: 0 0 12px; font-size: 17px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0 0 14px; align-items: center; }
.keys dt { white-space: nowrap; }
.keys dd { margin: 0; color: #c3c7cf; }
.drop {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; pointer-events: none;
  background: rgba(245,179,1,.08); border: 3px dashed var(--accent); font-size: 20px; font-weight: 600;
}
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 40;
  padding: 10px 16px; border-radius: 10px; background: #f2f2f2; color: #111; font-weight: 500;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); max-width: calc(100vw - 32px);
}

/* ---- fullscreen ---- */
.stage:fullscreen .controls { padding-bottom: 14px; }

/* ---- narrow screens ---- */
@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar { width: auto; max-height: 34vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand span { display: none; }
  .bar { gap: 8px; }
  .btn.toggle { padding: 0 8px; }
  .viewer[data-layout="focus"] { grid-template-columns: 1fr; grid-auto-rows: minmax(0, 1fr); }
  .viewer[data-layout="focus"] .tile { display: none; }
  .viewer[data-layout="focus"] .tile.focused { display: block; grid-column: 1; grid-row: 1; }
}


/* ===================== v2: views, drawer, tools ===================== */
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.viewer-row { flex: 1; display: flex; min-height: 0; }
.viewer-col { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.tabs { display: flex; gap: 2px; margin-left: 12px; padding: 3px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.tab { height: 28px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; font-weight: 550; }
.tab:hover { color: var(--text); }
.tab.on { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.offline-pill { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: #3a2a00; color: var(--accent); }

.search { padding: 0 12px 10px; border-bottom: 1px solid var(--line); }
.search input {
  width: 100%; height: 32px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.badges { display: inline-flex; gap: 4px; margin-left: auto; }
.mini-badge { display: inline-flex; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); }
.mini-badge svg { width: 12px; height: 12px; }
.mini-badge.ok { color: #5fd38d; }
.row1 { width: 100%; }

.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.sm svg { width: 15px; height: 15px; }
.btn.on { color: var(--accent); border-color: rgba(245, 179, 1, .45); background: rgba(245, 179, 1, .08); }
#btnIn, #btnOut { font: 700 15px ui-monospace, Menlo, monospace; }
#btnExport span, #btnView span { font-size: 13px; }

/* menu */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; bottom: 40px; z-index: 30; width: 270px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 16px 40px rgba(0,0,0,.55);
  max-height: 70vh; overflow-y: auto;
}
.mh { padding: 8px 10px 4px; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.mi { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; border: 0; border-radius: 8px; background: transparent; text-align: left; cursor: pointer; font-size: 13px; }
.mi:hover { background: var(--panel-2); }
.mi i { width: 16px; height: 16px; display: grid; place-items: center; color: var(--accent); flex: none; }
.mi i svg { width: 15px; height: 15px; }
.mi small { margin-left: auto; color: var(--muted); font-size: 11px; }

/* drawer */
.drawer { width: 320px; flex: none; display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); min-height: 0; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--line); }
.drawer-body { flex: 1; overflow-y: auto; padding: 4px 16px 24px; }
.dsec { padding: 12px 0; border-bottom: 1px solid var(--line); }
.dsec:last-child { border-bottom: 0; }
.dsec h3 { margin: 0 0 8px; font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.dsec p { margin: 0 0 8px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tag { display: inline-flex; align-items: center; gap: 2px; padding: 2px 4px 2px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); font-size: 12px; }
.tag button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 4px; font-size: 14px; line-height: 1; }
.tag-input { flex: 1; min-width: 90px; height: 26px; border: 1px dashed var(--line); border-radius: 999px; background: transparent; color: var(--text); padding: 0 10px; font: inherit; font-size: 12px; }
.note, .bm input, .cap-row input {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 13px; resize: vertical;
}
.note:focus, .bm input:focus, .tag-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.bm-head { display: flex; align-items: center; justify-content: space-between; margin: 12px 0 6px; font-weight: 600; font-size: 13px; }
.bm-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.bm { display: flex; align-items: center; gap: 6px; }
.bm input { padding: 6px 8px; }
.bm-t { display: flex; flex-direction: column; align-items: flex-start; min-width: 64px; padding: 3px 6px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-2); cursor: pointer; font: 600 12px ui-monospace, Menlo, monospace; }
.bm-t small { font: 10px system-ui; color: var(--muted); }
.bm-x { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; padding: 0 4px; }
.bm-x:hover { color: var(--c-incident); }
.rel { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 8px; margin: 3px 0; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); cursor: pointer; text-align: left; font-variant-numeric: tabular-nums; }
.rel:hover { border-color: #3a3e48; }
.rel small { margin-left: auto; color: var(--muted); }
.mini-map { height: 170px; border-radius: 10px; overflow: hidden; margin-bottom: 8px; background: #0d0e11; }

/* scrubber extras */
.scrub-heat { position: absolute; left: 0; right: 0; top: 0; width: 100%; height: 8px; pointer-events: none; opacity: 0; transition: opacity .2s; }
.scrub-heat.on { opacity: 1; }
.scrub-range { position: absolute; top: -2px; bottom: -2px; background: rgba(79, 179, 255, .35); border-left: 2px solid #4fb3ff; border-right: 2px solid #4fb3ff; border-radius: 2px; }
.scrub-pins { position: absolute; left: 0; right: 0; top: 50%; height: 0; pointer-events: none; }
.pin {
  position: absolute; top: -9px; width: 10px; height: 10px; margin-left: -5px; padding: 0; border: 2px solid #fff;
  border-radius: 50%; background: #fff; cursor: pointer; pointer-events: auto; transform: translateY(-50%);
}
.pin-bm { background: #fff; border-color: #fff; border-radius: 2px 2px 50% 50%; }
.pin-clip { background: currentColor; border-color: #000; top: 9px; width: 11px; height: 11px; }
.pin:hover { transform: translateY(-50%) scale(1.35); }
.scrub-tip { display: flex; flex-direction: column; align-items: center; gap: 4px; bottom: 30px; padding: 4px; }
.tip-img:empty { display: none; }
.tip-img canvas { display: block; width: 200px; height: auto; border-radius: 4px; }

/* tiles: car layout, swap, dewarp, activity */
.car-center { display: none; }
.viewer[data-layout="car"] {
  grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr));
  grid-template-areas: ". front ." "left car right" ". rear .";
}
.viewer[data-layout="car"] .tile[data-cam="frontCenter"] { grid-area: front; }
.viewer[data-layout="car"] .tile[data-cam="rearCenter"] { grid-area: rear; }
.viewer[data-layout="car"] .tile[data-cam="sideLeft"] { grid-area: left; }
.viewer[data-layout="car"] .tile[data-cam="sideRight"] { grid-area: right; }
.viewer[data-layout="car"][data-swap="1"] .tile[data-cam="sideLeft"] { grid-area: right; }
.viewer[data-layout="car"][data-swap="1"] .tile[data-cam="sideRight"] { grid-area: left; }
.viewer[data-layout="car"] .car-center { grid-area: car; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: #3b404b; font-size: 11px; font-weight: 600; }
.viewer[data-layout="car"] .car-center svg { height: 55%; max-height: 120px; }
.viewer[data-layout="grid"][data-swap="1"] .tile[data-cam="sideLeft"] { order: 4; }
.viewer[data-layout="grid"][data-swap="1"] .tile[data-cam="sideRight"] { order: 3; }
.tile .dewarp-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: none; }
.tile.dewarped .dewarp-canvas { display: block; }
.tile.dewarped .layer { opacity: 0; }
.tile.dewarped { cursor: grab; }
.tile.dewarped.panning { cursor: grabbing; }
.tile.dewarped.mirrored .tile-label::after { content: "mirrored"; }
.tile.active-cam { box-shadow: inset 0 0 0 2px rgba(255, 140, 40, .85); }
.tile.active-cam .tile-label { background: rgba(140, 70, 0, .75); }

/* modal forms & progress */
.modal-card.wide { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; }
.form { display: flex; flex-direction: column; gap: 6px; }
.fl { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-top: 8px; }
.opts { display: flex; flex-direction: column; gap: 6px; }
.opts.row { flex-direction: row; flex-wrap: wrap; }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; background: var(--bg); }
.opt:has(input:checked) { border-color: rgba(245, 179, 1, .6); background: rgba(245, 179, 1, .06); }
.opt:has(input:disabled) { opacity: .5; cursor: not-allowed; }
.opt input { margin-top: 3px; accent-color: var(--accent); }
.opt span { display: flex; flex-direction: column; gap: 2px; }
.opt small { color: var(--muted); font-size: 12px; }
.opt.chk { align-items: center; padding: 6px 10px; }
.opt.chk input { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.progress { height: 8px; border-radius: 999px; background: #262931; overflow: hidden; margin: 14px 0 8px; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.files { margin: 6px 0 0; padding-left: 18px; font: 12px ui-monospace, Menlo, monospace; color: #c3c7cf; }
.toast { display: flex; align-items: center; gap: 12px; }
.toast-btn { border: 0; background: #111; color: #fff; border-radius: 7px; padding: 5px 10px; cursor: pointer; font-weight: 600; }

/* storage view */
.storage { flex: 1; overflow-y: auto; background: var(--bg); }
.st-wrap { max-width: 860px; margin: 0 auto; padding: 20px 16px 40px; display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.card p { margin: 0 0 8px; }
.card .big { font-size: 17px; }
.warn { color: var(--c-incident); font-weight: 600; }
.cap-bar { display: flex; height: 14px; border-radius: 999px; background: #22252c; overflow: hidden; }
.cap-bar .seg { display: block; height: 100%; background: currentColor; }
.cap-bar .seg.cat-drive { color: #5b6476; }
.cap-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 12px 0; font-size: 13px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: currentColor; margin-right: 6px; }
.dot.cat-drive { color: #5b6476; }
.dot.free { color: #22252c; box-shadow: inset 0 0 0 1px #3a3e48; }
.cap-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.cap-row label { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
.cap-row input { width: 90px; padding: 6px 8px; }
.bk-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; margin-bottom: 12px; }
.bk { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: var(--bg); }
.bk input { margin-top: 3px; accent-color: var(--accent); }
.bk span { display: flex; flex-direction: column; gap: 2px; font-weight: 600; }
.bk small { font-weight: 400; color: var(--muted); }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* map view */
.view-map { position: relative; }
.map { flex: 1; min-height: 0; background: #0d0e11; }
.map-note { position: absolute; left: 12px; bottom: 12px; z-index: 500; max-width: min(560px, calc(100% - 24px)); padding: 8px 12px; border-radius: 10px; background: rgba(19, 20, 24, .92); border: 1px solid var(--line); font-size: 12.5px; color: #c3c7cf; }
.map-pin-wrap { background: none; border: 0; }
.map-pin {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--c); border: 2px solid #fff; color: #000; font: 700 11px system-ui; box-shadow: 0 2px 8px rgba(0,0,0,.5);
}
.leaflet-container { font: inherit; background: #0d0e11; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); border: 1px solid var(--line); }
.leaflet-popup-content { margin: 10px 12px; }
.leaflet-container a { color: var(--accent); }
.map-pop { display: flex; flex-direction: column; gap: 4px; min-width: 200px; }
.map-pop button { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-2); color: var(--text); cursor: pointer; text-align: left; font-size: 12.5px; }
.map-pop button:hover { border-color: #3a3e48; }
.leaflet-bar a { background: var(--panel); color: var(--text); border-color: var(--line); }
.leaflet-bar a:hover { background: var(--panel-2); }
.leaflet-control-attribution { background: rgba(19, 20, 24, .8) !important; color: var(--muted); }

@media (max-width: 1100px) {
  .drawer { position: absolute; right: 0; top: 0; bottom: 0; z-index: 25; box-shadow: -10px 0 30px rgba(0,0,0,.5); }
  .view-viewer { position: relative; }
  #btnExport span, #btnView span { display: none; }
}
@media (max-width: 860px) {
  .tabs { margin-left: 4px; }
  .tab { padding: 0 8px; }
  #btnOpen { display: none; }
  .vehicle { display: none !important; }
}


/* ===================== v3: Pro, ads, legal, mobile ===================== */
.pro-btn { border-color: rgba(245, 179, 1, .55); color: var(--accent); font-weight: 650; }
.pro-btn.is-pro { background: rgba(245, 179, 1, .1); }
.pro-btn b { letter-spacing: .8px; }
.pro-tag { display: inline-block; margin-left: 4px; padding: 0 5px; border-radius: 4px; background: var(--accent); color: var(--accent-ink); font: 700 9.5px/1.6 system-ui; letter-spacing: .6px; vertical-align: middle; }
.pro-hero { text-align: center; margin-bottom: 8px; }
.pro-hero h2 { margin: 8px 0 4px; }
.pro-badge { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font: 800 12px system-ui; letter-spacing: 1px; }
.pro-reason { color: var(--accent); margin: 0; }
.pro-list { list-style: none; margin: 14px 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.pro-list li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 10px; border: 1px solid transparent; }
.pro-list li.hl { border-color: rgba(245, 179, 1, .5); background: rgba(245, 179, 1, .06); }
.pro-list svg { width: 18px; height: 18px; color: var(--accent); flex: none; margin-top: 1px; }
.pro-list span { display: flex; flex-direction: column; gap: 2px; }
.pro-list small { color: var(--muted); }
.pro-buy { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.pro-buy small { display: block; color: var(--muted); font-size: 12px; }
.pro-price { font-size: 26px; font-weight: 750; }
.pro-key { margin-top: 12px; }
.pro-key summary { cursor: pointer; color: #c3c7cf; font-size: 13px; }
.pro-key-row { display: flex; gap: 8px; margin: 10px 0 6px; }
.pro-key-row input { flex: 1; min-width: 0; height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: 13px ui-monospace, Menlo, monospace; }
.legal-links a, .side-foot a { color: var(--muted); }
.legal-links a:hover, .side-foot a:hover { color: var(--text); }

.ad-card { margin: 6px 0; padding: 10px; border-radius: var(--radius); border: 1px dashed var(--line); background: rgba(255,255,255,.015); }
.ad-label { display: block; font-size: 10px; font-weight: 650; text-transform: uppercase; letter-spacing: .7px; color: #5d626c; margin-bottom: 4px; }
.ad-house { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.ad-house small { color: var(--muted); font-size: 12px; }
.ad-house .btn { margin-top: 4px; }
.ad-drawer { margin: 0; }

.side-foot { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); font-size: 11.5px; color: #5d626c; }
.side-foot span:first-child { margin-right: auto; }

/* notched phones / native shells */
.topbar { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
html[data-platform="ios"] .topbar, html[data-platform="android"] .topbar { padding-top: env(safe-area-inset-top); height: calc(52px + env(safe-area-inset-top)); }
.controls { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
html.touch .btn { min-height: 36px; }
html.touch .btn.icon { min-width: 38px; }
html.touch .scrub { height: 34px; }
html.touch .scrub-handle { opacity: 1; }

.btn:disabled { opacity: .45; cursor: not-allowed; }

/* own licensing */
.pro-keybox { display: flex; align-items: center; gap: 10px; justify-content: space-between; margin: 12px 0; padding: 12px 14px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); }
.pro-keybox code { font: 600 15px ui-monospace, Menlo, monospace; letter-spacing: .4px; background: none; padding: 0; word-break: break-all; }
.pro-lost { margin-top: 10px; }
.pro-lost summary { cursor: pointer; color: var(--muted); font-size: 12.5px; }
.acts { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.acts li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.acts span { display: flex; flex-direction: column; }
.acts small { color: var(--muted); font-size: 11.5px; }
