:root {
  /* popup background — a blurred page under a see-through warm haze
     (a touch darker than the page so the white lace shows up).
     For a darker look instead, try rgba(20, 18, 16, 0.55). */
  --backdrop-color: rgba(226, 220, 212, 0.55);
  --backdrop-blur: 14px;
  /* the one text color on the lace card. Passes WCAG AA (4.5:1) even with
     a black image blurred behind the see-through card; 11:1 over the plain
     page. If you change the backdrop or the medallion's milkiness in
     lace-card.svg, re-check it. */
  --lace-text: #3a3533;

  /* shrinks or grows every collage piece at once (keeps their --w
     sizes relative to each other). Smaller = shorter page. */
  --piece-scale: 0.9;

  /* hover glow: a soft baby-pink glow behind each image. Deep enough to
     show up against the cream page, still soft. Swap it to restyle */
  --glow: #f2a5c0;
  --glow-spread: -60%; /* how far past each image's edges its glow reaches */

  /* hover tilt */
  --tilt: 4deg;
  --lift: 1.04;
}

.life {
  display: grid;
  /* minmax(0, …) stops the collage from ever pushing past the screen */
  grid-template-columns: 300px minmax(0, 1fr);
  /* intro sits alone on top; the index and the collage start level below */
  grid-template-areas:
    "intro ."
    "index canvas";
  column-gap: 90px;
  padding: 0 60px 80px;
}

.life-intro {
  grid-area: intro;
}

/* ══ LEFT: title + index ══ */

.life-index {
  grid-area: index;
  align-self: start;
  position: sticky;
  top: 40px;
}

.life-meta {
  font-family: var(--font-body);
  font-size: 0.6rem;
  text-transform: uppercase;
  color: var(--color-text-muted);
  padding-bottom: 0.25rem;
}

.life-title {
  font-family: var(--font-subheading);
  font-weight: 100;
  font-size: 2.3rem;
  color: var(--color-text-strong);
  margin-bottom: 0.25rem;
}

.life-description {
  font-family: var(--font-body);
  font-size: 0.9rem;
  /* font-weight: 300; */
  color: var(--color-text);
  margin-bottom: 40px;
}

.index-head {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin-bottom: 16px;
}

.index-group + .index-group {
  margin-top: 40px;
}

.index-list {
  list-style: none;
  font-family: var(--font-body);
  font-size: 0.9rem;
}

.index-list li {
  padding: 6px 0;
  color: var(--color-text);
  cursor: pointer;
  transition: color 0.3s ease, translate 0.3s ease;
}

.index-list li.is-active {
  color: var(--color-accent-text); /* small text: the deeper pink */
  translate: 4px 0;
}

/* ══ RIGHT: scattered images ══ */

.life-canvas {
  grid-area: canvas;
  position: relative;
  align-self: start; /* height comes from the layout, not the sidebar */
  container-type: inline-size;
  /* height follows width, so pieces placed in cqw never drift apart.
     --canvas-h is set by the shuffle script to fit that load's layout */
  aspect-ratio: 100 / var(--canvas-h, 94);
  /* stays hidden until the shuffle has placed everything */
  opacity: 0;
  transition: opacity 0.5s ease;
}

.life-canvas.is-ready {
  opacity: 1;
}

.piece {
  position: absolute;
  left: calc(var(--x, 0) * 1cqw);
  top: calc(var(--y, 0) * 1cqw);
  width: calc(var(--w) * var(--piece-scale) * 1cqw);
  rotate: var(--r, 0deg);
  z-index: var(--z, 1);
  transition:
    rotate 0.45s cubic-bezier(0.2, 0.8, 0.2, 1),
    scale 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* the hover glow: a soft pink glow that fades in behind the piece.
   closest-side makes it fade out completely before the box edge, so it
   stays soft with no blur filter to get clipped. */
.piece::before {
  content: "";
  position: absolute;
  inset: var(--glow-spread); /* scales with each image's own size */
  z-index: -1;
  background:
    /* full colour until just past the image's edges, then a soft fade */
    radial-gradient(closest-side, var(--glow) 40%, transparent);
  opacity: 0;
  scale: 0.8;
  pointer-events: none;
  transition: opacity 0.45s ease, scale 0.45s ease;
}

.piece.is-active::before {
  opacity: 0.85;
  scale: 1;
}


.piece {
  cursor: pointer;
}

/* captions only show in the popup */
.piece figcaption {
  display: none;
}

/* keyboard focus only (never shows for mouse clicks): a thin stitched
   ring so keyboard users can see where they are */
.index-list li:focus-visible,
.piece:focus-visible {
  outline: 1px dashed var(--color-text-strong);
  outline-offset: 5px;
}

/* drag to rearrange (desktop) */
.piece img {
  -webkit-user-drag: none;
  user-select: none;
}

.piece.is-dragging {
  cursor: grabbing;
  scale: 1.06;
}

@media (min-width: 701px) {
  .piece {
    cursor: grab;
    touch-action: none; /* so dragging on a touchscreen laptop moves the piece */
  }
}

.piece img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 9px;
}

.piece.is-active {
  /* --tilt-dir is picked at random per piece by the shuffle script */
  rotate: calc(var(--r, 0deg) + var(--tilt) * var(--tilt-dir, 1));
  scale: var(--lift);
  z-index: 100; /* lift the hovered piece above the pile */
}

/* ══ POPUP ══ */

.viewer {
  /* reset the browser's default dialog box — it's a full-screen,
     see-through layer that centres the image + card */
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  padding: 1.5rem;
  border: 0;
  background: transparent;
}

/* the popup itself takes focus when opened with a mouse; no ring */
.viewer:focus {
  outline: none;
}

.viewer[open] {
  /* title down the left; image + lace card on top; "explore more" along
     the bottom. The card column never changes width, so the lace always
     sits in the same spot; only the image column grows or shrinks. */
  --piece-h: min(60vh, 520px); /* lace height = the image's max height */
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 2.5rem;
  row-gap: 1.5rem;
  animation: viewer-in 0.35s ease;
}

.viewer::backdrop {
  background: var(--backdrop-color);
  -webkit-backdrop-filter: blur(var(--backdrop-blur));
  backdrop-filter: blur(var(--backdrop-blur));
}

.viewer[open]::backdrop {
  animation: viewer-fade 0.35s ease;
}

body:has(.viewer[open]) {
  overflow: hidden;
}

.viewer-inner {
  display: contents; /* its image, card and button sit straight in the row */
}

.viewer-img {
  display: block;
  justify-self: center;
  min-width: 0;
  max-width: 100%;
  max-height: var(--piece-h);
  width: auto;
  height: auto;
  border-radius: 9px;
}

/* the caption card is an ornate piece of embroidered lace
   (lace-card.svg): a picot edge, a net band of flowers and scrolls, and
   an oval medallion of milky, dotted tulle where the text sits. The
   padding (worked out from --card-w) keeps the text inside that oval.
   The shadows lift the white "thread" off the haze like real embroidery. */
.viewer-card {
  --card-h: var(--piece-h);
  --card-w: calc(var(--card-h) * 460 / 500); /* lace-card.svg's own shape */
  width: var(--card-w);
  height: var(--card-h);
  padding: calc(var(--card-w) * 0.26) calc(var(--card-w) * 0.24);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: url("../images/lifeandnothingmore/lace-card.svg") center / 100% 100% no-repeat;
  filter:
    drop-shadow(0 0.5px 0.6px rgba(80, 68, 56, 0.45))
    drop-shadow(0 10px 24px rgba(60, 50, 40, 0.12));
}/* the title: big, theatrical ABC Honeymoon running up the far left of
   the popup, reading bottom to top, the same size for every piece. */
.viewer-title {
  --title-gap: 1.5rem; /* extra space kept clear at the top and bottom */
  flex-shrink: 0;
  /* fills the top row (the screen's height minus the thumbnail row) */
  height: calc(100% - var(--title-gap) * 2);
  margin-right: 1.5rem; /* + the 2.5rem column gap = at least 4rem to the image */
  grid-row: 1;
  writing-mode: vertical-rl;
  rotate: 180deg;
  font-family: var(--font-heading);
  font-weight: 400;
  /* a little room inside the ends so swashy letters aren't clipped */
  padding-inline: 0.12em;
  /* one size for every title: 10% of the screen height (~90px on a
     laptop). With normal line height it's the biggest that lets every
     title (two-column ones included) fit the height and 20% of the width. */
  font-size: 10vh;
  line-height: normal;
  text-align: center; /* centred along the full height */
  color: var(--color-accent); /* the site pink */
  /* a soft light halo keeps it readable over whatever is blurred behind */
  text-shadow: 0 0 14px rgba(253, 253, 250, 0.9);
}

/* caption font comes from the Adobe Fonts kit linked in the page's <head> */
.viewer-caption {
  font-family: "p22-folk-art-cross", sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  font-style: normal;
  font-weight: 400;
  color: var(--lace-text);
  margin-bottom: 16px;
}

.viewer-back {
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--lace-text);
  background: none;
  border: 0;
  padding: 4px 0;
  cursor: pointer;
}

.viewer-back:hover,
.viewer-back:focus-visible {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* no box around "back": for keyboard users the underline above is the
   focus cue instead */
.viewer-back:focus-visible {
  outline: none;
}


/* explore more: a row of small thumbnails along the bottom of the popup.
   Each shows its name on hover; the one being shown is marked with a
   small flower */
.viewer-more {
  grid-column: 1 / -1; /* the full width, so the row is centred on screen */
  grid-row: 2;
  align-self: end;
}

.viewer-more-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
}

.viewer-more-item {
  position: relative;
  display: block;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.viewer-more-item img {
  display: block;
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  transition: translate 0.3s ease, opacity 0.3s ease;
}

.viewer-more-item:hover img,
.viewer-more-item:focus-visible img {
  translate: 0 -4px;
}

/* the piece being shown: faded back, with a small flower beneath */
.viewer-more-item[aria-current] img {
  opacity: 0.45;
}

.viewer-more-item[aria-current]::after {
  content: "\273F\FE0E"; /* ✿ (\FE0E keeps it a plain text flower, not an emoji) */
  position: absolute;
  left: 50%;
  top: calc(100% + 2px);
  translate: -50% 0;
  font-size: 0.75rem;
  line-height: 1;
  color: var(--color-accent); /* the site's main colour */
}

.viewer-more-name {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  translate: -50% 4px;
  white-space: nowrap;
  font-family: var(--font-body);
  font-size: 0.7rem;
  color: var(--lace-text);
  background: rgba(253, 253, 250, 0.85);
  padding: 3px 8px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, translate 0.25s ease;
}

.viewer-more-item:hover .viewer-more-name,
.viewer-more-item:focus-visible .viewer-more-name {
  opacity: 1;
  translate: -50% 0;
}

.viewer-more-item:focus-visible {
  outline: 1px dashed var(--lace-text);
  outline-offset: 4px;
  border-radius: 6px;
}

@keyframes viewer-in {
  from { opacity: 0; scale: 0.97; }
}

@keyframes viewer-fade {
  from { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .piece,
  .piece::before,
  .index-list li {
    transition: opacity 0.3s ease;
  }

  .viewer[open] {
    animation: viewer-fade 0.2s ease;
  }
}

/* medium screens: a shorter image + lace so everything fits in one row */
@media (max-width: 1200px) {
  .viewer[open] {
    --piece-h: min(58vh, 440px);
  }
}

/* narrower screens (below 1000px): no room for the title column beside
   the image and card, so the popup stacks: title flat on top, then the
   image, the card and the explore-more thumbnails */
@media (max-width: 1000px) {
  .viewer {
    padding: 24px;
  }

  .viewer[open] {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
  }

  .viewer-title {
    height: auto;
    margin: 0;
    writing-mode: horizontal-tb;
    rotate: none;
    font-size: 2.75rem;
    line-height: 1.05;
    text-align: center;
  }

  .viewer-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
  }

  .viewer-img {
    max-height: 50vh;
  }

  .viewer-card {
    --card-h: min(500px, calc((100vw - 48px) * 500 / 460));
  }

}

@media (max-width: 700px) {
  .life {
    grid-template-columns: 1fr;
    grid-template-areas:
      "intro"
      "index"
      "canvas";
    gap: 0;
    padding: 0 24px 60px;
  }

  .life-index {
    margin-bottom: 40px;
  }

  .life-index {
    position: static;
  }

  .life-canvas {
    aspect-ratio: auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
  }

  .piece {
    position: relative;
    left: auto;
    top: auto;
    width: auto;
  }
}
