/* Page layouts: portada, directorio, ficha, proyecto — and the 390px behaviour. */

/* ---------------------------------------------------------------- portada */

.ap-hero {
  position: relative;
  background: var(--cielo-alto);
  /* The sky is bright, so the hero's own ink is night. Everything readable
     lives on the plate anyway; this is the safety net for anything that
     someday does not. */
  color: var(--noche);
  overflow: hidden;
  padding: 0 0 64px;
  /* Room for the tree. Without a floor the hero is only as tall as the plate,
     and the canopy gets cropped to a hedge. */
  min-height: min(780px, 84vh);
}
/* The sky the tree stands against: the prototype's, sun low behind the trunk.
   The one gradient in the system, and the reason the hero is not a flat green
   plate — the tree needs somewhere to be. */
.ap-hero__bg {
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 92% at 50% 104%,
    var(--sol-1) 0%, var(--sol-2) 22%, var(--sol-3) 40%,
    var(--cielo) 76%, var(--cielo-alto) 100%);
}
/* Host for static/js/tree.js. Empty without JavaScript, and the hero still
   reads: sky, plate, type. Nothing here is content. */
.ap-hero__tree {
  position: absolute;
  /* Exactly the hero box: the script sizes the drawing from this element, so
     any overhang is drawn and then clipped — wasted pixels and a cropped crown. */
  inset: 0;
  z-index: 2;
  pointer-events: none;
}
.ap-hero__inner {
  position: relative;
  /* Above the tree, which is z-index 2. Without this the canopy paints over
     the plate: both are positioned, and the one that declares a z-index wins
     regardless of document order. */
  z-index: 6;
  max-width: var(--ancho-ficha);
  margin: 0 auto;
  padding: 72px 22px 0;
}
.ap-hero__plate {
  background: var(--crema);
  color: var(--noche);
  border-radius: var(--radio-tarjeta);
  padding: 34px 36px 32px;
  max-width: 720px;
  box-shadow: var(--sombra-plato);
}
.ap-hero__title {
  font-family: var(--font-display);
  font-size: clamp(3rem, 7.2vw, 102px);
  line-height: .84;
  letter-spacing: -.025em;
  max-width: 9ch;
  font-weight: 400;
}
.ap-hero__dot { color: var(--ambar); }
.ap-hero__sub {
  margin-top: 16px;
  font-size: clamp(15px, 1.5vw, 19px);
  font-weight: 500;
  max-width: 36ch;
}
.ap-hero__actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }


/* ---------------------------------------------------------------- directorio */

.ap-directory__head {
  background: var(--crema);
  border-bottom: var(--borde-fuerte);
}
.ap-directory__head-inner {
  max-width: var(--ancho-directorio);
  margin: 0 auto;
  padding: 30px 24px 22px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 520px);
  gap: 26px;
  align-items: end;
}
.ap-directory__title {
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 5.4vw, 4.4rem);
  line-height: .86;
  letter-spacing: -.02em;
  font-weight: 400;
}
.ap-directory__body {
  max-width: var(--ancho-directorio);
  margin: 0 auto;
  padding: 24px 24px 70px;
  display: grid;
  grid-template-columns: var(--riel) minmax(0, 1fr);
  gap: 26px;
  align-items: start;
}
.ap-rail {
  position: sticky;
  top: var(--sticky-offset);
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  display: grid;
  gap: 20px;
  padding-right: 6px;
}
.ap-facet__options { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.ap-facet__options--column { display: grid; gap: 7px; }
.ap-facet__options--months { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.ap-facet__note { margin-top: 8px; font-size: 12.5px; font-weight: 500; line-height: 1.35; }

/* Family rows: a 1px ink gap between them reads as a hairline table. */
.ap-families { display: grid; gap: 1px; background: rgba(16, 32, 26, .16); margin-top: 10px; }
.ap-family {
  border: 0;
  background: var(--crema);
  color: var(--noche);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 9px 4px;
  font-family: var(--font-body);
  cursor: pointer;
  text-align: left;
  min-height: 38px;
  text-decoration: none;
}
.ap-family[aria-current] { background: var(--noche); color: var(--ambar); }
.ap-family__name { font-weight: 700; font-size: 14px; }
.ap-family__count {
  font-stretch: var(--label-stretch);
  font-weight: 800;
  font-size: 10px;
  letter-spacing: .1em;
  opacity: .65;
}

.ap-directory__results { display: grid; gap: 18px; }
.ap-directory__chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.ap-empty { padding: 34px 30px; max-width: 64ch; }
.ap-empty__title {
  font-family: var(--font-display);
  font-size: 32px;
  line-height: 1;
  max-width: 24ch;
  font-weight: 400;
}
.ap-empty__body { margin-top: 14px; font-weight: 500; }
.ap-empty__actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }

/* The mobile filter trigger; the rail replaces it from 900px up. */
.ap-directory__open { display: none; justify-self: start; }

/* ---------------------------------------------------------------- ficha */

.ap-sheet__head {
  position: relative;
  overflow: hidden;
  background: var(--verde);
  color: var(--crema);
  padding-bottom: 8px;
}
.ap-sheet__crowns {
  position: absolute;
  top: -40px;
  right: -120px;
  width: 760px;
  max-width: 80%;
  opacity: .42;
  pointer-events: none;
}
.ap-sheet__crowns ellipse { animation: viento 9s ease-in-out infinite alternate; transform-origin: center; }
@keyframes viento {
  from { transform: rotate(-.9deg) translateY(0); }
  to { transform: rotate(.9deg) translateY(-6px); }
}
.ap-sheet__head-inner {
  max-width: var(--ancho-ficha);
  margin: 0 auto;
  padding: 26px 22px 0;
  position: relative;
  z-index: 5;
}
.ap-sheet__identity {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(300px, .75fr);
  gap: 34px;
  align-items: end;
  padding: 18px 0 34px;
}
.ap-sheet__name {
  font-family: var(--font-display);
  font-size: var(--display-h1);
  line-height: var(--display-line);
  letter-spacing: -.02em;
  color: var(--crema);
  font-weight: 400;
}
.ap-sheet__bin {
  margin-top: 10px;
  font-style: italic;
  font-weight: 500;
  font-size: clamp(1.15rem, 2.6vw, 1.7rem);
  line-height: 1.1;
}
.ap-names {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  margin-top: 22px;
  max-width: 58ch;
}
.ap-name {
  display: flex;
  align-items: baseline;
  gap: 7px;
  border: 2px solid var(--crema-borde);
  border-radius: var(--radio-pill);
  padding: 5px 13px 6px;
}
.ap-name__text { font-weight: 700; font-size: 14.5px; }
.ap-sheet__provenance {
  margin-top: 12px;
  font-size: 13px;
  font-weight: 500;
  opacity: .88;
  max-width: 56ch;
}

/* --verde is the lightest ground the archive puts cream text on: 5.82:1 at full
   opacity, so anything faded below .85 falls under AA. --selva has enough
   headroom that the usual .7 is fine there. axe caught this on the sheet header. */
.ap-sheet__head .ap-label--muted,
.ap-sheet__head .ap-authority,
.ap-sheet__head .ap-breadcrumbs { opacity: .88; }

.ap-sheet__body {
  max-width: var(--ancho-ficha);
  margin: 0 auto;
  padding: 34px 22px 70px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 340px);
  gap: 34px;
  align-items: start;
}
.ap-sheet__main { display: grid; gap: 26px; }
.ap-sheet__aside {
  display: grid;
  gap: 20px;
  position: sticky;
  top: var(--sticky-offset);
}
.ap-sheet__section > .ap-prose { margin-top: 14px; }

.ap-calendar__row {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}
.ap-calendar__text {
  margin-top: 12px;
  min-height: 3.4em;
  font-weight: 500;
  font-size: 14.5px;
  line-height: 1.4;
}
.ap-calendar__foot {
  margin-top: 10px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  border-top: 2px solid var(--linea-suave);
  padding-top: 9px;
}

.ap-sheet__photo figcaption { margin-top: 8px; }

/* ---------------------------------------------------------------- proyecto */

.ap-about__figures {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 18px;
  margin-top: 22px;
}
.ap-figure__number {
  font-family: var(--font-display);
  font-size: 46px;
  line-height: .9;
  display: block;
  font-weight: 400;
}
.ap-figure__foot { margin-top: 8px; display: block; }

/* ---------------------------------------------------------------- panel de filtros (movil) */

.ap-panel { display: none; }
.ap-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--noche);
  color: var(--crema);
}
.ap-panel__title {
  font-stretch: var(--title-stretch);
  font-weight: 900;
  font-size: 19px;
  text-transform: uppercase;
  letter-spacing: -.01em;
}
.ap-panel__close {
  border: 2px solid var(--crema-borde);
  background: transparent;
  color: var(--crema);
  border-radius: var(--radio-pill);
  width: 44px;
  height: 44px;
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}
.ap-panel__body { flex: 1; overflow-y: auto; padding: 16px 16px 20px; display: grid; gap: 20px; }
.ap-panel__foot {
  display: flex;
  gap: 9px;
  padding: 12px 16px 16px;
  border-top: var(--borde-fuerte);
  background: var(--crema);
}
.ap-panel__foot .ap-button { min-height: 46px; justify-content: center; }
.ap-panel__foot .ap-button--amber { flex: 1; }

/* ---------------------------------------------------------------- responsive */

@media (max-width: 1080px) {
  .ap-sheet__body { grid-template-columns: minmax(0, 1fr); }
  .ap-sheet__aside { position: static; }
  .ap-sheet__identity { grid-template-columns: minmax(0, 1fr); gap: 24px; }
}

@media (max-width: 900px) {
  .ap-directory__body { grid-template-columns: minmax(0, 1fr); }
  .ap-directory__head-inner { grid-template-columns: minmax(0, 1fr); }

  /* The rail becomes a full-screen sheet, opened by a 44px pill. */
  .ap-directory__open { display: inline-flex; }
  .ap-rail { display: none; }

  .ap-panel {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 90;
    background: var(--crema);
    flex-direction: column;
  }
  .ap-panel:target,
  .ap-panel.is-open { display: flex; }
  .ap-panel .ap-rail { display: grid; position: static; max-height: none; overflow: visible; }
}

@media (max-width: 620px) {
  :root { --canal: 16px; }

  .ap-nav__inner { padding: 0 16px; }
  .ap-nav__links { gap: 14px; }
  .ap-nav__link { font-size: 11.5px; }

  .ap-hero__inner { padding: 40px 16px 0; }
  .ap-hero__plate { padding: 24px 20px 22px; }

  .ap-sheet__head-inner,
  .ap-sheet__body { padding-inline: 16px; }
  .ap-directory__head-inner,
  .ap-directory__body { padding-inline: 16px; }

  .ap-grid { grid-template-columns: minmax(0, 1fr); }

  .ap-nav__links { display: none; }
  .ap-nav__menu { display: block; }

  /* Mobile species card: text | 88px photo, bloom bar spanning beneath.
     Placement is explicit because the photo comes first in source order — it has
     to, for the absolutely-positioned desktop treatment. */
  .ap-species {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 88px;
    grid-template-rows: auto auto auto;
    gap: 12px;
    min-height: 0;
    padding: 15px;
    box-shadow: var(--sombra-movil);
  }
  .ap-species:hover { transform: none; }
  .ap-species__text { grid-column: 1; grid-row: 1 / span 2; }
  .ap-species__photo { grid-column: 2; grid-row: 1; }
  .ap-species__side { grid-column: 2; grid-row: 2; margin-top: 0; gap: 7px; }
  .ap-species__foot { grid-column: 1 / -1; grid-row: 3; }
  .ap-species__photo {
    position: static;
    width: auto;
    height: 78px;
    aspect-ratio: auto;
    border-radius: 999px 999px 12px 12px;
    padding: 4px;
  }
  .ap-species__name,
  .ap-species__bin,
  .ap-species__labels { max-width: none; }
  .ap-species__measure { margin-top: 0; padding-top: 0; max-width: none; }
  .ap-species__height { font-size: 21px; text-align: right; }
  .ap-species__foot {
    gap: 5px;
    border-top: 1.5px solid currentColor;
    padding-top: 9px;
  }
  .ap-species__months { max-width: none; margin-top: 0; }
  .ap-species__month { height: 8px; }
  .ap-species__note { max-width: none; }
  .ap-species__close-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-stretch: var(--label-stretch);
    font-weight: 800;
    font-size: 9px;
    letter-spacing: .11em;
    text-transform: uppercase;
    line-height: 1.3;
  }

  .ap-footer__inner { grid-template-columns: minmax(0, 1fr); gap: 26px; padding: 34px 16px 30px; }
}

/* Touch targets never fall below 44px on a phone. */
@media (pointer: coarse) {
  .ap-button,
  .ap-pill,
  .ap-chip { min-height: 44px; }
  .ap-pill--square { min-height: 44px; }
}
