:root {
  --bg: #f4f5f7; --panel: #ffffff; --text: #14171c; --muted: #5f6b7a; --line: #e2e5ea;
  --accent: #f5b82e; --rec: #e5484d; --ok: #2bb673; --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e1116; --panel: #171b22; --text: #e8ebf0; --muted: #8a94a6; --line: #262c36; }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: inherit; }
h1 { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 0.85rem; }

/* top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 1000;
}
.brand { display: flex; gap: 8px; align-items: center; font-weight: 700; text-decoration: none; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--rec); box-shadow: 0 0 0 3px rgba(229,72,77,.2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.btn-rec { background: var(--rec); border-color: var(--rec); color: #fff; }
.btn-ghost { background: transparent; }
.btn.danger { color: var(--rec); }
.btn:disabled { opacity: .5; }

.wrap { max-width: 760px; margin: 0 auto; padding: 20px 16px 40px; }
.wrap.wide { max-width: 1200px; }

/* list */
.cards { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 10px; }
.card {
  display: block; padding: 14px 16px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); text-decoration: none;
}
.card:hover { border-color: var(--accent); }
.card-title { font-weight: 650; }
.card-meta { color: var(--muted); font-size: .9rem; }
.stats { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 8px; color: var(--muted); font-size: .9rem; }
.stats b { color: var(--text); }
.empty { text-align: center; padding: 48px 16px; background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); margin-top: 16px; }
.empty p { margin: 0 0 8px; }
.empty .btn { margin-top: 12px; }

/* ---------- recording page ---------- */
body.rec-page { background: #000; overflow: hidden; }
.cam { position: fixed; inset: 0; background: #000; color: #fff; }
.cam video { width: 100%; height: 100%; object-fit: cover; }
.hud { position: absolute; left: 0; right: 0; display: flex; align-items: center; padding: 14px; gap: 10px; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud-top { top: env(safe-area-inset-top); }
.hud-speed { bottom: calc(120px + env(safe-area-inset-bottom)); flex-direction: column; align-items: flex-start; }
.hud-bottom { bottom: env(safe-area-inset-bottom); justify-content: space-between; padding: 18px 28px 26px; }
.hud-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: rgba(0,0,0,.5); color: #fff; font-size: 18px; text-decoration: none; backdrop-filter: blur(6px);
}
.hud-btn.ghost { font-size: 13px; font-variant-numeric: tabular-nums; }
.hud-btn[hidden] { display: none; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 999px;
  background: rgba(0,0,0,.55); font-size: 13px; font-weight: 600; backdrop-filter: blur(6px);
}
.pill[hidden] { display: none; }
.led { width: 8px; height: 8px; border-radius: 50%; background: #8a94a6; }
.pill.ok .led { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.pill.weak .led { background: var(--accent); }
.led.red { background: var(--rec); animation: blink 1s infinite; }
.rec-timer { margin-left: auto; font-variant-numeric: tabular-nums; }
@keyframes blink { 50% { opacity: .2; } }

.speed { font-size: 64px; font-weight: 800; line-height: 1; text-shadow: 0 2px 12px rgba(0,0,0,.6); font-variant-numeric: tabular-nums; }
.speed small { font-size: 18px; font-weight: 600; margin-left: 6px; opacity: .85; }
.coords { font: 13px ui-monospace, monospace; background: rgba(0,0,0,.5); padding: 4px 8px; border-radius: 6px; margin-top: 6px; }

.shutter {
  width: 78px; height: 78px; border-radius: 50%; border: 4px solid #fff; background: transparent;
  display: grid; place-items: center; cursor: pointer; padding: 0;
}
.shutter span { width: 60px; height: 60px; border-radius: 50%; background: var(--rec); transition: all .2s; }
.shutter.recording span { width: 30px; height: 30px; border-radius: 6px; }
.shutter:disabled { opacity: .4; }

.notice {
  position: absolute; left: 16px; right: 16px; top: calc(70px + env(safe-area-inset-top));
  background: rgba(20,20,20,.9); color: #fff; padding: 12px 14px; border-radius: 12px; font-size: 14px;
  border-left: 4px solid var(--accent);
}
.notice[hidden] { display: none; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 2000;
  background: var(--panel); color: var(--text); padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0; box-shadow: 0 -10px 40px rgba(0,0,0,.4);
  display: grid; gap: 12px; max-width: 560px; margin: 0 auto;
}
.sheet[hidden] { display: none; }
.sheet label { display: grid; gap: 6px; font-weight: 600; font-size: .9rem; }
.sheet label.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.sheet input:not([type=checkbox]), .sheet select {
  font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
.sheet input[type=checkbox] { width: 20px; height: 20px; }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress[hidden] { display: none; }
#progressBar { height: 100%; width: 0; background: var(--ok); transition: width .2s; }

/* ---------- playback page ---------- */
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.actions { display: flex; gap: 8px; }
.actions form { margin: 0; }
.player { display: grid; grid-template-columns: 1.4fr 1fr; gap: 12px; }
@media (max-width: 860px) { .player { grid-template-columns: 1fr; } }
.video-box { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 16/9; }
.video-box video { width: 100%; height: 100%; display: block; object-fit: contain; }
.overlay { position: absolute; left: 12px; top: 12px; pointer-events: none; color: #fff; }
.gauge { position: relative; width: 120px; background: rgba(0,0,0,.55); border-radius: 12px; padding: 8px 8px 4px; backdrop-filter: blur(4px); }
.gauge svg { width: 100%; display: block; }
.g-track, .g-fill { fill: none; stroke-width: 9; stroke-linecap: round; }
.g-track { stroke: rgba(255,255,255,.18); }
.g-fill { stroke: var(--ok); stroke-dasharray: 0 100; transition: stroke-dasharray .15s linear, stroke .3s; }
.g-val { position: absolute; left: 0; right: 0; bottom: 6px; text-align: center; font-weight: 800; font-size: 26px; line-height: 1; font-variant-numeric: tabular-nums; }
.g-val small { display: block; font-size: 10px; font-weight: 600; opacity: .8; letter-spacing: .05em; }
.ov-coords { margin-top: 6px; font: 12px ui-monospace, monospace; background: rgba(0,0,0,.55); padding: 3px 7px; border-radius: 6px; display: inline-block; }

.map { min-height: 320px; border-radius: var(--radius); border: 1px solid var(--line); z-index: 0; }
@media (max-width: 860px) { .map { height: 320px; } }
.car-marker { background: none; border: 0; }
.car {
  width: 28px; height: 28px; border-radius: 50%; background: #1f6feb; border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.4); display: grid; place-items: center;
}
.car-arrow {
  width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent;
  border-bottom: 10px solid #fff; transform-origin: 50% 60%; margin-top: -2px;
}
.follow-btn { background: #fff; color: #14171c; border: 2px solid rgba(0,0,0,.2); border-radius: 6px; padding: 5px 9px; font: 600 12px system-ui; cursor: pointer; }

.chart-box { margin-top: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.chart-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-weight: 600; margin-bottom: 6px; }
#chart { width: 100%; height: 120px; display: block; cursor: pointer; }

.stats.big { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 12px; }
@media (max-width: 560px) { .stats.big { grid-template-columns: repeat(2, 1fr); } }
.stats.big > div { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; }
.stats.big b { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.stats.big span { color: var(--muted); font-size: .85rem; }
