:root {
  color-scheme: light dark;
  --bg: rgba(255, 255, 255, 0.92);
  --bg-solid: #ffffff;
  --fg: #1c1c1e;
  --muted: #6b6b70;
  --line: rgba(0, 0, 0, 0.1);
  --accent: #2f7d4f;       /* DinoMaps green */
  --accent-fg: #ffffff;
  --route: #2f7d4f;
  --route-alt: #9aa5b1;
  --from: #2f7d4f;
  --to: #d9463e;
  --hover: rgba(0, 0, 0, 0.05);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: rgba(28, 28, 30, 0.92);
    --bg-solid: #1c1c1e;
    --fg: #f2f2f7;
    --muted: #a1a1a8;
    --line: rgba(255, 255, 255, 0.12);
    --accent: #4fae72;
    --hover: rgba(255, 255, 255, 0.06);
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: var(--font); color: var(--fg); background: #e9e5dc; }
#map { position: fixed; inset: 0; width: 100vw; height: 100vh; }

/* Panel ------------------------------------------------------------------ */
.panel {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  width: 360px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  background: var(--bg);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  z-index: 5;
}
.panel[hidden] { display: none; }
.panel-head { display: flex; align-items: center; gap: 12px; padding: 12px 12px 8px 14px; }
.panel-head img { border-radius: 9px; }
.panel-head .title { flex: 1; min-width: 0; }
.panel-head h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.panel-head p { margin: 1px 0 0; font-size: 12px; color: var(--muted); }

.tabs { display: flex; gap: 4px; padding: 0 12px; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; padding: 9px 4px; border: 0; background: none; color: var(--muted);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; position: relative;
}
.tab.is-active { color: var(--fg); }
.tab.is-active::after { content: ""; position: absolute; left: 10%; right: 10%; bottom: -1px; height: 2px; background: var(--accent); border-radius: 2px; }

.tab-page { display: none; padding: 12px; overflow: hidden auto; }
.tab-page.is-active { display: block; }

.field { display: flex; align-items: center; gap: 6px; }
.field input {
  flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-solid); color: var(--fg); font: inherit; font-size: 15px; outline: none;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.point-field { margin-top: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; border: 2px solid var(--bg-solid); box-shadow: 0 0 0 1px var(--line); }
.dot.from { background: var(--from); }
.dot.to { background: var(--to); }

.icon-btn {
  border: 0; background: var(--hover); color: var(--fg); width: 34px; height: 34px; border-radius: 10px;
  font: inherit; font-size: 18px; line-height: 1; cursor: pointer; flex: none;
}
.icon-btn:hover { background: color-mix(in srgb, var(--hover) 60%, var(--accent) 20%); }
.icon-btn.small { width: 32px; height: 32px; font-size: 15px; }
.icon-btn.is-active { background: var(--accent); color: var(--accent-fg); }

.results { list-style: none; margin: 8px 0 0; padding: 0; }
.results li { display: flex; gap: 10px; align-items: center; padding: 9px 8px; border-radius: 10px; cursor: pointer; }
.results li:hover, .results li:focus-visible { background: var(--hover); outline: none; }
.results .kind { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--hover); font-size: 15px; flex: none; }
.results .text { min-width: 0; }
.results .name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.results .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.results.compact li { padding: 6px 8px; }
.results.compact .kind { width: 22px; height: 22px; font-size: 12px; }
.results.compact .name { font-size: 14px; }

.hint { margin: 10px 2px 0; font-size: 12px; color: var(--muted); }
.hint.error { color: var(--to); }

.modes { display: flex; gap: 6px; margin-bottom: 4px; }
.mode { flex: 1; padding: 7px 4px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-solid); color: var(--fg); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.mode.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }

.options { margin: 10px 2px 0; font-size: 13px; color: var(--muted); }
.options summary { cursor: pointer; font-weight: 600; }
.options label { display: block; margin: 6px 0 0 2px; color: var(--fg); }

.primary {
  margin-top: 12px; width: 100%; padding: 11px; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-fg); font: inherit; font-size: 15px; font-weight: 700; cursor: pointer;
}
.primary:disabled { opacity: 0.45; cursor: default; }

.summary { margin: 12px 0 0; padding: 10px 12px; border-radius: 12px; background: var(--hover); display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; }
.summary .big { font-size: 22px; font-weight: 700; }
.summary .alt { width: 100%; font-size: 12px; color: var(--muted); }
.summary .alt button { font: inherit; color: var(--accent); background: none; border: 0; cursor: pointer; padding: 0 2px; text-decoration: underline; }
.summary .alt button.is-active { font-weight: 700; text-decoration: none; }

.steps { list-style: none; margin: 10px 0 0; padding: 0; }
.steps li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 6px; border-top: 1px solid var(--line); cursor: pointer; border-radius: 8px; }
.steps li:hover { background: var(--hover); }
.steps .sign { width: 26px; text-align: center; font-size: 18px; line-height: 22px; flex: none; }
.steps .what { font-size: 14px; }
.steps .dist { font-size: 12px; color: var(--muted); }

.panel-foot { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px 10px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); }
.panel-foot a { color: var(--muted); text-decoration: none; }
.panel-foot a:hover { color: var(--fg); text-decoration: underline; }

.expand {
  position: fixed; top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left));
  width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--bg); box-shadow: var(--shadow);
  display: grid; place-items: center; cursor: pointer; z-index: 5;
}
.expand[hidden] { display: none; }
.expand img { border-radius: 7px; }

.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--fg); color: var(--bg-solid); padding: 10px 14px; border-radius: 12px; font-size: 14px;
  box-shadow: var(--shadow); z-index: 6; max-width: calc(100vw - 32px);
}
.toast[hidden] { display: none; }

/* Markers and popups ----------------------------------------------------- */
.marker { width: 22px; height: 22px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.marker.from { background: var(--from); }
.marker.to { background: var(--to); }
.marker.pin { background: var(--accent); }
.maplibregl-popup-content { font-family: var(--font); border-radius: 12px; padding: 12px 14px; color: #1c1c1e; }
.maplibregl-popup-content h3 { margin: 0 0 2px; font-size: 15px; }
.maplibregl-popup-content p { margin: 0 0 8px; font-size: 12px; color: #6b6b70; }
.maplibregl-popup-content .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.maplibregl-popup-content .actions button, .maplibregl-popup-content .actions a {
  font: inherit; font-size: 13px; font-weight: 600; padding: 6px 10px; border-radius: 9px; border: 0;
  background: #2f7d4f; color: #fff; cursor: pointer; text-decoration: none;
}
.maplibregl-popup-content .actions .secondary { background: rgba(0,0,0,.08); color: #1c1c1e; }
.maplibregl-ctrl-top-right { top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); }
.maplibregl-ctrl-group { border-radius: 12px; box-shadow: var(--shadow); }
.maplibregl-ctrl-attrib { font-family: var(--font); border-radius: 10px; }

/* Phones: panel becomes a bottom sheet ----------------------------------- */
@media (max-width: 640px) {
  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; max-width: none;
    max-height: 62vh; border-radius: var(--radius) var(--radius) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel-head { padding-top: 10px; }
  .panel-head p { display: none; }
  .expand { top: auto; bottom: max(16px, env(safe-area-inset-bottom)); }
  .maplibregl-ctrl-top-right { top: max(12px, env(safe-area-inset-top)); }
}

/* Themes ------------------------------------------------------------------ */
.theme-h { margin: 12px 2px 6px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.theme-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.theme-card { display: flex; flex-direction: column; gap: 5px; padding: 5px; border: 2px solid transparent; border-radius: 12px; background: var(--hover); font: inherit; color: var(--fg); cursor: pointer; text-align: left; }
.theme-card:hover { border-color: var(--line); }
.theme-card.is-selected { border-color: var(--accent); }
.theme-name { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 2px; }
.swatch { position: relative; height: 54px; border-radius: 8px; overflow: hidden; }
.swatch i { position: absolute; display: block; border-radius: 3px; }
.sw-water { right: -10%; bottom: -20%; width: 55%; height: 60%; border-radius: 50% !important; }
.sw-road { height: 7%; transform: rotate(-12deg); transform-origin: left center; }
.sw-building { left: 12%; bottom: 10%; width: 22%; height: 26%; }
.theme-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.theme-actions .primary { width: auto; margin: 0; padding: 9px 12px; font-size: 14px; }
.secondary, .danger { padding: 9px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-solid); color: var(--fg); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-block; }
.secondary:hover { border-color: var(--accent); }
.danger { color: var(--to); }
.select-row { display: flex; align-items: center; gap: 8px; margin: 8px 0 0 2px; font-size: 13px; }
.select-row select { font: inherit; font-size: 13px; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg-solid); color: var(--fg); }
.editor-head { display: flex; gap: 8px; align-items: center; }
.editor-head input { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-solid); color: var(--fg); font: inherit; font-size: 16px; font-weight: 700; }
.color-row { display: grid; grid-template-columns: 34px 1fr auto 28px; gap: 8px; align-items: center; padding: 5px 2px; border-top: 1px solid var(--line); }
.color-row input[type="color"] { width: 34px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: none; cursor: pointer; }
.color-row .color-name { font-size: 14px; }
.color-row code { font-size: 11px; color: var(--muted); }
.color-row .reset { visibility: hidden; width: 28px; height: 28px; font-size: 14px; }
.color-row.is-modified .reset { visibility: visible; }
.color-row.is-modified .color-name::after { content: " •"; color: var(--accent); }

/* Live traffic (NDW) */
.options.live { margin-top: 16px; }
.options .muted { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
.legend { list-style: none; margin: 8px 0 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 10px; }
.legend label { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; color: var(--fg); cursor: pointer; }
.legend .swatch { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); flex: none; }
.legend .count { margin-left: auto; color: var(--muted); font-size: 11px; }
.live-popup .maplibregl-popup-content { max-width: 280px; }
.live-popup h3 { margin: 0 0 4px; font-size: 14px; }
.live-popup .kind { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.live-popup p { margin: 0 0 6px; font-size: 13px; }
.live-popup .when { font-size: 12px; color: var(--muted); }

/* Speed simulator */
.sim { margin: 12px 0 0; padding: 10px 12px; border-radius: 12px; background: var(--hover); }
.sim h3 { margin: 0 0 6px; font-size: 14px; }
.sim label { font-size: 13px; color: var(--muted); display: block; }
.sim output { color: var(--fg); font-weight: 600; }
.sim input[type=range] { width: 100%; margin: 6px 0 8px; accent-color: var(--accent); }
.sim-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.sim-grid div { background: var(--bg); border-radius: 8px; padding: 6px 8px; }
.sim-grid span { display: block; font-size: 11px; color: var(--muted); }
.sim-grid b { font-size: 15px; font-variant-numeric: tabular-nums; }
.sim-grid b.worse { color: var(--to); }
.sim-grid b.better { color: #2f9e44; }
.sim-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 8px; font-size: 12px; }
.sim-controls .primary.small { padding: 6px 10px; font-size: 13px; width: auto; }
.sim-controls .small:not(.primary) { padding: 6px 10px; font-size: 13px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); cursor: pointer; }
.sim-controls select { font: inherit; }
.sim-car { width: 18px; height: 34px; transform-origin: 50% 50%; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }

.summary .weather { width: 100%; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; font-size: 12px; margin-top: 2px; }
.summary .weather .muted { color: var(--muted); font-size: 11px; }

.live-popup img.cam { display: block; width: 100%; max-width: 320px; border-radius: 8px; margin: 6px 0; background: #222; min-height: 60px; }
.live-popup .maplibregl-popup-content { max-width: 340px; }
