:root {
  --font-head: "Jost", "Segoe UI", sans-serif;
  --font-display: "Playfair Display", "Georgia", serif;
  --font-body: "Newsreader", "Georgia", serif;
  --font-brush: "Ma Shan Zheng", cursive;

  --paper: #f7f1ea;
  --ink: #241b17;
  --ink-soft: #7a6a60;
  --line: rgba(36, 27, 23, 0.12);
  --accent: #b8362f;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-snap-type: y mandatory;
}

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  animation: page-fade-in 1s ease both;
}

@keyframes page-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

h1, h2 {
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: -0.005em;
  margin: 0;
}

p {
  margin: 0;
}

a {
  color: inherit;
}

/* Keyboard focus — visible on every interactive element. Circular buttons
   get a box-shadow ring instead of an outline: it follows border-radius
   cleanly, and (for .contact-toggle) isn't clipped by overflow: hidden the
   way an outline would be. */
a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

.logo:focus-visible,
.contact-toggle:focus-visible,
.dock-link:focus-visible,
.next-cue:focus-visible,
.scroll-cue:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(184, 54, 47, 0.45);
}

/* Progress bar */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0%;
  background: var(--accent);
  z-index: 100;
  transition: width 0.1s linear;
}

/* Header */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: rgba(247, 241, 234, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 1px 0 rgba(36, 27, 23, 0);
  transition: box-shadow 0.4s ease, background 0.4s ease;
}

.site-header.scrolled {
  background: rgba(247, 241, 234, 0.92);
  box-shadow: 0 1px 0 var(--line), 0 12px 24px -18px rgba(36, 27, 23, 0.25);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 2rem;
}

.chapter-counter {
  font-family: var(--font-head);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
}

.chapter-counter .divider {
  opacity: 0.4;
  margin: 0 0.15rem;
}

.logo {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--font-head);
  font-weight: 700;
  text-decoration: none;
  color: var(--ink);
  letter-spacing: 0.08em;
  font-size: 0.9rem;
}

.logo:hover .logo-mark {
  filter: drop-shadow(0 0 8px rgba(184, 54, 47, 0.5));
}

.logo-mark {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: var(--ink);
  overflow: visible;
  transition: filter 0.3s ease;
}

.logo-mark-flame {
  fill: var(--accent);
  transform-box: view-box;
  transform-origin: 50px 31px;
  animation: logo-flame-flicker 3.2s ease-in-out infinite;
}

@keyframes logo-flame-flicker {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.06); opacity: 0.88; }
}

.logo-mark-ember {
  fill: var(--accent);
  transform-box: view-box;
  transform-origin: 60px 60px;
  animation: logo-orbit 7s linear infinite;
  filter: drop-shadow(0 0 3px rgba(184, 54, 47, 0.8));
}

@keyframes logo-orbit {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.contact-toggle {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  cursor: pointer;
  overflow: hidden;
  padding: 0;
  transition: border-color 0.25s ease, color 0.25s ease, width 0.35s ease, padding 0.35s ease, box-shadow 0.3s ease;
}

/* A tiny ember circling inside the ring, echoing the logo mark. Kept
   well inside the border since this button clips overflow for its
   label reveal. */
.contact-toggle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 3px;
  height: 3px;
  margin: -1.5px 0 0 -1.5px;
  border-radius: 50%;
  background: var(--accent);
  animation: btn-orbit-inner 6s linear infinite;
  pointer-events: none;
}

@keyframes btn-orbit-inner {
  from { transform: rotate(0deg) translateX(12px); }
  to { transform: rotate(360deg) translateX(12px); }
}

.contact-toggle svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

.contact-toggle-label {
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  white-space: nowrap;
  font-family: var(--font-head);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  transition: max-width 0.35s ease, opacity 0.2s ease, margin-left 0.35s ease;
}

.contact-toggle[aria-expanded="true"] {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 22px rgba(184, 54, 47, 0.28);
}

/* The label only expands on hover while CLOSED — not once the menu is
   open (even if the cursor is still resting on the button from the
   click that opened it) — otherwise the wider button physically
   overlaps the fanned-out menu items, which are calibrated against the
   button's collapsed width. Scoped to real hover-capable pointers only:
   touch devices simulate ":hover" on tap and don't reliably clear it
   afterwards, so on mobile this was leaving the button stuck wide open
   — growing leftward, since it's the flex item pinned to the row's
   right edge — straight into the centered logo. */
@media (hover: hover) and (pointer: fine) {
  .contact-toggle:hover:not([aria-expanded="true"]) {
    border-color: var(--accent);
    color: var(--accent);
    width: auto;
    padding: 0 1rem 0 0.8rem;
    box-shadow: 0 0 22px rgba(184, 54, 47, 0.28);
  }

  .contact-toggle:hover:not([aria-expanded="true"]) .contact-toggle-label {
    max-width: 100px;
    opacity: 1;
    margin-left: 0.55rem;
  }
}

/* A quarter-circle fan of links swinging out from the toggle button,
   rather than a plain vertical list. Each link starts at the button
   (scale 0) and springs out to its position on the arc. */
.contact-menu {
  position: absolute;
  top: 2.9rem;
  right: 2rem;
  width: 0;
  height: 0;
}

.contact-menu .dock-link {
  position: absolute;
  top: 0;
  right: 0;
  opacity: 0;
  transform: translate(0, 0) scale(0.3);
  pointer-events: none;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
}

.contact-menu.open .dock-link {
  opacity: 1;
  pointer-events: auto;
}

.contact-menu.open .dock-link:nth-child(1) { transform: translate(-14px, 82px) scale(1); transition-delay: 0.02s; }
.contact-menu.open .dock-link:nth-child(2) { transform: translate(-58px, 63px) scale(1); transition-delay: 0.07s; }
.contact-menu.open .dock-link:nth-child(3) { transform: translate(-82px, 21px) scale(1); transition-delay: 0.12s; }
.contact-menu.open .dock-link:nth-child(4) { transform: translate(-70px, -22px) scale(1); transition-delay: 0.17s; }

/* Hero */
.hero {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(1.5rem, 4vh, 3rem);
  text-align: center;
  padding: 8rem 1.5rem 4rem;
  position: relative;
  overflow: hidden;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

.hero-glow {
  position: absolute;
  top: 32%;
  left: 50%;
  width: 60vw;
  height: 60vw;
  max-width: 680px;
  max-height: 680px;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(184, 54, 47, 0.12) 0%, transparent 70%);
  filter: blur(50px);
  z-index: 0;
  pointer-events: none;
  animation: hero-glow-drift 13s ease-in-out infinite;
}

@keyframes hero-glow-drift {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  50% { transform: translate(-47%, -53%) scale(1.1); opacity: 0.8; }
}

.hero-watermark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-brush);
  font-size: min(60vw, 42rem);
  line-height: 1;
  color: var(--ink);
  opacity: 0.07;
  z-index: 0;
  pointer-events: none;
  user-select: none;
  animation: watermark-breathe 9s ease-in-out infinite;
}

@keyframes watermark-breathe {
  0%, 100% { opacity: 0.05; transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  50% { opacity: 0.1; transform: translate(-50%, -50%) scale(1.025) rotate(0.6deg); }
}

.hero-inner {
  max-width: 900px;
  position: relative;
  z-index: 1;
}

/* Time-of-day scene — a quiet illustrated vignette (house, tree, sky) in
   its own band under the logo row. It used to be absolutely positioned
   over the header-inner row, which put it directly behind the logo/name
   text; now it's a normal flow row of its own, so the header simply grows
   to fit both and the two can never overlap. */
.time-strip {
  display: block;
  margin: 0 auto 0.35rem;
  width: clamp(280px, 58vw, 360px);
  height: 40px;
  overflow: hidden;
  pointer-events: none;
  opacity: 0.7;
  color: var(--ink);
}

.time-scene,
.time-scene svg {
  width: 100%;
  height: 100%;
  display: block;
}

.scene-tree {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: tree-sway 6s ease-in-out infinite;
}

.scene-bird {
  animation: bird-bob 2.2s ease-in-out infinite;
}

@keyframes bird-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

.scene-cloud {
  transform-box: fill-box;
  animation: cloud-drift 16s linear infinite;
}

.scene-cloud--slow {
  animation-duration: 22s;
  animation-delay: -9s;
}

@keyframes cloud-drift {
  from { transform: translateX(-40px); }
  to { transform: translateX(340px); }
}

.scene-figure {
  transform-box: fill-box;
  transform-origin: 50% 100%;
}

.scene-figure--run {
  animation: figure-run-bounce 0.6s ease-in-out infinite;
}

.scene-figure--walk {
  animation: figure-walk-bounce 1.1s ease-in-out infinite;
}

@keyframes figure-run-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-1.6px); }
}

@keyframes figure-walk-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-0.8px); }
}

.scene-star {
  transform-box: fill-box;
  animation: star-twinkle 2.6s ease-in-out infinite;
}

@keyframes star-twinkle {
  0%, 100% { opacity: 0.15; }
  50% { opacity: 0.9; }
}

.scene-sun {
  transform-box: fill-box;
  animation: sun-spin 26s linear infinite, sun-glow 3s ease-in-out infinite;
}

@keyframes sun-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes sun-glow {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(217, 150, 61, 0)); }
  50% { filter: drop-shadow(0 0 3px rgba(217, 150, 61, 0.45)); }
}

.scene-moon {
  transform-box: fill-box;
  animation: moon-glow 4s ease-in-out infinite;
}

@keyframes moon-glow {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(139, 129, 173, 0)); }
  50% { filter: drop-shadow(0 0 3px rgba(139, 129, 173, 0.55)); }
}

.scene-window {
  animation: window-flicker 3s ease-in-out infinite;
}

@keyframes window-flicker {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

.scene-family {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: family-bob 2.4s ease-in-out infinite;
}

@keyframes family-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-1px); }
}

.scene-pet-tail {
  transform-box: fill-box;
  transform-origin: 0% 100%;
  animation: tail-wag 0.7s ease-in-out infinite;
}

@keyframes tail-wag {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(14deg); }
}

.scene-z {
  transform-box: fill-box;
  opacity: 0;
  animation: zzz-float 2.8s ease-in infinite;
}

.scene-z2 {
  animation-delay: 0.6s;
}

.scene-z3 {
  animation-delay: 1.2s;
}

@keyframes zzz-float {
  0% { opacity: 0; transform: translateY(0); }
  25% { opacity: 0.85; }
  100% { opacity: 0; transform: translateY(-7px); }
}

.scene-owl {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: owl-bob 3.4s ease-in-out infinite;
}

@keyframes owl-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-0.8px); }
}

.scene-hoot {
  transform-box: fill-box;
  opacity: 0;
  animation: zzz-float 3.4s ease-in infinite;
  animation-delay: 0.4s;
}

.scene-swing {
  transform-box: fill-box;
  transform-origin: 50% 0%;
  animation: swing-sway 3.2s ease-in-out infinite;
}

@keyframes swing-sway {
  0%, 100% { transform: rotate(-4deg); }
  50% { transform: rotate(4deg); }
}

.eyebrow {
  font-family: var(--font-head);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.28em;
  font-size: clamp(1rem, 2.2vw, 1.25rem);
  color: var(--accent);
  margin-bottom: 1.5rem;
  animation: hero-fade-up 1s ease both;
  animation-delay: 0.15s;
}

.hero h1 {
  font-size: clamp(2.25rem, 6vw, 4.25rem);
  line-height: 1.15;
  letter-spacing: -0.01em;
  animation: hero-fade-up 1s ease both;
  animation-delay: 0.32s;
}

.hero-sub {
  margin-top: 1.75rem;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(1.05rem, 1.8vw, 1.35rem);
  color: var(--ink-soft);
  max-width: 46ch;
  margin-left: auto;
  margin-right: auto;
  animation: hero-fade-up 1s ease both;
  animation-delay: 0.52s;
}

@keyframes hero-fade-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.enso {
  width: 90px;
  height: 90px;
  display: block;
  color: var(--accent);
  opacity: 0.55;
}

.enso path {
  stroke: currentColor;
  stroke-width: 5;
  stroke-linecap: round;
}

.scroll-cue {
  /* In normal flow (not absolutely positioned) so it can never overlap
     hero-inner above it, no matter how tall that content gets at high
     browser-zoom levels — the two simply stack with a guaranteed gap. */
  position: relative;
  flex-shrink: 0;
  width: 90px;
  height: 90px;
  text-decoration: none;
  color: var(--ink-soft);
  z-index: 1;
  animation: scroll-cue-fade-up 1s ease both, scroll-cue-bob 3.4s ease-in-out infinite;
  animation-delay: 0.95s, 1.4s;
}

@keyframes scroll-cue-fade-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes scroll-cue-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(6px); }
}

.scroll-cue .enso {
  position: absolute;
  inset: 0;
  margin: 0;
  transition: filter 0.3s ease, opacity 0.3s ease;
}

.scroll-cue:hover .enso {
  opacity: 0.85;
  filter: drop-shadow(0 0 14px rgba(184, 54, 47, 0.4));
}

.scroll-cue-ember {
  fill: var(--accent);
  transform-box: view-box;
  transform-origin: 100px 100px;
  animation: logo-orbit 9s linear infinite;
  filter: drop-shadow(0 0 3px rgba(184, 54, 47, 0.7));
}

.scroll-cue-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  font-family: var(--font-head);
  white-space: nowrap;
}

/* Chapters */
.chapter {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 6rem 1.5rem;
  overflow: hidden;
  background: var(--chapter-bg, var(--paper));
  color: var(--chapter-fg, var(--ink));
  isolation: isolate;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

.chapter::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: radial-gradient(ellipse 60% 45% at 50% 45%, var(--chapter-glow, transparent) 0%, transparent 70%);
  pointer-events: none;
}

.chapter-content {
  max-width: 720px;
  position: relative;
  z-index: 2;
  opacity: 0;
  transform: translateY(28px);
  transition: opacity 0.9s ease, transform 0.9s ease;
}

.chapter-content.in-view {
  opacity: 1;
  transform: translateY(0);
}

.chapter-label {
  font-family: var(--font-head);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.78rem;
  color: var(--chapter-accent, var(--accent));
  margin-bottom: 1.5rem;
}

.chapter h2 {
  font-size: clamp(1.75rem, 4vw, 2.75rem);
  line-height: 1.25;
  margin-bottom: 1.5rem;
}

.chapter p:not(.chapter-label) {
  font-size: clamp(1rem, 1.4vw, 1.15rem);
  color: var(--chapter-muted, var(--ink-soft));
  max-width: 60ch;
}

/* A stronger invitation to keep scrolling, for the very first chapter */
.chapter-invite {
  margin-top: 2rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--chapter-accent, var(--accent));
  opacity: 0.9;
}

.chapter-invite-arrow {
  display: inline-block;
  animation: chapter-invite-bounce 1.6s ease-in-out infinite;
}

@keyframes chapter-invite-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(6px); }
}

/* Chapter art (tree line drawings) */
.chapter-art {
  position: absolute;
  right: 6%;
  bottom: 0;
  width: clamp(140px, 22vw, 260px);
  z-index: 1;
  color: var(--chapter-accent, var(--accent));
  opacity: 0.55;
  pointer-events: none;
  filter: drop-shadow(0 0 18px var(--chapter-glow, transparent));
}

.chapter-art--full {
  width: clamp(180px, 26vw, 320px);
}

.chapter-art svg {
  width: 100%;
  height: auto;
  display: block;
  transform-origin: 50% 100%;
  animation: tree-sway 6s ease-in-out infinite;
}

@keyframes tree-sway {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(1.4deg); }
}

/* Drifting motes — a quiet sense of growth/beginning behind the text */
.floating-motes {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}

.floating-motes span {
  position: absolute;
  bottom: -20px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--chapter-accent, currentColor);
  opacity: 0;
  animation: mote-drift linear infinite;
}

.floating-motes span:nth-child(1) { left: 8%; animation-delay: 0s; animation-duration: 16s; }
.floating-motes span:nth-child(2) { left: 22%; animation-delay: 3s; animation-duration: 13s; }
.floating-motes span:nth-child(3) { left: 40%; animation-delay: 6s; animation-duration: 18s; }
.floating-motes span:nth-child(4) { left: 58%; animation-delay: 1.5s; animation-duration: 15s; }
.floating-motes span:nth-child(5) { left: 75%; animation-delay: 4.5s; animation-duration: 17s; }
.floating-motes span:nth-child(6) { left: 90%; animation-delay: 8s; animation-duration: 14s; }

@keyframes mote-drift {
  0% { transform: translate(0, 0); opacity: 0; }
  10% { opacity: 0.55; }
  90% { opacity: 0.3; }
  100% { transform: translate(20px, -100vh); opacity: 0; }
}

.chapter-art path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.draw-path {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke-dashoffset 1.3s cubic-bezier(0.65, 0, 0.35, 1);
}

/* Tree branches draw one stroke at a time, like 道 being brush-written —
   not all at once. */
.chapter-art .draw-path:nth-child(1) { transition-delay: 0s; }
.chapter-art .draw-path:nth-child(2) { transition-delay: 0.55s; }
.chapter-art .draw-path:nth-child(3) { transition-delay: 1.1s; }
.chapter-art .draw-path:nth-child(4) { transition-delay: 1.65s; }
.chapter-art .draw-path:nth-child(5) { transition-delay: 2.2s; }
.chapter-art .draw-path:nth-child(6) { transition-delay: 2.75s; }

.chapter-art .chapter-art-ring {
  stroke-width: 1.4;
  opacity: 0.55;
}

/* Soft wave divider at the seam between sections */
.section-divider {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 44px;
  z-index: 1;
  pointer-events: none;
  color: var(--chapter-accent, var(--accent));
  opacity: 0.4;
}

.section-divider svg {
  width: 100%;
  height: 100%;
  display: block;
}

.section-divider path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
}

.chapter-art--stars .tip-star {
  fill: currentColor;
  opacity: 0;
  transition: opacity 0.6s ease 1.4s;
}

.in-view ~ .chapter-art--stars .tip-star,
.chapter-art--stars.drawn .tip-star {
  opacity: 0.9;
}

/* Chapter palettes: pink -> red -> purple, ink interludes with red/purple/orange glow */
.chapter--beginning {
  /* scattered seed-like dots — curiosity, the earliest, unformed chapter */
  --chapter-bg:
    radial-gradient(circle, rgba(198, 90, 99, 0.16) 1.6px, transparent 1.6px) 0 0/54px 54px,
    radial-gradient(circle, rgba(198, 90, 99, 0.11) 1.2px, transparent 1.2px) 27px 27px/54px 54px,
    linear-gradient(160deg, #fdf3ef 0%, #fbe9e4 55%, #f8ded8 100%);
  --chapter-glow: rgba(230, 120, 130, 0.3);
  --chapter-accent: #c65a63;
  --chapter-muted: #8a6e6a;
}

.chapter--build {
  /* faint blueprint grid — learning to engineer, structure, logic */
  --chapter-bg:
    repeating-linear-gradient(0deg, rgba(184, 54, 47, 0.07) 0px, rgba(184, 54, 47, 0.07) 1px, transparent 1px, transparent 34px),
    repeating-linear-gradient(90deg, rgba(184, 54, 47, 0.07) 0px, rgba(184, 54, 47, 0.07) 1px, transparent 1px, transparent 34px),
    linear-gradient(160deg, #fbeeec 0%, #f7e0dc 55%, #f2d3cd 100%);
  --chapter-glow: rgba(184, 54, 47, 0.2);
  --chapter-accent: #b8362f;
  --chapter-muted: #85675f;
}

.chapter--lead {
  /* even node grid — the org chart, systems of people and process */
  --chapter-bg:
    radial-gradient(circle, rgba(107, 63, 132, 0.17) 1.6px, transparent 1.6px) 0 0/30px 30px,
    linear-gradient(160deg, #f3ecf5 0%, #ecdff0 55%, #e4d1ea 100%);
  --chapter-glow: rgba(107, 63, 132, 0.2);
  --chapter-accent: #6b3f84;
  --chapter-muted: #776a78;
}

.chapter--tao {
  --chapter-bg: linear-gradient(160deg, #17100f 0%, #241318 55%, #1a1024 100%);
  --chapter-fg: #f4ece6;
  --chapter-accent: #e08a4f;
  --chapter-muted: #cbb9c4;
  --chapter-glow: rgba(224, 138, 79, 0.18);
}

.chapter--ai {
  --chapter-bg: linear-gradient(160deg, #140f1e 0%, #1f1430 55%, #170f2a 100%);
  --chapter-fg: #f1ecf7;
  --chapter-accent: #a97fd6;
  --chapter-muted: #beb0cf;
  --chapter-glow: rgba(107, 63, 132, 0.28);
}

.chapter--future {
  --chapter-bg: linear-gradient(160deg, #0e0a10 0%, #1c1016 55%, #21120f 100%);
  --chapter-fg: #f6ece4;
  --chapter-accent: #e07a3d;
  --chapter-muted: #d3b9ac;
  --chapter-glow: rgba(224, 122, 61, 0.28);
}

/* 道 interlude */
.chapter-content--tao {
  text-align: center;
}

.tao-glyph-writer {
  margin: 0.5rem auto 1.5rem;
  filter: drop-shadow(0 0 48px rgba(224, 138, 79, 0.65)) drop-shadow(0 0 20px rgba(240, 176, 136, 0.5));
}

.tao-glyph-writer svg {
  display: block;
}

.tao-glyph-writer.lit {
  animation: tao-glow-pulse 4.5s ease-in-out infinite;
}

@keyframes tao-glow-pulse {
  0%, 100% { filter: drop-shadow(0 0 44px rgba(224, 138, 79, 0.6)) drop-shadow(0 0 18px rgba(240, 176, 136, 0.45)); }
  50% { filter: drop-shadow(0 0 80px rgba(224, 138, 79, 0.95)) drop-shadow(0 0 32px rgba(240, 176, 136, 0.7)); }
}

.chapter .chapter-content--tao p.tao-line {
  font-size: clamp(1.05rem, 1.8vw, 1.3rem);
  color: var(--chapter-muted);
  max-width: 46ch;
  margin: 0 auto;
}

.chapter .chapter-content--tao p.tao-line--em {
  color: var(--chapter-fg);
  margin-top: 0.35rem;
}

.particle-canvas,
.galaxy-canvas,
.circuit-canvas {
  position: absolute;
  inset: 0;
  /* Canvas is a replaced element — inset:0 alone does not stretch it to
     fill its container the way it would a normal block element; without
     an explicit size it falls back to its own intrinsic pixel-buffer
     dimensions, which is exactly what resize() writes to. That mismatch
     was the real source of the runaway/incorrect sizing bug. */
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* Darkens the side of a canvas chapter that carries the text, so the
   background graphic can be bright/busy without hurting legibility */
.chapter-scrim {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.55) 0%, rgba(0, 0, 0, 0.28) 42%, transparent 68%);
  pointer-events: none;
}

/* Contact dropdown — links shown from the header toggle */
.dock-link {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(247, 241, 234, 0.95);
  border: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
  font-family: var(--font-head);
  font-size: 0.8rem;
  font-weight: 600;
  backdrop-filter: blur(6px);
  box-shadow: 0 12px 24px -16px rgba(36, 27, 23, 0.35);
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}

/* A little ember circling each dock icon, same idea as the logo mark */
.dock-link::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 3px;
  height: 3px;
  margin: -1.5px 0 0 -1.5px;
  border-radius: 50%;
  background: var(--accent);
  animation: btn-orbit-outer 7s linear infinite;
  pointer-events: none;
}

.dock-link:nth-child(2)::after { animation-duration: 8.5s; }
.dock-link:nth-child(3)::after { animation-duration: 6.2s; }
.dock-link:nth-child(4)::after { animation-duration: 9s; }

@keyframes btn-orbit-outer {
  from { transform: rotate(0deg) translateX(19px); }
  to { transform: rotate(360deg) translateX(19px); }
}

.dock-link svg {
  width: 18px;
  height: 18px;
}

.dock-link:hover {
  transform: translateX(-3px) scale(1.06);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 20px rgba(184, 54, 47, 0.38);
}

/* Footer */
.site-footer {
  padding: 2rem 1.5rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-soft);
  background: var(--paper);
  position: relative;
  z-index: 2;
}

/* Fixed indicators */
.next-cue {
  position: fixed;
  bottom: 2rem;
  left: 2rem;
  z-index: 40;
  text-decoration: none;
  color: var(--ink);
  font-family: var(--font-head);
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: rgba(247, 241, 234, 0.85);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  backdrop-filter: blur(6px);
  transition: gap 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
}

.next-cue:hover {
  gap: 0.9rem;
  transform: translateY(-2px);
  box-shadow: 0 10px 22px -14px rgba(36, 27, 23, 0.35), 0 0 20px rgba(184, 54, 47, 0.25);
}

.next-cue .arrow {
  color: var(--accent);
  display: inline-block;
  animation: next-arrow-nudge 1.8s ease-in-out infinite;
}

@keyframes next-arrow-nudge {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(3px); }
}

/* Cursor trail glow */
.cursor-glow {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 30;
}

@media (hover: none) {
  .cursor-glow {
    display: none;
  }
}

/* Ink-bloom tap effect — the touch-device counterpart to the cursor
   glow above (which needs a real pointer to trail). A soft red bloom,
   like a drop of ink hitting paper, at wherever the screen was tapped. */
.ink-tap {
  position: fixed;
  top: 0;
  left: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(184, 54, 47, 0.5) 0%, rgba(184, 54, 47, 0.2) 45%, transparent 75%);
  pointer-events: none;
  z-index: 200;
  transform: translate(-50%, -50%) scale(1);
  animation: ink-tap-bloom 0.9s cubic-bezier(0.25, 0.8, 0.4, 1) forwards;
}

@keyframes ink-tap-bloom {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 0.9; }
  100% { transform: translate(-50%, -50%) scale(9); opacity: 0; }
}

@media (max-width: 640px) {
  .header-inner {
    padding: 1rem 1.25rem;
  }
  .site-header nav a {
    margin-left: 1.25rem;
  }
  .next-cue span:first-child {
    display: none;
  }
  .chapter-indicator,
  .next-cue {
    padding: 0.55rem 0.7rem;
  }
  .chapter-art {
    opacity: 0.25;
    width: clamp(110px, 40vw, 180px);
  }
  /* Nudge the two icon buttons up to the recommended 44px touch target
     on mobile, where fingers (not cursor precision) are doing the tapping. */
  .contact-toggle,
  .dock-link {
    width: 44px;
    height: 44px;
  }
}

/* Respect the OS-level "reduce motion" preference. This site leans heavily
   on decorative animation (orbiting embers, drifting motes, brush-stroke
   draw-ins, the whole time-of-day vignette); none of it carries meaning,
   so for anyone who's asked their system to cut it out, every animation
   and transition collapses to a single instant frame instead of playing.
   Scroll-snap itself is untouched — only the smooth-scroll easing goes. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
