/* The metro map menu: a menu drawn as a metro line, on a white page. The map is an SVG the script draws the line on;
   the stops are links laid over it, sized with the map through container units. Next to it, a station board names the
   stop the car is at, or the next one while it travels. */
:root {
  --page: #ffffff;          /* the page, and the casing round the line */
  --ink: #131a24;           /* the words */
  --soft: #5d6876;          /* the quieter words */
  --main: #2b55e6;          /* the Canal line */
  --branch: #f29d12;        /* the Venues branch */
  --board: #121923;         /* the station board */
  --led: #ffb53d;           /* the board's dot letters */
  --board-text: #b7c1ce;
  --tint: 30%;              /* how much colour the line keeps where the car has not taken it */
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Overpass Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(16px, 3vh, 28px) clamp(16px, 4vw, 48px);
}

/* ---------------------------------------------------------------- the layout: map and board */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 400px) minmax(0, 440px);
  justify-content: center;
  align-items: center;
  gap: clamp(32px, 7vw, 96px);
  width: 100%;
  max-width: 1120px;
}

/* ---------------------------------------------------------------- the map */
.map {
  position: relative;
  /* as wide as the column, but never taller than the window can show (the drawing is 360 by 540) */
  width: min(100%, (100svh - 64px) * 0.667);
  justify-self: center;
  container-type: inline-size;
}

.map__art {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

/* the line: a casing the colour of the page, then the tint of the stretch the car has not taken, then the paint
   behind it */
.track__casing {
  fill: none;
  stroke: var(--page);
  stroke-linecap: round;
  stroke-linejoin: round;
}

.track__ghost,
.track__paint {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.track__ghost--main {
  stroke: color-mix(in srgb, var(--main) var(--tint), var(--page));
}

.track__ghost--branch {
  stroke: color-mix(in srgb, var(--branch) var(--tint), var(--page));
}

.track__paint--main {
  stroke: var(--main);
}

.track__paint--branch {
  stroke: var(--branch);
}

/* the way the car is about to take: a thin dashed line that marches towards the stop */
.route {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.6;
  stroke-linecap: butt;
  stroke-linejoin: round;
  stroke-dasharray: 5 4;
  opacity: 0.5;
}

.route.is-on {
  animation: march 0.6s linear infinite;
}

@keyframes march {
  to {
    stroke-dashoffset: -9;
  }
}

.mark {
  fill: #fff;
  stroke-width: 3;
}

.mark--main {
  stroke: var(--main);
}

.mark--branch {
  stroke: var(--branch);
}

/* the interchange: a bigger ring in ink */
.mark--change {
  stroke: var(--ink);
  stroke-width: 3.2;
}

/* the car */
.car__shadow {
  fill: rgba(19, 26, 36, 0.11);
}

.car__body {
  fill: #fff;
  stroke: var(--ink);
  stroke-width: 1.6;
}

.car__roof {
  fill: #e3e8ef;
}

.car__stripe {
  fill: var(--main);
  transition: fill 0.4s ease;
}

.car.on-branch .car__stripe {
  fill: var(--branch);
}

/* the stops: links over the map, placed by the script with --x and --y in map units (the map is 360 wide) */
.map__stops,
.map__branch {
  margin: 0;
  padding: 0;
  list-style: none;
}

.map__stops {
  --u: calc(100cqi / 360);
}

.stop {
  position: absolute;
  top: calc(var(--y, 0) * var(--u));
  left: calc((var(--x, 0) - 13) * var(--u));
  display: flex;
  align-items: center;
  min-height: calc(30 * var(--u));
  padding: 0 calc(6 * var(--u)) 0 calc(26 * var(--u));
  border-radius: 999px;
  color: var(--soft);
  font-size: calc(15 * var(--u));
  font-weight: 640;
  line-height: 1;
  white-space: nowrap;
  transform: translateY(-50%);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: color 0.25s ease;
}

/* a stop whose name is on the left: the box grows from the stop towards the left */
.stop.is-left {
  left: auto;
  right: calc((360 - var(--x, 0) - 13) * var(--u));
  padding: 0 calc(26 * var(--u)) 0 calc(6 * var(--u));
}

.stop[aria-current='page'] {
  color: var(--ink);
  font-weight: 820;
}

.stop.is-going {
  color: var(--ink);
}

@media (hover: hover) and (pointer: fine) {
  .stop:hover {
    color: var(--ink);
  }
}

.stop:active {
  color: var(--main);
}

.stop:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------- the board */
.board {
  position: relative;
  padding: 20px 26px 24px;
  border-radius: 18px;
  background: var(--board);
  color: var(--board-text);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 24px 48px -24px rgba(19, 26, 36, 0.55), 0 2px 6px rgba(19, 26, 36, 0.18);
}

.board__status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 14px;
  font-size: 14px;
  font-weight: 600;
}

/* the state is a word, and its colour: green at a stop, amber on the way */
.board__state {
  color: #7fdca6;
  transition: color 0.3s ease;
}

.board__state.is-moving {
  color: var(--led);
}

.board__line {
  padding: 4px 10px 3px;
  border-radius: 999px;
  background: var(--main);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  transition: background-color 0.4s ease;
}

.board__line.on-branch {
  background: var(--branch);
  color: var(--board);
}

.board__title {
  margin: 0;
  color: var(--led);
  font-family: 'Doto Variable', ui-monospace, monospace;
  font-size: clamp(34px, 4.2vw, 46px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.01em;
  text-shadow: 0 0 14px color-mix(in srgb, var(--led) 45%, transparent);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- phone: the board goes first */
@media (max-width: 760px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
  }

  .board {
    order: -1;
    padding: 16px 18px 18px;
  }

  .board__title {
    font-size: 32px;
  }

  .map {
    width: min(100%, 420px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .route {
    animation: none;
  }
}

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

/* ---------------------------------------------------------------- the car */
.car__glass {
  fill: #2a3646;
}

.car__lamp--a {
  fill: #fff4cf;
}

.car__lamp--b {
  fill: #ff5a3c;
}

/* going backwards along its line, the car swaps its lamps: white ahead, red behind */
.car:not(.is-forward) .car__lamp--a {
  fill: #ff5a3c;
}

.car:not(.is-forward) .car__lamp--b {
  fill: #fff4cf;
}
