/* ============================================================
   Weekend Line — tokens
   ============================================================ */
:root {
  --paper: #e8e9e2;
  --card: #fbfaf5;
  --ink: #232f38;
  --ink-soft: #5c6b75;
  --sat: #d98a1f;          /* Saturday line */
  --sat-text: #8f5a0e;     /* amber that passes on paper */
  --sun: #157f6d;          /* Sunday line */
  --sun-text: #0e6355;     /* teal that passes on paper */
  --stamp: #c2402f;        /* saved / rubber stamp */
  --font-ui: "Space Grotesk", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --shadow: 3px 3px 0 var(--ink);
}

@font-face {
  font-family: "Space Grotesk";
  src: url("assets/space-grotesk.ttf") format("truetype");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("assets/ibm-plex-mono.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* ============================================================
   Base
   ============================================================ */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
}
[hidden] { display: none !important; }

h1, h2, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }
button { font: inherit; color: inherit; cursor: pointer; }

:focus-visible {
  outline: 3px solid var(--sat-text);
  outline-offset: 3px;
  border-radius: 1px;
}

.skip {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  background: var(--card);
  border: 2px solid var(--ink);
  padding: 8px 14px;
  text-decoration: none;
  transition: top .15s ease;
}
.skip:focus { top: 10px; }

/* ============================================================
   Masthead + controls
   ============================================================ */
.masthead-wrap {
  max-width: 1330px;
  margin: 0 auto;
  padding: 0 20px;
}
.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 0 12px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.roundel { width: 46px; height: 46px; flex: none; }
.roundel-disc { fill: var(--sat); stroke: var(--ink); stroke-width: 2.5; }
.roundel-bar { fill: var(--ink); }
.roundel-w {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 16px;
  fill: var(--card);
}
.wordmark {
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.05;
}
.tagline {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 3px;
}
.masthead-note {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
  border: 1.5px solid var(--ink);
  background: var(--card);
  padding: 6px 10px;
  box-shadow: var(--shadow);
}

.controls-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--paper);
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
}
.controls {
  max-width: 1330px;
  margin: 0 auto;
  padding: 12px 20px 14px;
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}
.control { display: flex; flex-direction: column; gap: 4px; }
.control:first-child { flex: 1 1 240px; }
.control-label {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-soft);
}
.control-input {
  font-family: var(--font-ui);
  font-size: 15px;
  color: var(--ink);
  background: var(--card);
  border: 1.5px solid var(--ink);
  padding: 8px 10px;
  width: 100%;
  box-shadow: var(--shadow);
}
.control-input::placeholder { color: var(--ink-soft); }
select.control-input { width: auto; padding-right: 30px; }

.route-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1.5px solid var(--ink);
  padding: 8px 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
}
.route-count {
  font-family: var(--font-mono);
  font-size: 12px;
  border: 1.5px solid currentColor;
  padding: 0 6px;
  min-width: 22px;
  text-align: center;
}
.route-toggle[aria-pressed="true"] {
  background: var(--stamp);
  color: var(--card);
  border-color: var(--ink);
}
.route-toggle[aria-pressed="true"]:focus-visible {
  outline-color: var(--card);
}

.count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
  margin-left: auto;
  align-self: center;
  padding-bottom: 2px;
}

/* ============================================================
   Legend + stage (desktop route diagram)
   ============================================================ */
main { max-width: 1330px; margin: 0 auto; padding: 0 20px; }
.stage-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 20px;
  padding: 16px 0 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
}
.legend-key { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); }
.swatch { width: 26px; height: 5px; flex: none; }
.swatch-sat { background: var(--sat); }
.swatch-sun { background: var(--sun); }
.dot-key {
  width: 13px; height: 13px; flex: none;
  border: 2.5px solid var(--stamp);
  border-radius: 50%;
  background: var(--card);
}
.legend-note { flex-basis: 100%; }

.stage-wrap {
  display: flex;
  justify-content: center;
  overflow: hidden;
  overflow: clip;
  position: relative;
}
.stage {
  position: relative;
  width: 1200px;
  height: 1060px;
  flex: none;
  transform-origin: top center;
}
.map { position: absolute; inset: 0; width: 1200px; height: 1060px; }

/* SVG pieces (JS sets geometry; CSS sets paint) */
.grid-line { stroke: var(--ink); stroke-opacity: .08; stroke-width: 1; }
.grid-label {
  font-family: var(--font-mono);
  font-size: 11px;
  fill: var(--ink-soft);
  text-anchor: middle;
}
.line-route { stroke-linecap: butt; }
.line-sat { stroke: var(--sat); }
.line-sun { stroke: var(--sun); }
.line-dashed { stroke: var(--ink-soft); stroke-dasharray: 3 9; stroke-width: 2; }
.terminal { stroke: none; }
.terminal-sat { fill: var(--sat); }
.terminal-sun { fill: var(--sun); }
.day-label {
  font-family: var(--font-mono);
  font-size: 13px;
}
.day-label-sat { fill: var(--sat-text); }
.day-label-sun { fill: var(--sun-text); }
.overnight-label-bg { fill: var(--paper); }
.overnight-label {
  font-family: var(--font-mono);
  font-size: 13.5px;
  fill: var(--ink-soft);
}
.moon { fill: none; stroke: var(--ink-soft); stroke-width: 1.5; }

.stop.filtered { display: none; }
.stopg .stem { stroke: var(--ink); stroke-width: 1.5; }
.stopg .dot { fill: var(--card); stroke-width: 3.5; }
.stopg .savedring { fill: none; stroke: var(--stamp); stroke-width: 2.5; }
.stopg.sat .dot { stroke: var(--sat); }
.stopg.sun .dot { stroke: var(--sun); }
.stopg.dimmed { opacity: .14; }

/* Line-draw reveal (skipped for reduced motion in JS) */
.stage.reveal .line-route {
  stroke-dasharray: 1300;
  stroke-dashoffset: 1300;
  animation: draw 1s cubic-bezier(.6, 0, .2, 1) forwards;
}
.stage.reveal .stopg .dot,
.stage.reveal .stopg .stem,
.stage.reveal .stopg .savedring {
  animation: pop .3s cubic-bezier(.2, 1.4, .4, 1) backwards;
  animation-delay: var(--d, 0s);
}
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes pop { from { opacity: 0; } }

/* ============================================================
   Stop cards (shared desktop/mobile)
   ============================================================ */
.stop-card {
  position: relative;
  display: block;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1.5px solid var(--ink);
  padding: 10px 12px 11px;
  box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease;
}
.stop.sat .stop-card { border-left: 5px solid var(--sat); }
.stop.sun .stop-card { border-left: 5px solid var(--sun); }
@media (hover: hover) {
  .stop-card:hover { transform: translate(-2px, -2px); box-shadow: 5px 5px 0 var(--ink); }
}
.stop-card:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink); }

.card-time {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: .02em;
}
.stop.sat .card-time { color: var(--sat-text); }
.stop.sun .card-time { color: var(--sun-text); }
.card-title {
  display: block;
  font-size: 15.5px;
  font-weight: 600;
  line-height: 1.22;
  margin: 5px 0 3px;
}
.card-place {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.35;
}
.card-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.chip {
  font-family: var(--font-mono);
  font-size: 10.5px;
  border: 1.2px solid var(--ink-soft);
  color: var(--ink);
  padding: 1px 7px;
  border-radius: 999px;
  background: transparent;
}
.chip-fare { border-color: var(--ink); background: var(--paper); }

.onroute {
  position: absolute;
  top: 8px;
  right: 9px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--stamp);
  transform: rotate(-4deg);
}
.stop-card .onroute { display: none; }
.stop.is-saved .stop-card .onroute { display: block; }

/* Desktop positioning */
.card-layer { position: absolute; inset: 0; pointer-events: none; }
.card-layer .stop {
  position: absolute;
  width: 240px;
  pointer-events: auto;
  animation: rise .45s ease backwards;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
}

/* ============================================================
   Mobile browsing (vertical lines)
   ============================================================ */
.stage-wrap.mobile-off { display: none; }
.mobile-list { padding: 4px 0 10px; }
.day-section { position: relative; padding-left: 44px; margin-top: 14px; }
.day-heading {
  font-size: 19px;
  font-weight: 700;
  margin: 6px 0 4px;
  position: relative;
  z-index: 1;
}
.day-sub {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-soft);
  margin-bottom: 12px;
}
.day-section::before {
  content: "";
  position: absolute;
  left: 17px;
  top: 6px;
  bottom: 14px;
  width: 3px;
}
.day-section.sat::before { background: var(--sat); }
.day-section.sun::before { background: var(--sun); }
.day-section.sat .day-heading { color: var(--sat-text); }
.day-section.sun .day-heading { color: var(--sun-text); }

.mobile-list .stop { position: relative; margin: 0 0 14px; }
.mobile-list .stop::before {
  content: "";
  position: absolute;
  left: -33px;
  top: 16px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--card);
  border: 3px solid var(--ink);
}
.mobile-list .stop.sat::before { border-color: var(--sat); }
.mobile-list .stop.sun::before { border-color: var(--sun); }
.mobile-list .stop.is-saved::after {
  content: "";
  position: absolute;
  left: -36px;
  top: 13px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  border: 2.5px solid var(--stamp);
}

/* ============================================================
   Empty state
   ============================================================ */
.empty-state {
  max-width: 430px;
  margin: 26px auto;
  background: var(--card);
  border: 2px solid var(--ink);
  box-shadow: 6px 6px 0 var(--ink);
  padding: 26px 26px 22px;
  text-align: center;
}
.empty-title { font-size: 20px; font-weight: 700; }
.empty-body { font-size: 14px; color: var(--ink-soft); margin: 8px 0 16px; }
.empty-reset {
  background: var(--paper);
  border: 2px solid var(--ink);
  padding: 9px 16px;
  font-weight: 600;
  box-shadow: var(--shadow);
}
.empty-reset:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink); }

/* Desktop: float the empty state over the map area */
@media (min-width: 901px) {
  .empty-state { position: absolute; top: 240px; left: 50%; transform: translateX(-50%); z-index: 5; margin: 0; }
  main { position: relative; }
}

/* ============================================================
   Ticket (detail dialog)
   ============================================================ */
.ticket {
  border: 2px solid var(--ink);
  box-shadow: 8px 8px 0 rgba(35, 47, 56, .85);
  padding: 0;
  background: var(--card);
  width: min(600px, calc(100vw - 24px));
  max-height: min(86vh, 820px);
  overflow: auto;
}
.ticket::backdrop { background: rgba(35, 47, 56, .55); }

.ticket-inner { position: relative; }

.stub {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 30px;
  border-right: 2px dashed var(--ink);
}
.stub-sat { background: var(--sat); }
.stub-sun { background: var(--sun); }
.stub-label {
  position: absolute;
  left: 7px;
  top: 14px;
  writing-mode: vertical-rl;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .08em;
  color: var(--ink);
  background: var(--card);
  padding: 6px 2px;
  border: 1.2px solid var(--ink);
}
.stub-punch {
  position: absolute;
  left: 30px;
  width: 12px; height: 12px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--ink);
}
.stub-punch.top { top: 36px; }
.stub-punch.bottom { bottom: 36px; }

.ticket-body { padding: 20px 22px 18px 40px; position: relative; }

.ticket-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.ticket-kicker {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-soft);
}
.ticket-close {
  background: var(--paper);
  border: 1.5px solid var(--ink);
  padding: 6px 12px;
  font-weight: 600;
  box-shadow: var(--shadow);
}
.ticket-close:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink); }

.ticket-date {
  font-family: var(--font-mono);
  font-size: 12.5px;
  margin-bottom: 2px;
}
.ticket-time {
  font-family: var(--font-mono);
  font-size: 30px;
  letter-spacing: .01em;
  line-height: 1.1;
}
.stop.sat .ticket-time, .ticket-time.sat { color: var(--sat-text); }
.stop.sun .ticket-time, .ticket-time.sun { color: var(--sun-text); }
.ticket-title {
  font-size: 23px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.2px;
  margin: 10px 0 14px;
  padding-right: 40px;
}

.mini-route { display: block; width: 100%; height: 46px; margin-bottom: 16px; }
.mini-route .mini-line { stroke-width: 7; }
.mini-route .mini-dot { fill: var(--card); stroke-width: 3; }
.mini-route .mini-current { fill: var(--card); stroke-width: 3.5; }
.mini-route .mini-saved { stroke: var(--stamp); }
.mini-current-label {
  font-family: var(--font-mono);
  font-size: 11px;
  fill: var(--ink-soft);
  text-anchor: middle;
}

.facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5px;
  background: var(--ink);
  border: 1.5px solid var(--ink);
  margin-bottom: 16px;
}
.fact { background: var(--paper); padding: 9px 12px 10px; }
.fact-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-soft);
  margin-bottom: 2px;
}
.fact-value { font-size: 14.5px; font-weight: 600; line-height: 1.3; }

.ticket-body-text { font-size: 15px; line-height: 1.55; max-width: 62ch; }
.service-notes-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
  margin: 14px 0 2px;
}
.service-notes-text { font-size: 13.5px; line-height: 1.5; color: var(--ink); }

.save-btn {
  display: block;
  width: 100%;
  margin-top: 18px;
  padding: 13px 16px;
  background: var(--paper);
  border: 2px solid var(--ink);
  font-size: 16px;
  font-weight: 700;
  box-shadow: var(--shadow);
}
.save-btn[aria-pressed="true"] {
  background: var(--stamp);
  color: var(--card);
}
.save-btn:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink); }
.save-btn:focus-visible { outline-offset: -6px; outline-width: 3px; }

.stamp-mark {
  position: absolute;
  top: 44px;
  right: 18px;
  transform: rotate(-11deg);
  border: 3.5px double var(--stamp);
  color: var(--stamp);
  font-family: var(--font-mono);
  font-size: 13.5px;
  padding: 5px 10px 4px;
  letter-spacing: .06em;
  border-radius: 3px;
  pointer-events: none;
  animation: punch .25s cubic-bezier(.2, 1.6, .4, 1);
}
@keyframes punch {
  from { transform: rotate(-11deg) scale(1.7); opacity: 0; }
}

.ticket-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  border-top: 2px dashed var(--ink);
  padding-top: 12px;
}
.barcode {
  width: 150px; height: 30px;
  background: repeating-linear-gradient(90deg,
    var(--ink) 0 2px, transparent 2px 4px,
    var(--ink) 4px 7px, transparent 7px 9px,
    var(--ink) 9px 10px, transparent 10px 13px);
}
.ticket-no { font-family: var(--font-mono); font-size: 11px; color: var(--ink-soft); }

/* ============================================================
   Footer
   ============================================================ */
.footer {
  max-width: 1330px;
  margin: 26px auto 0;
  padding: 18px 20px 34px;
  border-top: 2px solid var(--ink);
  font-size: 13px;
  color: var(--ink-soft);
  display: flex;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}
.footer-fine { font-family: var(--font-mono); font-size: 11px; flex-basis: 260px; text-align: right; }

/* ============================================================
   Breakpoints
   ============================================================ */
@media (max-width: 900px) {
  .masthead { padding: 14px 0 10px; }
  .wordmark { font-size: 22px; }
  .roundel { width: 38px; height: 38px; }
  .masthead-note { display: none; }
  .controls { gap: 10px; }
  .control:first-child { flex-basis: 100%; }
  .count { flex-basis: 100%; margin-left: 0; padding: 0; }
  .route-toggle { margin-left: auto; }
  .stage-legend { padding-top: 10px; }
  .legend-note { display: none; }
  .ticket-body { padding: 16px 16px 16px 34px; }
  .ticket-time { font-size: 24px; }
  .ticket-title { font-size: 20px; }
  .footer { flex-direction: column; }
  .footer-fine { text-align: left; }
}

/* ============================================================
   Reduced motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .stage.reveal .line-route { stroke-dasharray: none; stroke-dashoffset: 0; animation: none; }
}
