/* ==========================================================================
   dBZ-Farblegende  – legend.css
   Position: links-unten, vertikal, niedrigste Werte unten
   Farben: ausschliesslich CSS-Tokens damit Light/Dark automatisch greift
   ========================================================================== */

.dbz-legend {
  position: absolute;
  left: 16px;
  /* bottom wird via JS (ResizeObserver + Kollisionserkennung) dynamisch gesetzt.
     Fallback fuer den ersten Frame vor JS-Auswertung: normaler controls-bottom. */
  bottom: var(--legend-bottom, var(--controls-bottom));
  z-index: 10000;

  /* Interaktiv: komplette Legende ist klickbar */
  cursor: pointer;
  pointer-events: auto;
  user-select: none;

  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;

  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-lg);

  background: var(--glass-bg);
  border: 1px solid var(--color-border);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  box-shadow: var(--shadow-md);

  color: var(--color-text-muted);

  transition:
    background   var(--transition-fast),
    border-color var(--transition-fast),
    color        var(--transition-fast),
    transform    var(--transition-fast),
    box-shadow   var(--transition-fast),
    bottom       var(--transition-fast);
}

/* Hover nur auf Geräten mit echter Zeigerunterstützung (Maus),
   verhindert sticky-hover Bug auf Touch-Geräten (iOS/Android):
   dort bleibt :hover nach dem Antippen aktiv bis woanders getippt wird,
   was die Legende beim Wiedereinblenden im glasigen Zoom-Zustand festhält. */
@media (hover: hover) {
  .dbz-legend:hover {
    background: var(--color-accent-dim);
    border-color: rgba(57, 208, 216, 0.35);
    color: var(--color-accent);
    transform: scale(1.08);
    box-shadow: 0 0 14px var(--color-accent-glow);
  }
}

.dbz-legend:active {
  transform: scale(0.95);
}

.dbz-legend:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* --- Icon: standardmaessig VERSTECKT (ausgeklappt) ---
   Wird nur im collapsed-Zustand eingeblendet */
.dbz-legend__icon {
  display: none;
  font-size: 1.15rem;
  line-height: 1;
}

/* --- Body: der eingeklappbare Inhaltsbereich --- */
.dbz-legend__body {
  display: flex;
  flex-direction: column;
  gap: 2px;

  overflow: hidden;
  max-height: 600px;
  opacity: 1;
  transition:
    opacity    var(--transition-smooth),
    max-height 250ms cubic-bezier(0.16, 1, 0.3, 1),
    margin-top var(--transition-smooth);
}

/* --- Eingeklappter Zustand --- */
.dbz-legend--collapsed {
  width: 44px;
  height: 44px;
  justify-content: center;
  padding: 0;
  gap: 0;
}

/* Icon nur im collapsed-Zustand sichtbar */
.dbz-legend--collapsed .dbz-legend__icon {
  display: block;
}

.dbz-legend--collapsed .dbz-legend__body {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

/* Titel "dBZ" */
.dbz-legend__title {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  text-align: center;
  margin-bottom: var(--space-2);
}

/* Eine Zeile: Farbklecks + Beschriftung */
.dbz-legend__row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 18px;
}

.dbz-legend__swatch {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid var(--color-border);
}

.dbz-legend__label {
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-muted);
  white-space: nowrap;
  line-height: 1;
}

@media (max-width: 1060px) {
  .dbz-legend {
    left: 8px;
    gap: 0;
    padding: var(--space-2) var(--space-2);
  }

  .dbz-legend--collapsed {
    width: 40px;
    height: 40px;
    padding: 0;
  }
}
