/* -------------------------------------------------------
   Google Fonts — also loaded via <link> in template head
------------------------------------------------------- */
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,700;1,700&family=EB+Garamond:ital,wght@0,400;0,500;1,400;1,500&family=Homemade+Apple&family=Inter:wght@400;500&display=swap');

/* -------------------------------------------------------
   Custom properties
------------------------------------------------------- */
:root {
  --bg:           #FDFAF2;
  --text:         #232323;
  --navy:         #17364A;
  --coral:        #B24A2F;
  --brass:        #B38A4A;
  --cream-panel:  #EDE5D6;

  --font-body:     'EB Garamond', Georgia, 'Times New Roman', serif;
  --font-headline: 'Cormorant Garamond', Georgia, serif;
  --font-ui:       'Inter', system-ui, -apple-system, sans-serif;
}

/* -------------------------------------------------------
   Reset
------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

img { max-width: 100%; display: block; }

/* -------------------------------------------------------
   Base — mobile first
------------------------------------------------------- */
html {
  font-size: 19px;
  -webkit-text-size-adjust: 100%;
}

/* Shield the 8px gap above the floating header.
   Fixed, full-width, background-color matches the page.
   z-index 99 sits above scrolling content (auto) but below
   the header (100), so text can never bleed into the gap. */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 8px;
  background-color: var(--bg);
  z-index: 99;
  pointer-events: none;
}

body {
  background-color: var(--bg);
  /* Paper materiality — two layers, each imperceptible alone:
     1. Radial luminance variation: a barely-there warm glow fixed to the
        viewport center, like ambient light falling on paper. Fixed attachment
        means it reads as environmental illumination, not a gradient on the page.
     2. Ultra-low-opacity fractalNoise: fine organic grain, stitched seamlessly.
        Scrolls with content — you read through it, not over it.
     Together they produce the subconscious tactile quality of good paper. */
  background-image:
    /* Primary warm luminance: soft light source upper-centre */
    radial-gradient(ellipse at 52% 18%, rgba(255, 252, 240, 0.28) 0%, rgba(235, 228, 210, 0.10) 52%, transparent 72%),
    /* Secondary: faint warm pooling at lower-left — paper held at angle */
    radial-gradient(ellipse at 12% 88%, rgba(232, 224, 206, 0.09) 0%, transparent 55%),
    /* Tertiary: very slight cool shadow at upper-right edge — depth plane */
    radial-gradient(ellipse at 94% 6%, rgba(210, 205, 195, 0.06) 0%, transparent 40%),
    /* Fine organic grain — reads as texture not noise */
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.68' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='0'/%3E%3C/svg%3E");
  background-size: cover, cover, cover, 300px 300px;
  background-attachment: fixed, fixed, fixed, scroll;
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.85;
}

/* -------------------------------------------------------
   Site header — contained editorial plate

   Width-constrained and centered to align with the reading
   column rhythm. top:0 ensures the header fully occludes
   content as it scrolls beneath — no gap, no bleed.
   width:calc(100% - 20px) provides 10px breathing room on
   each side on small viewports; max-width:760px caps it on
   wider screens so the plate never sprawls edge-to-edge.
   Rounded bottom corners complete the "placed object" feel.

   Two flex children: icon (left) and wordmark (right).
   Hamburger at position:absolute right. Nav at top:100%.
   At >250px scroll JS adds .is-scrolled — plate thins,
   hourglass withdraws.
------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 8px;
  z-index: 100;
  display: flex;
  align-items: center;
  background-color: var(--navy);
  /* Barely-perceptible tonal gradient — mimics slight ink
     density variation across a printed band. */
  background-image: linear-gradient(
    175deg,
    rgba(255, 255, 255, 0.025) 0%,
    transparent 45%,
    rgba(0, 0, 0, 0.03) 100%
  );
  border: none;
  border-radius: 0 0 3px 3px;
  box-shadow: 0 2px 6px rgba(27, 58, 78, 0.10);
  height: 112px;
  /* 8.5px each side; body::before shields the 8px gap above */
  width: calc(100% - 17px);
  max-width: 874px;
  margin: 8px auto 0;
  transition: height 320ms ease;
}

.header-icon {
  flex: 0 0 auto;
  /* Width is derived so the wordmark text left-aligns with the
     reading column. Both elements are margin:auto centered.
     At max-widths: (874 - 640) / 2 - 10px padding = 107px.
     On narrower viewports: calc((100vw - 677px) / 2) tracks
     the shrinking gap exactly. 44px floor keeps the icon visible. */
  width: clamp(44px, calc((100vw - 677px) / 2), 107px);
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  overflow: hidden;
  /* Collapses in sync with the header height transition.
     Width collapses to zero so the wordmark inherits the
     full band — leaving a pure textual running header. */
  transition: width 320ms ease, opacity 280ms ease;
}

.header-icon__img {
  display: block;
  height: 79px;
  width: auto;
  flex-shrink: 0;
}

.header-wordmark {
  flex: 1;
  padding-left: 10px;
  /* right padding clears the hamburger button */
  padding-right: clamp(44px, 5vw, 80px);
  display: flex;
  align-items: center;
  min-width: 0;
}

.header-wordmark__link {
  font-family: 'Homemade Apple', cursive;
  font-weight: 400;
  font-style: normal;
  font-size: clamp(16.2px, 2.16vw, 32.4px);
  color: var(--bg);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.15;
  transition: font-size 320ms ease;
}

.wm-full  { display: inline; }
.wm-short { display: none; }

/* Scrolled state — quiet, infrastructural, recedes while reading */
.site-header.is-scrolled {
  height: 45px;
}

/* Hourglass withdraws entirely — only the text remains,
   reading like a folio or running chapter header. */
.site-header.is-scrolled .header-icon {
  width: 0;
  opacity: 0;
}

.site-header.is-scrolled .header-wordmark__link {
  font-size: 15px;
}

.site-header.is-scrolled .wm-full  { display: none; }
.site-header.is-scrolled .wm-short { display: inline; }

@media (max-width: 600px) {
  .site-header              { height: 76px; }
  .site-header.is-scrolled  { height: 43px; }

  /* Left hourglass hidden — icon moves to the right as the nav trigger. */
  .header-icon              { display: none; }

  /* Wordmark aligns with body text: header left edge (~8.5px) + 15px = ~24px */
  .header-wordmark          { padding-left: 15px; }
  .header-wordmark__link                          { font-size: 20px; }
  .site-header.is-scrolled .header-wordmark__link { font-size: 13px; }

  /* Hamburger becomes the hourglass — spans hidden, img shown.
     Button element (and nav behaviour) is unchanged. */
  .hamburger               { padding: 0 4px; gap: 0; opacity: 1; }
  .hamburger span          { display: none; }
  .hamburger__icon         { display: block; height: 44px; width: auto; }
  .hamburger__icon.is-shaking { animation: hg-shake 320ms ease; }
}

/* -------------------------------------------------------
   Hamburger — all screen sizes
   Three lines morph to X when .is-open is on the button.
   Kept intentionally quiet — editorial, not prominent UI.
------------------------------------------------------- */
.hamburger {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 4px;
  position: absolute;
  right: clamp(14px, 2.5vw, 36px);
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.55;
  transition: opacity 0.2s ease;
}

/* Hourglass img inside button — hidden above mobile breakpoint (spans used instead) */
@media (min-width: 601px) {
  .hamburger__icon { display: none; }
}

.hamburger:hover {
  opacity: 0.85;
}

@media (max-width: 600px) {
  .hamburger { opacity: 1; }
}

.hamburger span {
  display: block;
  width: 18px;
  height: 1px;
  background-color: var(--cream-panel);
  transition: transform 0.15s ease, opacity 0.15s ease;
  transform-origin: center;
}

/* X morph — top line rotates +45°, middle fades out, bottom rotates -45° */
.hamburger.is-open span:nth-child(1) { transform: translateY(4px) rotate(45deg); }
.hamburger.is-open span:nth-child(2) { opacity: 0; }
.hamburger.is-open span:nth-child(3) { transform: translateY(-4px) rotate(-45deg); }

.hamburger.is-open { opacity: 0.8; }

/* On mobile the hourglass replaces the three-line icon — hide spans after
   the global span rules so this override wins the cascade. */
@media (max-width: 600px) {
  .hamburger span { display: none; }
}

@keyframes hg-shake {
  0%   { transform: rotate(0deg)   translateY(0); }
  18%  { transform: rotate(-9deg)  translateY(-1px); }
  36%  { transform: rotate(7deg)   translateY(0); }
  54%  { transform: rotate(-5deg)  translateY(-1px); }
  72%  { transform: rotate(3deg)   translateY(0); }
  100% { transform: rotate(0deg)   translateY(0); }
}

/* Sticky state on mobile: hourglass yields to the faint three-line hamburger */
@media (max-width: 600px) {
  .site-header.is-scrolled .hamburger__icon { display: none; }
  .site-header.is-scrolled .hamburger span  { display: block; }
  .site-header.is-scrolled .hamburger       { opacity: 0.55; }
}

/* -------------------------------------------------------
   Site nav dropdown
   Positioned absolutely below the sticky header band.
   Floats over page content — does not affect band height.
------------------------------------------------------- */
.site-nav {
  position: absolute;
  top: 100%;
  right: 0;
  left: auto;
  z-index: 50;
  background-color: var(--navy);
  border-radius: 0 0 2px 2px;
  overflow: hidden;
  box-shadow: 0 4px 10px rgba(23, 54, 74, 0.09);
}

.site-nav__link {
  display: block;
  font-family: var(--font-headline);
  font-size: 1.0rem;
  font-weight: 700;
  font-style: italic;
  color: var(--cream-panel);
  text-decoration: none;
  text-align: right;
  padding: 0.5rem 1.2rem;
  transition: opacity 0.15s ease;
  opacity: 0.82;
  white-space: nowrap;
}

.site-nav__link:hover {
  opacity: 1;
  color: var(--cream-panel);
  text-decoration: none;
}

.site-nav__divider {
  display: block;
  height: 1px;
  background-color: var(--coral);
  opacity: 0.2;
  margin: 0 16px;
}

/* -------------------------------------------------------
   Desktop breakpoint — 769px+
   Increase band padding only. Hamburger stays visible.
------------------------------------------------------- */
@media (min-width: 769px) {
  html { font-size: 20px; }
}

/* -------------------------------------------------------
   Large desktop — 1100px+
   Wider band padding for spacious editorial feel.
------------------------------------------------------- */
@media (min-width: 1100px) {
  html { font-size: 21px; }

  /* masthead sizing is purely image-driven — no breakpoint overrides needed */
}

/* -------------------------------------------------------
   Reading column — horizontally centered
   640px targets ~62–66 characters per line at desktop
   sizes with EB Garamond, the classical optimum for
   sustained prose reading.
------------------------------------------------------- */
.page-content {
  max-width: 640px;
  margin: 0 auto;
  padding: 2rem 24px 5.5rem;
}

@media (min-width: 769px) {
  .page-content { padding: 2.8rem 0 6.5rem; }
}

/* -------------------------------------------------------
   Essay header
   Spacing uses margin-bottom only — no margin-top — to keep
   the cascade predictable and avoid unexpected collapsing.
   Rhythm (approximate): title→subtitle 0.3, subtitle→author 0.75,
   author→lede 1.3, lede→date 0.8, date→divider 0.8.
------------------------------------------------------- */
.essay-header { margin-bottom: 3rem; }

/* Title */
.essay-header h1 {
  font-family: var(--font-headline);
  font-size: 2.0rem;
  font-weight: 700;
  font-style: normal;
  color: rgba(23, 54, 74, 0.88);
  line-height: 1.1;
  letter-spacing: -0.01em;
  margin-bottom: 0.3rem;
  text-align: center;
}

/* Subtitle */
.essay-subtitle {
  font-family: var(--font-headline);
  font-style: italic;
  font-weight: 700;
  font-size: 1.35rem;
  color: rgba(23, 54, 74, 0.65);
  line-height: 1.25;
  margin-bottom: 0.75rem;
  text-align: center;
}

/* Byline — shared style for author and date lines */
.essay-byline {
  font-family: var(--font-body);
  font-style: italic;
  font-weight: 400;
  font-size: 0.84rem;
  color: var(--text);
  opacity: 0.52;
  margin-bottom: 1.3rem; /* author → lede */
  text-align: center;
}

/* Lede / intro */
.essay-intro {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 1.05rem;
  line-height: 1.78;
  color: var(--text);
  margin-bottom: 0.8rem; /* lede → date */
}

/* Date byline — tighter spacing, PUBLISHED label above */
.essay-byline--date {
  margin-bottom: 0.8rem; /* date → divider */
}

.essay-byline--date::before {
  content: 'PUBLISHED';
  display: block;
  font-family: var(--font-ui);
  font-style: normal;
  font-weight: 500;
  font-size: 0.52rem;
  letter-spacing: 0.22em;
  opacity: 0.45;
  margin-bottom: 0.25rem;
}

/* Coral divider */
.essay-divider {
  border: none;
  border-top: 1px solid var(--coral);
  margin: 0;
}

@media (min-width: 769px) {
  .essay-header   { margin-bottom: 4rem; }
  .essay-header h1 { font-size: 2.8rem; }
  .essay-subtitle  { font-size: 1.6rem; }
}

@media (min-width: 1100px) {
  .essay-header h1 { font-size: 3.2rem; }
  .essay-subtitle  { font-size: 1.75rem; }
}

/* -------------------------------------------------------
   Essay body
   Explicit line-height and paragraph spacing give the
   prose its own slower rhythm, distinct from the rest
   of the page. This is where sustained reading happens.
------------------------------------------------------- */
.essay-body {
  line-height: 1.92;
}

.essay-body p { margin-bottom: 1.6em; }

.essay-body p:last-child { margin-bottom: 0; }

.essay-body h2 {
  font-family: var(--font-headline);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.15;
  margin: 2.8em 0 0.6em;
}

.essay-body h3 {
  font-family: var(--font-headline);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.15;
  margin: 2.2em 0 0.5em;
}

.essay-body blockquote {
  border-left: 2px solid rgba(178, 74, 47, 0.35);
  margin: 2.2em 0;
  padding-left: 1.4em;
  font-style: italic;
  color: #3d3d3d;
}

.essay-body ul,
.essay-body ol {
  margin: 0 0 1.6em 1.35em;
}

.essay-body li { margin-bottom: 0.5em; }

/* -------------------------------------------------------
   Links
------------------------------------------------------- */
a {
  color: var(--coral);
  text-decoration: underline;
  text-decoration-color: var(--coral);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

a:hover {
  color: #8c3330;
  text-decoration-color: #8c3330;
}

/* Structural links — override coral default */
.header-wordmark__link,
.header-wordmark__link:hover {
  color: var(--bg);
  text-decoration: none;
}

.site-nav__link,
.site-nav__link:hover {
  color: var(--cream-panel);
  text-decoration: none;
}

.site-footer a {
  color: inherit;
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
}

/* -------------------------------------------------------
   Images
------------------------------------------------------- */
.essay-body figure { margin: 2em 0; }

.essay-body figure img,
.essay-body img:not(figure img) {
  width: 100%;
  height: auto;
  filter: sepia(0.05) saturate(0.95);
}

.essay-body img:not(figure img) { margin: 2em 0; }

.essay-body figcaption {
  margin-top: 0.6em;
  font-family: var(--font-body);
  font-style: italic;
  text-align: center;
  font-size: 0.8rem;
  color: var(--coral);
  line-height: 1.5;
}

/* -------------------------------------------------------
   Homepage (Phase 3)
------------------------------------------------------- */

/* Latest essay — no extra margin; page-content padding handles top space */
.home-latest { }

/* Subsequent sections — generous vertical rhythm */
.home-section { margin-top: 5em; }

/* Section headings: lowercase Cormorant italic, coral, ~24px */
.home-section__heading {
  font-family: var(--font-headline);
  font-style: italic;
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--coral);
  margin-bottom: 1.4rem;
  letter-spacing: 0;
}

/* Recent essays list */
.recent-essay { padding: 1.1em 0; }

.recent-essay + .recent-essay {
  border-top: 1px solid rgba(178, 74, 47, 0.22);
}

.recent-essay__header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.7em;
  margin-bottom: 0.2em;
}

.recent-essay__title {
  font-family: var(--font-headline);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--navy);
  text-decoration: none;
  transition: color 0.15s ease;
}

.recent-essay__title:hover { color: var(--coral); text-decoration: none; }

.recent-essay__date {
  font-family: var(--font-ui);
  font-size: 0.60rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brass);
  flex-shrink: 0;
}

.recent-essay__desc {
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--navy);
  font-style: italic;
  margin: 0;
  opacity: 0.8;
}

/* Favorite essays — pure title list, hover to coral */
.favorite-essay {
  display: block;
  font-family: var(--font-headline);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--navy);
  text-decoration: none;
  padding: 0.75em 0;
  transition: color 0.15s ease;
}

.favorite-essay + .favorite-essay {
  border-top: 1px solid rgba(178, 74, 47, 0.22);
}

.favorite-essay:hover { color: var(--coral); text-decoration: none; }

/* Subjects — comma-separated prose-style Inter small caps */
.subjects-list {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--navy);
  margin: 0;
  line-height: 2;
}

.subjects-list a { color: var(--navy); text-decoration: none; transition: color 0.15s ease; }
.subjects-list a:hover { color: var(--coral); text-decoration: none; }

/* Surprise / Archive action links */
.home-action {
  text-align: center;
  font-family: var(--font-ui);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-top: 5em;
}

.home-action a { color: var(--coral); text-decoration: none; }
.home-action a:hover { text-decoration: underline; text-decoration-thickness: 1px; }

.home-action__sep {
  color: var(--coral);
  padding: 0 0.5em;
  opacity: 0.7;
  user-select: none;
}

/* Newsletter placeholder */
.home-newsletter {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--text);
  opacity: 0.45;
  text-align: center;
  max-width: 500px;
  margin: 2em auto 0;
}

/* Empty state for recent/favorites when no content exists */
.home-empty {
  font-family: var(--font-body);
  font-style: italic;
  color: var(--text);
  opacity: 0.45;
  text-align: center;
  margin: 0;
}

/* -------------------------------------------------------
   Preview card (Phase 2)
   Anchored to links with data-preview. JS positions it
   adjacent to the linked word and sets --tail-left so the
   triangular pointer aims at the link's horizontal center.
------------------------------------------------------- */
.preview-card {
  position: absolute;
  z-index: 200;
  background: #C4C6B2;        /* sage — matches masthead panel tone */
  border: 1px solid var(--navy);
  border-radius: 2px;
  box-shadow: 0 4px 16px rgba(23, 54, 74, 0.15);
  padding: 16px;
  max-width: 320px;
  width: max-content;
  transition: opacity 0.15s ease;
}

/* Tail pointing up — card is below the link (default) */
.preview-card::before,
.preview-card::after {
  content: '';
  position: absolute;
  left: var(--tail-left, 14px);
  transform: translateX(-50%);
  pointer-events: none;
}

.preview-card::before {
  top: -9px;
  border: 8px solid transparent;
  border-top: none;
  border-bottom-color: var(--navy);
}

.preview-card::after {
  top: -7px;
  border: 7px solid transparent;
  border-top: none;
  border-bottom-color: #C4C6B2;
}

/* Tail pointing down — card is above the link */
.preview-card--above::before {
  top: auto;
  bottom: -9px;
  border: 8px solid transparent;
  border-bottom: none;
  border-top-color: var(--navy);
}

.preview-card--above::after {
  top: auto;
  bottom: -7px;
  border: 7px solid transparent;
  border-bottom: none;
  border-top-color: #C4C6B2;
}

.preview-card__close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: var(--navy);
  opacity: 0.35;
  padding: 2px 5px;
  transition: opacity 0.12s ease;
}

.preview-card__close:hover,
.preview-card__close:focus {
  opacity: 0.8;
  outline: none;
}

.preview-card__text {
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--navy);
  line-height: 1.5;
  margin: 0;
  padding-right: 22px; /* clear close button */
}

.preview-card__divider {
  height: 1px;
  background: var(--coral);
  opacity: 0.45;
  margin: 10px 0;
}

.preview-card__read-more {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--coral);
  text-decoration: none;
}

.preview-card__read-more:hover {
  color: var(--coral);
  text-decoration: underline;
  text-decoration-thickness: 1px;
}

@media (max-width: 480px) {
  .preview-card { max-width: 280px; }
}

/* -------------------------------------------------------
   Footer
------------------------------------------------------- */
.site-footer {
  margin-top: 3.5rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(179, 138, 74, 0.35);
  font-family: var(--font-ui);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text);
  opacity: 0.5;
}
