/* ---------- Tokens ---------- */
:root {
  --bg: #f6f2ea;
  --bg-glow: #fffaf0;
  --ink: #2a2620;
  --muted: #6f675b;
  --rule: #e2dacb;
  --accent: #ff665f;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
  --bubble: 180px;
  --center: 350px;
  --creature: #00a621; /*#00a621; *//* #b5562b; */
}

.center { text-align: center; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17150f;
    --bg-glow: #24201a;
    --ink: #ece6da;
    --muted: #a39a8b;
    --rule: #39332a;
    --accent: #e48a5c;
    --creature: #e48a5c;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% 30%, var(--bg-glow), var(--bg) 70%) fixed;
  background-color: var(--bg);
  color: var(--ink);
  font: 400 17px/1.65 var(--sans);
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; }

a { color: var(--accent); }

/* ---------- Home ---------- */
.home {
  padding: 48px 16px 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.home-header { text-align: center; margin-bottom: 8px; }
.home-header h1 { font-size: 2.6rem; margin: 0; letter-spacing: -0.01em; }
.home-header p { margin: 4px 0 0; color: var(--muted); }

/* ---------- Orbit ---------- */
.bubble-orbit {
  position: relative;
  width: min(92vw, 720px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

.center-person {
  width: var(--center);
  height: var(--center);
  border-radius: 50%;
  overflow: hidden;
  z-index: 1;
  box-shadow: 0 0 0 6px var(--bg-glow), 0 18px 40px rgba(0, 0, 0, 0.18);
}

.center-person img { width: 100%; height: 100%; object-fit: cover; display: block; }

.center-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font: 600 5rem/1 var(--serif);
  color: #fff;
  background: radial-gradient(circle at 32% 28%, #d9b58c, #8a5a3b 75%);
}

/* The link: holds the orbit position only. */
.bubble {
  --orbit-x: 0px;
  --orbit-y: 0px;
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--bubble);
  height: var(--bubble);
  transform: translate(-50%, -50%) translate(var(--orbit-x), var(--orbit-y));
  border-radius: 50%;
  text-decoration: none;
  z-index: 3; /* above the creature (2) */
}

.bubble:hover, .bubble:focus-visible { z-index: 4; }
.bubble:focus-visible { outline: none; }

/* The inner span: bobs, zooms on hover, and looks like a bubble. */
.bubble-inner {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 14px;
  text-align: center;
  background:
    radial-gradient(circle at 30% 25%, hsl(var(--hue) 75% 80% / 0.95), transparent 55%),
    radial-gradient(circle at 50% 60%, hsl(var(--hue) 55% 52%), hsl(var(--hue) 50% 36%));
  border: 2px solid rgba(255, 255, 255, 0.55);
  box-shadow:
    inset 0 0 18px rgba(255, 255, 255, 0.55),
    0 10px 24px rgba(0, 0, 0, 0.18);
  animation: bob var(--bob-duration, 5s) ease-in-out var(--bob-delay, 0s) infinite;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

/* Glossy highlight on top of photo or gradient. */
.bubble-inner::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 22%, rgba(255, 255, 255, 0.55), transparent 32%);
  pointer-events: none;
}

.bubble-inner img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.bubble-inner.has-image::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.55), transparent 60%);
  z-index: 1;
}

.bubble-label {
  position: relative;
  z-index: 1;
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}

.has-image .bubble-label { align-self: end; margin-bottom: 10px; }

.bubble:hover .bubble-inner,
.bubble:focus-visible .bubble-inner {
  animation-play-state: paused;
  transform: scale(1.1);
  box-shadow:
    inset 0 0 22px rgba(255, 255, 255, 0.8),
    0 0 0 4px var(--accent),
    0 16px 32px rgba(0, 0, 0, 0.25);
}

@keyframes bob {
  0%, 100% { translate: 0 0; }
  50%      { translate: 0 -8px; }
}

@media (prefers-reduced-motion: reduce) {
  .bubble-inner { animation: none; }
}

/* Phones: no orbit, just the photo and a grid of bubbles. */
@media (max-width: 600px) {
  :root { --bubble: 128px; --center: 150px; }

  .bubble-orbit {
    width: 100%;
    max-width: 320px;
    aspect-ratio: auto;
    grid-template-columns: repeat(2, var(--bubble));
    justify-content: center;
    gap: 22px 28px;
    margin-top: 24px;
  }

  .center-person { grid-column: 1 / -1; margin-bottom: 8px; }

  .bubble {
    position: static;
    transform: none;
  }

  /* An odd bubble out on the last row sits in the middle. (The photo is
     the first child, so an odd number of bubbles ends on an even child.) */
  .bubble:last-child:nth-child(even) {
    grid-column: 1 / -1;
    justify-self: center;
  }
}

/* ---------- Topic pages ---------- */
.topic-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 16px 80px;
}

.back-home {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
}

.back-home:hover { color: var(--accent); }

.topic-hero {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: 28px 0 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--rule);
}

.topic-hero .bubble-inner {
  flex: none;
  width: 84px;
  height: 84px;
  padding: 0;
  animation: none;
}

.topic-hero h1 { margin: 0; font-size: clamp(1.8rem, 5vw, 2.4rem); }
.topic-hero p { margin: 4px 0 0; color: var(--muted); }

.prose h2 { font-size: 1.4rem; margin: 2em 0 0.4em; }
.prose img { max-width: 100%; border-radius: 10px; }

/* A single image, centered. Add a width to make it smaller than the column. */
.prose img.centered { display: block; margin: 1.5em auto; }

/* A single image with a caption underneath, centered.
   Set a width on the <figure> to make it smaller than the column. */
.prose > figure {
  margin: 1.5em auto;
  max-width: 100%;
  text-align: center;
}

.prose > figure img { display: block; width: 100%; margin: 0 auto; }

.prose > figure figcaption {
  margin-top: 8px;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--muted);
}

/* "Important takeaways" callout box. */
.takeaways {
  margin: 2em 0;
  padding: 16px 20px 6px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.takeaways h3 {
  margin: 0 0 6px;
  font: 600 0.8rem/1.2 var(--sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.takeaways ul { margin: 0 0 10px; padding-left: 1.2em; }
.takeaways li { margin-bottom: 4px; }

/* Side-by-side images. Two or more per row on wide screens, stacked on phones. */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin: 1.5em 0;
}

.gallery figure { margin: 0; }

.gallery img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;   /* keeps the row even; remove to show each photo uncropped */
  object-fit: cover;
}

.gallery figcaption {
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.placeholder {
  border: 1px dashed var(--rule);
  border-radius: 10px;
  padding: 14px 18px;
  color: var(--muted);
  font-size: 0.95rem;
}

.disclaimer {
  margin-top: 3em;
  padding: 14px 18px;
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  font-size: 0.9rem;
  color: var(--muted);
}

/* ---------- Books (a topic split into chapters) ---------- */

.book-title {
  text-align: center;
  margin: 1em 0 2.5em;
}

.book-title h2 { font-size: 2rem; margin: 0; }
.book-title__author { margin: 6px 0 0; color: var(--muted); letter-spacing: 0.04em; }
.book-title__dedication { margin: 1.6em 0 0; font-style: italic; color: var(--muted); font-size: 0.95rem; }

.contents {
  padding: 0;
  list-style: none;
  counter-reset: chapter;
  border-top: 1px solid var(--rule);
}

.contents li {
  counter-increment: chapter;
  border-bottom: 1px solid var(--rule);
}

.contents a {
  display: flex;
  gap: 14px;
  align-items: baseline;
  padding: 12px 4px;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--serif);
  font-size: 1.1rem;
}

.contents a::before {
  content: counter(chapter);
  min-width: 1.6em;
  color: var(--accent);
  font: 600 0.85rem/1 var(--sans);
}

.contents a:hover { color: var(--accent); }

.book-copyright { margin-top: 3em; font-size: 0.85rem; color: var(--muted); text-align: center; }

.chapter-hero {
  margin: 28px 0 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--rule);
}

.chapter-kicker {
  margin: 0 0 6px;
  font: 600 0.8rem/1.2 var(--sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.chapter-hero h1 { margin: 0; font-size: clamp(1.8rem, 5vw, 2.4rem); }

/* The quote that opens each chapter. */
.epigraph {
  margin: 0 0 2em;
  padding: 0 0 0 18px;
  border-left: 3px solid var(--accent);
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.1rem;
  color: var(--muted);
}

.epigraph p { margin: 0; }
.epigraph cite { display: block; margin-top: 6px; font: normal 0.9rem var(--sans); }
.epigraph cite::before { content: "— "; }

/* An indented passage: a poem, a prayer, a dialogue. */
.indented {
  margin: 1.5em 0;
  padding-left: 24px;
}

.indented h3,
.practice h3 { font-size: 1.1rem; margin: 1.2em 0 0.3em; }

/* A guided meditation to try. */
.practice {
  margin: 2em 0;
  padding: 6px 22px 10px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}

.practice h3:first-child { margin-top: 0.8em; }

.references { padding-left: 1.2em; font-size: 0.92rem; }
.references li { margin-bottom: 8px; }

.chapter-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin-top: 3.5em;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
}

.chapter-nav a { color: var(--ink); text-decoration: none; font-family: var(--serif); }
.chapter-nav a:hover { color: var(--accent); }
.chapter-nav span { display: block; font: 600 0.75rem/1.4 var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.chapter-nav__prev { grid-column: 1; }
.chapter-nav__contents { grid-column: 2; font: 600 0.9rem var(--sans) !important; color: var(--accent) !important; }
.chapter-nav__next { grid-column: 3; text-align: right; }

@media (max-width: 600px) {
  .chapter-nav { grid-template-columns: 1fr 1fr; }
  .chapter-nav__contents { grid-column: 1 / -1; grid-row: 2; text-align: center; }
  .chapter-nav__next { grid-column: 2; }
}

/* ---------- Text creature ---------- */

.text-creature {
  position: fixed;
  inset: 0;
  z-index: 2; /* above the portrait (1), under the bubbles (3) */
  pointer-events: none;
  overflow: hidden;
}

.text-creature__svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  --heat: 0;         /* 0 to 1, set by the controller as it overloads */
  --hot: #e0241b;
  --hunt: 0;         /* 0 to 1, set by the controller in predator mode */
  --prowl: var(--ink);
  --bird: #1d9bf0;
}

.text-creature__glyph {
  fill: color-mix(in srgb, var(--hot) calc(var(--heat) * 100%),
          color-mix(in srgb, var(--prowl) calc(var(--hunt) * 75%), var(--creature)));
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  opacity: 0.9;
}

/* The head is the sentence's final period, drawn big and dark. */
.text-creature__glyph.is-head {
  fill: color-mix(in srgb, var(--hot) calc(var(--heat) * 100%), var(--ink));
  font-size: 30px;
  font-weight: 700;
  opacity: 1;
}

/* The prey. */
.text-creature__bird .bird-body { fill: var(--bird); }
.text-creature__bird .bird-wing { fill: color-mix(in srgb, var(--bird) 55%, #fff); }
.text-creature__bird .bird-eye { fill: #0f1419; }
.text-creature__bird .bird-dead,
.text-creature__bird .bird-legs {
  fill: none;
  stroke: #0f1419;
  stroke-width: 1.3;
  stroke-linecap: round;
}
.text-creature__bird .bird-legs { stroke: color-mix(in srgb, var(--bird) 60%, #000); }

.text-creature__exclaim {
  fill: var(--ink);
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 800;
}

.text-creature__heart { font-size: 22px; }

.text-creature__feather { fill: color-mix(in srgb, var(--bird) 70%, #fff); }

.text-creature__fallback {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.8rem;
}

.text-creature.is-active .text-creature__fallback {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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