:root {
  --ink: #0a1230; /* night Beck blue: the map ground */
  --panel: rgba(13, 21, 56, 0.84);
  --panel-solid: #111a45;
  --hair: rgba(226, 231, 250, 0.1);
  --text: #eef0f8;
  --muted: #9aa2c6;
  --live: #e3342a;
  --warn: #ffb547;
  --focus: #8fb3ff;
  --font: 'Hanken Grotesk', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
}
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- map ---------- */

#map {
  position: fixed;
  inset: 0;
  background: var(--ink);
}
.maplibregl-map {
  font-family: var(--font);
}
.maplibregl-canvas-container {
  background: var(--ink);
}
/* The train canvas: above MapLibre's GL canvas, below its controls. */
.train-layer {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  pointer-events: none;
}
.maplibregl-control-container > * {
  z-index: 2;
}

.maplibregl-ctrl-group {
  border: 1px solid var(--hair);
  border-radius: 10px;
  overflow: hidden;
}
.maplibregl-ctrl.maplibregl-ctrl-group:not(:empty) {
  box-shadow: none;
}
.maplibregl-ctrl-group button {
  background-color: var(--panel-solid);
  width: 34px;
  height: 34px;
}
.maplibregl-ctrl-group button + button {
  border-top: 1px solid var(--hair);
}
.maplibregl-ctrl-group button:not(:disabled):hover {
  background-color: #1a2458;
}
/* MapLibre's +/- icons are dark SVGs; light them for the dark buttons. */
.maplibregl-ctrl-group button .maplibregl-ctrl-icon {
  filter: invert(1) brightness(0.93);
}
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib {
  margin: 0;
}
.maplibregl-ctrl.maplibregl-ctrl-attrib {
  background: rgba(10, 18, 48, 0.72);
  color: var(--muted);
  font-size: 11px;
  border-top-left-radius: 6px;
}
.maplibregl-ctrl-attrib a {
  color: #c3cbee;
}

#station-tip {
  position: fixed;
  z-index: 1001;
  pointer-events: none;
  transform: translate(-50%, -100%);
  white-space: nowrap;
  background: var(--panel-solid);
  color: var(--text);
  border: 1px solid var(--hair);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  font: 500 13px/1.3 var(--font);
  padding: 5px 9px;
}

/* ---------- panel ---------- */

#panel {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  width: 304px;
  max-height: calc(100% - 32px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid var(--hair);
  border-radius: 16px;
  z-index: 1000;
  overflow: hidden;
  box-shadow: 0 18px 48px rgba(3, 6, 22, 0.45);
}

.brand {
  padding: 18px 20px 16px;
}
.title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
h1 {
  flex: 1;
  margin: 0;
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -0.015em;
}
#clock {
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
#summary {
  margin: 10px 0 2px;
  font-size: 15px;
  line-height: 1.4;
}
#summary strong {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
#updated {
  margin: 0;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.muted {
  color: var(--muted);
}

.live-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 0 0 rgba(227, 52, 42, 0.55);
  animation: pulse 2.2s ease-out infinite;
}
.live-dot.stale {
  background: var(--muted);
  animation: none;
}
@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(227, 52, 42, 0.55);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(227, 52, 42, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(227, 52, 42, 0);
  }
}

.roster-wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-top: 1px solid var(--hair);
}
.roster-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 12px 20px 4px;
}
h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.linkish {
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  padding: 2px 5px;
  border-radius: 5px;
}
.linkish:hover {
  color: var(--text);
}
/* "Report a glitch": a plain underlined link, easy to find. */
.report-row {
  margin: 0;
  padding: 0 20px 16px;
}
.report-link {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
}
#report-dialog {
  width: min(420px, calc(100% - 32px));
  padding: 16px 18px;
  color: var(--text);
  background: var(--panel-solid);
  border: 1px solid var(--hair);
  border-radius: 14px;
}
#report-dialog::backdrop {
  background: rgba(3, 6, 22, 0.55);
}
#report-dialog h3 {
  margin: 0 0 6px;
  font-size: 19px;
}
#report-dialog p {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.45;
}
#report-dialog label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
}
#report-dialog textarea {
  box-sizing: border-box;
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--hair);
  border-radius: 8px;
  resize: vertical;
}

#roster {
  list-style: none;
  margin: 0;
  padding: 4px 10px 10px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.row {
  display: grid;
  grid-template-columns: 6px 1fr auto;
  column-gap: 12px;
  align-items: center;
  width: 100%;
  padding: 7px 10px;
  background: none;
  border: 0;
  border-radius: 9px;
  text-align: left;
  cursor: pointer;
}
.row:hover {
  background: rgba(255, 255, 255, 0.05);
}
.row .bar {
  grid-row: span 2;
  align-self: stretch;
  width: 6px;
  border-radius: 3px;
  background: var(--c);
}
.row.dual .bar {
  background: linear-gradient(90deg, var(--c) 0 33%, transparent 33% 67%, var(--c) 67%);
}
.row .name {
  font-size: 14.5px;
  font-weight: 600;
}
.row .count {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.row .status {
  grid-column: 2 / 4;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.35;
}
.row .status.bad {
  color: var(--warn);
}
.row[aria-pressed='false'] {
  opacity: 0.36;
}

.footnote {
  margin: 0;
  padding: 12px 20px 10px;
  border-top: 1px solid var(--hair);
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

.pill {
  display: none;
  margin-top: 12px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--hair);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- card ---------- */

#card {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  width: 330px;
  max-height: calc(100% - 140px);
  overflow-y: auto;
  background: var(--panel);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid var(--hair);
  border-top: 3px solid var(--edge, var(--c, var(--text)));
  border-radius: 16px;
  z-index: 1000;
  padding: 14px 18px 16px;
  box-shadow: 0 18px 48px rgba(3, 6, 22, 0.45);
}
.card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.card-top .sw {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c);
}
.card-top .grow {
  flex: 1;
}
.close {
  background: none;
  border: 0;
  cursor: pointer;
  width: 30px;
  height: 30px;
  margin: -6px -8px -6px 0;
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
}
.close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}
#card h3 {
  margin: 6px 0 2px;
  font-size: 25px;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.015em;
}
#card .sub {
  margin: 0;
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.45;
}

.stops {
  list-style: none;
  margin: 14px 0 0;
  padding: 0 0 0 20px;
  position: relative;
}
.stops::before {
  content: '';
  position: absolute;
  left: 5px;
  top: 12px;
  bottom: 12px;
  width: 2px;
  background: var(--c);
  opacity: 0.55;
}
.stops li {
  position: relative;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  font-size: 14px;
}
.stops li::before {
  content: '';
  position: absolute;
  left: -20px;
  top: 50%;
  width: 8px;
  height: 8px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--panel-solid);
  border: 2px solid var(--c);
}
.stops li:first-child::before {
  background: var(--c);
}
.eta {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stops li:first-child .eta {
  color: var(--text);
  font-weight: 600;
}

.arrivals {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}
.arrivals li {
  display: grid;
  grid-template-columns: 4px 1fr auto;
  column-gap: 10px;
  padding: 7px 0;
  border-top: 1px solid var(--hair);
  font-size: 14px;
}
.arrivals li:first-child {
  border-top: 0;
}
.arrivals .bar {
  grid-row: span 2;
  border-radius: 2px;
  background: var(--c);
}
.arrivals .plat {
  grid-column: 2 / 4;
  font-size: 12.5px;
  color: var(--muted);
}
/* Why a National Rail train is late or cancelled (Darwin). */
.arrivals .reason {
  color: var(--warn);
}
/* A National Rail train that's on the map: tap to show it. */
.arrivals li.live {
  cursor: pointer;
}
.arrivals li.live > span:nth-child(2)::after {
  content: ' ›';
  color: var(--muted);
}
@media (hover: hover) {
  .arrivals li.live:hover > span:nth-child(2) {
    text-decoration: underline;
  }
}
/* "National Rail" over a TfL station's National Rail board. */
.card-sub {
  margin: 16px 0 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.card-actions {
  margin-top: 14px;
  display: flex;
  gap: 8px;
}
.btn {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--hair);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover {
  background: rgba(255, 255, 255, 0.12);
}
.btn[aria-pressed='true'] {
  background: var(--text);
  color: var(--ink);
  border-color: var(--text);
}
.btn.quiet {
  background: none;
  border-color: transparent;
  color: var(--muted);
}

/* ---------- hover label, toast, loader ---------- */

#hover {
  position: fixed;
  z-index: 1001;
  pointer-events: none;
  background: var(--panel-solid);
  border: 1px solid var(--hair);
  border-left: 3px solid var(--edge, var(--c));
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 13px;
  white-space: nowrap;
  transform: translate(14px, -50%);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
#hover.flip {
  transform: translate(calc(-100% - 14px), -50%);
}

#toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 1100;
  max-width: min(520px, calc(100% - 32px));
  background: var(--panel-solid);
  border: 1px solid var(--hair);
  border-left: 3px solid var(--warn);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.45;
}

#loader {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  background: rgba(10, 18, 48, 0.9);
  transition: opacity 0.7s ease;
}
#loader.done {
  opacity: 0;
  pointer-events: none;
}
.loader-inner {
  text-align: center;
  padding: 24px;
}
#loader-text {
  margin: 0;
  font-size: 16px;
  color: var(--text);
  max-width: 440px;
  line-height: 1.5;
}
#loader .bar {
  width: 240px;
  height: 3px;
  margin: 14px auto 0;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
}
#loader-bar {
  display: block;
  height: 100%;
  width: 0;
  background: var(--text);
  transition: width 0.3s ease;
}
#loader code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 6px;
  border-radius: 4px;
}

/* ---------- small screens ---------- */

@media (max-width: 680px) {
  #panel {
    top: auto;
    left: 8px;
    right: 8px;
    width: auto;
    bottom: calc(8px + env(safe-area-inset-bottom));
    max-height: 62%;
    border-radius: 14px;
  }
  /* The panel, closed, is two short rows: the title and train count on the
     left, the lines button on the right. The phone shows the time already,
     and the dot turns amber when updates stall. */
  .brand {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    column-gap: 12px;
    padding: 10px 12px 10px 16px;
  }
  .title-row {
    gap: 8px;
  }
  h1 {
    font-size: 17px;
  }
  #clock,
  #updated {
    display: none;
  }
  #summary {
    grid-column: 1;
    margin: 2px 0 0;
    font-size: 13px;
    color: var(--muted);
  }
  #summary strong {
    color: var(--text);
  }
  .pill {
    display: inline-block;
    grid-column: 2;
    grid-row: 1 / span 2;
    margin: 0;
  }
  #panel.collapsed .roster-wrap {
    display: none;
  }
  /* A card is a sheet at the bottom, in the panel's place (the panel hides
     while it's open), with tighter rows. The map keeps its center above it
     (app.ts, sheetPadding). */
  #card {
    left: 8px;
    right: 8px;
    width: auto;
    top: auto;
    bottom: calc(8px + env(safe-area-inset-bottom));
    max-height: 40%;
    padding: 10px 14px 12px;
    border-radius: 14px;
  }
  body.card-open #panel {
    display: none;
  }
  #card h3 {
    margin: 2px 0 0;
    font-size: 19px;
  }
  #card .sub {
    font-size: 13px;
  }
  .card-top {
    font-size: 12px;
  }
  .arrivals {
    margin-top: 6px;
  }
  .arrivals li {
    padding: 5px 0;
    font-size: 13.5px;
  }
  .arrivals .plat {
    font-size: 12px;
  }
  .stops li {
    padding: 3px 0;
    font-size: 13.5px;
  }
  .card-sub {
    margin-top: 10px;
  }
  /* The Follow button stays in view: pinned to the bottom of the sheet
     while the stops scroll under it (it came after them, below the fold). */
  .card-actions {
    position: sticky;
    bottom: -12px;
    margin: 8px -14px -12px;
    padding: 8px 14px 12px;
    background: var(--panel-solid);
    border-top: 1px solid var(--hair);
  }
  .maplibregl-ctrl-group {
    display: none;
  }
  /* The credits' (i) goes to the top right, which is free (cards open at
     the bottom), so no row is kept for it; tapped, it opens downward. */
  .maplibregl-ctrl-bottom-right {
    top: env(safe-area-inset-top);
    bottom: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .live-dot {
    animation: none;
  }
  #loader,
  #loader-bar {
    transition: none;
  }
}

/* A dark line's black (the Northern line's), outlined to show on the panel. */
.row .bar,
.card-top .sw,
.arrivals .bar,
.stops li::before {
  box-shadow: 0 0 0 1px var(--ring, transparent);
}
