:root {
  --bg: #12161b;
  --panel: #1b2027;
  --text: #eef1f4;
  --muted: #9aa4af;
  --line: #2a313a;
  --green: #1fa855;
  --yellow: #f5c211;
  --red: #e0312b;
  --grey: #5b6570;
  --state: var(--grey);
  --state-text: #fff;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
main { max-width: 640px; margin: 0 auto; padding: 12px 16px 32px; }

body.state-green  { --state: var(--green);  --state-text: #fff; }
body.state-yellow { --state: var(--yellow); --state-text: #1a1a1a; }
body.state-red    { --state: var(--red);    --state-text: #fff; }

header { text-align: center; margin: 4px 0 12px; }
header h1 { font-size: 1.15rem; margin: 0; font-weight: 650; }
header p { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }

#signal {
  background: var(--state);
  color: var(--state-text);
  border-radius: 24px;
  padding: 20px 16px 24px;
  text-align: center;
  transition: background-color .4s ease;
  box-shadow: 0 10px 40px -10px var(--state);
}
.lights { display: flex; justify-content: center; gap: 14px; margin-bottom: 10px; }
.lamp {
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(0, 0, 0, .28);
  border: 3px solid rgba(0, 0, 0, .25);
}
body.state-red .lamp.red { background: #ff4d44; box-shadow: 0 0 18px #ff9b95; border-color: #fff; }
body.state-yellow .lamp.yellow { background: #ffe14d; box-shadow: 0 0 18px #fff3a8; border-color: #1a1a1a; }
body.state-green .lamp.green { background: #4dff8e; box-shadow: 0 0 18px #b3ffd0; border-color: #fff; }

#state-word { font-size: clamp(2.6rem, 13vw, 4.2rem); font-weight: 900; letter-spacing: .03em; line-height: 1.05; }
body.state-red #state-word { font-size: clamp(2rem, 10vw, 3.4rem); letter-spacing: 0; }
#countdown-label { font-size: 1.1rem; font-weight: 600; margin-top: 10px; opacity: .92; }
#countdown {
  font-size: clamp(4.5rem, 26vw, 8rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  margin: 4px 0;
}
#countdown-hint { font-size: 1rem; opacity: .9; min-height: 1.2em; }

#next {
  background: var(--panel);
  border-radius: 16px;
  padding: 14px 16px;
  margin-top: 14px;
}
#next .label { color: var(--muted); font-size: .85rem; }
#next-train { font-size: 1.3rem; font-weight: 700; margin-top: 2px; }
#next-time { color: var(--muted); margin-top: 2px; }

#report { background: var(--panel); border-radius: 16px; padding: 14px 12px; margin-top: 14px; }
.report-head { color: var(--muted); font-size: .85rem; margin: 0 4px 8px; }
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.rb {
  font: inherit; font-weight: 800; font-size: 1.05rem; color: #fff; border: 0; border-radius: 14px;
  min-height: 84px; padding: 8px; cursor: pointer; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; touch-action: manipulation;
}
.rb .ico { font-size: 1.5rem; line-height: 1; }
.rb small { font-weight: 500; font-size: .8rem; opacity: .9; }
.rb:active { transform: scale(.97); filter: brightness(1.15); }
.rb:disabled { opacity: .5; }
.rb-open { background: #17813f; }
.rb-closed { background: #b3261f; }
.rb-opening { background: #2c6e49; }
.rb-closing { background: #8a5a00; }
#report-msg { min-height: 1.3em; margin: 10px 4px 0; font-size: .92rem; }
#report-msg.ok { color: #8ff0b2; }
#report-msg.err { color: #ff9b95; }
.geo-toggle { display: flex; gap: 8px; align-items: center; margin: 10px 4px 0; font-size: .9rem; color: var(--muted); }
.geo-toggle input { width: 20px; height: 20px; }
#geo-status { margin: 4px 4px 0; font-size: .8rem; color: var(--muted); min-height: 1em; }

#freight-note { margin: 10px 4px 0; color: #f5dd7a; font-size: .9rem; }

#meta {
  display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center;
  color: var(--muted); font-size: .9rem; margin: 12px 4px 0;
}
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: .8rem; font-weight: 600; background: var(--line); color: var(--text);
}
.badge.realtime { background: #164d2c; color: #8ff0b2; }
.badge.timetable, .badge.stale { background: #4d4216; color: #f5dd7a; }
.badge.unavailable { background: #4d1a16; color: #ff9b95; }

#warning {
  margin: 10px 0 0; padding: 10px 12px; border-radius: 12px;
  background: #4d4216; color: #f5dd7a; font-size: .95rem;
}

#upcoming h2 { font-size: 1rem; margin: 24px 4px 8px; color: var(--muted); font-weight: 600; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: .8rem; }
td.time { font-variant-numeric: tabular-nums; white-space: nowrap; }
td .delay { color: #ff9b95; font-size: .85em; margin-left: 3px; }
td .ontime { color: #8ff0b2; font-size: .85em; margin-left: 3px; }
tr.cancelled td { color: var(--muted); text-decoration: line-through; }
tr.cancelled td.basis { text-decoration: none; }
.basis-tag { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.basis-tag.echtzeit { color: #8ff0b2; }
.basis-tag.geschaetzt { color: #9cc8ff; }

footer { margin-top: 20px; color: var(--muted); font-size: .85rem; text-align: center; }
footer .small { font-size: .78rem; opacity: .85; }

/* Kalibrierung */
form.obs { display: grid; gap: 10px; background: var(--panel); padding: 16px; border-radius: 16px; }
form.obs label { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
form.obs input, form.obs select, form.obs textarea {
  font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
form.obs button {
  font: inherit; font-weight: 700; padding: 10px; border-radius: 10px; border: 0;
  background: var(--green); color: #fff; cursor: pointer;
}
a { color: #9cc8ff; }

.voice { background: var(--panel); border-radius: 16px; padding: 4px 14px; font-size: .9rem; }
.voice code { word-break: break-all; font-size: .8rem; color: #9cc8ff; }
.voice .small { color: var(--muted); font-size: .8rem; }
