* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --accent: #ff6b35;
  --accent2: #2dd4a7;
  --danger: #ff4d6d;
  --bg: #0b1322;
  --bg2: #111c31;
  --card: #16223a;
  --glass: rgba(255,255,255,.06);
  --glass-strong: rgba(18,29,48,.86);
  --stroke: rgba(255,255,255,.1);
  --text: #eef4fb;
  --muted: #8ea4bd;
  --grad: linear-gradient(135deg, #ff6b35 0%, #ff3d5a 100%);
  --shadow-lg: 0 18px 50px rgba(0,0,0,.5);
  --shadow-sm: 0 6px 18px rgba(0,0,0,.35);
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
  --topbar-h: calc(max(10px, env(safe-area-inset-top)) + 38px + 10px);
}

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
::selection { background: rgba(255,107,53,.35); }
button { font-family: inherit; }

#map { position: fixed; inset: 0; z-index: 0; background: #0d1b2e; }
#map .leaflet-tile-pane { filter: saturate(.92) contrast(1.02); }

.leaflet-control-attribution {
  font-size: 9px !important;
  background: rgba(11,19,34,.65) !important;
  color: var(--muted) !important;
  backdrop-filter: blur(4px);
  border-radius: 8px 0 0 0;
  padding: 2px 6px !important;
}
.leaflet-control-attribution a { color: var(--accent) !important; }
.leaflet-container { font-family: inherit; background: transparent; }
.leaflet-popup-content-wrapper {
  background: var(--glass-strong);
  color: var(--text);
  border-radius: var(--r-md);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px);
}
.leaflet-popup-content { margin: 12px 14px; }
.leaflet-popup-tip { background: var(--glass-strong); }
.leaflet-popup-close-button { color: var(--muted) !important; }
.leaflet-bar a {
  background: rgba(18,29,48,.9) !important;
  color: var(--text) !important;
  border-bottom-color: var(--stroke) !important;
  backdrop-filter: blur(8px);
}
.leaflet-bar a:hover { background: var(--glass) !important; }
.leaflet-control-zoom a { width: 34px; height: 34px; line-height: 34px; font-size: 18px; }
#map .leaflet-bottom.leaflet-left { bottom: 50%; }
#map .leaflet-left .leaflet-control-zoom { margin-left: 10px; border-radius: 12px; overflow: hidden; box-shadow: var(--shadow-sm); }
#map .leaflet-bottom.leaflet-left .leaflet-control-zoom { margin-bottom: 0; transform: translateY(50%); }

/* ---------- Top bar ---------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: linear-gradient(180deg, rgba(11,19,34,.94) 0%, rgba(11,19,34,.75) 55%, transparent 100%);
  color: var(--text);
}
/* Installed / standalone app, and phones in any mode: keep the header clear
   of the Android status bar and notch. Floor of 72px guarantees the whole bar
   sits well below the status bar/cutout even where env(safe-area-inset-top)
   reports 0; env() extends it below a larger cutout. */
@media (display-mode: standalone), (display-mode: minimal-ui), (display-mode: fullscreen), (max-width: 700px) {
:root { --topbar-h: calc(max(20px, env(safe-area-inset-top) + 8px) + 38px + 10px); }
   #topbar {
     padding-top: 20px;
     padding-top: max(20px, calc(env(safe-area-inset-top) + 8px));
   }
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand .logo {
  width: 38px; height: 38px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; line-height: 1;
  background: var(--grad);
  border-radius: 12px;
  box-shadow: 0 6px 16px rgba(255,107,53,.4);
}
.brand .title { font-size: 16px; font-weight: 700; letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand .status {
  font-size: 11px; color: var(--muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw;
}
.top-tools { display: flex; align-items: center; gap: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.top-tools::-webkit-scrollbar { display: none; }
.tool, .pill { flex-shrink: 0; }
.tool {
  background: var(--glass); border: 1px solid var(--stroke); color: var(--text);
  width: 38px; height: 38px; border-radius: 12px; font-size: 17px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform .12s ease, background .2s ease, border-color .2s ease;
}
.tool:active { transform: scale(.92); background: var(--glass-strong); }
.tool.active { background: var(--grad); border-color: transparent; box-shadow: 0 5px 14px rgba(255,107,53,.4); }

.pill {
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
  padding: 5px 10px; border-radius: 999px; letter-spacing: 1px;
  animation: pulse 1.4s infinite; box-shadow: 0 0 14px rgba(255,107,53,.65);
  white-space: nowrap;
}
.pill.rec { background: var(--danger); box-shadow: 0 0 14px rgba(255,77,109,.65); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

/* ---------- Stats ---------- */
#stats {
  position: fixed; top: calc(var(--topbar-h) + 8px); left: 50%; transform: translateX(-50%);
  z-index: 999; display: flex; gap: 10px;
  background: var(--glass-strong); backdrop-filter: blur(16px) saturate(130%);
  border: 1px solid var(--stroke);
  padding: 9px 18px; border-radius: 16px; box-shadow: var(--shadow-sm);
}
.stat { text-align: center; padding: 0 9px; }
.stat-label { display: block; font-size: 9.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.2px; }
.stat span:last-child { font-size: 15px; font-weight: 800; color: var(--text); }

/* ---------- Controls / bottom dock ---------- */
#controls {
  position: fixed; left: 12px; right: 12px; z-index: 1000;
  bottom: calc(10px + env(safe-area-inset-bottom));
  display: flex; justify-content: space-around; align-items: flex-end;
  padding: 8px 4px 10px;
  background: rgba(18,29,48,.9); backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--stroke);
  border-radius: 24px; box-shadow: var(--shadow-lg);
}
.ctrl {
  background: none; border: none; color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 4px 10px 2px; cursor: pointer; border-radius: 14px; min-width: 52px;
  transition: transform .12s ease;
}
.ctrl:active { transform: scale(.9); }
.ctrl .ico {
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  font-size: 20px; line-height: 1; border-radius: 14px;
  background: var(--glass); border: 1px solid transparent;
  transition: background .2s ease, border-color .2s ease;
}
.ctrl .lbl { font-size: 10px; color: var(--muted); font-weight: 600; }
.ctrl.main .ico {
  background: var(--grad); color: #fff;
  width: 58px; height: 58px; border-radius: 50%;
  font-size: 25px;
  margin-top: -24px;
  box-shadow: 0 10px 26px rgba(255,107,53,.55);
  border: 4px solid rgba(18,29,48,.95);
}
.ctrl.main .lbl { color: var(--accent); font-weight: 800; }
.ctrl.main.recording .ico { background: linear-gradient(135deg, #ff4d6d, #ff2d55); box-shadow: 0 10px 26px rgba(255,77,109,.6); animation: pulse 1.2s infinite; }
.ctrl.main.recording .lbl { color: var(--danger); }
.ctrl.active { background: rgba(255,107,53,.12); }
.ctrl.active .ico { background: rgba(255,107,53,.2); border-color: rgba(255,107,53,.5); }
.ctrl.active .lbl { color: var(--accent); }

/* ---------- Sheet ---------- */
.sheet {
  position: fixed; left: 10px; right: 10px; bottom: calc(100px + env(safe-area-inset-bottom));
  z-index: 1100; max-width: 520px; margin: 0 auto;
  background: var(--glass-strong); backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--stroke);
  border-radius: var(--r-lg);
  max-height: 64vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: fadeUp .22s ease;
  padding-bottom: env(safe-area-inset-bottom);
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.sheet-handle { width: 44px; height: 4px; border-radius: 2px; background: var(--muted); margin: 10px auto 0; opacity: .55; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px 10px; }
#sheetTitle { font-size: 17px; font-weight: 800; }
.sheet-close {
  background: var(--glass); border: 1px solid var(--stroke); color: var(--muted);
  width: 30px; height: 30px; border-radius: 10px; cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.sheet-close:active { transform: scale(.9); }
.sheet-body { overflow-y: auto; padding: 4px 10px 16px; }
.sheet-body::-webkit-scrollbar { width: 4px; }
.sheet-body::-webkit-scrollbar-thumb { background: var(--muted); border-radius: 4px; }
.sheet-foot { display: flex; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--stroke); }
.foot-btn {
  flex: 1; background: var(--glass); border: 1px solid var(--stroke); color: var(--text);
  border-radius: var(--r-sm); padding: 11px; font-size: 12.5px; font-weight: 700; cursor: pointer;
  transition: transform .12s ease, background .2s ease;
}
.foot-btn:active { transform: scale(.97); background: var(--glass-strong); }

/* ---------- Lists / cards ---------- */
.list-item {
  background: var(--glass); border: 1px solid var(--stroke); border-radius: var(--r-md);
  padding: 13px 14px; margin-bottom: 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  cursor: pointer;
  transition: transform .12s ease, border-color .2s ease;
}
.list-item:active { transform: scale(.985); border-color: rgba(255,107,53,.6); }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 700; font-size: 14.5px; }
.list-item .li-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.list-item .li-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.icon-btn {
  background: var(--glass); border: 1px solid var(--stroke); color: var(--text);
  border-radius: 10px; width: 34px; height: 34px; cursor: pointer; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s ease, color .2s ease, transform .1s ease;
}
.icon-btn:active { transform: scale(.9); }
.icon-btn.del:hover { background: rgba(255,77,109,.18); color: var(--danger); border-color: rgba(255,77,109,.5); }
.icon-btn.share { color: var(--accent2); }
.icon-btn.trim { color: #f59e0b; }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }

.empty-state {
  text-align: center; color: var(--muted); padding: 34px 16px; font-size: 13.5px; line-height: 1.7;
}

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 2000; background: rgba(5,10,18,.62);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 18px;
  animation: fadeIn .18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-box {
  background: var(--glass-strong); backdrop-filter: blur(24px) saturate(150%);
  border: 1px solid var(--stroke);
  border-radius: var(--r-lg); padding: 22px;
  width: 100%; max-width: 400px; box-shadow: var(--shadow-lg);
  animation: fadeUp .24s ease;
}
.modal-box h3 { margin-bottom: 6px; font-size: 18px; font-weight: 800; }
.modal-box .hint { font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
.modal-box input, .modal-box textarea {
  width: 100%; background: var(--bg2); border: 1px solid var(--stroke);
  color: var(--text); border-radius: var(--r-sm); padding: 12px 14px; margin: 8px 0;
  font-size: 16px; font-family: inherit;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.modal-box input:focus, .modal-box textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255,107,53,.18);
}
.modal-box textarea { resize: vertical; min-height: 60px; }
.photo-preview { margin: 8px 0; }
.photo-preview img { width: 100%; max-height: 160px; object-fit: cover; border-radius: var(--r-sm); }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; justify-content: flex-end; flex-wrap: wrap; }

.btn {
  border: none; border-radius: var(--r-sm); padding: 12px 20px; font-size: 14px;
  font-weight: 700; cursor: pointer;
  transition: transform .12s ease, filter .2s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--grad); color: #fff; box-shadow: 0 6px 16px rgba(255,107,53,.4); }
.btn.ghost { background: var(--glass); color: var(--text); border: 1px solid var(--stroke); }
.btn.danger { background: var(--danger); color: #fff; box-shadow: 0 6px 16px rgba(255,77,109,.35); }
.btn.sm { padding: 8px 12px; font-size: 12.5px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(104px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%);
  z-index: 3000; background: var(--glass-strong); color: var(--text);
  padding: 12px 20px; border-radius: 14px; font-size: 13.5px;
  box-shadow: var(--shadow-lg); border: 1px solid var(--stroke);
  max-width: 90vw; text-align: center;
  backdrop-filter: blur(14px);
  animation: fadeUp .18s ease;
}
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--accent2); }

.hidden { display: none !important; }

/* ---------- Markers ---------- */
.place-marker {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--grad); color: #fff; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(255,107,53,.5);
}
.car-rot { font-size: 26px; line-height: 1; text-align: center; filter: drop-shadow(0 2px 4px rgba(0,0,0,.55)); transition: transform .25s linear; }
.place-popup .pp-name { font-weight: 700; font-size: 14px; }
.place-popup .pp-note { font-size: 12px; color: var(--muted); margin-top: 3px; white-space: pre-wrap; }
.place-popup .pp-photo { max-width: 200px; border-radius: var(--r-sm); margin-top: 8px; }
.track-start-marker, .track-end-marker { text-align: center; font-size: 16px; font-weight: 700; }

.loading-spin {
  display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.2);
  border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Draft banner ---------- */
.banner {
  position: fixed; top: calc(var(--topbar-h) + 8px); left: 50%; transform: translateX(-50%);
  z-index: 999; display: flex; align-items: center; gap: 8px;
  background: var(--glass-strong); border: 1px solid var(--stroke);
  backdrop-filter: blur(14px);
  padding: 9px 14px; border-radius: 14px; font-size: 12.5px; max-width: 94vw;
  box-shadow: var(--shadow-sm);
}

/* ---------- Layers panel ---------- */
.panel {
  position: fixed; top: calc(var(--topbar-h) + 10px); right: 12px; z-index: 3000;
  display: flex; justify-content: flex-end;
  animation: fadeIn .16s ease;
}
.panel-box {
  background: var(--glass-strong); backdrop-filter: blur(18px);
  border: 1px solid var(--stroke); border-radius: var(--r-md);
  padding: 12px; min-width: 190px; max-width: 92vw;
  box-shadow: var(--shadow-lg);
  max-height: calc(100vh - var(--topbar-h) - 34px); overflow-y: auto;
  overscroll-behavior: contain;
}
.panel-box h3 { font-size: 13.5px; margin-bottom: 6px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.ovr-h { font-size: 11.5px; margin: 10px 0 4px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; border-top: 1px solid var(--stroke); padding-top: 8px; }
.layer-opt {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 8px; border-radius: var(--r-sm); cursor: pointer; font-size: 14px;
  transition: background .15s ease;
}
.layer-opt:active { background: var(--glass); }
.layer-opt.sel { background: rgba(255,107,53,.10); color: var(--accent); font-weight: 700; }
.layer-opt .chk {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--muted); position: relative;
  transition: background .2s ease, border-color .2s ease;
}
.layer-opt.sel .chk { background: var(--accent); border-color: var(--accent); }
.layer-opt.sel .chk::after {
  content: ''; position: absolute; top: 50%; left: 50%;
  width: 6px; height: 6px; border-radius: 50%;
  background: #fff; transform: translate(-50%,-50%);
}

/* ---------- Search ---------- */
.search-results { max-height: 36vh; overflow-y: auto; margin-top: 6px; }
.search-results::-webkit-scrollbar { width: 4px; }
.search-results::-webkit-scrollbar-thumb { background: var(--muted); border-radius: 4px; }
.search-res {
  padding: 11px 10px; border-bottom: 1px solid var(--stroke); cursor: pointer;
  border-radius: var(--r-sm);
  transition: background .15s ease;
}
.search-res:active { background: var(--glass); }
.search-res .sr-name { font-size: 14px; font-weight: 700; }
.search-res .sr-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.search-loading { padding: 10px 8px; color: var(--muted); font-size: 13px; text-align: center; }

/* ---------- Dashboard ---------- */
.dash { display: flex; gap: 8px; margin-bottom: 14px; max-width: 420px; }
.dash-card {
  flex: 1; background: var(--glass); border: 1px solid var(--stroke);
  border-radius: var(--r-md); padding: 14px 8px; text-align: center;
}
.dash-card .dc-val { font-size: 19px; font-weight: 800; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.dash-card .dc-lbl { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .7px; margin-top: 3px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 14px; padding: 4px; background: var(--glass); border: 1px solid var(--stroke); border-radius: var(--r-md); }
.tab {
  flex: 1; background: none; border: none;
  color: var(--muted); border-radius: var(--r-sm); padding: 9px; font-size: 13px;
  font-weight: 700; cursor: pointer; transition: background .2s ease, color .2s ease;
}
.tab.sel { background: var(--grad); color: #fff; box-shadow: 0 4px 12px rgba(255,107,53,.35); }

/* ---------- Journal ---------- */
.journal-day {
  background: var(--glass); border: 1px solid var(--stroke);
  border-radius: var(--r-md); padding: 14px; margin-bottom: 14px;
}
.jd-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.jd-date { font-size: 14.5px; font-weight: 800; color: var(--accent); }
.jd-meta { font-size: 11.5px; color: var(--muted); text-align: right; }
.jd-note {
  width: 100%; background: var(--bg2); border: 1px solid var(--stroke);
  color: var(--text); border-radius: var(--r-sm); padding: 11px; margin-top: 10px;
  font-size: 16px; font-family: inherit; resize: vertical; min-height: 46px;
}
.jd-note:focus { outline: none; border-color: var(--accent); }

/* ---------- Directions ---------- */
.dir-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: nowrap; }
.dir-row input { margin: 0; min-width: 0; }
.dir-row .mini {
  flex: 0 0 auto; width: 46px; height: 46px; border: none; border-radius: var(--r-sm);
  background: var(--grad); color: #fff; font-size: 18px; cursor: pointer;
  box-shadow: 0 5px 14px rgba(255,107,53,.4);
}
.dir-row .delwp {
  flex: 0 0 auto; width: 42px; height: 42px; border: none; border-radius: var(--r-sm);
  background: var(--danger); color: #fff; font-size: 16px; cursor: pointer;
}
.dir-summary {
  margin-top: 12px; background: var(--glass); border: 1px solid var(--stroke);
  border-radius: var(--r-md); padding: 14px; text-align: center;
}
.dir-summary .ds-dist { font-size: 22px; font-weight: 800; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.dir-summary .ds-time { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.trim-info { font-size: 13px; color: var(--muted); line-height: 1.5; margin-top: 8px; }
#trimSlider { width: 100%; margin: 10px 0; accent-color: var(--accent); }

/* ---------- Navigation overlay ---------- */
#navBar {
  position: fixed; left: 10px; right: 10px; top: max(10px, env(safe-area-inset-top)); z-index: 1500;
  background: rgba(11,19,34,.92); backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--stroke);
  border-radius: var(--r-lg);
  padding: 12px; box-shadow: var(--shadow-lg); color: #fff;
}
#turnBanner {
  display: flex; align-items: center; gap: 12px;
  background: var(--grad); border-radius: var(--r-md); padding: 13px 15px; margin-bottom: 10px;
  box-shadow: 0 8px 20px rgba(255,107,53,.35);
}
.turn-icon { font-size: 27px; line-height: 1; }
.turn-text { flex: 1; font-size: 14.5px; font-weight: 800; }
.turn-dist { font-size: 14px; font-weight: 800; white-space: nowrap; }
#navHud { display: flex; gap: 6px; }
#navHud .hud { flex: 1; background: var(--glass); border: 1px solid var(--stroke); border-radius: var(--r-sm); padding: 9px 4px; text-align: center; }
#navHud .hud-l { display: block; font-size: 9px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); }
#navHud .hud-v { font-size: 14px; font-weight: 800; }
#navControls { display: flex; gap: 8px; margin-top: 10px; }
.nav-btn {
  flex: 1; border: none; border-radius: var(--r-sm); padding: 11px; font-size: 13px;
  font-weight: 700; cursor: pointer;
  background: var(--glass); color: #fff; border: 1px solid var(--stroke);
  transition: transform .12s ease;
}
.nav-btn:active { transform: scale(.97); }
.nav-btn.active { background: var(--grad); border-color: transparent; }
.nav-btn.danger { background: var(--danger); border-color: transparent; }

/* ---------- Dark theme ---------- */
body.dark { --bg: #070a12; --bg2: #0d1119; --card: #121826; --glass: rgba(255,255,255,.05); --glass-strong: rgba(11,14,22,.9); --text: #eef4fb; --muted: #7f92ab; }
body.dark #map { background: #070a12; }

/* ---------- Desktop / tablet polish ---------- */
@media (min-width: 640px) {
  #controls { left: 50%; right: auto; transform: translateX(-50%); width: min(94vw, 520px); }
  #navBar { left: 50%; transform: translateX(-50%); width: min(94vw, 560px); }
}
@media (max-width: 460px) {
  .top-tools { gap: 6px; }
  .tool { width: 34px; height: 34px; font-size: 16px; }
  .brand .logo { width: 34px; height: 34px; font-size: 18px; }
  .brand .title { display: none; }
  .brand .status { display: none; }
}
@media (max-width: 380px) {
  .tool { width: 32px; height: 32px; }
  .top-tools { gap: 4px; }
  .brand { gap: 8px; }
  #controls { left: 8px; right: 8px; }
  .ctrl { min-width: 46px; padding: 4px 6px 2px; }
  .ctrl .ico { width: 36px; height: 36px; }
  .ctrl.main .ico { width: 54px; height: 54px; }
}

@media (max-width: 640px), (orientation: portrait) {
  .panel { left: 8px; right: 8px; justify-content: stretch; }
  .panel-box { width: auto; max-height: calc(100vh - var(--topbar-h) - 26px); }
}

/* ---------- Driving HUD ---------- */
#hudBar { font-family: inherit; user-select: none; }
#hudSpeedBig { color: #fff; }
.hud-limit { font-weight: 700; }
.hud-limit.over { color: #ff5a6e; font-weight: 800; }
  .hud-limit.ok { color: #a3e635; }
  .hud-curve { color: #ffd166; }
  .hud-curve.over { color: #ff5a6e; font-weight: 800; }

/* ---------- Trip replay ---------- */
.replay-speed.sel { background: var(--grad); border-color: transparent; color: #fff; }
#replayBar .btn.ghost { background: var(--glass); color: #fff; border: 1px solid var(--stroke); }

/* ---------- Hazard voting ---------- */
.vote-btn {
  border: 1px solid var(--stroke); background: var(--glass); color: var(--text);
  border-radius: 8px; padding: 4px 8px; font-size: 12px; cursor: pointer;
  margin: 2px; transition: transform .12s ease;
}
.vote-btn:active { transform: scale(.92); }
.vote-btn:disabled { opacity: .4; }
.vote-wrap { display: flex; align-items: center; gap: 2px; margin-top: 6px; }

/* ---------- Track action buttons ---------- */
.icon-btn.replay { color: #38bdf8; }
.icon-btn.attach { color: #f472b6; }
.icon-btn.card { color: #a3e635; }
  .icon-btn.sim { color: #22d3ee; }

/* ---------- v26 Visual modernization ---------- */
:root { --grad2: linear-gradient(135deg,#2563eb 0%,#7c3aed 60%,#ff3d5a 100%); --accent-blue:#3b82f6; }
button, input, select, textarea { -webkit-tap-highlight-color: transparent; }

/* sheet + gap + shadow polish */
.sheet { border-radius: var(--r-lg) var(--r-lg) 0 0; box-shadow: 0 -14px 44px rgba(0,0,0,.55) !important; }
.sheet-head h2 { font-size: 17px; letter-spacing: .2px; }

/* softer, airier top-level surfaces */
.panel-box, .modal-box { background: linear-gradient(180deg, var(--glass-strong), var(--glass-strong)); }

/* modern pill buttons */
.btn.primary { background: var(--grad2); box-shadow: 0 8px 22px rgba(37,99,235,.45); }
.btn.primary:active { filter: brightness(1.1); }
.pill2 { transition: transform .12s ease, background .2s ease, box-shadow .2s ease; }
.pill2:active { transform: scale(.94); }
.pill2.active { background: var(--grad2) !important; color: #fff !important; border-color: transparent !important; box-shadow: 0 4px 14px rgba(37,99,235,.4); }

/* driving HUD: speed-cam countdown line + speed readout glow */
.nav-camline {
  margin-top: 8px; border-radius: var(--r-sm); padding: 7px 10px; font-size: 12px; font-weight: 700;
  background: linear-gradient(135deg, rgba(220,38,38,.85), rgba(255,77,109,.75));
  border: 1px solid rgba(255,255,255,.18); color: #fff; align-items: center; justify-content: center; gap: 6px;
  animation: fadeUp .2s ease;
}
#hudSpeedBig { text-shadow: 0 0 18px rgba(120,220,255,.45); }
.hud-v { font-variant-numeric: tabular-nums; }

/* service-due banner (v26) */
#svcBanner .svc-text { font-weight: 700; }

/* smoother keyframes (additive) */
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pop { from { opacity: 0; transform: scale(.92); } to { opacity: 1; transform: scale(1); } }

/* darker dark theme refinement */
body.dark { --glass: rgba(255,255,255,.045); }
body.dark #map .leaflet-tile-pane { filter: brightness(.85) saturate(.85) contrast(1.04); }

/* toast refresh */
.toast { border-left: 3px solid var(--accent); }
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--accent2); }

/* badges + route list extras */
.dc-val.gold { background: linear-gradient(135deg,#fbbf24,#f59e0b); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- v27 accent themes + compass + haptics ---------- */
html[data-accent="blue"]   { --accent: #3b82f6; --grad: linear-gradient(135deg, #3b82f6 0%, #2dd4bf 100%); --accent2: #2dd4bf; }
html[data-accent="violet"] { --accent: #a855f7; --grad: linear-gradient(135deg, #a855f7 0%, #ec4899 100%); --accent2: #ec4899; }
html[data-accent="teal"]   { --accent: #14b8a6; --grad: linear-gradient(135deg, #14b8a6 0%, #22d3ee 100%); --accent2: #22d3ee; }
.theme-sw { display: flex; gap: 10px; padding: 6px 12px 10px; }
.dark-swatch {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer; padding: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.4); transition: transform .15s ease, border-color .15s ease;
}
.dark-swatch:active { transform: scale(.88); }
.dark-swatch.active { border-color: #fff; transform: scale(1.08); }
#hudCmp { font-size: 12.5px; font-weight: 800; }

/* ---------- v29 route alternatives + elevation summary ---------- */
.alt-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0 2px; }
.alt-pick {
  border: 1px solid var(--stroke); background: var(--glass); color: var(--text);
  border-radius: 999px; padding: 5px 11px; font-size: 11.5px; cursor: pointer; font-weight: 700;
  transition: transform .12s ease, background .2s ease;
}
.alt-pick:active { transform: scale(.94); }
.alt-pick.sel { background: var(--grad2); border-color: transparent; color: #fff; box-shadow: 0 4px 12px rgba(37,99,235,.35); }
#dsProfile { font-size: 0; }
#dsProfile > div { font-size: 10px; }
#dsProfile .ds-elev-note { font-size: 10px; color: var(--muted); margin-top: 2px; }
#profCanvas { background: rgba(255,255,255,.04); border: 1px solid var(--stroke); border-radius: var(--r-sm); }
/* ---------- v30 overlay + nav guidance + photos + i18n ---------- */
.age-row { display: flex; align-items: center; gap: 8px; padding: 4px 12px 10px; }
.age-row input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
.age-lbl { font-size: 11.5px; font-weight: 700; color: var(--muted); white-space: nowrap; }

#navLanes { display: flex; gap: 4px; justify-content: center; padding: 6px 8px 0; flex-wrap: wrap; }
#navLanes .lane {
  min-width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--stroke); border-radius: 8px; font-size: 14px; color: var(--muted);
  background: var(--panel); opacity: .55;
}
#navLanes .lane.true { opacity: 1; border-color: var(--accent2); background: var(--accent2); color: #06243a; font-weight: 800; box-shadow: 0 2px 8px rgba(45,212,191,.4); }
#navUpcoming { display: flex; gap: 8px; justify-content: center; padding: 6px 8px; flex-wrap: wrap; }
#navUpcoming .up-item {
  width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--stroke); border-radius: 50%; font-size: 12px; background: var(--glass); color: var(--muted);
}

/* satellite/transit vector markers are plain divIcons so no extra CSS needed;
   keep pill + photo panel consistent with the glass theme */
#photoBar .panel-box { min-width: 300px; max-width: 360px; }
#photoBar img { border: 1px solid var(--stroke); }
#photoGrid { align-items: flex-start; }

@media (max-width: 460px) {
  #navLanes .lane { min-width: 26px; height: 26px; font-size: 12px; }
  #navUpcoming .up-item { width: 22px; height: 22px; font-size: 10px; }
}

/* ============ v32 ============ */
/* Recurring-trip / rest / fuel banner chips */
.banner.chip-banner{display:flex;align-items:center;gap:8px;flex-wrap:wrap;position:fixed;left:50%;bottom:96px;transform:translateX(-50%);background:var(--card);border:1px solid var(--border);box-shadow:0 10px 30px rgba(0,0,0,.25);padding:8px 12px;border-radius:14px;z-index:1100;max-width:92vw}
.banner.chip-banner .rc-title{font-weight:700;font-size:13px;color:var(--text)}
.banner.chip-banner .rc-sub{font-size:11.5px;color:var(--muted)}
.banner.chip-banner .btn{white-space:nowrap}
.banner.chip-banner.hidden{display:none}
/* Routing profile badge next to the distance in the directions summary */
.ds-mode{display:inline-block;font-size:10.5px;font-weight:700;background:rgba(37,99,235,.14);color:var(--accent,#2563eb);border:1px solid rgba(37,99,235,.3);padding:1px 6px;border-radius:20px;vertical-align:middle;margin-left:4px;text-transform:none}
/* route profile select in the directions modal */
#routeProf{border:1px solid var(--border);border-radius:8px;background:var(--card);color:var(--text);padding:6px 8px;font-size:12.5px;margin-left:6px}
#dirFromRow{display:flex;align-items:center;gap:6px;flex-wrap:wrap}
/* road-works polygon markers are Lines so nothing extra needed */

/* ============ v33 (modern SVG icons) ============ */
/* Toolbar buttons - SVG scale with the round button */
.tool svg { display:block; }
/* Bottom dock icons */
.ctrl .ico svg { display:block; }
.ctrl.main .ico svg { width: 28px; height: 28px; }
/* Pill buttons: icon + label inline */
.pill2 { display: inline-flex; align-items: center; gap: 5px; }
.pill2 svg { flex-shrink:0; display:block; }
/* Foot buttons */
.foot-btn { display: inline-flex; align-items: center; gap: 4px; }
.foot-btn svg { flex-shrink:0; display:block; }
/* Layer options: icon + label inline */
.layer-opt { display: flex; align-items: center; }
.layer-opt .lopt-ic { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; margin-right: 8px; border-radius: 6px; background: var(--glass); color: var(--muted); flex-shrink: 0; }
.layer-opt.sel .lopt-ic { color: var(--accent); background: rgba(255,107,53,.14); }
/* Logo icon sits on the orange gradient tile, so it must be white */
.brand .logo svg { color: #fff; display: block; }

/* v37: night drive + extra chrome */
body.nightdrive .leaflet-tile { filter: brightness(.55) contrast(1.1); }
body.nightdrive #navBar { background: rgba(10,20,40,.95); }
body.nightdrive #hudBar { background: rgba(10,20,40,.95); }
body.nightdrive .place-marker { box-shadow: 0 0 0 6px rgba(255,107,53,.25); }
#navSos { background: #dc2626 !important; color: #fff !important; }
.nav-btn.danger#navSos:hover { background: #b91c1c !important; }
.icon-btn.split { color: #34d399; }

/* v37 end */

/* ---------- v41 driver toolkit ---------- */
.spd-sign {
  width: 24px; height: 24px; border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, #fff 0 58%, #dc2626 58% 100%);
  color: #b91c1c; font-weight: 900; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #dc2626; box-shadow: 0 2px 6px rgba(0,0,0,.35);
}
.icon-btn.elev { color: #a78bfa; }
#exitPreview { display: flex; align-items: center; gap: 8px; }
#exitPreview .ep-x { font-size: 11.5px; opacity: .9; }

/* v42: photo timelapse strip + per-track action buttons */
#tlStrip { gap: 6px; overflow-x: auto; }
#tlStrip .tl-title { font-size: 11px; font-weight: 800; white-space: nowrap; opacity: .85; flex-shrink: 0; }
#tlStrip .tl-ph { height: 64px; width: 64px; object-fit: cover; border-radius: 10px; flex-shrink: 0; opacity: .35; filter: grayscale(.6); transition: opacity .25s, filter .25s; border: 2px solid transparent; }
#tlStrip .tl-ph.on { opacity: 1; filter: none; border-color: var(--accent2, #3b82f6); }
#tlStrip::-webkit-scrollbar { height: 4px; }
.icon-btn.kmz { color: #34d399; }
.icon-btn.tl { color: #f59e0b; }
#saveVehWrap select { width: 100%; padding: 10px; margin: 6px 0; background: var(--bg2); border: 1px solid var(--stroke); color: var(--text); border-radius: var(--r-sm); }

/* v43: photo gallery overlay + import help */
.vg-overlay { position: fixed; inset: 0; z-index: 4000; background: rgba(2,6,16,.94); display: flex; align-items: center; justify-content: center; }
.vg-slide { max-width: 94vw; max-height: 86vh; display: flex; flex-direction: column; align-items: center; }
.vg-img { max-width: 94vw; max-height: 76vh; border-radius: 12px; box-shadow: 0 8px 40px rgba(0,0,0,.6); object-fit: contain; }
.vg-cap { margin-top: 10px; font-size: 13px; color: #cfe0f2; text-align: center; }
.vg-count { opacity: .6; }
.vg-x { position: absolute; top: 14px; right: 18px; font-size: 26px; color: #fff; cursor: pointer; opacity: .8; padding: 6px; }
.vg-nav { position: absolute; left: 10px; right: 10px; top: 50%; transform: translateY(-50%); display: flex; justify-content: space-between; pointer-events: none; }
.vg-nav button { pointer-events: auto; background: rgba(255,255,255,.12); border: 0; color: #fff; font-size: 30px; width: 48px; height: 56px; border-radius: 12px; cursor: pointer; }
.help-card .help-step { padding: 9px 12px; margin: 8px 0; background: var(--bg2); border: 1px solid var(--stroke); border-radius: 10px; font-size: 13px; line-height: 1.5; }
.icon-btn.gal { color: #f472b6; }
.icon-btn.cmp { color: #fb923c; }
.icon-btn.cln { color: #34d399; }

/* ---------- Car mode: big-touch Android head-unit dashboards ---------- */
#carDock { position: fixed; left: 50%; transform: translateX(-50%); bottom: 12px; z-index: 980; display: flex; gap: 10px; padding: 8px 10px; background: rgba(10, 20, 35, .88); border-radius: 20px; border: 1px solid rgba(255, 255, 255, .12); box-shadow: 0 8px 28px rgba(0, 0, 0, .45); }
.carrep { min-width: 92px; min-height: 62px; border: none; border-radius: 16px; color: #fff; font-size: 15px; font-weight: 800; display: flex; align-items: center; justify-content: center; gap: 7px; padding: 0 16px; box-shadow: 0 4px 14px rgba(0, 0, 0, .35); letter-spacing: .2px; }
.carrep:active, .carrep:focus { transform: scale(.94); }
.rep-police { background: #2563eb; }
.rep-cam { background: #dc2626; }
.rep-acc { background: #ea580c; }
.rep-haz { background: #ca8a04; }
body.car-mode .pill2, body.car-mode .mini2, body.car-mode .foot-btn { min-height: 52px; font-size: 15px; }
body.car-mode .pill2 svg, body.car-mode .mini2 svg { width: 19px; height: 19px; }
body.car-mode .top-bar { height: 62px; }
body.car-mode #hudSpeedBig { font-size: 54px !important; }
body.car-mode #hudBar { padding: 16px 20px; min-width: 220px; }
body.car-mode #hudLimit, body.car-mode #hudScore, body.car-mode #hudEvents, body.car-mode #hudCurve, body.car-mode #hudGps { font-size: 15px !important; }
body.car-mode .hud-v { font-size: 24px; }
body.car-mode .hud-l { font-size: 13px; }
body.car-mode #turnText { font-size: 30px !important; font-weight: 800; }
body.car-mode #turnDist { font-size: 20px !important; }
body.car-mode .nav-btn { min-height: 54px; min-width: 92px; font-size: 16px; }
body.car-mode .leaflet-control-zoom a { width: 46px; height: 46px; line-height: 46px; font-size: 22px; }
body.car-mode #navHud .hud-v { font-size: 22px; }
@media (orientation: landscape) and (max-height: 460px) {
  body.car-mode .pill2, body.car-mode .mini2, body.car-mode .foot-btn { min-height: 50px; }
  body.car-mode #carDock { bottom: 8px; }
}

/* ============ v53x UI refresh ============ */
/* Modern glass surfaces, floating top chips, friendly focus rings, refined controls */

:root {
  --r-lg: 22px; --r-md: 16px; --r-sm: 12px;
  --shadow-sm: 0 8px 24px rgba(0,0,0,.4);
  --shadow-lg: 0 26px 60px rgba(0,0,0,.55);
}

/* Keyboard / accessibility focus rings */
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px;
}

/* Friendly glass chip for every pill button (they had no base look before) */
.pill2 {
  background: rgba(255,255,255,.055); border: 1px solid var(--stroke); color: var(--text);
  border-radius: 999px; padding: 7px 13px; font-size: 12.5px; font-weight: 650; cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.05);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.pill2:hover { background: rgba(255,255,255,.09); }
.pill2.active { box-shadow: 0 6px 18px rgba(37,99,235,.45); }

/* Top bar: two floating glass capsules instead of a full-width tint */
#topbar { background: transparent; padding: 8px 10px; padding-top: max(10px, env(safe-area-inset-top)); }
.brand {
  background: rgba(18,29,48,.75); backdrop-filter: blur(16px) saturate(140%); -webkit-backdrop-filter: blur(16px) saturate(140%);
  border: 1px solid var(--stroke); border-radius: 18px; padding: 4px 12px 4px 5px; box-shadow: var(--shadow-sm); gap: 8px;
}
.top-tools { padding: 4px; border: 1px solid var(--stroke); border-radius: 20px; background: rgba(18,29,48,.75); box-shadow: var(--shadow-sm); }
.tool { border-radius: 14px; box-shadow: inset 0 1px 0 rgba(255,255,255,.05); }
.tool:hover { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.22); }

/* Bottom dock */
#controls { border-radius: 26px; padding: 8px 6px 10px; background: linear-gradient(180deg, rgba(22,35,57,.92), rgba(13,22,37,.92)); }
.ctrl .ico { border-radius: 16px; }
.ctrl.active .ico { background: var(--grad2); color: #fff; border-color: transparent; }

/* Sheet */
.sheet { border: 1px solid rgba(255,255,255,.12); }
.sheet-handle { width: 52px; height: 5px; border-radius: 3px; background: linear-gradient(90deg, var(--accent), var(--accent2)); opacity: .85; }
.sheet-head { padding: 14px 18px 10px; }

/* Toast -> capsule with glowing status dot */
.toast { border-radius: 999px; padding: 13px 22px; border: 1px solid var(--stroke); background: rgba(13,22,38,.96); display: flex; align-items: center; justify-content: center; gap: 8px; }
.toast::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); flex-shrink: 0; }
.toast.error::before { background: var(--danger); box-shadow: 0 0 10px var(--danger); }
.toast.success::before { background: var(--accent2); box-shadow: 0 0 10px var(--accent2); }

/* Stats strip */
#stats { border-radius: 18px; padding: 10px 20px; background: rgba(15,25,42,.8); }
.stat { padding: 0 13px; }
.stat + .stat { border-left: 1px solid var(--stroke); }

/* Layers panel */
.panel-box { border-radius: 20px; padding: 14px; border: 1px solid rgba(255,255,255,.12); }
.layer-opt { padding: 11px 9px; border-radius: 14px; }
.layer-opt:hover { background: var(--glass); }
.layer-opt.sel { background: linear-gradient(90deg, rgba(255,107,53,.16), rgba(255,61,90,.05)); }
.layer-opt.sel .chk { box-shadow: 0 0 12px rgba(255,107,53,.65); }
.ovr-h { letter-spacing: 1.2px; }

/* Modals + lists + buttons */
.modal { background: rgba(4,8,16,.72); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.modal-box { border-radius: 24px; border: 1px solid rgba(255,255,255,.12); }
.btn { border-radius: 14px; }
.btn.sm { border-radius: 10px; }
.btn.ghost:hover { background: rgba(255,255,255,.09); }
.list-item { border-radius: 18px; }
.foot-btn { border-radius: 14px; }
.icon-btn { border-radius: 12px; }

/* Search results */
.search-res { padding: 12px 12px; border-radius: 14px; }
.search-res .sr-name { font-weight: 750; }

/* Dashboard cards + tabs */
.dash-card { border-radius: 18px; background: linear-gradient(180deg, rgba(255,255,255,.07), rgba(255,255,255,.03)); }
.tabs { border-radius: 18px; padding: 5px; }
.tab { border-radius: 12px; }
.tab.sel { background: var(--grad2); }

/* Nav overlay */
#navBar { border-radius: 24px; }
#turnBanner { border-radius: 18px; }

/* Gradient scrollbars inside panels */
.panel-box::-webkit-scrollbar, .sheet-body::-webkit-scrollbar, .search-results::-webkit-scrollbar { width: 5px; }
.panel-box::-webkit-scrollbar-thumb, .sheet-body::-webkit-scrollbar-thumb, .search-results::-webkit-scrollbar-thumb { background: linear-gradient(180deg, var(--accent), var(--accent2)); border-radius: 5px; }

/* ---------- v53y: master mute in the top bar ---------- */
#btnMute.active { background: var(--danger); box-shadow: 0 5px 14px rgba(255,77,109,.45); }

/* ---------- v54a: Layers panel -> Base / Overlays / Tools tabs ---------- */
.ltabs { display: flex; gap: 4px; background: rgba(255,255,255,.045); border: 1px solid var(--stroke); border-radius: 14px; padding: 4px; margin-bottom: 10px; }
.ltab { flex: 1; background: none; border: none; color: var(--muted); padding: 9px 6px; border-radius: 10px; font-size: 13px; font-weight: 800; letter-spacing: .3px; cursor: pointer; }
.ltab.sel { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; box-shadow: 0 4px 14px rgba(37,99,235,.4); }
.ovr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ovr-grid .layer-opt { padding: 10px 9px; }
.ovr-grid .lopt-ic { margin-right: 6px; }
@media (max-width: 400px) { .ovr-grid { grid-template-columns: 1fr; } }
