/* =========================================================================
   RITESH S NIGAM — A LIFE IN CHAPTERS
   A no-scroll, single-viewport digital flip-book.
   Chromatic identity: the sampled blue of the supplied portrait,
   balanced by bone paper, near-black ink, and one warm accent.
   ========================================================================= */

/* ---------- 0. Tokens ---------------------------------------------------- */
:root {
  --paper: #f5f0e6;
  --parchment: #e7ddcb;
  --ink: #1b1b19;
  --ink-soft: #33322e;
  --blue-500: #2786be;   /* sampled from the supplied portrait */
  --blue-700: #154b6e;   /* darkened, AA-safe for body-size text */
  --blue-900: #0d2f45;
  --warm: #c56b35;       /* the one restrained warm accent */

  --rule: rgba(27, 27, 25, 0.18);
  --rule-on-ink: rgba(245, 240, 230, 0.22);

  /* Two voices only: one literary face, one quiet utility face. */
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --font-mono: "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --ease: cubic-bezier(0.45, 0.05, 0.35, 1);
  --dur: 620ms;

  /* fluid type, bound mainly by viewport height so nothing ever forces scroll */
  --fs-display: clamp(1.9rem, 6.6vh, 3.4rem);
  --fs-h2: clamp(1.15rem, 4.2vh, 1.9rem);
  --fs-lede: clamp(0.85rem, 2.15vh, 1rem);
  --fs-body: clamp(0.78rem, 1.9vh, 0.95rem);
  --fs-meta: clamp(0.62rem, 1.35vh, 0.74rem);
  --fs-micro: clamp(0.56rem, 1.15vh, 0.66rem);

  /* chrome reserved outside the book, used by the book's own max-size formula */
  --chrome: 148px;
  --ar: 1.5; /* book width / height, desktop open volume */
}

@media (max-width: 760px) {
  :root {
    --ar: 0.72; /* pocket edition: a single, taller page */
  }
}

/* ---------- 1. Reset & base ---------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden; /* belt-and-suspenders: never scroll, no matter the maths below */
  background: var(--ink);
}

body {
  font-family: var(--font-serif);
  font-weight: 400;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  font-kerning: normal;
  font-feature-settings: "kern" 1, "liga" 1;
}

h1, h2, h3 { font-family: inherit; margin: 0; font-weight: 600; }
strong, b { font-weight: 600; }
p, ul, ol, dl, blockquote, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
kbd { font-family: var(--font-mono); border: 1px solid var(--rule); border-radius: 3px; padding: 0 0.35em; font-size: 0.9em; }

:focus-visible {
  outline: 2px solid var(--blue-500);
  outline-offset: 2px;
  border-radius: 2px;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--paper);
  color: var(--ink);
  padding: 0.5em 1em;
  z-index: 999;
}
.skip-link:focus { left: 0.5em; top: 0.5em; }

/* ---------- 2. App shell (fixed viewport, three flex rows) ---------------- */
.app {
  position: fixed;
  inset: 0;
  height: 100dvh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--ink);
  background-image: radial-gradient(circle, rgba(245, 240, 230, 0.05) 1px, transparent 1.4px);
  background-size: 7px 7px;
}

.titlebar {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: clamp(6px, 1.4dvh, 12px) clamp(10px, 2vw, 22px);
  min-height: clamp(34px, 5.5dvh, 48px);
  color: var(--paper);
}

.wordmark {
  display: flex;
  align-items: baseline;
  gap: 0.6em;
  white-space: nowrap;
}
.wordmark-title {
  font-family: var(--font-serif);
  font-size: clamp(0.72rem, 1.9dvh, 0.95rem);
  letter-spacing: 0.02em;
}
.social-links {
  display: flex;
  align-items: center;
  gap: clamp(3px, 0.55vw, 7px);
}
.social-link {
  width: clamp(23px, 2.4dvh, 27px);
  height: clamp(23px, 2.4dvh, 27px);
  display: grid;
  place-items: center;
  color: rgba(245, 240, 230, 0.68);
  border: 1px solid rgba(245, 240, 230, 0.14);
  border-radius: 7px;
  transition: color 160ms var(--ease), border-color 160ms var(--ease), transform 160ms var(--ease), background 160ms var(--ease);
}
.social-link svg {
  width: 55%;
  height: 55%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.social-link:hover,
.social-link:focus-visible {
  color: var(--paper);
  border-color: var(--blue-500);
  background: rgba(39, 134, 190, 0.16);
  transform: translateY(-2px);
}
@media (max-width: 420px) {
  .social-links { gap: 2px; }
  .social-link { width: 22px; height: 22px; border-radius: 6px; }
}

.statusbar {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(4px, 1dvh, 10px) clamp(10px, 2vw, 22px);
  min-height: clamp(30px, 4.5dvh, 40px);
  color: var(--paper);
}
.status-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}
.counter {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.03em;
  text-align: center;
}
.developer-credit {
  position: absolute;
  right: clamp(10px, 2vw, 22px);
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.01em;
  color: rgba(245, 240, 230, 0.58);
  white-space: nowrap;
  transition: color 160ms var(--ease);
}
.developer-credit strong { color: var(--paper); font-weight: 500; }
.developer-credit:hover,
.developer-credit:focus-visible { color: var(--blue-500); }
@media (max-width: 760px) {
  .statusbar { justify-content: flex-start; }
  .status-primary { gap: 0.55rem; }
  .developer-credit { right: 8px; font-size: clamp(0.46rem, 1.05dvh, 0.58rem); }
}
.help-btn {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--rule-on-ink);
  padding: 0.35em 0.1em;
  transition: transform 120ms var(--ease), border-color 120ms var(--ease);
}
.help-btn:hover { border-color: var(--blue-500); }
.help-btn:active { transform: scale(0.95); }

/* ---------- 3. Stage & the book (guaranteed to fit, by construction) ----- */
.stage {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(4px, 1dvh, 14px) clamp(6px, 2vw, 20px);
}

.book {
  position: relative;
  perspective: 2600px;
  background: var(--paper);
  border-radius: 3px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25), 0 30px 60px -20px rgba(0, 0, 0, 0.55);
  /* Keep this arithmetic broadly supported: CSS multiplication inside calc()
     collapses the book to zero width in Chromium versions without Values 4. */
  width: max(160px, min(94vw, calc(150dvh - 222px)));
  aspect-ratio: var(--ar);
  height: auto;
  overflow: hidden;
}

@media (max-width: 760px) {
  .book {
    width: max(160px, min(94vw, calc(72dvh - 107px)));
  }
}

.pages { position: absolute; inset: 0; }

.spread {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: clamp(10px, 3dvh, 30px) clamp(14px, 3.4vw, 40px);
  background: var(--paper);
}
.spread.is-current { display: flex; }
.leaf-front > .spread, .leaf-back > .spread { display: flex; }

.spread-inner--dark { background: var(--ink); color: var(--paper); }
.spread-cover { background: var(--paper); }

/* recurring editorial marks */
.folio {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--blue-700);
  margin-bottom: clamp(4px, 1dvh, 10px);
}
.spread-inner--dark .folio, .spread-cover .folio { color: var(--blue-500); }
.folio-rotated {
  /* Page identity already lives in the bottom folio. Keeping this hidden also
     prevents its trailing letters appearing beneath the folded Contents tab. */
  display: none;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: var(--fs-meta);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--blue-700);
  margin-bottom: 0.5em;
}
.spread-inner--dark .eyebrow { color: var(--blue-500); }

.spread-title {
  font-size: var(--fs-h2);
  line-height: 1.14;
  margin-bottom: 0.55em;
}

.lede {
  font-size: var(--fs-body);
  line-height: 1.45;
  max-width: 34ch;
  color: var(--ink-soft);
}
.spread-inner--dark .lede { color: rgba(245, 240, 230, 0.86); }

.spread-inner {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(0.3rem, 1.2dvh, 0.8rem);
}

.spread-inner--split {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: clamp(14px, 3vw, 40px);
  align-items: center;
}
@media (max-width: 760px) {
  .spread-inner--split { grid-template-columns: 1fr; align-content: center; gap: clamp(8px, 1.6dvh, 16px); }
}

.pane { min-height: 0; }
.pane-right { border-left: 1px solid var(--rule); padding-left: clamp(10px, 2.4vw, 28px); }
.spread-inner--dark .pane-right { border-left-color: var(--rule-on-ink); }
@media (max-width: 760px) {
  .pane-right { border-left: 0; padding-left: 0; border-top: 1px solid var(--rule); padding-top: clamp(8px, 1.6dvh, 14px); }
  .spread-inner--dark .pane-right { border-top-color: var(--rule-on-ink); }
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-family: var(--font-mono);
  font-size: var(--fs-meta);
  font-weight: 500;
  letter-spacing: 0.01em;
  padding: 0.6em 1.1em;
  border-radius: 3px;
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease);
}
.btn:active { transform: scale(0.96); }
.btn-open { background: var(--ink); color: var(--paper); margin-top: clamp(6px, 1.4dvh, 14px); }
.btn-open:hover { box-shadow: 0 4px 14px rgba(27, 27, 25, 0.3); }
.btn-outline { border: 1px solid var(--blue-700); color: var(--blue-700); margin-top: clamp(6px, 1.2dvh, 12px); }
.spread-inner--dark .btn-outline { border-color: var(--blue-500); color: var(--blue-500); }
.btn-outline:hover { background: rgba(39, 134, 190, 0.08); }
.btn-warm { background: var(--warm); color: var(--paper); margin-top: clamp(6px, 1.2dvh, 12px); }
.btn-warm:hover { box-shadow: 0 4px 14px rgba(197, 107, 53, 0.4); }

/* ---------- 4. Cover ------------------------------------------------------ */
.cover-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  align-items: center;
  gap: 0;
}
@media (max-width: 760px) {
  .cover-grid { grid-template-columns: 1fr; grid-template-rows: auto 1fr; align-content: center; }
}

.cover-text { min-height: 0; position: relative; z-index: 2; }
.cover-title {
  font-size: var(--fs-display);
  line-height: 1.02;
  letter-spacing: -0.01em;
}
.cover-title .reveal { display: block; }
.cover-title .reveal:last-child {
  display: inline-block;
  position: relative;
  z-index: 3;
  color: var(--paper);
  background: var(--blue-700);
  padding: 0 0.14em;
  transform: translateX(18%);
}
@media (max-width: 760px) {
  .cover-title .reveal:last-child { transform: none; }
}

.cover-tagline {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: clamp(0.85rem, 2.4dvh, 1.15rem);
  line-height: 1.28;
  margin-top: clamp(6px, 1.4dvh, 14px);
  color: var(--ink-soft);
}
.cover-sub {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.03em;
  margin-top: clamp(8px, 1.6dvh, 16px);
  color: var(--ink-soft);
}
.cover-margin {
  font-family: var(--font-serif);
  font-style: normal;
  font-size: clamp(0.82rem, 2dvh, 1.02rem);
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--blue-700);
  margin-top: clamp(8px, 1.6dvh, 16px);
}

.cover-figure {
  position: relative;
  z-index: 1;
  height: 100%;
  min-height: 0;
  margin-left: clamp(-40px, -4vw, -16px);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  clip-path: polygon(14% 0, 100% 0, 100% 100%, 0% 100%);
}
@media (max-width: 760px) {
  .cover-figure { margin-left: 0; clip-path: polygon(0 8%, 100% 0, 100% 100%, 0 100%); max-height: 34dvh; }
}
.cover-portrait {
  height: 100%;
  width: auto;
  max-width: none;
  object-fit: cover;
  object-position: 60% 40%;
}
@media (max-width: 760px) { .cover-portrait { width: 100%; height: auto; } }

.registration-mark { position: absolute; width: 14px; height: 14px; opacity: 0.55; }
.registration-mark::before, .registration-mark::after { content: ""; position: absolute; background: var(--paper); }
.registration-mark::before { top: 50%; left: 0; width: 100%; height: 1px; transform: translateY(-50%); }
.registration-mark::after { left: 50%; top: 0; height: 100%; width: 1px; transform: translateX(-50%); }
.reg-tl { top: 10px; left: 10px; }
.reg-br { bottom: 10px; right: 10px; }

/* cover reveal sequence */
.reveal {
  animation: revealIn 620ms var(--ease) both;
  animation-delay: calc(var(--d) * 110ms);
}
@keyframes revealIn {
  from { opacity: 0; transform: translateY(0.5em); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 5. Table of contents ------------------------------------------ */
.toc-list { display: flex; flex-direction: column; gap: clamp(2px, 0.65dvh, 5px); counter-reset: toc -1; }
.toc-list li { counter-increment: toc; }
.toc-item {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: flex;
  align-items: baseline;
  gap: 0.8em;
  width: 100%;
  text-align: left;
  padding: clamp(3px, 0.7dvh, 6px) 0;
  border-bottom: 1px solid var(--rule);
  transition: padding-left 220ms var(--ease), color 220ms var(--ease);
}
.toc-item::after {
  content: counter(toc, decimal-leading-zero);
  position: absolute;
  z-index: -1;
  right: 0.08em;
  top: 50%;
  transform: translate(35%, -50%) scale(0.72);
  font-family: var(--font-serif);
  font-size: clamp(2.2rem, 7dvh, 4.6rem);
  font-weight: 600;
  line-height: 0.8;
  color: var(--blue-500);
  opacity: 0;
  transition: opacity 240ms var(--ease), transform 420ms var(--ease);
}
.toc-item:hover, .toc-item:focus-visible { padding-left: 0.65em; color: var(--blue-700); }
.toc-item:hover::after, .toc-item:focus-visible::after { opacity: 0.1; transform: translate(0, -50%) scale(1); }
.toc-num { font-family: var(--font-mono); font-size: var(--fs-meta); color: var(--blue-700); flex: 0 0 auto; transition: transform 260ms var(--ease); }
.toc-item:hover .toc-num, .toc-item:focus-visible .toc-num { transform: translateY(-0.18em) rotate(-8deg); }
.toc-text { display: flex; flex-direction: column; gap: 0.08em; }
.toc-text strong { font-family: var(--font-serif); font-size: var(--fs-body); font-weight: 600; transition: letter-spacing 260ms var(--ease), transform 260ms var(--ease); }
.toc-item:hover .toc-text strong, .toc-item:focus-visible .toc-text strong { letter-spacing: 0.025em; transform: translateX(0.16em); }
.toc-text em { font-style: italic; font-size: clamp(0.72rem, 1.6dvh, 0.84rem); line-height: 1.16; color: var(--ink-soft); }

/* ---------- 6. Acrostic --------------------------------------------------- */
.acrostic-list { display: flex; flex-direction: column; gap: clamp(2px, 0.9dvh, 8px); }
.acrostic-list li {
  font-family: var(--font-serif);
  font-size: var(--fs-body);
  line-height: 1.3;
  animation: revealIn 560ms var(--ease) both;
  animation-delay: calc(var(--d) * 90ms + 120ms);
}
.acrostic-letter { color: var(--blue-700); font-weight: 600; font-size: 1.25em; margin-right: 0.05em; }

/* ---------- 7. Timeline & quote ------------------------------------------- */
.timeline { display: flex; flex-direction: column; gap: clamp(3px, 0.9dvh, 8px); }
.timeline li { display: grid; grid-template-columns: 5.4em 1fr; gap: 0.6em; align-items: baseline; }
.timeline time { font-family: var(--font-mono); font-size: var(--fs-meta); color: var(--blue-500); }
.timeline p { font-size: var(--fs-body); line-height: 1.3; }

.quote {
  margin-top: clamp(8px, 1.6dvh, 16px);
  padding-left: clamp(8px, 1.4vw, 16px);
  border-left: 2px solid var(--blue-500);
}
.quote p {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: clamp(0.9rem, 2.3dvh, 1.15rem);
  line-height: 1.3;
}
.quote cite {
  display: block;
  font-family: var(--font-serif);
  font-style: normal;
  font-size: var(--fs-meta);
  color: rgba(245, 240, 230, 0.7);
  margin-top: 0.4em;
}

/* ---------- 8. Books constellation ---------------------------------------- */
.constellation-field { position: relative; flex: 1; min-height: 0; }
.constellation-lines { position: absolute; inset: 0; width: 100%; height: 100%; }
.constellation-lines line { stroke: var(--rule); stroke-width: 0.3; }

.book-node {
  position: absolute;
  left: var(--x);
  top: var(--y);
  max-width: 40%;
}
.book-node h3 { font-size: clamp(0.85rem, 2.2dvh, 1.15rem); line-height: 1.15; margin-bottom: 0.15em; }
.book-node p { font-size: var(--fs-meta); line-height: 1.3; color: var(--ink-soft); }
.book-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.03em;
  color: var(--blue-700);
  margin-bottom: 0.3em;
}
.book-badge--soon { color: var(--warm); }

@media (max-width: 760px) {
  .constellation-lines { display: none; }
  .constellation-field {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: clamp(4px, 1dvh, 10px);
  }
  .book-node {
    position: static;
    max-width: none;
    border-left: 2px solid var(--blue-500);
    padding-left: 0.7em;
  }
}

/* ---------- 9. Svagītā steps & tags ---------------------------------------- */
.steps { display: flex; flex-direction: column; gap: clamp(3px, 1dvh, 10px); }
.steps li { display: flex; align-items: center; gap: 0.7em; font-size: var(--fs-body); }
.step-num {
  flex: 0 0 auto;
  width: 1.7em; height: 1.7em;
  border-radius: 50%;
  border: 1px solid var(--blue-700);
  color: var(--blue-700);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: var(--fs-meta);
}
.tag-row { display: flex; flex-wrap: wrap; gap: 0.5em; margin-top: clamp(8px, 1.6dvh, 16px); }
.tag-row li {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--blue-500);
  padding: 0 0 0.15em;
  color: var(--ink-soft);
}
.recognition-line {
  font-family: var(--font-mono);
  font-size: var(--fs-meta);
  color: var(--blue-700);
  margin-top: clamp(6px, 1.2dvh, 12px);
  padding-top: clamp(6px, 1.2dvh, 12px);
  border-top: 1px solid var(--rule);
}

/* ---------- 10. Impact & ventures ------------------------------------------ */
.venture { margin-top: clamp(6px, 1.4dvh, 14px); }
.venture h3 { font-size: clamp(0.9rem, 2.3dvh, 1.2rem); margin-bottom: 0.2em; }
.venture p { font-size: var(--fs-body); line-height: 1.35; color: var(--ink-soft); max-width: 36ch; }
.marker-list { display: flex; flex-direction: column; gap: clamp(3px, 0.9dvh, 8px); }
.marker-list li {
  font-size: var(--fs-body);
  padding-left: 1em;
  position: relative;
}
.marker-list li::before { content: "—"; position: absolute; left: 0; color: var(--blue-500); }
.closing-thought {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: clamp(0.85rem, 2.1dvh, 1.05rem);
  margin-top: clamp(10px, 2dvh, 18px);
  padding-top: clamp(8px, 1.6dvh, 14px);
  border-top: 1px solid var(--rule);
  color: var(--ink-soft);
  max-width: 32ch;
}

/* ---------- 11. Speaking, recognition & contact ----------------------------- */
.topic-list { display: flex; flex-direction: column; gap: clamp(3px, 0.9dvh, 8px); }
.topic-list li {
  font-size: var(--fs-body);
  padding-left: 1em;
  position: relative;
}
.topic-list li::before { content: "—"; position: absolute; left: 0; color: var(--blue-500); }

.ledger { display: flex; flex-direction: column; gap: clamp(3px, 0.9dvh, 8px); }
.ledger-row { display: flex; flex-direction: column; padding-bottom: clamp(3px, 0.8dvh, 7px); border-bottom: 1px solid var(--rule-on-ink); }
.ledger-row dt { font-family: var(--font-mono); font-size: var(--fs-meta); color: var(--blue-500); }
.ledger-row dd { margin: 0.1em 0 0; font-size: var(--fs-body); }

.contact-heading { font-size: clamp(1rem, 2.6dvh, 1.3rem); margin-top: clamp(10px, 2dvh, 18px); }
.contact-note { font-family: var(--font-mono); font-size: var(--fs-micro); color: rgba(245, 240, 230, 0.72); margin-top: 0.4em; }

/* ---------- 12. Corner fold (quick TOC) ------------------------------------- */
.corner-fold {
  position: absolute;
  top: 0; right: 0;
  width: clamp(46px, 9vw, 68px);
  height: clamp(46px, 9vw, 68px);
  z-index: 6;
  transition: width 160ms var(--ease), height 160ms var(--ease);
}
.corner-fold:hover, .corner-fold:focus-visible { width: clamp(54px, 10.5vw, 78px); height: clamp(54px, 10.5vw, 78px); }
.fold-shape {
  position: absolute; inset: 0;
  clip-path: polygon(100% 0, 100% 100%, 0 0);
  background: var(--parchment);
  box-shadow: -3px 3px 8px rgba(27, 27, 25, 0.28) inset;
}
.fold-shape::after {
  content: "";
  position: absolute;
  top: 0; right: 0;
  width: 60%; height: 60%;
  clip-path: polygon(100% 0, 100% 100%, 0 0);
  border-top: 1px solid var(--rule);
  border-right: 1px solid var(--rule);
}
.fold-label {
  position: absolute;
  left: 66%;
  top: 33%;
  transform: translate(-50%, -50%) rotate(45deg);
  transform-origin: center;
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--blue-700);
  white-space: nowrap;
  line-height: 1;
}

/* ---------- 13. Nav buttons & progress edge --------------------------------- */
.nav-btn {
  position: absolute;
  top: auto;
  bottom: clamp(12px, 2dvh, 20px);
  transform: none;
  width: clamp(32px, 3.2vw, 38px);
  height: clamp(23px, 2.6vw, 28px);
  border: 1px solid rgba(21, 75, 110, 0.2);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(245, 240, 230, 0.94);
  color: var(--ink);
  box-shadow: 0 2px 6px rgba(27, 27, 25, 0.14);
  z-index: 8;
  transition: transform 140ms var(--ease), opacity 140ms var(--ease);
}
.nav-btn svg { width: 46%; height: 46%; }
.nav-btn:hover { background: var(--paper); }
.nav-btn:active { transform: scale(0.9); }
.nav-btn:disabled { opacity: 0.28; pointer-events: none; }
.nav-btn.prev { left: auto; right: clamp(54px, 7vw, 68px); }
.nav-btn.next { right: clamp(12px, 1.8vw, 18px); }

.progress-edge {
  position: absolute;
  left: 50%;
  right: auto;
  top: auto;
  bottom: clamp(9px, 1.5dvh, 15px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: clamp(7px, 1vw, 11px);
  z-index: 9;
}
.progress-edge .tick {
  display: block;
  width: 8px;
  height: 8px;
  min-width: 8px;
  padding: 0;
  border: 1px solid rgba(21, 75, 110, 0.4);
  border-radius: 50%;
  background: rgba(245, 240, 230, 0.78);
  transition: width 140ms var(--ease), border-radius 140ms var(--ease), background 140ms var(--ease), transform 140ms var(--ease);
}
.progress-edge .tick:hover,
.progress-edge .tick:focus-visible { transform: scale(1.45); background: var(--blue-500); }
.progress-edge .tick.is-active {
  width: 18px;
  border-radius: 4px;
  border-color: var(--blue-500);
  background: var(--blue-500);
}

/* ---------- 14. The turning leaf -------------------------------------------- */
.leaf {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  transform-style: preserve-3d;
  transform: rotateY(0deg);
  /* The animation sheet must not cover the live spread while idle. */
  visibility: hidden;
}
.leaf.turn-next,
.leaf.turn-back {
  visibility: visible;
}
.leaf-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  overflow: hidden;
  background: var(--paper);
}
.leaf-back { transform: rotateY(180deg); }
.leaf::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--ink);
  opacity: 0;
  pointer-events: none;
}

.leaf.turn-next { transform-origin: 0% 50%; animation: turnNext var(--dur) var(--ease) forwards; }
.leaf.turn-next::after { animation: shadeNext var(--dur) var(--ease) forwards; }
.leaf.turn-back { transform-origin: 100% 50%; animation: turnBack var(--dur) var(--ease) forwards; }
.leaf.turn-back::after { animation: shadeBack var(--dur) var(--ease) forwards; }

@keyframes turnNext {
  0% { transform: rotateY(0deg); }
  100% { transform: rotateY(-180deg); }
}
@keyframes turnBack {
  0% { transform: rotateY(0deg); }
  100% { transform: rotateY(180deg); }
}
@keyframes shadeNext {
  0% { opacity: 0; } 45% { opacity: 0.32; } 55% { opacity: 0.32; } 100% { opacity: 0; }
}
@keyframes shadeBack {
  0% { opacity: 0; } 45% { opacity: 0.32; } 55% { opacity: 0.32; } 100% { opacity: 0; }
}

/* ---------- 15. Help panel & scrim ------------------------------------------ */
.overlay-scrim {
  position: fixed; inset: 0;
  background: rgba(13, 13, 12, 0.5);
  z-index: 50;
}
.help-panel {
  position: fixed;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 420px);
  max-height: 86dvh;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  border-radius: 4px;
  padding: clamp(16px, 3dvh, 28px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  z-index: 51;
}
.help-panel h2 { font-size: clamp(1.05rem, 2.6dvh, 1.35rem); margin-bottom: 0.7em; }
.help-panel ul { display: flex; flex-direction: column; gap: 0.55em; margin-bottom: 1em; }
.help-panel li { font-size: var(--fs-body); line-height: 1.4; }

/* ---------- 16. Living portrait & kinetic chapter typography ----------------- */
/* The supplied portrait is re-drawn as transparent ink and drifts to a new
   margin on each chapter. It is deliberately quiet: atmosphere, not wallpaper. */
.spread-inner { position: relative; isolation: isolate; }
.spread-inner::before {
  content: "";
  position: absolute;
  z-index: 0;
  width: min(58%, 520px);
  aspect-ratio: 1000 / 956;
  right: -12%;
  bottom: -19%;
  pointer-events: none;
  background: url("assets/ritesh-portrait-ink.png") center / contain no-repeat;
  opacity: 0.045;
  transform: rotate(-3deg) scale(0.94);
  transition: opacity 450ms var(--ease), transform 900ms var(--ease);
}
.spread-inner > * { position: relative; z-index: 1; }
.spread.is-current .spread-inner::before,
.leaf-face > .spread .spread-inner::before {
  animation: portraitSet 900ms var(--ease) both;
}
/* Keep the portrait in one recognisable bottom-right position throughout.
   Dark chapters use the same geometry with a restrained light-ink treatment. */
.spread[data-index="3"] .spread-inner::before,
.spread[data-index="7"] .spread-inner::before {
  filter: brightness(0) invert(1);
  opacity: 0.055;
}

@keyframes portraitSet {
  from { opacity: 0; translate: 5% 0; }
  to { translate: 0 0; }
}

/* Titles settle like freshly printed type when a page arrives. */
.spread.is-current .spread-title,
.leaf-face > .spread .spread-title {
  animation: titleSet 620ms var(--ease) both;
}
@keyframes titleSet {
  from { opacity: 0; transform: translateY(0.35em); letter-spacing: 0.025em; }
  to { opacity: 1; transform: translateY(0); letter-spacing: normal; }
}

@media (max-width: 760px) {
  .spread-inner::before { width: 88%; opacity: 0.032; }
  .spread[data-index="3"] .spread-inner--dark,
  .spread[data-index="7"] .spread-inner--dark {
    padding-left: clamp(16px, 5vw, 24px);
    padding-right: clamp(12px, 4vw, 20px);
  }
  .spread[data-index="3"] .spread-inner::before,
  .spread[data-index="7"] .spread-inner::before { opacity: 0.042; }
}

/* ---------- 17. Reduced motion ---------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .reveal, .acrostic-list li, .spread-title, .spread-inner::before {
    animation: none !important;
    opacity: 1;
  }
  .reveal, .acrostic-list li { transform: none !important; }
  .spread-inner::before { opacity: 0.04; translate: none; }
  .leaf, .leaf::after { animation: none !important; }
  .btn, .toc-item, .nav-btn, .help-btn, .corner-fold, .social-link, .developer-credit {
    transition: none !important;
  }
  .social-link:hover, .social-link:focus-visible { transform: none; }
}

/* ---------- 17. Short-viewport safety (guarantees no overflow at 320×568) --- */
@media (max-width: 760px) {
  .lede { max-width: none; }
}
@media (max-height: 620px) {
  .quote, .tag-row, .cover-margin { display: none; }
  .spread { padding: clamp(8px, 2.4dvh, 30px) clamp(12px, 3.4vw, 40px); }
  .spread-title { margin-bottom: 0.35em; }
  .venture { margin-top: clamp(4px, 1dvh, 14px); }
}

/* ---------- 18. Print / degenerate-size safety ------------------------------ */
@media (max-height: 380px) {
  .titlebar, .statusbar { min-height: 26px; padding-top: 2px; padding-bottom: 2px; }
}
