:root {
  --bg: #0b0d10;
  --ink: #f4f6f8;
  --muted: #8b96a5;
  --dim: #5b6573;
  --panel: #12151a;
  --line: #232830;
  --accent: #4b8ff0;
  --warn: #f5c73b;
  --bad: #ef6b41;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app {
  display: grid;
  grid-template-columns: 1fr 360px;
  height: 100%;
}

/* ------------------------------------------------------------------- stage */

#stage {
  position: relative;
  overflow: hidden;
  min-width: 0;
  touch-action: none;
}

#map { display: block; width: 100%; height: 100%; cursor: grab; }
#map.dragging { cursor: grabbing; }

#titlebar {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 22px 26px;
  pointer-events: none;
  gap: 16px;
}

#titlebar h1 {
  margin: 0;
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

#subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13.5px;
}

.title-right { text-align: right; }

#clock {
  font: 600 44px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

#running {
  margin-top: 6px;
  color: var(--muted);
  font-size: 10.5px;
  letter-spacing: 0.09em;
}
#running b {
  display: block;
  color: var(--ink);
  font: 600 17px/1.2 ui-monospace, Menlo, monospace;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ legend */

#legend {
  position: absolute;
  inset: auto 0 74px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  padding: 0 26px;
  font-size: 12.5px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: none;
  border: 0;
  padding: 3px 2px;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  border-radius: 5px;
  opacity: 1;
  transition: opacity 0.15s;
}
/* Short legend names are for the phone layout only. */
.legend-short { display: none; }
.legend-item[aria-pressed="false"] { opacity: 0.32; }
.legend-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
  box-shadow: 0 0 8px currentColor;
  background: currentColor;
}
.legend-count { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- controls */

#controls {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 26px 18px;
  background: linear-gradient(to top, rgba(11, 13, 16, 0.92), transparent);
}

.icon-btn, .pill, #speed {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 999px;
  font: inherit;
  font-size: 12.5px;
  padding: 5px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.icon-btn { padding: 5px 11px; font-size: 14px; line-height: 1.2; }
.icon-btn:hover, .pill:hover, #speed:hover { background: rgba(255, 255, 255, 0.13); }
.pill.on { background: var(--accent); border-color: var(--accent); color: #05070a; font-weight: 600; }
#speed { padding: 5px 8px; }

#scrub {
  flex: 1;
  min-width: 90px;
  accent-color: var(--accent);
  height: 3px;
  cursor: pointer;
}

/* ----------------------------------------------------------------- tooltip */

#tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  background: rgba(10, 12, 15, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  max-width: 260px;
  transform: translate(-50%, calc(-100% - 12px));
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.55);
}
#tooltip b { display: block; }
#tooltip small { display: block; color: var(--muted); margin-top: 2px; }

/* ------------------------------------------------------------------- panel */

#panel {
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

/* Sits over every tab's content rather than inside one, so switching tabs
   never hides the language choice. */
.lang-picker-global {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 5;
  background: var(--panel);
  box-shadow: 0 0 8px 6px var(--panel);
}
#app.panel-collapsed .lang-picker-global { display: none; }

.panel-tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.panel-tabs button {
  /* `auto` rather than a fixed basis: "Bauarbeiten" needs more room than
     "Zug", and equal thirds would truncate the long one in every language but
     English. */
  flex: 1 1 auto;
  min-width: 0;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 12px 2px;
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
  /* French and German labels are longer than the English ones; the row must
     stay one line rather than growing to two, and the count must not push the
     label into an ellipsis. */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  white-space: nowrap;
}
.panel-tabs button > span:first-of-type { overflow: hidden; text-overflow: ellipsis; }
.panel-tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }
.panel-tabs button > span[id] {
  flex: none;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  padding: 1px 5px;
  font-size: 10.5px;
}

.tab { display: none; overflow-y: auto; padding: 16px 18px 28px; }
.tab.active { display: block; }
.tab h2 { font-size: 12px; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); margin: 22px 0 7px; }
.tab h2:first-child { margin-top: 0; }
.tab p { margin: 0 0 10px; font-size: 13.5px; }
.fineprint, .hint { color: var(--muted); font-size: 12.5px; }

.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.stat {
  background: rgba(255, 255, 255, 0.045);
  border-radius: 8px;
  padding: 9px 10px;
}
.stat b { display: block; font: 600 18px/1.2 ui-monospace, Menlo, monospace; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 10.5px; letter-spacing: 0.05em; text-transform: uppercase; }

.stale-banner {
  background: rgba(245, 199, 59, 0.13);
  border: 1px solid rgba(245, 199, 59, 0.35);
  color: var(--warn);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 12.5px;
  margin-bottom: 14px;
}

.alert {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  margin-bottom: 9px;
  background: rgba(255, 255, 255, 0.022);
}
.alert-head { display: flex; gap: 9px; align-items: flex-start; }
.alert-emoji { font-size: 19px; line-height: 1.2; flex: none; }
.alert-title { font-size: 13.5px; font-weight: 600; }
.alert-meta { color: var(--muted); font-size: 11.5px; margin-top: 3px; display: flex; flex-wrap: wrap; gap: 4px 8px; }
.alert-desc { color: var(--muted); font-size: 12.5px; margin-top: 7px; }
.chip {
  background: rgba(255, 255, 255, 0.07);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 11px;
  white-space: nowrap;
}
.alert a { color: var(--accent); }


/* -------------------------------------------------------------- train card */

.train-card h3 { margin: 0 0 2px; font-size: 17px; }
.train-sub { color: var(--muted); font-size: 12.5px; margin-bottom: 12px; }
.delay-badge {
  display: inline-block;
  border-radius: 6px;
  padding: 3px 9px;
  font: 600 13px/1.4 ui-monospace, Menlo, monospace;
  margin-bottom: 12px;
}
.stoplist { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.stoplist li { position: relative; padding: 3px 0 3px 16px; font-size: 12.5px; display: flex; justify-content: space-between; gap: 10px; }
.stoplist li::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 11px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dim);
}
.stoplist li.done::before { background: var(--accent); }
.stoplist li.skipped { text-decoration: line-through; color: var(--dim); }
.stoplist time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  flex: none;
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
}
/* Scheduled time, struck through, then the time the feed reports for that stop. */
.stoplist time s { color: var(--dim); text-decoration-thickness: 1px; }
.stoplist time b { font-weight: 600; }
.stoplist time b.late { color: var(--warn); }
.stoplist time b.early { color: #3ad9a4; }
.stoplist time em {
  font-style: normal;
  font-size: 10.5px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.07);
  border-radius: 4px;
  padding: 0 4px;
}
/* A deviation carried over from a neighbouring stop, not reported for this one. */
.stoplist time em.carried { opacity: 0.6; }

/* ----------------------------------------------------------------- loading */

#loadbox {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: var(--bg);
  z-index: 10;
  transition: opacity 0.35s;
}
#app:not(.loading) #loadbox { opacity: 0; pointer-events: none; }
#loadmsg { color: var(--muted); font-size: 13px; margin: 0; }
.spinner {
  width: 26px;
  height: 26px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-box { color: var(--bad); max-width: 420px; text-align: center; font-size: 13.5px; }

/* -------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  /* The map takes what the panel leaves: collapsed, that is nearly all of it. */
  #app { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  /* An open tab takes a third of the screen at most: the map is the point. */
  #panel { border-left: 0; border-top: 1px solid var(--line); max-height: 34vh; }
  #app.panel-collapsed #panel { max-height: none; }
  #app.panel-collapsed .tab { display: none; }
  .panel-tabs button { padding: 10px 4px; font-size: 11.5px; }
  .panel-tabs span { font-size: 10px; padding: 1px 5px; }

  #titlebar { padding: 10px 14px; }
  #titlebar h1 { font-size: 16px; }
  #subtitle { font-size: 11px; margin-top: 2px; }
  #clock { font-size: 24px; }
  #running { margin-top: 3px; font-size: 9px; white-space: nowrap; }
  .title-right { white-space: nowrap; }
  #subtitle { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #running b { font-size: 13px; }

  /* One line, short names, no wrapping — a phone has no room for two rows. */
  #legend {
    padding: 0 14px;
    inset: auto 0 62px 0;
    gap: 0 8px;
    font-size: 10.5px;
    flex-wrap: nowrap;
    justify-content: space-between;
    overflow: hidden;
  }
  .legend-item { gap: 5px; padding: 2px 0; }
  .legend-full { display: none; }
  .legend-short { display: inline; }
  .legend-count { font-size: 10px; }

  #controls { padding: 8px 14px 12px; gap: 8px; }
  #speedwrap { display: none; }
  #colormode { font-size: 11px; padding: 5px 9px; }
  .tab { padding: 12px 14px 20px; }

  /* A third of the screen is not much: the summary gives the list its room. */
  .summary { gap: 6px; margin-bottom: 10px; }
  .stat { padding: 6px 8px; }
  .stat b { font-size: 15px; }
  .stat span { font-size: 9px; letter-spacing: 0.03em; }
  .panel-controls { margin-bottom: 9px; }
  .alert { padding: 8px 10px; margin-bottom: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 3s; }
}

/* ------------------------------------------------- panel controls & i18n */

.panel-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}
.segmented button {
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: 11.5px;
  padding: 4px 9px;
  cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button.active { background: var(--accent); color: #05070a; font-weight: 600; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.check input { accent-color: var(--accent); margin: 0; }

.alert-where {
  color: var(--muted);
  font-size: 11.5px;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.alert.located { border-left: 2px solid rgba(75, 143, 240, 0.55); }
.alert.selected { border-color: rgba(245, 199, 59, 0.6); background: rgba(245, 199, 59, 0.07); }

/* The full alert text is long and repetitive — keep it one tap away. */
.alert-more { margin-top: 7px; }
.alert-more summary {
  color: var(--accent);
  font-size: 11.5px;
  cursor: pointer;
  list-style: none;
  width: max-content;
}
.alert-more summary::-webkit-details-marker { display: none; }
.alert-more summary::before { content: '▸ '; }
.alert-more[open] summary::before { content: '▾ '; }
.alert-desc p { margin: 0 0 6px; }
.alert-desc p:last-child { margin-bottom: 0; }

#works .alert { cursor: pointer; }
.stat b small { display: block; font: 400 10px/1.3 ui-sans-serif, system-ui, sans-serif; color: var(--muted); letter-spacing: 0; text-transform: none; }
