.cm-key {
  --key-paper: #f5f0df;
  --key-ink: #2d443a;
  --key-rule: #c9c6af;
  --key-live: #a44632;
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
  overflow: clip;
  container: campkey / size;
}
.cm-key button { color: inherit; }
.cm-key button:focus-visible {
  outline: 2px solid #9a4835;
  outline-offset: -2px;
}
.cm-key-toggle {
  position: absolute;
  top: clamp(9px, 1.25vw, 18px);
  left: clamp(9px, 1.25vw, 18px);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 6px 12px 6px 9px;
  font: 650 .89rem/1.2 var(--body);
  color: var(--key-ink);
  background: var(--key-paper);
  border: 1px solid #697165;
  border-radius: 2px;
  box-shadow: 1px 2px 0 #39493e30;
  pointer-events: auto;
}
.cm-key-toggle svg { flex: none; }
.cm-key-toggle:hover { background: #fffae9; }
.cm-key[data-open="true"] .cm-key-toggle { visibility: hidden; }
.cm-key-panel {
  position: absolute;
  inset: 0 auto auto 0;
  width: min(354px, calc(100% - 12px));
  padding: 0 16px;
  background: var(--key-paper);
  border: 1px solid #858b76;
  border-left: 3px solid #637b68;
  border-radius: 0 0 3px 0;
  box-shadow: 2px 4px 7px #25382d25;
  color: var(--key-ink);
  pointer-events: none;
  visibility: hidden;
  transform: translateX(calc(-100% - 12px));
  transition: transform 230ms cubic-bezier(.2,.75,.25,1), visibility 0s linear 230ms;
}
.cm-key[data-open="true"] .cm-key-panel {
  transform: none;
  pointer-events: auto;
  visibility: visible;
  transition-delay: 0s;
}
.cm-key-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  border-bottom: 3px double #89917c;
}
.cm-key-heading h2 {
  margin: 0;
  font: 400 clamp(1.65rem, 3.7vw, 2.15rem)/1.15 var(--display);
  letter-spacing: -.065em;
}
.cm-key-close {
  width: 36px;
  height: 36px;
  margin-right: -6px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
}
.cm-key-close:hover,
.cm-legend-places button:hover,
.cm-layer-toggle:hover { background: #e8e4d1; }
.cm-legend-group { padding: 8px 0; }
.cm-legend-group + .cm-legend-group { border-top: 1px solid var(--key-rule); }
.cm-legend-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 22px;
  margin-bottom: 2px;
}
.cm-legend-group-head h3 {
  margin: 0;
  font: 400 .76rem/1.2 var(--mono);
  text-transform: uppercase;
  letter-spacing: .1em;
  color: #586752;
}
.cm-legend-places {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 5px;
}
.cm-legend-places button {
  display: flex;
  align-items: center;
  gap: 7px;
  position: relative;
  min-width: 0;
  min-height: 38px;
  padding: 3px 2px;
  border: 0;
  background: transparent;
  border-radius: 2px;
  text-align: left;
  font: 600 .9rem/1.16 var(--body);
}
.cm-legend-places .cm-legend-symbol {
  flex: none;
  display: block;
  width: 27px;
  height: 27px;
}
.cm-key-live::after,
.cm-now-swatch {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--key-live);
}
.cm-key-live::after {
  content: '';
  position: absolute;
  top: calc(50% - 13px);
  left: 24px;
  box-shadow: 0 0 0 1.2px var(--key-paper);
}
.cm-layer-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 2px 3px;
  border: 0;
  background: transparent;
  font: 600 .82rem/1.2 var(--body);
}
.cm-layer-toggle i {
  display: grid;
  width: 14px;
  height: 14px;
  place-items: center;
  border: 1px solid #5c705a;
  border-radius: 2px;
}
.cm-layer-toggle[aria-pressed="true"] i { background: #3c5a49; }
.cm-layer-toggle[aria-pressed="true"] i::before {
  content: "";
  width: 8px;
  height: 5px;
  margin-top: -2px;
  border-left: 1.5px solid #fff9e7;
  border-bottom: 1.5px solid #fff9e7;
  transform: rotate(-45deg);
}
.cm-legend-swatches {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 10px 0;
  border-top: 1px solid #a6ab93;
  background: transparent;
  color: #455945;
  font: 500 .79rem/1.15 var(--body);
}
.cm-legend-swatches span { display: inline-flex; align-items: center; gap: 5px; }
.cm-legend-swatches svg { width: 21px; height: 12px; fill: none; }
.cm-key-categories { display: none; }
.cm-key-categories button {
  min-height: 32px;
  padding: 3px 6px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: #526452;
  font: 550 .89rem/1.1 var(--body);
}
.cm-key-categories button[aria-pressed="true"] {
  color: #283f33;
  border-bottom-color: #526b55;
  font-weight: 700;
}
@container campkey (max-height: 31rem) {
  .cm-key-categories {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border-bottom: 1px solid var(--key-rule);
  }
  .cm-key-heading { min-height: 46px; }
  .cm-key-panel .cm-legend-group { border: 0; }
  .cm-legend-group-head h3 { display: none; }
  .cm-legend-group-head:not(:has(.cm-layer-toggle)) { display: none; }
  .cm-legend-group-head:has(.cm-layer-toggle) { justify-content: flex-start; }
  .cm-key[data-category="venues"] .cm-legend-group:not(#cm-legend-venues),
  .cm-key[data-category="landmarks"] .cm-legend-group:not(#cm-legend-landmarks),
  .cm-key[data-category="amenities"] .cm-legend-group:not(#cm-legend-amenities) { display: none; }
}
/* Short landscape maps share their vertical space with the timepiece.
   Put the open index in the viewport margin so every section remains reachable. */
@media (max-height: 480px) and (orientation: landscape) {
  .cm-field-row:has(.cm-key[data-open="true"]) { z-index: 8; }
  .cm-key[data-open="true"] {
    position: fixed;
    inset: 0;
  }
  .cm-key[data-open="true"] .cm-key-panel {
    top: max(5px, env(safe-area-inset-top));
    padding-left: max(16px, env(safe-area-inset-left));
  }
}
@media (prefers-reduced-motion: reduce) {
  .cm-key-panel { transition: none; }
}
.motion-paused .cm-key-panel { transition: none; }
