:root {
  --bg: #ffffff;
  --fg: #1d1d1f;
  --muted: #6e6e73;
  --panel: rgba(255, 255, 255, 0.95);
  --line: #d2d2d7;
  --accent: #2171b5;
  --error: #b42318;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111111;
    --fg: #f2f2f2;
    --muted: #a1a1a6;
    --panel: rgba(28, 28, 30, 0.95);
    --line: #3a3a3c;
    --accent: #6baed6;
    --error: #ff8a80;
  }
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font:
    14px / 1.4 system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
}

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

#panel {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 290px;
  max-height: calc(100% - 24px);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  background: var(--panel);
  padding: 14px 16px;
  border-radius: 12px;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.2);
}

h1 {
  font-size: 16px;
  margin: 0;
}

/* Cards (the explorer and the spot): a top bar, and a body that minimises away */
.card-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.card-head h1,
.card-head .titles {
  flex: 1;
  min-width: 0;
}
.card.minimised .card-head {
  margin-bottom: 0;
}
.card.minimised .card-body {
  display: none;
}
button.icon {
  width: 26px;
  height: 26px;
  flex: none;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  color: var(--fg);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
button.icon:hover {
  border-color: var(--accent);
}

#spot {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 320px;
  max-width: calc(100% - 24px);
  max-height: calc(100% - 24px);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  background: var(--panel);
  color: var(--fg);
  padding: 10px 12px 12px;
  border-radius: 12px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
  font-size: 13px;
}
#spot[hidden] {
  display: none;
}
/* the top bar stays put; the rest scrolls */
.card .card-head {
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.card.dragging .card-head {
  cursor: grabbing;
}
.card .card-body {
  overflow-y: auto;
}
.card .grip {
  color: var(--muted);
  font-size: 14px;
}
#spot h2 {
  font-size: 14px;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#spot .summary {
  color: var(--muted);
  font-size: 12px;
}
#spot .summary:empty {
  display: none;
}
.spot-info {
  color: var(--muted);
}
.spot-info .times {
  display: flex;
  gap: 12px;
  color: var(--fg);
  margin-bottom: 2px;
}
.spot-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #111;
  border: 3px solid #fff;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.45);
}

.hint {
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 10px;
}

.field {
  margin: 12px 0;
}

.label,
summary {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

summary {
  cursor: pointer;
}

.label strong {
  color: var(--fg);
  font-size: 15px;
}

input[type="range"],
select,
input[type="date"] {
  width: 100%;
  font: inherit;
  box-sizing: border-box;
}

.ticks {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 10px;
}

.segmented {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segmented button {
  flex: 1;
  font: inherit;
  padding: 5px 0;
  border: 0;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
}

.segmented button.on {
  background: var(--accent);
  color: #fff;
}

/* Record week: day picker (recorded days underlined), record and play */
.week {
  margin-top: 6px;
}
#days button {
  font-size: 12px;
  padding: 3px 0;
}
#days button.recorded {
  box-shadow: inset 0 -3px 0 #41ab5d;
}
#days button.partial {
  box-shadow: inset 0 -3px 0 #c6dbef;
}
.record-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
#record {
  flex: 1;
  font: inherit;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}
#record:hover:not(:disabled),
#record.running {
  border-color: var(--accent);
}
#record:disabled,
#play:disabled {
  opacity: 0.5;
  cursor: default;
}

.check {
  display: flex;
  gap: 6px;
  align-items: center;
  margin: 4px 0;
}

.status {
  font-size: 12px;
  min-height: 18px;
}

.status div {
  margin: 2px 0;
}

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

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  font-size: 12px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.legend i {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid #888;
}

.maplibregl-popup-content {
  color: #1d1d1f;
  font-size: 13px;
}

.journey-buttons {
  display: flex;
  gap: 6px;
  margin: 8px 0 4px;
}

.journey-buttons button {
  flex: 1;
  font: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--bg);
  color: var(--accent);
  cursor: pointer;
}
.journey-buttons button.on,
.journey-buttons button:hover {
  background: var(--accent);
  color: #fff;
}

.journey .asking {
  color: var(--muted);
}
.trip-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 4px 0 8px;
}
.trip-head strong {
  font-size: 15px;
}
.trip-head span {
  flex: 1;
  color: var(--muted);
}
.trip-head a {
  font-size: 11px;
  color: var(--muted);
}

/* The legs as a timeline: time, a coloured bar per leg (dotted for walking), details */
.journey ol.legs {
  list-style: none;
  padding: 0;
  margin: 0;
}
.legs li {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 0 18px;
  position: relative;
  padding-bottom: 10px;
}
.legs li::before {
  content: "";
  position: absolute;
  left: 46px;
  top: 6px;
  bottom: -6px;
  width: 5px;
  border-radius: 3px;
  background: var(--c);
}
.legs li.walk::before {
  width: 0;
  left: 47px;
  border-radius: 0;
  border-left: 3px dotted var(--muted);
  background: none;
}
.legs li::after {
  content: "";
  position: absolute;
  left: 43px;
  top: 3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--fg);
}
.legs li.end {
  padding-bottom: 0;
}
.legs li.end::before {
  display: none;
}
.legs time {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.legs small {
  display: block;
  color: var(--muted);
}
.legs .chip {
  display: inline-block;
  padding: 0 6px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 12px;
}
.legs .wait {
  color: var(--muted);
  font-size: 12px;
}

.modes {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  margin-bottom: 4px;
}

/* Which carriage to board: the vehicle heading right (carriage 1 on the right) */
.cars {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 6px;
  margin: 3px 0 1px;
  font-size: 11px;
  color: var(--muted);
}
.cars .vehicle {
  display: inline-flex;
  flex-direction: row-reverse;
  gap: 2px;
}
.cars i {
  width: 13px;
  height: 9px;
  border: 1.5px solid var(--c);
  border-radius: 2px;
  box-sizing: border-box;
}
.cars i.on {
  background: var(--c);
}
.cars.train i:first-child,
.cars.metro i:first-child {
  border-top-right-radius: 6px;
  border-bottom-right-radius: 6px;
}
.cars.metro i {
  width: 15px;
}
/* a tram: one articulated vehicle, round at both ends */
.cars.light-rail .vehicle {
  gap: 0;
}
.cars.light-rail i {
  width: 18px;
  border-radius: 0;
}
.cars.light-rail i + i {
  border-right-width: 0.5px;
}
.cars.light-rail i:first-child {
  border-radius: 0 6px 6px 0;
}
.cars.light-rail i:last-child {
  border-radius: 6px 0 0 6px;
}
.cars .text {
  color: var(--fg);
}

/* Admin mode: Google's route under Desto's */
.journey .google {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.journey .google h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin: 0 0 4px;
}
.journey .google summary {
  display: list-item;
  color: var(--fg);
  font-size: 13px;
  margin: 0;
}
.journey .google details[open] summary {
  margin-bottom: 6px;
}
.verdict {
  font-size: 12px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
}
.verdict.ahead {
  background: #dff3e4;
  color: #146c2e;
}
.verdict.behind {
  background: #fde2e1;
  color: #a4161a;
}
.verdict.same {
  background: #ececec;
  color: #444;
}
.admin {
  margin-top: 12px;
}

.journey .error {
  color: #b42318;
}

@media (max-width: 600px) {
  #panel {
    top: auto;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 45%;
    border-radius: 12px 12px 0 0;
  }
  #spot {
    top: 8px;
    right: 8px;
    width: calc(100% - 16px);
    max-height: 50%;
  }
}

.search {
  position: relative;
  display: flex;
  gap: 6px;
}
.search input {
  flex: 1;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
  padding: 7px 9px;
  border: 1px solid var(--line, #d2d2d7);
  border-radius: 8px;
  font: inherit;
  background: var(--bg);
  color: var(--fg);
}
#lock {
  font: inherit;
  padding: 0 10px;
  border: 1px solid var(--line, #d2d2d7);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  white-space: nowrap;
}
#lock[aria-pressed="true"] {
  background: #2171b5;
  border-color: #2171b5;
  color: #fff;
}
.matches {
  position: absolute;
  z-index: 5;
  top: 100%;
  left: 0;
  right: 0;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
  background: var(--bg);
  border: 1px solid var(--line, #d2d2d7);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  max-height: 260px;
  overflow: auto;
}
.matches li {
  padding: 7px 9px;
  cursor: pointer;
  border-bottom: 1px solid var(--line, #eee);
}
.matches li:last-child {
  border-bottom: 0;
}
.matches li:hover {
  background: rgba(33, 113, 181, 0.12);
}
.matches li small {
  color: var(--muted);
  margin-left: 4px;
}
.matches li.none {
  cursor: default;
  color: var(--muted);
}

/* Two controls side by side (date + ring limit) */
.field.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Optional settings: folded sections with a caret */
details.group {
  margin: 8px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
}

details.group summary {
  margin: 0;
  color: var(--fg);
  font-weight: 600;
  font-size: 13px;
  list-style: none;
}

details.group summary::-webkit-details-marker {
  display: none;
}

details.group summary::before {
  content: "▸";
  display: inline-block;
  width: 1em;
  color: var(--muted);
  transition: transform 0.15s;
}

details.group[open] summary::before {
  transform: rotate(90deg);
}

details.group[open] summary {
  margin-bottom: 6px;
}

details.group .label {
  margin-top: 8px;
}

/* Desto's ways to get there: pick one to show it */
.options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 10px;
}
.options button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  padding: 5px 9px;
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}
.options button b {
  display: block;
  font-size: 11px;
  text-transform: capitalize;
  color: var(--muted);
}
.options button.on {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.options button.on b {
  color: var(--accent);
}

/* Server trouble (offline, busy), across the top of the map */
.notice {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  max-width: min(440px, calc(100% - 32px));
  box-sizing: border-box;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--panel);
  color: var(--error);
  border: 1px solid var(--error);
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.2);
  font-weight: 600;
  text-align: center;
}

/* About Desto and credits */
#about {
  width: min(520px, calc(100% - 32px));
  max-height: calc(100% - 48px);
  box-sizing: border-box;
  padding: 16px 20px 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--fg);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}
#about::backdrop {
  background: rgba(0, 0, 0, 0.35);
}
#about h2 {
  flex: 1;
  font-size: 18px;
  margin: 0;
}
#about h3 {
  font-size: 14px;
  margin: 14px 0 4px;
}
#about p,
#about ul {
  margin: 0 0 8px;
}
#about ul {
  padding-left: 18px;
}
#about li {
  margin-bottom: 4px;
}
#about .credits {
  color: var(--muted);
  font-size: 13px;
}
#about a {
  color: var(--accent);
}
