:root {
  color: #1c1917;
  background: #e7e5e4;
  font-family: system-ui, sans-serif;
  line-height: 1.4;
  interpolate-size: allow-keywords;
}

* { box-sizing: border-box; }

body { margin: 0; }

#map {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: #d6d3d1;
}

.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

button,
input {
  font: inherit;
  font-size: 1rem;
}

button { cursor: pointer; }

:focus-visible {
  outline: 3px solid #0b57d0;
  outline-offset: 2px;
}

.search,
.sheet {
  position: absolute;
  z-index: 1000;
  inline-size: min(28rem, calc(100% - 1.5rem));
  background: #fff;
  border-radius: 1rem;
  box-shadow: 0 10px 28px rgb(28 25 23 / 18%);
}

.search {
  inset-block-start: 0.75rem;
  inset-inline-start: 0.75rem;
  padding: 0.85rem 0.9rem 0.7rem;
}

.search-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

h1 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.2;
}

.muted { color: #57534e; }

#feed {
  margin: 0;
  font-size: 0.8rem;
  text-align: end;
}

.stops { margin-block-start: 0.7rem; }

.stop {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.badge {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  inline-size: 1.7rem;
  block-size: 1.7rem;
  border-radius: 999px;
  color: #fff;
  font-weight: 700;
}

.badge-start { background: #2563eb; }
.badge-end { background: #059669; }

.combo {
  position: relative;
  flex: 1 1 auto;
  min-inline-size: 0;
}

input[type="text"] {
  inline-size: 100%;
  min-block-size: 48px;
  padding-block: 0.55rem;
  padding-inline: 0.75rem 2.4rem;
  border: 1px solid #d6d3d1;
  border-radius: 0.7rem;
  background: #fafaf9;
}

.combo:focus-within input[type="text"] {
  border-color: #1c1917;
  background: #fff;
}

.clear {
  position: absolute;
  inset-block-start: 6px;
  inset-inline-end: 6px;
  inline-size: 36px;
  block-size: 36px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #57534e;
  font-size: 1.3rem;
  line-height: 1;
}

.suggestions {
  position: absolute;
  z-index: 2;
  inset-inline: 0;
  inset-block-start: calc(100% + 0.3rem);
  max-block-size: 18rem;
  margin: 0;
  padding: 0.3rem;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  list-style: none;
  background: #fff;
  border-radius: 0.8rem;
  box-shadow: 0 12px 32px rgb(28 25 23 / 20%);
}

.suggestions li {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-block-size: 48px;
  padding-block: 0.35rem;
  padding-inline: 0.7rem;
  border-radius: 0.55rem;
}

.suggestions li[aria-selected="true"] { background: #f4f1ea; }

.sug-title { font-weight: 650; }

.sug-sub {
  color: #57534e;
  font-size: 0.85rem;
}

.sug-recent {
  color: #57534e;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

mark {
  background: transparent;
  font-weight: 800;
}

.swap {
  margin-block: 0.15rem;
  margin-inline-start: 2.2rem;
  min-block-size: 32px;
  padding-inline: 0.2rem;
  border: 0;
  background: transparent;
  color: #1d4ed8;
  font-weight: 700;
}

.search-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-block-start: 0.75rem;
}

fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.7rem;
}

.choice {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-block-size: 48px;
  font-weight: 600;
}

input[type="radio"] { accent-color: #1c1917; }

#compare {
  min-block-size: 48px;
  padding-inline: 0.9rem;
  border: 0;
  border-radius: 999px;
  background: #1c1917;
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
}

#compare:disabled { opacity: 0.55; }

.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-block-start: 0.15rem;
}

.tools button,
#sheet-toggle {
  min-block-size: 40px;
  padding-inline: 0.55rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #1d4ed8;
  font-weight: 650;
}

.tools button[aria-pressed="true"] { background: #e7e5e4; }

#drop-note,
.status { margin: 0.2rem 0 0; }

.status.error { color: #b91c1c; }

.fine,
.credit {
  margin: 0.35rem 0 0;
  color: #44403c;
  font-size: 0.78rem;
}

a { color: #1d4ed8; }

.sheet {
  inset-inline-start: 0.75rem;
  inset-block-end: 0.75rem;
  overflow: clip;
}

.sheet[hidden] { display: none; }

#sheet-toggle {
  inline-size: 100%;
  min-block-size: 48px;
  text-align: start;
  padding-inline: 1rem;
}

#sheet-toggle::before {
  content: "";
  display: inline-block;
  inline-size: 2rem;
  block-size: 0.25rem;
  margin-inline-end: 0.6rem;
  border-radius: 999px;
  background: #d6d3d1;
  vertical-align: middle;
}

#sheet-body {
  block-size: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding-inline: 0.9rem;
  transition: block-size 0.28s ease;
}

.sheet.is-open #sheet-body {
  block-size: auto;
  max-block-size: min(38dvh, 22rem);
  padding-block-end: 0.85rem;
}

.bar {
  block-size: 3px;
  overflow: hidden;
  background: #e7e5e4;
}

.bar[hidden] { display: none; }

.bar span {
  display: block;
  inline-size: 35%;
  block-size: 100%;
  background: #1c1917;
  animation: slide 1.1s ease-in-out infinite;
}

@keyframes slide {
  from { transform: translateX(-120%); }
  to { transform: translateX(320%); }
}

.routes { margin-block-end: 0.4rem; }

.route {
  display: block;
  margin-block-end: 0.45rem;
  padding: 0.65rem 0.7rem;
  border: 1px solid #e7e5e4;
  border-radius: 0.8rem;
}

.route:has(input:checked) {
  border-color: #1c1917;
  background: #fafaf9;
}

.route input { margin-inline-end: 0.35rem; }

.route-title { font-weight: 750; }

.meta { color: #57534e; }

.steps { margin-block-start: 0.35rem; }

.map-note {
  position: absolute;
  z-index: 500;
  inset-block-end: 1rem;
  inset-inline-start: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  background: rgb(255 255 255 / 92%);
  color: #44403c;
  white-space: nowrap;
}

.pin span {
  display: grid;
  place-items: center;
  inline-size: 1.75rem;
  block-size: 1.75rem;
  border: 2px solid #fff;
  border-radius: 999px;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 1px 3px rgb(0 0 0 / 35%);
}

.pin-start span { background: #2563eb; }
.pin-end span { background: #059669; }

.leaflet-top.leaflet-right { margin-block-start: 0.5rem; }

body:has(#sheet:not([hidden])) .leaflet-bottom.leaflet-right,
body:has(#sheet:not([hidden])) .map-note {
  margin-block-end: 0;
  inset-block-end: calc(38dvh + 0.6rem);
}

.noscript {
  position: absolute;
  z-index: 1100;
  inset-block-end: 1rem;
  inset-inline: 1rem;
}

@media (max-width: 800px) {
  .search,
  .sheet {
    inset-inline: 0;
    inline-size: auto;
    border-radius: 0 0 1rem 1rem;
  }

  .sheet {
    border-radius: 1rem 1rem 0 0;
    inset-block-end: 0;
  }

  #feed { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #sheet-body,
  .bar span { transition: none; animation: none; }
}

/* ---- Theme toggle + dark mode (basedmaps.com copy) ---- */
.head-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.theme-toggle {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  inline-size: 40px;
  block-size: 40px;
  border: 1px solid #d6d3d1;
  border-radius: 999px;
  background: #fafaf9;
  color: #1c1917;
}

.theme-toggle .i-sun,
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: block; }

.search-head { align-items: center; }

:root[data-theme="dark"] {
  color: #f5f5f4;
  background: #0c0a09;
  color-scheme: dark;
}

:root[data-theme="dark"] #map { background: #1b1b1b; }
:root[data-theme="dark"] .bm-tiles { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.88) saturate(0.55); }
:root[data-theme="dark"] :focus-visible { outline-color: #60a5fa; }

:root[data-theme="dark"] .search,
:root[data-theme="dark"] .sheet {
  background: #1c1917;
  box-shadow: 0 12px 32px rgb(0 0 0 / 55%), 0 0 0 1px #2e2a27;
}

:root[data-theme="dark"] .muted,
:root[data-theme="dark"] .meta,
:root[data-theme="dark"] .sug-sub,
:root[data-theme="dark"] .sug-recent,
:root[data-theme="dark"] .clear { color: #a8a29e; }

:root[data-theme="dark"] .fine,
:root[data-theme="dark"] .credit { color: #a8a29e; }

:root[data-theme="dark"] a,
:root[data-theme="dark"] .swap,
:root[data-theme="dark"] .tools button,
:root[data-theme="dark"] #sheet-toggle { color: #7cb4ff; }

:root[data-theme="dark"] input[type="text"] {
  border-color: #44403c;
  background: #292524;
  color: #f5f5f4;
}

:root[data-theme="dark"] input[type="text"]::placeholder { color: #8f8a85; }

:root[data-theme="dark"] .combo:focus-within input[type="text"] {
  border-color: #e7e5e4;
  background: #1c1917;
}

:root[data-theme="dark"] .suggestions {
  background: #1c1917;
  box-shadow: 0 12px 32px rgb(0 0 0 / 60%), 0 0 0 1px #2e2a27;
}

:root[data-theme="dark"] .suggestions li[aria-selected="true"] { background: #292524; }
:root[data-theme="dark"] mark { color: inherit; }
:root[data-theme="dark"] input[type="radio"] { accent-color: #e7e5e4; }

:root[data-theme="dark"] #compare {
  background: #f5f5f4;
  color: #1c1917;
}

:root[data-theme="dark"] .tools button[aria-pressed="true"] { background: #292524; }
:root[data-theme="dark"] .status.error { color: #f87171; }
:root[data-theme="dark"] #sheet-toggle::before { background: #57534e; }
:root[data-theme="dark"] .bar { background: #292524; }
:root[data-theme="dark"] .bar span { background: #e7e5e4; }
:root[data-theme="dark"] .route { border-color: #3a3532; }

:root[data-theme="dark"] .route:has(input:checked) {
  border-color: #e7e5e4;
  background: #292524;
}

:root[data-theme="dark"] .map-note {
  background: rgb(28 25 23 / 92%);
  color: #d6d3d1;
}

:root[data-theme="dark"] .pin span { border-color: #1c1917; }

:root[data-theme="dark"] .theme-toggle {
  border-color: #44403c;
  background: #292524;
  color: #fde68a;
}

:root[data-theme="dark"] .leaflet-bar a,
:root[data-theme="dark"] .leaflet-bar a:hover {
  background: #1c1917;
  color: #e7e5e4;
  border-bottom-color: #3a3532;
}

:root[data-theme="dark"] .leaflet-bar { border-color: #3a3532; }

:root[data-theme="dark"] .leaflet-container .leaflet-control-attribution {
  background: rgb(28 25 23 / 85%);
  color: #a8a29e;
}

:root[data-theme="dark"] .leaflet-container .leaflet-control-attribution a { color: #7cb4ff; }

:root[data-theme="dark"] .leaflet-popup-content-wrapper,
:root[data-theme="dark"] .leaflet-popup-tip {
  background: #1c1917;
  color: #f5f5f4;
}

:root[data-theme="dark"] .leaflet-container a.leaflet-popup-close-button { color: #a8a29e; }
