:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --border: #e3e3e3;
  --accent: #0019a8;
  --error: #c0392b;
  --hover: #f4f4f4;
  --current: #ececec;
  --station-text: #333;
  --river: #dbe9f4;
  --river-text: #7d9db6;
  --glass: rgba(255, 255, 255, 0.58);   /* see-through panels over the map */
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #15171a;
  --fg: #e8e8e6;
  --muted: #9a9a98;
  --border: #2e3136;
  --accent: #6d84ff;
  --error: #ff7a6b;
  --hover: #22252a;
  --current: #2a2e34;
  --station-text: #d4d4d2;
  --river: #1d2a37;
  --river-text: #5d7a92;
  --glass: rgba(21, 23, 26, 0.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body { display: flex; }

#panel {
  flex: none;
  width: 280px;
  height: 100%;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  padding: 14px 16px;
  font-size: 14px;
}

#views {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 100%;
}

#strip {
  position: absolute;
  inset: 0;
}
[hidden] { display: none !important; }

h1 {
  margin: 0;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}
h1::before {
  content: "";
  width: 18px;
  height: 18px;
  border: 4px solid #dc241f;
  border-radius: 50%;
  background: linear-gradient(transparent 38%, var(--accent) 38%, var(--accent) 62%, transparent 62%);
}

h2 {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

#status { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
#status.error { color: var(--error); }

.segmented {
  display: flex;
  margin-top: 12px;
}
.segmented button {
  flex: 1;
  font-size: 13px;
  padding: 5px 0;
  border-radius: 0;
}
.segmented button:first-child { border-radius: 6px 0 0 6px; }
.segmented button:last-child { border-radius: 0 6px 6px 0; }
.segmented button + button { border-left: none; }
.segmented button[aria-pressed="true"] {
  background: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
}

.option {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 13px;
  cursor: pointer;
}

section { margin-top: 16px; }
section > h2 { margin-bottom: 6px; }

button {
  font: inherit;
  font-size: 12px;
  color: var(--fg);
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 6px;
  padding: 2px 8px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }

#lines { list-style: none; margin: 0; padding: 0; }
#lines label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 6px;
  margin: 0 -6px;
  border-radius: 6px;
  cursor: pointer;
}
#lines label:hover { background: var(--hover); }
#lines li.current label { background: var(--current); font-weight: 600; }
#lines .swatch {
  width: 22px;
  height: 6px;
  border-radius: 3px;
  flex: none;
}
#lines .count {
  margin-left: auto;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#train-info {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
#train-info h3 { margin: 4px 0 2px; font-size: 16px; }
#train-info .where { margin: 0 0 8px; color: var(--muted); }
#train-info ol { margin: 0; padding-left: 0; list-style: none; }
#train-info li {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
  font-variant-numeric: tabular-nums;
}

footer {
  margin-top: 16px;
  font-size: 11px;
  color: var(--muted);
}

/* Line diagram */
#strip {
  overflow: hidden;
  /* Drag to pan, pinch to zoom: handled in app.js rather than by the browser. */
  touch-action: none;
  cursor: grab;
}
#strip.dragging { cursor: grabbing; }
#strip svg { display: block; }
#strip .diagram-title { font-size: 26px; font-weight: 700; }
#strip .diagram-sub { font-size: 13px; fill: var(--muted); transition: opacity 0.5s ease; }
#strip .diagram-sub.off { opacity: 0; }
#strip .diagram-title,
#strip .diagram-sub {
  /* Readable over the diagram when zoomed in. */
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 4px;
  stroke-linejoin: round;
  pointer-events: none;
}
#strip .station {
  font-size: var(--station-size, 11px);
  fill: var(--station-text);
  /* Outline in the background colour keeps names readable over trains;
     clicks pass through to the train underneath. */
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 3px;
  stroke-linejoin: round;
  pointer-events: none;
}
#strip .poi-icon { cursor: default; }
/* Names, ticks and icons are "pinned" to a point on the diagram: they move
   with it when zooming but are scaled back by --s (set in app.js), so they
   grow much more slowly than the distances between them. */
#strip .pin {
  transform: translate(calc(var(--x) * 1px), calc(var(--y) * 1px)) scale(var(--s, 1));
}
#strip .track { stroke-width: calc(5px * var(--s, 1)); }
/* On phones, quieter stations show as a dot until there's room for their
   name; names fade in as you zoom. */
#strip .station-dot { fill: var(--bg); stroke-width: 2; }
#strip .pin.fades { transition: opacity 0.25s ease; }
#strip .pin.off { opacity: 0; }
#strip .river {
  fill: none;
  stroke: var(--river);
  stroke-width: calc(14px * var(--s, 1));
  stroke-linecap: round;
  stroke-linejoin: round;
}
#strip .river-label {
  font-size: var(--station-size, 11px);
  font-style: italic;
  letter-spacing: 0.08em;
  fill: var(--river-text);
  pointer-events: none;
}
#strip .train { cursor: pointer; }
#strip .train-halo { fill: none; stroke: var(--fg); stroke-width: 2; }

.zoom-controls {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
}
.zoom-controls button {
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  flex: none;
  font-size: 18px;
  line-height: 1;
  border-radius: 0;
}
.zoom-controls button:first-child { border-radius: 6px 6px 0 0; }
.zoom-controls button:last-child { border-radius: 0 0 6px 6px; }
.zoom-controls button + button { border-top: none; }
.zoom-controls button:disabled { color: var(--muted); cursor: default; }

#train-info .focus-btn {
  width: 100%;
  margin-top: 10px;
  padding: 6px 0;
  font-size: 13px;
}

/* Card shown while following a train */
#focus-card {
  position: absolute;
  left: 16px;
  right: 66px;            /* clear of the zoom buttons */
  bottom: 16px;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.15);
  padding: 12px 16px;
  font-size: 14px;
}
#focus-card .head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}
#focus-card .head button { margin-left: auto; font-weight: 400; }
#focus-card .eta { margin: 10px 0 6px; font-size: 16px; }
#focus-card .eta strong { font-variant-numeric: tabular-nums; }
#focus-card .track {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
#focus-card .bar {
  position: relative;
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
}
#focus-card .bar span {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 3px;
}
#focus-card .where { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  border-radius: 4px;
  padding: 1px 6px;
}

#tip {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
  background: var(--fg);
  color: var(--bg);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  max-width: 260px;
}

/* Tapping or long-pressing the diagram shouldn't select text or open the
   copy menu. */
#views, #mobile-bar {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#train-info h2 { display: flex; align-items: center; gap: 6px; }
#train-info .info-actions { margin-left: auto; display: flex; gap: 6px; }
/* Phone-only controls; on wider screens the full Follow button is used. */
#train-info .icon-btn { display: none; }
/* Short messages, top right: location results, and landmark names on phones. */
#toast {
  position: absolute;
  top: 16px;
  right: 62px;              /* left of the location button */
  max-width: min(360px, 60%);
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  pointer-events: none;
  animation: toast-in 0.2s ease;
  z-index: 5;
}
#toast[hidden] { display: none; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-4px); }
}

/* Location button, top right. */
#locate-btn {
  position: absolute;
  top: 16px;
  right: 16px;               /* anchored right, so it opens out to the left */
  height: 36px;
  padding: 0 8px;            /* with the 18px icon and border: 36px square */
  display: flex;
  align-items: center;
  white-space: nowrap;
  border-radius: 8px;
  z-index: 5;
}
#locate-btn svg { flex: none; }
/* "Nearest to me" shows inside the button for a few seconds on each visit. */
#locate-btn .locate-label {
  max-width: 0;
  overflow: hidden;
  opacity: 0;
  font-size: 13px;
  font-weight: 600;
  transition: max-width 0.45s ease, margin-left 0.45s ease, opacity 0.3s ease;
}
#locate-btn.expanded .locate-label {
  max-width: 120px;
  margin-left: 6px;
  opacity: 1;
}
#locate-btn.locating svg { animation: locating 0.9s ease-in-out infinite alternate; }
@keyframes locating { to { opacity: 0.25; } }

/* "You are here" on the diagram. */
#strip .you-are-here .spot { fill: #1a73e8; stroke: var(--bg); stroke-width: 2.5; }
#strip .you-are-here .halo {
  fill: #1a73e8;
  opacity: 0.18;
  transform-box: fill-box;
  transform-origin: center;
  animation: here-pulse 2s ease-out infinite;
}
@keyframes here-pulse { from { transform: scale(0.6); opacity: 0.35; } to { transform: scale(1.6); opacity: 0; } }

/* ---- Phones ------------------------------------------------------------ */

#mobile-bar { display: none; }

@media (max-width: 700px) {
  :root { --bar-h: calc(60px + env(safe-area-inset-bottom, 0px)); }
  body { display: block; }

  /* The diagram fills the screen above the bottom bar. */
  #views {
    position: fixed;
    inset: 0 0 var(--bar-h) 0;
    height: auto;
  }
  #strip .diagram-title { font-size: 20px; }
  #strip .diagram-sub { font-size: 12px; }

  /* Pinch replaces the zoom buttons; keep "fit line" once zoomed in. */
  /* No zoom buttons on phones: pinch instead. */
  .zoom-controls { display: none; }
  #locate-btn { top: 12px; right: 12px; }
  .zoom-controls [data-zoom="in"],
  .zoom-controls [data-zoom="out"] { display: none; }
  .zoom-controls [data-zoom="reset"] { border-radius: 8px; width: 36px; height: 36px; }
  .zoom-controls [data-zoom="reset"]:disabled { visibility: hidden; }

  /* Bottom bar: one dot per line, then the settings cog. */
  #mobile-bar {
    display: flex;
    align-items: center;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--bar-h);
    padding: 0 8px env(safe-area-inset-bottom, 0px) 10px;
    gap: 6px;
    background: var(--bg);
    border-top: 1px solid var(--border);
    z-index: 30;
  }
  /* Line picker: a pill of line colours with a larger circle (the thumb)
     on the current line. Dragging is handled in app.js. */
  #line-slider {
    flex: 1;
    height: 44px;
    display: flex;
    align-items: center;
    padding: 0 16px;       /* room for the thumb at either end */
    touch-action: none;
    cursor: pointer;
  }
  #line-slider .rail {
    position: relative;
    flex: 1;
    height: 14px;
  }
  #line-slider .track {
    position: absolute;
    inset: 0;
    display: flex;
    border-radius: 7px;
    overflow: hidden;
    box-shadow: 0 0 0 1px var(--border);
  }
  #line-slider .seg { flex: 1; }
  #line-slider .thumb {
    position: absolute;
    top: 50%;
    width: 30px;
    height: 30px;
    margin-left: -15px;
    border-radius: 50%;
    border: 3px solid var(--bg);
    box-shadow: 0 0 0 2px var(--fg), 0 2px 6px rgba(0, 0, 0, 0.3);
    transform: translateY(-50%);
    transition: left 0.2s ease, transform 0.15s ease;
  }
  #line-slider.dragging .thumb {
    transition: transform 0.15s ease;
    transform: translateY(-50%) scale(1.15);
  }
  #line-bubble {
    position: absolute;
    bottom: calc(var(--bar-h) + 6px);
    transform: translateX(-50%);
    padding: 5px 10px;
    border-radius: 6px;
    background: var(--fg);
    color: var(--bg);
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
  }
  #settings-btn {
    flex: none;
    width: 40px;
    height: 40px;
    padding: 0;
    display: grid;
    place-items: center;
    border: none;
    color: var(--fg);
  }

  /* The side panel becomes the settings sheet, opened by the cog. */
  #panel {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--bar-h);
    width: auto;
    height: auto;
    max-height: 70vh;
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.18);
    background: var(--bg);
    z-index: 25;
  }
  .settings-open #panel { display: block; }
  #lines-section { display: none; }

  /* Selected train: a compact card above the bar (moved here by app.js). */
  #views > #train-info {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 8px;
    margin: 0;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.15);
    font-size: 14px;
  }
  #views > #train-info .icon-btn {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 8px;
    background: transparent;
    font-size: 14px;
  }
  #views > #train-info .text-btn {
    width: auto;
    padding: 0 12px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: normal;
    text-transform: none;
    color: var(--fg);
    border-color: var(--fg);
  }
  #views > #train-info .icon-btn[aria-pressed="true"] { background: var(--fg); color: var(--bg); }
  #views > #train-info .focus-btn { display: none; }
  #views > #train-info li:nth-child(n + 4) { display: none; }
  .following #views > #train-info { display: none; }

  #focus-card { left: 8px; right: 8px; bottom: 8px; }

  /* Pop-ups over the map are slightly see-through, blurring the map behind. */
  #views > #train-info,
  #focus-card,
  #toast {
    background: var(--glass);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
  }
  /* Toggled every frame by refreshGlass() in app.js to force the blur to redraw. */
  #views > #train-info.glass-flip,
  #focus-card.glass-flip,
  #toast.glass-flip {
    -webkit-backdrop-filter: blur(4.01px);
    backdrop-filter: blur(4.01px);
  }

  /* Below the line title, clear of the buttons on the right. */
  #toast { top: 60px; left: 12px; right: 56px; max-width: none; width: fit-content; margin-left: auto; }
}
