/* =====================================================================
   The Portrait Archive (/portraits). Loaded after style.css; reuses its
   brand tokens, .btn, .section-head, .is-locked, and the .lightbox__close /
   .lightbox__arrow chrome, which the living-portrait overlay borrows.
   ===================================================================== */

.archive-page { padding: 8rem 1.25rem clamp(3rem, 7vw, 5rem); }
.archive__lead {
  max-width: 56ch; margin: -1rem auto 0; text-align: center;
  color: var(--ink-dim); font-size: 1.05rem;
}

/* ---------- Filters ---------- */
.filters {
  max-width: 900px; margin: 2.4rem auto 0; padding: 1.2rem 1.3rem 1rem;
  border: 1px solid rgba(123, 123, 224, 0.18); border-radius: 10px;
  background: rgba(8, 8, 36, 0.5);
}
.filters__group { border: 0; margin: 0 0 0.9rem; padding: 0; }
.filters__legend {
  padding: 0 0 0.5rem;
  font-family: var(--font-display); font-size: 0.68rem; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--sun-soft);
}
.filters__chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip {
  padding: 0.4em 0.85em; border-radius: 999px;
  border: 1px solid rgba(123, 123, 224, 0.35);
  background: transparent; color: var(--ink);
  font-family: var(--font-display); font-size: 0.72rem; letter-spacing: 0.08em;
  text-transform: uppercase; cursor: pointer;
  transition: border-color 0.18s ease, color 0.18s ease, background 0.18s ease;
}
.chip:hover { border-color: rgba(253, 206, 28, 0.6); color: var(--light); }
.chip:focus-visible { outline: 2px solid var(--sun-gold); outline-offset: 2px; }
.chip.is-on {
  border-color: var(--sun-gold); color: var(--night);
  background: var(--sun-gold); font-weight: 700;
}
.filters__foot {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin-top: 0.2rem; padding-top: 0.8rem;
  border-top: 1px solid rgba(123, 123, 224, 0.14);
}
.filters__count { margin: 0; color: var(--ink-dim); font-size: 0.92rem; }
.filters__clear {
  padding: 0; border: 0; background: none; cursor: pointer;
  color: var(--sun-soft); font-family: var(--font-body); font-size: 0.9rem;
  text-decoration: underline; text-underline-offset: 3px;
}
.filters__clear:hover { color: var(--sun-gold); }

/* The one thing a visitor has to know to get the good part. */
.archive__cue {
  margin: 2.4rem auto 0; text-align: center;
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(1.05rem, 2.4vw, 1.5rem); letter-spacing: 0.08em;
  color: var(--sun-gold);
}

/* ---------- The grid ---------- */
.archive {
  max-width: 1180px; margin: 1.2rem auto 0;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 12px;
}
.archive__state { text-align: center; color: var(--ink-dim); }
.archive__face {
  position: relative; aspect-ratio: 1; padding: 0; overflow: hidden;
  border-radius: 8px; border: 1px solid rgba(123, 123, 224, 0.16);
  background: radial-gradient(circle at 50% 36%, #15163a, #07071a);
  cursor: zoom-in;
  transition: transform 0.2s ease, box-shadow 0.25s ease, border-color 0.2s ease;
}
/* Race stature: the tile's data-race sets --stature (css/portrait-stature.css,
   generated). Scaled about the bottom edge so every bust shares a baseline and
   short folk sit lower in the frame; --stature-fit sizes the frame for the
   tallest race so nothing is cropped. */
.archive__face img {
  width: 100%; height: 100%; object-fit: contain; object-position: center bottom;
  display: block; transform-origin: center bottom;
  transform: translateY(5%) scale(calc(var(--stature, 1) * var(--stature-fit, 1)));
  filter: brightness(0.6) saturate(0.84) contrast(0.98);
  transition: filter 0.25s ease;
}
.archive__face:hover, .archive__face:focus-visible {
  transform: scale(1.5); z-index: 5; outline: none;
  border-color: rgba(253, 206, 28, 0.6);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.7), 0 0 26px rgba(253, 206, 28, 0.4);
}
.archive__face:hover img, .archive__face:focus-visible img {
  filter: brightness(1.08) saturate(1.08) contrast(1.02);
}
.archive__face .face__label {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  padding: 0.6em 0.3em 0.4em;
  font-family: var(--font-display); font-size: 0.5rem; letter-spacing: 0.05em;
  line-height: 1.3; text-transform: uppercase; text-align: center; color: var(--sun-gold);
  background: linear-gradient(transparent, rgba(2, 2, 20, 0.94) 60%);
  opacity: 0; transition: opacity 0.2s ease; pointer-events: none;
}
.archive__face:hover .face__label,
.archive__face:focus-visible .face__label { opacity: 1; }

.archive__more { text-align: center; margin-top: 2.2rem; }

/* ---------- The living portrait ---------- */
.living {
  position: fixed; inset: 0; z-index: 100;
  /* Race stature applies here too (data-race on this overlay), but without the
     grid's fit factor: the panel has no neighbour to compare against, and its
     motion is ~1% of its size, so shrinking it to 0.52 for a hobbit left the
     portrait looking nearly still. Humans open at the full 560px; short folk
     smaller, tall folk larger. */
  --stature-fit: 1;
  display: flex; align-items: center; justify-content: center;
  padding: clamp(0.75rem, 2vmin, 1.5rem);
  background: rgba(1, 1, 16, 0.9);
  -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px);
  opacity: 0; transition: opacity 0.25s ease;
}
.living[hidden] { display: none; }
.living.is-visible { opacity: 1; }
.living__frame {
  position: relative; display: flex; flex-direction: column; align-items: center;
  gap: 0.6rem; max-width: 100%; max-height: 100%;
}
/* The still and the canvas occupy the same box: the still paints immediately and
   is what remains if WebGL or the depth map never arrives; the canvas fades in
   over it once it is actually drawing frames. */
.living__still, .living__canvas {
  width: min(560px, 82vw); height: auto; aspect-ratio: 1;
  display: block; border-radius: 10px;
  /* Same race stature as the grid (the overlay carries data-race), so a
     hobbit opened from a half-orc's neighbour still reads as the shorter one. */
  transform-origin: center bottom;
  transform: scale(calc(var(--stature, 1) * var(--stature-fit, 1)));
}
.living__canvas {
  position: absolute; top: 0; left: 50%;
  /* Above the still. The still's stature transform makes it a stacking context
     in this same paint layer, and it follows the canvas in the DOM, so without
     this the static still paints OVER the animated canvas. */
  z-index: 1;
  transform: translateX(-50%) scale(calc(var(--stature, 1) * var(--stature-fit, 1)));
  opacity: 0; transition: opacity 0.35s ease; pointer-events: none;
}
.living__canvas.is-live { opacity: 1; }
/* The still hands over to the canvas: left visible underneath, it leaks through
   at the figure's silhouette wherever the parallax has shifted the canvas copy
   (a doubled outline, a hard bottom edge where the shader feathers). It fades
   out on the same clock the canvas fades in, and stays if the canvas never
   goes live (no WebGL, reduced motion). */
.living__still { transition: opacity 0.35s ease; }
.living__canvas.is-live + .living__still { opacity: 0; }
.living__cap {
  margin: 0; text-align: center;
  font-family: var(--font-display); font-size: 0.86rem; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--sun-gold);
}
.living__note {
  margin: 0; min-height: 1.2em; text-align: center;
  font-family: var(--font-fell); font-style: italic;
  font-size: 0.92rem; color: var(--ink-dim);
}

@media (max-width: 1100px) { .archive { grid-template-columns: repeat(6, 1fr); } }
@media (max-width: 760px) {
  .archive-page { padding-top: 6rem; }
  .archive { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .archive__face:hover, .archive__face:focus-visible { transform: scale(1.2); }
}
@media (prefers-reduced-motion: reduce) {
  .archive__face { transition: none; }
  .archive__face:hover, .archive__face:focus-visible { transform: none; }
  .living, .living__canvas, .living__still { transition: none; }
}
