*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #f4f6f9;
  color: #1c2333;
  min-height: 100vh;
}

/* ── header ── */
.feature-header {
  position: relative;
  text-align: center;
  padding: 36px 24px 20px;
}

.feature-header h1 {
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #000000;
}

.feature-header p {
  margin-top: 8px;
  color: #e41d38;
  font-size: 0.92rem;
}

/* ── layout toggle button ── */
.layout-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 14px;
  padding: 6px 14px 6px 10px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  /* border-radius: 20px; */
  font-size: 0.75rem;
  font-weight: 600;
  color: #e41d38;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
  line-height: 1.4;
}

.layout-toggle:hover:not(:disabled) {
  background: #f3f4f6;
  border-color: #d1d5db;
}

.layout-toggle[aria-pressed="true"] {
  background: #eff6ff;
  border-color: rgba(37, 99, 235, 0.4);
  color: #e41d38;
}

.layout-toggle:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.layout-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* show the correct icon based on current state */
.layout-icon--side  { display: none; }
.layout-icon--below { display: block; }

.layout-toggle[aria-pressed="true"] .layout-icon--side  { display: block; }
.layout-toggle[aria-pressed="true"] .layout-icon--below { display: none; }

/* ── side layout modifier ── */
.feature-container.layout-side {
  flex-direction: row;
  align-items: flex-start;
}

.feature-container.layout-side .image-wrapper {
  flex: 1;
  min-width: 0;
}

.feature-container.layout-side .legend {
  width: 280px;
  flex-shrink: 0;
  position: sticky;
  top: 24px;
}

/* in side layout, legend items stack as a single column */
.feature-container.layout-side .legend-items {
  grid-template-columns: 1fr;
}

/* ── layout ── */
.feature-container {
  display: flex;
  flex-direction: column;
  gap:0;
  /* padding: 12px 32px 48px; */
  max-width: 1400px;
  margin: 0 auto;
  border: 1px solid #e5e7eb;
}

/* ── image stack ── */
.image-wrapper {
  width: 100%;
  overflow: hidden;   /* clips the zoom so it doesn't spill outside the widget */
  border-radius: inherit;
}

.image-stack {
  position: relative;
  width: 100%;
  line-height: 0;
  transform-origin: 50% 50%; /* overridden per-hotspot by JS */
  transition:
    transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}

.image-stack.zoom-active {
  transform: scale(1);
}

.layer-base {
  display: block;
  width: 100%;
  height: auto;
  position: relative;
  z-index: 1;
  transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.layer-base.base-hidden {
  opacity: 0;
}

.layer-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: auto;
  display: block;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.layer-overlay.active {
  opacity: 1;
}

/* ── hotspots ── */
.hotspot {
  position: absolute;
  z-index: 20;
  cursor: pointer;
  transform: translate(-50%, -50%);
}

.hotspot-ring {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2.5px solid color-mix(in srgb, var(--layer-color) 65%, transparent);
  background: color-mix(in srgb, var(--layer-color) 18%, white);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.3s ease, background 0.3s ease, transform 0.2s ease;
  position: relative;
  /* idle breathe — pauses on hover/active via override below */
  animation: hotspot-breathe 3s ease-in-out infinite;
  animation-delay: var(--hotspot-delay, 0s);
}

.hotspot:hover {
  z-index: 30; /* raise above sibling hotspots so hover tooltip clears their rings */
}

.hotspot:hover .hotspot-ring {
  transform: scale(1.2);
  animation-play-state: paused;
}

.hotspot.active {
  z-index: 50;
}

/* While any callout card is visible, pause ring/pulse animations on ALL hotspots.
   Animated elements get promoted to GPU compositor sub-layers whose paint order
   the browser doesn't always reconcile with CSS z-index — pausing them removes
   their GPU promotion so normal z-index ordering takes over. */
.image-stack:has(.hotspot-callout.active) .hotspot-ring,
.image-stack:has(.hotspot-callout.active) .hotspot-pulse {
  animation-play-state: paused;
}

.hotspot.active .hotspot-ring {
  background: var(--layer-color);
  border-color: rgba(255, 255, 255, 0.9);
  animation-play-state: paused;
}

.hotspot-inner {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--layer-color);
  opacity: 0.8;
  transition: opacity 0.3s ease, background 0.3s ease;
}

.hotspot.active .hotspot-inner {
  background: #fff;
  opacity: 1;
}

/* idle ripple — slower, more subtle than the active pulse */
.hotspot-pulse {
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  background: transparent;
  border: 2px solid var(--layer-color);
  opacity: 0;
  pointer-events: none;
  animation: hotspot-ripple-idle 3.5s ease-out infinite;
  animation-delay: var(--hotspot-delay, 0s);
}

/* active pulse overrides the idle ripple — bigger, faster, more prominent */
.hotspot.active .hotspot-pulse {
  animation: hotspot-pulse 2s ease-out infinite;
}

@keyframes hotspot-breathe {
  0%, 100% { transform: scale(1);    }
  50%       { transform: scale(1.06); }
}

@keyframes hotspot-ripple-idle {
  0%   { transform: scale(1);   opacity: 0.25; }
  80%  { transform: scale(1.6); opacity: 0;    }
  100% { transform: scale(1.6); opacity: 0;    }
}

@keyframes hotspot-pulse {
  0%   { transform: scale(1);   opacity: 0.8; }
  100% { transform: scale(2.8); opacity: 0;   }
}

/* tooltip */
.hotspot-tooltip {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  background: rgba(255, 255, 255, 0.97);
  color: #000000;
  font-size: 1.2rem;
  font-weight: 600;
  white-space: nowrap;
  padding: 15px;
  /* border-radius: 5px; */
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  border-left: 3px solid var(--layer-color);
  transform: translateX(-50%) translateY(4px);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.hotspot:hover .hotspot-tooltip {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* hide label tooltip when the full callout card is visible */
.hotspot.active .hotspot-tooltip {
  opacity: 0;
  pointer-events: none;
}

.hotspot-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: rgba(255, 255, 255, 0.97);
}

/* ── hotspot callout card ── */
/* Callouts are absolute children of .image-stack, so inline top/left matches
   the pin position exactly. The directional classes use transform to offset the
   card to the correct side of the pin — translateX(14px) for right, and
   translateX(calc(-100% - 14px)) for left so the card's right edge sits 14 px
   left of the pin. A small extra shift is used for the enter animation. */
.hotspot-callout {
  position: absolute;
  width: 250px;
  background: #ffffff;
  border-left: 3px solid var(--layer-color);
  /* border-radius: 6px; */
  padding: 8px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.16);
  pointer-events: none;
  opacity: 0;
  z-index: 40;
  transition:
    opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* card to the RIGHT of the pin — starts 10 px further right, slides in */
.hotspot-callout--right {
  transform: translateY(-50%) translateX(24px);
}

.hotspot-callout--right.active {
  opacity: 1;
  transform: translateY(-50%) translateX(14px) translateZ(0); /* translateZ(0) forces own GPU layer at correct z-order */
  pointer-events: auto;
  cursor: pointer;
  z-index: 100;
}

/* card to the LEFT of the pin — starts 10 px further left, slides in */
.hotspot-callout--left {
  transform: translateY(-50%) translateX(calc(-100% - 24px));
}

.hotspot-callout--left.active {
  opacity: 1;
  transform: translateY(-50%) translateX(calc(-100% - 14px)) translateZ(0); /* translateZ(0) forces own GPU layer at correct z-order */
  pointer-events: auto;
  cursor: pointer;
  z-index: 100;
}

.hotspot-callout-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
}

.hotspot-callout-title {
  font-size: 1rem;
  font-weight: 700;
  /* color: var(--layer-color); */
  color: #000000;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.3;
  flex: 1;
}

.hotspot-callout-close {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
  color: #9ca3af;
  /* border-radius: 3px; */
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, background 0.15s ease;
  /* Disabled on hidden callouts — on mobile all callouts share the same fixed
     center position, so an inactive callout's button would sit on top of the
     active one and intercept taps. Only re-enable when the parent is active. */
  pointer-events: none;
}

.hotspot-callout.active .hotspot-callout-close {
  pointer-events: auto;
}

.hotspot-callout-close:hover {
  color: #000000;
  background: #f3f4f6;
}

.hotspot-callout-body {
  font-size: 1rem;
  color: #000000;
  line-height: 1.2rem;
  font-weight: 400;
  margin-bottom: 8px;
}

/* hide callouts on small screens to avoid overflow */
@media (max-width: 600px) {
  /* .hotspot-callout { display: none; } */
}

/* ── legend ── */
.legend {
  width: 100%;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  padding: 10px;
}

@media screen and (max-width: 768px) {
  .feature-container {
    display: flex;
    flex-direction: column;
    /* gap: 16px; */
  }

  .legend {
    display: none;
    order: -1;
    width: 100%;
    position: relative;
    top: auto;
    margin-bottom: 0.5rem;
  }

  .legend-select {
    order: -2;
    width: 100%;
    display: block; /* ensure visible at <=600px */
    position: relative;
    top: auto;
  }

  .mobile-callout-description {
    order: -1;
  }

  .hotspot-callout-title {
    font-size: 0.85rem;
    line-height: 1rem;
  }
  .hotspot-callout-body {
    font-size: 0.75rem;
    line-height: 1rem;
  }
  .hotspot-tooltip {
    display: none !important;
  }
}

/* On touch devices, hover tooltips cause sticky-hover overlap bugs.
   The callout card already shows the label, so tooltips are redundant. */
@media (hover: none) {
  .hotspot-tooltip {
    display: none !important;
  }
}

.legend-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid #e5e7eb;
}

.legend-title {
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #e41d38;
}

.legend-toggle-all {
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: none;
  color: #e41d38;
  border: 2px solid #e41d38;
  border-radius: 4px;
  padding: 0.4rem 1rem;
  /* border-radius: 20px; */
  transition: background 0.2s ease, border-color 0.2s ease;
  line-height: 1.4;
}

.legend-toggle-all:hover {
  background: rgba(228, 29, 56, 0.07);
  border-color: rgba(228, 29, 56, 0.6);
}

.legend-toggle-all:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* grid layout for legend items since legend is now full-width */
.legend-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px;
  margin-bottom: 15px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  /* border-radius: 8px; */
  cursor: pointer;
  border: 1px solid transparent;
  transition:
    background 0.28s ease,
    border-color 0.28s ease;
  user-select: none;
}

.legend-item:hover {
  background: #f3f4f6;
}

.legend-item.active {
  background: color-mix(in srgb, var(--layer-color) 10%, transparent);
  border-color: color-mix(in srgb, var(--layer-color) 45%, transparent);
}

.legend-swatch {
  width: 13px;
  height: 13px;
  /* border-radius: 3px; */
  flex-shrink: 0;
  background: var(--layer-color);
  /* opacity: 0.38; */
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.legend-item.active .legend-swatch {
  opacity: 1;
  transform: scale(1.15);
}

.legend-label {
  font-size: 1rem;
  line-height: 1.1rem;
  /* color: #9ca3af; */
  transition: color 0.3s ease;
  flex: 1;
}

.legend-item.active .legend-label {
  color: #000000;
}

.legend-check {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #d1d5db;
  flex-shrink: 0;
  position: relative;
  transition: border-color 0.3s ease, background 0.3s ease;
}

.legend-item.active .legend-check {
  background: var(--layer-color);
  border-color: var(--layer-color);
}

.legend-check::after {
  content: '';
  position: absolute;
  top: 43%;
  left: 50%;
  transform: translate(-55%, -60%) rotate(40deg);
  width: 3.5px;
  height: 6px;
  border-right: 2px solid #fff;
  border-bottom: 2px solid #fff;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.legend-item.active .legend-check::after {
  opacity: 1;
}

/* ── responsive ── */
@media (max-width: 1024px) {
  /* force column layout below breakpoint regardless of toggle state */
  .feature-container,
  .feature-container.layout-side {
    flex-direction: column;
  }

  .feature-container.layout-side .legend {
    width: 100%;
    position: static;
  }

  .feature-container.layout-side .legend-items {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  }
}

@media (max-width: 600px) {
  .feature-container {
    /* padding: 12px 16px 40px; */
  }

  .legend-items,
  .feature-container.layout-side .legend-items {
    grid-template-columns: 1fr;
  }
}

/* Mobile dropdown legend (shown at <= 768px) */
.legend-select {
  display: none;
  width: 100%;
  margin-top: 12px;
  padding: 10px 12px;
  font-size: 1rem;
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #000000;
  border-radius: 6px;
  padding-left: 15px;
  padding-right: 15px;

}

@media (max-width: 768px) {
  /* hide full grid legend and clear button on small screens */
  .legend-items { display: none; }
  .legend-toggle-all { display: none; }
  /* reveal the select dropdown when present in DOM */
  .legend-select { display: block; }

  /* On mobile, callout cards are replaced by the .mobile-callout-description
     panel rendered outside .feature-container — hide the in-feature cards entirely. */
  .hotspot-callout {
    display: none !important;
  }
}

/* Custom dropdown internals */
.legend-select { border: none; background: transparent; }
.legend-select__button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  padding: 12px;
  background: #fff;
  border: 1px solid #000000;
  border-radius: 4px;
  font-size: 1.2rem;
  color: #000000;
  cursor: pointer;
  text-align: left;
}
.legend-select__list {
  display: none;
  margin: 8px 0 0 0;
  padding: 6px 6px;
  list-style: none;
  border: 1px solid #e5e7eb;
  background: #fff;
  border-radius: 4px;
  max-height: 320px;
  overflow: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
}
.legend-select__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: 1.2rem;
}
.legend-select__item:hover,
.legend-select__item.active { background: #f3f4f6; }
.legend-select__swatch {
  width: 14px;
  height: 14px;
  /* border-radius: 3px; */
  flex-shrink: 0;
  box-shadow: 0 1px 0 rgba(0,0,0,0.05) inset;
}
.legend-select__label { color: #000000; }

/* Swatch inside the trigger button — hidden until a layer is selected (JS sets display:inline-block when active) */
.legend-select__button-swatch {
  display: none;
  flex-shrink: 0;
}
.legend-select__button-text {
  flex: 1;
  text-align: left;
}
.legend-select__chevron {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  color: #000000;
  transition: transform 0.2s ease;
}
.legend-select__chevron svg {
  width: 18px;
  height: 18px;
  display: block;
}
.legend-select__chevron.open {
  transform: rotate(180deg);
}

/* ── mobile description panel ── */
/* Shown outside .feature-container on mobile (≤768px) when a hotspot is
   active. JS toggles the [hidden] attribute to show/hide; CSS controls
   display at the desktop breakpoint. */
.mobile-callout-description {
  padding: 10px 15px;
  background: #ffffff;
  border-top: 2px solid var(--layer-color);
  border-bottom: 2px solid var(--layer-color);
  font-size: 1rem;
  color: #000000;
  line-height: 1.5;
}
.mobile-callout-description p {
  margin-bottom: 0;
}

@media (min-width: 769px) {
  .mobile-callout-description {
    display: none !important;
  }
}
