:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #1b1d21;
  --muted: #5d6470;
  --border: #dcdfe4;
  --accent: #c8102e;
  --accent-text: #ffffff;
  --hover: #f0f1f3;
  --active: #f8d9df;
  --shadow: 0 2px 6px rgba(0, 0, 0, .08), 0 8px 24px rgba(0, 0, 0, .10);
  --error: #b3261e;
  --radius: 14px;
  --gutter: 16px;
  --panel-w: 380px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --map-bg: #f6f6f3;  /* = the light map's background: no flash */
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

/* Dark: follows the OS unless the user picked "lys"; or forced with data-theme="dark". */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --card: #1f2227;
    --text: #eceef1;
    --muted: #a1a8b3;
    --border: #353a42;
    --accent: #ff4d63;
    --accent-text: #1a0005;
    --hover: #2a2e35;
    --active: #57283a;
    --shadow: 0 2px 6px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .45);
    --error: #ff8a80;
    --map-bg: #0c0c0c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171a;
  --card: #1f2227;
  --text: #eceef1;
  --muted: #a1a8b3;
  --border: #353a42;
  --accent: #ff4d63;
  --accent-text: #1a0005;
  --hover: #2a2e35;
  --active: #57283a;
  --shadow: 0 2px 6px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .45);
  --error: #ff8a80;
  --map-bg: #0c0c0c;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--sans);
  -webkit-text-size-adjust: 100%;
}

#map {
  position: fixed;
  inset: 0;
  background: var(--map-bg);  /* matches the map style's own background: no flash */
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- panel ---------- */
#panel {
  position: fixed;
  top: var(--gutter);
  left: var(--gutter);
  width: var(--panel-w);
  max-width: calc(100vw - 2 * var(--gutter));
  max-height: calc(100vh - 2 * var(--gutter));
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
  pointer-events: none;
}
#panel > * { pointer-events: auto; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.brand {
  margin: 0;
  font-size: 22px;
  font-weight: 750;
  letter-spacing: -.02em;
}
.mark { color: var(--accent); font-weight: 800; margin-right: 1px; }
.tld { color: var(--muted); font-weight: 500; font-size: .7em; letter-spacing: 0; }

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-size: 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 6px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn:focus-visible, input:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { border-color: transparent; color: var(--muted); padding: 6px 8px; }
.btn-ghost:hover { color: var(--text); }
.btn-link {
  border: 0; background: none; padding: 0 2px;
  color: var(--accent); font-size: 13px; text-decoration: underline;
}
.btn-link:hover { background: none; }

/* ---------- search ---------- */
.search-field { position: relative; }
.search-prefix {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  font-weight: 800;
  font-size: 18px;
  pointer-events: none;
}
#q {
  width: 100%;
  font: 500 17px/1.2 var(--sans);
  padding: 11px 12px 11px 30px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
#q:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--card); }
#q::placeholder { color: var(--muted); opacity: .8; }

#suggestions {
  list-style: none;
  margin: 6px 0 0;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  max-height: 50vh;
  overflow-y: auto;
}
#suggestions .head {
  padding: 4px 8px 2px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
#suggestions .empty { padding: 8px; color: var(--muted); font-size: 14px; }
#suggestions [role="option"] {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
}
#suggestions [role="option"]:hover { background: var(--hover); }
#suggestions [aria-selected="true"] { background: var(--active); box-shadow: inset 3px 0 0 var(--accent); }
.sg-words { font-weight: 600; overflow-wrap: anywhere; }
.sg-dist { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* ---------- result ---------- */
.status { color: var(--muted); }
.status.error { color: var(--error); font-weight: 500; }
.status:empty { display: none; }

.address-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.address {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: normal;
  min-width: 0;
}
.address.long { font-size: 18px; }
.coords {
  margin: 6px 0 0;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: baseline;
}
.coords .btn-link { font-family: var(--sans); }
#about, #api-docs { margin-top: 10px; font-size: 14px; }
#result[hidden] + #about { margin-top: 6px; }
#api-docs { margin-top: 4px; }
#about summary, #api-docs summary { cursor: pointer; color: var(--muted); font-size: 13px; }
#about p, #api-docs p { margin: 6px 0 0; }
#api-docs { font-size: 13px; }
#api-docs code { font-family: var(--mono); font-size: 12px; }
.api-list { margin: 8px 0 0; }
.api-list dt { margin-top: 8px; overflow-wrap: anywhere; }
.api-list dt code { color: var(--text); font-weight: 600; }
.api-list dd { margin: 2px 0 0; color: var(--muted); }
.api-examples { color: var(--muted); }
.api-examples a { color: var(--accent); }
.muted { color: var(--muted); }

/* ---------- toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--card);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 2000;
  box-shadow: var(--shadow);
  width: max-content;
  max-width: calc(100vw - 2 * var(--gutter));
  text-align: center;
}

/* ---------- map bits ---------- */
.pin { width: 26px; height: 34px; pointer-events: none; }
.pin svg { display: block; overflow: visible; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .4)); }
.pin path { fill: var(--accent); stroke: #fff; stroke-width: 2; stroke-linejoin: round; }
.pin circle { fill: #fff; }
.maplibregl-map { font: 13px/1.4 var(--sans); }
.maplibregl-ctrl-group, .maplibregl-ctrl-attrib.maplibregl-compact {
  background: var(--card) !important;
  color: var(--text);
}
.maplibregl-ctrl-group button + button { border-top-color: var(--border) !important; }
.maplibregl-ctrl-attrib a { color: var(--muted) !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .maplibregl-ctrl button .maplibregl-ctrl-icon,
  :root:not([data-theme="light"]) .maplibregl-ctrl-attrib-button { filter: invert(1); }
}
:root[data-theme="dark"] .maplibregl-ctrl button .maplibregl-ctrl-icon,
:root[data-theme="dark"] .maplibregl-ctrl-attrib-button { filter: invert(1); }
.maplibregl-ctrl-top-right, .maplibregl-ctrl-bottom-right,
.maplibregl-ctrl-bottom-left { transition: margin .2s; }

/* Base map / overlay switcher */
.mapctl {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
}
.mapctl .seg { display: flex; gap: 2px; }
.mapctl .seg button {
  flex: 1;
  font: inherit;
  border: 0;
  border-radius: 7px;
  padding: 5px 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.mapctl .seg button[aria-pressed="true"] { background: var(--active); color: var(--text); font-weight: 600; }
.mapctl hr { border: 0; border-top: 1px solid var(--border); margin: 2px 4px; }
.mapctl .seg.small button { padding: 3px 8px; font-size: 12px; }
.mapctl label { display: flex; align-items: center; gap: 6px; padding: 3px 6px; cursor: pointer; }
.mapctl input { accent-color: var(--accent); margin: 0; }

/* ---------- phone ---------- */
@media (max-width: 640px) {
  #panel {
    top: max(var(--gutter), env(safe-area-inset-top));
    left: var(--gutter);
    right: var(--gutter);
    width: auto;
    max-width: none;
    max-height: none;
    display: block;
  }
  .card { padding: 10px 12px; }
  .brand-row { margin-bottom: 8px; }
  .brand { font-size: 20px; }
  #result-card {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: 0;
    padding: 14px var(--gutter) max(14px, env(safe-area-inset-bottom));
    max-height: 45vh;
    overflow-y: auto;
  }
  #result-card::before {
    content: "";
    display: block;
    width: 36px; height: 4px;
    border-radius: 2px;
    background: var(--border);
    margin: -6px auto 10px;
  }
  .address { font-size: 19px; }
  .address.long { font-size: 16px; }
  #suggestions { max-height: 40vh; }
  #toast { bottom: auto; top: calc(var(--top-offset, 120px) + 8px); }
  /* Keep map controls clear of the top card and bottom sheet. */
  .maplibregl-ctrl-top-right { margin-top: var(--top-offset, 0px); }
  .maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { margin-bottom: var(--bottom-offset, 0px); }
  .maplibregl-ctrl-zoom-in, .maplibregl-ctrl-zoom-out { display: none !important; }
}

