:root {
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --fill: rgba(118,118,128,0.12);
  --fill-strong: #F2F2F7;
  --text: #1C1C1E;
  --text-2: #6E6E73;
  --text-3: #8E8E93;
  --sep: rgba(60,60,67,0.12);
  --accent: #0A5BD6;
  --accent-tint: rgba(10,91,214,0.10);
  --accent-on: #FFFFFF;
  --to: #F2542D;
  --ok: #18803A;
  --late: #D12F3A;
  --late-tint: #FDE7E8;
  --late-on-tint: #B3202B;
  --warn: #B35200;
  --warn-tint: #FFF1E0;
  --seg-on: #FFFFFF;
  --bar: rgba(242,242,247,0.78);
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.06);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --skeleton: rgba(118,118,128,0.14);

  --p-ice: #D12F3A; --p-ic: #A8326E; --p-re: #1F63D6; --p-s: #0F7A37;
  --p-u: #3B4CC0; --p-tram: #B35200; --p-bus: #7B3FD0; --p-ferry: #0B7285; --p-other: #5B5B66;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --ease: cubic-bezier(.2,.8,.2,1);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1C1C1E;
    --fill: rgba(118,118,128,0.24);
    --fill-strong: #2C2C2E;
    --text: #F5F5F7;
    --text-2: #98989F;
    --text-3: #8E8E93;
    --sep: rgba(255,255,255,0.08);
    --accent: #4C8DFF;
    --accent-tint: rgba(76,141,255,0.16);
    --accent-on: #0B0B0F;
    --to: #FF6A45;
    --ok: #32D74B;
    --late: #FF6B6B;
    --late-tint: rgba(255,107,107,0.18);
    --late-on-tint: #FF8A8A;
    --warn: #FFB340;
    --warn-tint: rgba(255,179,64,0.16);
    --seg-on: #636366;
    --bar: rgba(28,28,30,0.72);
    --shadow: 0 0 0 1px rgba(255,255,255,0.06);
    --shadow-sm: none;
    --skeleton: rgba(118,118,128,0.22);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg.ico { width: 15px; height: 15px; flex: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
a { color: var(--accent); }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 0 calc(24px + env(safe-area-inset-bottom));
}

/* Header */
.top { display: flex; align-items: center; justify-content: space-between; padding: 22px 20px 14px; }
.brand { display: flex; align-items: center; gap: 6px; }
.brand h1 { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -0.8px; }
.bolt { width: 22px; height: 22px; color: var(--accent); }
.today { font-size: 13px; color: var(--text-2); }

/* Route card */
.route { position: relative; margin: 0 16px; background: var(--card); border-radius: 22px; box-shadow: var(--shadow); }
.field { width: 100%; display: flex; align-items: center; gap: 14px; padding: 14px 72px 14px 18px; min-height: 64px; border-radius: 22px; transition: background .15s; }
.field:active { background: var(--fill); }
.field-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.field-label { font-size: 12px; color: var(--text-2); }
.field-value { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field-value.empty { color: var(--text-3); font-weight: 500; }
.mark { width: 12px; height: 12px; flex: none; }
.mark-from { border-radius: 50%; border: 3px solid var(--accent); }
.mark-to { border-radius: 4px; background: var(--to); }
.hairline { height: 1px; margin-left: 44px; background: var(--sep); }
.swap {
  position: absolute; right: 14px; top: 50%; margin-top: -22px;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--fill-strong); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  transition: transform .35s var(--ease);
}
.swap svg { width: 20px; height: 20px; }
.swap.spin { transform: rotate(180deg); }
.swap:active { scale: .92; }

/* Departure segmented control */
.when { display: flex; margin: 12px 16px 0; }
.segmented { display: flex; padding: 2px; background: var(--fill); border-radius: 10px; }
.segmented button {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 16px; min-height: 36px; border-radius: 8px;
  font-size: 14px; color: var(--text-2);
  transition: background .2s, box-shadow .2s, color .2s;
}
.segmented button[aria-pressed="true"] { background: var(--seg-on); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.12); }

/* Results */
.results { padding: 0 16px; }
.results-head { display: flex; align-items: center; justify-content: space-between; margin: 22px 4px 8px; min-height: 32px; }
.results-title { font-size: 13px; font-weight: 600; color: var(--text-2); letter-spacing: 0.2px; }
.text-btn { display: flex; align-items: center; gap: 4px; font-size: 15px; font-weight: 500; color: var(--accent); min-height: 36px; padding: 0 4px; }
.text-btn svg { width: 14px; height: 14px; }
.text-btn:disabled { opacity: .5; cursor: default; }
.list { display: flex; flex-direction: column; gap: 10px; }

.conn { background: var(--card); border-radius: 20px; box-shadow: var(--shadow-sm); animation: rise .35s var(--ease) both; transition: border-radius .25s var(--ease); }
.conn.open { border-radius: 22px; box-shadow: var(--shadow); }
.conn-sum { width: 100%; display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; border-radius: inherit; }
.conn-sum:active { background: var(--fill); }
.row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.row.mid { align-items: center; }
.times { display: flex; align-items: baseline; gap: 6px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.t { font-size: 21px; font-weight: 700; letter-spacing: -0.3px; }
.dash { font-size: 17px; color: var(--text-3); margin: 0 2px; }
.d { font-size: 13px; font-weight: 700; color: var(--late); }
.dur { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; text-align: right; flex: none; }
.dur b { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.sub { font-size: 13px; color: var(--text-2); }
.ok { color: var(--ok); font-weight: 600; }
.changed { color: var(--late); font-weight: 600; }
.lines { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; min-width: 0; }
.lines svg { width: 12px; height: 12px; color: var(--text-3); }
.pill { display: inline-block; padding: 3px 8px; border-radius: 7px; color: #fff; font-size: 13px; font-weight: 700; white-space: nowrap; background: var(--p-other); }
.pill.sm { padding: 1px 5px; border-radius: 5px; font-size: 11px; }
.p-ice { background: var(--p-ice); } .p-ic { background: var(--p-ic); } .p-re { background: var(--p-re); }
.p-s { background: var(--p-s); } .p-u { background: var(--p-u); } .p-tram { background: var(--p-tram); }
.p-bus { background: var(--p-bus); } .p-ferry { background: var(--p-ferry); }
.c-ice { --line: var(--p-ice); } .c-ic { --line: var(--p-ic); } .c-re { --line: var(--p-re); } .c-s { --line: var(--p-s); }
.c-u { --line: var(--p-u); } .c-tram { --line: var(--p-tram); } .c-bus { --line: var(--p-bus); } .c-ferry { --line: var(--p-ferry); } .c-other { --line: var(--p-other); }
.badge-cancel { padding: 3px 8px; border-radius: 7px; background: var(--late-tint); color: var(--late-on-tint); font-size: 12px; font-weight: 700; flex: none; }
.conn.cancelled .times { color: var(--text-3); }
.conn.cancelled .t { text-decoration: line-through; }
.conn.cancelled .lines { opacity: .55; }

/* Expanded legs */
.conn-more { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .3s var(--ease); }
.conn.open .conn-more { grid-template-rows: 1fr; }
.conn-more > div { overflow: hidden; }
.legs { border-top: 1px solid var(--sep); margin: 0 16px; padding: 14px 0 16px; }
.leg { display: grid; grid-template-columns: 52px 18px minmax(0, 1fr); column-gap: 10px; }
.leg .tm { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.leg .tm .d { font-size: 12px; margin-left: 2px; }
.leg .st { display: flex; justify-content: space-between; gap: 8px; min-width: 0; }
.leg .st b { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.leg .pl { font-size: 13px; color: var(--text-2); white-space: nowrap; }
.node { display: flex; justify-content: center; padding-top: 3px; }
.node i { width: 12px; height: 12px; border-radius: 50%; border: 3px solid var(--line); background: var(--card); }
.node i.end { border: 0; border-radius: 3px; background: var(--line); }
.track { display: flex; justify-content: center; }
.track i { width: 4px; background: var(--line); border-radius: 2px; }
.leg-info { display: flex; flex-direction: column; gap: 4px; padding: 10px 0 14px; min-width: 0; }
.leg-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.status { font-size: 12px; font-weight: 600; padding-top: 12px; }
.leg.cancelled .tm, .leg.cancelled .st b { text-decoration: line-through; color: var(--text-3); }
.transfer { display: flex; align-items: center; gap: 10px; margin: 12px 0; padding: 10px 12px; border-radius: 12px; background: var(--fill); font-size: 13px; }
.transfer svg { width: 16px; height: 16px; color: var(--warn); flex: none; }
.transfer.tight { background: var(--warn-tint); }
.walk { display: flex; align-items: center; gap: 8px; margin: 4px 0 10px 62px; font-size: 13px; color: var(--text-2); }
.walk svg { width: 15px; height: 15px; }

.later { width: 100%; display: flex; align-items: center; justify-content: center; gap: 6px; height: 48px; margin-top: 14px; border-radius: 16px; background: var(--accent-tint); color: var(--accent); font-size: 16px; font-weight: 600; }
.later svg { width: 14px; height: 14px; }
.later:disabled { opacity: .6; }
.inline-err { margin: 10px 4px 0; font-size: 13px; color: var(--late); text-align: center; }
.note { margin: 12px 4px 0; font-size: 12px; color: var(--text-2); text-align: center; }
.attrib { margin: 18px 0 0; text-align: center; font-size: 12px; color: var(--text-2); }

/* Skeleton */
.skel { height: 96px; border-radius: 20px; background: var(--card); padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.skel span { display: block; height: 18px; border-radius: 6px; background: var(--skeleton); animation: pulse 1.2s ease-in-out infinite; }
.skel span:first-child { width: 55%; height: 22px; }
.skel span:last-child { width: 30%; }

/* Empty / error card */
.state { margin-top: 28px; padding: 32px 24px; background: var(--card); border-radius: 22px; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; animation: rise .35s var(--ease) both; }
.state-icon { width: 56px; height: 56px; border-radius: 18px; background: var(--warn-tint); color: var(--warn); display: flex; align-items: center; justify-content: center; }
.state-icon.neutral { background: var(--accent-tint); color: var(--accent); }
.state-icon svg { width: 28px; height: 28px; }
.state h2 { margin: 4px 0 0; font-size: 19px; font-weight: 700; }
.state p { margin: 0; font-size: 15px; line-height: 1.4; color: var(--text-2); }
.primary { display: flex; align-items: center; justify-content: center; gap: 8px; height: 48px; padding: 0 24px; border-radius: 16px; background: var(--accent); color: var(--accent-on); font-size: 16px; font-weight: 600; }
.primary svg { width: 18px; height: 18px; }
.state .primary { margin-top: 8px; }
.primary:active, .later:active { scale: .98; }

/* Compact bar */
.compact {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  padding-top: env(safe-area-inset-top);
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--sep);
  transform: translateY(-110%); transition: transform .25s var(--ease);
}
.compact.show { transform: none; }
.compact-inner { width: 100%; max-width: 560px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; }
.compact-route { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 600; min-width: 0; }
.compact-route span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compact-route svg { width: 14px; height: 14px; color: var(--text-2); flex: none; }
.compact-when { font-size: 14px; color: var(--text-2); flex: none; }

/* Station picker */
.picker { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto; padding-top: env(safe-area-inset-top); animation: fade .2s ease both; }
.picker[hidden], .sheet-wrap[hidden] { display: none; }
.picker-bar { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 12px; max-width: 560px; margin: 0 auto; padding: 20px 16px 12px; background: var(--bg); }
.search-box { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 12px; background: var(--fill); border-radius: 12px; }
.search-box svg { width: 18px; height: 18px; color: var(--text-2); }
.search-box input { flex: 1; min-width: 0; border: 0; background: none; font-size: 17px; outline: none; -webkit-appearance: none; appearance: none; }
.search-box input::-webkit-search-cancel-button { display: none; }
.search-box:focus-within { outline: 2px solid var(--accent); outline-offset: 0; }
.link-btn { font-size: 17px; color: var(--accent); min-height: 44px; }
.picker-body { max-width: 560px; margin: 0 auto; padding-bottom: 40px; }
.group-label { margin: 8px 20px 8px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.group-label + .group, .group + .group-label { }
.group { list-style: none; margin: 0 16px 24px; padding: 0; background: var(--card); border-radius: 20px; overflow: hidden; }
.group li + li { border-top: 1px solid var(--sep); }
.opt { width: 100%; display: flex; align-items: center; gap: 14px; padding: 12px 16px; min-height: 58px; }
.opt:active, .opt.active { background: var(--accent-tint); }
.opt-icon { width: 34px; height: 34px; border-radius: 10px; background: var(--line, var(--p-other)); color: #fff; display: flex; align-items: center; justify-content: center; flex: none; }
.opt-icon svg { width: 18px; height: 18px; }
.opt-icon.recent { background: none; color: var(--text-2); width: 18px; height: 18px; }
.opt-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.opt-name { font-size: 17px; overflow-wrap: anywhere; }
.opt-name b { font-weight: 700; }
.prods { display: flex; gap: 4px; flex-wrap: wrap; }
.picker-msg { margin: 24px 20px; font-size: 15px; color: var(--text-2); text-align: center; }

/* Time sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 30; }
.scrim { position: absolute; inset: 0; background: rgba(0,0,0,0.4); animation: fade .25s ease both; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 560px; margin: 0 auto;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
  background: var(--card); border-radius: 28px 28px 0 0;
  display: flex; flex-direction: column; gap: 20px;
  animation: up .32s var(--ease) both;
}
@media (prefers-color-scheme: dark) { .sheet { background: rgba(36,36,38,0.92); -webkit-backdrop-filter: blur(30px); backdrop-filter: blur(30px); } }
.grabber { align-self: center; width: 36px; height: 5px; border-radius: 3px; background: var(--fill); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 20px; font-weight: 700; }
.days { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -20px; padding: 0 20px; }
.days::-webkit-scrollbar { display: none; }
.day { flex: none; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 16px; border-radius: 14px; background: var(--fill); min-width: 64px; transition: background .2s, color .2s; }
.day small { font-size: 12px; color: var(--text-2); }
.day span { font-size: 15px; font-weight: 600; }
.day[aria-pressed="true"] { background: var(--accent); color: var(--accent-on); }
.day[aria-pressed="true"] small { color: inherit; font-weight: 600; }
.stepper { display: flex; align-items: center; justify-content: space-between; padding: 8px; border-radius: 18px; background: var(--fill); }
.step { width: 52px; height: 52px; border-radius: 14px; background: var(--fill); display: flex; align-items: center; justify-content: center; }
.step svg { width: 20px; height: 20px; }
.step:active { scale: .94; }
.time-field { min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.time-field span { font-size: 12px; color: var(--text-2); }
.time-field input { border: 0; background: none; text-align: center; font-size: 40px; font-weight: 700; letter-spacing: -1px; font-variant-numeric: tabular-nums; width: 200px; max-width: 100%; padding: 0; }
.time-field input::-webkit-calendar-picker-indicator { display: none; }
.sheet .primary { height: 52px; font-size: 17px; font-weight: 700; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(100%); } }
@keyframes pulse { 50% { opacity: .5; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
