/* ── Tokens ─────────────────────────────────────────────────────────
   Palette: Porto azulejo. Cool porcelain ground, cobalt ink, and the
   metro line colours as the only saturated things on the page.
   ------------------------------------------------------------------ */
:root {
  --porcelain: #eef3f7;
  --glaze: #ffffff;
  --ink: #16305c;
  --ink-soft: #5b7ba6;
  --hairline: #d4dfe9;
  --hairline-firm: #b9cbdc;

  --r-sm: 6px;
  --r-md: 12px;
  --r-lg: 18px;

  --pad: 20px;

  --display: "Archivo", system-ui, sans-serif;
  --body: "IBM Plex Sans", system-ui, sans-serif;
  --data: "IBM Plex Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--porcelain);
  color: var(--ink);
  font-family: var(--body);
  -webkit-text-size-adjust: 100%;
}

body {
  max-width: 560px;
  margin-inline: auto;
  padding: 0 var(--pad) calc(48px + env(safe-area-inset-bottom));
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
  border-radius: var(--r-sm);
}

/* ── Masthead ───────────────────────────────────────────────────── */
.masthead {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(18px + env(safe-area-inset-top)) 0 22px;
}

.masthead__mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: var(--r-sm);
  background: var(--ink);
  color: var(--porcelain);
  font-family: var(--display);
  font-weight: 800;
  font-size: 17px;
  line-height: 1;
  padding-bottom: 1px;
}

.masthead__title {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-variation-settings: "wdth" 115;
  font-size: 19px;
  letter-spacing: 0.02em;
}

.masthead__refresh {
  margin-left: auto;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--hairline-firm);
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.masthead__refresh svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.masthead__refresh[data-spinning="true"] svg {
  animation: spin 700ms linear infinite;
}

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

/* ── Stop chooser ───────────────────────────────────────────────── */
.chooser {
  position: relative;
}

.chooser__current {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  background: var(--glaze);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: inherit;
}
.chooser__eyebrow {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.chooser__name {
  font-family: var(--display);
  font-size: 16px;
  font-weight: 700;
  font-variation-settings: "wdth" 108;
}
.chooser__chev {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--ink-soft);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 160ms;
}
.chooser__current[aria-expanded="true"] .chooser__chev {
  transform: rotate(180deg);
}

.chooser__panel {
  position: absolute;
  inset: calc(100% + 6px) 0 auto;
  z-index: 20;
  background: var(--glaze);
  border: 1px solid var(--hairline-firm);
  border-radius: var(--r-md);
  box-shadow: 0 14px 34px rgba(22, 48, 92, 0.16);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chooser__panel[hidden] {
  display: none;
}

.chooser__search {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: var(--porcelain);
  font-family: var(--body);
  font-size: 15px;
  color: var(--ink);
}
.chooser__search::placeholder {
  color: var(--ink-soft);
}

.chooser__recents {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chooser__recents:empty {
  display: none;
}
.chip {
  border: 1px solid var(--hairline-firm);
  background: transparent;
  border-radius: 999px;
  padding: 6px 12px;
  font-family: var(--display);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}

.chooser__list {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 46vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.chooser__item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 8px;
  border: 0;
  border-bottom: 1px solid var(--hairline);
  background: transparent;
  font-family: var(--body);
  font-size: 15px;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}
li:last-child .chooser__item {
  border-bottom: 0;
}
.chooser__item[aria-selected="true"] {
  font-weight: 600;
}
.chooser__dots {
  margin-left: auto;
  display: flex;
  gap: 4px;
  flex: none;
}
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--c, var(--hairline-firm));
}
.chooser__none {
  padding: 18px 8px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
}

/* ── Signature: the direction picker as a line diagram ──────────── */
.picker {
  padding: 30px 0 26px;
}

.picker__heading {
  margin: 0 0 22px;
  font-family: var(--body);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.picker__diagram {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  column-gap: 10px;
}

/* the track: striped with every line colour that runs through this stop */
.track {
  grid-column: 1 / -1;
  grid-row: 1;
  height: 6px;
  margin-top: 17px;
  border-radius: 3px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.track__strand {
  flex: 1;
}

/* the terminus buttons sit on top of the track */
.end {
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  z-index: 1;
}
.end--left {
  grid-column: 1;
  align-items: flex-start;
  text-align: left;
}
.end--right {
  grid-column: 3;
  align-items: flex-end;
  text-align: right;
}

.end__cap {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid var(--hairline-firm);
  background: var(--porcelain);
  display: grid;
  place-items: center;
  transition:
    border-color 160ms,
    background 160ms,
    transform 160ms;
}
.end__arrow {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: var(--hairline-firm);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke 160ms;
}
.end--left .end__arrow {
  transform: rotate(180deg);
}

.end__label {
  font-family: var(--display);
  font-size: 14px;
  font-weight: 600;
  font-variation-settings: "wdth" 105;
  color: var(--ink-soft);
  transition: color 160ms;
  max-width: 11ch;
  line-height: 1.25;
}
.end__note {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--hairline-firm);
  margin-top: -6px;
}

.end[aria-pressed="true"] .end__cap {
  border-color: var(--ink);
  background: var(--ink);
  transform: scale(1.06);
}
.end[aria-pressed="true"] .end__arrow {
  stroke: var(--glaze);
}
.end[aria-pressed="true"] .end__label {
  color: var(--ink);
}
.end[aria-pressed="true"] .end__note {
  color: var(--ink-soft);
}

/* you are here */
.here {
  grid-row: 1;
  grid-column: 2;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
}
.here__dot {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: var(--glaze);
  display: grid;
  place-items: center;
}
.here__dot::after {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink);
}
.here__label {
  font-family: var(--display);
  font-size: 13px;
  font-weight: 700;
  font-variation-settings: "wdth" 105;
  white-space: nowrap;
}

/* ── Board ──────────────────────────────────────────────────────── */
.board {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.board__loading,
.board__empty {
  padding: 34px 0;
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
}
.board__empty strong {
  display: block;
  font-family: var(--display);
  font-size: 16px;
  color: var(--ink);
  margin-bottom: 6px;
}

/* line badge */
.badge {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--line, var(--ink));
  color: #fff;
  font-family: var(--display);
  font-weight: 700;
  font-size: 14px;
  line-height: 1;
  flex: none;
}
.badge--lg {
  width: 38px;
  height: 38px;
  font-size: 18px;
}
.badge--onlight {
  color: #fff;
}

/* next departure — the one you actually look at */
.next {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 22px 20px;
  background: var(--glaze);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.next::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--line, var(--ink));
}

.next__headsign {
  font-family: var(--display);
  font-size: 17px;
  font-weight: 600;
  font-variation-settings: "wdth" 105;
  line-height: 1.2;
}
.next__time {
  font-family: var(--data);
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 3px;
}

.next__count {
  display: flex;
  align-items: baseline;
  gap: 3px;
}
.next__min {
  font-family: var(--display);
  font-size: 46px;
  font-weight: 700;
  font-variation-settings: "wdth" 112;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
}
.next__unit {
  font-family: var(--body);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
}
.next__due {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 700;
  font-variation-settings: "wdth" 112;
  color: var(--line, var(--ink));
}

/* the rest */
.row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 13px 20px;
  background: var(--glaze);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
}
.row__headsign {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
}
.row__time {
  font-family: var(--data);
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 2px;
}
.row__count {
  font-family: var(--data);
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.row__count span {
  font-size: 10px;
  font-weight: 400;
  color: var(--ink-soft);
  margin-left: 2px;
}

/* ── Stamp ──────────────────────────────────────────────────────── */
.stamp {
  margin: 20px 0 0;
  text-align: center;
  font-family: var(--data);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--hairline-firm);
  text-transform: uppercase;
}

body[data-loading="true"] .board {
  opacity: 0.45;
}
.board {
  transition: opacity 160ms;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
