:root {
  --bg: #f4f6f9; --card: #ffffff; --fg: #1b1d22; --muted: #5f6672; --line: #e2e5ea;
  --accent: #0b6bcb; --chip: #eef2f7;
  --early: #2563eb; --ontime: #16a34a; --late: #ea8a0c; --verylate: #dc2626; --unknown: #8a919c;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121418; --card: #1c1f24; --fg: #e8eaee; --muted: #a3aab5; --line: #333841;
    --accent: #5aa7ff; --chip: #2a2f37; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121418; --card: #1c1f24; --fg: #e8eaee; --muted: #a3aab5; --line: #333841;
  --accent: #5aa7ff; --chip: #2a2f37; color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--fg);
       font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.wrap { max-width: 1000px; margin: 0 auto; padding: 12px 16px 32px; }
.top { display: flex; justify-content: space-between; align-items: center; }
.top h1 { font-size: 19px; display: flex; gap: 8px; align-items: center; margin: 4px 0 12px; }
a, .link { color: var(--accent); }
.card { background: var(--card); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.row { display: flex; gap: 8px; margin-top: 10px; }
.row input, .row select { flex: 1; min-width: 0; }
input, select { font: inherit; color: var(--fg); background: var(--card); border: 1px solid var(--line);
                border-radius: 8px; padding: 8px 10px; }
.btn { font: inherit; font-weight: 600; color: #fff; background: var(--accent); border: 0; border-radius: 8px;
       padding: 8px 14px; cursor: pointer; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn { color: #0b1f3a; } }
:root[data-theme="dark"] .btn { color: #0b1f3a; }
.seg { display: inline-flex; background: var(--chip); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 14px;
              padding: 6px 12px; border-radius: 7px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--fg); font-weight: 600; }
.hint { color: var(--muted); font-size: 14px; }
.hint:empty { display: none; }
.foot { color: var(--muted); font-size: 12px; margin-top: 16px; }
.choices { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 4px; }
.choices a { display: block; padding: 8px 10px; background: var(--chip); border-radius: 8px; text-decoration: none;
             color: var(--fg); }
.choices small { color: var(--muted); }

.head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 10px; }
.head h2 { font-size: 24px; margin: 0; font-weight: 800; }
.head .sub { color: var(--muted); }
.tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
         margin-bottom: 10px; }
.datepick { display: inline-flex; align-items: center; gap: 4px; }
.datepick button { font: inherit; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 8px;
                   background: var(--card); color: var(--fg); cursor: pointer; }
.datepick button:disabled { opacity: .35; cursor: default; }

/* Aikajana */
.tl-scroll { overflow-x: auto; }
.tl { position: relative; min-width: 640px; }
.tl-axis, .tl-row { display: grid; grid-template-columns: 62px 1fr; align-items: center; }
.tl-axis { height: 20px; color: var(--muted); font-size: 11.5px; }
.tl-row { border-top: 1px solid var(--line); min-height: 30px; }
.tl-label { position: sticky; left: 0; z-index: 2; background: var(--card); font-weight: 700; font-size: 13.5px;
            padding-right: 6px; }
.tl-track { position: relative; height: 30px; }
.tl-axis .tl-track { height: 20px; }
.tick { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--line); }
.tick span { position: absolute; top: 2px; left: 3px; }
.tl-row .tick { opacity: .6; }
.bar { position: absolute; top: 5px; height: 20px; min-width: 4px; border: 0; padding: 0 4px; border-radius: 5px;
       color: #fff; font: 600 11.5px/20px system-ui, sans-serif; overflow: hidden; white-space: nowrap;
       text-align: left; cursor: pointer; }
.bar[aria-pressed="true"] { outline: 2px solid var(--fg); outline-offset: 1px; z-index: 1; }
.c-early { background: var(--early); }
.c-ontime { background: var(--ontime); }
.c-late { background: var(--late); }
.c-verylate { background: var(--verylate); }
.c-unknown { background: var(--unknown); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 12.5px; margin-top: 10px; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* Lähdön tiedot */
.detail h3, .card h3 { margin: 0 0 6px; font-size: 16px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 8px 0; }
.fact { background: var(--chip); border-radius: 8px; padding: 6px 10px; }
.fact small { display: block; color: var(--muted); font-size: 12px; }
.fact b { font-size: 17px; font-variant-numeric: tabular-nums; }
.actions { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 14px; }

/* Kierto */
.chain { list-style: none; margin: 0; padding: 0; }
.leg { display: grid; grid-template-columns: 46px 1fr auto; gap: 2px 10px; align-items: center; padding: 8px 0; }
.leg .time { font-weight: 700; font-variant-numeric: tabular-nums; }
.leg .what small { display: block; color: var(--muted); font-size: 12.5px; }
.gap { margin-left: 22px; padding: 2px 0 2px 34px; border-left: 2px dashed var(--line); color: var(--muted);
       font-size: 13px; }
.gap b { color: var(--fg); }
.gap .carry { color: var(--late); font-weight: 600; display: block; }
.pill { display: inline-block; color: #fff; border-radius: 6px; padding: 1px 7px; font-size: 12.5px; font-weight: 700;
        font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Lista */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12.5px; padding: 4px 8px; white-space: nowrap; }
td { padding: 6px 8px; border-top: 1px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
td.wrap-text { white-space: normal; min-width: 120px; }
tr.stale td { color: var(--muted); }
.live { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--ontime); margin-right: 6px; }

/* Lähdön vertailu */
.strip { display: flex; flex-wrap: wrap; gap: 3px; margin: 8px 0 2px; }
.strip a, .strip span { width: 18px; height: 26px; border-radius: 4px; display: block; }
.strip .none { background: var(--chip); }
.meter { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--chip); margin: 6px 0; }
.meter i { display: block; }

@media (max-width: 520px) {
  .head h2 { font-size: 21px; }
  .leg { grid-template-columns: 44px 1fr; }
  .leg .pills { grid-column: 2; }
}
