/* =====================================================================
   MARGIN — Literary manuscript template
   All selectors scoped under .pg-margin
   ===================================================================== */

/* ── Base ─────────────────────────────────────────────────────────── */

.pg-margin {
  font-family: 'Cormorant Garamond', var(--font-serif);
  font-size: clamp(1rem, 1.9cqw, 1.125rem);
  line-height: 1.72;
  color: var(--ink);
  background: var(--bg);
}

.pg-margin *,
.pg-margin *::before,
.pg-margin *::after {
  box-sizing: border-box;
}

.pg-margin a {
  color: inherit;
  text-decoration-color: var(--line);
  text-underline-offset: 3px;
}

.pg-margin a:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

.pg-margin figure {
  margin: 0;
}

/* ── Two-column manuscript grid ───────────────────────────────────── */
/* Left: narrow annotation rail   Right: measured text column         */

.pg-margin .mg-section,
.pg-margin .mg-divider-row,
.pg-margin .mg-head,
.pg-margin .mg-footer {
  display: grid;
  grid-template-columns: clamp(72px, 16cqw, 148px) minmax(0, 1fr);
  column-gap: clamp(1.2rem, 3.4cqw, 2.6rem);
}

/* Constrain the text column to ~65ch — the heart of the design */
.pg-margin .mg-col {
  max-width: 65ch;
  padding-right: clamp(1rem, 4cqw, 3rem);
}

/* ── Hairline rules ───────────────────────────────────────────────── */

.pg-margin .mg-rule {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 0;
}

.pg-margin .mg-rule-heavy {
  border-top-width: 2px;
  border-top-color: var(--ink);
}

/* ── Header ───────────────────────────────────────────────────────── */

.pg-margin .mg-head {
  padding: clamp(1.4rem, 3.6cqw, 2rem) clamp(1rem, 3.4cqw, 2rem) 0;
  align-items: end;
}

.pg-margin .mg-head-rail {
  padding-bottom: 0.9rem;
}

.pg-margin .mg-logo {
  max-height: 36px;
  max-width: 100%;
  object-fit: contain;
  object-position: left bottom;
}

.pg-margin .mg-wordmark {
  display: inline-block;
  font-family: 'Fraunces', var(--font-serif);
  font-size: clamp(1.1rem, 3cqw, 1.7rem);
  font-style: italic;
  line-height: 1;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.pg-margin .mg-head-copy {
  padding-bottom: 0.9rem;
}

.pg-margin .mg-running-head {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.7rem;
}

/* ── Margin rail — the annotation gutter ─────────────────────────── */

.pg-margin .mg-rail {
  padding-left: clamp(1rem, 3.4cqw, 2rem);
  padding-top: 0.25rem;
  border-right: 1px solid var(--line);
}

/* Mono annotation stamps */
.pg-margin .mg-stamp {
  display: block;
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  writing-mode: horizontal-tb;
  margin-top: 0.4rem;
}

/* Stats annotations in the opener rail */
.pg-margin .mg-ann {
  margin-bottom: 1.4rem;
  padding-bottom: 1.1rem;
  border-bottom: 1px solid var(--line);
}

.pg-margin .mg-ann-val {
  display: block;
  font-family: 'Fraunces', var(--font-serif);
  font-size: clamp(1.5rem, 4.5cqw, 2.2rem);
  font-weight: 400;
  line-height: 1;
  color: var(--accent);
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
}

.pg-margin .mg-ann-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ── Opener — name, portrait, bio ────────────────────────────────── */

.pg-margin .mg-opener {
  padding: clamp(2rem, 5cqw, 3.4rem) clamp(1rem, 3.4cqw, 2rem) clamp(2.4rem, 6cqw, 4rem);
}

.pg-margin .mg-opener-rail {
  padding-top: 1rem;
}

.pg-margin .mg-name {
  font-family: 'Fraunces', var(--font-serif);
  font-size: clamp(2.8rem, 10cqw, 6.4rem);
  font-weight: 400;
  line-height: 0.88;
  letter-spacing: -0.025em;
  color: var(--ink);
  margin-bottom: clamp(0.8rem, 2cqw, 1.2rem);
  text-wrap: balance;
}

.pg-margin .mg-tagline {
  font-family: var(--font-mono);
  font-size: clamp(0.7rem, 1.6cqw, 0.85rem);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: clamp(1.4rem, 4cqw, 2.4rem);
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

/* Hero portrait — tipped-in plate I */
.pg-margin .mg-hero-plate {
  margin: clamp(1.4rem, 4cqw, 2.2rem) 0 clamp(1.8rem, 4cqw, 2.6rem);
  max-width: 340px;
}

.pg-margin .mg-hero-plate img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  object-position: center 20%;
  border: 1px solid var(--line);
  display: block;
}

.pg-margin .mg-hero-plate figcaption {
  margin-top: 0.45rem;
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  font-style: italic;
}

/* Bio paragraph with editorial drop cap */
.pg-margin .mg-bio {
  font-family: 'Cormorant Garamond', var(--font-serif);
  font-size: clamp(1.05rem, 2.2cqw, 1.2rem);
  line-height: 1.78;
  color: color-mix(in srgb, var(--ink) 88%, var(--bg));
  margin-top: clamp(1.2rem, 3cqw, 1.8rem);
  /* Hanging punctuation feel */
  text-align: justify;
  hyphens: auto;
}

.pg-margin .mg-bio::first-letter {
  font-family: 'Fraunces', var(--font-serif);
  font-size: 4.6em;
  font-weight: 400;
  font-style: italic;
  line-height: 0.72;
  float: left;
  margin: 0.06em 0.1em 0 0;
  color: var(--accent);
  /* Prevent the capital dipping below the line */
  padding-top: 0.04em;
}

/* ── Divider row ──────────────────────────────────────────────────── */

.pg-margin .mg-divider-row {
  padding: 0 clamp(1rem, 3.4cqw, 2rem);
}

.pg-margin .mg-divider-row .mg-col {
  padding-top: 0;
  padding-bottom: 0;
}

/* ── Generic section spacing ──────────────────────────────────────── */

.pg-margin .mg-section {
  padding: clamp(2rem, 5.5cqw, 3.6rem) clamp(1rem, 3.4cqw, 2rem);
}

.pg-margin .mg-kicker {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

.pg-margin .mg-section-title {
  font-family: 'Fraunces', var(--font-serif);
  font-size: clamp(1.6rem, 4.5cqw, 2.6rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.015em;
  margin-bottom: clamp(1.2rem, 3.5cqw, 2rem);
  padding-bottom: clamp(0.8rem, 2cqw, 1rem);
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 45%, var(--bg));
}

/* ── Productions — dotted-leader table of contents ───────────────── */

.pg-margin .mg-toc {
  list-style: none;
  margin: 0;
  padding: 0;
}

.pg-margin .mg-toc-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}

.pg-margin .mg-toc-num {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  color: var(--muted);
  min-width: 1.8em;
}

.pg-margin .mg-toc-title {
  flex-shrink: 0;
  font-family: 'Cormorant Garamond', var(--font-serif);
  font-size: clamp(1rem, 2.2cqw, 1.1rem);
  line-height: 1.25;
  color: var(--ink);
  /* No truncation — titles may wrap on narrow widths */
}

/* The dotted leader fills remaining space */
.pg-margin .mg-toc-leader {
  flex: 1;
  min-width: 1rem;
  height: 0;
  border-bottom: 1px dotted color-mix(in srgb, var(--ink) 30%, var(--bg));
  align-self: flex-end;
  margin-bottom: 5px;
}

.pg-margin .mg-cont {
  margin-top: 1rem;
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-style: italic;
}

/* ── Tipped-in plates ─────────────────────────────────────────────── */

.pg-margin .mg-plate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: clamp(0.8rem, 2cqw, 1.4rem);
}

.pg-margin .mg-plate {
  display: grid;
  gap: 0.4rem;
}

.pg-margin .mg-plate img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border: 1px solid var(--line);
  display: block;
  /* Tipped-in plate feel — slight desaturation */
  filter: saturate(0.82) contrast(1.04);
  transition: filter 0.3s ease;
}

.pg-margin .mg-plate img:hover {
  filter: saturate(1) contrast(1);
}

.pg-margin .mg-plate figcaption {
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  font-style: italic;
}

/* ── YouTube reel ─────────────────────────────────────────────────── */

.pg-margin .mg-yt {
  border: 1px solid var(--line);
}

/* ── Inline list (works, territories) ────────────────────────────── */

.pg-margin .mg-inline-list {
  font-family: var(--font-mono);
  font-size: clamp(0.72rem, 1.6cqw, 0.82rem);
  letter-spacing: 0.04em;
  line-height: 2;
  color: color-mix(in srgb, var(--ink) 80%, var(--bg));
  text-transform: uppercase;
}

/* ── Publishers — colophon block ──────────────────────────────────── */

.pg-margin .mg-pub-section {
  background: var(--surface);
  padding-top: clamp(1.8rem, 4cqw, 2.8rem);
  padding-bottom: clamp(1.8rem, 4cqw, 2.8rem);
}

.pg-margin .mg-pub-list {
  border-top: 1px solid color-mix(in srgb, var(--ink) 45%, var(--bg));
}

.pg-margin .mg-pub-row {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--line);
}

.pg-margin .mg-pub-num {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  color: var(--muted);
  min-width: 1.8em;
}

.pg-margin .mg-pub-name {
  font-family: 'Cormorant Garamond', var(--font-serif);
  font-size: clamp(1rem, 2.2cqw, 1.15rem);
  font-style: italic;
  color: var(--ink);
}

/* ── Footer ───────────────────────────────────────────────────────── */

.pg-margin .mg-footer {
  padding: clamp(2rem, 5.5cqw, 3.6rem) clamp(1rem, 3.4cqw, 2rem) clamp(2rem, 5cqw, 3rem);
  background: var(--ink);
  color: var(--bg);
}

.pg-margin .mg-footer .mg-rail {
  border-right-color: color-mix(in srgb, var(--bg) 25%, transparent);
}

.pg-margin .mg-footer .mg-stamp {
  color: color-mix(in srgb, var(--bg) 55%, transparent);
}

.pg-margin .mg-footer .mg-rule {
  border-top-color: color-mix(in srgb, var(--bg) 28%, transparent);
  margin-bottom: clamp(1.2rem, 3cqw, 1.8rem);
}

.pg-margin .mg-footer .mg-rule-heavy {
  border-top-width: 2px;
  border-top-color: var(--bg);
}

.pg-margin .mg-foot-name {
  font-family: 'Fraunces', var(--font-serif);
  font-size: clamp(1.4rem, 4cqw, 2.2rem);
  font-weight: 400;
  font-style: italic;
  line-height: 1.1;
  margin-bottom: 0.8rem;
}

.pg-margin .mg-foot-detail {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  line-height: 1.9;
  color: color-mix(in srgb, var(--bg) 72%, transparent);
}

.pg-margin .mg-foot-detail a {
  color: inherit;
  text-decoration-color: color-mix(in srgb, var(--bg) 35%, transparent);
}

.pg-margin .mg-foot-detail a:hover {
  color: var(--accent);
}

.pg-margin .mg-soc-links {
  display: flex;
  flex-wrap: wrap;
  gap: 1.2rem 1.8rem;
  margin-top: clamp(1.2rem, 3cqw, 1.8rem);
  padding-top: 1rem;
  border-top: 1px solid color-mix(in srgb, var(--bg) 22%, transparent);
}

.pg-margin .mg-footer .soc {
  color: color-mix(in srgb, var(--bg) 75%, transparent);
  font-size: 9px;
  letter-spacing: 0.12em;
  transition: color 0.2s ease;
}

.pg-margin .mg-footer .soc:hover {
  color: var(--accent);
}

.pg-margin .colophon {
  color: color-mix(in srgb, var(--bg) 40%, transparent);
}

/* ── Container queries — manuscript reflows at narrow widths ──────── */

@container page (max-width: 620px) {
  /* Collapse to single column — rail moves above content */
  .pg-margin .mg-section,
  .pg-margin .mg-divider-row,
  .pg-margin .mg-head,
  .pg-margin .mg-footer {
    grid-template-columns: 1fr;
  }

  .pg-margin .mg-rail {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding-left: 0;
    padding-bottom: 0.5rem;
    display: flex;
    gap: 1.4rem;
    flex-wrap: wrap;
    align-items: baseline;
  }

  /* Rail annotations go horizontal in narrow mode */
  .pg-margin .mg-ann {
    border-bottom: 0;
    margin-bottom: 0;
    padding-bottom: 0;
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
  }

  .pg-margin .mg-ann-val {
    font-size: 1.3rem;
    display: inline;
    margin-bottom: 0;
  }

  .pg-margin .mg-ann-label {
    display: inline;
    font-size: 8px;
  }

  .pg-margin .mg-col {
    max-width: none;
    padding-right: 0;
  }

  .pg-margin .mg-head-rail {
    padding-bottom: 0.5rem;
  }

  .pg-margin .mg-footer .mg-rail {
    border-bottom-color: color-mix(in srgb, var(--bg) 22%, transparent);
  }

  .pg-margin .mg-name {
    font-size: clamp(2.4rem, 12cqw, 4.2rem);
  }

  .pg-margin .mg-hero-plate {
    max-width: 240px;
  }

  .pg-margin .mg-bio::first-letter {
    font-size: 3.6em;
  }

  .pg-margin .mg-plate-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@container page (max-width: 440px) {
  .pg-margin .mg-toc-title {
    font-size: 0.95rem;
  }

  .pg-margin .mg-plate-grid {
    grid-template-columns: 1fr;
  }

  .pg-margin .mg-hero-plate {
    max-width: 100%;
  }
}

/* ── Margin: motion & detail polish ─────────────────────────────────── */

.pg-margin ::selection { background: var(--accent); color: var(--bg); }

/* TOC: accent colour on title when row is hovered */
.pg-margin .mg-toc-row:hover .mg-toc-title { color: var(--accent); }

/* Publisher names: accent on row hover */
.pg-margin .mg-pub-row:hover .mg-pub-name { color: var(--accent); }

/* Plates — clip the scaled image; preserve figcaption below */
.pg-margin .mg-plate { overflow: hidden; }
.pg-margin .mg-plate img {
  transition: filter .45s ease, transform .75s cubic-bezier(.22, 1, .36, 1);
}
.pg-margin .mg-plate:hover img {
  filter: saturate(1) contrast(1);
  transform: scale(1.03);
}

/* Ambient keyframe — defined at root so it's always parseable */
@keyframes mg-stamp-breathe {
  0%, 100% { opacity: .55; }
  50%       { opacity: 1; }
}

@media (prefers-reduced-motion: no-preference) {
  /* Ambient: annotation stamps gently breathe in the margin rail */
  .pg-margin .mg-stamp {
    animation: mg-stamp-breathe 14s ease-in-out infinite;
  }

  /* Section-title hairline: an accent line draws left→right over the
     border-bottom when the index section enters view */
  .pg-margin .mg-index .mg-section-title { position: relative; }
  .pg-margin .mg-index .mg-section-title::after {
    content: '';
    position: absolute;
    bottom: -1px; left: 0; right: 0; height: 1px;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 1.1s cubic-bezier(.22, 1, .36, 1) .15s;
  }
  .stage.animate .pg-margin .mg-index.in .mg-section-title::after {
    transform: scaleX(1);
  }

  /* TOC rows cascade up when the index section enters view */
  .stage.animate .pg-margin .mg-index .mg-toc-row {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .45s ease, transform .45s ease;
  }
  .stage.animate .pg-margin .mg-index.in .mg-toc-row         { opacity: 1; transform: none; }
  .stage.animate .pg-margin .mg-index.in .mg-toc-row:nth-child(1)   { transition-delay: .08s; }
  .stage.animate .pg-margin .mg-index.in .mg-toc-row:nth-child(2)   { transition-delay: .14s; }
  .stage.animate .pg-margin .mg-index.in .mg-toc-row:nth-child(3)   { transition-delay: .20s; }
  .stage.animate .pg-margin .mg-index.in .mg-toc-row:nth-child(4)   { transition-delay: .26s; }
  .stage.animate .pg-margin .mg-index.in .mg-toc-row:nth-child(5)   { transition-delay: .32s; }
  .stage.animate .pg-margin .mg-index.in .mg-toc-row:nth-child(6)   { transition-delay: .38s; }
  .stage.animate .pg-margin .mg-index.in .mg-toc-row:nth-child(7)   { transition-delay: .44s; }
  .stage.animate .pg-margin .mg-index.in .mg-toc-row:nth-child(n+8) { transition-delay: .50s; }
}

/* ── Margin: xsec flex-zone — manuscript voice ───────────────────── */
.pg-margin .xsec-zone {
  padding-left: clamp(1rem, 3.4cqw, 2rem);
  padding-right: clamp(1rem, 3.4cqw, 2rem);
  border-top: 1px solid var(--line);
}
.pg-margin .xsec-h {
  font-family: 'Cormorant Garamond', var(--font-serif);
  font-size: clamp(2rem, 6cqw, 3.2rem);
  font-weight: 400;
}
.pg-margin .xsec-title { letter-spacing: .28em; }
.pg-margin .xsec-text p { font-family: 'Cormorant Garamond', var(--font-serif); font-size: 1.05rem; line-height: 1.8; }
