/* Humedales · globe surface (archive_index, dataviz: sidebar).
   The zone (#hero-left) is the canvas. Land, sea and border tones are variables
   so the palette can move without touching geometry. */

#viz-app {
  --globe-land: #4e4e56;
  --globe-sea: #2b2b32;
  --globe-border: #2b2b2f;
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100%;
}

/* The right-to-left veil the image zone carried — a_layout.css draws it as a
   ::before, and .no-img is exactly what suppresses it, so the map inherits
   nothing and has to paint it. Solid page colour where the column sits, fading
   out across the globe, so the zone's right edge stops being a hard cut and the
   text keeps a ground of its own. */
#viz-app::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: linear-gradient(to left,
    rgba(39, 39, 42, 1) 0%,
    rgba(39, 39, 42, 1) 12%,
    rgba(39, 39, 42, 0) 42%);
}

/* below lg the column sits under the zone, not beside it: the veil turns */
@media (max-width: 1023px) {
  #viz-app::after {
    background: linear-gradient(to top,
      rgba(39, 39, 42, 1) 0%,
      rgba(39, 39, 42, 1) 10%,
      rgba(39, 39, 42, 0) 45%);
  }
}

/* The zone is `position: fixed` with `width: auto`. An image gave it a width by
   its intrinsic size; a drawing has none, so the zone collapses to 0 and the
   globe renders into nothing. 100% of a fixed element resolves against the
   viewport, and the template's lg:max-w-[110vh] still caps it. */
@media (min-width: 1024px) {
  #hero-left.no-img {
    width: 100%;
    overflow: hidden;
  }
}

#viz-app svg.globe {
  display: block;
  width: 100%;
  height: 100%;
}

#viz-app .globe-land path {
  fill: var(--globe-land);
  stroke: var(--globe-border);
  stroke-width: 0.4;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

/* the sea is a touch lighter than the page, so the sphere reads as a disc
   without a plate; land sits darker on top of it */
#viz-app .globe-sphere {
  fill: var(--globe-sea);
  stroke: none;
}

/* routes and points fade in once the data is bound */
#viz-app .globe-routes,
#viz-app .globe-dots,
#viz-app .globe-hub {
  opacity: 0;
  transition: opacity 0.9s ease;
}

#viz-app svg.on .globe-routes,
#viz-app svg.on .globe-dots,
#viz-app svg.on .globe-hub {
  opacity: 1;
}

#viz-app .globe-routes path {
  fill: none;
  stroke-width: 1.4;
  stroke-linecap: round;
  opacity: 0.6;
  vector-effect: non-scaling-stroke;
  transition: opacity 0.35s ease, stroke-width 0.35s ease;
}

#viz-app .globe-dots circle {
  opacity: 0.85;
  transition: opacity 0.35s ease;
}

/* one piece is playing: its own lines stay, everything else recedes */
#viz-app svg.active .globe-routes path { opacity: 0.08; }
#viz-app svg.active .globe-routes path.hl { opacity: 1; stroke-width: 2.4; }
#viz-app svg.active .globe-dots circle { opacity: 0.1; }
#viz-app svg.active .globe-dots circle.hl { opacity: 1; }

/* the piece's own lines draw themselves in once, then keep crawling along the
   flow direction — the path is already built that way, so no reversed animation */
#viz-app svg.active .globe-routes path.hl.drawin {
  /* pathLength="1" on the element: the dash is expressed in the path's own unit
     space, so a changing projection cannot shorten it */
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: globeDrawIn 0.75s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

#viz-app svg.active .globe-routes path.hl.flow {
  stroke-dasharray: 6 12;
  animation: globeFlow 1.5s linear infinite;
}

@keyframes globeDrawIn {
  to { stroke-dashoffset: 0; }
}

@keyframes globeFlow {
  to { stroke-dashoffset: -18; }
}

@media (prefers-reduced-motion: reduce) {
  #viz-app svg.active .globe-routes path.hl.drawin {
    animation: none;
    stroke-dasharray: none;
    stroke-dashoffset: 0;
  }
  #viz-app svg.active .globe-routes path.hl.flow {
    animation: none;
    stroke-dasharray: none;
  }
}

/* The zone is at z-index -10, which makes it a stacking context: nothing inside
   it — legend included — can rise above #page-content, the full-width block the
   archive layout pulls up over the zone. It is transparent there but still takes
   the pointer, so the legend could never be hovered. Let the empty part of the
   page pass events through and give the content column its own back. */
.archive-index #page-content {
  pointer-events: none;
}

.archive-index #contentbar {
  pointer-events: auto;
}

/* The legend lives in the sidebar: above the content (z-10), a normal surface
   that can take a hover, unlike anything drawn in the zone behind the page.
   Right-aligned, which is how the sidebar's own content sits. */
.globe-legend {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  gap: 0.4rem;
  width: 100%;
  font-size: 13px;
  line-height: 1.3;
  margin-bottom: 0rem;
}

.globe-legend-row {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  cursor: default;
  transition: opacity 0.25s ease;
}

/* At rest, hovering one key fades the other two out, so the hovered family is
   the only thing read. While a piece plays the legend is describing that piece
   and the hover is cancelled — hence :not(.playing). */
.globe-legend:not(.playing):has(.globe-legend-row:hover) .globe-legend-row:not(:hover) {
  opacity: 0.3;
}

.globe-legend-swatch {
  flex: none;
  width: 18px;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
  transform: translateY(-2px);
}

.globe-legend-title {
  font-weight: 600;
}

.globe-legend-desc {
  font-weight: 400;
  opacity: 0.72;
}

/* while a piece plays the legend carries the piece's own sources: the note on
   top, and each row's detail replacing the generic description */
.globe-legend-note {
  color: #b9b9c2;
  font-size: 13px;
  line-height: 1.35;
  margin: 0 0 0.45rem;
  max-width: 34rem;
  display: none;
}

.globe-legend-detail {
  display: none;
  font-weight: 400;
  opacity: 0.85;
}

.globe-legend-detail i {
  font-style: italic;
}

.globe-legend.playing .globe-legend-note,
.globe-legend.playing .globe-legend-detail {
  display: inline;
}

.globe-legend.playing .globe-legend-desc {
  display: none;
}

/* the note needs the width only desktop has: below lg the rows stand alone */
@media (max-width: 1023px) {
  .globe-legend.playing .globe-legend-note {
    display: none;
  }
}

/* No legend below lg: no play buttons and no hover there, so it has nothing to
   isolate or name — and it keeps the mobile navigation clean without the app
   knowing anything about the nav's state.
   Declared last in this section on purpose: the base rule sets display:flex, and
   with equal specificity only a later rule can overrule it. */
@media (max-width: 1023px) {
  .globe-legend {
    display: none;
  }
}

/* isolation: the hovered layer stays, every other line recedes — only while
   nothing is playing. Once a piece is on screen the legend describes that piece
   and a hover must not disturb its lines, so .active silences the whole group. */
#viz-app svg[data-isolate]:not(.active) .globe-routes path { opacity: 0.06; }
#viz-app svg[data-isolate]:not(.active) .globe-dots circle { opacity: 0.08; }
#viz-app svg[data-isolate="aves"]:not(.active) .globe-routes path[data-layer="aves"],
#viz-app svg[data-isolate="migraciones"]:not(.active) .globe-routes path[data-layer="migraciones"],
#viz-app svg[data-isolate="peregrinaciones"]:not(.active) .globe-routes path[data-layer="peregrinaciones"] { opacity: 1; }
#viz-app svg[data-isolate="aves"]:not(.active) .globe-dots circle[data-layer="aves"],
#viz-app svg[data-isolate="migraciones"]:not(.active) .globe-dots circle[data-layer="migraciones"],
#viz-app svg[data-isolate="peregrinaciones"]:not(.active) .globe-dots circle[data-layer="peregrinaciones"] { opacity: 1; }

#viz-app .globe-hub .hub-halo {
  fill: rgba(255, 224, 102, 0.12);
  stroke: rgba(255, 224, 102, 0.45);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

#viz-app .globe-hub .hub-dot {
  fill: #ffe066;
}

/* place names, only while a piece is on screen, in the colour of the line they
   belong to — no halo, no shadow */
#viz-app .globe-labels text {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease;
}

#viz-app svg.on .globe-labels.on text {
  opacity: 1;
}
