:root {
  --navy: #0e2a47;
  --yellow: #ffc72c;
  --paper: #f8faf9;
  --red: #d9362b;
  --sans: "Avenir Next Condensed", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  --serif: Charter, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --lx: 39px;   /* x-centre of the route line */
  --lw: 12px;   /* route line width */
  --ms: 34px;   /* stop marker size */
  --pl: 88px;   /* stop indent */
  --bus-w: 26px;
}

[data-cat="Culture"]  { --cat: #6b3a9e; }
[data-cat="Food"]     { --cat: #b34a00; }
[data-cat="Movement"] { --cat: #0b5cb5; }
[data-cat="People"]   { --cat: #b8245a; }
[data-cat="Places"]   { --cat: #17714a; }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }
html:has(dialog[open]) { overflow: hidden; }

body {
  margin: 0;
  background: var(--navy);
  color: var(--navy);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

:focus-visible {
  outline: 3px solid var(--navy);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px #fff;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip {
  position: absolute; left: 12px; top: -80px; z-index: 50;
  background: #fff; color: var(--navy); padding: 10px 16px; font-family: var(--sans); font-weight: 800;
}
.skip:focus { top: 12px; }

/* ---------- layout ---------- */

.shell {
  display: grid;
  grid-template-columns: minmax(340px, 28vw) 1fr;
  min-height: 100vh;
}

.pole {
  position: sticky; top: 0;
  height: 100vh; overflow-y: auto;
  background: var(--yellow);
  padding: 32px 28px 24px;
  display: flex; flex-direction: column; gap: 22px;
}

.name {
  margin: 0;
  font-family: var(--sans);
  font-weight: 800;
  font-size: 84px;
  line-height: .86;
  letter-spacing: -.035em;
  /* each word on its own line, like a sign stacked on a pole */
  max-width: 5.2em;
}
.tagline { margin: 14px 0 0; font-size: 18px; line-height: 1.4; max-width: 30ch; }

/* ---------- controls ---------- */

.controls { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field label { font-family: var(--sans); font-weight: 800; font-size: 17px; }

input[type="text"], select {
  width: 100%; min-height: 48px;
  border: 3px solid var(--navy); border-radius: 8px;
  background: #fff; color: var(--navy);
  font: 600 18px/1.2 var(--serif);
  padding: 0 12px;
}
select {
  appearance: none; -webkit-appearance: none;
  padding-right: 40px;
  background-image: linear-gradient(45deg, transparent 50%, var(--navy) 50%), linear-gradient(135deg, var(--navy) 50%, transparent 50%);
  background-position: calc(100% - 22px) 55%, calc(100% - 16px) 55%;
  background-size: 6px 6px; background-repeat: no-repeat;
  cursor: pointer;
}
input::placeholder { color: #4a5f75; font-weight: 400; }

.saved-toggle {
  display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 48px; padding: 0 14px;
  border: 3px solid var(--navy); border-radius: 8px;
  background: #fff; color: var(--navy);
  font: 800 18px/1 var(--sans);
  cursor: pointer; text-align: left;
}
.saved-toggle[aria-pressed="true"] { background: var(--navy); color: var(--yellow); }
.saved-toggle .count {
  margin-left: auto; min-width: 28px; padding: 3px 8px;
  border-radius: 99px; background: var(--navy); color: var(--yellow);
  text-align: center; font-size: 16px;
}
.saved-toggle[aria-pressed="true"] .count { background: var(--yellow); color: var(--navy); }

.status { margin: 0; font-family: var(--sans); font-weight: 700; font-size: 17px; min-height: 1.4em; }

.fine { margin: 0; font-size: 14px; line-height: 1.45; max-width: 34ch; }

/* ---------- destination blind ---------- */

.blind {
  position: relative;
  background: var(--navy); color: var(--yellow);
  border-radius: 8px;
  font-family: var(--sans); font-weight: 800;
  overflow: hidden;
}
.blind::after { /* LED grid */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(14, 42, 71, .8) 1px, transparent 1px),
    linear-gradient(90deg, rgba(14, 42, 71, .8) 1px, transparent 1px);
  background-size: 3px 3px;
}
.blind p { margin: 0; }
.blind-pole { margin-top: auto; padding: 14px 16px 16px; }
.blind-pole .blind-top { font-size: 15px; opacity: .85; }
.blind-pole .blind-text { font-size: 28px; line-height: 1.05; letter-spacing: .01em; min-height: 2.1em; }
.blind-bar { display: none; }

/* ---------- route ---------- */

.route-area { padding: 56px 40px 120px 0; min-width: 0; outline: none; }
.route-wrap { position: relative; max-width: 800px; }

.route { list-style: none; margin: 0; padding: 0; position: relative; }

.stop {
  position: relative;
  padding: 0 0 calc(var(--min) * 9px + 30px) var(--pl);
}
.stop::before { /* the line */
  content: ""; position: absolute;
  left: calc(var(--lx) - var(--lw) / 2); width: var(--lw);
  top: 0; bottom: 0;
  background: var(--yellow);
}
.stop:first-child::before { top: 39px; border-radius: 6px 6px 0 0; }
.stop:last-child::before { bottom: 12px; }
.stop:last-child::after { /* buffer stop */
  content: ""; position: absolute;
  left: calc(var(--lx) - 24px); width: 48px; bottom: 4px; height: 10px;
  background: var(--yellow); border-radius: 3px;
}
.marker {
  position: absolute; z-index: 1;
  left: calc(var(--lx) - var(--ms) / 2); top: 22px;
  width: var(--ms); height: var(--ms); border-radius: 50%;
  background: var(--cat); border: 5px solid #fff;
  box-shadow: 0 0 0 5px var(--navy);
}
.leg {
  position: absolute; z-index: 1;
  left: calc(var(--lx) + 22px); bottom: 14px;
  font-family: var(--sans); font-weight: 800; font-size: 15px; color: var(--yellow);
}
.stop:last-child .leg { bottom: 20px; }

.card {
  position: relative;
  background: var(--paper);
  border-radius: 4px 22px 4px 22px;
  padding: 22px 26px 24px;
  max-width: 680px;
}
.card::before { /* pointer to the stop marker */
  content: ""; position: absolute; left: -12px; top: 27px;
  border: 12px solid transparent; border-left: 0; border-right-color: var(--paper);
}
.card-top { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; flex-wrap: wrap; }
.chip {
  margin: 0; display: inline-block;
  background: var(--cat); color: #fff;
  font: 800 15px/1 var(--sans); letter-spacing: .02em;
  padding: 6px 10px 6px; border-radius: 3px;
}
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font: 800 15px/1 var(--sans);
  border: 2px dashed var(--navy); border-radius: 3px; padding: 4px 8px;
}
.card-title {
  margin: 0 0 10px;
  font-family: var(--sans); font-weight: 800;
  font-size: 34px; line-height: 1.02; letter-spacing: -.015em;
  text-wrap: balance;
}
.summary { margin: 0 0 12px; font-size: 18px; line-height: 1.5; max-width: 52ch; }
.byline { margin: 0 0 16px; font-size: 15px; color: #3c5269; }
.byline span + span::before { content: ""; display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: currentColor; margin: 0 9px 2px; }

.ring {
  display: inline-flex; align-items: center; gap: 10px;
  min-height: 48px; padding: 0 18px 0 14px;
  background: var(--red); color: #fff;
  border: 3px solid var(--navy); border-radius: 99px;
  font: 800 18px/1 var(--sans);
  cursor: pointer;
  transition: transform .12s ease;
}
.ring:hover { background: #b82a20; }
.ring:active { transform: translateY(2px) scale(.98); }
.ring svg { flex: none; }

/* ---------- bus ---------- */

.bus {
  position: absolute; z-index: 2; pointer-events: none;
  left: calc(var(--lx) - var(--bus-w) / 2);
  width: var(--bus-w); aspect-ratio: 26 / 46;
  top: 70px;
  transition: top .7s cubic-bezier(.5, 0, .2, 1);
  filter: drop-shadow(0 3px 0 rgba(14, 42, 71, .5));
}

/* ---------- empty state ---------- */

.empty {
  margin: 0 40px 0 56px; max-width: 520px;
  background: var(--yellow); border: 4px solid #fff; border-radius: 4px 22px 4px 22px;
  padding: 28px;
}
.empty h2 { margin: 0 0 8px; font: 800 36px/1 var(--sans); letter-spacing: -.015em; }
.empty p { margin: 0 0 20px; max-width: 40ch; }
.btn-reset {
  min-height: 48px; padding: 0 20px;
  background: var(--navy); color: var(--yellow);
  border: 3px solid var(--navy); border-radius: 8px;
  font: 800 18px/1 var(--sans); cursor: pointer;
}
.empty .btn-reset:focus-visible { outline-color: var(--navy); }

/* ---------- detail ---------- */

.ticket {
  border: 0; padding: 0; margin: 0;
  position: fixed; top: 0; right: 0; bottom: 0; left: auto;
  width: min(820px, 100vw); max-width: none;
  height: 100vh; height: 100dvh; max-height: none;
  background: var(--paper); color: var(--navy);
  overflow: hidden;
}
.ticket[open] { display: flex; flex-direction: column; animation: board .26s ease-out; }
.ticket::backdrop { background: rgba(14, 42, 71, .74); }
.ticket[open]::backdrop { animation: fade .26s ease-out; }
@keyframes board { from { transform: translateX(48px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.ticket-head {
  flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background-color: var(--cat);
  background-image: repeating-linear-gradient(90deg, rgba(255, 255, 255, .18) 0 2px, transparent 2px 5px, rgba(255, 255, 255, .18) 5px 6px, transparent 6px 12px);
  padding: 12px 20px;
  border-bottom: 4px solid var(--yellow);
}
.ticket-head .chip { background: #fff; color: var(--cat); font-size: 17px; padding: 8px 12px; }
.close {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 46px; padding: 0 16px;
  background: #fff; color: var(--navy);
  border: 3px solid var(--navy); border-radius: 99px;
  font: 800 17px/1 var(--sans); cursor: pointer;
}
.close:hover { background: var(--yellow); }

.ticket-scroll {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 40px clamp(20px, 5vw, 56px) 48px calc(clamp(20px, 5vw, 56px) + 14px);
  background:
    linear-gradient(var(--yellow), var(--yellow)) left top / 12px 100% no-repeat,
    var(--paper);
}
.story { max-width: 62ch; }
.story h2 {
  margin: 0 0 14px;
  font: 800 clamp(36px, 5.2vw, 60px)/.98 var(--sans); letter-spacing: -.025em;
  text-wrap: balance;
}
.meta { margin: 0 0 22px; font-size: 16px; color: #3c5269; }
.lede { margin: 0 0 26px; padding-bottom: 26px; border-bottom: 3px dashed var(--navy); font-size: 22px; line-height: 1.4; font-style: italic; }
.body { white-space: pre-line; font-size: 19px; line-height: 1.75; }

.ticket-foot {
  flex: none;
  display: flex; gap: 12px; align-items: stretch;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
  border-top: 4px solid var(--yellow);
  background: var(--paper);
  position: relative;
}
.save {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 56px; padding: 0 22px;
  background: var(--yellow); color: var(--navy);
  border: 3px solid var(--navy); border-radius: 10px;
  font: 800 19px/1 var(--sans); cursor: pointer;
}
.save[aria-pressed="true"] { background: var(--navy); color: var(--yellow); }
.next {
  margin-left: auto; min-width: 0; max-width: 55%;
  display: flex; flex-direction: column; justify-content: center; align-items: flex-start; gap: 3px;
  min-height: 56px; padding: 6px 18px;
  background: #fff; color: var(--navy);
  border: 3px solid var(--navy); border-radius: 10px;
  font-family: var(--sans); cursor: pointer; text-align: left;
}
.next:hover { background: #e9eef2; }
.next-top { font-weight: 800; font-size: 18px; line-height: 1; }
.next-title { font-family: var(--serif); font-size: 14px; line-height: 1.2; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- mobile ---------- */

@media (max-width: 860px) {
  :root { --lx: 24px; --lw: 10px; --ms: 28px; --pl: 56px; --bus-w: 22px; }

  .shell { display: block; }
  .pole { position: static; height: auto; overflow: visible; padding: 22px 16px 18px; gap: 16px; }
  .name { font-size: 46px; max-width: none; line-height: .9; }
  .tagline { margin-top: 8px; font-size: 16px; max-width: 34ch; }
  .controls { grid-template-columns: 1fr 1fr; align-items: end; gap: 12px; }
  .field-search { grid-column: 1 / -1; }
  .saved-toggle { padding: 0 10px; font-size: 17px; }
  .saved-toggle svg { display: none; }
  .blind-pole { display: none; }
  .fine { display: none; }

  .blind-bar {
    display: block; position: sticky; top: 0; z-index: 20;
    border-radius: 0; padding: 0 16px;
    border-bottom: 4px solid var(--yellow);
  }
  .blind-bar .blind-text {
    font-size: 21px; line-height: 48px; height: 48px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }

  .route-area { padding: 36px 14px 90px 0; }
  .stop { padding-bottom: calc(var(--min) * 7px + 26px); }
  .stop:first-child::before { top: 33px; }
  .marker { top: 18px; border-width: 4px; box-shadow: 0 0 0 4px var(--navy); }
  .leg { font-size: 14px; left: calc(var(--lx) + 18px); }
  .stop:last-child::after { left: calc(var(--lx) - 18px); width: 36px; }
  .card { padding: 16px 16px 18px; border-radius: 3px 18px 3px 18px; }
  .card::before { left: -10px; top: 21px; border-width: 10px; border-left: 0; }
  .card-title { font-size: 28px; }
  .summary { font-size: 17px; }
  .bus { top: 56px; }

  .empty { margin: 0 14px 0 16px; padding: 22px; }
  .empty h2 { font-size: 30px; }

  .ticket { width: 100vw; }
  .ticket-head { padding: 10px 14px; }
  .ticket-scroll { padding: 28px 18px 36px 30px; }
  .lede { font-size: 20px; }
  .body { font-size: 18px; line-height: 1.7; }
  .ticket-foot { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); gap: 10px; }
  .save { flex: 1 1 0; padding: 0 10px; font-size: 17px; min-width: 0; }
  .save svg { display: none; }
  .next { flex: 1 1 0; max-width: none; margin-left: 0; padding: 6px 12px; }
  .next-top { font-size: 17px; }
}

@media (max-width: 860px) and (max-height: 500px) {
  .blind-bar { position: static; }
}

@media (min-width: 861px) and (max-height: 760px) {
  .name { font-size: 64px; }
  .tagline { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .bus { transition: none; }
  .ticket[open], .ticket[open]::backdrop { animation: none; }
  .ring { transition: none; }
}
