/* ============================================================
   Components. Each block matches a builder in assets/js/ui/ and is
   documented in docs/FRONTEND.md. Class names are the component's name
   and its parts (.dep, .dep-when, .dep-main); states are is-* classes
   (.is-cancelled) and theme hooks are custom properties.
   ============================================================ */

/* ---------------- Route bullets ----------------
   The one shape allowed to be round. A circle for a name of one or two
   characters (T1, M1, L2, F1), a pill for longer (333, M30, BMT). An
   express service wears the MTA diamond (or a pointed pill). The colour is
   the line's own, from the API. */
.bullet {
  --b: 1.7em;
  --bullet-bg: var(--mode-other);
  --bullet-ink: #ffffff;
  position: relative;
  isolation: isolate;
  display: inline-grid;
  place-items: center;
  flex: none;
  min-width: var(--b);
  height: var(--b);
  padding: 0;
  border-radius: 999px;
  background: var(--bullet-bg);
  color: var(--bullet-ink);
  font-size: 0.86rem;
  font-weight: 800;
  font-style: normal;
  letter-spacing: -0.02em;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  vertical-align: middle;
  text-decoration: none;
}
.bullet.is-pill { padding: 0 0.48em; }
@supports (text-box: trim-both cap alphabetic) {
  .bullet { text-box: trim-both cap alphabetic; }
}
.bullet-sm { font-size: 0.72rem; }
.bullet-md { font-size: 0.86rem; }
.bullet-lg { font-size: 1.1rem; }
.bullet-xl { font-size: 1.5rem; }

/* Express: a diamond behind the name, upright type on it */
.bullet.is-express { background: none; }
.bullet.is-express::before {
  content: '';
  position: absolute;
  z-index: -1;
  inset: 8%;
  background: var(--bullet-bg);
  border-radius: 2px;
  transform: rotate(45deg);
}
.bullet.is-express.is-pill { padding: 0 0.7em; }
.bullet.is-express.is-pill::before {
  inset: 0;
  transform: none;
  border-radius: 0;
  clip-path: polygon(0.55em 0, calc(100% - 0.55em) 0, 100% 50%, calc(100% - 0.55em) 100%, 0.55em 100%, 0 50%);
}

/* Mode bullets: the TfNSW mode colour with its letter */
.bullet-mode { --b: 1.6em; }
.bullet.mode-train { --bullet-bg: var(--mode-train); }
.bullet.mode-metro { --bullet-bg: var(--mode-metro); }
.bullet.mode-lightrail { --bullet-bg: var(--mode-lightrail); }
.bullet.mode-bus { --bullet-bg: var(--mode-bus); }
.bullet.mode-ferry { --bullet-bg: var(--mode-ferry); }
.bullet.mode-coach { --bullet-bg: var(--mode-coach); }
.bullet.mode-schoolbus { --bullet-bg: var(--mode-schoolbus); --bullet-ink: #111111; }
.bullet.mode-walk, .bullet.mode-cycle, .bullet.mode-ondemand, .bullet.mode-other { --bullet-bg: var(--mode-other); }
/* a toggle made of a mode bullet (nearby filters): off is the outline */
button.bullet { border: 0; cursor: pointer; }
.bullet[aria-pressed="false"] {
  background: transparent;
  color: var(--muted);
  box-shadow: inset 0 0 0 2px var(--bullet-bg);
}
.bullet[aria-pressed="false"].is-express::before { opacity: 0.25; }

.bullets { display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.bullets-overlap .bullet + .bullet { margin-left: -0.28em; box-shadow: 0 0 0 2px var(--row-bg, var(--page-bg)); }

/* A row of line chips (the search tab's line picker): scrolls sideways. */
.hscroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  padding: 2px var(--gutter) 6px;
  margin-inline: calc(var(--gutter) * -1);
  scroll-padding-inline: var(--gutter);
}
.hscroll::-webkit-scrollbar { display: none; }
.hscroll > * { flex: none; }
a.bullet:focus-visible, button.bullet:focus-visible { outline-offset: 2px; }

/* ---------------- Lists ----------------
   A list is rows on hairlines. No cards: the rule is the structure. */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-bottom: 1px solid var(--border); }
.list-top { border-top: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.list.list-closed > li:last-child { border-bottom: 1px solid var(--border); }

/* The pressable row every list is made of */
.row {
  --row-bg: var(--page-bg);
  display: grid;
  align-items: center;
  column-gap: 12px;
  min-height: 56px;
  padding: var(--row-pad) 0;
  color: inherit;
  text-decoration: none;
  position: relative;
}
a.row, button.row { cursor: pointer; }
button.row { width: 100%; border: 0; background: none; text-align: left; font: inherit; }
a.row::after, button.row::after {
  /* the press lights the row edge to edge, past the gutter */
  content: '';
  position: absolute;
  inset: 0 calc(var(--gutter) * -1);
  z-index: -1;
  background: transparent;
  transition: background-color var(--duration-quick) var(--ease-smooth-out);
}
a.row, button.row { isolation: isolate; }
@media (hover: hover) and (pointer: fine) {
  a.row:hover::after, button.row:hover::after { background: var(--surface-2); }
}
a.row:active::after, button.row:active::after { background: var(--surface-2); }
a.row:focus-visible, button.row:focus-visible { outline-offset: -2px; }
.row-chev { width: 16px; height: 16px; color: var(--muted); }

/* ---------------- Stop row ---------------- */
.stop-row { grid-template-columns: minmax(0, 1fr) auto auto; }
.stop-row-main { display: grid; gap: 2px; min-width: 0; }
.stop-row-eyebrow { margin-bottom: 1px; }
.stop-row-name {
  font-weight: 750;
  font-size: var(--t-body);
  letter-spacing: -0.015em;
  line-height: 1.25;
}
.stop-row-sub { color: var(--muted); font-size: var(--t-small); line-height: 1.35; }
.stop-row-side { display: grid; justify-items: end; gap: 4px; }
.stop-row-code { color: var(--muted); font-family: var(--mono); font-size: var(--t-micro); letter-spacing: 0.02em; }
.stop-row-dist { color: var(--muted); font-size: var(--t-small); font-weight: 700; white-space: nowrap; }
.stop-row.is-child { padding-left: 28px; min-height: 48px; }
.stop-row.is-child::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 50%;
  width: 10px;
  border-left: 2px solid var(--border-strong);
  border-bottom: 2px solid var(--border-strong);
}

/* ---------------- Departure row ----------------
   A departure board line: the countdown on a black plate, the line's
   bullet and destination, the time and how it is running, the platform
   at the right edge. Realtime counts in white; timetable-only in grey. */
.dep { grid-template-columns: 56px minmax(0, 1fr) auto; column-gap: 12px; align-items: stretch; min-height: 72px; }
.dep-when {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 3px;
  min-height: 52px;
  border-radius: var(--radius);
  background: var(--sign-bg);
  color: var(--sign-ink);
  box-shadow: inset 0 0 0 1px var(--sign-edge);
  line-height: 1;
}
.dep-count { font-size: 1.22rem; font-weight: 850; letter-spacing: -0.04em; }
.dep-unit { font-size: var(--t-micro); font-weight: 700; color: var(--sign-muted); letter-spacing: 0.02em; }
.dep.is-sched .dep-count { color: var(--sign-muted); }
.dep.is-now .dep-count { color: var(--ok-sign); font-size: 1.06rem; }
.dep-main { display: grid; align-content: center; gap: 4px; min-width: 0; }
.dep-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.dep-dest {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--t-body);
  font-weight: 800;
  letter-spacing: -0.02em;
}
.dep-via { font-weight: 600; color: var(--muted); }
.dep-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 10px;
  row-gap: 2px;
  font-size: var(--t-small);
  color: var(--muted);
}
.dep-time { font-weight: 700; color: var(--text); }
.dep-time s { color: var(--muted); font-weight: 500; margin-right: 4px; }
.dep-nerd {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  font-size: var(--t-small);
  color: var(--muted);
}
.dep-plat { display: grid; justify-items: end; align-content: center; gap: 3px; min-width: 42px; text-align: right; }
.dep-plat-num { font-size: 1.22rem; font-weight: 850; letter-spacing: -0.03em; line-height: 1; }
.dep-plat-num.is-long { font-size: var(--t-body); }
.dep.is-cancelled .dep-dest { text-decoration: line-through; text-decoration-thickness: 2px; color: var(--muted); }
.dep.is-cancelled .dep-count { color: var(--sign-muted); }
.dep.is-departed { opacity: 0.55; }
.dep .alert-dot { width: 16px; height: 16px; color: var(--alert-ink); }

/* ---------------- Status words ----------------
   How a service is running, in words with a small square of the same
   ink before them (the word is the signal; the square is the glance). */
.st {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--t-small);
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}
.st::before {
  content: '';
  width: 0.62em;
  height: 0.62em;
  background: currentColor;
  flex: none;
}
.st-ok { color: var(--ok-ink); }
.st-late { color: var(--late-ink); }
.st-early { color: var(--early-ink); }
.st-cancelled { color: var(--late-ink); text-transform: uppercase; letter-spacing: 0.06em; font-size: var(--t-micro); font-weight: 800; }
.st-sched::before, .st-skip::before, .st-departed::before { display: none; }
.st-skip { font-style: italic; font-weight: 600; }
.sign .st-ok, .view-head .st-ok { color: var(--ok-sign); }
.sign .st-late, .view-head .st-late { color: var(--alert-sign); }

/* ---------------- Alert item ----------------
   One disruption: a mark in the severity ink, the title (red when it
   stops or delays you), when it runs, the lines it names; the detail
   opens in place. */
.alert { border-bottom: 1px solid var(--border); }
.alert:last-child { border-bottom: 0; }
.alert > details > summary,
.alert > .alert-sum {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  column-gap: 10px;
  padding: 12px 0;
  list-style: none;
  cursor: pointer;
}
.alert > details > summary::-webkit-details-marker { display: none; }
.alert-mark { width: 20px; height: 20px; margin-top: 1px; color: var(--muted); }
.alert-body-wrap { min-width: 0; }
.alert-title {
  margin: 0;
  font-size: var(--t-body);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.35;
}
.alert-when { margin: 3px 0 0; color: var(--muted); font-size: var(--t-small); }
.alert-lines { margin-top: 7px; }
.alert-chev { width: 16px; height: 16px; margin-top: 3px; color: var(--muted); transition: transform var(--duration-fast) var(--ease-smooth-out); }
.alert details[open] .alert-chev { transform: rotate(180deg); }
.alert-body {
  margin: -2px 0 14px 32px;
  color: var(--text);
  font-size: var(--t-small);
  line-height: 1.55;
  white-space: pre-line;
}
.alert-body a { font-weight: 700; }
.alert.sev-major .alert-title, .alert.sev-severe .alert-title { color: var(--alert-ink); }
.alert.sev-major .alert-mark, .alert.sev-severe .alert-mark { color: var(--alert-ink); }
.alert.sev-minor .alert-mark { color: var(--warn-ink); }
.alert.kind-trackwork .alert-mark, .alert.kind-planned .alert-mark { color: var(--warn-ink); }
.alert.sev-info .alert-mark { color: var(--info-ink); }
.alert-banner {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px var(--gutter);
  margin: 0 calc(var(--gutter) * -1) 14px;
  background: var(--notice-bg);
  border-top: 1px solid var(--notice-border);
  border-bottom: 1px solid var(--notice-border);
  color: var(--text);
  text-decoration: none;
}
.alert-banner svg { width: 20px; height: 20px; color: var(--alert-ink); }
.alert-banner strong { font-weight: 800; }

/* ---------------- Trip stop rows: the strip map ----------------
   A trip's stopping pattern as an MTA strip map: the line runs down the
   left in the line's colour, a station tick (paper disc, line-coloured
   ring) where it stops, nothing where it runs through, a solid disc where
   the vehicle is. Passed stops fade; the hairline starts after the rail so
   the rail runs unbroken. */
.tstops { list-style: none; margin: 0; padding: 0; }
.tstop-row {
  grid-template-columns: 24px minmax(0, 1fr) auto;
  column-gap: 12px;
  min-height: 60px;
  background: linear-gradient(var(--border), var(--border)) no-repeat 36px 100% / calc(100% - 36px) 1px;
}
.tstop.is-last .tstop-row { background: none; }
.tstop-rail { position: relative; align-self: stretch; margin: calc(var(--row-pad) * -1) 0; }
.tstop-rail::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 6px;
  margin-left: -3px;
  background: var(--line, var(--text));
}
.tstop.is-first .tstop-rail::before { top: 50%; }
.tstop.is-last .tstop-rail::before { bottom: 50%; }
.tstop-rail::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  background: var(--page-bg);
  border: 3px solid var(--line, var(--text));
}
.tstop.is-first .tstop-rail::after, .tstop.is-last .tstop-rail::after { width: 20px; height: 20px; margin: -10px 0 0 -10px; border-width: 4px; }
.tstop.is-skipped .tstop-rail::after { display: none; }
.tstop.is-passed .tstop-rail { opacity: 0.4; }
.tstop.is-current .tstop-rail { opacity: 1; }
.tstop.is-current .tstop-rail::after { background: var(--line, var(--text)); box-shadow: 0 0 0 3px var(--page-bg), 0 0 0 5px var(--line, var(--text)); }
.tstop-main { display: grid; gap: 2px; min-width: 0; }
.tstop-name { font-weight: 700; letter-spacing: -0.015em; line-height: 1.25; }
.tstop-sub { color: var(--muted); font-size: var(--t-small); }
.tstop.is-skipped .tstop-name, .tstop.is-passed .tstop-name { color: var(--muted); font-weight: 500; }
.tstop-side { display: grid; justify-items: end; gap: 4px; text-align: right; }
.tstop-time { display: flex; align-items: baseline; gap: 8px; font-weight: 750; }
.tstop-time s { font-weight: 500; font-size: var(--t-small); }
.tstop.is-skipped .tstop-time, .tstop.is-passed .tstop-time { color: var(--muted); font-weight: 500; }
.tstop-meta { display: flex; align-items: center; gap: 8px; }

/* ---------------- Occupancy ----------------
   Per car: one cell a car, front first, the front car cut to a nose. How
   full is drawn twice, as fill height and colour, so it reads without
   colour. Single meter: three rising bars. */
.cars { display: inline-flex; align-items: flex-end; gap: 2px; vertical-align: middle; }
.car {
  position: relative;
  width: var(--car-w, 10px);
  height: var(--car-h, 13px);
  background: var(--occ-none);
  overflow: hidden;
}
.car::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--fill, 0%);
  background: var(--occ, transparent);
}
.car.is-nose { clip-path: polygon(0 0, 55% 0, 100% 100%, 0 100%); width: calc(var(--car-w, 10px) * 1.35); }
.cars.is-reverse { flex-direction: row-reverse; }
.cars.is-reverse .car.is-nose { clip-path: polygon(45% 0, 100% 0, 100% 100%, 0 100%); }
.cars-md { --car-w: 14px; --car-h: 16px; gap: 3px; }
.occ-many, .occ-empty { --occ: var(--occ-many); --fill: 34%; }
.occ-few { --occ: var(--occ-few); --fill: 67%; }
.occ-standing { --occ: var(--occ-standing); --fill: 100%; }
.occ-crushed, .occ-full, .occ-not_accepting { --occ: var(--occ-full); --fill: 100%; }
.car.is-quiet { box-shadow: inset 0 2px 0 var(--info-ink); }

.occ { display: inline-flex; align-items: flex-end; gap: 2px; height: 13px; vertical-align: middle; }
.occ > i { width: 4px; background: var(--occ-none); }
.occ > i:nth-child(1) { height: 5px; }
.occ > i:nth-child(2) { height: 9px; }
.occ > i:nth-child(3) { height: 13px; }
.occ.occ-many > i:nth-child(1), .occ.occ-empty > i:nth-child(1) { background: var(--occ-many); }
.occ.occ-few > i:nth-child(-n+2) { background: var(--occ-few); }
.occ.occ-standing > i, .occ.occ-crushed > i, .occ.occ-full > i, .occ.occ-not_accepting > i { background: var(--occ-standing); }
.occ.occ-crushed > i, .occ.occ-full > i, .occ.occ-not_accepting > i { background: var(--occ-full); }
.occ-label { font-size: var(--t-small); color: var(--muted); }

/* ---------------- Pin (star) ---------------- */
.pin-btn { position: relative; }
.pin-btn svg {
  grid-area: 1 / 1;
  transition:
    opacity var(--icon-swap-dur) var(--icon-swap-ease),
    transform var(--icon-swap-dur) var(--ease-bounce),
    visibility var(--icon-swap-dur) var(--icon-swap-ease);
}
.pin-btn .icon-fill,
.pin-btn[aria-pressed="true"] .icon-line { opacity: 0; visibility: hidden; transform: scale(0.5); }
.pin-btn .icon-line,
.pin-btn[aria-pressed="true"] .icon-fill { opacity: 1; visibility: visible; transform: none; }
.view-head .pin-btn[aria-pressed="true"],
.sign .pin-btn[aria-pressed="true"] { color: var(--line-yellow); }

/* ---------------- Updated ticker ---------------- */
.ticker {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: var(--t-small);
  font-weight: 600;
}
.ticker::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok-ink);
}
.ticker.is-live::before { animation: t-pulse 2s var(--ease-in-out) infinite; }
.ticker.is-stale::before { background: var(--warn-ink); animation: none; }
.ticker.is-error::before { background: var(--late-ink); animation: none; }

/* ---------------- Notices and states ---------------- */
.notice {
  margin: 0 0 16px;
  padding: 14px 16px;
  border: 1px solid var(--notice-border);
  border-radius: var(--radius);
  background: var(--notice-bg);
  font-size: var(--t-small);
  line-height: 1.55;
}
.notice-title { margin: 0 0 4px; font-size: var(--t-body); font-weight: 800; letter-spacing: -0.015em; }
.notice .btn { margin-top: 10px; }
.notice.is-error { border-color: var(--danger-border); background: var(--danger-bg); }
.notice.is-info { border-color: var(--border); background: var(--surface); }

.empty {
  display: grid;
  justify-items: start;
  gap: 8px;
  padding: 28px 0 20px;
  color: var(--muted);
}
.empty > svg { width: 28px; height: 28px; color: var(--border-strong); }
.empty-title { margin: 0; color: var(--text); font-size: var(--t-lede); font-weight: 800; letter-spacing: -0.02em; }
.empty p { margin: 0; max-width: 30em; font-size: var(--t-small); line-height: 1.55; }
.empty .btn { margin-top: 6px; }

/* Skeleton rows: grey bars breathing while the first answer is on its way */
.skel { list-style: none; margin: 0; padding: 0; }
.skel-row { display: grid; grid-template-columns: 52px 1fr 36px; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.skel-row.is-simple { grid-template-columns: 1fr 60px; }
.skel-bar {
  display: block;
  height: 12px;
  border-radius: var(--radius);
  background: var(--border);
  animation: t-pulse var(--pulse-dur) var(--ease-in-out) infinite;
}
.skel-block { height: 48px; }
.skel-lines { display: grid; gap: 8px; }

/* ---------------- Rocker (the O/I switch) ----------------
   A paper box with a solid block over one half: grey over O when off,
   accent green over I when on. Measured in em so the text-size ladder
   scales the whole switch. */
.rocker { position: relative; display: inline-flex; align-items: center; min-height: 44px; cursor: pointer; flex: none; }
.rocker input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.rocker-switch {
  position: relative;
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  font-size: var(--t-micro);
  font-weight: 800;
  line-height: 1;
  user-select: none;
  transition: transform var(--duration-quick) var(--ease-smooth-out);
}
.rocker-switch::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 50%;
  background: var(--border-strong);
  transition:
    transform var(--duration-fast) var(--ease-bounce),
    background-color var(--duration-fast) var(--ease-smooth-out);
}
.rocker input:checked + .rocker-switch::before { transform: translateX(100%); background: var(--accent-solid); }
.rocker-switch span {
  position: relative;
  min-width: 2.6em;
  padding: 0.6em 0;
  text-align: center;
  color: var(--muted);
  transition: color var(--duration-micro) var(--ease-in-out);
}
.rocker input:not(:checked) + .rocker-switch .rocker-o,
.rocker input:checked + .rocker-switch .rocker-i { transition: color var(--duration-micro) var(--ease-in-out) 140ms; }
.rocker input:not(:checked) + .rocker-switch .rocker-o { color: var(--text); }
.rocker input:checked + .rocker-switch .rocker-i { color: var(--on-accent); }
.rocker:active .rocker-switch { transform: scale(0.94); }
.rocker input:focus-visible + .rocker-switch { outline: 2px solid var(--accent); outline-offset: 2px; }
.rocker input:disabled + .rocker-switch { opacity: 0.4; }

/* ---------------- Segmented control ----------------
   A choice of two to four, the picked one filled with the sign's black. */
.seg {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.seg button {
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: var(--t-micro);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  transition: background-color var(--duration-quick) var(--ease-smooth-out), color var(--duration-quick) var(--ease-smooth-out);
}
.seg button + button { border-left: 1px solid var(--border-strong); }
/* the picked one is inverted (the page's ink as its ground), which reads in
   both themes; sign-black would vanish on the dark theme's near-black */
.seg button[aria-checked="true"] { background: var(--text); color: var(--page-bg); }
@media (hover: hover) and (pointer: fine) {
  .seg button:hover:not([aria-checked="true"]) { background: var(--page-bg); }
}
.seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
.seg-block { display: grid; width: 100%; }

/* ---------------- Text size stepper ---------------- */
.stepper {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  width: calc(5.2em + 2px);
  height: 40px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: var(--t-micro);
}
.stepper button {
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-weight: 800;
  line-height: 1;
  transition: background-color var(--duration-quick) var(--ease-smooth-out);
}
.stepper button + button { border-left: 1px solid var(--border-strong); }
@media (hover: hover) and (pointer: fine) {
  .stepper button:hover:not(:disabled) { background: var(--page-bg); }
}
.stepper button:active:not(:disabled) { background: var(--border-strong); }
.stepper button:disabled { color: var(--border-strong); cursor: default; }
.stepper button:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }

/* ---------------- Settings rows (menu and page) ----------------
   A name over one muted line saying what it does, the control beside both,
   rows on hairlines, groups set apart by a label in the label voice. */
.set-group + .set-group { margin-top: 18px; }
.set-group-title { margin: 0 0 2px; }
.set-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 14px;
  align-items: center;
  min-height: 56px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.set-row:last-child { border-bottom: 0; }
.set-name { grid-column: 1; grid-row: 1; font-weight: 700; line-height: 1.35; }
.set-desc { grid-column: 1; grid-row: 2; margin: 2px 0 0; color: var(--muted); font-size: 0.8rem; line-height: 1.45; }
.set-desc:empty { display: none; }
.set-control { grid-column: 2; grid-row: 1 / span 2; display: flex; align-items: center; justify-content: flex-end; }
.set-row.no-desc .set-control { grid-row: 1; }
.set-row.is-stacked { grid-template-columns: 1fr; }
.set-row.is-stacked .set-control { grid-column: 1; grid-row: 3; justify-content: flex-start; margin-top: 10px; }
.set-link {
  display: grid;
  place-items: center;
  width: calc(5.2em + 2px);
  height: 40px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: var(--t-micro);
  color: var(--text);
}
.set-link svg { width: 15px; height: 15px; }
a.set-row { color: inherit; text-decoration: none; }

/* The settings menu: a dropdown from the gear */
.menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 8px;
  z-index: var(--z-menu);
  width: 340px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - var(--nav-h) - 24px);
  max-height: calc(100dvh - var(--nav-h) - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 14px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.92rem;
  transform-origin: top right;
}
html.is-app .menu-panel {
  right: 8px;
  max-height: calc(100dvh - var(--nav-h) - var(--tabbar-full) - 20px);
}
.menu-panel:not([hidden]):not(.is-closing) { animation: menu-open var(--dropdown-open-dur) var(--ease-smooth-out); }
@keyframes menu-open {
  from { opacity: 0; transform: translateY(-4px) scale(var(--dropdown-pre-scale)); }
  to { opacity: 1; transform: none; }
}
.menu-panel.is-closing {
  opacity: 0;
  transform: translateY(-4px) scale(var(--dropdown-closing-scale));
  pointer-events: none;
  transition:
    opacity var(--dropdown-close-dur) var(--ease-smooth-out),
    transform var(--dropdown-close-dur) var(--ease-smooth-out);
}

/* ---------------- Toasts ----------------
   They drop in under the top bar: the bottom of the screen belongs to the
   sheet and the tab bar. */
.toast-stack {
  position: fixed;
  left: 50%;
  top: calc(var(--nav-h) + 10px);
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: grid;
  gap: 8px;
  justify-items: center;
  width: max-content;
  max-width: calc(100vw - 24px);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: rgba(12, 15, 20, 0.95);
  color: #ffffff;
  box-shadow: 2px 2px 0 rgba(12, 15, 20, 0.25);
  font-size: 0.9rem;
  font-weight: 650;
  line-height: 1.4;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(calc(-1 * var(--toast-distance))) scale(var(--toast-scale));
  filter: blur(var(--toast-blur));
  transition:
    opacity var(--toast-close) var(--ease-smooth-out),
    transform var(--toast-close) var(--ease-smooth-out),
    filter var(--toast-close) var(--ease-smooth-out);
}
.toast.is-open {
  opacity: 1;
  transform: none;
  filter: blur(0);
  transition:
    opacity var(--toast-open) var(--ease-smooth-out),
    transform var(--toast-open) var(--ease-smooth-out),
    filter var(--toast-open) var(--ease-smooth-out);
}
.toast button {
  padding: 4px 0;
  border: 0;
  background: none;
  color: #7fdca2;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: var(--t-micro);
}
.toast.is-error { background: var(--danger-solid); }
.toast.is-error button { color: #ffffff; }
:root[data-theme="dark"] .toast:not(.is-error) { background: rgba(233, 237, 240, 0.97); color: #10151a; box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.45); }
:root[data-theme="dark"] .toast:not(.is-error) button { color: #00752f; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .toast:not(.is-error) { background: rgba(233, 237, 240, 0.97); color: #10151a; box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.45); }
  :root:not([data-theme="light"]) .toast:not(.is-error) button { color: #00752f; }
}

/* ---------------- Dialog ----------------
   The question on the sign bar, the consequence on the paper, the actions
   under it. Native <dialog> (focus trap, Escape) with a back layer. */
.dialog {
  width: min(460px, calc(100vw - 24px));
  max-height: calc(100dvh - 48px);
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-hover);
  overflow: auto;
}
.dialog::backdrop { background: rgba(12, 15, 20, 0.45); }
.dialog[open] { animation: dialog-in var(--duration-fast) var(--ease-smooth-out); }
@keyframes dialog-in {
  from { opacity: 0; transform: translateY(var(--distance-base)) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 14px 8px 14px 18px;
  background: var(--sign-bg);
  color: var(--sign-ink);
}
.dialog-title { margin: 0; font-size: var(--t-lede); font-weight: 800; letter-spacing: -0.02em; }
.dialog-head .icon-btn { color: var(--sign-ink); }
.dialog-body { padding: 16px 18px 4px; font-size: var(--t-small); line-height: 1.55; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding: 14px 18px 18px; }

/* ---------------- Map controls ----------------
   Square buttons on the map's top right, the SCS map-button: paper, a
   strong line, the hard shadow (they float over a picture). */
.map-ctrls {
  position: absolute;
  top: 12px;
  right: calc(12px + env(safe-area-inset-right, 0px));
  z-index: var(--z-map-ctrl);
  display: grid;
  gap: 8px;
  justify-items: end;
}
.map-ctrl-group { display: grid; box-shadow: var(--shadow); }
.map-ctrl-group .map-btn { box-shadow: none; }
.map-ctrl-group .map-btn + .map-btn { border-top-width: 0; }
.map-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 0.8rem;
  font-weight: 850;
  letter-spacing: 0.02em;
  transition: background-color var(--duration-quick) var(--ease-smooth-out), color var(--duration-quick) var(--ease-smooth-out);
}
.map-btn svg { width: 20px; height: 20px; }
.map-btn:active { transform: translate(1px, 1px); box-shadow: none; }
.map-btn[aria-pressed="true"], .map-btn[aria-expanded="true"] { background: var(--sign-bg); border-color: var(--sign-bg); color: var(--sign-ink); }
.map-btn.is-busy svg { animation: t-pulse 900ms var(--ease-in-out) infinite; }
.map-btn[hidden] { display: none; }
html.is-app .map-zoom { display: none; }

.map-layers {
  position: absolute;
  top: 0;
  right: calc(100% + 8px);
  width: 260px;
  max-width: calc(100vw - 88px);
  max-height: min(460px, calc(100dvh - var(--nav-h) - var(--tabbar-full, 0px) - 40px));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 14px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  transform-origin: top right;
  animation: menu-open var(--dropdown-open-dur) var(--ease-smooth-out);
}
.map-layers .set-row { min-height: 48px; padding: 4px 0; }
.map-layers .set-name { display: flex; align-items: center; gap: 8px; font-size: var(--t-small); }

.map-note {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: var(--t-small);
  background: var(--map-bg);
}
.map-note svg { width: 32px; height: 32px; color: var(--border-strong); }
.map-note strong { color: var(--text); font-size: var(--t-body); }

/* The approximate-location chip: says the blue dot is a guess */
.map-chip {
  position: absolute;
  left: calc(12px + env(safe-area-inset-left, 0px));
  bottom: calc(var(--map-bottom, 0px) + 12px);
  z-index: var(--z-map-ctrl);
  padding: 6px 10px;
  border-radius: var(--radius);
  background: var(--sign-bg);
  color: var(--sign-ink);
  font-size: var(--t-micro);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  box-shadow: var(--shadow);
}

/* MapLibre's own chrome, redrawn in the system's terms */
.maplibregl-map { font-family: var(--font); }
.maplibregl-ctrl-bottom-right,
.maplibregl-ctrl-bottom-left { bottom: var(--map-bottom, 0px); transition: bottom 120ms linear; }
.maplibregl-ctrl.maplibregl-ctrl-attrib {
  margin: 0 !important;
  padding: 2px 6px;
  border-radius: 0;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--muted);
  font-size: 0.66rem;
}
.maplibregl-ctrl-attrib a { color: var(--text); }
.maplibregl-ctrl-attrib.maplibregl-compact { min-height: 22px; }
.maplibregl-ctrl-attrib-button { background-color: transparent; }
:root[data-theme="dark"] .maplibregl-ctrl-attrib-button { filter: invert(1); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .maplibregl-ctrl-attrib-button { filter: invert(1); } }
.maplibregl-canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------------- Misc ---------------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: var(--t-small); }
.kv dt { color: var(--muted); font-weight: 700; }
.kv dd { margin: 0; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); margin: 0 0 18px; }
.fact { padding: 12px 14px 12px 0; }
.fact + .fact { padding-left: 14px; border-left: 1px solid var(--border); }
.fact-value { margin-top: 4px; font-size: var(--t-lede); font-weight: 850; letter-spacing: -0.03em; font-variant-numeric: tabular-nums lining-nums; }

.install-steps { margin: 8px 0 0; padding-left: 1.2em; font-size: var(--t-small); line-height: 1.6; }
.divider { height: 1px; margin: 18px 0; border: 0; background: var(--border); }

/* ---------------- View scaffolding ---------------- */
.stub-item { padding: 10px 0; font-size: var(--t-small); line-height: 1.45; }
.settings-page { max-width: 640px; }
.settings-page .set-group + .set-group { margin-top: 26px; }
.settings-mode:empty { display: none; }
.settings-mode .notice { margin: 8px 0 0; }
