:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #17211f;
  --muted: #5d6b68;
  --line: #dbe2e0;
  --brand: #0f5c4d;
  --brand-ink: #ffffff;
  --brand-soft: #dcefe9;
  --tight: #c2410c;
  --tight-bg: #fde7dc;
  --ok: #a16207;
  --ok-bg: #fdf3d3;
  --easy: #15803d;
  --easy-bg: #dcf5e4;
  --hidden: #4338ca;
  --hidden-bg: #e5e7ff;
  --ride-national: #0f5c4d;
  --ride-regional: #3f8f7e;
  --ride-bus: #8b6b2e;
  --ride-other: #5b6b8a;
  --delay: #b91c1c;
  --shadow: 0 1px 2px rgb(16 24 22 / 6%), 0 4px 14px rgb(16 24 22 / 5%);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1514; --surface: #172120; --surface-2: #1f2b29; --text: #e5ecea; --muted: #97a7a3;
    --line: #2c3b38; --brand: #3fb59a; --brand-ink: #062a22; --brand-soft: #18352f;
    --tight: #fb923c; --tight-bg: #3b2114; --ok: #facc15; --ok-bg: #352d10; --easy: #4ade80; --easy-bg: #13321f;
    --hidden: #a5b4fc; --hidden-bg: #23264a;
    --ride-national: #3fb59a; --ride-regional: #2f7d6c; --ride-bus: #a98a4c; --ride-other: #7286ad; --delay: #f87171;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1514; --surface: #172120; --surface-2: #1f2b29; --text: #e5ecea; --muted: #97a7a3;
  --line: #2c3b38; --brand: #3fb59a; --brand-ink: #062a22; --brand-soft: #18352f;
  --tight: #fb923c; --tight-bg: #3b2114; --ok: #facc15; --ok-bg: #352d10; --easy: #4ade80; --easy-bg: #13321f;
  --hidden: #a5b4fc; --hidden-bg: #23264a;
  --ride-national: #3fb59a; --ride-regional: #2f7d6c; --ride-bus: #a98a4c; --ride-other: #7286ad; --delay: #f87171;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); font-weight: 400; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.top { background: var(--brand); color: var(--brand-ink); }
.top-inner { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding-top: 14px; padding-bottom: 14px; }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 700; font-size: 20px; }
.brand svg { width: 30px; height: 30px; }
.tag { opacity: .85; font-size: 14px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

.search { margin-top: 18px; padding: 18px; display: grid; gap: 14px; }
.route { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: end; }
.field { display: grid; gap: 4px; position: relative; min-width: 0; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); min-height: 46px;
}
.field input:focus, .field select:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; background: var(--surface); }
.station input.chosen { background: var(--surface); border-color: var(--brand); }
.swap {
  width: 44px; height: 46px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; color: var(--brand);
}
.swap svg { width: 22px; height: 22px; transform: rotate(90deg); }

.suggest {
  position: absolute; z-index: 20; top: 100%; left: 0; right: 0; margin: 4px 0 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgb(0 0 0 / 14%);
  max-height: 320px; overflow: auto;
}
.suggest li { padding: 9px 10px; border-radius: 7px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.suggest li[aria-selected="true"], .suggest li:hover { background: var(--brand-soft); }
.suggest li small { color: var(--muted); }

.when { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.when .field.small { flex: 1 1 130px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; height: 46px; }
.seg label { display: flex; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { padding: 0 14px; display: grid; place-items: center; cursor: pointer; background: var(--surface-2); }
.seg input:checked + span { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: -3px; }
.link-btn { background: none; border: 0; color: var(--brand); font-weight: 600; padding: 10px 4px; text-decoration: none; }
.link-btn:hover { text-decoration: underline; }

.more summary { cursor: pointer; color: var(--brand); font-weight: 600; width: fit-content; }
.more-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; margin-top: 12px; align-items: end; }
.check { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }

.primary {
  background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 10px; padding: 14px 18px;
  font-weight: 700; font-size: 17px;
}
.primary:disabled { opacity: .6; cursor: progress; }
.secondary { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 11px 16px; font-weight: 600; }

.recent { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 14px; }
.recent button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 5px 11px; }

#results { margin-top: 18px; }
.toolbar { padding: 12px 14px; display: grid; gap: 10px; position: sticky; top: 0; z-index: 10; }
.tb-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.tb-label { font-size: 13px; font-weight: 600; color: var(--muted); min-width: 170px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 6px 12px; font-size: 14px; }
.chip[aria-checked="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.chip .n { opacity: .7; font-size: 12px; margin-left: 4px; }

.summary { margin: 14px 2px 8px; color: var(--muted); font-size: 14px; }
.summary b { color: var(--text); }

.highlights { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; margin-bottom: 12px; }
.hl { text-align: left; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); display: grid; gap: 2px; }
.hl:hover { border-color: var(--brand); }
.hl .k { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
.hl .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.hl .s { font-size: 13px; color: var(--muted); }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.day-sep { font-weight: 700; color: var(--muted); font-size: 14px; margin: 8px 2px 0; }
.journey.flash { outline: 3px solid var(--brand); }
.journey.cancelled { opacity: .6; }
.j-head { width: 100%; text-align: left; background: none; border: 0; padding: 14px 16px; display: grid; gap: 8px; border-radius: var(--radius); }
.j-head:focus-visible { outline: 2px solid var(--brand); }
.j-times { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.j-times .t { font-size: 22px; font-weight: 700; }
.j-times .arrow { color: var(--muted); }
.j-times .dur { margin-left: auto; color: var(--muted); font-weight: 600; }
.delay { color: var(--delay); font-size: 14px; font-weight: 700; margin-left: 2px; }
.j-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 14px; }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.risk-tight { background: var(--tight-bg); color: var(--tight); }
.risk-ok { background: var(--ok-bg); color: var(--ok); }
.risk-easy { background: var(--easy-bg); color: var(--easy); }
.hidden-tag { background: var(--hidden-bg); color: var(--hidden); }
.pill.line { background: var(--brand-soft); color: var(--text); }
.pill.bad { background: var(--tight-bg); color: var(--delay); }

.timeline { position: relative; height: 22px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.timeline .seg-r, .timeline .seg-w { position: absolute; top: 0; bottom: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; overflow: hidden; white-space: nowrap; }
.timeline .seg-r { background: var(--ride-national); color: #fff; border-radius: 4px; }
.timeline .seg-r.regional { background: var(--ride-regional); }
.timeline .seg-r.bus { background: var(--ride-bus); }
.timeline .seg-r.other { background: var(--ride-other); }
.timeline .seg-w { color: var(--muted); background: repeating-linear-gradient(135deg, transparent 0 4px, var(--line) 4px 6px); }
.timeline .seg-w.tight { color: var(--tight); }

.j-body { border-top: 1px solid var(--line); padding: 6px 16px 16px; }
.leg { display: grid; grid-template-columns: 56px 18px 1fr; column-gap: 8px; }
.leg .tm { font-weight: 700; font-variant-numeric: tabular-nums; padding-top: 10px; }
.leg .rail { position: relative; }
.leg .rail::before { content: ""; position: absolute; left: 7px; top: 16px; bottom: -4px; width: 4px; border-radius: 2px; background: var(--ride-national); }
.leg .rail::after { content: ""; position: absolute; left: 3px; top: 12px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 3px solid var(--ride-national); }
.leg.end .rail::before { display: none; }
.leg .st { padding: 8px 0; min-width: 0; }
.leg .st .name { font-weight: 600; }
.leg .st .sub { color: var(--muted); font-size: 14px; }
.leg .train { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 4px 0; font-size: 14px; }
.stops-btn { background: none; border: 0; color: var(--brand); font-size: 14px; padding: 2px 0; font-weight: 600; }
.stops { list-style: none; margin: 4px 0 0; padding: 0; font-size: 14px; color: var(--muted); }
.stops li { display: flex; gap: 10px; padding: 1px 0; }
.stops li span:first-child { width: 42px; font-variant-numeric: tabular-nums; }

.change { margin: 6px 0 6px 74px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); display: grid; gap: 6px; font-size: 14px; }
.change .ch-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.change .fallback-btn { justify-self: start; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; color: var(--brand); font-weight: 600; font-size: 13px; background: var(--surface); }
.fallback { display: grid; gap: 4px; }
.fallback .fb { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 4px 0; border-top: 1px dashed var(--line); font-variant-numeric: tabular-nums; }

.list-foot { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin: 14px 0 0; }
.status { margin: 18px 0; padding: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); text-align: center; }
.status.err { border-color: var(--tight); color: var(--tight); }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

.info { margin: 22px 0 40px; padding: 16px 18px; font-size: 15px; }
.info h2 { margin: 0 0 6px; font-size: 18px; }
.info ul { padding-left: 18px; }
.info li { margin: 6px 0; }

@media (max-width: 620px) {
  .route { grid-template-columns: 1fr; }
  .swap { justify-self: end; margin: -6px 0 -6px; height: 36px; width: 40px; }
  .swap svg { transform: none; }
  .more-grid { grid-template-columns: 1fr; }
  .tb-label { min-width: 0; width: 100%; }
  .toolbar { position: static; }
  .j-times .t { font-size: 20px; }
  .change { margin-left: 0; }
  .leg { grid-template-columns: 48px 18px 1fr; }
}
