:root {
  --bg: #FFFFFF;
  --bg-soft: #F7F7F7;
  --bg-tile: #F2F2F2;
  --ink: #222222;
  --ink-2: #717171;
  --ink-3: #BBBBBB;
  --line: #EBEBEB;
  --accent: #00ACC1;
  --accent-ink: #0c7a89;
  --accent-soft: #E6F7FA;
  --shadow-card: 0 2px 16px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.04);
  --shadow-search: 0 4px 14px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.06);
  --pad: 24px;
  --radius-card: 16px;
  --radius-pill: 999px;
  --tap: cubic-bezier(.2,.7,.2,1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg-soft);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Desktop frame */
.device {
  width: min(430px, 100vw);
  height: min(932px, 100vh);
  background: var(--bg);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
@media (min-width: 460px) {
  .device {
    border-radius: 44px;
    box-shadow: 0 30px 80px rgba(0,0,0,0.18), 0 8px 24px rgba(0,0,0,0.08);
    border: 1px solid #ECECEC;
    height: 932px;
  }
}
@media (max-width: 459px) {
  body { background: var(--bg); }
}

/* Screens stack */
.screens {
  flex: 1;
  position: relative;
  overflow: hidden;
}
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
  transition: transform 280ms var(--tap), opacity 280ms var(--tap);
  will-change: transform, opacity;
}
.screen.active {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}
.screen.behind {
  transform: translateX(-18%);
  opacity: 0.6;
}

/* Fixed top section (header, search, etc.) */
.screen-fixed {
  flex-shrink: 0;
  background: var(--bg);
  padding-top: max(env(safe-area-inset-top, 0px), 12px);
  position: relative;
  z-index: 2;
}
@supports not (padding-top: max(0px, 0px)) {
  .screen-fixed { padding-top: 12px; }
}

.scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 40px;
}
.scroll::-webkit-scrollbar { width: 0; }

/* Header */
.header {
  padding: 14px var(--pad) 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
}
.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.brand .title {
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -0.025em;
  line-height: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand .title .dot {
  width: 22px; height: 22px;
  border-radius: 8px;
  background: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 2px 6px rgba(0,172,193,0.35);
}
.brand .sub { font-size: 13px; color: var(--ink-2); font-weight: 500; letter-spacing: -0.01em; }
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: transform 120ms var(--tap), background 120ms var(--tap);
  color: var(--ink);
  text-decoration: none;
}
.icon-btn:active { transform: scale(0.94); background: #EFEFEF; }

/* Back row */
.back-row {
  padding: 8px var(--pad) 4px;
  display: flex;
  align-items: center;
}
.back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 8px 8px 8px 0;
  cursor: pointer;
  letter-spacing: -0.01em;
}
.back:active { opacity: 0.6; }

/* Page intro */
.page-intro { padding: 12px var(--pad) 20px; }
.page-intro h1 {
  margin: 0 0 6px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.08;
}
.page-intro p { margin: 0; color: var(--ink-2); font-size: 14px; }

/* Origin badge row (step 2) */
.from-row {
  padding: 0 var(--pad) 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.from-label { font-size: 12px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.08em; }
.pill-from {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pill-from .bullet { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }

/* Search bar */
.search-wrap { padding: 4px var(--pad) 22px; }
.search {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
  background: var(--bg);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-search);
  padding: 0 18px;
  position: relative;
  transition: box-shadow 200ms var(--tap);
}
.search:focus-within { box-shadow: var(--shadow-search), 0 0 0 2px var(--accent); }
.search svg.search-icon { color: var(--ink); flex-shrink: 0; }
.search input {
  border: none;
  outline: none;
  background: transparent;
  flex: 1;
  font-family: inherit;
  font-size: 15px;
  color: var(--ink);
  font-weight: 500;
  letter-spacing: -0.01em;
  min-width: 0;
}
.search input::placeholder { color: var(--ink-2); font-weight: 500; }
.search .clear {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--bg-tile);
  color: var(--ink);
  border: none;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.search.has-value .clear { display: inline-flex; }

/* Section title */
.section-title {
  padding: 0 var(--pad);
  margin: 0 0 12px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--ink);
}

.section-sub {
  padding: 0 var(--pad);
  margin: -8px 0 14px;
  font-size: 14px;
  color: var(--ink-2);
}

/* Stop list (full-bleed rows) */
.stops { padding: 0; }
.stop-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px var(--pad);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  cursor: pointer;
  transition: background 120ms var(--tap), transform 120ms var(--tap);
  border: none;
  text-align: left;
  width: 100%;
  border-left: none;
  border-right: none;
  border-top: none;
  font-family: inherit;
}
.stop-row:active { background: var(--bg-soft); transform: scale(0.995); }
.stop-row .ico {
  width: 48px; height: 48px;
  border-radius: 12px;
  background: var(--bg-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stop-row .ico svg { color: var(--ink); }
.stop-row .body { flex: 1; min-width: 0; }
.stop-row .name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin: 0 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stop-row .muni { font-size: 13px; color: var(--ink-2); }
.stop-row .chev { color: var(--ink-3); flex-shrink: 0; }
.stop-row.hidden { display: none; }

/* Animations: staggered enter */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}
.screen.active .stagger > * {
  animation: fadeUp 380ms var(--tap) both;
}
.screen.active .stagger > *:nth-child(1) { animation-delay: 40ms; }
.screen.active .stagger > *:nth-child(2) { animation-delay: 100ms; }
.screen.active .stagger > *:nth-child(3) { animation-delay: 160ms; }
.screen.active .stagger > *:nth-child(4) { animation-delay: 220ms; }
.screen.active .stagger > *:nth-child(5) { animation-delay: 280ms; }
.screen.active .stagger > *:nth-child(6) { animation-delay: 340ms; }
.screen.active .stagger > *:nth-child(7) { animation-delay: 400ms; }
.screen.active .stagger > *:nth-child(8) { animation-delay: 460ms; }
.screen.active .stagger > *:nth-child(n+9) { animation-delay: 520ms; }

/* Route card (step 3) */
.route-card {
  margin: 4px var(--pad) 18px;
  background: var(--bg);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.line-badge {
  flex-shrink: 0;
  min-width: 52px;
  height: 52px;
  padding: 0 10px;
  border-radius: 14px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(0,172,193,0.28);
}
.route-text { flex: 1; min-width: 0; }
.route-text .od {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.02em;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  line-height: 1.2;
}
.route-text .od .arrow { color: var(--ink-3); font-weight: 600; }
.route-text .meta { font-size: 13px; color: var(--ink-2); margin-top: 4px; }

/* Next bus block */
.next-bus {
  padding: 4px var(--pad) 24px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}
.next-bus .left .label {
  font-size: 12px;
  color: var(--ink-2);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 6px;
}
.next-bus .left .time {
  font-size: 48px;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--ink);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.next-bus .left .sub {
  font-size: 13px;
  color: var(--ink-2);
  margin-top: 8px;
}
.countdown {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.01em;
  box-shadow: 0 6px 14px rgba(0,172,193,0.3);
  white-space: nowrap;
}
.countdown .pulse {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 0 0 0 rgba(255,255,255,0.7);
  animation: pulse 1.6s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,255,255,0.7); }
  70% { box-shadow: 0 0 0 8px rgba(255,255,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); }
}

/* Filter chips */
.chips {
  display: flex;
  gap: 8px;
  padding: 0 var(--pad) 20px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font-family: inherit;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background 180ms var(--tap), color 180ms var(--tap), border-color 180ms var(--tap), transform 120ms var(--tap);
}
.chip:active { transform: scale(0.96); }
.chip.active {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}

/* Time groups */
.time-group { padding: 0 var(--pad) 22px; }
.time-group .gtitle {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.time-group .gtitle::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.time-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.time-chip {
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font-weight: 700;
  font-family: inherit;
  font-size: 14px;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 120ms var(--tap);
}
.time-chip:active { transform: scale(0.95); }
.time-chip.past {
  color: var(--ink-3);
  text-decoration: line-through;
  background: var(--bg);
}
.time-chip.next {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(0,172,193,0.28);
}

/* Fermate timeline (step 4) */
.fermate-head {
  padding: 4px var(--pad) 18px;
}
.fermate-head .lbl {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}
.fermate-head h1 {
  margin: 0 0 4px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.fermate-head .meta { font-size: 13px; color: var(--ink-2); }
.city-section {
  padding: 14px var(--pad) 6px;
}
.city-section .ctitle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.city-section .ctitle .badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.city-section .ctitle .nm { font-size: 13px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.08em; }
.stop-line {
  position: relative;
  padding: 12px 0 12px 40px;
  border-bottom: 1px solid var(--line);
}
.stop-line:last-child { border-bottom: none; }
.stop-line::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px; height: 12px;
  border-radius: 50%;
  background: white;
  border: 2.5px solid var(--accent);
  z-index: 1;
}
.stop-line.is-departure::before,
.stop-line.is-arrival::before {
  background: var(--accent);
}
.stop-line::after {
  content: "";
  position: absolute;
  left: 17px;
  top: 50%;
  height: 100%;
  width: 2px;
  background: var(--line);
  z-index: 0;
}
.stop-line:last-child::after { display: none; }
.stop-line .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.stop-line .nm-stop {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--ink);
}
.stop-line .tm {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  letter-spacing: -0.01em;
}

/* Transit separator */
.transit-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0 8px 40px;
  position: relative;
}
.transit-separator::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--bg-soft);
  border: 2px dashed var(--ink-3);
  z-index: 1;
}
.transit-label {
  font-size: 13px;
  font-weight: 500;
  font-style: italic;
  color: var(--ink-2);
}
.transit-dots {
  color: var(--ink-3);
  font-size: 16px;
  letter-spacing: 2px;
}

/* Empty state */
.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px var(--pad);
}
.empty .illo {
  width: 120px; height: 120px;
  border-radius: 50%;
  background: var(--bg-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 22px;
  color: var(--ink-2);
}
.empty h2 { margin: 0 0 8px; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.empty p { margin: 0 0 24px; color: var(--ink-2); font-size: 14px; max-width: 280px; }
.btn-ghost {
  height: 54px;
  padding: 0 28px;
  border-radius: var(--radius-pill);
  background: var(--bg);
  color: var(--ink);
  border: 1.5px solid var(--ink);
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: transform 120ms var(--tap), background 120ms var(--tap);
}
.btn-ghost:active { transform: scale(0.98); background: var(--bg-soft); }

/* Loading spinner */
.loading-box {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 0;
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Validity period badge */
.validity-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--bg-soft);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 16px;
}
