:root {
  --bg: #0d1117; --panel: rgba(13, 17, 23, .92); --line: #2a313c; --text: #e8edf3; --muted: #8b96a5;
  --green: #2fbf71; --yellow: #f5c518; --orange: #ff8a1f; --red: #ff3b30; --blue: #3b82f6;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; overflow: hidden; }
#map { position: fixed; inset: 0; z-index: 0; background: #1a1f27; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

/* HUD */
#hud { position: fixed; top: 0; left: 0; right: 0; z-index: 500; display: flex; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-t)) 14px 10px; background: var(--panel); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.speedbox { min-width: 104px; text-align: center; }
.speed { font-size: 64px; line-height: .95; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -2px; }
.speed.over { color: var(--red); animation: pulse .8s infinite alternate; }
.unit { font-size: 12px; color: var(--muted); margin-top: 2px; }
.mid { flex: 1; min-width: 0; }
.kmline { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nextline { font-size: 15px; margin-top: 4px; color: var(--yellow); min-height: 18px; }
.srcline { font-size: 11px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sign { width: 82px; height: 82px; flex: none; border-radius: 50%; background: #fff; color: #111; border: 9px solid var(--red);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 32px; font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 2px rgba(255,255,255,.15); }
.sign.temp { box-shadow: 0 0 0 4px var(--yellow), 0 0 18px var(--yellow); }
.sign.unknown { border-color: #666; color: #777; font-size: 22px; }
.sign.flash { animation: flash .5s 4; }
@keyframes pulse { from { opacity: 1 } to { opacity: .55 } }
@keyframes flash { 50% { transform: scale(1.15); } }

.tempbar { position: fixed; z-index: 499; left: 10px; right: 10px; top: calc(112px + var(--safe-t)); padding: 8px 12px; border-radius: 10px;
  background: rgba(245, 197, 24, .95); color: #111; font-size: 14px; font-weight: 600; box-shadow: 0 4px 16px rgba(0,0,0,.4); }
.sheet-open .tempbar { display: none; }
.tempbar.closure { background: rgba(255, 59, 48, .95); color: #fff; }

/* Dock */
#dock { position: fixed; z-index: 500; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around;
  padding: 6px 6px calc(6px + var(--safe-b)); background: var(--panel); border-top: 1px solid var(--line);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.dockbtn { position: relative; flex: 1; background: none; border: 0; display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 6px 2px; font-size: 12px; color: var(--muted); border-radius: 10px; }
.dockbtn .ico { font-size: 22px; line-height: 1; }
.dockbtn:active { background: rgba(255,255,255,.06); }
.dockbtn.on { color: var(--blue); }
.badge { position: absolute; top: 2px; right: calc(50% - 26px); background: var(--yellow); color: #111; border-radius: 9px;
  font-size: 11px; padding: 1px 6px; }
.conn { position: fixed; z-index: 501; right: 10px; bottom: calc(76px + var(--safe-b)); width: 12px; height: 12px; border-radius: 50%;
  background: #666; border: 2px solid var(--bg); }
.conn.ok { background: var(--green); } .conn.bad { background: var(--red); }

/* Sheet */
.sheet { position: fixed; z-index: 450; left: 0; right: 0; bottom: calc(62px + var(--safe-b)); max-height: calc(100vh - 190px - var(--safe-t) - var(--safe-b)); display: flex; flex-direction: column;
  background: #11161d; border-top-left-radius: 16px; border-top-right-radius: 16px; border-top: 1px solid var(--line);
  box-shadow: 0 -10px 30px rgba(0,0,0,.5); }
.sheet-head { display: flex; align-items: center; padding: 14px 16px 8px; }
.sheet-head h2 { margin: 0; font-size: 18px; flex: 1; }
.close { background: #222a35; border: 0; width: 34px; height: 34px; border-radius: 50%; }
.sheet-body { overflow: auto; padding: 4px 16px 16px; -webkit-overflow-scrolling: touch; }
.item { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 8px 0; background: #161c24; }
.item h3 { margin: 0 0 4px; font-size: 15px; display: flex; gap: 8px; align-items: center; }
.item p { margin: 4px 0; font-size: 13px; color: #c7d0db; }
.item a { color: #7fb2ff; }
.pill { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 13px; font-weight: 700; color: #111; }
.muted { color: var(--muted); } .small { font-size: 13px; } .tiny { font-size: 11px; color: var(--muted); }
.seg { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid #1e252f; font-size: 14px; }
.seg:last-child { border-bottom: 0; }
.seg .km { flex: 1; } .seg .lim { font-weight: 800; min-width: 52px; text-align: right; }
video.cam { width: 100%; border-radius: 10px; background: #000; aspect-ratio: 16/9; display: block; }
.wx { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; margin-top: 6px; color: #c7d0db; }
label.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid #1e252f; font-size: 15px; }
label.row input[type=range] { width: 140px; }
label.row input[type=checkbox] { width: 22px; height: 22px; }

/* Overlay / start */
.overlay { position: fixed; inset: 0; z-index: 900; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(5, 8, 12, .82); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.card { max-width: 420px; width: 100%; background: #11161d; border: 1px solid var(--line); border-radius: 18px; padding: 22px; }
.card h1 { margin: 0 0 8px; font-size: 24px; }
.card p { color: #c7d0db; margin: 8px 0; }
.card ul { padding-left: 18px; color: #c7d0db; }
button.primary { width: 100%; margin-top: 12px; padding: 15px; font-size: 18px; font-weight: 700; border: 0; border-radius: 12px; background: var(--blue); color: #fff; }
button.ghost { width: 100%; margin-top: 8px; padding: 12px; font-size: 15px; border: 1px solid var(--line); border-radius: 12px; background: none; color: var(--text); }

/* Alert */
.alert { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 18px;
  background: rgba(120, 0, 0, .55); animation: bg 1s infinite alternate; }
@keyframes bg { to { background: rgba(120, 0, 0, .25); } }
.alert-card { width: 100%; max-width: 460px; background: #fff; color: #111; border-radius: 18px; padding: 20px; border: 6px solid var(--red); }
.alert-title { font-size: 22px; font-weight: 800; margin-bottom: 10px; }
.alert-text { font-size: 18px; line-height: 1.35; white-space: pre-line; }
.alert-text b { font-size: 22px; }
.alert-src { font-size: 12px; color: #555; margin-top: 10px; word-break: break-word; }
.alert-src a { color: #0b57d0; }

.toast { position: fixed; z-index: 800; left: 12px; right: 12px; bottom: calc(80px + var(--safe-b)); padding: 12px; border-radius: 12px;
  background: #1f2937; border: 1px solid var(--line); font-size: 14px; text-align: center; }

/* Leaflet tweaks */
.leaflet-container { background: #1a1f27; }
/* тёмная подложка из обычных тайлов OSM */
.dark-tiles { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9) saturate(.6); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: #11161d; color: var(--text); }
.leaflet-popup-content { margin: 10px; width: 260px !important; }
.leaflet-control-attribution { font-size: 9px; background: rgba(0,0,0,.5) !important; color: #aaa; }
.leaflet-control-attribution a { color: #9ab; }
.leaflet-top { top: calc(108px + var(--safe-t)); }
.leaflet-bottom { bottom: calc(66px + var(--safe-b)); }
.me-dot { width: 22px; height: 22px; border-radius: 50%; background: var(--blue); border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(59,130,246,.3); }
.cam-ico { font-size: 22px; filter: drop-shadow(0 1px 2px #000); }
.km-label { color: #cfd6df; font-size: 11px; font-weight: 700; text-shadow: 0 0 3px #000, 0 0 3px #000; white-space: nowrap; }

@media (max-width: 380px) {
  .speed { font-size: 52px; } .speedbox { min-width: 84px; } .sign { width: 70px; height: 70px; font-size: 27px; border-width: 8px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  #hud { padding-top: 6px; padding-bottom: 6px; } .speed { font-size: 48px; } .sign { width: 62px; height: 62px; font-size: 24px; border-width: 7px; }
  .tempbar { top: 84px; } .leaflet-top { top: 84px; }
}

/* Перекрытие и частичные ограничения движения */
.sign.closed { border-color: var(--red); background: var(--red); color: #fff; font-size: 34px; box-shadow: 0 0 0 4px #fff, 0 0 22px var(--red); }
.tempbar.partial { background: rgba(245, 197, 24, .96); color: #111; }
.alert[data-kind="closed"] .alert-card { border-color: var(--red); background: #fff1f0; }
.alert[data-kind="closed"] .alert-title { color: #c4001a; font-size: 26px; }
.alert[data-kind="open"] .alert-card { border-color: #2fbf71; }
.alert[data-kind="partial"] .alert-card { border-color: #f5c518; }
.srcline.warn, #srcline.warn { color: #f5c518; }
