@font-face {
  font-family: "Archivo";
  src: url("/fonts/archivo-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Archivo";
  src: url("/fonts/archivo-latin-ext.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Doto";
  src: url("/fonts/doto-latin.woff2") format("woff2");
  font-weight: 400 900;
  font-display: block;
}

:root {
  /* shell */
  --blue: #1D4F91;
  --blue-deep: #163E73;
  --blue-ink: #C9D6EA;
  --ground: #E9EDF2;
  --paper: #FBFBFC;
  --ink: #16202B;
  --ink-2: #4A5664;
  --rule: #CDD4DC;
  --tint: #EDF1F7;
  /* validator */
  --violet: #5B3F99;
  --violet-paper: #F6F3FB;
  /* delay scale */
  --ok: #2E8B57;
  --warn: #E3A21A;
  --late: #C62F2F;
  --unknown: #8A96A3;

  --float: 0 1px 2px rgb(16 32 48 / .16), 0 3px 8px rgb(16 32 48 / .10);
  --rail-h: 64px;
  --stub-w: 400px;
  --font: "Archivo", system-ui, sans-serif;
  --stamp: "Doto", ui-monospace, monospace;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: grid;
  grid-template-rows: var(--rail-h) 1fr;
  grid-template-columns: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--ground);
  color: var(--ink);
  font: 400 15px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  caret-color: var(--blue);
}

::selection { background: color-mix(in srgb, var(--violet) 22%, transparent); color: var(--ink); }

:focus-visible { outline: 2px solid var(--violet); outline-offset: 2px; }

a { color: var(--blue); text-underline-offset: .18em; text-decoration-thickness: 1px; }
a:hover { color: var(--blue-deep); text-decoration-thickness: 2px; }

button { font: inherit; color: inherit; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── header rail ───────────────────────────────────────────── */

.rail {
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 0 20px 0 24px;
  padding-left: max(24px, env(safe-area-inset-left));
  background: var(--blue);
  color: #fff;
  position: relative;
  z-index: 1000;
}

.brand { display: flex; align-items: baseline; gap: 14px; min-width: 0; }

.wordmark {
  margin: 0;
  font-size: 23px;
  font-weight: 800;
  font-stretch: 112%;
  letter-spacing: -0.02em;
  line-height: 1;
}

.tagline { margin: 0; color: var(--blue-ink); font-size: 14px; white-space: nowrap; }

.fleet {
  display: flex;
  gap: 18px;
  margin: 0 0 0 auto;
  color: var(--blue-ink);
  font-size: 14px;
  white-space: nowrap;
}
.fleet b { color: #fff; font-weight: 700; font-size: 16px; }

/* The validator stamp: a slip of ticket stock carrying the last refresh in
   violet dot-matrix ink. It re-prints on every refresh. */
.stamp {
  position: relative;
  display: grid;
  grid-template-columns: auto auto;
  column-gap: 12px;
  align-items: baseline;
  padding: 6px 12px 6px 12px;
  background: var(--violet-paper);
  color: var(--violet);
  transform: rotate(-1.2deg);
  box-shadow: 0 2px 3px rgb(0 0 0 / .22);
}
.stamp-label {
  grid-row: 1 / span 2;
  align-self: center;
  max-width: 5.5em;
  color: var(--ink-2);
  font-size: 11px;
  line-height: 1.15;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.stamp-time, .stamp-groups {
  font-family: var(--stamp);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: .02em;
  white-space: nowrap;
}
.stamp-time { font-size: 19px; }
.stamp-groups { font-size: 13px; }
.stamp.press .stamp-time, .stamp.press .stamp-groups { animation: press 420ms var(--ease-out); }
@keyframes press {
  from { opacity: 0; filter: blur(1.5px); transform: scale(1.08) translateY(-1px); }
  to { opacity: 1; filter: blur(0); transform: none; }
}
.stamp-void {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%) rotate(-8deg);
  padding: 1px 8px;
  border: 2px solid var(--late);
  color: var(--late);
  background: color-mix(in srgb, var(--violet-paper) 80%, transparent);
  font: 800 15px/1.1 var(--stamp);
  letter-spacing: .12em;
  text-transform: uppercase;
}
.stamp.stale .stamp-time, .stamp.stale .stamp-groups { opacity: .45; }

/* ── workspace ─────────────────────────────────────────────── */

.workspace {
  display: grid;
  grid-template-columns: 1fr var(--stub-w);
  min-height: 0;
}

.map-area { position: relative; min-width: 0; isolation: isolate; }
#map { position: absolute; inset: 0; background: #E4E8EC; }

.leaflet-container { font: inherit; }
/* OSM's standard tiles are loud; mute them so vehicle colour owns the map */
.leaflet-tile-pane { filter: grayscale(.85) sepia(.08) hue-rotate(180deg) brightness(1.06) contrast(.82); }
.leaflet-control-attribution {
  background: rgb(251 251 252 / .86) !important;
  color: var(--ink-2) !important;
  font-size: 11px;
}
.leaflet-control-attribution a { color: var(--ink-2); }
.leaflet-bar { border: 0 !important; box-shadow: var(--float) !important; border-radius: 0 !important; }
.leaflet-bar a { color: var(--ink) !important; border-radius: 0 !important; }
.leaflet-bar a:hover { background: var(--tint) !important; }

.vehicles { position: absolute; top: 0; left: 0; pointer-events: none; }

/* find a line */
.find {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 800;
  display: flex;
  align-items: center;
  background: var(--paper);
  box-shadow: var(--float);
}
.find input {
  width: 8.5em;
  padding: 9px 12px;
  border: 0;
  background: transparent;
  font: 600 15px/1.2 var(--font);
  color: var(--ink);
}
.find input::placeholder { color: var(--ink-2); font-weight: 400; }
.find input:focus-visible { outline: none; }
.find:focus-within { outline: 2px solid var(--violet); outline-offset: 2px; }
.find-clear {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-right: 4px;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.find-clear svg { width: 14px; height: 14px; stroke: var(--ink-2); stroke-width: 1.6; stroke-linecap: round; fill: none; }
.find-clear:hover svg { stroke: var(--ink); }
.find-clear[hidden] { display: none; }

/* map key */
.legend {
  position: absolute;
  left: 16px;
  bottom: 24px;
  z-index: 800;
  margin: 0;
  padding: 10px 12px;
  background: var(--paper);
  box-shadow: var(--float);
  font-size: 13px;
}
.legend ul { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend small { color: var(--ink-2); font-size: 12px; }
.legend-shapes { margin-top: 4px; padding-top: 6px; border-top: 1px solid var(--rule); }
.key { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 0 1px #fff; }
.key-ok { background: var(--ok); }
.key-warn { background: var(--warn); }
.key-late { background: var(--late); }
.key-unknown { background: #fff; box-shadow: inset 0 0 0 2px var(--unknown); }
.shape { display: inline-block; flex: none; background: var(--ink-2); }
.shape-tram { width: 16px; height: 8px; border-radius: 4px; }
.shape-bus { width: 9px; height: 9px; border-radius: 50%; margin-left: 8px; }

/* vehicle tooltip */
.tip {
  position: absolute;
  z-index: 900;
  min-width: 190px;
  max-width: 280px;
  padding: 10px 12px;
  background: var(--paper);
  box-shadow: var(--float);
  pointer-events: none;
  font-size: 13px;
  line-height: 1.35;
}
.tip-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.tip-head strong { font-size: 14px; }
.tip .badge { height: 24px; min-width: 34px; padding: 0 5px; font-size: 15px; }
.tip-delay { font-weight: 700; }
.tip-meta { color: var(--ink-2); }

.map-state {
  position: absolute;
  top: 16px;
  left: 50%;
  z-index: 800;
  transform: translateX(-50%);
  margin: 0;
  padding: 8px 14px;
  background: var(--paper);
  box-shadow: var(--float);
  font-size: 14px;
}
.map-state:empty { display: none; }
.map-state.error { color: var(--late); font-weight: 600; }

/* ── ticket stub (ranking rail) ────────────────────────────── */

.stub {
  position: relative;
  z-index: 900;
  min-height: 0;
  filter: drop-shadow(-6px 0 16px rgb(16 32 48 / .12));
}

.stub-body {
  height: 100%;
  overflow-y: auto;
  padding: 24px 24px 20px 34px;
  background: var(--paper);
  /* perforated tear-off edge: a column of notches cut from the paper */
  -webkit-mask: radial-gradient(circle 4px at 0 50%, #0000 97%, #000) 0 0 / 100% 14px repeat-y;
  mask: radial-gradient(circle 4px at 0 50%, #0000 97%, #000) 0 0 / 100% 14px repeat-y;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}
.stub-body::before {
  /* the perforation line itself */
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 16px;
  border-left: 1px dashed var(--rule);
}

.stub-handle { display: none; }

.stub h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 750;
  font-stretch: 94%;
  letter-spacing: -0.015em;
  line-height: 1.15;
}
.lede { margin: 4px 0 0; color: var(--ink-2); font-size: 14px; }

.now {
  margin: 18px 0 0;
  padding: 12px 0;
  border-block: 1px solid var(--rule);
  font-size: 14px;
}
.now:empty { display: none; }
.now strong { font-weight: 700; }

/* tram / bus sides */
.sides {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  margin: 18px 0 0;
  padding: 3px;
  border: 1px solid var(--blue);
}
.sides button {
  padding: 6px 12px;
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 160ms var(--ease-out), color 160ms var(--ease-out);
}
.sides button:hover { background: var(--tint); }
.sides button[aria-selected="true"] { background: var(--blue); color: #fff; }
.sides button:focus-visible { outline-offset: -4px; outline-color: #fff; box-shadow: inset 0 0 0 2px var(--violet); }

/* ranking */
.ranking { --cols: 44px 1fr 64px; margin-top: 14px; }

.scale {
  position: relative;
  height: 18px;
  margin-left: calc(44px + 12px);
  margin-right: calc(64px + 10px);
  color: var(--ink-2);
  font-size: 11px;
}
.scale span { position: absolute; left: calc(var(--at) * 100%); transform: translateX(-50%); white-space: nowrap; }
.scale span:first-child { transform: none; }
.scale span:last-child { transform: translateX(-70%); }

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

.row {
  display: grid;
  grid-template-columns: var(--cols);
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 2px;
  align-items: center;
  width: 100%;
  padding: 7px 10px 7px 0;
  border: 0;
  border-bottom: 1px solid var(--rule);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background-color 140ms var(--ease-out);
}
.lines li:first-child .row { border-top: 1px solid var(--rule); }
.row:hover, .row:focus-visible { background: var(--tint); }
.row:focus-visible { outline-offset: -2px; }
/* a pinned line is "validated": its badge takes the violet stamp ring */
.row[aria-pressed="true"] { background: #DFE7F3; }
.row[aria-pressed="true"] .badge { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--violet); }
.row[aria-pressed="true"] .badge.bus { box-shadow: inset 0 0 0 1.5px var(--blue), 0 0 0 2px var(--paper), 0 0 0 4px var(--violet); }

.badge {
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  height: 30px;
  font-weight: 800;
  font-stretch: 80%;
  font-size: 17px;
  letter-spacing: -0.01em;
  line-height: 1;
}
.badge.tram { background: var(--blue); color: #fff; }
.badge.bus { background: var(--paper); color: var(--blue); box-shadow: inset 0 0 0 1.5px var(--blue); }

.bar-track {
  position: relative;
  height: 12px;
  border-left: 1px solid var(--ink-2);
  border-right: 1px solid var(--rule); /* the 30-min end of the scale */
}
.bar-track::before, .bar-track::after {
  content: "";
  position: absolute;
  top: -3px;
  bottom: -3px;
  border-left: 1px solid var(--rule);
}
.bar-track::before { left: 33.333%; }
.bar-track::after { left: 66.667%; }
.bar {
  position: absolute;
  z-index: 1; /* above the gridlines */
  inset: 1px auto 1px 0;
  width: 100%;
  background: var(--c, var(--ok));
  transform: scaleX(var(--v, 0));
  transform-origin: left;
  transition: transform 600ms var(--ease-out);
}
.bar.over { clip-path: polygon(0 0, calc(100% - 6px) 0, 100% 50%, calc(100% - 6px) 100%, 0 100%); }

.figure {
  grid-row: 1;
  grid-column: 3;
  justify-self: end;
  color: var(--violet);
  font: 800 19px/1 var(--stamp);
  white-space: nowrap;
}
.figure small { font: 600 11px/1 var(--font); color: var(--ink-2); margin-left: 2px; }
/* Doto's full stop reads as a plus and its colon as a dagger; set separators in the text face */
.sep { font-family: var(--font); font-weight: 700; margin: 0 .04em; }

.detail {
  grid-column: 2 / span 2;
  color: var(--ink-2);
  font-size: 12px;
  line-height: 1.3;
}

.empty {
  margin: 0;
  padding: 18px 0;
  border-block: 1px solid var(--rule);
  color: var(--ink-2);
  font-size: 14px;
}

.today { margin: 14px 0 0; color: var(--ink-2); font-size: 13px; }
.today:empty { display: none; }
.today strong { color: var(--ink); }

.method {
  margin-top: 22px;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
  color: var(--ink-2);
  font-size: 12px;
  line-height: 1.45;
}
.method p { margin: 0 0 6px; max-width: 60ch; }
.lede, .now, .today, .method p { text-wrap: pretty; }

/* phone-only pieces: the map key and fleet split live in the stub there */
.key-line, .now-split { display: none; }

/* ── narrow screens: map first, ranking as a pull-up stub ──── */

@media (max-width: 1100px) {
  :root { --stub-w: 360px; }
  .tagline, .fleet-note { display: none; }
  .rail { gap: 20px; }
}

@media (max-width: 760px) {
  :root { --rail-h: 56px; }
  body { grid-template-rows: var(--rail-h) 1fr; }
  .rail { padding: 0 12px 0 16px; gap: 12px; }
  .wordmark { font-size: 20px; }
  .fleet { gap: 10px; font-size: 13px; }
  .fleet b { font-size: 14px; }
  .stamp { grid-template-columns: auto; padding: 4px 8px; margin-left: auto; }
  .stamp-label, .stamp-groups, .stamp-date { display: none; }
  .stamp-time { font-size: 16px; }

  .workspace { grid-template-columns: 1fr; position: relative; }
  .map-area { grid-row: 1; grid-column: 1; }

  .find { top: 12px; left: 12px; }
  .find input { font-size: 16px; } /* below 16px iOS zooms on focus */
  .legend { display: none; }
  .map-state { top: 64px; }

  :root { --peek: 176px; }
  .stub {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: min(78dvh, 640px);
    transform: translateY(calc(100% - var(--peek)));
    transition: transform 360ms var(--ease-out);
    filter: drop-shadow(0 -6px 16px rgb(16 32 48 / .16));
  }
  .stub.open { transform: none; }
  .stub.dragging { transition: none; }

  /* collapsed, the peek shows the heading, the key and the worst line */
  .stub:not(.open) :is(.lede, .now, .sides, .scale) { display: none; }
  .stub:not(.open) .ranking { margin-top: 8px; }
  .key-line {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    margin: 6px 0 0;
    padding: 0;
    list-style: none;
    color: var(--ink-2);
    font-size: 12px;
  }
  .key-line li { display: flex; align-items: center; gap: 5px; }
  .key-line .key { width: 9px; height: 9px; }
  .key-line .shape-tram { width: 13px; height: 7px; }
  .key-line .shape-bus { width: 8px; height: 8px; margin-left: 0; }
  .now-split { display: inline; }
  .stub-body {
    padding: 30px 16px calc(16px + env(safe-area-inset-bottom));
    -webkit-mask: radial-gradient(circle 4px at 50% 0, #0000 97%, #000) 0 0 / 14px 100% repeat-x;
    mask: radial-gradient(circle 4px at 50% 0, #0000 97%, #000) 0 0 / 14px 100% repeat-x;
    overflow-y: hidden;
  }
  .stub.open .stub-body { overflow-y: auto; }
  .stub-body::before { left: 0; right: 0; top: 14px; bottom: auto; border-left: 0; border-top: 1px dashed var(--rule); }
  .stub-handle {
    display: block;
    position: absolute;
    z-index: 1;
    top: 0;
    left: 0;
    right: 0;
    height: 30px;
    border: 0;
    background: transparent;
    cursor: grab;
    touch-action: none;
  }
  .stub h2 { cursor: grab; touch-action: none; user-select: none; }
  .stub-handle::after {
    content: "";
    position: absolute;
    top: 18px;
    left: 50%;
    width: 40px;
    height: 4px;
    margin-left: -20px;
    border-radius: 2px;
    background: var(--rule);
  }
  .stub h2 { font-size: 19px; }
  .ranking { --cols: 40px 1fr 60px; }
  .scale { margin-left: calc(40px + 12px); margin-right: calc(60px + 10px); }
  .leaflet-bottom { bottom: var(--peek); }
}

@media (max-width: 480px) {
  /* the tram/bus split moves into the stub's "right now" line */
  .fleet { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
