/* Wasm Maps. Colours are tokens here; don't hard-code new ones below.
   Motion: only transform and opacity animate, so the compositor does the work. */

:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1b2330;
  --muted: #5d6b7c;
  --faint: #93a0b0;
  --line: #e3e8ee;
  --hover: #f1f4f8;
  --accent: #2f7bf5;
  --accent-ink: #ffffff;
  --accent-soft: #e6f0ff;
  --pin: #e5484d;
  --shadow: 0 1px 2px rgba(16, 24, 40, .08), 0 6px 20px rgba(16, 24, 40, .12);
  --shadow-lg: 0 2px 6px rgba(16, 24, 40, .08), 0 18px 48px rgba(16, 24, 40, .18);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.34, 1.4, .64, 1);
  color-scheme: light;
}

/* Dark UI goes with the Dark map style (map.js sets the class; the first style follows the phone). */
:root.dark-ui {
  --bg: #15191e;
  --card: #1f252d;
  --ink: #e9eef4;
  --muted: #a3afbd;
  --faint: #6f7c8b;
  --line: #2e3640;
  --hover: #283039;
  --accent: #5b9bff;
  --accent-ink: #0b1526;
  --accent-soft: #1f3354;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, .4), 0 18px 48px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
h1 { margin: 0; }

/* ---- Map ---- */
#map { position: fixed; inset: 0; opacity: 0; transition: opacity .5s var(--ease); }
.map-ready #map { opacity: 1; }
.maplibregl-ctrl-attrib { font-size: 11px; }
.maplibregl-ctrl-bottom-right { bottom: var(--safe-bottom); }

/* The UI layer lets touches through to the map except on its own controls. */
.ui { position: fixed; inset: 0; pointer-events: none; z-index: 2; }
.ui > * { pointer-events: auto; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.icon { width: 22px; height: 22px; flex: none; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none;
  color: var(--muted); transition: transform .15s var(--ease), background-color .15s;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn:active { transform: scale(.9); }

/* ---- Search ---- */
.search {
  position: absolute; top: calc(var(--safe-top) + 12px); left: 12px; right: 12px;
  max-width: 420px; z-index: 5;
}
.search-bar {
  display: flex; align-items: center; gap: 4px; height: 50px; padding: 0 5px 0 6px;
  background: var(--card); border-radius: 25px; box-shadow: var(--shadow);
  transition: box-shadow .2s var(--ease), transform .2s var(--ease);
}
.search.open .search-bar { box-shadow: var(--shadow-lg); }
.search-icon { width: 40px; display: grid; place-items: center; color: var(--muted); }
.search-input {
  flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none;
  font: inherit; font-size: 16px; color: var(--ink);
}
.search-input::placeholder { color: var(--faint); }
.search-input::-webkit-search-cancel-button { display: none; }
.booting .search-bar { gap: 12px; padding-left: 18px; color: var(--muted); }

.results { margin-top: 8px; padding: 6px; max-height: min(60vh, 420px); overflow-y: auto; }
.result {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px; border-radius: 12px; text-align: left;
  transition: background-color .15s, transform .15s var(--ease);
}
.result:hover { background: var(--hover); }
.result:active { transform: scale(.98); }
.result-icon {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--accent-soft); color: var(--accent);
}
.result-icon .icon { width: 18px; height: 18px; }
.result-text { display: flex; flex-direction: column; min-width: 0; }
.result-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-detail { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-note { display: flex; align-items: center; gap: 10px; padding: 12px; color: var(--muted); }

/* ---- Map buttons ---- */
.fabs {
  position: absolute; right: 12px; top: calc(var(--safe-top) + 74px);
  display: flex; flex-direction: column; gap: 10px; align-items: center;
}
.fab {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: var(--card); color: var(--ink); box-shadow: var(--shadow);
  transition: transform .18s var(--ease), background-color .2s, color .2s, opacity .25s var(--ease);
}
.fab:active { transform: scale(.9); }
.fab.active { background: var(--accent); color: var(--accent-ink); }
.compass { opacity: 0; transform: scale(.6); pointer-events: none; }
.compass.shown { opacity: 1; transform: none; pointer-events: auto; }
.compass .needle { width: 26px; height: 26px; transition: transform .05s linear; }
.zoom { display: none; flex-direction: column; border-radius: 22px; box-shadow: var(--shadow); overflow: hidden; }
.zoom .fab { box-shadow: none; border-radius: 0; }
.zoom .fab + .fab { border-top: 1px solid var(--line); }

.locate {
  position: absolute; right: 12px; bottom: calc(var(--safe-bottom) + 40px);
  transition: transform .3s var(--ease), opacity .25s var(--ease), color .2s;
}
.locate.found { color: var(--accent); }
.locate.busy .icon { animation: spin 1s linear infinite; }
.has-panel .locate { opacity: 0; transform: translateY(20px); pointer-events: none; }

/* ---- Layers ---- */
.scrim { position: absolute; inset: 0; }
.layers {
  position: absolute; right: 64px; top: calc(var(--safe-top) + 74px); width: 240px; padding: 14px;
  transform-origin: top right;
}
.layers-title { font-weight: 600; margin-bottom: 10px; }
.layers-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.style-opt { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); text-align: left; }
.style-opt.on { color: var(--accent); font-weight: 600; }
.swatch {
  height: 64px; border-radius: 12px; border: 2px solid transparent; box-shadow: inset 0 0 0 1px var(--line);
  transition: border-color .2s, transform .15s var(--ease);
}
.style-opt:active .swatch { transform: scale(.95); }
.style-opt.on .swatch { border-color: var(--accent); }
/* Little map-like previews of each style (not screenshots). */
.swatch-streets { background: linear-gradient(135deg, transparent 46%, #f7d38a 46% 54%, transparent 54%), linear-gradient(45deg, #cfe8c4 30%, #f3efe6 30% 70%, #a8d4f2 70%); }
.swatch-light { background: linear-gradient(135deg, transparent 47%, #fff 47% 53%, transparent 53%), linear-gradient(45deg, #e6ece3 30%, #f5f5f3 30% 70%, #d4dde6 70%); }
.swatch-dark { background: linear-gradient(135deg, transparent 47%, #5a6270 47% 53%, transparent 53%), linear-gradient(45deg, #253029 30%, #2d3136 30% 70%, #1c2833 70%); }
.swatch-bright { background: linear-gradient(135deg, transparent 45%, #ffb04a 45% 55%, transparent 55%), linear-gradient(45deg, #b8e39f 30%, #fff8e8 30% 70%, #86c8f5 70%); }
.layers-foot { margin-top: 12px; font-size: 11px; color: var(--faint); }

/* ---- Place / directions panel: bottom sheet on phones ---- */
.panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 58vh; overflow-y: auto; overscroll-behavior: contain;
  padding: 8px 18px calc(var(--safe-bottom) + 18px);
  border-radius: 20px 20px 0 0; box-shadow: var(--shadow-lg);
}
.grabber { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 10px; }
.place-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.place-name { font-size: 21px; line-height: 1.25; font-weight: 700; letter-spacing: -.01em; }
.place-detail { color: var(--muted); margin-top: 3px; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); margin-bottom: 2px; }
.place-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 42px; padding: 0 18px; border-radius: 21px;
  border: 1px solid var(--line); font-weight: 600; color: var(--accent);
  transition: transform .15s var(--ease), background-color .15s;
}
.btn .icon { width: 19px; height: 19px; }
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(.95); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.coords { margin-top: 14px; font-size: 13px; color: var(--faint); font-variant-numeric: tabular-nums; }

.modes { display: flex; gap: 8px; margin: 14px 0 4px; }
.mode {
  display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 14px; border-radius: 19px;
  background: var(--hover); color: var(--muted); font-weight: 600; font-size: 14px;
  transition: background-color .2s, color .2s, transform .15s var(--ease);
}
.mode .icon { width: 19px; height: 19px; }
.mode:active { transform: scale(.94); }
.mode.on { background: var(--accent-soft); color: var(--accent); }

.route-summary { display: flex; align-items: baseline; gap: 10px; margin-top: 14px; }
.route-time { font-size: 26px; font-weight: 700; color: var(--accent); letter-spacing: -.01em; }
.route-dist { color: var(--muted); font-size: 16px; }
.route-from { color: var(--faint); font-size: 13px; margin-top: 2px; }
.route-error { margin-top: 14px; color: var(--muted); }
.route-error p { margin: 0 0 12px; }
.steps { list-style: none; margin: 14px 0 0; padding: 0; border-top: 1px solid var(--line); }
.step {
  display: flex; justify-content: space-between; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--line);
  cursor: pointer; transition: background-color .15s;
}
.step:hover { background: var(--hover); }
.step-text { min-width: 0; }
.step-dist { color: var(--faint); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }

.loading { flex-direction: column; gap: 8px; }
.shimmer { display: block; height: 16px; border-radius: 8px; background: var(--hover); position: relative; overflow: hidden; }
.shimmer::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .5), transparent);
  transform: translateX(-100%); animation: sweep 1.1s infinite;
}
.w60 { width: 60%; height: 24px; } .w40 { width: 40%; }

/* ---- Markers ---- */
.pin { width: 32px; height: 42px; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .3)); }
.pin svg { width: 100%; height: 100%; display: block; }
.pin path { fill: var(--pin); stroke: #fff; stroke-width: 1.5; }
.pin circle { fill: #fff; }
.pin.drop svg { animation: drop .5s var(--spring) both; transform-origin: 50% 100%; }
.me { width: 22px; height: 22px; position: relative; }
.me .dot { position: absolute; inset: 3px; border-radius: 50%; background: var(--accent); border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .35); }
.me .pulse { position: absolute; inset: -12px; border-radius: 50%; background: var(--accent); opacity: .25; animation: pulse 2s var(--ease) infinite; }

/* ---- Messages ---- */
.toast, .hint {
  position: absolute; left: 50%; bottom: calc(var(--safe-bottom) + 100px); translate: -50% 0;
  max-width: min(92vw, 420px); padding: 11px 16px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-size: 14px; box-shadow: var(--shadow-lg);
}
.hint { pointer-events: none; animation: pop .35s var(--spring) both, fade-out .4s 4s var(--ease) forwards; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent);
  display: inline-block; animation: spin .8s linear infinite; flex: none;
}

#blazor-error-ui {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; padding: 12px 16px;
  background: #fff4e5; color: #6b3d00;
}
#blazor-error-ui .reload { margin-left: 8px; }
#blazor-error-ui .dismiss { float: right; cursor: pointer; }

/* ---- Entrances ---- */
.rise { animation: rise .35s var(--ease) both; animation-delay: calc(var(--i, 0) * 35ms); }
.pop { animation: pop .28s var(--spring) both; }
.slide { animation: slide-up .38s var(--ease) both; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes pop { from { opacity: 0; transform: scale(.92); } }
@keyframes slide-up { from { transform: translateY(100%); } }
@keyframes slide-in { from { opacity: 0; transform: translateX(-24px); } }
@keyframes drop { 0% { opacity: 0; transform: translateY(-30px) scale(.7); } 100% { opacity: 1; transform: none; } }
@keyframes pulse { 0% { transform: scale(.4); opacity: .45; } 100% { transform: scale(1.4); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes sweep { to { transform: translateX(100%); } }
@keyframes fade-out { to { opacity: 0; } }

/* ---- Desktop: panel becomes a card on the left under the search bar ---- */
@media (min-width: 800px) {
  .search { left: 16px; right: auto; width: 400px; top: 16px; }
  .panel {
    left: 16px; right: auto; top: 78px; bottom: auto; width: 400px; max-height: calc(100vh - 110px);
    border-radius: var(--radius); padding: 16px 20px 20px;
  }
  .grabber { display: none; }
  .slide { animation-name: slide-in; }
  .zoom { display: flex; }
  .fabs { top: 16px; right: 16px; }
  .layers { top: 16px; right: 70px; }
  .locate { right: 16px; bottom: 40px; }
  .has-panel .locate { opacity: 1; transform: none; pointer-events: auto; }
  .toast, .hint { bottom: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
}
