/* Track-Map – eigenständiges Stylesheet für die iFrame-Ansicht (map.php).
   Bewusst getrennt von mainElements.css, damit die alten Seiten unberührt bleiben. */

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --surface: rgba(255, 255, 255, 0.86);
  --surface-solid: #ffffff;
  --text: #1b1f24;
  --text-muted: #6b7280;
  --border: rgba(16, 24, 40, 0.10);
  --shadow: 0 2px 4px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.10);

  --c-planned: #7a8290;
  --c-stage: #2c7be5;
  --c-live: #f97316;
  --c-dot: #ef4444;
  --c-dot-idle: #9aa3af;

  --panel-radius: 12px;
}

:root[data-theme="dark"],
html.theme-dark {
  --surface: rgba(20, 24, 30, 0.86);
  --surface-solid: #14181e;
  --text: #e8ecf2;
  --text-muted: #9aa3af;
  --border: rgba(255, 255, 255, 0.12);
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.45);

  --c-planned: #98a1ae;
  --c-stage: #5b9df9;
  --c-live: #fb923c;
  --c-dot: #f87171;
  --c-dot-idle: #6b7280;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: contain;
  font-family: var(--font);
  color: var(--text);
  background: #eef1f4;
}

html.theme-dark body { background: #0e1116; }

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Die Basiskarte wird entsaettigt, damit die Spuren der klare Inhalt bleiben
   und nicht gegen bunte Autobahnen und POI-Symbole antreten muessen.
   Die Klasse setzt mapView.js ueber die className-Option der Kachelebene. */
.basemap {
  filter: grayscale(0.78) saturate(0.8) contrast(0.9) brightness(1.07);
}

html.theme-dark .basemap {
  filter: grayscale(0.95) invert(1) brightness(0.86) contrast(0.92) hue-rotate(180deg);
}

/* Die Karte nimmt die Wischgeste selbst entgegen, damit sie sich mit einem
   Finger schieben laesst. Mit ?touch=two bekommt die Elternseite die
   Einfinger-Geste zurueck und die Karte braucht zwei Finger. */
.ol-viewport { touch-action: none !important; }
body.two-finger-pan .ol-viewport { touch-action: pan-y !important; }

/* ---------------------------------------------------------------- Panels */

.panel {
  position: absolute;
  z-index: 20;
  background: var(--surface);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--panel-radius);
  box-shadow: var(--shadow);
}

/* Legende + Ebenenschalter in einem */
#layer-panel {
  top: 12px;
  right: 12px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 150px;
}

.layer-toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color .15s ease, opacity .15s ease;
}

.layer-toggle:hover { background: rgba(127, 137, 150, 0.12); }
.layer-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.layer-toggle .swatch {
  flex: 0 0 auto;
  width: 22px;
  height: 4px;
  border-radius: 2px;
  background: var(--swatch, var(--c-stage));
}
.layer-toggle .swatch.snail {
  width: 22px;
  height: auto;
  background: none;
  border-radius: 0;
  font-size: 14px;
  line-height: 1;
  text-align: center;
}

.layer-toggle .swatch.dashed {
  height: 0;
  border-top: 3px dashed var(--swatch);
  border-radius: 0;
}
.layer-toggle .name { flex: 1 1 auto; }
.layer-toggle .amount {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--text-muted);
}
/* .off wird zusaetzlich von mapView.js gesetzt, damit die Abblendung auch
   ohne :has()-Unterstuetzung funktioniert. */
.layer-toggle.off,
.layer-toggle:has(input:not(:checked)) { opacity: .42; }
.layer-toggle.off .swatch,
.layer-toggle:has(input:not(:checked)) .swatch { background: var(--text-muted); border-top-color: var(--text-muted); }
.layer-toggle.off .swatch.snail,
.layer-toggle:has(input:not(:checked)) .swatch.snail { background: none; }
.layer-toggle:has(input:focus-visible) { outline: 2px solid var(--c-stage); outline-offset: 1px; }

/* Statusleiste unten links: der eigentliche Dot-Watching-Inhalt */
#status-panel {
  left: 12px;
  bottom: 12px;
  right: auto;
  padding: 12px 14px;
  max-width: min(340px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}

.status-line .beacon {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--c-dot);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--c-dot) 60%, transparent);
}

body[data-state="live"] .status-line .beacon { animation: beacon 2s ease-out infinite; }
body[data-state="idle"] .status-line .beacon { background: var(--c-live); }
body[data-state="archive"] .status-line .beacon { background: var(--c-dot-idle); }

@keyframes beacon {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c-dot) 70%, transparent); }
  70%  { box-shadow: 0 0 0 9px color-mix(in srgb, var(--c-dot) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c-dot) 0%, transparent); }
}

.stat-row {
  display: flex;
  gap: 18px;
}

.stat { white-space: nowrap; }

.stat .value {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat .value .unit { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-left: 2px; }
.label .short { display: none; }

.stat .label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-top: 2px;
}

.progress {
  height: 5px;
  border-radius: 3px;
  background: rgba(127, 137, 150, .25);
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--c-stage), var(--c-live));
  transition: width .6s cubic-bezier(.2, .7, .3, 1);
}

.progress-caption {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  margin-top: -4px;
}

/* --------------------------------------------------------------- Marker */

#dot {
  position: relative;
  width: 0;
  height: 0;
  pointer-events: none;
}

#dot .halo {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  background: var(--c-dot);
  opacity: 0;
}

body[data-state="live"] #dot .halo { animation: halo 2.4s ease-out infinite; }

@keyframes halo {
  0%   { transform: scale(.6); opacity: .55; }
  80%  { transform: scale(3.4); opacity: 0; }
  100% { transform: scale(3.4); opacity: 0; }
}

#dot .core {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  background: var(--c-dot);
  border: 2.5px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
}

html.theme-dark #dot .core { border-color: #11151a; }
body[data-state="archive"] #dot .core { background: var(--c-dot-idle); }
body[data-state="idle"] #dot .core { background: var(--c-live); }

/* Fahrtrichtung */
#dot .heading {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  transition: transform .5s ease;
}
#dot .heading::after {
  content: "";
  position: absolute;
  left: -5px;
  top: -20px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 8px solid var(--c-dot);
  filter: drop-shadow(0 0 1.5px rgba(255, 255, 255, .9));
}
#dot.no-heading .heading { display: none; }
body[data-state="archive"] #dot .heading { display: none; }

/* Deadline-Schnecke: die Soll-Position auf der Planroute */
#pace-dot {
  position: relative;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border-radius: 50%;
  background: var(--surface-solid);
  border: 1.5px solid var(--border);
  box-shadow: 0 1px 4px rgba(16, 24, 40, .3);
  font-size: 15px;
  line-height: 23px;
  text-align: center;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

#pace-dot.hidden { display: none; }

/* Ausserhalb der Fahrzeit (9-19 Uhr) schlaeft die Schnecke. */
#pace-dot.sleeping { filter: saturate(.45) brightness(.95); }
#pace-dot.sleeping::before,
#pace-dot.sleeping::after {
  content: 'z';
  position: absolute;
  left: 18px;
  top: -6px;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  color: var(--text-muted);
  opacity: 0;
  animation: snail-zzz 2.8s ease-out infinite;
}
#pace-dot.sleeping::after {
  content: 'Z';
  font-size: 12px;
  animation-delay: 1.4s;
}
/* Im Ziel: eine Woche Umarmung und Konfetti (siehe mapView.js). */
#pace-dot.hug::after {
  content: '🤗';
  position: absolute;
  left: 15px;
  top: -15px;
  font-size: 16px;
  line-height: 1;
  animation: snail-hug 1.6s ease-in-out infinite;
}
@keyframes snail-hug {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.25); }
}
.hug-scene {
  position: relative;
  width: 170px;
  height: 170px;
  pointer-events: none;
}
.hug-scene canvas { display: block; width: 170px; height: 170px; }
.hug-scene::before,
.hug-scene::after {
  content: '❤️';
  position: absolute;
  left: 52%;
  top: 4px;
  font-size: 15px;
  opacity: 0;
  animation: hug-heart 3s ease-out infinite;
}
.hug-scene::after { left: 40%; font-size: 11px; animation-delay: 1.5s; }
@keyframes hug-heart {
  0%   { opacity: 0; transform: translateY(14px) scale(.6); }
  25%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(-18px) scale(1.1); }
}
.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1000;
}

@keyframes snail-zzz {
  0%   { opacity: 0; transform: translate(0, 0); }
  25%  { opacity: 1; }
  100% { opacity: 0; transform: translate(7px, -13px); }
}

/* Etappen-Popup */
#popup {
  position: absolute;
  transform: translate(-50%, -100%) translateY(-12px);
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow);
  padding: 8px 12px;
  font-size: 12.5px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s ease;
}
#popup.visible { opacity: 1; }
#popup strong { display: block; font-size: 13px; margin-bottom: 2px; }
#popup .km { color: var(--text-muted); font-variant-numeric: tabular-nums; }
#popup::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  background: var(--surface-solid);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  transform: rotate(45deg);
}

/* ----------------------------------------------------------- Hinweise */

#hint {
  position: absolute;
  z-index: 30;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(17, 21, 26, .82);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s ease;
}
#hint.visible { opacity: 1; }

#loading {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: inherit;
  background-color: #eef1f4;
  transition: opacity .4s ease;
}
html.theme-dark #loading { background-color: #0e1116; }
#loading.done { opacity: 0; pointer-events: none; }
#loading .spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid rgba(127, 137, 150, .3);
  border-top-color: var(--c-stage);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------- OpenLayers-Bedienelemente */

.ol-control {
  position: absolute;
  background: none;
  padding: 0;
}

.ol-zoom {
  top: 12px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.ol-zoom button,
#follow-btn {
  display: block;
  width: 34px;
  height: 34px;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--surface);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: var(--text);
  font: 600 17px/1 var(--font);
  cursor: pointer;
  transition: background-color .15s ease;
}

.ol-zoom button:hover,
#follow-btn:hover { background: var(--surface-solid); }

.ol-zoom button + button { border-top: 1px solid var(--border); }

#follow-btn {
  position: absolute;
  z-index: 20;
  top: 95px;
  left: 12px;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  font-size: 15px;
}
#follow-btn[aria-pressed="true"] {
  background: var(--c-stage);
  border-color: var(--c-stage);
  color: #fff;
}

.ol-scale-line {
  left: auto;
  right: 12px;
  bottom: 12px;
  background: none;
  padding: 0;
}
.ol-scale-line-inner {
  border: 1px solid var(--text-muted);
  border-top: none;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  text-shadow: 0 0 3px var(--surface-solid), 0 0 3px var(--surface-solid);
  margin: 0;
}

.ol-attribution {
  right: 12px;
  bottom: 34px;
  max-width: calc(100% - 24px);
  font-size: 10px;
}
.ol-attribution ul {
  background: var(--surface);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-radius: 6px;
  padding: 3px 7px;
  color: var(--text-muted);
  text-shadow: none;
  border: 1px solid var(--border);
}
.ol-attribution a { color: var(--text-muted); }
.ol-attribution button {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 20px;
  height: 20px;
  font-size: 11px;
  cursor: pointer;
}

/* ------------------------------------------------------------- Kleine Screens */

/* Kompaktmodus: schmale Displays und niedrige iFrames. Entscheidend ist hier
   die Karte - Legende und Statusleiste schrumpfen auf je eine Zeile, damit sie
   nicht die halbe Flaeche wegnehmen. Der Kartenausschnitt richtet sich in
   mapView.js nach der tatsaechlichen Panel-Hoehe, nicht nach festen Werten. */
@media (max-width: 560px), (max-height: 560px) {
  /* Legende: aus der Spalte wird eine Zeile */
  #layer-panel {
    top: 8px;
    right: 8px;
    min-width: 0;
    flex-direction: row;
    padding: 3px;
    gap: 0;
  }

  .layer-toggle {
    padding: 5px 7px;
    font-size: 10.5px;
    gap: 6px;
  }

  .layer-toggle .swatch { width: 14px; height: 3px; }
  .layer-toggle .swatch.dashed { border-top-width: 2px; }
  .layer-toggle .amount { display: none; }

  /* Statusleiste: Werte und Beschriftungen nebeneinander statt gestapelt */
  #status-panel {
    left: 8px;
    right: 8px;
    bottom: 8px;
    max-width: none;
    padding: 7px 10px;
    gap: 5px;
  }

  .status-line { font-size: 12px; }

  .stat-row {
    gap: 12px;
    row-gap: 3px;
    flex-wrap: wrap;
  }

  .label .long { display: none; }
  .label .short { display: inline; }

  .stat {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
  }

  .stat .value { font-size: 13px; }
  .stat .value .unit { font-size: 10px; margin-left: 1px; }

  .stat .label {
    font-size: 9.5px;
    margin-top: 0;
    letter-spacing: .04em;
  }

  .progress { height: 4px; }
  .progress-caption { display: none; }

  /* Bedienknoepfe links etwas kleiner, sie stehen sonst im Weg */
  .ol-zoom, #follow-btn { left: 8px; }
  .ol-zoom { top: 8px; width: 32px; }
  .ol-zoom button, #follow-btn { width: 30px; height: 30px; font-size: 15px; }
  #follow-btn { top: 78px; width: 32px; height: 32px; }

  .ol-scale-line { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #dot .halo, .status-line .beacon { animation: none; }
  #pace-dot.sleeping::before { animation: none; opacity: 0; }
  #pace-dot.hug::after { animation: none; }
  .hug-scene::before { animation: none; opacity: 1; transform: none; }
  .hug-scene::after { animation: none; }
  #pace-dot.sleeping::after { animation: none; opacity: 1; transform: translate(4px, -8px); }
  .progress > span { transition: none; }
}
