/* Bahn-Atlas
   Visual language borrowed from German station furniture: the dark-blue
   station sign, the yellow departure poster and the platform display board. */

@font-face { font-family: "Barlow"; font-weight: 400; font-display: swap; src: url("vendor/fonts/barlow-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 500; font-display: swap; src: url("vendor/fonts/barlow-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 600; font-display: swap; src: url("vendor/fonts/barlow-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 700; font-display: swap; src: url("vendor/fonts/barlow-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-weight: 500; font-display: swap; src: url("vendor/fonts/barlow-semi-condensed-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-weight: 600; font-display: swap; src: url("vendor/fonts/barlow-semi-condensed-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-weight: 700; font-display: swap; src: url("vendor/fonts/barlow-semi-condensed-latin-700-normal.woff2") format("woff2"); }

:root {
  --sign: #0b2c6b;        /* station sign blue */
  --sign-deep: #061c47;
  --fahrplan: #f7d117;    /* departure poster yellow */
  --paper: #f5f7fa;
  --white: #ffffff;
  --ink: #1b2230;
  --muted: #586174;
  --rule: #d5dbe5;
  --late: #b42318;

  /* reliability scale: good → bad */
  --s1: #1f5fa8;
  --s2: #7fa6d3;
  --s3: #f2c94c;
  --s4: #e07b26;
  --s5: #b42318;

  --display: "Barlow Semi Condensed", "Arial Narrow", sans-serif;
  --body: "Barlow", "Helvetica Neue", Arial, sans-serif;

  --step--1: 0.875rem;
  --step-0: 1.0625rem;
  --step-1: 1.3rem;
  --step-2: 1.75rem;
  --step-3: 2.5rem;
  --step-4: clamp(2.6rem, 5vw, 4rem);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--body);
  font-size: var(--step-0);
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  font-variant-numeric: tabular-nums;
}
a { color: var(--sign); }
code { font-size: 0.9em; background: rgba(11, 44, 107, 0.08); padding: 0.05em 0.3em; border-radius: 3px; }
h1, h2, h3 { font-family: var(--display); line-height: 1.1; margin: 0 0 0.5rem; }
h2 { font-size: var(--step-3); font-weight: 600; }
h3 { font-size: var(--step-1); font-weight: 600; }
:focus-visible { outline: 3px solid var(--fahrplan); outline-offset: 2px; box-shadow: 0 0 0 5px var(--sign); }

.skip { position: absolute; left: -999px; top: 0; background: var(--fahrplan); padding: 0.5rem 1rem; z-index: 2000; }
.skip:focus { left: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Demo banner: a construction-site barrier */
.demo-banner {
  background: var(--white);
  border-top: 10px solid transparent;
  border-image: repeating-linear-gradient(-45deg, var(--late) 0 14px, var(--white) 14px 28px) 10;
  padding: 0.6rem 1.5rem;
  font-size: var(--step--1);
}

/* Top bar = station sign */
.topbar {
  display: flex; align-items: center; gap: 2rem;
  background: var(--sign); color: var(--white);
  padding: 0.8rem clamp(1rem, 4vw, 3rem);
  position: sticky; top: 0; z-index: 1000;
}
.wordmark {
  font-family: var(--display); font-weight: 700; font-size: 1.5rem;
  color: var(--white); text-decoration: none;
  border: 2px solid var(--white); padding: 0.05rem 0.6rem; border-radius: 4px;
}
.topbar nav { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.topbar nav a { color: var(--white); text-decoration: none; font-weight: 500; }
.topbar nav a:hover { text-decoration: underline; text-underline-offset: 4px; }
.period { margin-left: auto; font-size: var(--step--1); opacity: 0.85; }

main { padding: 0 clamp(1rem, 4vw, 3rem); max-width: 1400px; margin: 0 auto; }

/* Hero */
.hero {
  display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: clamp(1.5rem, 4vw, 4rem); align-items: center;
  padding: clamp(2rem, 5vw, 4.5rem) 0;
}
.hero h2 { font-size: var(--step-4); font-weight: 700; max-width: 14ch; }
.lede { font-size: var(--step-1); line-height: 1.45; max-width: 36rem; margin: 0 0 1rem; }
.lede-small { color: var(--muted); max-width: 34rem; margin: 0 0 1.5rem; }
.hero-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }

.board {
  background: var(--sign-deep); color: var(--white);
  border-radius: 10px; overflow: hidden;
  border: 6px solid #2b3a55;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
}
.board-head {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: 0.9rem 1.4rem; font-family: var(--display); font-weight: 600; font-size: var(--step-1);
  border-bottom: 1px solid rgba(255,255,255,0.18);
}
.board-head span:last-child { opacity: 0.7; font-weight: 500; }
.board-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  padding: 0.85rem 1.4rem; border-bottom: 1px solid rgba(255,255,255,0.1);
}
.board-label { font-size: var(--step-1); font-weight: 500; opacity: 0.9; }
.board-value { font-family: var(--display); font-weight: 600; font-size: var(--step-3); letter-spacing: 0.02em; white-space: nowrap; }
.board-row-strong .board-label { opacity: 1; font-weight: 600; }
.board-row-strong .board-value { color: var(--fahrplan); font-size: clamp(2.6rem, 5vw, 3.6rem); }
.ticker { background: var(--fahrplan); color: var(--ink); overflow: hidden; white-space: nowrap; font-weight: 600; padding: 0.45rem 0; }
.ticker span { display: inline-block; padding-left: 100%; animation: ticker 26s linear infinite; }
@keyframes ticker { to { transform: translateX(-100%); } }

.flap.flipping { animation: flap 0.5s steps(4) 1; }
@keyframes flap { 0% { opacity: 0.2; transform: scaleY(0.2); } 100% { opacity: 1; transform: scaleY(1); } }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  font: 600 1rem var(--body); padding: 0.7rem 1.2rem; border-radius: 6px;
  border: 2px solid transparent; cursor: pointer; text-decoration: none;
}
.btn-primary { background: var(--fahrplan); color: var(--ink); border-color: var(--fahrplan); }
.btn-primary:hover { background: #ffe14d; }
.btn-dark { background: var(--ink); color: var(--white); }
.btn-dark:hover { background: var(--sign); }
.btn-quiet { background: transparent; color: var(--sign); border-color: var(--sign); }
.btn-quiet:hover { background: rgba(11,44,107,0.06); }
.btn[disabled] { opacity: 0.6; cursor: progress; }

/* Sections */
.section { scroll-margin-top: 4.5rem; padding: clamp(2rem, 5vw, 4rem) 0; border-top: 2px solid var(--ink); }
.section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 1rem; margin-bottom: 1.5rem; }
.section-head h2 { max-width: 26ch; }
.section-note { color: var(--muted); margin: 0; max-width: 40rem; }

.segmented { display: inline-flex; border: 2px solid var(--sign); border-radius: 6px; overflow: hidden; }
.segmented button { font: 600 0.95rem var(--body); padding: 0.5rem 0.9rem; border: 0; background: var(--white); color: var(--sign); cursor: pointer; }
.segmented button + button { border-left: 2px solid var(--sign); }
.segmented button[aria-checked="true"] { background: var(--sign); color: var(--white); }

/* Map */
.map-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); gap: 1.5rem; }
.map-wrap { position: relative; }
#leaflet { height: min(72vh, 680px); border: 2px solid var(--ink); border-radius: 6px; background: #e8ecf1; }
.legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 500;
  background: var(--white); border: 2px solid var(--ink); border-radius: 6px;
  padding: 0.6rem 0.8rem; font-size: var(--step--1);
}
.legend strong { display: block; margin-bottom: 0.3rem; }
.legend-row { display: flex; align-items: center; gap: 0.5rem; }
.swatch { width: 14px; height: 14px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,0.25); }

.station-panel { background: var(--white); border: 2px solid var(--ink); border-radius: 6px; padding: 1.2rem; max-height: min(72vh, 680px); overflow: auto; }
.station-panel .empty p { color: var(--muted); margin-top: 0; }
.station-panel.has-station .empty { display: none; }

.field { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 600; font-size: var(--step--1); }
.field input, .field select, .field textarea {
  font: 400 1rem var(--body); padding: 0.6rem 0.7rem; border: 2px solid var(--ink); border-radius: 6px; background: var(--white); color: var(--ink);
}
.field textarea { line-height: 1.5; resize: vertical; }
.field-inline { flex-direction: row; align-items: center; gap: 0.6rem; margin-bottom: 0.8rem; }

.st-name { font-family: var(--display); font-size: var(--step-2); font-weight: 700; margin: 1.2rem 0 0.1rem; }
.st-sub { color: var(--muted); margin: 0 0 1rem; }
.st-figures { display: grid; grid-template-columns: 1fr 1fr; gap: 0.2rem 1rem; margin: 0 0 1rem; }
.st-figures dt { color: var(--muted); font-size: var(--step--1); }
.st-figures dd { margin: 0 0 0.6rem; font-family: var(--display); font-size: var(--step-2); font-weight: 600; }
.st-figures dd.big { color: var(--sign); }
.st-rank { background: var(--paper); border-left: 4px solid var(--fahrplan); padding: 0.5rem 0.8rem; margin: 0 0 1rem; }

.heatmap { display: grid; grid-template-columns: 2.2rem repeat(24, minmax(0, 1fr)); gap: 2px; font-size: 0.7rem; margin: 0.4rem 0 0.4rem; }
.heatmap .hm-cell { aspect-ratio: 1; border-radius: 2px; background: #eef1f5; }
.heatmap .hm-label { color: var(--muted); align-self: center; }
.heatmap .hm-hour { color: var(--muted); text-align: center; }
.hm-caption { color: var(--muted); font-size: var(--step--1); margin: 0 0 1rem; }

/* Tables */
.table-wrap { overflow-x: auto; border: 2px solid var(--ink); border-radius: 6px; background: var(--white); }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.98rem; }
.data-table th {
  text-align: left; font-family: var(--display); font-weight: 600; font-size: 1rem;
  padding: 0.75rem 0.9rem; background: var(--sign); color: var(--white); cursor: pointer; user-select: none; white-space: nowrap;
}
.data-table th[aria-sort="ascending"]::after { content: " ▲"; font-size: 0.75em; }
.data-table th[aria-sort="descending"]::after { content: " ▼"; font-size: 0.75em; }
.data-table td { padding: 0.6rem 0.9rem; border-top: 1px solid var(--rule); }
.data-table .num { text-align: right; }
.data-table tbody tr:hover { background: #f0f4fb; }
.bar-cell { display: flex; align-items: center; justify-content: flex-end; gap: 0.6rem; }
.bar { height: 10px; border-radius: 2px; min-width: 2px; }

.two-col { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 2.5rem; margin-top: 2.5rem; }
.chart-box { position: relative; height: 300px; background: var(--white); border: 2px solid var(--ink); border-radius: 6px; padding: 0.8rem; }

.line-list { list-style: none; padding: 0; margin: 0; border: 2px solid var(--ink); border-radius: 6px; background: var(--white); }
.line-list li { display: grid; grid-template-columns: 5.5rem 1fr auto; gap: 0.8rem; align-items: center; padding: 0.55rem 0.8rem; border-top: 1px solid var(--rule); }
.line-list li:first-child { border-top: 0; }
.line-badge { font-family: var(--display); font-weight: 700; background: var(--ink); color: var(--white); border-radius: 4px; padding: 0.1rem 0.45rem; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.line-meta { color: var(--muted); font-size: var(--step--1); }
.line-val { font-family: var(--display); font-weight: 600; font-size: 1.2rem; }

/* Ask = yellow departure poster */
.poster {
  background: var(--fahrplan); color: var(--ink);
  margin: 0 calc(-1 * clamp(1rem, 4vw, 3rem));
  padding-left: clamp(1rem, 4vw, 3rem); padding-right: clamp(1rem, 4vw, 3rem);
  border-top: 0;
}
.poster h2 { font-size: var(--step-4); font-weight: 700; }
.poster-lede { max-width: 40rem; font-size: var(--step-1); margin: 0 0 1.5rem; }
.ask-form { display: flex; gap: 0.6rem; max-width: 60rem; }
.ask-form input { flex: 1; font: 500 1.15rem var(--body); padding: 0.85rem 1rem; border: 3px solid var(--ink); border-radius: 6px; background: var(--white); }
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1rem 0 0; max-width: 60rem; }
.chips button { font: 500 0.95rem var(--body); background: transparent; border: 2px solid var(--ink); border-radius: 999px; padding: 0.35rem 0.85rem; cursor: pointer; color: var(--ink); text-align: left; }
.chips button:hover { background: rgba(0,0,0,0.07); }
.ask-result { max-width: 60rem; }
.ask-result:not(:empty) { margin-top: 1.5rem; background: var(--white); border: 3px solid var(--ink); border-radius: 6px; padding: 1.2rem 1.4rem; }
.ask-result .chart-box { margin: 1rem 0; border-width: 1px; }
.ask-result details { margin-top: 1rem; font-size: var(--step--1); }
.ask-result pre { white-space: pre-wrap; background: var(--paper); padding: 0.6rem; border-radius: 4px; font-size: 0.85rem; }
.thinking { display: flex; align-items: center; gap: 0.6rem; font-weight: 600; }
.thinking::before { content: ""; width: 14px; height: 14px; border: 3px solid var(--ink); border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Report */
.report-form { display: grid; grid-template-columns: 2fr 2fr 1fr auto; gap: 1rem; align-items: end; max-width: 70rem; }
.report-output { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 2rem; margin-top: 2rem; }
.report-summary { align-self: start; background: var(--white); border: 2px solid var(--ink); border-radius: 6px; padding: 1.2rem 1.5rem; }
.report-summary h2 { font-size: var(--step-2); }
.report-summary blockquote { margin: 0 0 1rem; border-left: 4px solid var(--late); padding-left: 0.8rem; }
.letter-actions { display: flex; gap: 0.6rem; margin-top: 0.8rem; flex-wrap: wrap; }
.error { margin-top: 1rem; border-left: 4px solid var(--late); background: var(--white); padding: 0.7rem 1rem; }

.footer { background: var(--sign); color: var(--white); padding: 2.5rem clamp(1rem, 4vw, 3rem); margin-top: 3rem; }
.footer > div { max-width: 60rem; }
.footer h2 { font-size: var(--step-2); }
.footer a { color: var(--fahrplan); }
.footer code { background: rgba(255,255,255,0.12); }
.footer .fine { opacity: 0.75; font-size: var(--step--1); }

@media (max-width: 960px) {
  .hero, .map-layout, .two-col, .report-output { grid-template-columns: minmax(0, 1fr); }
  .report-form { grid-template-columns: 1fr 1fr; }
  .topbar nav { display: none; }
  #leaflet { height: 60vh; }
  .station-panel { max-height: none; }
}
@media (max-width: 560px) {
  .report-form { grid-template-columns: 1fr; }
  .ask-form { flex-direction: column; }
  .board-label { font-size: 1rem; }
  .board-value { font-size: var(--step-2); }
  #board-period { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .ticker span { animation: none; padding-left: 1.4rem; }
  .flap.flipping, .thinking::before { animation: none; }
}
@media print {
  .topbar, .hero, #map, #states, #ask, .report-form, .letter-actions, .footer, .demo-banner { display: none; }
  .report-output { display: block !important; }
}
