/* Minimalistisches Dark-UI, Google-Maps-Vibe. */

:root {
  --bg: #0a0a0a;
  --fg: #f5f5f7;
  --muted: #9a9a9f;
  --card: #121214;
  --card-border: #1d1d21;
  --accent: #2ecc71;
  --accent-red: #ff4954;
  --accent-amber: #ffb020;
  --accent-green: #2ecc71;
  --accent-grey: #3a3a40;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

#map {
  position: fixed;
  inset: 0;
  background: #101014;
  z-index: 0;
  /* Map-Rotation: JS setzt --map-rot auf -heading (Grad). Wir rotieren den
     #map-Container selbst, NICHT die .leaflet-map-pane — Leaflet setzt dort
     sein eigenes transform für's Panning und würde unsere Rotation löschen.
     Container ist 100vw × 100vh → etwas overscale damit die Ecken nach
     Rotation noch gefüllt sind (sonst sieht man schwarze Bereiche). */
  --map-rot: 0deg;
  transform-origin: 50% 50%;
  transition: transform 180ms cubic-bezier(0.25, 0.1, 0.25, 1);
}
#map.rotating {
  transform: rotate(var(--map-rot)) scale(1.45);
  will-change: transform;
}
/* Marker-Inhalt "aufrecht" halten wenn die Map rotiert — die Kacheln drehen
   mit, die Marker-Labels sollen lesbar bleiben. */
#map.rotating .tl-cluster,
#map.rotating .tl-marker {
  transform: translate(-50%, -50%) rotate(calc(-1 * var(--map-rot)));
}

/* ---------- Primary HUD ---------- */
#hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  z-index: 10;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.hud-card {
  pointer-events: auto;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 18px;
  width: min(520px, 100%);
  display: grid;
  grid-template-rows: auto auto;
  gap: 6px;
  transition: border-color 200ms ease, box-shadow 200ms ease, transform 200ms ease;
}

.hud-main {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.kmh {
  font-size: clamp(36px, 9vw, 56px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.kmh small {
  font-size: 0.35em;
  font-weight: 500;
  color: var(--muted);
  margin-left: 6px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.phase {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 500;
  color: var(--fg);
  min-width: 0;
  text-align: right;
}
.phase .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-grey);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-grey) 30%, transparent);
  flex: none;
}

.hud-meta {
  display: flex;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
}
#lightName {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-hint {
  font-size: 12px;
  color: var(--muted);
  opacity: 0.9;
  min-height: 1em;
}
.hud-hint.warn { color: var(--accent-amber); }
.hud-hint.good { color: var(--accent-green); }
.hud-hint.bad  { color: var(--accent-red); }

/* State-Farben — werden über data-state auf #hud geschaltet */
#hud[data-state="green"]  .hud-card { border-color: color-mix(in srgb, var(--accent-green) 60%, transparent); }
#hud[data-state="green"]  .phase .dot { background: var(--accent-green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-green) 30%, transparent); }
#hud[data-state="red"]    .hud-card { border-color: color-mix(in srgb, var(--accent-red) 50%, transparent); }
#hud[data-state="red"]    .phase .dot { background: var(--accent-red); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-red) 30%, transparent); }
#hud[data-state="amber"]  .hud-card { border-color: color-mix(in srgb, var(--accent-amber) 50%, transparent); }
#hud[data-state="amber"]  .phase .dot { background: var(--accent-amber); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-amber) 30%, transparent); }

#hud[data-state="loading"] .kmh,
#hud[data-state="none"]    .kmh { color: var(--muted); }

/* ---------- Footer ---------- */
#bar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 16px;
}

.speed {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}
.speed span { font-size: 28px; font-weight: 700; line-height: 1; }
.speed small { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.status .indicator {
  width: 8px; height: 8px; border-radius: 50%;
  background: #444;
  box-shadow: 0 0 0 2px transparent;
}
.status .indicator.on {
  background: var(--accent-green);
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent-green) 50%, transparent);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.mode {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 3px 6px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: help;
}
.mode .mode-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #444;
}
.mode[data-mode="live"] {
  color: #2ecc71;
  background: rgba(46, 204, 113, 0.10);
  border-color: rgba(46, 204, 113, 0.35);
}
.mode[data-mode="live"] .mode-dot {
  background: #2ecc71;
  box-shadow: 0 0 8px rgba(46, 204, 113, 0.65);
  animation: pulse 1.6s ease-in-out infinite;
}
.mode[data-mode="poll"] {
  color: #ffb020;
  background: rgba(255, 176, 32, 0.10);
  border-color: rgba(255, 176, 32, 0.35);
}
.mode[data-mode="poll"] .mode-dot {
  background: #ffb020;
}
.mode[data-mode="off"] {
  color: #6a6a73;
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
}

/* ---------- Re-Center Button ---------- */
#recenter {
  position: fixed;
  right: 14px;
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + 72px);
  z-index: 10;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px);
  color: var(--fg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: background 150ms ease, transform 150ms ease;
  padding: 0;
}
#recenter:hover {
  background: color-mix(in srgb, var(--card) 98%, transparent);
  transform: scale(1.04);
}
#recenter:active { transform: scale(0.96); }

/* ---------- Sim-Hinweis ---------- */
#sim {
  position: fixed;
  right: 14px;
  top: calc(max(12px, env(safe-area-inset-top)) + 110px);
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 10px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--card) 85%, transparent);
  backdrop-filter: blur(14px);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
#sim kbd {
  font: inherit;
  font-weight: 700;
  color: var(--fg);
  background: #222;
  border: 1px solid #333;
  padding: 1px 6px;
  border-radius: 5px;
  min-width: 22px;
  text-align: center;
}

/* ---------- Leaflet overrides ---------- */
.leaflet-container { background: #101014; outline: none; }
.leaflet-control-zoom { display: none; }
.leaflet-control-attribution {
  background: rgba(0,0,0,0.5) !important;
  color: #777 !important;
  font-size: 9px !important;
}
.leaflet-control-attribution a { color: #aaa !important; }

/* User-Marker (Pfeil) */
.me-marker {
  width: 26px; height: 26px;
  background: #4a9eff;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(74, 158, 255, 0.3), 0 0 12px rgba(74, 158, 255, 0.8);
  transform: translate(-50%, -50%);
}
.me-arrow {
  width: 0; height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 16px solid #4a9eff;
  position: absolute;
  top: -12px; left: 50%;
  transform: translateX(-50%);
  filter: drop-shadow(0 0 3px rgba(0,0,0,0.5));
}

/* Ampel-Marker */
.tl-marker {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #6a6a73;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.6), 0 0 6px rgba(255,255,255,0.25);
  transform: translate(-50%, -50%);
  transition: background 120ms linear, box-shadow 120ms linear, width 120ms, height 120ms;
}
.tl-marker.red { background: var(--accent-red); box-shadow: 0 0 0 1px rgba(0,0,0,0.6), 0 0 10px var(--accent-red); }
.tl-marker.green { background: var(--accent-green); box-shadow: 0 0 0 1px rgba(0,0,0,0.6), 0 0 10px var(--accent-green); }
.tl-marker.amber { background: var(--accent-amber); box-shadow: 0 0 0 1px rgba(0,0,0,0.6), 0 0 10px var(--accent-amber); }
.tl-marker.redamber { background: linear-gradient(180deg, var(--accent-red) 50%, var(--accent-amber) 50%); }
.tl-marker.primary {
  width: 26px; height: 26px;
  border-width: 3px;
  box-shadow: 0 0 0 4px rgba(255,255,255,0.18), 0 0 18px currentColor;
}
.tl-marker.primary.green { color: var(--accent-green); }
.tl-marker.primary.red { color: var(--accent-red); }
.tl-marker.primary.amber { color: var(--accent-amber); }

/* Kreuzungs-Cluster: ein Marker pro Knoten statt 20 einzelne SG-Punkte. */
.tl-cluster {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #3a3a40;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.65), 0 0 6px rgba(255,255,255,0.2);
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: rgba(255,255,255,0.85);
  letter-spacing: 0;
  transition: background 150ms linear, box-shadow 150ms linear, width 150ms, height 150ms;
}
.tl-cluster.red { background: var(--accent-red); box-shadow: 0 0 0 1px rgba(0,0,0,0.65), 0 0 12px var(--accent-red); }
.tl-cluster.green { background: var(--accent-green); box-shadow: 0 0 0 1px rgba(0,0,0,0.65), 0 0 12px var(--accent-green); }
.tl-cluster.amber { background: var(--accent-amber); box-shadow: 0 0 0 1px rgba(0,0,0,0.65), 0 0 12px var(--accent-amber); }
.tl-cluster.unknown { background: #3a3a40; color: rgba(255,255,255,0.4); }
.tl-cluster.osm {
  width: 10px; height: 10px;
  background: rgba(255,255,255,0.25);
  border: 1px solid rgba(255,255,255,0.35);
  box-shadow: none;
  opacity: 0.7;
}
.tl-cluster.primary {
  width: 34px; height: 34px;
  border-width: 3px;
  font-size: 13px;
  box-shadow: 0 0 0 4px rgba(255,255,255,0.18), 0 0 22px currentColor;
}
.tl-cluster.primary.green { color: var(--accent-green); }
.tl-cluster.primary.red { color: var(--accent-red); }
.tl-cluster.primary.amber { color: var(--accent-amber); }

/* HTTPS-Banner (für mobile Browser ohne sicheren Kontext) */
#https-banner {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(8, 8, 10, 0.92);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.https-banner-inner {
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 28px 24px;
  text-align: center;
  box-shadow: var(--shadow);
}
.https-banner-inner strong {
  display: block;
  font-size: 22px;
  margin-bottom: 12px;
  color: var(--accent-amber);
}
.https-banner-inner p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.4;
}
.https-banner-inner code {
  background: rgba(255,255,255,0.08);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--fg);
}
.https-banner-btn {
  display: inline-block;
  margin: 8px 0 12px;
  padding: 14px 28px;
  background: var(--accent-green);
  color: #08130b;
  border-radius: 12px;
  font-weight: 700;
  font-size: 16px;
  text-decoration: none;
  letter-spacing: 0.02em;
}
.https-banner-btn:active { transform: scale(0.97); }
.https-banner-note {
  font-size: 12px !important;
  margin-top: 12px !important;
  color: #6a6a73 !important;
}
