/*
 * Design tokens. Change colours here; line colours live in js/network-data.js.
 * Keep --bg and --ink as 6-digit hex: the map script reads them to pick
 * outline colours for lines that would otherwise be hard to see.
 */
:root {
  --bg: #f6f6f2;
  --ink: #14181d;
  --muted: #4e5663;
  --card: #ffffff;
  --card-border: #dcdfd8;
  --grid-dot: rgba(20, 24, 29, 0.16);
  --vertex: #ffffff;
  --focus: #0033a0;
  --shadow: 0 1px 2px rgba(20, 24, 29, 0.06), 0 6px 20px rgba(20, 24, 29, 0.08);
  --font: "Overpass", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e141f;
    --ink: #eef1f5;
    --muted: #a6b0c1;
    --card: #161e2c;
    --card-border: #2b3548;
    --grid-dot: rgba(238, 241, 245, 0.11);
    --vertex: #0e141f;
    --focus: #8db2ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

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

/* `hidden` must win over any display rule below. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--font);
}

button,
input {
  font: inherit;
  color: inherit;
}

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

/* ── The map fills the window ───────────────────────────────────────────── */

.map {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  background-color: var(--bg);
  background-image: radial-gradient(circle at 0 0, var(--grid-dot) 1.3px, transparent 1.8px);
}

.map:focus-visible {
  outline-offset: -3px;
}

.map.is-dragging {
  cursor: grabbing;
}

.map__svg {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.line__casing,
.line__stroke {
  fill: none;
  stroke-linecap: round;
}

.line__stroke {
  stroke-width: var(--line-width, 4px);
}

.line__casing {
  stroke-width: calc(var(--line-width, 4px) + 4px);
}

.line--bus .line__stroke {
  stroke-width: var(--bus-width, 2px);
}

.line--bus .line__casing {
  stroke-width: calc(var(--bus-width, 2px) + 3px);
}

/* SeaBus crosses the water: dashed. */
.line--ferry .line__stroke {
  stroke-linecap: butt;
  stroke-dasharray: 10px 6px;
}

/* Switched off in the legend. */
.line.is-off {
  display: none;
}

/* Stations and stops: hidden until you zoom in (the script removes .is-hidden). */
.stop {
  cursor: pointer;
}

.stop__hit {
  fill: transparent;
}

.stop__dot {
  fill: var(--vertex);
  stroke: var(--ink);
  stroke-width: 2.25px;
  transition: opacity 0.2s;
}

.stop--interchange .stop__dot {
  stroke-width: 3.5px;
}

.stop--bus .stop__dot {
  stroke-width: 1.75px;
}

.stop--bus.stop--interchange .stop__dot {
  stroke-width: 2.5px;
}

.stop:hover .stop__dot {
  stroke-width: 4px;
}

.stop.is-selected .stop__dot {
  fill: var(--ink);
  stroke: var(--vertex);
  stroke-width: 3px;
}

.stop.is-hidden:not(.is-selected) {
  pointer-events: none;
}

.stop.is-hidden:not(.is-selected) .stop__dot {
  opacity: 0;
}

.stop__label {
  font: 600 13px var(--font);
  fill: var(--ink);
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 4px;
  stroke-linejoin: round;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s;
}

.stop--major .stop__label {
  font-weight: 800;
}

.stop--bus .stop__label {
  font-size: 12px;
  font-weight: 600;
}

.stop--bus.stop--major .stop__label {
  font-weight: 800;
}

.stop__label.is-shown {
  opacity: 1;
  pointer-events: auto;
}

/* ── Cards floating over the map ────────────────────────────────────────── */

/* Two independent columns (so a tall legend never squeezes the station
   panel) above a full-width credit line. */
.ui {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    "left   right"
    "credit credit";
  gap: 12px;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  pointer-events: none;
}

.ui__col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  min-height: 0;
}

.ui__col--left {
  grid-area: left;
  align-items: flex-start;
}

.ui__col--right {
  grid-area: right;
}

.masthead,
.search,
.panel,
.legend,
.controls,
.credit {
  pointer-events: auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.masthead {
  max-width: 420px;
  padding: 14px 18px 12px;
}

.masthead__site {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.masthead__site svg {
  flex: none;
}

.masthead__title {
  margin: 4px 0 2px;
  font-size: clamp(20px, 2.4vw, 26px);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.masthead__hint {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.search {
  padding: 12px 14px;
}

.search__label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
}

.search__row {
  display: flex;
  gap: 8px;
}

.search__input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 12px;
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
}

.search__go {
  min-width: 56px;
  min-height: 44px;
  padding: 0 14px;
  background: var(--ink);
  color: var(--card);
  border: 0;
  border-radius: 8px;
  font-weight: 800;
  cursor: pointer;
}

.search__status {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.search__status:empty {
  display: none;
}

/* Station panel: right-hand card on wide screens, bottom sheet on phones. */
.panel {
  flex: 0 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 16px 18px 18px;
}

.panel__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.panel__eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.panel__name {
  margin: 2px 0 0;
  font-size: 26px;
  font-weight: 800;
  line-height: 1.15;
}

.panel__name:focus {
  outline: none;
}

.panel__close {
  display: grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: -6px -8px 0 0;
  background: none;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.panel__close:hover {
  background: var(--bg);
}

.panel__lines {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

.panel__line-name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
  font-weight: 800;
}

.panel__next {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.panel__next-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}

.panel__next-link::before {
  content: "→";
  margin-right: 6px;
  color: var(--muted);
}

.panel__next-link:hover {
  border-color: var(--ink);
}

.tag {
  padding: 1px 8px;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.swatch {
  flex: none;
  display: inline-block;
  width: 26px;
  height: 7px;
  border-radius: 4px;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1px rgba(20, 24, 29, 0.18);
}

.swatch--bus {
  height: 4px;
}

.swatch--ferry {
  border-radius: 0;
  background: repeating-linear-gradient(90deg, var(--swatch) 0 7px, transparent 7px 10px);
  box-shadow: none;
}

.legend {
  margin-top: auto;
  max-width: 420px;
  padding: 12px 16px;
}

.legend__title {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.legend__hint {
  margin: -4px 0 6px;
  color: var(--muted);
  font-size: 12px;
}

.legend__list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px 18px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Each row is a switch that hides or shows its line. */
.legend__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: calc(100% + 12px);
  min-height: 30px;
  margin: 0 -6px;
  padding: 2px 6px;
  background: none;
  border: 0;
  border-radius: 6px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.legend__item:hover {
  background: var(--bg);
}

.legend__item[aria-pressed="false"] {
  color: var(--muted);
  text-decoration: line-through;
}

.legend__item[aria-pressed="false"] .swatch {
  opacity: 0.3;
}

/* TransLink's required data notice, always on screen. */
.credit {
  grid-area: credit;
  justify-self: center;
  max-width: 980px;
  margin: 0;
  padding: 6px 14px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
}

.controls {
  margin-top: auto;
  align-self: flex-end;
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.scale {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.scale__bar {
  height: 6px;
  border: 2px solid var(--muted);
  border-top: 0;
}

.controls__buttons {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.controls__buttons button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  background: none;
  border: 0;
  cursor: pointer;
}

.controls__buttons button + button {
  border-top: 1px solid var(--card-border);
}

.controls__buttons button:hover {
  background: var(--bg);
}

.controls__buttons button:focus-visible {
  outline-offset: -3px;
}

/* ── 404 page ───────────────────────────────────────────────────────────── */

.not-found {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 16px;
  overflow: auto;
  background-image: radial-gradient(circle at 0 0, var(--grid-dot) 1.3px, transparent 1.8px);
  background-size: 40px 40px;
}

.not-found__card {
  max-width: 420px;
  padding: 22px 24px 24px;
}

.not-found__text {
  margin: 6px 0 18px;
  color: var(--muted);
}

.not-found__link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 18px;
  background: var(--ink);
  color: var(--card);
  border-radius: 8px;
  font-weight: 800;
  text-decoration: none;
}

.noscript {
  position: fixed;
  inset: auto 16px 16px;
  margin: 0;
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 10px;
}

/* ── Phones ─────────────────────────────────────────────────────────────── */

@media (max-width: 720px) {
  .ui {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "head   head"
      "search search"
      ".      controls"
      "legend legend"
      "credit credit";
    gap: 8px;
  }

  /* Let the cards join the grid directly. */
  .ui__col {
    display: contents;
  }

  .masthead {
    grid-area: head;
    max-width: none;
    padding: 10px 14px;
  }

  .search {
    grid-area: search;
  }

  .legend {
    grid-area: legend;
    max-width: none;
    margin-top: 0;
  }

  .controls {
    grid-area: controls;
    align-self: end;
    justify-self: end;
    margin-top: 0;
  }

  .masthead__hint {
    font-size: 14px;
  }

  .search {
    padding: 10px 12px;
  }

  .search__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .legend {
    padding: 10px 12px;
  }

  .legend__list {
    column-gap: 14px;
  }

  .legend__item {
    font-size: 14px;
  }

  .credit {
    justify-self: stretch;
    padding: 6px 10px;
    font-size: 11px;
  }

  .panel {
    position: fixed;
    inset: auto 0 0 0;
    max-height: 55%;
    padding-bottom: max(18px, env(safe-area-inset-bottom));
    border-radius: 14px 14px 0 0;
  }

  .has-panel .legend,
  .has-panel .controls {
    visibility: hidden;
  }
}

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