/* ===================================================
   Open Heart Journey — Stylesheet v7 ("The Garden")
   Spec: design/design-spec-v4.md (r3)

   Two surfaces, one seam:
   - The garden (roji): home hero, seam, chapter index, clearings
   - The room (tea room): chapter pages, about — v3 reading spec verbatim
   =================================================== */

/* --- Font Faces (self-hosted, no new fonts — spec SS4) --- */

@font-face {
  font-family: 'EB Garamond';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url('/fonts/eb-garamond-variable.woff2') format('woff2');
}

@font-face {
  font-family: 'EB Garamond';
  font-style: italic;
  font-weight: 400 800;
  font-display: swap;
  src: url('/fonts/eb-garamond-italic-variable.woff2') format('woff2');
}

@font-face {
  font-family: 'Instrument Sans';
  font-style: normal;
  font-weight: 400 500;
  font-display: swap;
  src: url('/fonts/instrument-sans-variable.woff2') format('woff2');
}

/* --- Reading Tokens (v3 SS2 verbatim — light mode default) --- */

:root {
  --surface: #FAFAF7;
  --surface-depth: #F5F5F0;
  --text: #1C1917;
  --text-secondary: #78716C;
  --accent: #A8A29E;
  --link: #44403C;
  --epigraph-rule: #D6D3D1;
  /* --paper is an alias of --surface (spec SS3.3) — use --surface in CSS. */

  /* Garden tokens — day (spec SS3.1). Used ONLY on garden surfaces. */
  --g-pond: #48685C;
  --g-pond-deep: #1F3A33;
  --g-koi-verm: #C1553B;
  --g-koi-white: #F2EDE2;
  --g-komorebi: #E8DCA8;
  --g-lantern: #D9A05B;
  --g-moon: #EFF3E9;
  --g-ink: var(--g-pond-deep);
  --g-deep-rgb: 31, 58, 51; /* --g-pond-deep as components, for alpha use */
  --g-hero-text: #FAFAF7;
  --g-ring: rgba(250, 250, 247, 0.45);
  --g-mist: rgba(250, 250, 247, 0.8);
  --glow-o: 0.3; /* lantern glow at day: 30% — a promise, not a beacon (SS7.2) */
}

/* --- Night Garden + dark reading room (v3 SS2.2 / v4 SS3.2) --- */

@media (prefers-color-scheme: dark) {
  :root {
    --surface: #1C1917;
    --surface-depth: #171412;
    --text: #E7E5E4;
    --text-secondary: #A8A29E;
    --accent: #57534E;
    --link: #D6D3D1;
    --epigraph-rule: #44403C;

    --g-pond: #101B2C;
    --g-pond-deep: #070E1A;
    --g-deep-rgb: 7, 14, 26;
    --g-koi-white: #E4DFD2;
    --g-koi-verm: #96492F;
    --g-hero-text: #E7E5E4;
    --g-ring: rgba(239, 243, 233, 0.5);
    --g-mist: rgba(239, 243, 233, 0.7);
    --glow-o: 0.95;
  }
}

/* --- Reset & Base --- */

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

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  font-family: 'EB Garamond', 'Georgia', 'Times New Roman', serif;
  font-size: clamp(1.125rem, 0.97rem + 0.68vw, 1.375rem);
  line-height: 1.72;
  color: var(--text);
  /* v3 SS2.4 — the surface receiving light from above */
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-depth) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures;
  font-variant-numeric: oldstyle-nums;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

@supports not (background-attachment: fixed) {
  body { background: var(--surface); }
}

@media (max-width: 768px) {
  body {
    background: var(--surface);
    background-attachment: scroll;
  }
}

/* Page presence — v3 SS6.4: the content resolves; the eyes adjust */
body {
  opacity: 0;
  animation: page-present 400ms ease-out 50ms forwards;
}

@keyframes page-present {
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  body { opacity: 1; animation: none; }
}

/* --- Selection (v3 SS6.2 — inverted palette) --- */

::selection {
  background-color: var(--text);
  color: var(--surface);
}

/* --- Links (v3 SS6.3) --- */

a {
  color: var(--link);
  text-decoration: none;
  transition: color 200ms ease-out;
}

a:hover {
  text-decoration: none;
  border-bottom: 1px solid currentColor;
  padding-bottom: 1px;
}

/* Exceptions: large text links + shipped nav mechanics get color-only hover */
.chapter-title-link:hover,
.site-title a:hover,
.drawer-chapter-entry a:hover {
  border-bottom: none;
  padding-bottom: 0;
}

/* --- Focus States (v3 SS7.3) --- */

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 4px;
  border-radius: 2px;
}

/* --- Layout (v3 SS4.2) --- */

.page-column {
  max-width: 38em;
  margin: 0 auto;
  padding: 4rem clamp(1.5rem, 6vw, 2rem) 0;
}

@media (min-width: 640px) {
  .page-column {
    padding-top: 5.5rem;
    padding-left: 2.5rem;
    padding-right: 2.5rem;
  }
}

@media (min-width: 1024px) {
  .page-column {
    padding-top: 7rem;
    padding-left: 0;
    padding-right: 0;
  }
}

/* --- Site Header (subpages — v3 SS5.1) --- */

.site-header {
  text-align: center;
  margin-bottom: 2.5rem;
}

@media (min-width: 640px) {
  .site-header { margin-bottom: 3rem; }
}

@media (min-width: 1024px) {
  .site-header { margin-bottom: 3.5rem; }
}

.site-title {
  font-family: 'EB Garamond', 'Georgia', serif;
  font-size: clamp(0.875rem, 0.8rem + 0.34vw, 1.0625rem);
  font-weight: 400;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-secondary);
  line-height: 1.4;
}

.site-title a {
  color: inherit;
}

.site-title a:hover {
  color: var(--link);
}

/* The structural whisper below the subpage header (v3 SS5.1) */
.site-header-rule {
  display: block;
  width: 100%;
  height: 1px;
  background-color: var(--accent);
  opacity: 0.3;
  border: none;
  margin: 1rem 0 0;
}

.site-nav {
  margin-top: 1rem;
  margin-bottom: 1rem;
  font-family: 'Instrument Sans', 'Helvetica Neue', system-ui, sans-serif;
  font-size: clamp(0.8125rem, 0.77rem + 0.23vw, 0.9375rem);
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.site-nav a {
  color: var(--text-secondary);
  margin: 0 1em;
}

.site-nav a:hover {
  color: var(--link);
  border-bottom: none;
  padding-bottom: 0;
}

/* ===================================================
   THE GARDEN — Zone A: the pond (spec SS5.1, SS7.1)
   =================================================== */

.garden-hero {
  position: relative;
  height: 100svh;
  overflow: hidden;
  background: var(--g-pond);
  z-index: 0; /* isolate the hero's stacking context */
}

/* Layer z-stack, nearest first (SS6.5): branches > mist > surface > koi > floor */
.garden-still    { z-index: 1; }
.garden-water    { z-index: 2; }
.garden-hero::after { z-index: 3; }
.garden-mist     { z-index: 4; }
.garden-branches { z-index: 5; }
.hero-title-block { z-index: 6; }

.garden-still,
.garden-water,
.garden-branches,
.garden-mist {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* The live water canvas fades in over the still (SS6.1) */
.garden-water {
  opacity: 0;
  transition: opacity 900ms ease;
}

.garden-water.is-live { opacity: 1; }
.garden-water.is-fading { transition: opacity 600ms ease; opacity: 0; }

/* Tier 2 water: CSS gradient background — --pond -> --pond-deep radial
   offset toward the title corner, plus an edge vignette (SS6.2 Tier 2).
   Opaque: it replaces the still while live koi swim over it. */
.garden-water.tier2 {
  background:
    radial-gradient(78% 78% at 50% 46%,
      rgba(var(--g-deep-rgb), 0) 55%,
      rgba(var(--g-deep-rgb), 0.42) 100%),
    radial-gradient(130% 130% at 24% 28%,
      var(--g-pond-deep) 0%,
      var(--g-pond) 62%);
}

/* Hero bottom dissolves into the flat pond that continues in the seam */
.garden-hero::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 16svh;
  background: linear-gradient(to bottom, transparent, var(--g-pond));
  pointer-events: none;
}

/* --- The Tier 3 still: painting classes (SS6.2 Tier 3) --- */

.gs-water   { fill: var(--g-pond); }
.gs-depth-a { stop-color: var(--g-pond-deep); stop-opacity: 0.8; }
.gs-depth-b { stop-color: var(--g-pond-deep); stop-opacity: 0.45; }
.gs-depth-c { stop-color: var(--g-pond-deep); stop-opacity: 0.15; }
.gs-depth-d { stop-color: var(--g-pond-deep); stop-opacity: 0; }
.gs-vig-a   { stop-color: var(--g-pond-deep); stop-opacity: 0; }
.gs-vig-b   { stop-color: var(--g-pond-deep); stop-opacity: 0.05; }
.gs-vig-c   { stop-color: var(--g-pond-deep); stop-opacity: 0.38; }
.gs-mot-a   { stop-color: var(--g-pond-deep); stop-opacity: 0.32; }
.gs-mot-b   { stop-color: var(--g-pond-deep); stop-opacity: 0.18; }
.gs-mot-c   { stop-color: var(--g-pond-deep); stop-opacity: 0; }
.gs-komo-a  { stop-color: var(--g-komorebi); stop-opacity: 0.07; }
.gs-komo-b  { stop-color: var(--g-komorebi); stop-opacity: 0.04; }
.gs-komo-c  { stop-color: var(--g-komorebi); stop-opacity: 0; }
.gs-halo-a  { stop-color: var(--g-moon); stop-opacity: 0.35; }
.gs-halo-b  { stop-color: var(--g-moon); stop-opacity: 0.12; }
.gs-halo-c  { stop-color: var(--g-moon); stop-opacity: 0; }
.gs-moon    { fill: var(--g-moon); }
.gs-shard   { fill: var(--g-moon); }
.gs-ring    { fill: none; stroke: var(--g-ring); stroke-width: 1; }
.gs-ink     { fill: var(--g-ink); }
.gs-twig    { stroke: var(--g-ink); stroke-width: 3; fill: none; opacity: 0.9; }

/* Koi (SS6.3 — flat tones + spine contour, no gradients on fish) */
.k-body-white { fill: var(--g-koi-white); }
.k-body-verm  { fill: var(--g-koi-verm); }
.k-patch-verm { fill: var(--g-koi-verm); }
.k-patch-ink  { fill: var(--g-ink); }
.k-fin        { opacity: 0.85; }
.k-line       { fill: none; stroke: var(--g-ink); stroke-width: 1.2; opacity: 0.7; }

/* Day / night groups inside the still */
.still-night { display: none; }
.still-day   { display: block; }

@media (prefers-color-scheme: dark) {
  .still-night { display: block; }
  .still-day   { display: none; }
}

/* Still composition — transform-positioned groups. Koi scale implements the
   exact SS6.3 body-length clamp: clamp(70px, 9vw, 150px) x variance, where
   the drawn spine is 102 local units. */
.pos-koi.koi-lead {
  transform: translate(55vw, 47svh) rotate(-22deg)
    scale(calc(clamp(70px, 9vw, 150px) * 1.15 / 102px));
}

.pos-koi.koi-b {
  transform: translate(37vw, 64svh) rotate(18deg)
    scale(calc(clamp(70px, 9vw, 150px) * 0.85 / 102px));
}

.pos-koi.koi-c {
  transform: translate(64vw, 69svh) rotate(-98deg)
    scale(calc(clamp(70px, 9vw, 150px) / 102px));
}

/* Moon anchored at (68%, 22%) of viewport (SS6.2); glint path below it */
.pos-moon {
  transform: translate(68vw, 22svh)
    scale(calc(clamp(80px, 10vw, 150px) / 100px));
}

.pos-glint {
  transform: translate(68vw, 30svh)
    scale(calc(clamp(56px, 7vw, 100px) / 60px), calc(38svh / 260px));
}

/* --- Branches (SS6.5 layer 1) --- */

@media (max-width: 639.98px) {
  .garden-branches .branch-r { display: none; } /* SS9: one corner only */

  /* Narrow portrait: the 68%/22% moon anchor would sit under the title
     block and break the SS3.4 mandatory contrast (measured 1.12:1 at gate 1).
     The moon rides higher, clear of the title. Tier 1/2 anchors match. */
  .pos-moon  { transform: translate(74vw, 8svh) scale(calc(clamp(80px, 10vw, 150px) / 100px)); }
  .pos-glint { transform: translate(74vw, 15svh) scale(calc(clamp(56px, 7vw, 100px) / 60px), calc(34svh / 260px)); }
  .tier2-moon  { top: 8%; left: 74%; }
  .tier2-glint { top: 12%; left: 74%; }
}

/* --- Mist wisps (SS6.7 — continuous but sub-perceptual) --- */

.mist-band {
  position: absolute;
  left: -12%;
  width: 124%;
  height: 16%;
  /* Soft-stop 2D gradient — no hard band edges (SS8) */
  background: radial-gradient(50% 50% at 50% 50%,
    var(--g-mist) 0%,
    rgba(255, 255, 255, 0) 72%);
  will-change: transform;
}

.mist-a {
  top: 32%;
  opacity: 0.06;
  animation: mist-drift-a 90s ease-in-out infinite;
}

.mist-b {
  top: 61%;
  opacity: 0.09;
  animation: mist-drift-b 140s ease-in-out infinite;
}

@keyframes mist-drift-a {
  0%   { transform: translateX(-4%); }
  50%  { transform: translateX(4%); }
  100% { transform: translateX(-4%); }
}

@keyframes mist-drift-b {
  0%   { transform: translateX(3.5%); }
  50%  { transform: translateX(-3.5%); }
  100% { transform: translateX(3.5%); }
}

/* --- Hero title block (SS4, SS7.1) --- */

.hero-title-block {
  position: absolute;
  top: clamp(4rem, 16svh, 10rem);
  left: clamp(1.5rem, 8vw, 7rem);
  right: clamp(1.5rem, 6vw, 2rem);
  max-width: 40ch;
  text-align: left;
  color: var(--g-hero-text);
  pointer-events: none;
}

.hero-title {
  font-family: 'EB Garamond', 'Georgia', serif;
  font-size: clamp(2.25rem, 1.6rem + 2.9vw, 4rem);
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: normal;
  color: inherit;
}

.hero-subtitle {
  font-family: 'EB Garamond', 'Georgia', serif;
  font-style: italic;
  font-weight: 400;
  font-size: clamp(1.0625rem, 0.95rem + 0.5vw, 1.375rem);
  line-height: 1.5;
  max-width: 34ch;
  margin-top: 1.25rem;
  color: inherit;
}

/* Day-mode scrim — MANDATORY (SS3.4). Radial pond-deep (#1F3A33) at 35%,
   soft-stop, >= 1.5x the title block box, reads as deep water. */
.hero-title-block::before {
  content: '';
  position: absolute;
  inset: -55% -45% -60% -45%;
  /* Explicit ellipse size: alpha reaches 0 INSIDE the box — no hard edge */
  background: radial-gradient(ellipse 42% 42% at 50% 48%,
    rgba(31, 58, 51, 0.35) 0%,
    rgba(31, 58, 51, 0.31) 30%,
    rgba(31, 58, 51, 0.22) 55%,
    rgba(31, 58, 51, 0.10) 76%,
    rgba(31, 58, 51, 0) 100%);
  z-index: -1;
  pointer-events: none;
}

@media (prefers-color-scheme: dark) {
  /* Night needs no scrim (13.9:1) — legibility insurance is the shadow (SS4) */
  .hero-title-block::before { display: none; }
  .hero-title,
  .hero-subtitle { text-shadow: 0 1px 18px rgba(0, 0, 0, 0.25); }
}

/* ===================================================
   THE GARDEN — Zone B: the seam (SS5.1, SS7.2)
   =================================================== */

.garden-seam {
  position: relative;
  z-index: 1;
  height: 55vh;
  margin-top: -4svh; /* the miegakure glimpse — foliage intrudes into Zone A */
  pointer-events: none;
}

.seam-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.gs-seamw-a { stop-color: var(--g-pond); }
.gs-seamw-b { stop-color: var(--g-pond-deep); }
.gs-paper   { fill: var(--surface); }
.gs-lant-a  { stop-color: var(--g-lantern); stop-opacity: 0.5; }
.gs-lant-b  { stop-color: var(--g-lantern); stop-opacity: 0.26; }
.gs-lant-c  { stop-color: var(--g-lantern); stop-opacity: 0.1; }
.gs-lant-d  { stop-color: var(--g-lantern); stop-opacity: 0; }
.gs-flame   { fill: var(--g-lantern); opacity: 0.4; }

@media (prefers-color-scheme: dark) {
  .gs-flame { opacity: 0.9; }
}

/* Lantern breathing: ±3% at ~7s (SS6.7). The JS dip lives on .lantern-dim. */
.lantern-glow {
  opacity: var(--glow-o);
  animation: lantern-breath 7s ease-in-out infinite;
}

@keyframes lantern-breath {
  0%, 100% { opacity: var(--glow-o); }
  50%      { opacity: calc(var(--glow-o) * 0.94); }
}

.lantern-dim {
  transition: opacity 1.2s ease;
}

.lantern-dim.is-dip {
  opacity: 0.92; /* −8% dip over 1.2s — a flame answering unseen air */
}

/* ===================================================
   THE GARDEN — Zone C: the index (v3 SS5.2 via v4 SS7.3)
   =================================================== */

.index-zone {
  padding-top: 4rem; /* Zone B -> first stone: 4rem mobile */
  padding-bottom: 1rem;
}

@media (min-width: 1024px) {
  .index-zone { padding-top: 6rem; } /* 6rem desktop (SS5.3) */
}

.chapter-index {
  list-style: none;
  max-width: 38em;
  margin: 0 auto;
  padding: 0 clamp(1.5rem, 6vw, 2rem);
}

@media (min-width: 640px) {
  .chapter-index { padding: 0 2.5rem; }
}

@media (min-width: 1024px) {
  .chapter-index { padding: 0; }
}

.chapter-entry {
  margin-bottom: 3rem;
  position: relative;
  text-align: left;
  transition: transform 400ms ease-in-out; /* the breath back in (v3 SS5.2) */
}

.chapter-entry:hover {
  transform: translateX(3px);
  transition: transform 300ms ease-out; /* the breath out */
}

/* Ghost separator — 2.5em, half-visible, the faintest metronome tick */
.chapter-entry::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -1.5rem;
  transform: translateX(-50%);
  width: 2.5em;
  height: 1px;
  background-color: var(--accent);
  opacity: 0.5;
}

.chapter-index > li:last-child::after,
.chapter-entry:has(+ .clearing)::after {
  display: none;
}

.chapter-number {
  font-family: 'Instrument Sans', 'Helvetica Neue', system-ui, sans-serif;
  font-size: clamp(0.8125rem, 0.79rem + 0.11vw, 0.875rem);
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 0.4rem;
}

.chapter-title-link {
  font-family: 'EB Garamond', 'Georgia', serif;
  font-size: clamp(1.375rem, 1.2rem + 0.8vw, 1.75rem);
  font-weight: 500;
  line-height: 1.25;
  color: var(--text);
  display: block;
  margin-bottom: 0.5rem;
  transition: color 200ms ease-out;
}

.chapter-title-link:hover {
  color: var(--link);
}

.chapter-epigraph-preview {
  font-family: 'EB Garamond', 'Georgia', serif;
  font-size: clamp(0.9375rem, 0.89rem + 0.23vw, 1.0625rem);
  font-style: italic;
  line-height: 1.55;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Once-only reveals (SS6.6) — JS adds the hidden state only when the
   observer will run; content is never gated on JS. */
.chapter-entry.reveal-pending {
  opacity: 0;
  transform: translateY(12px);
}

.chapter-entry.reveal-in {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 600ms ease-out, transform 600ms ease-out;
}

/* ===================================================
   THE GARDEN — Zone C': clearings (SS5.1, SS7.4)
   =================================================== */

.clearing {
  list-style: none;
  height: 35vh;
  width: 100vw;
  margin-left: calc(50% - 50vw);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  pointer-events: none;
}

.clearing-art {
  opacity: 0.07;
  height: min(24vh, 240px);
}

.clearing-art svg {
  height: 100%;
  width: auto;
}

/* ===================================================
   THE ROOM — chapter pages (v3 verbatim + SS6.10 presences)
   =================================================== */

.chapter-header {
  text-align: center;
  margin-bottom: 0;
  position: relative;
}

.chapter-header .chapter-number {
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

.chapter-page-title {
  font-family: 'EB Garamond', 'Georgia', serif;
  font-size: clamp(1.625rem, 1.28rem + 1.52vw, 2.25rem);
  font-weight: 400;
  line-height: 1.15;
  color: var(--text);
}

/* Presence 1 — ripple-on-load: the roji's last stone (SS6.10). CSS-only. */
.chapter-ripple {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(26rem, 80vw);
  aspect-ratio: 1;
  border: 1px solid currentColor;
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  animation: chapter-ripple 1100ms ease-out 1 forwards;
}

@keyframes chapter-ripple {
  from { transform: translate(-50%, -50%) scale(0.2); opacity: 0.06; }
  to   { transform: translate(-50%, -50%) scale(1.6); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .chapter-ripple { display: none; }
}

/* Presence 2 — the resting koi watermark (SS6.10) */
.koi-watermark {
  display: flex;
  justify-content: center;
  margin-top: 3rem;
  opacity: 0.04;
  color: var(--text);
}

.koi-watermark svg {
  width: 60px;
  height: 120px;
}

.koi-watermark path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
}

@media (prefers-color-scheme: dark) {
  .koi-watermark { opacity: 0.06; }
}

/* --- The Epigraph — the cruciform cut (v3 SS5.3) --- */

.epigraph {
  font-family: 'EB Garamond', 'Georgia', 'Times New Roman', serif;
  font-size: clamp(1.1875rem, 1.01rem + 0.78vw, 1.5rem);
  font-style: italic;
  line-height: 1.5;
  color: var(--text);
  padding: 0;
  border: none;
  margin-top: 2.5rem;
  margin-bottom: 3rem;
  text-align: center;
}

.epigraph::before {
  content: '';
  display: block;
  width: 5rem;
  max-width: 5rem;
  height: 1px;
  background-color: var(--epigraph-rule);
  margin: 0 auto 1.5rem;
}

.epigraph p {
  margin: 0;
}

/* --- Chapter Body (v3 SS5.4 — no drop caps, no first-line effects) --- */

.chapter-body {
  text-align: left;
}

.chapter-body p {
  margin-bottom: 1.5em;
}

.chapter-body p:first-child {
  margin-top: 0;
}

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

.chapter-divider {
  display: block;
  width: 2.5em;
  max-width: 2.5em;
  height: 1px;
  background-color: var(--accent);
  border: none;
  margin: 3.5rem auto;
  opacity: 0.6;
}

/* --- Prev/Next Navigation (v3 SS5.6) --- */

.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--accent);
  font-family: 'Instrument Sans', 'Helvetica Neue', system-ui, sans-serif;
  font-size: clamp(0.8125rem, 0.77rem + 0.23vw, 0.9375rem);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.chapter-nav a {
  color: var(--text-secondary);
}

.chapter-nav a:hover {
  color: var(--link);
  border-bottom: none;
  padding-bottom: 0;
}

.chapter-nav-prev { flex: 1; text-align: left; }
.chapter-nav-center { flex: 1; text-align: center; }
.chapter-nav-next { flex: 1; text-align: right; }

/* --- Chapter Drawer (shipped navigation — survives v4 unchanged, SS10.2.
       Token inheritance only; box-shadow removed per SS8.) --- */

.chapter-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 900;
  opacity: 0;
  visibility: hidden;
  transition: opacity 250ms ease-out, visibility 250ms ease-out;
}

.chapter-drawer-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

.chapter-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(24rem, 85vw);
  background-color: var(--surface);
  border-right: 1px solid var(--epigraph-rule);
  z-index: 1000;
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform 250ms ease-out;
  padding: 2rem 1.5rem;
}

.chapter-drawer.is-open {
  transform: translateX(0);
}

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

.chapter-drawer-title {
  font-family: 'Instrument Sans', 'Helvetica Neue', system-ui, sans-serif;
  font-size: clamp(0.8125rem, 0.77rem + 0.23vw, 0.9375rem);
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--epigraph-rule);
}

.drawer-chapter-list {
  list-style: none;
}

.drawer-chapter-entry {
  margin-bottom: 0.25rem;
}

.drawer-chapter-entry a {
  display: block;
  padding: 0.5rem 0.75rem;
  border-left: 2px solid transparent;
  transition: border-color 200ms ease-out, color 200ms ease-out;
}

.drawer-chapter-entry a:hover {
  border-left-color: var(--accent);
}

.drawer-chapter-entry.is-current a {
  border-left-color: var(--text-secondary);
  background-color: var(--surface-depth);
}

.drawer-chapter-number {
  font-family: 'Instrument Sans', 'Helvetica Neue', system-ui, sans-serif;
  font-size: 0.6875rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 0.125rem;
}

.drawer-chapter-title {
  font-family: 'EB Garamond', 'Georgia', serif;
  font-size: 1rem;
  font-weight: 400;
  color: var(--text);
  line-height: 1.3;
}

/* --- About Page (v3 SS5.8) --- */

.about-body {
  font-size: clamp(1.0625rem, 0.95rem + 0.45vw, 1.3125rem);
}

.about-body p {
  margin-bottom: 1.5em;
}

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

.page-title {
  font-family: 'EB Garamond', 'Georgia', serif;
  font-size: clamp(1.625rem, 1.28rem + 1.52vw, 2.25rem);
  font-weight: 400;
  line-height: 1.15;
  color: var(--text);
  margin-bottom: 2.5rem;
  text-align: center;
}

/* --- Footer (v3 SS5.7 — the quiet credit at the end of the film) --- */

.site-footer {
  margin-top: 3rem;
  padding-top: 2rem;
  padding-bottom: 3.5rem;
  text-align: center;
  font-family: 'Instrument Sans', 'Helvetica Neue', system-ui, sans-serif;
  font-size: clamp(0.8125rem, 0.77rem + 0.23vw, 0.9375rem);
  font-weight: 400;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
  line-height: 1.8;
  border-top: 1px solid var(--accent);
  opacity: 0.85;
}

/* Homepage footer sits in the index column (garden zones are full-bleed) */
.page-home .site-footer {
  max-width: 38em;
  margin-left: auto;
  margin-right: auto;
  padding-left: clamp(1.5rem, 6vw, 2rem);
  padding-right: clamp(1.5rem, 6vw, 2rem);
}

.site-footer a {
  color: var(--text-secondary);
}

.site-footer a:hover {
  color: var(--link);
}

.colophon {
  margin-bottom: 0.5rem;
  font-style: italic;
  font-family: 'EB Garamond', 'Georgia', serif;
  letter-spacing: 0.02em;
}

/* ===================================================
   Tier 2 DOM helpers (created by garden.js only — SS6.2 Tier 2, SS6.7)
   =================================================== */

/* Day: exactly ONE soft-stop komorebi patch, own layer, transform-only 90s loop */
.tier2-komorebi {
  position: absolute;
  left: 12%;
  top: 6%;
  width: 46vw;
  height: 30vw;
  max-width: 640px;
  max-height: 420px;
  /* Explicitly sized gradient: alpha reaches 0 INSIDE the box — the
     farthest-corner default printed a visible rectangle (SS8) */
  background: radial-gradient(50% 50% at 50% 50%,
    rgba(232, 220, 168, 0.08) 0%,
    rgba(232, 220, 168, 0.04) 45%,
    rgba(232, 220, 168, 0) 72%);
  pointer-events: none;
  z-index: 3;
  will-change: transform;
  animation: komorebi-drift 90s ease-in-out infinite;
}

@keyframes komorebi-drift {
  0%   { transform: translate(0, 0); }
  22%  { transform: translate(9vw, 4vh); }
  47%  { transform: translate(15vw, -2vh); }
  71%  { transform: translate(6vw, 6vh); }
  100% { transform: translate(0, 0); }
}

/* Night: static moon disc + pre-drawn glint streak, opacity ±10% at 1.3Hz */
.tier2-moon {
  position: absolute;
  left: 68%;
  top: 22%;
  width: clamp(56px, 7vw, 96px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle,
    var(--g-moon) 0%,
    var(--g-moon) 46%,
    rgba(239, 243, 233, 0.22) 58%,
    rgba(239, 243, 233, 0) 72%);
  pointer-events: none;
  z-index: 3;
}

.tier2-glint {
  position: absolute;
  left: 68%;
  top: 30%; /* gap below the moon disc */
  width: clamp(72px, 9vw, 120px);
  height: 38%;
  transform: translateX(-50%);
  /* Pre-drawn glint as stacked horizontal shards (the Tier 3 arrangement) —
     soft dash gradients, not a searchlight column (SS6.2 night) */
  background-image:
    radial-gradient(closest-side, rgba(239, 243, 233, 0.5), rgba(239, 243, 233, 0) 100%),
    radial-gradient(closest-side, rgba(239, 243, 233, 0.38), rgba(239, 243, 233, 0) 100%),
    radial-gradient(closest-side, rgba(239, 243, 233, 0.3), rgba(239, 243, 233, 0) 100%),
    radial-gradient(closest-side, rgba(239, 243, 233, 0.22), rgba(239, 243, 233, 0) 100%),
    radial-gradient(closest-side, rgba(239, 243, 233, 0.16), rgba(239, 243, 233, 0) 100%),
    radial-gradient(closest-side, rgba(239, 243, 233, 0.11), rgba(239, 243, 233, 0) 100%);
  background-size: 44% 10px, 34% 9px, 28% 8px, 24% 7px, 19% 6px, 15% 6px;
  background-position: 46% 2%, 62% 17%, 34% 36%, 58% 55%, 42% 74%, 54% 92%;
  background-repeat: no-repeat;
  pointer-events: none;
  z-index: 3;
  animation: glint-shiver 0.77s ease-in-out infinite;
}

@keyframes glint-shiver {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.9; }
}

/* The falling petal / leaf (SS6.7 — one event you're lucky to see).
   Element created by garden.js; movement is rAF transform-only. */
.garden-petal {
  position: absolute;
  z-index: 5;
  width: 16px;
  height: 16px;
  pointer-events: none;
  will-change: transform;
}

.garden-petal svg { display: block; width: 100%; height: 100%; }
.garden-petal .petal-day   { fill: var(--g-koi-white); opacity: 0.85; }
.garden-petal .petal-night { fill: var(--g-pond-deep); opacity: 0.9; }

/* ===================================================
   The Seam transition (SS6.10) — cross-document view transitions
   =================================================== */

@view-transition {
  navigation: auto;
}

::view-transition-old(root) {
  animation: 400ms ease both vt-fade-out;
}

::view-transition-new(root) {
  animation: 400ms ease both vt-fade-in;
}

@keyframes vt-fade-out {
  to { opacity: 0; transform: scale(1.01); }
}

@keyframes vt-fade-in {
  from { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) { animation: none; }
}

/* ===================================================
   Reduced motion (SS10.7) — Tier 3 static, everything quiet
   =================================================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
  .chapter-entry:hover { transform: none; }
  .mist-band { animation: none; }
  .lantern-glow { animation: none; }
  .tier2-komorebi, .tier2-glint { animation: none; }
}

/* ===================================================
   Print (v3 SS7.6 — garden layers gone)
   =================================================== */

@media print {
  body {
    background: #fff;
    color: #1C1917;
    font-size: 12pt;
    line-height: 1.7;
    opacity: 1;
    animation: none;
  }
  .garden-hero,
  .garden-seam,
  .clearing,
  .chapter-nav,
  .site-footer,
  .chapter-drawer,
  .chapter-drawer-backdrop,
  .chapter-ripple,
  .koi-watermark { display: none; }
  .site-header a { color: #1C1917; text-decoration: none; }
  .page-column { max-width: 100%; padding: 0; }
  .epigraph { color: #333; }
  .epigraph::before { background-color: #999; }
  .chapter-divider { background-color: #ccc; }
  a { color: #1C1917; text-decoration: none; }
}
