:root {
  --bg: #ffffff;
  --fg: #1c1c1e;
  --muted: #6c6c72;
  --line: #e2e2e6;
  --field: #f4f4f6;
  --accent: #1c1c1e;
  --accent-fg: #ffffff;
  --error: #b42318;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 4px 16px rgba(0, 0, 0, 0.12);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1f1f22;
    --fg: #ececef;
    --muted: #9b9ba3;
    --line: #36363b;
    --field: #2a2a2e;
    --accent: #ececef;
    --accent-fg: #1f1f22;
    --error: #ff8a7a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #1f1f22;
  --fg: #ececef;
  --muted: #9b9ba3;
  --line: #36363b;
  --field: #2a2a2e;
  --accent: #ececef;
  --accent-fg: #1f1f22;
  --error: #ff8a7a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: #e8e6e1;
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
}

#map {
  position: absolute;
  inset: 0;
  background: #e8e6e1;
}

.maplibregl-map { font: inherit; }

/* The map stays light in dark mode, so its controls keep dark text. */
.maplibregl-ctrl-attrib { color: rgba(0, 0, 0, 0.75); }

/* Panel */

.panel {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1000;
  width: 288px;
  max-height: calc(100% - 24px);
  overflow: auto;
  padding: 14px;
  background: var(--bg);
  color: var(--fg);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.titles { flex: 1; min-width: 0; }

h1 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
}

.summary {
  display: none;
  margin: 2px 0 0;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toggle {
  display: none;
  flex: none;
  width: 28px;
  height: 28px;
  margin: -4px -4px 0 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.toggle::before {
  content: "";
  display: block;
  width: 8px;
  height: 8px;
  margin: 8px auto 0;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
}

.toggle[aria-expanded="false"]::before {
  margin-top: 12px;
  transform: rotate(-135deg);
}

.toggle:hover { background: var(--field); }

.panel-body { margin-top: 12px; }

/* Search */

.search { margin-bottom: 12px; }

input[type="search"],
input[type="date"],
#clock {
  width: 100%;
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  color: var(--fg);
  font: inherit;
}

input[type="search"]:focus,
input[type="date"]:focus,
#clock:focus {
  outline: 2px solid var(--fg);
  outline-offset: -1px;
}

.results {
  max-height: 232px;
  overflow: auto;
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.results li {
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.results li[aria-selected="true"] { background: var(--field); }

.results li.note {
  color: var(--muted);
  cursor: default;
}

/* Fields */

.field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.field-label {
  flex: none;
  width: 76px;
  color: var(--muted);
}

.field input[type="date"] { flex: 1; min-width: 0; }

/* The label goes on its own line, so that the date fits next to the time. */
#time-field { flex-wrap: wrap; row-gap: 4px; }
#time-field .field-label { width: 100%; }

#clock {
  flex: none;
  width: 62px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

#clock[aria-invalid="true"] { outline: 2px solid var(--error); outline-offset: -1px; }

.seg {
  display: flex;
  flex: 1;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
}

.seg label { flex: 1; position: relative; }

.seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg span {
  display: block;
  height: 26px;
  line-height: 26px;
  text-align: center;
  border-radius: 4px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.seg input:disabled + span {
  opacity: 0.35;
  cursor: default;
}

.seg.mode { margin-bottom: 10px; }

.seg.mode label { flex: auto; }

.seg.mode span { padding: 0 6px; white-space: nowrap; }

.seg input:checked + span {
  background: var(--accent);
  color: var(--accent-fg);
}

.seg input:focus-visible + span {
  outline: 2px solid var(--fg);
  outline-offset: 1px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 8px;
  cursor: pointer;
}

.check input { margin: 0; accent-color: var(--fg); }

/* Sliders */

.slider-field { margin-bottom: 6px; }

.slider-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.slider-head label { color: var(--muted); }

.slider-head output { font-variant-numeric: tabular-nums; }

input[type="range"] {
  /* --pos (0..1) is set by app.js. Track positions follow the thumb centre, which stays half a thumb from the ends. */
  --pos: 0;
  --thumb: 18px;
  --at: calc(var(--thumb) / 2 + (100% - var(--thumb)) * var(--pos));
  --ticks: linear-gradient(transparent, transparent);
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--ticks), linear-gradient(to right, var(--fg) var(--at), var(--line) var(--at));
}

input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--ticks), linear-gradient(to right, var(--fg) var(--at), var(--line) var(--at));
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: var(--thumb);
  height: var(--thumb);
  margin-top: calc(2px - var(--thumb) / 2);
  border: 2px solid var(--bg);
  border-radius: 50%;
  background: var(--fg);
  box-shadow: 0 0 0 1px var(--line), 0 1px 3px rgba(0, 0, 0, 0.25);
}

input[type="range"]::-moz-range-thumb {
  box-sizing: border-box;
  width: var(--thumb);
  height: var(--thumb);
  border: 2px solid var(--bg);
  border-radius: 50%;
  background: var(--fg);
  box-shadow: 0 0 0 1px var(--line), 0 1px 3px rgba(0, 0, 0, 0.25);
}

input[type="range"]:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Legend */

.legend { margin: 14px 0 0; }

.legend-title {
  margin: 0 0 5px;
  color: var(--muted);
}

.legend-bar {
  display: flex;
  height: 10px;
  border-radius: 2px;
  overflow: hidden;
}

.legend-bar span {
  flex: 1;
  transition: transform 80ms;
}

.legend-bar span.active {
  transform: scaleY(1.6);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.45);
}

.legend-bar:has(.active) { overflow: visible; }

.legend-ticks {
  position: relative;
  height: 16px;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.legend-ticks span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  white-space: nowrap;
}

.legend-ticks span:first-child { transform: none; }
.legend-ticks span:last-child { transform: translateX(-100%); }

.day {
  margin: 8px 0 0;
  color: var(--muted);
}

.day:empty { display: none; }

#note + .day { margin-top: 4px; }

/* Status */

.status {
  margin: 10px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.status:empty { display: none; }

.status.error { color: var(--error); }

.status.loading::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 7px;
  vertical-align: -1px;
  border: 1.5px solid var(--line);
  border-top-color: var(--fg);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Pin and readout */

.pin {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  cursor: grab;
}

.pin span {
  width: 16px;
  height: 16px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #1c1c1e;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), 0 1px 4px rgba(0, 0, 0, 0.4);
}

.pin:active { cursor: grabbing; }

.readout {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 900;
  padding: 3px 7px 3px 6px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--fg);
  box-shadow: var(--shadow);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}

.readout .legs {
  display: block;
  max-width: 320px;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  white-space: normal;
}

.dest {
  width: 12px;
  height: 12px;
  border: 2px solid #1c1c1e;
  border-radius: 50%;
  background: #fff;
  pointer-events: none;
}

/* Route panel: a second floating panel on the right; in the phone sheet it follows the controls. */

.trip {
  position: fixed;
  top: 12px;
  right: 12px;
  width: 300px;
  max-height: calc(100% - 24px);
  overflow: auto;
  padding: 14px;
  background: var(--bg);
  color: var(--fg);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.trip { transition: opacity 150ms; }

.trip:not([hidden]) { animation: trip-in 200ms ease-out; }



@keyframes trip-in { from { opacity: 0; } }

.trip-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.trip-head strong { font-size: 18px; font-weight: 600; }

.trip-head span,
.trip-legs { color: var(--muted); font-variant-numeric: tabular-nums; }

.trip-legs { margin: 2px 0 10px; font-size: 12px; }

.steps { margin: 0; padding: 0; list-style: none; }

.step {
  --rail: var(--muted);
  position: relative;
  display: grid;
  grid-template-columns: 42px 1fr;
  column-gap: 20px;
  padding-bottom: 12px;
}

.step::before {
  content: "";
  position: absolute;
  top: 8px;
  bottom: -6px;
  left: 51px;
  border-left: 3px solid var(--rail);
}

.step[data-kind="walk"]::before { border-left: 2px dashed var(--rail); left: 52px; }

.step.end::before { display: none; }

.step::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 47px;
  width: 7px;
  height: 7px;
  border: 2px solid var(--fg);
  border-radius: 50%;
  background: var(--bg);
}

.step-time { font-variant-numeric: tabular-nums; }

.step-place { font-weight: 500; }

.step-leg { margin-top: 2px; color: var(--muted); }

.badge {
  display: inline-block;
  min-width: 22px;
  padding: 0 5px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
}

.badge.light { box-shadow: inset 0 0 0 1px var(--line); }

.profile { position: relative; margin-top: 6px; height: 60px; }

.profile svg { display: block; width: 100%; height: 60px; }

.profile path { fill: rgba(37, 99, 235, 0.18); stroke: #2563eb; stroke-width: 1.5; vector-effect: non-scaling-stroke; }

.profile span {
  position: absolute;
  left: 2px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.profile .hi { top: 0; }
.profile .lo { bottom: 0; }

.readout i {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 5px;
  border-radius: 2px;
  vertical-align: -0.5px;
}

/* Phone: the panel becomes a sheet below the map. */

@media (max-width: 640px) {
  body {
    display: flex;
    flex-direction: column;
  }

  #map {
    position: relative;
    inset: auto;
    flex: 1;
    min-height: 0;
  }

  .panel {
    position: relative;
    top: auto;
    left: auto;
    width: auto;
    max-height: 55vh;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    border-radius: 0;
    box-shadow: 0 -1px 0 var(--line), 0 -4px 12px rgba(0, 0, 0, 0.08);
  }

  .toggle { display: block; }

  .trip {
    position: static;
    width: auto;
    max-height: none;
    margin-top: 10px;
    padding: 10px 0 0;
    border-top: 1px solid var(--line);
    border-radius: 0;
    box-shadow: none;
  }

  .panel.collapsed .panel-body { display: none; }
  .panel.collapsed .summary { display: block; }
  .panel.collapsed .status { margin-top: 6px; padding-top: 0; border-top: 0; }

  input[type="search"],
  input[type="date"],
  #clock { height: 36px; font-size: 16px; }

  .seg span { height: 30px; line-height: 30px; }

  input[type="range"] { --thumb: 26px; height: 44px; }
}
