/* ORGANISMS · page structures and reusable components. */
main {
  max-width: var(--col);
  margin: 0 auto;
  padding: clamp(1.15rem, 4vw, 3rem);
  background: var(--bg);
}
/* Floated images in the text never spill past the end of the page. */
main::after { content: ""; display: block; clear: both; }

main blockquote {
  font-size: clamp(1.25rem, 2.4vw, 1.8rem);
}

footer {
  max-width: var(--col);
  margin: 4rem auto 0;
  padding: 1.5rem clamp(1.15rem, 4vw, 3rem) 3rem;
  border-top: 1px solid var(--rule);
}

body > header {
  position: sticky;
  z-index: 99;
  top: 0;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
  border-bottom: 1px solid var(--rule);
  background-color: transparent;
  padding: .5rem 0;
  text-align: center;
  backdrop-filter: blur(14px);

  nav {
    display: block;
    max-width: var(--col);
    margin: .5rem auto;
    overflow: hidden;
    padding-inline: clamp(1.15rem, 4vw, 3rem);
    font: 600 .76rem/normal var(--interface);
    letter-spacing: .09em;
    text-align: left;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;

    a {
      color: inherit;
      text-decoration: none;

      &:hover { color: var(--red); }
    }

    ul {
      display: inline;
      float: right;
      margin: 0;
      padding: 0;
      list-style: none;

      li { display: inline; }
      a { margin-left: clamp(.6rem, 2vw, 1.5rem); }
    }
  }
}

section[data-layout="grid"] {
  column-gap: clamp(1rem, 3vw, 2.5rem);
  display: grid;
  grid-template-columns: 1fr;
  margin: 3rem auto;
  max-width: var(--col);
  row-gap: 2rem;

  /* Each item follows the shared card structure. */
  article {
    display: grid;
    grid-template-columns: minmax(5.2rem, .55fr) minmax(0, 1fr);
    align-items: start;
    border-top: 1px solid var(--rule);
    margin: 0;
    padding: 1rem 0 0;

    @media (prefers-reduced-motion: no-preference) {
      transition: transform .3s;
      &:hover { transform: translateY(-2px); }
    }

    a {
      text-decoration: none;
      color: inherit;
    }

    /* Each card image keeps the same frame. */
    figure {
      grid-column: 1;
      align-self: start;
      overflow: hidden;
      aspect-ratio: 3 / 4;
      margin: 0;
      padding: 0;

      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }


    figure:not(:has(img)) {
      display: grid;
      place-items: end start;
      padding: 0.7rem;
      background: var(--oblivion);
    }
    figure:not(:has(img)) a {
      display: block;
      font-family: var(--interface);
      font-size: clamp(0.72rem, 1.2vw, 0.95rem);
      font-weight: 700;
      letter-spacing: 0.04em;
      line-height: 1.1;
      text-transform: uppercase;
    }

    > div {
      grid-column: 2;
      padding: 0.8rem 1rem;
      font-size: clamp(0.95rem, 1.25vw, 1.15rem);
      line-height: 1.45;
    }
    > div :is(h2, h3) {
      margin: 0;
      padding: 0;
      color: var(--red);
      font-family: inherit;
      font-size: 1.12em;
      font-weight: 700;
      letter-spacing: normal;
      line-height: 1.12;
    }
    > div time {
      display: block;
      margin-top: 0.45rem;
      color: color-mix(in srgb, currentColor, transparent 45%);
      font-family: var(--interface);
      font-size: 0.72em;
      font-style: normal;
      line-height: 1.25;
    }
    > div > span {
      display: block;
      margin-top: 0.55rem;
    }
    > div:only-child {
      grid-column: 1 / -1;
    }

  }

  @media (min-width: 721px) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    article { grid-template-columns: minmax(5.5rem, .72fr) minmax(0, 1fr); }
  }
}


/* Archivio letture: elenco intenzionalmente lineare, non griglia di card. */
section:has(> ul) {
  display: block;
  max-width: 48rem;
  margin: 2.5rem 0;
}
section:has(> ul) h2 {
  padding-top: 2rem;
}
section:has(> ul) ul {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
}
section:has(> ul) li {
  border-top: 1px solid color-mix(in srgb, var(--ink), transparent 82%);
  padding: 1rem 0;
}
section:has(> ul) li > span {
  opacity: .65;
}
section:has(> ul) li > p {
  margin: .25rem 0 0;
}

/* ── Language switcher: nav a[lang] ─────────────────────── */
nav a[lang],
nav span[aria-disabled="true"] {
  font-family: var(--interface);
  font-size: 0.75em;
  font-weight: 700;
  letter-spacing: 0.06em;
  border: 1.5px solid currentColor;
  padding: 0.15em 0.45em;
  border-radius: 3px;
  margin-left: 0.6em;
  vertical-align: middle;
}
nav a[lang] {
  text-decoration: none !important;
  background: none !important;
  background-clip: unset !important;
  color: inherit !important;
  opacity: 0.65;
  transition: opacity 0.2s;
}
nav a[lang]:hover {
  opacity: 1;
}
nav span[aria-disabled="true"] {
  opacity: 0.25;
  cursor: default;
  pointer-events: none;
}

/* ── Translation notice: aside ──────────────────────────── */
aside {
  background: color-mix(in srgb, var(--link) 12%, transparent);
  border-left: 3px solid var(--link);
  padding: 0.6rem 1rem;
  margin-bottom: 2rem;
  font-size: 0.88em;
  font-family: var(--interface);
  color: var(--ink);
}

/* ── Shadow on inline images in post content ─────────────── */
main p img {
  box-shadow: var(--image-shadow);
  border-radius: 4px;
  margin-block: 1rem;
  float: left;
  margin-right: 1rem;
}

/* ── Gallery ─────────────────────────────────────────────── */

/*
  Sintassi markdown per le gallerie (post con layout photo_post.njk):

  Due o più immagini consecutive senza riga vuota → gruppo galleria.

  Alt text controls:
    ![caption](url)           → peso 1 (default)
    ![2|caption](url)         → peso numerico (fr unit)
    ![pair|caption](url)      → layout predefinito (sul primo del gruppo)

  Named layouts: full · pair · feature · triptych · mosaic
*/

[data-gallery] {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.25rem;
  margin: 2rem 0;
}

/* picture è display:contents globalmente, ma nel grid deve essere un item */
[data-gallery] picture {
  display: block;
  overflow: hidden;
}

@media (min-width: 641px) {
  [data-gallery] { grid-template-columns: var(--gallery-cols, 1fr 1fr); }
}

[data-gallery] img {
  width: 100%;
}

/* Dark palette is defined with the editorial tokens below the legacy rules. */

/* Conceptual Work plates: no embedded labels, no crop, translated captions. */
main > article:has(> figure img[src*="life-chart-art"]) {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  max-width: var(--col);
  margin: clamp(2.5rem, 6vw, 5rem) auto;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--ink), transparent 78%);
}
main > article:has(> figure img[src*="life-chart-art"]) > figure {
  grid-column: 1;
  width: 100%;
  aspect-ratio: 3 / 4;
  margin: 0;
  background: #f5eedf;
}
main > article:has(> figure img[src*="life-chart-art"]) > figure a { display: block; width: 100%; height: 100%; }
main > article:has(> figure img[src*="life-chart-art"]) > figure img { width: 100%; height: 100%; object-fit: contain; background: #f5eedf; }
main > article:has(> figure img[src*="life-chart-art"]) > section {
  display: block;
  grid-column: 1;
  align-self: center;
  max-width: none;
  margin: 0;
  padding: 1.25rem;
}
main > article:has(> figure img[src*="life-chart-art"]) > section > p:first-child {
  margin: 0 0 1rem;
  color: var(--red);
  font: 700 .72rem/1.3 var(--interface);
  letter-spacing: .12em;
  text-transform: uppercase;
}
main > article:has(> figure img[src*="life-chart-art"]) h2 { margin: 0; padding: 0; font-size: clamp(2.5rem, 5vw, 5rem); line-height: .95; }
main > article:has(> figure img[src*="life-chart-art"]) h2 a { color: var(--ink) !important; text-decoration: none; }
main > article:has(> figure img[src*="life-chart-art"]) > section > p:not(:first-child) { max-width: 32rem; margin: 1.25rem 0 0; font-size: clamp(1rem, 1.5vw, 1.2rem); line-height: 1.5; }
main > article:has(> figure img[src*="life-chart-art"]) > section > p:last-child > a { font: 700 1rem/1.4 var(--interface); text-decoration-thickness: 1px; text-underline-offset: .2em; }
@media (min-width: 721px) {
  main > article:has(> figure img[src*="life-chart-art"]) { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  main > article:has(> figure img[src*="life-chart-art"]) > section { grid-column: 2; padding: clamp(1.25rem, 4vw, 4rem); }
}
