/* ==========================================================================
   Life and Conservation Stylesheet
   ========================================================================== */

/* --- Visibility and Stacking --- */
#life {
  position: fixed;
  inset: 0;
  z-index: 46;
  background: #a8cad6;
  color: var(--text);
  font-family: var(--font-sans);
}

/* The hidden attribute loses to author display rules, so restate it. */
#life[hidden],
#life-card[hidden],
#life-range-key[hidden],
#life-species-list[hidden] {
  display: none;
}

#life-map {
  position: absolute;
  inset: 0;
}

body.view-life > :not(#life, #buddy-sprite, #buddy-bubble) {
  visibility: hidden;
  pointer-events: none;
}

body.morphing #life {
  pointer-events: none;
}

/* --- Panel Glass --- */
#life-head,
#life-layers,
#life-species,
#life-range-key,
#life-card {
  background: var(--surface-glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-float);
}

/* --- Header --- */
#life-head {
  position: absolute;
  top: 56px;
  left: 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  max-width: calc(100vw - 420px);
  background:
    linear-gradient(90deg, rgba(17, 23, 32, 0.95) 0%, rgba(17, 23, 32, 0.86) 55%, rgba(17, 23, 32, 0.35) 100%),
    url(./assets/life/header.webp) right center / cover no-repeat;
}

#life-back {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 2;
}

#life-title h1 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}

#life-title p {
  font-size: 12px;
  color: var(--muted);
  margin: 2px 0 0;
}

#life-guide {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: 8px;
}

#life-guide > * {
  position: static;
  margin: 0;
}

/* --- Layers --- */
#life-layers {
  position: absolute;
  left: 16px;
  top: 132px;
  padding: 8px 12px;
  font-size: 13px;
}

#life-layers label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  cursor: pointer;
}

#life-layers input {
  accent-color: var(--accent);
}

.life-sw {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: none;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.life-sw-forest {
  background: linear-gradient(90deg, #1d6b34 0 50%, #5fa05a 50% 100%);
}

.life-sw-loss {
  background: #ec6f2d;
}

.life-sw-canopy {
  background: #3f9a43;
}

.life-sw-closed {
  background: #1d6b34;
}

.life-sw-open {
  background: #5fa05a;
}

.life-sw-missed {
  background: #a6cf7e;
}

.life-sw-other {
  background: #d8cf8a;
}

.life-sw-mangroves {
  background: #8e44ad;
}

.life-sw-coral {
  background: #ff6f61;
}

.life-sw-parks {
  background: #1f7a3a;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  width: 10px;
  height: 10px;
}

#life-forest-key {
  list-style: none;
  margin: 0 0 4px 24px;
  padding: 0;
  font-size: 12px;
  color: var(--muted, #555);
}

#life-forest-key li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 1px 0;
}

#life-layers:has(input[data-layer="forest"]:not(:checked)) #life-forest-key {
  display: none;
}

.life-ramp {
  margin: 0 0 4px 24px;
  font-size: 12px;
  color: var(--muted, #555);
  max-width: 180px;
}

.life-ramp-bar {
  height: 8px;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.life-ramp-loss {
  background: linear-gradient(90deg, #f7dc6f 0 20%, #f5a742 20% 40%, #ec6f2d 40% 60%, #cf3a1f 60% 80%, #8e1212 80% 100%);
}

.life-ramp-canopy {
  background: linear-gradient(90deg, #d4ecb0, #8cc56a, #3f9a43, #1d6b34, #0b3d1d);
}

.life-ramp-ends {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  margin-top: 1px;
}

.life-hint {
  font-size: 11px;
  margin-top: 2px;
}

#life-layers:has(input[data-layer="loss"]:not(:checked)) #life-loss-key,
#life-layers:has(input[data-layer="canopy"]:not(:checked)) #life-canopy-key {
  display: none;
}

/* --- Species Panel --- */
#life-species {
  position: absolute;
  top: 16px;
  right: 16px;
  bottom: 16px;
  width: 360px;
  overflow-y: auto;
  padding: 14px;
}

#life-species h2 {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 10px;
}

/* --- Photo Strip --- */
#life-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  padding: 2px 2px 8px;
  margin: 0 0 10px;
}

#life-strip:empty {
  display: none;
}

.life-strip-item {
  flex: none;
  width: 64px;
  height: 64px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel-2);
  cursor: pointer;
  scroll-snap-align: start;
}

.life-strip-item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.life-strip-item:hover,
.life-strip-item:focus-visible {
  border-color: var(--accent);
  outline: none;
}

#life-species-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.life-sp {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 6px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  cursor: pointer;
}

.life-sp:hover,
.life-sp:focus-visible {
  background: var(--panel-2);
  border-color: var(--border);
}

.life-sp-thumb {
  width: 56px;
  height: 56px;
  flex: none;
  object-fit: cover;
  border-radius: 6px;
  background: var(--panel-2);
}

.life-sp-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.life-sp-name {
  font-size: 14px;
  font-weight: 600;
}

.life-sp-sub {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Conservation Status Chips --- */
.life-chip {
  flex: none;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 999px;
}

.life-chip-cr {
  background: #d81e05;
  color: #fff;
}

.life-chip-en {
  background: #fc7f3f;
  color: #000;
}

.life-chip-vu {
  background: #f9e814;
  color: #000;
}

.life-chip-nt {
  background: #cce226;
  color: #000;
}

.life-chip-lc {
  background: #60c659;
  color: #000;
}

/* --- Species Card --- */
#life-card-back {
  display: inline-block;
  font-size: 12px;
  color: var(--accent);
  background: transparent;
  border: 0;
  padding: 0;
  margin-bottom: 8px;
  cursor: pointer;
}

#life-card-back:hover {
  text-decoration: underline;
}

.life-card-photo {
  display: block;
  width: 100%;
  height: auto;
  max-height: 240px;
  object-fit: cover;
  border-radius: 8px;
}

#life-card h3 {
  font-size: 18px;
  margin: 10px 0 2px;
}

.life-card-names {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 8px;
}

.life-card-status,
.life-card-where,
.life-card-fact {
  font-size: 13px;
  line-height: 1.5;
  margin: 0 0 8px;
}

#life-card a {
  color: var(--accent);
}

#life-range-btn {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

#life-range-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--bg);
}

#life-range-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.life-card-note {
  font-size: 12px;
  color: var(--muted);
}

.life-card-gbif {
  display: inline-block;
  margin: 8px 0;
  font-size: 13px;
}

.life-card-credit {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

/* --- Park Card --- */
.life-gallery {
  position: relative;
  margin: 0 0 10px;
  container-type: inline-size;
}

.life-gallery .life-card-photo {
  aspect-ratio: 3 / 2;
  height: auto;
  max-height: none;
  object-fit: cover;
}

.life-gal-prev,
.life-gal-next {
  position: absolute;
  top: calc(100cqw / 3 - 16px);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 0;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.life-gal-prev {
  left: 8px;
}

.life-gal-next {
  right: 8px;
}

.life-gal-prev:hover,
.life-gal-next:hover {
  background: rgba(0, 0, 0, 0.72);
}

.life-gal-prev:focus-visible,
.life-gal-next:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.life-gal-count {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 11px;
}

.life-gallery .life-card-credit {
  margin: 6px 0 0;
}

.life-card-kind {
  font-size: 12px;
  color: var(--muted);
  margin: 2px 0 6px;
}

.life-park-facts {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 8px;
}

.life-park-summary {
  font-size: 13px;
  line-height: 1.5;
  margin: 0 0 8px;
}

.life-park-source {
  font-size: 11px;
  color: var(--muted);
}

.life-park-links {
  display: flex;
  gap: 12px;
  font-size: 13px;
  margin: 0;
}

/* --- Range Key --- */
#life-range-key {
  position: absolute;
  left: 16px;
  bottom: 40px;
  width: 260px;
  padding: 10px 12px;
  font-size: 12px;
}

#life-range-key strong {
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
}

.life-key-bar {
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(90deg, #fed976, #feb24c, #fd8d3c, #f03b20, #bd0026);
}

.life-key-ends {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.life-key-note {
  font-size: 11px;
  color: var(--muted);
  margin: 6px 0 0;
  line-height: 1.4;
}

/* --- Map Markers (light map, dark text) --- */
.life-city {
  display: flex;
  align-items: center;
  gap: 4px;
  pointer-events: none;
}

.life-city-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #33404d;
}

.life-city-name {
  font-size: 11px;
  font-weight: 600;
  color: #2a3540;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff;
  white-space: nowrap;
}

.life-pin {
  width: 14px;
  height: 14px;
  padding: 0;
  border-radius: 50%;
  background: #1f7a3a;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
  cursor: pointer;
}

.life-pin:hover,
.life-pin:focus-visible {
  transform: scale(1.25);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Wide Screens: keep map controls clear of the species panel --- */
#life .maplibregl-ctrl-bottom-right {
  margin-right: 392px;
}

/* The open credits wrap short of the map buttons. */
#life .maplibregl-ctrl-bottom-left {
  max-width: calc(100% - 470px);
}

#life #life-home svg {
  display: block;
  margin: auto;
}

/* --- Narrow Screens --- */
@media (max-width: 899px) {
  #life-back {
    top: 12px;
    left: 12px;
  }
}

@media (max-width: 700px) {
  #life-head {
    left: 8px;
    right: 8px;
    top: 52px;
    max-width: none;
    flex-wrap: wrap;
    padding: 8px 10px;
  }

  #life-title p {
    display: none;
  }

  #life-layers {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: calc(45vh + 44px);
    display: flex;
    flex-wrap: wrap;
    gap: 2px 12px;
    padding: 6px 10px;
  }

  #life-forest-key,
  #life-loss-key,
  #life-canopy-key {
    display: none;
  }

  #life-species {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: 45vh;
    border-radius: 14px 14px 0 0;
  }

  #life-range-key {
    left: 8px;
    bottom: calc(45vh + 110px);
    width: 220px;
  }

  #life .maplibregl-ctrl-bottom-right {
    margin-right: 0;
    margin-bottom: 45vh;
  }

  /* The credits sit above the species sheet, not over it. */
  #life .maplibregl-ctrl-bottom-left {
    margin-bottom: 45vh;
    max-width: calc(100% - 60px);
  }
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
  .life-pin:hover {
    transform: none;
  }
}
