/* The home page (maps/show): header with the menu, the map, its markers and the card a tapped
   bus or stop opens. Made for children and older people: large type, large tap targets, words next to colours. */
:root {
  --color-ok: #18794e;
  --color-warn: #f5c400;
  --color-bad: #c4291c;
  --color-ink: #16202e;
  --color-button: #0a58ca;
}

.home {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;

  [data-controller="map"] { position: relative; flex: 1; min-height: 0; }
  .map { height: 100%; }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem 0.5rem 1.25rem;
  border-bottom: 1px solid var(--color-border);

  /* One line beside the Menu button, down to a 320px phone. */
  h1 { display: flex; align-items: center; gap: 0.4rem; margin: 0; font-size: clamp(0.875rem, 4.2vw, 1.3125rem); font-weight: 600; line-height: 1.2; white-space: nowrap; }
  h1 img { width: 1.6em; height: 1.6em; }
  /* The narrowest phones have room for the name or the logo, not both. */
  @media (max-width: 355px) { h1 img { display: none; } }
}

/* The back button names where it leads: "Mapa". */
.back {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  min-width: 0;
  min-height: 2.75rem;
  margin-left: -0.5rem;
  padding: 0 1rem 0 0.5rem;
  border-radius: 1.5rem;
  background: var(--color-button);
  color: #ffffff;
  font-weight: 600;
  text-decoration: none;

  svg { flex: none; }
  span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* The menu button says "Menu"; open, the menu covers the page and the same button says "Zamknij". */
.menu {
  summary {
    list-style: none;
    padding: 0 1rem 0 0.75rem;
    border: 2px solid var(--color-text);
    border-radius: 1.5rem;
    background: var(--color-bg);
    font-weight: 600;
    cursor: pointer;
  }
  summary::-webkit-details-marker { display: none; }
  .menu-open, .menu-close { display: flex; align-items: center; gap: 0.5rem; min-height: 2.75rem; }
  .menu-close { display: none; }

  nav {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.5rem 1rem 1.5rem;
    overflow: auto;
    background: var(--color-bg);
  }
  h2 { margin: 0 0 0 0.25rem; font-size: 1.5rem; line-height: 3rem; }
}
.menu[open] {
  summary { position: fixed; top: 0.5rem; right: 0.75rem; z-index: 2001; }
  .menu-open { display: none; }
  .menu-close { display: flex; }
}

.menu-row {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  min-height: 5.5rem;
  padding: 0.625rem 0.875rem;
  border: 2px solid var(--color-border);
  border-radius: 1rem;
  color: var(--color-text);
  text-decoration: none;

  svg { flex: none; box-sizing: content-box; padding: 0.75rem; border-radius: 50%; background: var(--color-border); }
  span { color: var(--color-muted); font-size: 0.9375rem; }
  strong { display: block; color: var(--color-text); font-size: 1.25rem; font-weight: 600; }
}
.menu-row[aria-current] {
  border-color: var(--color-button);
  svg { background: var(--color-button); color: #ffffff; }
}

/* Markers (map_controller.js). Leaflet places the zero-sized .map-marker; its child is centred on that point. */
.map-marker > * { position: absolute; transform: translate(-50%, -50%); white-space: nowrap; }

.bus-pill {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  height: 2.75rem;
  padding: 0 0.875rem 0 0.625rem;
  border: 3px solid #ffffff;
  border-radius: 1.375rem;
  background: #5c6470;
  color: #ffffff;
  box-shadow: 0 3px 8px rgb(22 32 46 / 0.4);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
}
.bus-on_time { background: var(--color-ok); }
.bus-late { background: var(--color-warn); color: var(--color-ink); }
.bus-very_late { background: var(--color-bad); }
/* The bus whose card is open: larger, ringed, with the halo the selected stop has. */
.bus-selected { scale: 1.15; box-shadow: 0 0 0 4px var(--color-ink), 0 0 0 14px rgb(10 88 202 / 0.25), 0 4px 10px rgb(22 32 46 / 0.4); }
.bus-badge {
  position: absolute;
  top: -1rem;
  right: -1rem;
  padding: 0.125rem 0.4375rem;
  border-radius: 0.6875rem;
  background: var(--color-ink);
  color: #ffffff;
  font-size: 0.8125rem;
  font-weight: 600;
}

/* A stop's name with an arrow, so it reads as something to tap. */
.stop-chip {
  display: flex;
  align-items: center;
  height: 2.5rem;
  padding: 0 0.625rem 0 0.75rem;
  border: 2px solid var(--color-button);
  border-radius: 1.25rem;
  background: #ffffff;
  color: #0a4bad;
  box-shadow: 0 3px 8px rgb(22 32 46 / 0.3);
  font-size: 0.9375rem;
  font-weight: 600;
}
/* The stop whose card is open: filled, larger, with the halo the selected bus has. */
.stop-chip-selected {
  scale: 1.15;
  border-color: #ffffff;
  background: var(--color-button);
  color: #ffffff;
  box-shadow: 0 0 0 10px rgb(10 88 202 / 0.25), 0 3px 8px rgb(22 32 46 / 0.3);
}
.stop-chip::after { content: "›"; margin-left: 0.375rem; font-size: 1.375rem; line-height: 1; }

/* Where the commuter is: the blue dot with a halo they know from other maps. */
.me-dot {
  box-sizing: border-box;
  border: 3px solid #ffffff;
  border-radius: 50%;
  background: #4285f4;
  box-shadow: 0 0 0 9px rgb(66 133 244 / 0.25), 0 1px 4px rgb(0 0 0 / 0.4);
}

/* The card: a Turbo Frame over the bottom of the map, above Leaflet's panes and controls. */
.map-card {
  position: absolute;
  right: 0.75rem;
  bottom: 0.75rem;
  left: 0.75rem;
  z-index: 1100;
  display: block;
  max-width: 28rem;
  max-height: 62%;
  margin: 0 auto;
  overflow: auto;
  border-radius: 1.5rem;
  background: var(--color-bg);
  box-shadow: 0 8px 28px rgb(22 32 46 / 0.3);
}
.map-card:empty { display: none; }

/* "Najbliższy przystanek", in the card's place while none is open. */
.nearest {
  position: absolute;
  right: 0.75rem;
  bottom: 1.5rem;
  left: 0.75rem;
  z-index: 1100;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  max-width: 22rem;
  min-height: 3.375rem;
  margin: 0 auto;
  border: 0;
  border-radius: 1.75rem;
  background: var(--color-button);
  box-shadow: 0 8px 28px rgb(22 32 46 / 0.3);
  color: #ffffff;
  font-family: inherit;
  font-size: 1.125rem;
  font-weight: 600;
  cursor: pointer;
}
.map-card:empty ~ .nearest { display: flex; }

/* "Stan na 12:34"; a card that can no longer be refreshed is greyed out around it (map#cardFailed). */
.card-asof { color: #5b6470; font-size: 0.9375rem; }
.map-card.stale {
  .card-body > :not(.card-asof), .card-band { opacity: 0.4; }
  .card-asof { color: #b3261e; font-weight: 700; }
}

/* ← only when a card came before this one (map_controller.js). */
.card-back { display: none; }
.map-card.has-back .card-back { display: flex; align-items: center; justify-content: center; }
.card-band { .card-close + .card-close { margin-left: -0.375rem; } }

/* A trip's card lists every stop once expanded (map#toggleCard): it then covers the map, so the list has room on
   a small phone too, and the list scrolls between the heading and the button, which folds it again. */
/* Folded only once the map's scripts run (.scripted, map_controller.js): without them the button could not open it. */
.card-less, .scripted .card-route { display: none; }
[data-controller="map"]:not(.scripted) :is([data-action="map#toggleCard"], .card-min) { display: none; }
.map-card.expanded {
  top: 0.75rem;
  max-height: none;
  overflow: hidden;

  .card { display: flex; flex-direction: column; height: 100%; }
  .card-body { flex: 1; min-height: 0; }
  .card-route { display: block; flex: 1; min-height: 0; overflow: auto; }
  .card-track, .card-stops, .card-more { display: none; }
  .card-less { display: inline; }
}

/* Folded down to its band (map#minimizeCard), to look at the map; the same button, its arrow turned, opens it again. */
.card-min { display: flex; align-items: center; justify-content: center; }
.card-min-up { display: none; }
.map-card.minimized {
  top: auto;
  overflow: hidden;

  .card-body, .card-min-down { display: none; }
  .card-min-up { display: inline; }
  .card-min svg { rotate: 180deg; }
}

/* The band carries the delay colour, and stays in place while a long card scrolls under it. */
.card-band {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 0.875rem 0.875rem 1.25rem;
  background: #5c6470;
  color: #ffffff;
}
.card-on_time .card-band { background: var(--color-ok); }
.card-late .card-band { background: var(--color-warn); color: var(--color-ink); }
.card-very_late .card-band { background: var(--color-bad); }
.card-stop .card-band { background: var(--color-button); }

.card-line { font-size: 2.5rem; font-weight: 700; line-height: 1; }
.card-status {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 0.9375rem;
  strong { display: block; font-size: 1.1875rem; line-height: 1.25; }
}
.card-close {
  flex: none;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 2px solid currentColor;
  border-radius: 50%;
  background: none;
  color: inherit;
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  padding: 1rem 1.25rem 1.25rem;

  p { margin: 0; }
  .stop-empty { font-size: 1.125rem; }
}
/* The lines calling at a stop. */
.card-lines {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin: 0.25rem 0 0;
  padding: 0;
  list-style: none;
  text-align: center;

  /* A tappable line is a blue button; one with no bus or departure now is a muted label. */
  .departure-line { display: block; min-width: 3.5rem; padding: 0.5rem 0.75rem; border-radius: 0.75rem; text-decoration: none; }
  a.departure-line { background: var(--color-button); color: #ffffff; }
  a.departure-line::after { content: " ›"; }
  span.departure-line { background: var(--color-border); color: var(--color-muted); }
}
.card-label { display: block; color: var(--color-muted); font-size: 0.875rem; }
.card-headsign { font-size: 1.25rem; font-weight: 600; }

/* Stop behind, the bus, stop ahead. */
.card-track {
  display: flex;
  align-items: center;

  i { flex: 1; height: 0.3125rem; background: var(--color-border); }
  b { width: 1.5rem; height: 1.5rem; border-radius: 50%; background: var(--color-ok); }
  .card-late & b { background: var(--color-warn); box-shadow: inset 0 0 0 1px #8a6d00; }
  .card-very_late & b { background: var(--color-bad); }
  &::before { content: ""; width: 1rem; height: 1rem; border-radius: 50%; background: var(--color-muted); }
  &::after { content: ""; width: 1.375rem; height: 1.375rem; border: 0.3125rem solid var(--color-button); border-radius: 50%; }
}
.card-stops {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  font-size: 1.125rem;

  p:last-child { text-align: right; }
}

.card-action {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  min-height: 3.375rem;
  border: 0;
  border-radius: 0.875rem;
  background: var(--color-button);
  color: #ffffff;
  font-size: 1.125rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}
