/* wonders — reader
   The design is the typography. Everything else disappears. */

@font-face {
  font-family: 'Newsreader';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url(/fonts/newsreader-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Newsreader';
  font-style: italic;
  font-weight: 300 700;
  font-display: swap;
  src: url(/fonts/newsreader-italic-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* Fallback tuned to Newsreader's metrics so the swap is nearly invisible. */
@font-face {
  font-family: 'Newsreader Fallback';
  src: local('Georgia'), local('Times New Roman');
  size-adjust: 96%;
  ascent-override: 92%;
  descent-override: 24%;
  line-gap-override: 0%;
}

:root {
  --bg: #0e0d0c;
  --fg: #e6e1d8;
  --fg-dim: rgba(230, 225, 216, .58);
  --fg-faint: rgba(230, 225, 216, .30);
  --line: rgba(230, 225, 216, .08);
  --accent: #c9a86a;
  --accent-ink: #0e0d0c;

  --fs: 20px;
  --lh: 1.62;
  --measure: 33em;
  --pad: 26px;

  --serif: 'Newsreader', 'Newsreader Fallback', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --ui: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;

  --ease: cubic-bezier(.2, .7, .2, 1);
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f5f1e9;
  --fg: #1c1a17;
  --fg-dim: rgba(28, 26, 23, .62);
  --fg-faint: rgba(28, 26, 23, .34);
  --line: rgba(28, 26, 23, .10);
  --accent: #96773a;
  --accent-ink: #f5f1e9;
  color-scheme: light;
}

* { box-sizing: border-box; }
html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  scroll-behavior: auto;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  font-size: var(--fs);
  line-height: var(--lh);
  font-optical-sizing: auto;
  font-feature-settings: 'kern', 'liga', 'onum';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  transition: background .5s var(--ease), color .5s var(--ease);
}
/* The page arrives already at position, then fades in. Without JS, no fade. */
html.js body { opacity: 0; }
html.js body.ready { opacity: 1; transition: opacity .7s var(--ease), background .5s var(--ease), color .5s var(--ease); }

::selection { background: rgba(201, 168, 106, .28); }

/* ---------- The column ---------- */

.book {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 34vh var(--pad) 28vh;
  hyphens: auto;
  -webkit-hyphens: auto;
  hyphenate-limit-chars: 7 3 3;
  text-wrap: pretty;
}
@media (min-width: 720px) {
  :root { --fs: 21.5px; --pad: 40px; }
  .book { padding-top: 32vh; }
}
@media (min-width: 1100px) {
  :root { --fs: 22px; }
}

.book p {
  margin: 0 0 1.3em;
  transition: opacity 1.2s var(--ease);
}
.book p:last-child { margin-bottom: 0; }
.book em { font-style: italic; }

/* Two paragraphs above the reading line are dimmed on return, then settle. */
.book p.settle { opacity: .45; transition: none; }

/* ---------- Chapters ---------- */

.chapter { margin-top: 40vh; }
.chapter-head { margin-bottom: 15vh; }
html.js .chapter-head {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .8s var(--ease), transform .8s var(--ease);
}
html.js .chapter-head.in { opacity: 1; transform: none; }

.chapter-num {
  font-family: var(--ui);
  font-size: 11px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--fg-faint);
  margin: 0 0 1.6em;
  font-variant-numeric: tabular-nums;
}
.chapter-title {
  font-family: var(--serif);
  font-size: 1.42em;
  font-weight: 400;
  line-height: 1.28;
  letter-spacing: -.004em;
  margin: 0;
  text-wrap: balance;
  hyphens: manual;
}
.chapter-title em { font-style: italic; }

/* ---------- The lock ---------- */

.veil {
  position: relative;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  transition: max-height 1s var(--ease);
}
.veil .chapter { margin-top: 0; }
html.js .veil .chapter-head { opacity: 1; transform: none; }
.veil::after {
  content: '';
  position: absolute;
  inset: 0;
  transition: opacity .9s var(--ease);
  pointer-events: none;
}
/* Cut at a chapter start: the title stays, the first lines dissolve. */
.veil--head { margin-top: 40vh; max-height: calc(15vh + 11.5em); }
.veil--head::after { background: linear-gradient(to bottom, transparent 0%, transparent 52%, var(--bg) 97%); }
/* Cut mid-chapter: the answer begins, and fades on its first line. */
.veil--mid { margin-top: 1.3em; max-height: 4.3em; }
.veil--mid::after { background: linear-gradient(to bottom, transparent 0%, rgba(14, 13, 12, 0) 12%, var(--bg) 88%); }
.veil--mid .book p, .veil--mid p { margin-bottom: 0; }
.veil.lift { pointer-events: auto; user-select: text; -webkit-user-select: text; }
.veil.lift::after { opacity: 0; }

.gate {
  margin-top: 2.4em;
  transition: opacity .45s var(--ease), max-height .6s var(--ease), margin .6s var(--ease);
  overflow: hidden;
}
.gate.out { opacity: 0; max-height: 0 !important; margin-top: 0; }
.gate-lead {
  color: var(--fg-dim);
  margin: 0 0 1.6em;
}
.gate-actions { margin: 0 0 .9em; }
.gate-note {
  font-family: var(--ui);
  font-size: 11.5px;
  letter-spacing: .04em;
  color: var(--fg-faint);
  margin: 0 0 3.2em;
}
.gate-note a { color: inherit; text-decoration: underline; text-underline-offset: 3px; }

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .6em;
  font-family: var(--ui);
  font-size: 14px;
  letter-spacing: .05em;
  padding: 15px 24px;
  border: 1px solid var(--accent);
  color: var(--accent);
  background: transparent;
  border-radius: 2px;
  cursor: pointer;
  text-decoration: none;
  transition: background .3s var(--ease), color .3s var(--ease), transform .3s var(--ease), opacity .3s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--accent); color: var(--accent-ink); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: default; }
.btn .price { color: inherit; opacity: .85; }
@media (max-width: 719px) { .gate-actions .btn { width: 100%; } }

.gate-toc {
  list-style: none;
  margin: 0;
  padding: 0;
}
.gate-toc li {
  display: flex;
  gap: 1.1em;
  align-items: baseline;
  padding: .5em 0;
  color: var(--fg-faint);
  font-size: .94em;
  line-height: 1.4;
}
.gate-toc .n {
  font-family: var(--ui);
  font-size: 11px;
  letter-spacing: .14em;
  min-width: 1.8em;
  font-variant-numeric: tabular-nums;
}

/* Locked content arrives after unlock. */
.locked-in { opacity: 0; transition: opacity .9s var(--ease); }
.locked-in.show { opacity: 1; }

/* ---------- Closing mark ---------- */

.colophon {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 var(--pad) 12vh;
  font-family: var(--ui);
  font-size: 11px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--fg-faint);
  text-align: center;
}
.colophon a { color: inherit; text-decoration: none; }

/* ---------- Progress ---------- */

.progress {
  position: fixed;
  top: 0; left: 0;
  height: 1px;
  width: 0;
  background: var(--accent);
  z-index: 30;
  transition: width .12s linear;
  pointer-events: none;
}
.progress-hit {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 30px;
  z-index: 29;
  cursor: pointer;
  background: transparent;
  border: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
.progress-hit:focus-visible { outline: 1px solid var(--accent); outline-offset: -1px; }
.chapter-label {
  position: fixed;
  top: 9px;
  right: 12px;
  padding: 5px 9px;
  background: var(--bg);
  border-radius: 2px;
  font-family: var(--ui);
  font-size: 11px;
  letter-spacing: .16em;
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity .5s var(--ease);
  pointer-events: none;
  z-index: 31;
}
.chapter-label.show { opacity: 1; }

/* ---------- Drawer (the only navigation) ---------- */

.drawer { position: fixed; inset: 0; z-index: 40; visibility: hidden; }
.drawer.open { visibility: visible; }
.drawer-bg {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, .55);
  opacity: 0;
  transition: opacity .4s var(--ease);
}
.drawer.open .drawer-bg { opacity: 1; }
.drawer-panel {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: min(380px, 88vw);
  background: var(--bg);
  border-right: 1px solid var(--line);
  transform: translateX(-102%);
  transition: transform .5s var(--ease);
  padding: 52px 30px 40px;
  padding-top: max(52px, env(safe-area-inset-top));
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
}
.drawer.open .drawer-panel { transform: none; }

.toc { list-style: none; margin: 0 0 auto; padding: 0; }
.toc li { margin: 0; }
.toc a {
  display: flex;
  gap: 1em;
  align-items: baseline;
  padding: .55em 0;
  color: var(--fg-dim);
  text-decoration: none;
  font-size: .92em;
  line-height: 1.35;
  transition: color .25s var(--ease);
}
.toc a:hover { color: var(--fg); }
.toc a.current { color: var(--accent); }
.toc a.locked { color: var(--fg-faint); }
.toc .n {
  font-family: var(--ui);
  font-size: 10.5px;
  letter-spacing: .14em;
  min-width: 1.7em;
  font-variant-numeric: tabular-nums;
  padding-top: .2em;
}

.drawer-controls {
  margin-top: 2.4em;
  padding-top: 1.6em;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-family: var(--ui);
  font-size: 12px;
  color: var(--fg-dim);
}
.ctl {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--fg-dim);
  font-family: var(--ui);
  font-size: 12px;
  letter-spacing: .04em;
  padding: 8px 12px;
  border-radius: 2px;
  cursor: pointer;
  transition: color .25s, border-color .25s;
  -webkit-tap-highlight-color: transparent;
}
.ctl:hover { color: var(--fg); border-color: var(--fg-faint); }
.ctl.serif { font-family: var(--serif); font-size: 15px; padding: 5px 12px; }
.ctl-spacer { flex: 1; }
.drawer-account {
  margin-top: 1.2em;
  font-family: var(--ui);
  font-size: 12px;
  color: var(--fg-faint);
  line-height: 1.6;
}
.drawer-account a, .drawer-account button.link {
  color: var(--fg-dim);
  text-decoration: underline;
  text-underline-offset: 3px;
  background: none; border: 0; padding: 0; font: inherit; cursor: pointer;
}

/* ---------- Sheet (login / password) ---------- */

.sheet { position: fixed; inset: 0; z-index: 50; visibility: hidden; }
.sheet.open { visibility: visible; }
.sheet-bg {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, .55);
  opacity: 0;
  transition: opacity .4s var(--ease);
}
.sheet.open .sheet-bg { opacity: 1; }
.sheet-panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--line);
  padding: 28px var(--pad) calc(28px + env(safe-area-inset-bottom));
  transform: translateY(104%);
  transition: transform .5s var(--ease);
}
.sheet.open .sheet-panel { transform: none; }
@media (min-width: 720px) {
  .sheet-panel {
    left: 50%; right: auto; bottom: auto; top: 50%;
    width: 420px;
    transform: translate(-50%, -46%);
    opacity: 0;
    border: 1px solid var(--line);
    border-radius: 3px;
    padding: 34px 36px;
    transition: transform .5s var(--ease), opacity .4s var(--ease);
  }
  .sheet.open .sheet-panel { transform: translate(-50%, -50%); opacity: 1; }
}
.sheet h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.15em;
  margin: 0 0 .5em;
}
.sheet p {
  font-family: var(--ui);
  font-size: 12.5px;
  color: var(--fg-dim);
  margin: 0 0 1.4em;
  line-height: 1.55;
}
.sheet form { display: flex; flex-direction: column; gap: 10px; }
.field {
  appearance: none;
  width: 100%;
  font-family: var(--ui);
  font-size: 15px;
  padding: 13px 14px;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 2px;
  outline: none;
  transition: border-color .25s;
}
.field:focus { border-color: var(--fg-faint); }
.field::placeholder { color: var(--fg-faint); }
.sheet .btn { width: 100%; margin-top: 4px; }
.sheet-alt {
  font-family: var(--ui);
  font-size: 12px;
  color: var(--fg-faint);
  margin: 1.2em 0 0;
  line-height: 1.6;
}
.sheet-alt a, .sheet-alt button.link {
  color: var(--fg-dim);
  text-decoration: underline;
  text-underline-offset: 3px;
  background: none; border: 0; padding: 0; font: inherit; cursor: pointer;
}
.sheet-err {
  font-family: var(--ui);
  font-size: 12px;
  color: #c97a6a;
  min-height: 1.2em;
  margin: 0;
}

/* ---------- Nudge (choose a password, never blocking) ---------- */

.nudge {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 28;
  padding: 12px 44px 12px 18px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  font-family: var(--ui);
  font-size: 12px;
  color: var(--fg-dim);
  text-align: center;
  transform: translateY(-104%);
  transition: transform .55s var(--ease);
}
.nudge.show { transform: none; }
.nudge button.link {
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 3px;
  background: none; border: 0; padding: 0; font: inherit; cursor: pointer;
}
.nudge .x {
  position: absolute;
  right: 10px; top: 50%;
  transform: translateY(-50%);
  background: none; border: 0;
  color: var(--fg-faint);
  font-size: 18px;
  line-height: 1;
  padding: 8px;
  cursor: pointer;
}

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
  }
  html.js .chapter-head { opacity: 1; transform: none; }
}

/* Screen-reader only */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
