:root {
  --ink: #1c1917;
  --muted: #57534e;
  --paper: #f6f3ee;
  --line: #e6dfd4;
  --gold: #c9a227;
  --blue: #003399;
  --panel: 340px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", Helvetica, Arial, sans-serif;
}

body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 10px 16px;
  background: #1c1917;
  color: #f6f3ee;
  border-bottom: 3px solid var(--gold);
}


.home-link {
  display: inline-flex;
  align-items: center;
  flex: none;
  margin-right: 4px;
  padding: 6px 10px;
  border-radius: 8px;
  color: #f6f3ee;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  border: 1px solid rgba(246, 243, 238, 0.18);
  background: rgba(255, 255, 255, 0.06);
}
.home-link:hover, .home-link:focus-visible {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(201, 162, 39, 0.55);
  outline: none;
}

.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }

.mark {
  display: block;
  width: auto;
  height: 40px;
  max-width: 132px;
  flex: none;
  object-fit: contain;
  background: #ffffff;
  border-radius: 8px;
  padding: 4px 6px;
}

h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.brand p {
  margin: 1px 0 0;
  color: #d6d3d1;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status { text-align: right; flex: none; }
#clock { display: block; font-variant-numeric: tabular-nums; font-weight: 650; }
#freshness { display: block; margin-top: 2px; color: #d6d3d1; font-size: 12px; }
#freshness.is-stale { color: #fecaca; }

#stage { position: relative; min-height: 0; }

#map { position: absolute; inset: 0; background: #e7e5e4; }

#panel {
  position: absolute;
  z-index: 500;
  top: 12px;
  bottom: 12px;
  left: 12px;
  width: min(var(--panel), calc(100% - 24px));
  display: flex;
  flex-direction: column;
  background: rgba(246, 243, 238, 0.96);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(28, 25, 23, 0.12);
  overflow: hidden;
  transition: width 0.2s ease, border-radius 0.2s ease;
}

#panel-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  flex: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 650;
  text-align: left;
  padding: 12px 14px;
  cursor: pointer;
}

#panel-toggle .count {
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

#panel-toggle .chevron {
  flex: none;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
}

#panel.is-collapsed {
  width: 52px;
  border-radius: 0 14px 14px 0;
  left: 0;
  top: 12px;
  bottom: 12px;
}

#panel.is-collapsed #panel-toggle {
  flex: 1;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  gap: 14px;
  height: 100%;
  border-bottom: 0;
  padding: 16px 8px;
}

#panel.is-collapsed #panel-toggle .count {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 15px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

#panel.is-collapsed #panel-toggle .chevron {
  transform: rotate(180deg);
}

#panel.is-collapsed #panel-body {
  display: none;
}

#panel-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.legend {
  display: flex;
  gap: 14px;
  padding: 12px 14px 8px;
  color: var(--muted);
  font-size: 12px;
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border-radius: 3px;
  vertical-align: -2px;
}

#trains {
  overflow: auto;
  padding: 0 8px 8px;
  min-height: 0;
}

.note {
  margin: 0;
  padding: 10px 14px 14px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  border-top: 1px solid var(--line);
}

.train {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  border-radius: 12px;
  padding: 8px;
  cursor: pointer;
}

.train:hover, .train.is-open { background: white; }

.train-head {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.badge .code, .flag .code {
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 13px;
  font-weight: 750;
  letter-spacing: 0.01em;
}

.badge .num, .flag .num {
  max-width: 9.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.dest {
  font-size: 14px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.run {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
}

.late, .early {
  font-size: 11px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.late { color: #b91c1c; }
.early { color: #047857; }

.timetable {
  margin: 8px 0 2px;
  padding: 0;
  list-style: none;
}

.timetable li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 5px 4px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.timetable time {
  display: flex;
  flex-direction: column;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  white-space: nowrap;
}
.timetable .plan { color: var(--muted); font-weight: 500; text-decoration: line-through; margin-right: 4px; }
.timetable .quay { color: var(--muted); font-size: 12px; }
.timetable .is-past { color: #a8a29e; }
.timetable .is-current { background: #fff7ed; border-radius: 8px; }
.timetable .is-current .name { font-weight: 750; }
.timetable .is-cancelled .name { text-decoration: line-through; }

.empty {
  margin: 12px;
  color: var(--muted);
  font-size: 14px;
}

/* Nur das sichtbare Flag nimmt Klicks an — nicht die Icon-Box darunter im Stapel. */
.train-icon {
  background: transparent !important;
  border: 0 !important;
  pointer-events: none !important;
}
.flag-slot {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  pointer-events: none;
}
.flag {
  position: relative;
  display: inline-flex;
  align-items: stretch;
  background: white;
  border-radius: 5px;
  overflow: visible;
  filter: drop-shadow(0 1px 2px rgba(28, 25, 23, 0.45));
  cursor: pointer;
  pointer-events: auto;
}
.flag .code { border-radius: 5px 0 0 5px; }
.flag .num {
  padding: 3px 6px;
  background: white;
  color: var(--ink);
  border-radius: 0 5px 5px 0;
}
.flag .late, .flag .early { align-self: center; padding-right: 6px; background: white; }
.flag.is-selected { outline: 2px solid #1c1917; outline-offset: 1px; }
.flag:after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  transform: translateX(-50%);
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid #1c1917;
}

.station-label {
  background: transparent;
  border: 0;
  color: #44403c;
  font-size: 11px;
  font-weight: 700;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff;
  white-space: nowrap;
}

.leaflet-control-attribution { font-size: 10px; }

@media (max-width: 800px) {
  .brand p { display: none; }
  #panel {
    top: auto;
    right: 8px;
    left: 8px;
    bottom: 8px;
    width: auto;
    max-height: min(58vh, 480px);
  }
  #panel.is-collapsed {
    top: auto;
    right: auto;
    left: 0;
    bottom: 8px;
    width: 52px;
    max-height: min(58vh, 480px);
    height: min(42vh, 320px);
    border-radius: 0 14px 14px 0;
  }
}


.flag .num {
  max-width: 9.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rate-banner {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  z-index: 2000;
  background: #1c1917;
  color: #fafaf9;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  font: 600 0.9rem/1.3 system-ui, sans-serif;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  max-width: min(92vw, 28rem);
  text-align: center;
}
