/* RideWhereSG — dark instrument panel. One accent colour, thin borders, no gradients on controls. */
:root {
  --bg: #0a0c0e;
  --panel: #0e1216;
  --panel-2: #141b22;
  --line: #1e262e;
  --line-strong: #2a3540;
  --text: #e8eef4;
  --muted: #8b98a6;
  --accent: #38e08a;
  --road: #ffb020;
  --path: #5ab8ff;
  --push: #ff5c5c;
}

* { box-sizing: border-box; }

/* The spinner sets display:flex, which beats the UA [hidden] rule. Without this, hideSpinner() sets
   the attribute and the overlay stays on screen — the r8 bug. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#map { position: absolute; inset: 0; background: var(--bg); }

/* --- brand ------------------------------------------------------------------ */
.brand {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: 10px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px 7px 11px;
  background: rgba(14, 18, 22, 0.92);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  backdrop-filter: blur(6px);
}
.brand-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 224, 138, 0.16);
}
.icon-btn {
  margin-left: 4px;
  min-height: 30px;
  padding: 0 10px;
  font: 500 12px/1 inherit;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}
.icon-btn:active { background: var(--panel-2); }

/* --- dock ------------------------------------------------------------------- */
.dock {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 10px calc(8px + env(safe-area-inset-bottom));
  pointer-events: none;
}
.dock > * { pointer-events: auto; }

.hint {
  margin: 0 auto;
  padding: 7px 12px;
  max-width: 92%;
  background: rgba(14, 18, 22, 0.94);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.hud {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 16px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.stats {
  display: grid;
  grid-template-columns: 1.05fr 1fr 1fr;
  gap: 10px;
}
.stat { min-width: 0; }
.v {
  display: block;
  font-size: clamp(22px, 7.2vw, 34px);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#stat-km { color: var(--accent); }
.l {
  display: block;
  margin-top: 3px;
  font-size: 10px;
  line-height: 1.2;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.sub {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.actions { display: flex; gap: 8px; margin-top: 12px; }
.btn {
  flex: 1;
  min-height: 44px;
  padding: 0 14px;
  font: 500 14px/1 inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.btn:active { background: #1a232c; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:focus-visible, .icon-btn:focus-visible, .foot a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.toast {
  margin: 0 auto;
  max-width: 560px;
  padding: 10px 14px;
  background: #1a1214;
  border: 1px solid rgba(255, 92, 92, 0.45);
  border-radius: 10px;
  color: #ffd7d7;
  font-size: 13px;
}

.errline {
  margin: 0 auto;
  width: 100%;
  max-width: 560px;
  padding: 9px 12px;
  background: #1a1214;
  border: 1px solid rgba(255, 92, 92, 0.55);
  border-left-width: 3px;
  border-radius: 8px;
  color: #ffd7d7;
  font-size: 12.5px;
  line-height: 1.4;
}

/* ?debug=1 only */
.dbg {
  margin: 0 auto;
  width: 100%;
  max-width: 560px;
  padding: 8px 10px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.dbg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.dbg-btn { flex: 0 0 auto; min-height: 34px; font-size: 12px; padding: 0 10px; width: auto; }
.dbg pre {
  margin: 0;
  max-height: 34vh;
  overflow: auto;
  font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #c8d2dc;
  white-space: pre-wrap;
  word-break: break-word;
  font-variant-numeric: tabular-nums;
}

.foot {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: baseline;
  justify-content: space-between;
  max-width: 560px;
  margin: 0 auto;
  font-size: 10px;
  line-height: 1.5;
  color: #6f7c89;
}
.foot-src { flex: 1 1 240px; }
.foot-links { display: flex; gap: 10px; white-space: nowrap; }
.foot a { color: var(--muted); text-decoration: none; border-bottom: 1px solid var(--line-strong); }
.foot a:hover { color: var(--text); }

/* --- map bits ---------------------------------------------------------------- */
.pin {
  width: 26px; height: 26px;
  padding: 0;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #05070a;
  box-shadow: 0 0 0 2px rgba(56, 224, 138, 0.22);
  cursor: grab;
  touch-action: none;
}
.pin:active { cursor: grabbing; }
.pin-end {
  background: #f4f8fb;
  box-shadow: 0 0 0 2px rgba(244, 248, 251, 0.2);
}
.pin-via {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  background: var(--panel);
  border-color: var(--accent);
  color: var(--accent);
  font: 600 11px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  box-shadow: none;
}

.push-label {
  padding: 3px 6px;
  background: #2a1214;
  border: 1px solid var(--push);
  border-radius: 5px;
  color: #ffc2c2;
  font: 600 10px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.maplibregl-ctrl-group {
  background: var(--panel) !important;
  border: 1px solid var(--line) !important;
  border-radius: 10px !important;
  overflow: hidden;
}
.maplibregl-ctrl-group button { width: 40px !important; height: 40px !important; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line) !important; }
.maplibregl-ctrl button .maplibregl-ctrl-icon { filter: invert(0.92); }
.maplibregl-ctrl-scale {
  background: rgba(14, 18, 22, 0.85) !important;
  border-color: var(--line-strong) !important;
  color: var(--muted) !important;
  font-size: 10px !important;
  margin-bottom: 220px;
}

/* --- spinner ----------------------------------------------------------------- */
.spinner {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(14, 18, 22, 0.96);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 13px;
  color: var(--text);
}
.spinner-ring {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner-ring { animation-duration: 2.4s; }
}

/* --- about ------------------------------------------------------------------- */
.about {
  width: min(560px, calc(100vw - 24px));
  max-height: 80vh;
  padding: 20px 20px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}
.about::backdrop { background: rgba(0, 0, 0, 0.62); }
.about h2 { margin: 0 0 10px; font-size: 18px; letter-spacing: -0.01em; }
.about h3 {
  margin: 18px 0 6px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.about p { margin: 0 0 10px; color: #c8d2dc; }
.about ul { margin: 0 0 10px; padding-left: 18px; color: #c8d2dc; }
.about li { margin-bottom: 6px; }
.about a { color: var(--accent); text-decoration: none; border-bottom: 1px solid rgba(56, 224, 138, 0.35); }
.about-fine { font-size: 12px; color: var(--muted) !important; }
.about form { margin-top: 16px; }

@media (min-width: 700px) {
  .hud, .foot, .toast { max-width: 620px; }
  .hud { padding: 16px 18px 14px; }
}

/* --- search (OneMap) ---------------------------------------------------------- */
.search {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}
.search-input {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  font: 400 15px/1 inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  -webkit-appearance: none;
  appearance: none;
}
.search-input::placeholder { color: var(--muted); }
.search-input:focus { outline: none; border-color: var(--accent); }
.search.busy .search-input { border-color: var(--line-strong); }

.results {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 6px);
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.55);
  max-height: 46vh;
  overflow: auto;
}
.res { display: flex; align-items: stretch; gap: 6px; border-radius: 8px; }
.res[aria-selected="true"] { background: var(--panel-2); }
.res:focus-within { outline: 2px solid var(--accent); outline-offset: -2px; }
.res-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 10px;
  text-align: left;
  background: none;
  border: 0;
  color: var(--text);
  cursor: pointer;
}
.res-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.res-addr {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.res-acts { display: flex; align-items: center; gap: 4px; padding-right: 4px; }
.res-act {
  min-height: 32px;
  padding: 0 9px;
  font: 500 11px/1 inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}
.res-act:active { border-color: var(--accent); }
.res-empty { padding: 12px; color: var(--muted); font-size: 13px; text-align: center; }

/* --- actions: GPX gets its own row on narrow screens --------------------------- */
.actions { flex-wrap: wrap; }
#btn-gpx { flex: 1 1 100%; }

/* --- debug: first 15 segments -------------------------------------------------- */
.dbg-segs { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 6px; }
.dbg-segs summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.segs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 6px;
  font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.seg-row { display: grid; grid-template-columns: 3ch 9ch 7ch 5ch 7ch 11ch; gap: 6px; }
.seg-row > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg-head { color: var(--muted); }
.seg-flag { color: var(--road); }
.segs-empty { margin: 0; color: var(--muted); font-size: 11px; }
