/* ============================================================
   WRITING / PUBLISHED PAGE
   Each piece is an editorial "spread".
   Layout:
     - Giant ghost page number watermark (decorative)
     - Vertical metadata spine on the left
     - Oversized serif title breaking the grid
     - Cover placed as if lying on a desk (slight rotation)
     - Main body set as proper reading column
     - Margin-placed pullquote, set in serif, like printed marginalia
     - Topics + actions footer
   Second spread mirrors: cover on the left instead of the right.
   ============================================================ */

@layer pages {

  /* Use overflow-clip so rotated cover + ghost pageno can poke
     without triggering horizontal scroll. */
  .writings {
    max-width: var(--content-max);
    margin-inline: auto;
    padding-block: 0 var(--section);
    display: flex;
    flex-direction: column;
    gap: clamp(4rem, 10vw, 10rem);
    overflow: clip;
  }

  /* ==================================================
     SPREAD (.wp)
     12-col grid. Spine, title, cover, body, margin-quote,
     footer all take specific columns & rows.
     ================================================== */
  .wp {
    position: relative;
    display: grid;
    grid-template-columns: 64px minmax(0, 5fr) minmax(0, 4fr);
    grid-template-areas:
      "spine  header  cover"
      "spine  body    cover"
      "spine  body    quote"
      "footer footer  footer";
    gap: clamp(1.5rem, 4vw, 3rem) clamp(1.5rem, 4vw, 3rem);
    padding-block: clamp(3rem, 8vw, 6rem);
    border-top: 1px solid var(--line);
  }

  /* Mirrored spread: cover moves to the left column */
  .wp--mirror {
    grid-template-columns: 64px minmax(0, 4fr) minmax(0, 5fr);
    grid-template-areas:
      "spine  cover  header"
      "spine  cover  body"
      "spine  quote  body"
      "footer footer footer";
  }

  /* ==================================================
     GHOST PAGE NUMBER WATERMARK
     A huge, very quiet serif numeral in the background.
     ================================================== */
  .wp__pageno {
    position: absolute;
    font-size: clamp(12rem, 32vw, 26rem);
    line-height: 0.85;
    letter-spacing: -0.03em;
    color: var(--fg);
    opacity: 0.03;
    pointer-events: none;
    user-select: none;
    top: -2rem;
    right: -4rem;
    z-index: 0;
  }
  .wp--mirror .wp__pageno {
    right: auto;
    left: -4rem;
  }

  /* ==================================================
     SPINE (vertical metadata rail)
     ================================================== */
  .wp__spine {
    grid-area: spine;
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
    align-items: flex-start;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    font-size: 0.75rem;
    letter-spacing: var(--track-wide);
    text-transform: uppercase;
    color: var(--mid);
    font-variant-numeric: tabular-nums;
    padding-block: var(--s-3);
    border-right: 1px solid var(--line);
    padding-right: var(--s-2);
    min-height: 260px;
    position: relative;
    z-index: 1;
  }
  .wp__spine-kind { color: var(--fg); }

  /* ==================================================
     HEADER (title + subtitle)
     ================================================== */
  .wp__header {
    grid-area: header;
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
    position: relative;
    z-index: 1;
  }
  .wp__title {
    font-size: clamp(2.5rem, 6.5vw, 5.5rem);
    line-height: 0.98;
    letter-spacing: -0.02em;
    margin: 0;
  }
  .wp__subtitle {
    font-size: clamp(1rem, 1.4vw, 1.25rem);
    line-height: 1.5;
    color: var(--mid);
    max-width: 44ch;
    margin: 0;
  }

  /* ==================================================
     COVER (as if lying on a desk)
     Slightly rotated, subtle shadow, sticky at wide widths
     so it stays in view while the body scrolls beside it.
     ================================================== */
  .wp__cover {
    grid-area: cover;
    position: relative;
    z-index: 1;
    align-self: start;
    max-width: 380px;
    aspect-ratio: 3 / 4;
    border: 1px solid var(--line);
    overflow: hidden;
    transform: rotate(-1.8deg);
    box-shadow:
      0 2px 6px oklch(from var(--fg) l c h / 0.08),
      0 12px 32px oklch(from var(--fg) l c h / 0.10);
    transition: transform var(--t-med) var(--ease);
    justify-self: end;
  }
  .wp__cover:hover {
    transform: rotate(0deg);
  }
  .wp--mirror .wp__cover {
    transform: rotate(1.8deg);
    justify-self: start;
  }
  .wp--mirror .wp__cover:hover {
    transform: rotate(0deg);
  }

  .wp__cover-inner {
    width: 100%;
    height: 100%;
    padding: clamp(1.5rem, 2.5vw, 2rem);
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    gap: var(--s-3);
  }
  .wp__cover--azgzaw {
    background: oklch(0.22 0.04 320);
    color: oklch(0.95 0.01 85);
  }
  .wp__cover--mot {
    background: oklch(0.28 0.04 90);
    color: oklch(0.95 0.01 85);
  }
  .wp__cover-kicker {
    font-size: 0.7rem;
    letter-spacing: var(--track-wide);
    text-transform: uppercase;
    opacity: 0.7;
  }
  .wp__cover-title {
    font-size: clamp(1.75rem, 2.75vw, 2.5rem);
    line-height: 1;
    letter-spacing: -0.01em;
    align-self: center;
  }
  .wp__cover-sub {
    font-size: 0.875rem;
    opacity: 0.75;
    line-height: 1.4;
    max-width: 22ch;
  }
  .wp__cover-foot {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    letter-spacing: var(--track-wide);
    text-transform: uppercase;
    opacity: 0.5;
    padding-top: var(--s-2);
    border-top: 1px solid oklch(from currentColor l c h / 0.25);
  }

  /* ==================================================
     BODY (reading column)
     ================================================== */
  .wp__body {
    grid-area: body;
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
    max-width: 56ch;
    position: relative;
    z-index: 1;
  }
  .wp__body p {
    color: var(--fg);
    line-height: 1.65;
    margin: 0;
    font-size: 1.0625rem;
  }
  .wp__body p:first-child::first-letter {
    font-family: 'Young Serif', Georgia, serif;
    font-size: 3.5rem;
    line-height: 0.9;
    float: left;
    padding: 0.1em 0.1em 0 0;
    color: var(--fg);
  }

  /* ==================================================
     MARGIN PULLQUOTE
     Printed-marginalia treatment. Sits in the same column
     as the cover, below it.
     ================================================== */
  .wp__margin-quote {
    grid-area: quote;
    font-size: clamp(1rem, 1.3vw, 1.125rem);
    line-height: 1.45;
    color: var(--fg);
    max-width: 30ch;
    padding-top: var(--s-4);
    border-top: 1px solid var(--line);
    font-style: italic;
    justify-self: end;
    position: relative;
    z-index: 1;
  }
  .wp--mirror .wp__margin-quote {
    justify-self: start;
  }

  /* ==================================================
     FOOTER (topics + actions)
     ================================================== */
  .wp__footer {
    grid-area: footer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--s-4);
    padding-top: var(--s-4);
    margin-top: var(--s-4);
    border-top: 1px solid var(--line);
    position: relative;
    z-index: 1;
  }
  .wp__topics {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }
  .wp__topics .tag {
    font-size: 0.75rem;
    color: var(--mid);
  }
  .wp__actions {
    display: flex;
    gap: var(--s-3);
    flex-wrap: wrap;
  }

  /* ==================================================
     RESPONSIVE
     ================================================== */
  @media (max-width: 1000px) {
    .wp, .wp--mirror {
      grid-template-columns: 40px 1fr;
      grid-template-areas:
        "spine  header"
        "spine  cover"
        "spine  body"
        "spine  quote"
        "footer footer";
    }
    .wp__cover, .wp--mirror .wp__cover {
      justify-self: start;
      max-width: 280px;
      transform: rotate(-1deg);
    }
    .wp__margin-quote, .wp--mirror .wp__margin-quote {
      justify-self: start;
      max-width: 44ch;
    }
    .wp__pageno {
      font-size: clamp(8rem, 25vw, 16rem);
      top: -1rem;
      right: -1rem;
    }
    .wp--mirror .wp__pageno {
      left: auto; right: -1rem;
    }
  }

  @media (max-width: 600px) {
    .wp, .wp--mirror {
      grid-template-columns: 1fr;
      grid-template-areas:
        "spine"
        "header"
        "cover"
        "body"
        "quote"
        "footer";
      gap: var(--s-4);
    }
    .wp__spine {
      writing-mode: horizontal-tb;
      transform: none;
      flex-direction: row;
      flex-wrap: wrap;
      border-right: 0;
      border-bottom: 1px solid var(--line);
      padding-right: 0;
      padding-bottom: var(--s-3);
      min-height: 0;
      gap: var(--s-3);
    }
    .wp__cover { transform: none; }
    .wp__cover:hover { transform: none; }
  }

  /* ==================================================
     FOOTNOTE
     ================================================== */
  .writings-footnote {
    padding-block: var(--section-tight);
    max-width: var(--content-max);
    margin-inline: auto;
    text-align: center;
  }
  .writings-footnote p {
    color: var(--mid);
    font-size: 1rem;
    line-height: 1.6;
    font-style: italic;
    max-width: 48ch;
    margin-inline: auto;
  }
}
