:root {
  --accent: #007AFF;
  --mint: #12B886;
  --warning: #FF9500;
  --danger: #FF3B30;
  --surface: #ffffff;
  --surface-2: #F2F2F7;
  --field: #ffffff;
  --ink: #1C1C1E;
  --ink-soft: #6E6E73;
  --line: #D1D1D6;
  --shadow: 0 2px 10px rgba(0, 0, 0, .18);
  --panel-h: 0px;
  --top-h: 70px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface: #1C1C1E;
    --surface-2: #2C2C2E;
    --field: #1C1C1E;
    --ink: #F2F2F7;
    --ink-soft: #98989D;
    --line: #3A3A3C;
    --shadow: 0 2px 12px rgba(0, 0, 0, .5);
  }
  .leaflet-tile-pane { filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(90%) saturate(75%); }
  .leaflet-container { background: #1c1c1e; }
  .leaflet-control-attribution { background: rgba(28, 28, 30, .8) !important; color: #a1a1a6; }
  .leaflet-control-attribution a { color: #8fb4d9; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Rubik, Arial, sans-serif;
  color: var(--ink);
  background: var(--surface);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

svg.i { width: 22px; height: 22px; fill: currentColor; flex: none; }
[dir="rtl"] .flip { transform: scaleX(-1); }

#map { position: fixed; inset: 0; direction: ltr; }

#top {
  position: fixed;
  top: 0;
  inset-inline-start: 0;
  width: 100%;
  max-width: 460px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 0;
  z-index: 1000;
}

.field {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 10px;
  min-height: 46px;
}
.field input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  outline: none;
  padding: 12px 0;
}
.field input::placeholder { color: var(--ink-soft); }
.field input::-webkit-search-cancel-button { display: none; }

.icon-btn {
  border: 0;
  background: none;
  padding: 5px;
  border-radius: 50%;
  color: var(--ink-soft);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.icon-btn.ink { color: var(--ink); }
.icon-btn.accent { color: var(--accent); }

.dir { display: flex; align-items: center; gap: 8px; }
.dir .ends { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.end {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 8px 0 12px;
  min-height: 44px;
  cursor: pointer;
  width: 100%;
  text-align: start;
}
[dir="rtl"] .end { padding: 0 12px 0 8px; }
.end .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.end .txt { flex: 1; min-width: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.end.empty .txt { color: var(--ink-soft); }

.round {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
  border: 0;
  display: grid;
  place-items: center;
  color: var(--ink);
  cursor: pointer;
  flex: none;
}

#results {
  position: fixed;
  inset: 0;
  top: var(--top-h);
  background: var(--surface);
  z-index: 900;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 900px) {
  #results { inset-inline-end: auto; width: 460px; bottom: auto; max-height: calc(100vh - var(--top-h) - 12px); border-radius: 0 0 12px 12px; box-shadow: var(--shadow); }
}

.row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  cursor: pointer;
  width: 100%;
  border: 0;
  background: none;
  text-align: start;
}
.row:hover { background: var(--surface-2); }
.row .badge {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  flex: none;
}
.row .badge svg.i { width: 18px; height: 18px; }
.row .t { flex: 1; min-width: 0; }
.row .t b, .row .t small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .t b { font-weight: 500; }
.row .t small { color: var(--ink-soft); font-size: 13px; }
.row.hl .badge, .row.hl small { color: var(--accent); }
.section-h { padding: 16px 16px 4px; color: var(--ink-soft); font-size: 13px; font-weight: 600; }
.empty-hint { padding: 24px 16px; color: var(--ink-soft); text-align: center; }

#locate {
  position: fixed;
  left: 16px;
  bottom: calc(var(--panel-h) + 16px + env(safe-area-inset-bottom));
  z-index: 800;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
  border: 0;
  color: var(--accent);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: bottom .25s ease;
}
@media (min-width: 900px) { #locate { bottom: 24px; left: auto; right: 16px; } }

#panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--panel-h);
  z-index: 950;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -2px 16px rgba(0, 0, 0, .18);
  display: flex;
  flex-direction: column;
  transition: height .25s ease;
  padding-bottom: env(safe-area-inset-bottom);
}
#panel.dragging { transition: none; }
#panel .grab { flex: none; padding: 10px 0 8px; touch-action: none; cursor: grab; }
#panel .grab i { display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: auto; }
#panel .body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#panel .body > * { flex-shrink: 0; }
@media (min-width: 900px) {
  #panel { left: 12px; right: auto; width: 436px; top: calc(var(--top-h) + 8px); bottom: auto; height: auto; max-height: calc(100vh - var(--top-h) - 20px); border-radius: 16px; box-shadow: var(--shadow); }
  [dir="rtl"] #panel { left: auto; right: 12px; }
  #panel .grab { display: none; }
  #panel .body { padding-top: 16px; }
}

.place { display: flex; align-items: flex-start; gap: 2px; position: relative; }
.place .t { flex: 1; min-width: 0; }
.place h2 { margin: 0; font-size: 21px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.place p { margin: 2px 0 0; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.menu {
  position: absolute;
  top: 40px;
  inset-inline-end: 36px;
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  z-index: 5;
  min-width: 180px;
  padding: 4px 0;
}
.menu button { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; background: none; padding: 10px 14px; cursor: pointer; text-align: start; }
.menu button:hover { background: var(--surface-2); }
.menu svg.i { width: 20px; height: 20px; color: var(--ink-soft); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: 999px;
  padding: 8px 13px;
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.chip[aria-pressed="true"] { background: var(--accent); color: #fff; }
.chip svg.i { width: 18px; height: 18px; }
.chip .caution { width: 14px; height: 14px; color: var(--warning); }
.chip[aria-pressed="true"] .caution { color: #fff; }

.bar { display: flex; align-items: center; gap: 8px; }
.bar .grow { flex: 1; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 9px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  background: none;
}
.btn svg.i { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.outline { border-color: var(--line); color: var(--accent); }
.btn.text { color: var(--accent); padding-inline: 8px; }
.btn.full { width: 100%; justify-content: center; padding: 13px; }
a.btn { text-decoration: none; }
.field > svg.i, #lead span.icon-btn { color: var(--ink-soft); }
#lead, #trail { display: contents; }

.card {
  display: flex;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
  text-align: start;
  padding: 0;
}
button.card { cursor: pointer; }
button.card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.card .stripe { width: 5px; flex: none; background: var(--accent); }
.card .c { flex: 1; min-width: 0; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.card .head { display: flex; align-items: baseline; gap: 8px; }
.card .when { font-weight: 600; font-size: 17px; font-variant-numeric: tabular-nums; unicode-bidi: plaintext; }
.card .dur { margin-inline-start: auto; color: var(--ink-soft); white-space: nowrap; }
.card .save { margin-inline-start: auto; color: #34C759; font-weight: 500; }

.legs { display: flex; align-items: center; gap: 6px; overflow-x: auto; white-space: nowrap; scrollbar-width: none; }
.line-chip { background: var(--accent); color: #fff; font-weight: 700; font-size: 12px; border-radius: 6px; padding: 2px 6px; }
.im { display: inline-flex; align-items: center; gap: 1px; font-size: 13px; font-weight: 500; color: #8E8E93; }
.im svg.i { width: 16px; height: 16px; }
.im.mint { color: var(--mint); }
.sep svg.i { width: 14px; height: 14px; fill: #8E8E93; }
.meta { font-size: 12px; color: #8E8E93; }
.sub { font-size: 13px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.warn-line { display: flex; gap: 5px; align-items: flex-start; font-size: 13px; color: var(--warning); }
.warn-line.sun { color: #D4A300; }
.warn-line svg.i { width: 14px; height: 14px; margin-top: 2px; }
.notice { display: flex; gap: 8px; align-items: flex-start; padding: 10px; border-radius: 8px; font-size: 13px; }
.notice svg.i { width: 16px; height: 16px; margin-top: 1px; }
.notice.warn { color: var(--warning); background: color-mix(in srgb, var(--warning) 12%, transparent); }
.notice.err { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.notice.soft { color: var(--ink-soft); background: var(--surface-2); }
.notice ul { margin: 4px 0 0; padding-inline-start: 18px; }
.notice li { margin: 2px 0; }

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
  margin: 12px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.journey-head { display: flex; align-items: center; gap: 6px; }
.journey-head .when { font-weight: 600; font-size: 17px; unicode-bidi: plaintext; }
.journey-head .dur { margin-inline-start: auto; color: var(--accent); font-weight: 600; }
.steps-h { font-size: 14px; font-weight: 600; color: var(--ink-soft); }
.step { display: flex; gap: 12px; align-items: flex-start; }
.step > svg.i { color: var(--accent); }
.step.walk > svg.i { color: #8E8E93; }
.step b { font-weight: 600; display: block; }
.step small { display: block; font-size: 13px; color: var(--ink-soft); }
.step .meta { display: block; margin-top: 2px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { flex: 1; padding: 9px 6px; border: 0; background: none; font-size: 14px; cursor: pointer; white-space: nowrap; }
.seg button + button { border-inline-start: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); font-weight: 600; }
.time-input {
  font: inherit;
  font-size: 30px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink);
  direction: ltr;
  align-self: flex-start;
}

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .35);
  z-index: 2000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  background: var(--surface);
  width: 100%;
  max-width: 520px;
  border-radius: 16px 16px 0 0;
  padding: 20px 20px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 88vh;
  overflow-y: auto;
}
.sheet.full { height: 100%; max-height: none; border-radius: 0; padding: calc(env(safe-area-inset-top) + 8px) 0 0; gap: 8px; }
.sheet.full .field { margin: 0 16px; }
.sheet h3 { margin: 0; font-size: 20px; }
.sheet h4 { margin: 8px 0 0; font-size: 15px; }
.sheet .title-row { display: flex; align-items: center; gap: 6px; padding: 0 8px; }
.sheet .title-row h3 { font-size: 18px; font-weight: 600; }
@media (min-width: 900px) {
  .scrim { align-items: center; }
  .sheet { border-radius: 16px; }
  .sheet.full { height: min(640px, 90vh); border-radius: 16px; padding-top: 12px; }
}
.radio { display: flex; align-items: center; gap: 12px; padding: 6px 0; cursor: pointer; }
.radio input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.radio small { display: block; color: var(--ink-soft); font-size: 13px; }
.saved-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; cursor: pointer; }
.saved-row > svg.i { color: var(--accent); }
.saved-row .t { flex: 1; min-width: 0; }
.saved-row small { display: block; font-size: 13px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-row small.unset { color: var(--accent); }
.op-head { display: flex; align-items: center; gap: 10px; }
.op-head .dot { width: 12px; height: 12px; border-radius: 50%; }
.op-head b { font-size: 17px; font-weight: 600; display: block; }
.op-head small { color: var(--ink-soft); }
.stats { display: flex; gap: 28px; }
.stat small { display: block; font-size: 11px; color: var(--ink-soft); letter-spacing: .04em; text-transform: uppercase; }
.stat b { font-size: 18px; font-weight: 500; }
.about { font-size: 12px; color: var(--ink-soft); line-height: 1.6; margin-top: 10px; }

.veh { width: 18px; height: 18px; border-radius: 50%; border: 3px solid; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); }
.cluster {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #27AE60;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font: 600 13px system-ui, sans-serif;
}
.user-dot { width: 22px; height: 22px; border-radius: 50%; background: rgba(0, 122, 255, .22); display: grid; place-items: center; }
.user-dot i { width: 14px; height: 14px; border-radius: 50%; background: #007AFF; border: 2.5px solid #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .35); }

@media (prefers-reduced-motion: reduce) {
  #panel, #locate { transition: none; }
  .spinner { animation: none; }
}
