#map {
  width: 100%;
  height: 100%;
  touch-action: pan-x pan-y;
}

/* ================== Base Panel ================== */
.legend-panel {
  position: relative;
  z-index: 1000;
  background: #fff;
  padding: 8px;
  box-sizing: border-box;
  overflow-y: auto;
}

.legend-panel {
  font-size: 14px;
}

.legend-panel h2 {
  font-size: 18px;
}

.legend-panel h3 {
  font-size: 15px;
}

.legend-panel.hidden {
  display: none !important;
}

/* ================== Header ================== */
.legend-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-weight: 600;
}

#legend-toggle {
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
}

/* ================== Layout ================== */
.legend-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 24px; /* slightly tighter */
}

.legend-section {
  min-width: 180px;
}

/* ================== Items ================== */
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
}

.legend-item img {
  width: 14px;
  height: 14px;
  object-fit: contain;
  flex-shrink: 0;
}

.legend-item span {
  line-height: 1.2;
}

/* ================== Responsive Layout ================== */
@media (min-aspect-ratio: 1/1) {
  .legend-panel {
    top: 0;
    left: 0;
    width: 20%;
    height: 100%;
  }
}

@media (max-aspect-ratio: 1/1) {
  .legend-panel {
    bottom: 0;
    left: 0;
    width: 100%;
    height: 20%;
  }
}