:root {
  --bg: #f5f7fa;
  --card: #fff;
  --text: #1a202c;
  --muted: #667085;
  --border: #dde3ea;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12161c; --card: #1b212a; --text: #e6e9ee; --muted: #9aa4b2; --border: #2c3542; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
/* Dark departure-board header with the logo; a stripe in the selected line's color sits under it. */
.top { background: #161616; border-bottom: 4px solid var(--accent); padding: 10px 16px; }
.top h1 { display: flex; justify-content: center; margin: 0 auto; max-width: 760px; font-size: 1rem; line-height: 1; }
.top .mtt-logo { font-size: 9px; }
main { max-width: 760px; margin: 0 auto; padding: 16px; }
.picker, .results { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
select { display: block; width: 100%; height: 44px; margin-top: 4px; padding: 0 10px; font-size: 1rem; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }
.when { display: flex; align-items: flex-end; gap: 12px; margin-top: 12px; }
.when label { flex: 1 1 0; min-width: 0; } /* min-width: 0 lets the date field shrink; Safari gives it a wide built-in minimum otherwise */
/* iPhone Safari draws date fields with its own size, centering and height, so drop its styling and size the field explicitly. */
.when input[type="date"] { display: block; width: 100%; min-width: 0; height: 44px; margin-top: 4px; padding: 0 10px; box-sizing: border-box; -webkit-appearance: none; appearance: none; font: inherit; font-size: 1rem; line-height: 42px; text-align: left; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color-scheme: light dark; }
/* Safari puts the date text in an inner element at the top of a fixed-height field. A line height equal to the field's
   inner height (44px minus its 2px of border) makes that element fill the field, so the text sits in the middle. */
.when input[type="date"]::-webkit-date-and-time-value { min-height: 1.2em; margin: 0; text-align: left; line-height: inherit; }
/* iPhone and iPad only (-webkit-touch-callout exists only there): also center the text with flex, a second way to
   get the same result in case Safari ignores the line height. Desktop browsers are left alone. */
@supports (-webkit-touch-callout: none) {
  .when input[type="date"] { display: flex; align-items: center; justify-content: flex-start; }
}
.today-link { display: flex; flex: none; align-items: center; height: 44px; padding: 0 14px; border: 1px solid var(--border); border-radius: 8px; font-size: .9rem; font-weight: 600; text-decoration: none; white-space: nowrap; }
.today-link:hover { background: var(--bg); }
/* On the narrowest phones the date and button would squeeze each other, so stack them. */
@media (max-width: 360px) {
  .when { flex-direction: column; align-items: stretch; gap: 8px; }
  .today-link { justify-content: center; }
}
.stations { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: end; margin-top: 12px; }
.swap { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: var(--accent-text); text-decoration: none; font-size: 1.3rem; }
.swap.off { background: var(--border); color: var(--muted); }
.swap:hover { filter: brightness(1.1); }
/* Find a station: a collapsed card above the pickers that opens with the results. */
.finder { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 0 16px; margin-bottom: 16px; }
.finder summary { display: flex; align-items: center; min-height: 48px; font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; cursor: pointer; list-style: none; }
.finder summary::-webkit-details-marker { display: none; }
.finder summary::after { content: ""; width: 8px; height: 8px; margin-left: auto; border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(45deg); transition: transform .15s; }
.finder[open] summary::after { transform: rotate(-135deg); }
.finder[open] { padding-bottom: 16px; }
.finder-row { display: flex; gap: 8px; }
.finder-row input[type="search"] { flex: 1 1 0; min-width: 0; height: 44px; padding: 0 10px; box-sizing: border-box; -webkit-appearance: none; appearance: none; font: inherit; font-size: 1rem; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }
.finder-row button { flex: none; height: 44px; padding: 0 16px; font: inherit; font-size: .95rem; font-weight: 600; color: var(--accent-text); background: var(--accent); border: 0; border-radius: 8px; cursor: pointer; }
.found { list-style: none; margin: 12px 0 0; padding: 0; border-top: 1px solid var(--border); }
.found li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.found-name { display: block; margin-bottom: 4px; }
.found-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 4px 0; }
.found-chip { flex: none; min-width: 3.4em; padding: 2px 8px; border-radius: 6px; font-size: .8rem; font-weight: 700; text-align: center; }
.found-long { flex: 1 1 60%; min-width: 0; font-size: .9rem; color: var(--muted); }
/* On a phone the two buttons share the row under the chip and line name; on wider screens everything fits on one row. */
.found-pick { flex: 1 1 40%; display: flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; font-size: .9rem; font-weight: 600; text-decoration: none; }
.found-pick:hover { background: var(--bg); }
@media (min-width: 560px) {
  .found-long { flex-basis: 8em; }
  .found-pick { flex: none; min-height: 36px; }
}
.results h2 { margin: 0; font-size: 1.1rem; }
.arrow { color: var(--muted); }
.sub { margin: 4px 0 12px; color: var(--muted); font-size: .9rem; }
a { color: inherit; }
small { color: var(--muted); font-weight: 400; }

/* Train list: one expandable row per train */
.trains { border-top: 1px solid var(--border); }
.train { border-bottom: 1px solid var(--border); }
.train.gone { display: none; }
.train.past { opacity: .5; }
.train.next { background: color-mix(in srgb, var(--accent) 14%, transparent); box-shadow: inset 4px 0 0 var(--accent); }
.train.canceled .c-times, .train.canceled .c-info { text-decoration: line-through; opacity: .6; }
.train summary { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) auto 14px; grid-template-areas: "times info right chev";
  gap: 4px 12px; align-items: center; padding: 10px 6px 10px 14px; cursor: pointer; list-style: none; }
.train summary::-webkit-details-marker { display: none; }
.train summary::after { grid-area: chev; content: ""; width: 8px; height: 8px; border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(45deg); transition: transform .15s; justify-self: center; }
.train[open] summary::after { transform: rotate(-135deg); }
.train summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.c-times { grid-area: times; display: flex; flex-direction: column; }
.c-times .dep { font-size: 1.05rem; white-space: nowrap; }
.c-times .arr { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.c-times .exp { color: #b45309; font-size: .8rem; font-weight: 600; }
.c-info { grid-area: info; display: flex; flex-direction: column; }
.muted { color: var(--muted); font-size: .85rem; }
.c-title { display: flex; align-items: center; gap: 8px; }
.tag-express { padding: 1px 7px; border-radius: 4px; font-size: .7rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; background: var(--accent); color: var(--accent-text); }
.c-right { grid-area: right; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; background: color-mix(in srgb, var(--muted) 18%, transparent); color: var(--muted); }
.b-ontime { background: color-mix(in srgb, #16a34a 20%, transparent); color: #15803d; }
.b-late { background: color-mix(in srgb, #d97706 22%, transparent); color: #b45309; }
.b-verylate { background: color-mix(in srgb, #dc2626 20%, transparent); color: #b91c1c; }
.b-canceled { background: #dc2626; color: #fff; }
.b-added { background: color-mix(in srgb, #2563eb 20%, transparent); color: #1d4ed8; }
.b-atstation { background: #2563eb; color: #fff; }
@media (prefers-color-scheme: dark) {
  .b-ontime { color: #4ade80; } .b-late { color: #fbbf24; } .b-verylate { color: #f87171; } .b-added { color: #93c5fd; }
  .c-times .exp { color: #fbbf24; }
}
.live { font-size: .7rem; font-weight: 600; color: #15803d; margin-left: 6px; }
.c-right .badge + .live { margin: 0; }
.cd { min-height: 1.2em; font-size: .85rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--muted); }
.cd-soon { color: #b45309; }
.cd-urgent { color: #b91c1c; font-size: .95rem; }
.cd-now { color: #15803d; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .cd-now { animation: none; } }
.stops { list-style: none; margin: 2px 0 4px 24px; padding: 0 0 0 16px; border-left: 3px solid var(--accent); }
.stops li { position: relative; display: flex; justify-content: space-between; gap: 12px; padding: 5px 14px 5px 0; font-size: .92rem; }
.stops li::before { content: ""; position: absolute; left: -24px; top: 50%; width: 12px; height: 12px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; background: var(--card); border: 2px solid var(--accent); }
.stops li.end { font-weight: 700; }
.stops li.end::before { background: var(--accent); }
.stops time { color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stops-note { margin: 0; padding: 0 14px 12px 24px; font-size: .78rem; color: var(--muted); }
.results .sub:last-child { margin-bottom: 0; }
.stops li.passed { color: var(--muted); }
.stops li.passed::before { background: var(--accent); }
.stops li.next { font-weight: 700; }
.stops li.next::before { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.stops li.here::before { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }

/* Tabs: Schedule / In motion */
.tabs { display: flex; gap: 2px; margin: 12px 0 14px; border-bottom: 1px solid var(--border); }
.tab { appearance: none; background: none; border: 0; border-bottom: 3px solid transparent; margin-bottom: -1px; padding: 8px 10px; font: inherit; font-weight: 600; color: var(--muted); white-space: nowrap; cursor: pointer; }
@media (max-width: 400px) { .tab { padding: 8px 7px; font-size: .92rem; } }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.count:not(:empty) { display: inline-block; min-width: 1.5em; margin-left: 4px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-text); font-size: .75rem; line-height: 1.5; text-align: center; }

/* Service alerts */
.alerts { margin-bottom: 16px; }
.alerts-box { border: 1px solid color-mix(in srgb, #d97706 45%, var(--border)); border-radius: 10px; background: color-mix(in srgb, #d97706 11%, var(--card)); }
.alerts-box.severe { border-color: color-mix(in srgb, #dc2626 45%, var(--border)); background: color-mix(in srgb, #dc2626 9%, var(--card)); }
.alerts-box > summary { padding: 10px 14px; font-weight: 700; cursor: pointer; list-style: none; }
.alerts-box > summary::-webkit-details-marker { display: none; }
.alerts-box > summary::after { content: " \25be"; color: var(--muted); }
.alerts-box[open] > summary::after { content: " \25b4"; }
.alerts-box > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 10px; }
.alert { padding: 10px 14px; border-top: 1px solid var(--border); }
.alert-title { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.alert-text { margin: 4px 0 6px; font-size: .9rem; white-space: pre-line; }
.alert a { font-size: .85rem; }
.alerts-note { margin: 0; padding: 8px 14px; font-size: .78rem; color: var(--muted); border-top: 1px solid var(--border); }
#fav-alerts { margin-bottom: 12px; }

/* Favorite star: sits beside the train number in lists and cards */
.fav { appearance: none; background: none; border: 0; padding: 0 4px; margin: 0; font: inherit; font-size: 1.15rem; line-height: 1; color: var(--muted); cursor: pointer; }
.fav[aria-pressed="true"] { color: #d97706; }
.fav:hover { color: #d97706; }
.fav:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* In-motion and favorite cards */
.mt-route { margin-top: 4px; font-size: .85rem; color: var(--muted); }
.chip { display: inline-block; padding: 0 7px; border-radius: 4px; font-size: .72rem; font-weight: 700; background: var(--accent); color: var(--accent-text); vertical-align: 1px; }
.mt-card.canceled .mt-bar { opacity: .35; }
.mt-missing { opacity: .8; }
.mt-none { margin: 8px 0 0; font-size: .9rem; color: var(--muted); }
.mt-facts div[hidden] { display: none; }
.mt-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }
.mt-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px; }
.mt-badges { display: flex; align-items: center; gap: 8px; }
.mt-src { font-size: .72rem; font-weight: 600; color: var(--muted); }
.mt-src.live { color: #15803d; }
.mt-bar { position: relative; height: 22px; margin: 14px 10px 2px; }
.mt-track { position: absolute; left: 0; right: 0; top: 9px; height: 4px; border-radius: 2px; background: var(--border); }
.mt-fill { width: 0; height: 100%; border-radius: 2px; background: var(--accent); }
.mt-tick { position: absolute; top: 7px; width: 8px; height: 8px; margin-left: -4px; box-sizing: border-box; border-radius: 50%; background: var(--card); border: 2px solid var(--border); }
.mt-tick.passed { background: var(--accent); border-color: var(--accent); }
.mt-tick.next { border-color: var(--accent); }
.mt-train { position: absolute; top: 0; display: flex; align-items: center; justify-content: center; width: 22px; height: 22px; margin-left: -11px; border-radius: 50%; background: var(--accent); color: var(--accent-text); border: 2px solid var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, .45); font-size: 10px; line-height: 1; }
.mt-ends { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; font-size: .75rem; color: var(--muted); }
.mt-facts { display: grid; gap: 4px; margin: 0; }
.mt-facts div { display: grid; grid-template-columns: 5.2rem 1fr; gap: 8px; font-size: .9rem; }
.mt-facts dt { color: var(--muted); }
.mt-facts dd { margin: 0; font-weight: 600; }
.mt-more { margin-top: 6px; }
.mt-more summary { padding: 4px 0; font-size: .85rem; color: var(--muted); cursor: pointer; }
.mapcard { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.mapcard h2 { margin: 0 0 10px; font-size: 1.1rem; }
.mapcard .sub { margin: 10px 0 0; }
#map { height: 380px; border-radius: 8px; z-index: 0; }
.train-icon { background: none; border: 0; }
.train-dot { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--accent); color: var(--accent-text); border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .55); font-size: 13px; line-height: 1; }
.train-dot span { display: block; }
.train-dot.faded { opacity: .55; filter: grayscale(.6); }
.notice { background: var(--card); border: 1px dashed var(--border); border-radius: 10px; padding: 14px 16px; color: var(--muted); }
.admin-link { margin-left: 8px; font-size: .72rem; opacity: .7; }
footer { max-width: 760px; margin: 0 auto; padding: 0 16px 24px; color: var(--muted); font-size: .8rem; }
@media (max-width: 560px) {
  .stations { grid-template-columns: 1fr; }
  .swap { justify-self: center; transform: rotate(90deg); }
  .train summary { grid-template-columns: minmax(0, 1fr) auto 14px; grid-template-areas: "times right chev" "info info chev"; }
}
