:root {
  --ink: #1d2330;
  --muted: #667085;
  --line: #e3e6ec;
  --bg: #fff;
  /* Where a time comes from */
  --timetable: #64748b;
  --estimate: #2563eb;
  --actual: #7c3aed;
  /* How late it is */
  --on: #15803d;
  --late: #d97706;
  --vlate: #dc2626;
  --cancelled: #111827;
  --sheet: 33.34dvh;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.35 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  display: grid;
  grid-template-rows: 1fr var(--sheet);
  height: 100dvh;
  overflow: hidden;
}
body.big { --sheet: 66.67dvh; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--estimate); }

#map { grid-row: 1; min-height: 0; background: #dfe3ea; z-index: 0; }
/* The map controls (tune.js) set these; without them the background is as it always was. */
.tiles-grey { filter: grayscale(var(--bg-grey, 1)) contrast(var(--bg-contrast, 0.9)) brightness(var(--bg-bright, 1.06)); }
.leaflet-container { font: inherit; }

/* ---- search and time range, over the map ---- */
#top {
  position: absolute; z-index: 500; top: 0; left: 0; right: 0;
  padding: calc(6px + env(safe-area-inset-top)) 8px 0;
  display: grid; gap: 5px; pointer-events: none;
}
#top .row { display: flex; gap: 6px; pointer-events: none; }
#top .row > * { pointer-events: auto; }
.ac { position: relative; flex: 1; min-width: 0; }
#top input, #top button {
  border: 1px solid #c9ced8; border-radius: 9px; background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18); height: 40px;
}
#search { width: 100%; padding: 0 11px; font-size: 16px; }
#locate { width: 42px; font-size: 22px; line-height: 1; padding: 0; }
/* Vanilla or Trainslut: one control, the half that is on is dark. */
#view { display: flex; flex: none; border: 1px solid #c9ced8; border-radius: 9px; overflow: hidden; background: rgba(255, 255, 255, 0.96); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18); }
#view button { border: 0; border-radius: 0; box-shadow: none; background: none; height: 38px; padding: 0 9px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
#view button.on { background: var(--ink); color: #fff; }
@media (max-width: 400px) { #view button { padding: 0 6px; font-size: 12px; } }
/* What only the Trainslut view shows. */
body:not(.tech) .tech-only { display: none !important; }
body:not(.tech) .train > .head { grid-template-columns: 44px 1fr auto auto; }
.times label {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
  background: rgba(255, 255, 255, 0.96); border: 1px solid #c9ced8; border-radius: 9px; padding-left: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}
.times input { flex: 1; min-width: 0; border: 0 !important; box-shadow: none !important; background: none !important; font-size: 16px; padding: 0 4px 0 0; height: 36px !important; }
.presets { overflow-x: auto; scrollbar-width: none; padding-bottom: 4px; }
.presets::-webkit-scrollbar { display: none; }
.presets button { height: 30px !important; padding: 0 11px; font-size: 13px; white-space: nowrap; border-radius: 15px !important; }
.presets button.on { background: var(--ink) !important; color: #fff; border-color: var(--ink) !important; }
#suggest {
  position: absolute; left: 0; right: 0; top: 44px; margin: 0; padding: 4px 0; list-style: none; background: #fff;
  border: 1px solid #c9ced8; border-radius: 9px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2); max-height: 45dvh; overflow: auto;
}
#suggest li { padding: 9px 12px; display: flex; justify-content: space-between; gap: 10px; }
#suggest li.hot, #suggest li:active { background: #eef2ff; }
#suggest small { color: var(--muted); font-family: ui-monospace, Menlo, monospace; }

/* ---- the panel: a third of the screen ---- */
#sheet {
  grid-row: 2; min-height: 0; background: var(--bg); border-top: 1px solid #c9ced8; z-index: 600;
  display: flex; flex-direction: column; box-shadow: 0 -3px 12px rgba(0, 0, 0, 0.12);
  padding-bottom: env(safe-area-inset-bottom);
}
#grip { border: 0; background: none; height: 16px; flex: none; position: relative; }
#grip::after { content: ''; position: absolute; left: 50%; top: 6px; width: 42px; height: 4px; margin-left: -21px; border-radius: 2px; background: #c3c8d2; }
#sheet header { display: flex; align-items: baseline; gap: 8px; padding: 0 12px; flex: none; }
#title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
h1 { font-size: 17px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#station-codes { font: 12px ui-monospace, Menlo, monospace; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#close { border: 0; background: none; font-size: 24px; line-height: 1; padding: 0 4px; color: var(--muted); }
#status { margin: 1px 12px 0; font-size: 12px; color: var(--muted); flex: none; display: flex; align-items: center; gap: 6px; }
#dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: #9ca3af; }
#dot.live { background: var(--on); box-shadow: 0 0 0 3px rgba(21, 128, 61, 0.18); }
#dot.wait { background: var(--late); animation: pulse 1.2s infinite; }
#dot.off { background: #9ca3af; }
@keyframes pulse { 50% { opacity: 0.3; } }
#moan { margin-left: auto; flex: none; border: 1px solid #c9ced8; border-radius: 11px; background: #fff; padding: 1px 10px; font-size: 12px; font-weight: 600; color: var(--ink); }
#loading { margin: 6px 12px 0; padding: 6px 8px; font-size: 13px; font-weight: 600; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 6px; color: #1e3a8a; flex: none; display: flex; align-items: center; gap: 8px; }
#loading[hidden] { display: none; }
#loading .spin { width: 12px; height: 12px; flex: none; border-radius: 50%; border: 2px solid #93c5fd; border-top-color: #1d4ed8; animation: spin 0.9s linear infinite; }
#loading.slow { background: #fff7ed; border-color: #fed7aa; color: #7c2d12; font-weight: 400; }
#loading.slow .spin { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
#notice { margin: 4px 12px 0; padding: 5px 8px; font-size: 12px; background: #fff7ed; border: 1px solid #fed7aa; border-radius: 6px; color: #7c2d12; flex: none; }

#tabs { display: flex; border-bottom: 1px solid var(--line); margin-top: 4px; flex: none; overflow-x: auto; scrollbar-width: none; }
#tabs button { flex: 1; border: 0; background: none; padding: 7px 6px 6px; font-size: 13px; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
#tabs button.on { color: var(--ink); border-bottom-color: var(--ink); }
#tabs b { font-weight: 500; font-size: 11px; background: #eef0f4; border-radius: 8px; padding: 0 5px; }
#filter { flex: none; padding: 5px 12px; font-size: 12px; background: #eef2ff; display: flex; gap: 8px; align-items: center; }
#filter button { border: 0; background: none; font-size: 16px; line-height: 1; padding: 0 4px; margin-left: auto; }

#list { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.hint { margin: 14px 12px; color: var(--muted); }
.train { border-bottom: 1px solid var(--line); }
.train > .head {
  display: grid; grid-template-columns: 44px 44px 1fr auto auto; gap: 7px; align-items: center;
  width: 100%; padding: 7px 12px 7px 7px; border: 0; border-left: 6px solid transparent; background: none; text-align: left;
}
.train.open > .head { background: #f6f7fa; }
/* The trains after the time range: on the board under a heading, paler, and not on the map. */
.later-head { margin: 0; padding: 8px 12px; display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); background: #f6f7fa; border-bottom: 1px solid var(--line); }
.later-head button { margin-left: auto; flex: none; padding: 4px 8px; font-size: 12px; font-weight: 600; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.train.later > .head { opacity: 0.7; }
.train.cancelled .place b { text-decoration: line-through; }
.time { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 16px; }
.time.working { font-style: italic; font-weight: 500; }
.hc { font: 700 14px ui-monospace, Menlo, monospace; letter-spacing: 0.3px; }
.hc.none { color: var(--muted); font-weight: 400; }
.place { min-width: 0; }
.place b, .place small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.place small { color: var(--muted); font-size: 11.5px; }
.plat { font-size: 12px; text-align: center; min-width: 30px; border: 1px solid var(--line); border-radius: 5px; padding: 1px 4px; white-space: nowrap; }
.plat.live { border-color: var(--estimate); color: var(--estimate); }
.plat.confirmed { border-color: var(--actual); color: var(--actual); font-weight: 700; }
.plat.suppressed { border-style: dashed; }
.state { text-align: right; white-space: nowrap; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }

.pill { display: inline-block; font-size: 11.5px; font-weight: 700; border-radius: 4px; padding: 1px 6px; color: #fff; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pill.timetable { background: none; color: var(--timetable); border: 1px dashed var(--timetable); }
.pill.estimate { background: var(--estimate); }
.pill.actual { background: var(--actual); }
.pill.cancelled { background: var(--cancelled); }
.late { font-size: 11.5px; font-weight: 700; }
.late.on, .late.early { color: var(--on); }
.late.late, .late.unknown { color: var(--late); }
.late.vlate { color: var(--vlate); }
.late.cancelled { color: var(--cancelled); text-decoration: line-through; }

/* ---- one train's detail ---- */
.detail { padding: 2px 12px 12px; background: #f6f7fa; font-size: 12.5px; }
.detail .meta { display: flex; flex-wrap: wrap; gap: 3px 10px; color: var(--muted); margin: 0 0 6px; }
.detail .meta span b { color: var(--ink); font: 600 12px ui-monospace, Menlo, monospace; }
.detail .reason { margin: 0 0 6px; padding: 4px 8px; border-left: 3px solid var(--late); background: #fff; }
.detail .reason.cancel { border-color: var(--cancelled); }
.detail .links { display: flex; gap: 14px; margin: 0 0 6px; }
.detail .links button { border: 0; background: none; padding: 0; color: var(--estimate); text-decoration: underline; font-size: 12.5px; }
.calls { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); }
.calls th { text-align: left; font-size: 11px; color: var(--muted); font-weight: 600; padding: 3px 6px; border-bottom: 1px solid var(--line); }
.calls td { padding: 3px 6px; border-bottom: 1px solid #f0f1f4; vertical-align: top; }
.calls tr.here td { background: #fffbe6; }
.calls tr.pp td { color: var(--muted); font-size: 11.5px; }
.calls tr.can .loc { text-decoration: line-through; }
.calls .loc small { display: block; color: var(--muted); font: 10.5px ui-monospace, Menlo, monospace; }
.calls .t { white-space: nowrap; font-variant-numeric: tabular-nums; }
.calls .t i { font-style: italic; }
.calls .t .pill { margin-left: 4px; }
.calls .t small { display: block; color: var(--muted); font-size: 10.5px; }

.dest { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; width: 100%; padding: 8px 12px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; }
.dest b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dest .n { font-weight: 700; }
.dest small { grid-column: 1 / -1; color: var(--muted); font-size: 11.5px; }
.dest small .hc { font-size: 11.5px; color: var(--ink); }

#key { flex: none; border-top: 1px solid var(--line); font-size: 12px; padding: 0 12px; max-height: 45%; overflow-y: auto; }
#key summary { padding: 5px 0; color: var(--muted); }
#key p { margin: 0 0 7px; }
#key .credit, #data-info { color: var(--muted); }
i.line-unused { display: inline-block; width: 22px; height: 0; border-top: 4px solid; vertical-align: middle; border-radius: 2px; }
i.line.timetable { border-top-style: dashed; border-color: var(--timetable); }
i.line.on { border-color: var(--on); }
i.line.late { border-color: var(--late); }
i.line.vlate { border-color: var(--vlate); }
i.line.cancelled { border-top-style: dotted; border-color: var(--cancelled); }

.leaflet-popup-content { margin: 10px 12px; font-size: 13px; }
.leaflet-popup-content button { margin-top: 6px; border: 1px solid #c9ced8; border-radius: 6px; background: #fff; padding: 5px 9px; }
.station-label { background: var(--ink); color: #fff; border: 0; font-weight: 600; box-shadow: none; font-size: var(--sel-label, inherit); }
.station-label::before { display: none; }

/* ---- wide screens and phones on their side: the panel is the left third ---- */
@media (orientation: landscape) and (min-width: 700px) {
  body { grid-template-rows: 1fr; grid-template-columns: max(33.34vw, 330px) 1fr; }
  body.big { grid-template-columns: 50vw 1fr; }
  #sheet { grid-row: 1; grid-column: 1; border-top: 0; border-right: 1px solid #c9ced8; box-shadow: 3px 0 12px rgba(0, 0, 0, 0.1); padding-left: env(safe-area-inset-left); }
  #map { grid-row: 1; grid-column: 2; }
  #top { left: max(33.34vw, 330px); max-width: 560px; }
  body.big #top { left: 50vw; }
  #grip::after { left: auto; right: 3px; top: 50%; width: 4px; height: 42px; margin: -21px 0 0; }
  #grip { position: absolute; right: 0; top: 0; bottom: 0; height: auto; width: 12px; z-index: 2; }
  #sheet { position: relative; padding-top: 8px; }
}

/* ---- lines ---- */
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; margin-right: 6px; vertical-align: -2px; flex: none; }
.dest.on { background: #eef2ff; }
.dest small { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#filter { justify-content: flex-start; }
.leaflet-popup-content .stops { color: var(--muted); font-size: 12px; margin-top: 3px; max-height: 6.5em; overflow: auto; }

/* ---- the Moan dialog ---- */
#moan-dialog { width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); border: 1px solid #c9ced8; border-radius: 12px; padding: 16px; color: var(--ink); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3); }
#moan-dialog::backdrop { background: rgba(29, 35, 48, 0.45); }
#moan-dialog h2 { font-size: 17px; margin: 0 0 6px; }
#moan-dialog p { margin: 0 0 10px; }
#moan-dialog label { display: block; font-size: 12.5px; font-weight: 600; margin: 0 0 10px; }
#moan-dialog textarea, #moan-dialog input[type='email'] { display: block; width: 100%; margin-top: 3px; padding: 7px 9px; border: 1px solid #c9ced8; border-radius: 8px; font: inherit; font-size: 16px; font-weight: 400; }
#moan-dialog textarea { resize: vertical; }
#moan-dialog label.check { font-weight: 400; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
#moan-shot-state { color: var(--muted); }
#moan-tech { font-size: 12px; color: var(--muted); }
body.replay #moan { display: none; }
#moan-preview { display: block; max-width: 100%; max-height: 130px; border: 1px solid var(--line); border-radius: 6px; margin: 0 0 10px; }
#moan-preview[hidden], #moan-form[hidden], #moan-done[hidden] { display: none; }
#moan-error { padding: 5px 8px; font-size: 12.5px; background: #fef2f2; border: 1px solid #fecaca; border-radius: 6px; color: #7f1d1d; }
#moan-dialog .buttons { display: flex; justify-content: flex-end; gap: 8px; margin: 0; }
#moan-dialog .buttons button { border: 1px solid #c9ced8; border-radius: 9px; background: #fff; padding: 7px 14px; font-weight: 600; }
#moan-dialog .buttons button[type='submit'], #moan-dialog .buttons #moan-close { background: var(--ink); color: #fff; border-color: var(--ink); }
#moan-dialog .buttons button:disabled { opacity: 0.5; }
#moan-ticket { font: 700 16px ui-monospace, Menlo, monospace; }

/* Lab view: the same map on plain white, with the layout's measurements. */
body.lab #map { background: #fff; }
#lab { margin: 0 12px 6px; font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
#lab[hidden] { display: none; }
#lab select { font: inherit; }
#lab-out { color: #1d2330; }
#lab .swap { color: #dc2626; } #lab .parting { color: #d97706; }
/* A stop only some of a line's trains call at, with how many do. */
.stops .some { opacity: 0.6; white-space: nowrap; }
.stops .some small { font-size: 0.85em; display: inline; }
.dest small .stops { display: inline; }

/* ---- map controls (tune.js): the sliders take the board's place in the panel ---- */
#tune { display: none; flex: 1; min-height: 0; flex-direction: column; font-size: 12px; }
body.tunable.tuning #tune { display: flex; }
body.tunable.tuning #sheet > :not(#grip):not(#tune) { display: none !important; }
/* The controls' buttons, in browsers that have been given them (#tune=1). */
body:not(.tunable) .tune-only { display: none !important; }
#tune-open { margin-left: auto; flex: none; border: 1px solid #c9ced8; border-radius: 11px; background: #fff; padding: 1px 10px; font-size: 12px; font-weight: 600; color: var(--ink); }
body.tunable #tune-open + #moan { margin-left: 0; }
#tune-head { flex: none; margin: 0; padding: 0 12px 5px; display: flex; align-items: baseline; gap: 8px; border-bottom: 1px solid var(--line); }
#tune-head b { font-size: 14px; flex: none; }
#tune-zoom { color: var(--muted); min-width: 0; }
#tune-back { margin-left: auto; flex: none; }
#tune button, #tune-from { border: 1px solid #c9ced8; border-radius: 6px; background: #fff; padding: 3px 8px; font: inherit; }
#tune-body { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 4px 12px 10px; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 2px 18px; align-content: start; }
#tune fieldset { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 4px 0 2px; min-width: 0; }
#tune fieldset[hidden] { display: none; }
#tune legend { padding: 0 4px 0 0; font-weight: 600; color: var(--muted); }
#tune label { display: grid; grid-template-columns: 96px 1fr 40px; gap: 4px; align-items: center; min-height: 26px; }
#tune input[type=range] { width: 100%; min-width: 0; margin: 0; }
#tune output { text-align: right; font-variant-numeric: tabular-nums; }
#tune-note { grid-column: 1 / -1; margin: 0; color: var(--vlate); }
#tune-note[hidden] { display: none; }
#tune-out { grid-column: 1 / -1; }
#tune-string { width: 100%; margin-top: 6px; font: 10.5px/1.3 ui-monospace, Menlo, monospace; border: 1px solid #c9ced8; border-radius: 6px; padding: 4px; resize: vertical; }
#tune .buttons { margin: 4px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
#tune-scales { margin: 4px 0 0; font: 10.5px/1.35 ui-monospace, Menlo, monospace; overflow-x: auto; }
#tune details summary { margin-top: 6px; color: var(--muted); cursor: pointer; }

/* ---- known bugs: one line under the status, which opens ---- */
#bugs { flex: none; margin: 3px 12px 0; font-size: 12px; max-height: 45%; overflow-y: auto; }
#bugs summary { color: var(--late); font-weight: 600; cursor: pointer; }
#bugs ul { margin: 4px 0 6px; padding-left: 18px; }
#bugs li { margin-bottom: 4px; }
#bugs button { border: 1px solid #c9ced8; border-radius: 6px; background: #fff; padding: 1px 8px; font: inherit; }
body.replay #bugs { display: none; }
#tune-help { grid-column: 1 / -1; }
#tune-help summary { margin-top: 0; font-weight: 600; color: var(--ink); }
#tune-help ol { margin: 4px 0 6px; padding-left: 20px; max-width: 70ch; }
#tune-help li { margin-bottom: 3px; }
