:root {
  --bg: #eef2f8; --panel: #ffffff; --raise: #f6f8fc; --text: #0f1a2e; --muted: #5a6780; --line: #dfe5ee;
  --brand: #0f2557; --brand-text: #ffffff;
  --accent: #1d4fb8; --accent-hover: #173f94; --accent-text: #ffffff; --accent-soft: #e5edfb;
  --hero-1: #1d4fb8; --hero-2: #0f2557;
  --warn: #8a5a00; --warn-soft: #fff4d9; --bad: #b42328; --ok: #127a43;
  --route: #1d4fb8; --place: #0f2557;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f17; --panel: #121826; --raise: #182032; --text: #e9edf5; --muted: #98a3b8; --line: #263049;
    --brand: #0a1a3f;
    --accent: #6f9cf5; --accent-hover: #8cb0f8; --accent-text: #0a1222; --accent-soft: #1a2742;
    --hero-1: #2556c4; --hero-2: #10285e;
    --warn: #f2c66a; --warn-soft: #33290f; --bad: #f08a8a; --ok: #2f9e62;
    --route: #4f84f0; --place: #9fbcf5;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0f17; --panel: #121826; --raise: #182032; --text: #e9edf5; --muted: #98a3b8; --line: #263049;
  --brand: #0a1a3f;
  --accent: #6f9cf5; --accent-hover: #8cb0f8; --accent-text: #0a1222; --accent-soft: #1a2742;
  --hero-1: #2556c4; --hero-2: #10285e;
  --warn: #f2c66a; --warn-soft: #33290f; --bad: #f08a8a; --ok: #2f9e62;
  --route: #4f84f0; --place: #9fbcf5;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--brand); color: var(--brand-text);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 800; font-size: 17px; letter-spacing: -.01em; white-space: nowrap; }
.brand img { border-radius: 7px; box-shadow: 0 0 0 1px rgba(255,255,255,.25); }
.when { font-size: 13px; font-weight: 600; background: rgba(255,255,255,.12); padding: 5px 10px; border-radius: 999px; white-space: nowrap; }
@media (max-width: 420px) { .brand { font-size: 15px; gap: 8px; } .brand img { width: 24px; height: 24px; } .when { font-size: 12px; padding: 4px 9px; } }

/* ---------- Layout: one column on phones, panel beside a full-height map on wider screens ---------- */
.layout { display: flex; flex-direction: column; }
#map { height: 320px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--raise); z-index: 0; }
/* Phones: the panel's sections and the map share one column, ordered search/results, map, footer. */
@media (max-width: 899px) {
  .panel { display: contents; }
  #search, #results { order: 1; padding: 22px 16px 0; }
  .map-wrap { order: 2; padding: 18px 16px 0; }
  footer { order: 3; margin: 24px 16px 0; padding-bottom: max(28px, env(safe-area-inset-bottom)); }
}

@media (min-width: 900px) {
  body { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
  .topbar { padding: 12px 24px; }
  .layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(400px, 460px) 1fr; }
  .panel {
    overflow-y: auto; padding: 32px 28px 12px; background: var(--panel);
    border-right: 1px solid var(--line); box-shadow: 4px 0 24px rgba(15, 26, 46, .08); z-index: 1;
  }
  .map-wrap { padding: 0; position: relative; }
  #map { position: absolute; inset: 0; height: auto; border: 0; border-radius: 0; }
}
@media (min-width: 1400px) { .layout { grid-template-columns: 500px 1fr; } }

/* ---------- Step 1: search ---------- */
.context { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 14px; font-size: 14px; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 999px; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
h1 { font-size: 30px; line-height: 1.1; letter-spacing: -.02em; margin: 0 0 8px; }
@media (min-width: 900px) { h1 { font-size: 34px; } }
.lede { color: var(--muted); margin: 0 0 22px; font-size: 16px; }

.cta {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 12px;
  border: 0; border-radius: 16px; padding: 18px 20px; min-height: 64px; cursor: pointer;
  background: linear-gradient(135deg, var(--hero-1), var(--hero-2)); color: #fff;
  font-size: 19px; font-weight: 800; letter-spacing: -.005em;
  box-shadow: 0 8px 24px rgba(29, 79, 184, .35), inset 0 1px 0 rgba(255,255,255,.15);
  transition: transform .12s ease, box-shadow .12s ease;
}
.cta:hover { transform: translateY(-1px); box-shadow: 0 12px 28px rgba(29, 79, 184, .42), inset 0 1px 0 rgba(255,255,255,.15); }
.cta:active { transform: translateY(0); }
.cta svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; }
.cta svg .fill { fill: currentColor; stroke: none; }
.cta:disabled { opacity: .75; cursor: progress; transform: none; }
.cta.loading svg { animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.privacy { font-size: 13px; color: var(--muted); margin: 10px 0 0; text-align: center; }
.privacy svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2.2; vertical-align: -2px; margin-right: 4px; }

.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; font-weight: 600; margin: 26px 0 12px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

input[type=text], select {
  width: 100%; padding: 12px 14px; min-height: 50px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--text); font: inherit; font-size: 16px;
}
input[type=text]:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.combo { position: relative; display: flex; gap: 8px; }
.combo input { flex: 1; min-width: 0; }
.combo button {
  border: 1px solid var(--line); background: var(--raise); border-radius: 12px; padding: 0 18px; min-height: 50px;
  font-weight: 700; cursor: pointer;
}
.combo button:hover { border-color: var(--accent); color: var(--accent); }
.combo button:disabled { opacity: .6; cursor: progress; }
#suggestions {
  position: absolute; z-index: 1000; left: 0; right: 0; top: calc(100% + 6px); margin: 0; padding: 6px; list-style: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,.18);
}
#suggestions li { padding: 11px 12px; border-radius: 8px; cursor: pointer; font-size: 15px; }
#suggestions li[aria-selected="true"], #suggestions li:hover { background: var(--accent-soft); }

.status { font-size: 14px; margin: 10px 0 0; color: var(--muted); }
.status:empty { display: none; }
.status.error { color: var(--bad); font-weight: 600; }

.browse { margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line); }
.browse label { display: block; font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
select { font-weight: 600; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }

details.all { margin-top: 14px; }
details.all summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-weight: 700; font-size: 15px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--raise);
}
details.all summary::-webkit-details-marker { display: none; }
details.all summary::after { content: "▾"; color: var(--muted); transition: transform .15s; }
details.all[open] summary::after { transform: rotate(180deg); }
details.all[open] summary { border-radius: 12px 12px 0 0; }
details.all .places { border-radius: 0 0 12px 12px; border-top: 0; }

/* ---------- Step 2: results ---------- */
.from-bar {
  display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted);
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--raise); margin-bottom: 14px;
}
.from-dot { width: 12px; height: 12px; border-radius: 50%; background: #1a73e8; box-shadow: 0 0 0 3px rgba(26,115,232,.25); flex-shrink: 0; }
.from-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.from-text b { color: var(--text); }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 700; cursor: pointer; padding: 4px 2px; }

.notice {
  background: var(--warn-soft); border: 1px solid var(--line); border-left: 4px solid var(--warn);
  border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: 14px;
}
.notice p { margin: 0 0 8px; }
.notice button { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; font-size: 14px; font-weight: 600; cursor: pointer; }

.hero {
  position: relative; overflow: hidden; color: #fff; border-radius: 20px; padding: 22px 20px 20px;
  background: radial-gradient(120% 140% at 100% 0%, rgba(255,255,255,.16), transparent 55%),
              linear-gradient(150deg, var(--hero-1), var(--hero-2));
  box-shadow: 0 14px 36px rgba(15, 37, 87, .35);
  animation: rise .35s ease-out both;
}
/* Slide only, never fade: if a browser stalls animations, the card must still be visible. */
@keyframes rise { from { transform: translateY(8px); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) { .hero, .toast { animation: none; } .cta { transition: none; } }
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.hero-label {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase;
  background: rgba(255,255,255,.16); padding: 5px 10px 5px 8px; border-radius: 999px; white-space: nowrap;
}
.hero-label svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.hero-district { font-size: 13px; opacity: .8; font-weight: 600; text-align: right; }
.hero h2 { font-size: 26px; line-height: 1.15; letter-spacing: -.015em; margin: 0 0 4px; }
.hero .addr { margin: 0; opacity: .85; font-size: 16px; }
.hero-stat { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; margin: 18px 0 20px; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.18); }
.hero-stat b { font-size: 44px; line-height: 1; font-weight: 800; letter-spacing: -.03em; }
.hero-stat span { font-size: 15px; opacity: .85; line-height: 1.3; }
.hero .approx { background: rgba(255, 214, 102, .2); color: #ffe29a; }
.hero .actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.hero .btn { border: 0; min-height: 54px; font-size: 17px; border-radius: 14px; }
.hero .btn.go { background: #fff; color: #0f2557; box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.hero .btn.go:hover { background: #eef3ff; }
.hero .btn.share { background: rgba(255,255,255,.16); color: #fff; padding: 0 20px; }
.hero .btn.share:hover { background: rgba(255,255,255,.26); }
.hero .manual-link { color: rgba(255,255,255,.85); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-align: center; text-decoration: none;
  border-radius: 10px; padding: 10px 14px; min-height: 44px; font-weight: 700; font-size: 15px; cursor: pointer;
  background: var(--raise); color: var(--text); border: 1px solid var(--line);
}
.btn:hover { border-color: var(--accent); }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.btn.go { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.go:hover { background: var(--accent-hover); }
.approx { display: inline-block; font-size: 12px; font-weight: 700; color: var(--warn); background: var(--warn-soft); border-radius: 6px; padding: 3px 8px; margin-top: 8px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin: 16px 0 0; background: var(--raise); border: 1px solid var(--line); border-radius: 12px; }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; text-align: center; padding: 9px 8px; border-radius: 9px; font-weight: 700; font-size: 14px; color: var(--muted); }
.seg input:checked + span { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.14); }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 1px; }

.list-title { font-size: 13px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 26px 0 10px; }
.places { list-style: none; margin: 0 0 8px; padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); overflow: hidden; }
.places li { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 14px; border-top: 1px solid var(--line); }
.places li:first-child { border-top: 0; }
.places .rank { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 13px; align-self: flex-start; }
.places .info { flex: 1; min-width: 0; }
.places b { display: block; font-size: 15px; line-height: 1.3; }
.places .addr { color: var(--muted); font-size: 14px; }
.places .trip { font-size: 14px; font-weight: 700; margin-top: 3px; color: var(--text); }
.places .row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.places .row-actions .btn { min-height: 40px; padding: 6px 11px; font-size: 14px; }
/* Phones: buttons get their own row under the name, so the address isn't squeezed. */
@media (max-width: 899px) {
  .places .row-actions { flex-basis: 100%; padding-left: 40px; }
  .places .row-actions .btn { flex: 1; }
  details.all .places .row-actions { padding-left: 0; }
}
/* Secondary to the result card: outlined, not filled. */
.places .row-actions .btn.go { background: var(--panel); color: var(--accent); border-color: var(--line); }
.places .row-actions .btn.go:hover { border-color: var(--accent); background: var(--accent-soft); }
.city-head { background: var(--raise); font-size: 12px; font-weight: 800; color: var(--muted); padding: 8px 14px !important; text-transform: uppercase; letter-spacing: .06em; }

.manual-link { display: block; width: 100%; font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 0; }
.manual-link input { margin-top: 6px; font-size: 14px; min-height: 42px; }

footer { color: var(--muted); font-size: 13px; margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); }
footer p { margin: 0 0 8px; }

/* ---------- Map ---------- */
.leaflet-container { font: inherit; }
.leaflet-popup-content-wrapper { border-radius: 12px; }
.leaflet-popup-content { font-size: 14px; line-height: 1.4; margin: 12px 14px; }
.leaflet-popup-content b { font-size: 15px; }
.you-dot { width: 18px; height: 18px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(26,115,232,.25), 0 1px 4px rgba(0,0,0,.4); }
.vote-pin {
  position: absolute; transform: translate(-50%, calc(-100% - 10px));
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
  background: linear-gradient(150deg, var(--hero-1), var(--hero-2)); color: #fff; font-weight: 800; font-size: 13px;
  padding: 7px 11px 7px 9px; border-radius: 10px; border: 2px solid #fff; box-shadow: 0 6px 16px rgba(0,0,0,.35);
}
.vote-pin svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.vote-pin::after { content: ""; position: absolute; left: 50%; bottom: -9px; transform: translateX(-50%); border: 8px solid transparent; border-top-color: #fff; border-bottom: 0; }
.vote-pin::before { content: ""; position: absolute; left: 50%; bottom: -5px; transform: translateX(-50%); border: 6px solid transparent; border-top-color: var(--hero-2); border-bottom: 0; z-index: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 2000;
  display: flex; align-items: center; gap: 10px; white-space: nowrap;
  background: #0f1a2e; color: #fff; padding: 13px 18px 13px 13px; border-radius: 14px; font-weight: 700; font-size: 15px;
  box-shadow: 0 10px 30px rgba(0,0,0,.3); max-width: calc(100% - 32px);
  animation: toast-in .2s ease-out both;
}
:root[data-theme="dark"] .toast { background: #f1f4fa; color: #0f1a2e; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .toast { background: #f1f4fa; color: #0f1a2e; } }
.toast .check { width: 24px; height: 24px; border-radius: 50%; background: #127a43; display: grid; place-items: center; flex-shrink: 0; }
.toast .check svg { width: 14px; height: 14px; fill: none; stroke: #fff; stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }
@keyframes toast-in { from { transform: translate(-50%, 10px); } to { transform: translate(-50%, 0); } }
