/* ── Légende — desktop : toujours visible ── */
.legend {
  position: absolute;
  bottom: 110px;
  left: 16px;
  background: #fffbf0;
  border: 3px solid #333;
  border-radius: 16px;
  padding: 10px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 10;
  box-shadow: 4px 4px 0px #333;
}

.legend__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}

.legend__title {
  font-family: 'Fredoka One', cursive;
  font-size: 13px;
  color: #1a1a2e;
  letter-spacing: 0.03em;
}

/* Croix cachée sur desktop */
.legend__close {
  display: none;
}

/* Bouton toggle caché sur desktop */
.legend__toggle {
  display: none;
}

.legend__item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: 'Fredoka', sans-serif;
  font-size: 12px;
  font-weight: 500;
  color: #333;
  white-space: nowrap;
}

.legend__swatch {
  width: 16px;
  height: 10px;
  border-radius: 3px;
  border: 2px solid #333;
  flex-shrink: 0;
}
.legend__swatch--obs-s2 { background: #f4720a; }
.legend__swatch--obs-s3 { background: #d4b830; opacity: 0.7; }
.legend__swatch--fore   { background: #818cf8; }

.legend__divider {
  height: 2px;
  background: #333;
  margin: 2px 0;
  border-radius: 1px;
}

.legend__dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid #fff;
  outline: 2px solid #333;
  flex-shrink: 0;
}
.legend__dot--low    { background: #22c55e; }
.legend__dot--medium { background: #f59e0b; }
.legend__dot--high   { background: #ef4444; }

/* ── Mobile ── */
@media (max-width: 480px) {
  /* Bouton toggle flottant en bas à gauche */
  .legend__toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    bottom: max(60px, calc(60px + env(safe-area-inset-bottom)));
    left: max(16px, calc(16px + env(safe-area-inset-left)));
    width: 36px;
    height: 36px;
    background: #fffbf0;
    border: 2.5px solid #333;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    box-shadow: 3px 3px 0px #333;
    z-index: 15;
    transition: transform .1s, box-shadow .1s;
  }
  .legend__toggle:hover {
    transform: translate(-2px, -2px);
    box-shadow: 5px 5px 0px #333;
  }

  /* Backdrop semi-transparent */
  .legend__backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.25);
    z-index: 19;
  }

  /* Légende cachée par défaut sur mobile */
  .legend {
    position: fixed;
    bottom: max(20px, calc(20px + env(safe-area-inset-bottom)));
    left: max(16px, calc(16px + env(safe-area-inset-left)));
    right: max(16px, calc(16px + env(safe-area-inset-right)));
    /* centré horizontalement */
    width: auto;
    border-radius: 20px;
    padding: 16px 18px 18px;
    gap: 10px;
    z-index: 20;
    box-shadow: 5px 5px 0px #333;
    /* Caché par défaut */
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
    transition: opacity .2s ease, transform .2s ease;
  }

  .legend--open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }

  /* Croix visible sur mobile */
  .legend__close {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 2px solid #333;
    border-radius: 6px;
    width: 24px;
    height: 24px;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    color: #333;
    box-shadow: 1px 1px 0 #333;
  }

  .legend__title {
    font-size: 15px;
  }

  .legend__item {
    font-size: 14px;
    gap: 10px;
  }

  .legend__swatch {
    width: 20px;
    height: 13px;
  }

  .legend__dot {
    width: 14px;
    height: 14px;
  }
}
