/*
 * EB Garamond Initials (Georg Duffner, SIL OFL 1.1 — see assets/fonts/OFL.txt).
 * The decorative initials come in two layers: F1 draws the ornament and F2 the
 * letter, so they can be coloured separately and superimposed.
 */
@font-face {
  font-family: "EB Garamond Initials Ornament";
  src: url("assets/fonts/EBGaramond-InitialsF1.otf") format("opentype");
  font-display: swap;
}

@font-face {
  font-family: "EB Garamond Initials Letter";
  src: url("assets/fonts/EBGaramond-InitialsF2.otf") format("opentype");
  font-display: swap;
}

:root {
  --ink: #1c1a17;
  --ink-soft: #6f6759;
  --gold: #b8922a;
  --rule: #e4e0d7;
  --substack: #ff6719;
  --border-width: 120px;
  /* the tile is 140x560 and the flourish 140x150, both drawn to the margin's
     width; the stem repeats every half tile, which is the unit the vine's
     height snaps to so it is never cut mid-ornament */
  --half-tile: calc(var(--border-width) * 2);
  --flourish: calc(var(--border-width) * 15 / 14);
  --wordmark: clamp(3rem, 9vw, 6.6rem);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: #ffffff;
  color: var(--ink);
  font-family: "EB Garamond", Garamond, "Times New Roman", serif;
  -webkit-font-smoothing: antialiased;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.page {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: clamp(1.25rem, 3.5vw, 2.5rem) 0 clamp(2rem, 4vw, 3rem);
  overflow: hidden;
  background: #ffffff;
}

/* marginal vines ---------------------------------------------------------- */

.border {
  position: absolute;
  top: 0;
  bottom: 0;
  width: var(--border-width);
  display: flex;
  flex-direction: column;
  /* the vine takes whole half-tiles, so the leftover is split above the head
     flourish and below the foot one, as a margin rather than a broken stem */
  justify-content: center;
  pointer-events: none;
}

.border--left {
  left: clamp(0.4rem, 2.4vw, 3rem);
}

.border--right {
  right: clamp(0.4rem, 2.4vw, 3rem);
  transform: scaleX(-1);
}

/* A repeating background is cut wherever its element ends, so the height is
   rounded down to whole half-tiles: the cut then lands on a line where the
   stem's position and tangent repeat, and the join is invisible. */
.vine {
  flex: 0 0 auto;
  height: max(
    var(--half-tile),
    round(down, calc(100% - 2 * var(--flourish)), var(--half-tile))
  );
  background-image: url("assets/vine.svg?v=21");
  background-repeat: repeat-y;
  background-position: center top;
  background-size: var(--border-width) auto;
}

.vine-tip {
  flex: 0 0 auto;
  height: var(--flourish);
  background-image: url("assets/vine-tip.svg?v=21");
  background-repeat: no-repeat;
  background-position: center bottom;
  background-size: var(--border-width) auto;
}

/* turned rather than flipped: a vertical flip would reverse the stem's lean
   and kink it where it meets the vine */
.vine-tip--foot {
  transform: rotate(180deg);
}

/* the wordmark ----------------------------------------------------------- */

.folio {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(1rem, 4vw, 3rem) calc(var(--border-width) + clamp(0.9rem, 3vw, 3.5rem));
}

.wordmark {
  display: flex;
  align-items: baseline;
  justify-content: center;
  margin: 0;
  line-height: 1;
  font-weight: 400;
}

/* the two initial layers are stacked, so the box is sized by the first and
   the second is pulled back over it */
.initial {
  position: relative;
  display: inline-block;
  font-size: calc(var(--wordmark) * 1.42);
  line-height: 1;
  margin-right: calc(var(--wordmark) * 0.05);
}

.initial__ornament,
.initial__letter {
  display: block;
  font-weight: 400;
}

.initial__ornament {
  font-family: "EB Garamond Initials Ornament", "EB Garamond", serif;
  color: var(--gold);
}

.initial__letter {
  position: absolute;
  left: 0;
  top: 0;
  font-family: "EB Garamond Initials Letter", "EB Garamond", serif;
  color: var(--ink);
}

.wordmark__rest {
  font-family: "EB Garamond", Garamond, serif;
  font-weight: 400;
  font-size: var(--wordmark);
  letter-spacing: 0.008em;
  color: var(--ink);
}

/* the foot of the page --------------------------------------------------- */

.colophon {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  padding: 0 calc(var(--border-width) + clamp(0.9rem, 3vw, 3.5rem));
  text-align: center;
}

.colophon__rule {
  width: 4.5rem;
  height: 1px;
  margin-bottom: 0.35rem;
  background: linear-gradient(90deg, transparent, var(--rule) 22%, var(--rule) 78%, transparent);
}

.substack {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  background: var(--substack);
  color: #ffffff;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.substack__mark {
  width: 1.15rem;
  height: 1.15rem;
  fill: currentColor;
  /* the mark's own shapes sit slightly high in the 24-unit box */
  margin-top: 0.05rem;
}

.substack:hover,
.substack:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(255, 103, 25, 0.32);
}

.substack:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.colophon__lede {
  margin: 0;
  font-family: "EB Garamond", Garamond, serif;
  font-size: 1.05rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
}

.colophon__meta {
  margin: -0.35rem 0 0;
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
}

/* narrower pages --------------------------------------------------------- */

@media (max-width: 960px) {
  :root {
    --border-width: 86px;
  }
}

@media (max-width: 620px) {
  :root {
    --border-width: 50px;
    /* keep the word on one line: a stacked G reads as a separate letter */
    --wordmark: clamp(1.85rem, 10vw, 3.1rem);
  }

  .border--left {
    left: 0.15rem;
  }

  .border--right {
    right: 0.15rem;
  }

  .folio,
  .colophon {
    padding-left: calc(var(--border-width) + 0.7rem);
    padding-right: calc(var(--border-width) + 0.7rem);
  }

  .colophon__lede {
    font-size: 0.95rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .substack {
    transition: none;
  }
}
