/* ============================================================
   MARGINALIA · Issue Nº 12 — Notes in the Margin
   Print-grade editorial typography. Everything here is type.
   ============================================================ */

:root {
  --cream: #faf6ee;
  --cream-deep: #f3ecdc;
  --ink: #22201c;
  --ink-soft: #555047;
  --ink-mute: #6f6a5f;
  --hair: rgba(34, 32, 28, 0.22);
  --hair-soft: rgba(34, 32, 28, 0.13);
  --verm: #d93a2b;
  --verm-soft: rgba(217, 58, 43, 0.14);
  --serif: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html {
  font-size: clamp(17px, 0.42vw + 13.4px, 20px);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--serif);
  background: var(--cream);
  color: var(--ink);
  font-variant-numeric: oldstyle-nums proportional-nums;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  hanging-punctuation: first last;
  overflow-x: hidden;
}

/* faint laid-paper grain */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
}

::selection { background: var(--verm-soft); color: var(--ink); }

a { color: inherit; text-decoration-color: rgba(217, 58, 43, 0.55); text-decoration-thickness: 1px; text-underline-offset: 0.18em; transition: color 0.25s ease, text-decoration-color 0.25s ease; }
a:hover { color: var(--verm); text-decoration-color: var(--verm); }
a:focus-visible, button:focus-visible { outline: 2px solid var(--verm); outline-offset: 2px; border-radius: 1px; }

em, i { font-style: italic; }
.sc {
  font-variant-caps: small-caps;
  letter-spacing: 0.05em;
}

/* ---------------- shared measure column ---------------- */
.masthead, .hero, .contents, .letters,
.essay-header, .essay-body, .essay-foot,
.also, .colophon {
  width: min(41.5rem, 100% - 2.75rem);
  margin-inline: auto;
}

@media (min-width: 1200px) {
  :root {
    /* fluid margin column: note width + outset scale with the viewport so
       sidenotes never overrun the page edge between 1200 and ~1330px */
    --mn-w: clamp(12.5rem, 18.5vw, 15rem);
    --mn-out: clamp(15rem, 23vw, 19rem);
  }
  .masthead, .hero, .contents, .letters,
  .essay-header, .essay-body, .essay-foot,
  .also, .colophon {
    margin-left: clamp(4.5rem, 10vw, 11rem);
    margin-right: auto;
  }
}

/* ---------------- reading progress: the inked line ---------------- */
.progress {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  z-index: 70;
  background: transparent;
  overflow: hidden; /* keep the vermilion tip from bleeding past the inked length */
}
.progress-ink {
  position: relative;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2a2620, var(--ink) 60%, #35302a);
}
.progress-ink::after {
  content: "";
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 3.2rem;
  background: linear-gradient(90deg, rgba(217, 58, 43, 0), var(--verm));
}

/* ---------------- live folio ---------------- */
.folio-live {
  position: fixed;
  right: 1.3rem;
  bottom: 1.1rem;
  z-index: 65;
  font-size: 0.72rem;
  font-variant-caps: small-caps;
  letter-spacing: 0.12em;
  color: var(--ink-mute);
  border-top: 1px solid var(--hair);
  padding-top: 0.35rem;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.5s ease, transform 0.5s ease;
  pointer-events: none;
}
.folio-live.show { opacity: 1; transform: none; }
@media (max-width: 760px) { .folio-live { display: none; } }

/* ---------------- rules & ornaments ---------------- */
.rule-double { height: 8px; border-top: 3px solid var(--ink); border-bottom: 1px solid var(--ink); }
.rule-hair { border-top: 1px solid var(--hair); }

.fleuron {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
  margin: 2.4rem auto 0;
}
.fleuron-rule { display: block; width: clamp(3rem, 9vw, 6.5rem); height: 1px; background: var(--hair); }
.hedera { width: 1.15rem; height: auto; color: var(--verm); }

/* ---------------- masthead ---------------- */
.masthead { padding-top: 2.4rem; text-align: center; }
.masthead-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin: 0.7rem 0.1rem 1.9rem;
  font-size: 0.68rem;
  font-variant-caps: small-caps;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
}
.masthead-meta-mid { color: var(--verm); }
@media (max-width: 620px) {
  .masthead-meta { font-size: 0.6rem; letter-spacing: 0.1em; }
}

.wordmark {
  font-size: clamp(2rem, 7.2vw, 4.8rem);
  font-weight: 500;
  letter-spacing: clamp(0.05em, 1vw, 0.12em);
  text-indent: clamp(0.05em, 1vw, 0.12em); /* re-centre letterspaced caps */
  line-height: 1;
  white-space: nowrap;
}
.wordmark-star {
  color: var(--verm);
  text-decoration: none;
  font-size: 0.5em;
  vertical-align: 0.72em;
  letter-spacing: 0;
  margin-left: 0.06em;
}
.wordmark-star:hover { color: var(--ink); }

.brandnote {
  margin: 1.15rem 0 1.9rem;
  font-style: italic;
  font-size: 0.94rem;
  color: var(--ink-soft);
}
.brandnote .star { color: var(--verm); font-style: normal; }

.issue-line {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.65rem;
  padding: 0.62rem 0;
  font-size: 0.8rem;
  font-variant-caps: small-caps;
  letter-spacing: 0.14em;
}
.issue-no { color: var(--verm); }
.issue-title-inline { font-style: italic; font-variant-caps: normal; letter-spacing: 0.02em; }
.dot { color: var(--hair); }

/* ---------------- reader's pencil in the margin ---------------- */
.margin-annot { display: none; }
@media (min-width: 1200px) {
  .margin-annot {
    display: block;
    position: absolute;
    right: calc(-1 * var(--mn-out));
    width: var(--mn-w);
    font-style: italic;
    font-size: 0.95rem;
    line-height: 1.5;
    color: #6e675a;
    text-align: left;
  }
  .margin-annot > span { display: block; }
  .hero-annot, .toc-annot { padding-left: 2.5em; }
  .annot-manicule {
    width: 1.9em;
    height: auto;
    color: var(--verm);
    position: absolute;
    left: 0;
    top: 0.28em;
  }
  .hero { position: relative; }
  .hero-annot { top: 52%; transform: rotate(-2.2deg); }
  .toc-lead { position: relative; }
  .toc-annot { top: -0.15rem; transform: rotate(1.7deg); font-size: 1rem; }
  .tease { position: relative; }
  .tease-annot { top: 2.2rem; transform: rotate(-1.6deg); }
}

/* ---------------- hero ---------------- */
.hero { padding: clamp(4rem, 9vh, 6.5rem) 0 4.2rem; text-align: center; }

.kicker {
  font-size: 0.74rem;
  font-variant-caps: small-caps;
  letter-spacing: 0.24em;
  color: var(--ink-soft);
  margin-bottom: 1.6rem;
}
.kicker-red { color: var(--verm); }

.hero-title {
  font-size: clamp(3rem, 10vw, 6.4rem);
  font-weight: 400;
  line-height: 1.02;
  letter-spacing: -0.012em;
}
.hero-title em { font-style: italic; }

.hero-deck {
  max-width: 30.5rem;
  margin: 2rem auto 0;
  font-size: 1.12rem;
  line-height: 1.58;
  color: var(--ink-soft);
  text-wrap: balance;
}

/* ---------------- contents ---------------- */
.contents { padding: 3.2rem 0 1rem; }

.contents-head, .also-head, .colophon-head, .letters-head {
  text-align: center;
  font-size: 0.82rem;
  font-weight: 500;
  font-variant-caps: small-caps;
  letter-spacing: 0.28em;
  color: var(--ink);
  margin-bottom: 2rem;
}

.toc { list-style: none; border-top: 1px solid var(--hair); }
.toc-row {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  padding: 0.78rem 0.1rem;
  border-bottom: 1px solid var(--hair-soft);
  transition: background-color 0.3s ease;
}
.toc-row:hover { background-color: rgba(217, 58, 43, 0.045); }
.toc-title { font-size: 1.02rem; }
.toc-title a { text-decoration: none; }
.toc-title a:hover { color: var(--verm); }
.toc-note { display: block; font-style: italic; font-size: 0.82rem; color: var(--ink-mute); margin-top: 0.12rem; }
.toc-lead .toc-title a { font-weight: 600; }
.toc-lead .toc-page { color: var(--verm); }
.toc-leader { flex: 1 1 2rem; min-width: 1.5rem; border-bottom: 1px dotted rgba(34,32,28,0.4); transform: translateY(-0.28em); transition: border-color 0.3s ease; }
.toc-page { font-size: 0.95rem; min-width: 1.6em; text-align: right; transition: color 0.3s ease; }
/* hovering a contents row inks its trail: leader and folio take the rubricator's red */
.toc-row:hover .toc-leader { border-bottom-color: rgba(217, 58, 43, 0.6); }
.toc-row:hover .toc-page { color: var(--verm); }

.toc-aside {
  margin: 1.5rem auto 0;
  text-align: center;
  font-style: italic;
  font-size: 0.9rem;
  color: var(--ink-mute);
  max-width: 26rem;
}

/* ---------------- letters ---------------- */
.letters { padding: 3.6rem 0 0.6rem; }
.letters-head .letters-sub {
  display: block;
  margin-top: 0.4rem;
  font-variant-caps: normal;
  letter-spacing: 0.02em;
  font-style: italic;
  font-weight: 400;
  font-size: 0.86rem;
  color: var(--ink-mute);
}
.letter { max-width: 33rem; margin: 0 auto 1.9rem; font-size: 0.99rem; line-height: 1.62; }
.letter .letter-salute { color: var(--verm); font-weight: 500; }
.letter-sig { text-align: right; margin-top: 0.45rem; font-size: 0.9rem; color: var(--ink-soft); }
@media (min-width: 640px) {
  .letter { border-left: 1px solid var(--hair); padding-left: 1.6rem; }
}
@media (min-width: 1200px) { .letter { margin-left: 3.2rem; } }

/* ---------------- essay ---------------- */
.essay { padding-top: 4.4rem; }
.essay-header { text-align: center; padding-bottom: 3rem; }
.essay-title {
  font-size: clamp(2.5rem, 7.4vw, 4.6rem);
  font-weight: 500;
  line-height: 1.06;
  letter-spacing: -0.01em;
}
.essay-deck {
  max-width: 29rem;
  margin: 1.7rem auto 0;
  font-style: italic;
  font-size: 1.1rem;
  line-height: 1.55;
  color: var(--ink-soft);
  text-wrap: balance;
}
.byline { margin-top: 1.7rem; font-size: 0.85rem; letter-spacing: 0.14em; font-variant-caps: small-caps; color: var(--ink-soft); }
.byline-name { color: var(--ink); font-weight: 500; }

.essay-body {
  position: relative;
  font-size: 1.07rem;
  line-height: 1.66;
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
  text-wrap: pretty;
}
.essay-body > p + p { text-indent: 1.7em; }
.essay-body > .section-break + p,
.essay-body > .pull + p { text-indent: 0; }

/* the ruling line between text block and margin (desktop) */
@media (min-width: 1200px) {
  .essay-body::before {
    content: "";
    position: absolute;
    top: 0.4rem; bottom: 0.4rem;
    right: -1.6rem;
    width: 1px;
    background: linear-gradient(180deg, transparent, var(--hair-soft) 6%, var(--hair-soft) 94%, transparent);
  }
}

/* drop cap */
.opener::first-letter {
  float: left;
  font-size: 4.9em;
  line-height: 0.78;
  padding: 0.06em 0.12em 0 0;
  font-weight: 500;
  color: var(--verm);
}
@supports (initial-letter: 3) or (-webkit-initial-letter: 3) {
  .opener::first-letter {
    float: none;
    padding: 0 0.12em 0 0;
    font-size: inherit;
    line-height: inherit;
    -webkit-initial-letter: 3;
    initial-letter: 3;
    font-weight: 500;
    color: var(--verm);
  }
}

/* opener: first line in small caps, as in fine press work */
.opener::first-line { font-variant-caps: small-caps; letter-spacing: 0.045em; }

/* section breaks */
.section-break { display: flex; justify-content: center; margin: 2.4rem 0; }
.section-break .hedera { width: 1.25rem; opacity: 0.95; }

/* ---------------- margin-note system ---------------- */
.mn-ref { line-height: 0; }
.mn-ref button {
  font: inherit;
  font-size: 0.78em;
  font-weight: 600;
  color: var(--verm);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.3em 0.25em; /* generous tap target */
  margin: -0.3em -0.11em;
  vertical-align: 0.42em;
  line-height: 1;
  transition: color 0.2s ease;
}
.mn-ref button:hover { color: var(--ink); }
.mn-ref button[aria-expanded="true"] { color: var(--ink); }

.mn {
  display: none;
  font-size: 0.8rem;
  line-height: 1.55;
  text-align: left;
  text-indent: 0;
  hyphens: none;
  -webkit-hyphens: none;
  color: var(--ink-soft);
  font-variant-numeric: oldstyle-nums;
}
.mn-mark { color: var(--verm); font-weight: 600; padding-right: 0.4em; font-style: normal; }
.mn-manicule { width: 1.7em; height: auto; color: var(--verm); vertical-align: -0.16em; margin-right: 0.35em; }

/* wide screens: true sidenotes floated into the margin */
@media (min-width: 1200px) {
  .mn {
    display: block;
    float: right;
    clear: right;
    width: var(--mn-w);
    margin-right: calc(-1 * var(--mn-out));
    margin-top: 0.2rem;
    margin-bottom: 0.9rem;
    padding-left: 0.7rem;
    border-left: 2px solid transparent;
    transition: color 0.35s ease, border-color 0.35s ease;
  }
  .mn.lit { color: var(--ink); border-left-color: var(--verm); }
}

/* narrow screens: tap-popover footnotes in the flow */
@media (max-width: 1199.98px) {
  .mn.open {
    display: block;
    margin: 1rem 0 1.1rem;
    padding: 0.85rem 1rem 0.9rem;
    background: var(--cream-deep);
    border: 1px solid var(--hair-soft);
    border-left: 2px solid var(--verm);
    font-size: 0.85rem;
  }
}

/* ---------------- pull quotes ---------------- */
.pull {
  margin: 3rem auto;
  text-align: center;
}
.pull p {
  font-size: clamp(1.4rem, 3.4vw, 1.78rem);
  font-style: italic;
  font-weight: 400;
  line-height: 1.32;
  text-align: center;
  text-indent: 0;
  hyphens: none;
  -webkit-hyphens: none;
  text-wrap: balance;
}
.pull::before, .pull::after {
  content: "";
  display: block;
  width: 3.4rem;
  height: 1px;
  background: var(--verm);
  margin: 0 auto;
}
.pull::before { margin-bottom: 1.5rem; }
.pull::after { margin-top: 1.5rem; }

@media (min-width: 1200px) {
  .pull { width: calc(100% + 10rem); margin-left: -2rem; }
  /* the second pull sits out in the margin, like a giant annotation */
  .pull-right {
    float: right;
    clear: right;
    width: calc(var(--mn-w) + 1rem);
    margin: 0.3rem calc(-1 * var(--mn-out)) 1.4rem 2rem;
  }
  .pull-right p { font-size: 1.32rem; text-align: left; line-height: 1.4; }
  .pull-right::before, .pull-right::after { margin-left: 0; width: 2.6rem; }
  .pull-right::before { margin-bottom: 1rem; }
  .pull-right::after { margin-top: 1rem; }
}

.endmark { white-space: nowrap; }
.endmark svg { width: 1.05em; height: auto; color: var(--verm); vertical-align: -0.14em; margin-left: 0.45em; }

.essay-foot {
  margin-top: 3.4rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--hair);
  font-size: 0.88rem;
  font-style: italic;
  color: var(--ink-soft);
}
.essay-foot .sc { font-style: normal; }

/* ---------------- also in this issue ---------------- */
.also { padding: 4.6rem 0 1rem; }
.also .rule-double { margin-bottom: 2.1rem; }

.tease {
  display: grid;
  grid-template-columns: 5rem 1fr;
  gap: 1.4rem;
  padding: 1.75rem 0;
  border-top: 1px solid var(--hair-soft);
}
.tease:last-of-type { border-bottom: 1px solid var(--hair-soft); }
.tease-folio {
  font-size: 0.82rem;
  font-variant-caps: small-caps;
  letter-spacing: 0.1em;
  color: var(--verm);
}
.tease-title { font-size: 1.5rem; font-weight: 500; line-height: 1.15; letter-spacing: -0.005em; }
.tease-by { margin-top: 0.35rem; font-size: 0.8rem; letter-spacing: 0.1em; font-variant-caps: small-caps; color: var(--ink-soft); }
.tease-excerpt { margin-top: 0.7rem; font-size: 0.96rem; line-height: 1.6; color: var(--ink-soft); max-width: 33rem; }
.tease-cont { margin-top: 0.8rem; font-size: 0.8rem; font-style: italic; color: var(--ink-mute); }
.cont-mark { color: var(--verm); font-style: normal; font-size: 1.05rem; }

@media (max-width: 620px) {
  .tease { grid-template-columns: 1fr; gap: 0.45rem; }
}

/* ---------------- colophon ---------------- */
.colophon { padding: 4.2rem 0 3rem; }
.colophon .rule-double { margin-bottom: 2.1rem; }
.colophon-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2.4rem;
  font-size: 0.9rem;
  line-height: 1.62;
  color: var(--ink-soft);
}
.colophon-cols .sc { color: var(--ink); }
@media (max-width: 680px) { .colophon-cols { grid-template-columns: 1fr; gap: 1.1rem; } }

.colophon .fleuron { margin-top: 2.3rem; }
.credit {
  margin-top: 2.2rem;
  text-align: center;
  font-size: 0.78rem;
  font-variant-caps: small-caps;
  letter-spacing: 0.12em;
  color: var(--ink-mute);
}

/* ---------------- anchor arrivals: a fading highlighter stroke ---------------- */
.letters, .tease, .essay, .colophon { scroll-margin-top: 1.8rem; }
@keyframes target-wash {
  from { background-color: rgba(217, 58, 43, 0.09); }
  to { background-color: transparent; }
}
:target { animation: target-wash 2.2s ease 0.25s both; }

/* ---------------- reveal motion ---------------- */
@media (prefers-reduced-motion: no-preference) {
  .js .reveal { opacity: 0; transform: translateY(14px); transition: opacity 0.85s ease, transform 0.85s ease; }
  .js .reveal.in { opacity: 1; transform: none; }
  /* the hero annotation is pencilled in a beat after the page settles */
  .js .hero-annot { opacity: 0; transform: rotate(-4.6deg) translateY(5px); transition: opacity 1.1s ease 0.9s, transform 1.1s cubic-bezier(0.2, 0.7, 0.3, 1) 0.9s; }
  .js .hero-annot.penned { opacity: 1; transform: rotate(-2.2deg) translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* ---------------- guide page ---------------- */
body.guide .masthead { margin-inline: auto; }
.guide-main { width: min(38rem, 100% - 2.75rem); margin-inline: auto; padding-bottom: 3rem; }
.guide-main h2 {
  font-size: clamp(2.1rem, 6vw, 3.2rem);
  font-weight: 500;
  line-height: 1.1;
  text-align: center;
  margin: 1rem 0 0.8rem;
}
.guide-main .guide-deck { text-align: center; font-style: italic; color: var(--ink-soft); margin-bottom: 2.4rem; }
.guide-main h3 {
  font-size: 0.82rem;
  font-variant-caps: small-caps;
  letter-spacing: 0.24em;
  font-weight: 500;
  color: var(--verm);
  margin: 2.4rem 0 0.9rem;
}
.guide-main p { font-size: 1rem; line-height: 1.66; margin-bottom: 1rem; }
.guide-main ul { margin: 0 0 1rem 1.2rem; font-size: 1rem; line-height: 1.66; }
.guide-main li { margin-bottom: 0.45rem; }
.guide-main li::marker { color: var(--verm); }
.guide-main code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.82em;
  background: var(--cream-deep);
  border: 1px solid var(--hair-soft);
  padding: 0.08em 0.34em;
  border-radius: 2px;
}
.guide-shots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.9rem; margin: 1.4rem 0 0.6rem; }
.guide-shots figure { margin: 0; }
.guide-shots img { width: 100%; height: auto; display: block; border: 1px solid var(--hair); }
.guide-shots figcaption {
  margin-top: 0.45rem;
  font-size: 0.72rem;
  font-variant-caps: small-caps;
  letter-spacing: 0.1em;
  text-align: center;
  color: var(--ink-mute);
}
@media (max-width: 620px) { .guide-shots { grid-template-columns: 1fr; } }
.guide-back { text-align: center; margin: 2.6rem 0 0; font-size: 0.9rem; }

/* ---------------- print: the magazine goes back to paper ---------------- */
@media print {
  .progress, .folio-live, .margin-annot { display: none !important; }
  body { background: #fff; }
  body::after { display: none; }
  .reveal { opacity: 1 !important; transform: none !important; }
  /* sidenotes become indented notes in the flow, rubricated rule kept */
  .mn {
    display: block !important;
    float: none;
    width: auto;
    margin: 0.75rem 0 0.85rem 1.4rem;
    padding-left: 0.8rem;
    border-left: 2px solid var(--verm);
  }
  .essay-body::before { display: none; }
  .pull, .section-break, .tease, .letter { break-inside: avoid; }
  a { text-decoration: none; }
}
