/* Schienen-Chaos (Präfix .mg-rails-) */
.mg-rails-root { position: relative; width: 100%; height: 100%; }
.mg-rails {
  --rl-ink: var(--c-outline, #1b1b2f);
  --rl-panel: var(--c-panel, #fff6e0);
  --rl-gold: var(--c-gold, #ffd23f);
  --rl-good: var(--c-good, #2ec27e);
  --rl-bad: var(--c-bad, #ff4d4d);
  position: absolute; inset: 0; overflow: hidden;
  background: repeating-linear-gradient(45deg, #23253a 0 14px, #1f2134 14px 28px);
  color: var(--rl-ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  touch-action: none; user-select: none; -webkit-user-select: none; overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
.mg-rails * { box-sizing: border-box; }
.mg-rails-stage {
  position: absolute;
  top: var(--safe-top, 0px); right: var(--safe-right, 0px);
  bottom: var(--safe-bottom, 0px); left: var(--safe-left, 0px);
}

/* ---------- Kopfzeile ---------- */
.mg-rails-hud {
  position: absolute; z-index: 3; pointer-events: none;
  top: calc(var(--safe-top, 0px) + 6px); left: calc(var(--safe-left, 0px) + 8px); right: calc(var(--safe-right, 0px) + 8px);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
}
.mg-rails-round, .mg-rails-title {
  background: var(--rl-panel); border: 3px solid var(--rl-ink); border-radius: 12px; padding: 5px 10px;
  box-shadow: 0 3px 0 var(--rl-ink);
  font-family: "Press Start 2P", system-ui, monospace; font-size: 11px; line-height: 1.3; white-space: nowrap;
}
.mg-rails-title { flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; }
.mg-rails-timer {
  min-width: 56px; text-align: center;
  font-family: "Press Start 2P", system-ui, monospace; font-size: 22px; color: #fff;
  text-shadow: 3px 3px 0 var(--rl-ink), -2px -2px 0 var(--rl-ink), 2px -2px 0 var(--rl-ink), -2px 2px 0 var(--rl-ink);
}
.mg-rails-timer:empty { visibility: hidden; }
.mg-rails-timer.is-low { color: var(--rl-bad); animation: mg-rails-pulse .5s infinite alternate; }
@keyframes mg-rails-pulse { from { transform: scale(1); } to { transform: scale(1.18); } }

/* ---------- Punkte-Leiste ---------- */
.mg-rails-scores {
  position: absolute; z-index: 3; pointer-events: none;
  left: calc(var(--safe-left, 0px) + 8px); right: calc(var(--safe-right, 0px) + 120px);
  bottom: calc(var(--safe-bottom, 0px) + 6px);
  display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-start;
}
.mg-rails-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(255, 246, 224, 0.92); border: 2px solid var(--rl-ink); border-radius: 10px;
  padding: 2px 7px; font-size: 11px; line-height: 1.2;
}
.mg-rails-chip.is-me { background: var(--rl-gold); }
.mg-rails-chip.is-off { opacity: .55; }
.mg-rails-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--pc); border: 2px solid var(--rl-ink); }
.mg-rails-name { max-width: 7em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-rails-last { font-weight: 700; }
.mg-rails-last.is-good { color: #127a46; }
.mg-rails-last.is-bad { color: #b3261e; }

/* ---------- Ansicht-Knopf ---------- */
.mg-rails-viewbtn {
  position: absolute; z-index: 4;
  right: calc(var(--safe-right, 0px) + 8px); bottom: calc(var(--safe-bottom, 0px) + 6px);
  min-width: var(--btn-min, 48px); min-height: var(--btn-min, 48px); padding: 0 12px;
  background: var(--rl-panel); color: var(--rl-ink);
  border: 3px solid var(--rl-ink); border-radius: 12px; box-shadow: 0 3px 0 var(--rl-ink);
  font: 700 13px system-ui, sans-serif;
}
.mg-rails-viewbtn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--rl-ink); }
.mg-rails-viewbtn[hidden] { display: none; }

/* ---------- Banner ---------- */
.mg-rails-banner {
  position: absolute; z-index: 5; left: 50%; top: 28%; transform: translate(-50%, -50%) scale(.6);
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s;
  background: var(--rl-panel); border: 4px solid var(--rl-ink); border-radius: 14px; box-shadow: 0 4px 0 var(--rl-ink);
  padding: 8px 16px; max-width: 90%; text-align: center;
  font-family: "Press Start 2P", system-ui, monospace; font-size: 13px; line-height: 1.4;
}
.mg-rails-banner.is-on { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.mg-rails-banner.is-go { background: var(--rl-gold); }
.mg-rails-banner.is-bad { background: #ffd6d6; }

/* ---------- Overlay (Ansage / Zwischenstand / Endstand) ---------- */
.mg-rails-overlay {
  position: absolute; z-index: 6; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(27, 27, 47, 0.45); pointer-events: none;
}
.mg-rails-overlay.is-on { display: flex; }
.mg-rails-card {
  background: var(--rl-panel); border: 4px solid var(--rl-ink); border-radius: 16px; box-shadow: 0 5px 0 var(--rl-ink);
  padding: 10px 16px; max-width: min(92vw, 520px); max-height: 86%; overflow: auto; text-align: center;
  animation: mg-rails-pop .25s ease-out;
}
@keyframes mg-rails-pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.mg-rails-card h2 { margin: 2px 0 8px; font-family: "Press Start 2P", system-ui, monospace; font-size: 15px; }
.mg-rails-card p { margin: 4px 0; font-size: 14px; line-height: 1.4; }
.mg-rails-card table { border-collapse: collapse; margin: 0 auto; font-size: 13px; }
.mg-rails-card th, .mg-rails-card td { padding: 3px 8px; border-bottom: 2px solid rgba(27, 27, 47, .15); }
.mg-rails-card th { font-size: 11px; text-transform: uppercase; }
.mg-rails-card tr.is-me td { background: var(--rl-gold); }
.mg-rails-note { margin-top: 6px; font-size: 11px; opacity: .75; }
.mg-rails-card--prep h2 { font-size: 18px; }

.layout-tablet .mg-rails-round, .layout-tablet .mg-rails-title { font-size: 14px; padding: 7px 14px; }
.layout-tablet .mg-rails-timer { font-size: 30px; }
.layout-tablet .mg-rails-chip { font-size: 14px; padding: 4px 10px; }
.layout-tablet .mg-rails-card { font-size: 16px; }
