/* ============================================================================
   Book reader — Unwind style (Quattro, gold accent, quiet uppercase labels).
   Used by books/*.html together with books/reader.js. Size, font and theme
   come from ../reading-prefs.css (--read-root, --font-text, the palette).
   Without JS the whole book reads top to bottom with the same typography.
   =========================================================================== */

:root {
  --black-rgb: 17, 17, 17;
  --gold-rgb: 112, 84, 28;
  --bg: #ffffff;
  --surface: #f5f5f5;
  --border: rgba(var(--black-rgb), 0.16);
  --text: rgb(var(--black-rgb));
  --dim: rgba(var(--black-rgb), 0.7);
  --accent: rgb(var(--gold-rgb));
  --accent-dim: rgba(var(--gold-rgb), 0.6);
  --accent-faint: rgba(var(--gold-rgb), 0.37);
  --measure: 680px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --black-rgb: 248, 245, 239;
    --gold-rgb: 196, 169, 110;
    --bg: #0e0d0b;
    --surface: #161510;
    --border: rgba(var(--black-rgb), 0.18);
  }
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
  font-size: var(--read-root, 18px);
  scroll-padding-top: 4.5rem;
  -webkit-text-size-adjust: 100%;
}

body {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 2.5rem 1.5rem 7rem;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-text);
  font-size: 1rem;
  line-height: 1.78;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

::selection { background: var(--accent-faint); }

/* ---- Text ---------------------------------------------------------------- */
p { margin: 0 0 1rem; }
strong, b { font-weight: 700; }
em, i, cite { font-style: italic; }
abbr { text-decoration: none; }
sup { line-height: 0; font-size: 0.7em; }

a { color: inherit; text-decoration: none; }
main a,
.note-sheet a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--accent-faint);
  text-underline-offset: 0.2em;
}
main a:hover,
.note-sheet a:hover { text-decoration-color: currentColor; }
sup a { text-decoration: none !important; padding: 0 0.1em; }

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

hr { display: none; }

/* Heading anchors (#) and "back to top" arrows from the source markup. */
h2 > a[href^="#"],
h3 > a[href^="#"],
h4 > a[href^="#"],
p > a.return:first-child { display: none; }

h1, h2, h3, h4 {
  font-weight: 400;
  color: var(--accent);
  line-height: 1.2;
}
main h2 {
  margin: 0 0 2rem;
  font-style: italic;
  font-size: 2.1rem;
}
main h3 {
  margin: 2.6rem 0 0.8rem;
  font-style: italic;
  font-size: 1.45rem;
}
main h4 {
  margin: 2rem 0 0.6rem;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-dim);
}
main h3 strong { font-weight: 400; color: var(--accent-dim); margin-right: 0.35em; }

blockquote {
  margin: 1.8rem 0 1.8rem 0.45rem;
  padding: 0.2rem 1.3rem 0.2rem 1.4rem;
  border-left: 4px solid var(--accent);
  font-style: italic;
}
blockquote p { margin: 0 0 0.4rem; }
blockquote cite {
  display: block;
  font-size: 0.78rem;
  font-style: normal;
  color: var(--dim);
  letter-spacing: 0.04em;
}

ul, ol { padding-left: 1.4rem; }
li { margin: 0 0 0.4rem; }

dl { margin: 1.5rem 0; }
dt {
  margin-top: 1.2rem;
  font-style: italic;
  color: var(--accent);
}
dd { margin: 0.1rem 0 0; }

/* Numbered passages (2.1, 2.2…): small gold numbers, hung in the margin
   when there's room for them. */
p > strong[id] {
  font-weight: 400;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-right: 0.4em;
}
@media (min-width: 880px) {
  p > strong[id] {
    position: absolute;
    margin-left: -4.2rem;
    width: 3.4rem;
    margin-top: 0.22rem;
    text-align: right;
  }
}

/* ---- Cover --------------------------------------------------------------- */
.cover { margin: 0 0 3rem; }
.cover-author {
  margin: 4rem 0 0.75rem;
  font-size: 0.78rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent-dim);
}
.cover-title {
  margin: 0 0 1rem;
  font-size: clamp(2.6rem, 9vw, 3.6rem);
  font-style: italic;
  line-height: 1.05;
}
.cover-credit { margin: 0 0 2.5rem; color: var(--dim); font-size: 0.9rem; }

.cover-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.5rem;
  margin: 0 0 3.5rem;
}
.reader-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3.2rem;
  padding: 0.75rem 1.4rem;
  border: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
  transition: border-color 180ms ease, background-color 180ms ease, color 180ms ease;
}
.reader-button.primary,
.reader-button:hover {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--bg);
}
.reader-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--dim);
  font: inherit;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
}
.reader-link:hover { color: var(--accent); }

/* Contents list (on the cover and in the contents sheet). */
.toc > h2 {
  margin: 0 0 1rem;
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent-dim);
}
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0; }
.toc li > a {
  display: block;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
  transition: color 180ms ease;
}
.toc li > a[aria-current] { color: var(--accent); }
@media (hover: hover) {
  .toc li > a:hover { color: var(--accent); }
}
.toc ul ul { margin: 0 0 0.3rem 1.1rem; }
.toc ul ul a { padding: 0.25rem 0; border-bottom: 0; font-size: 0.86rem; color: var(--dim); }
.toc ul ul ul a { font-size: 0.8rem; }

/* ---- Reading view (reader.js) ---------------------------------------------- */
.reading .cover { display: none; }

.progress {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 30;
  height: 2px;
  width: 100%;
  background: var(--accent);
  transform-origin: left;
  transform: scaleX(0);
  pointer-events: none;
}

.chapter { min-height: 60vh; }

.chapter-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin: 4rem 0 0;
  padding-top: 0.8rem;
  border-top: 2px solid var(--accent-faint);
}
.chapter-nav a {
  display: block;
  color: var(--text);
  text-decoration: none;
  line-height: 1.4;
}
.chapter-nav a:hover { color: var(--accent); }
.chapter-nav .next { grid-column: 2; text-align: right; }
.chapter-nav span {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent-dim);
}

/* Gold square, bottom right — opens the contents. */
.contents-button {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 20;
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
}
.contents-button i {
  display: block;
  width: 1.1rem;
  border-top: 2px solid currentColor;
}

/* Bottom sheets: contents and notes. */
.sheet {
  position: fixed;
  inset: auto 0 0 0;
  width: 100%;
  max-width: var(--measure);
  max-height: 78vh;
  margin: 0 auto;
  padding: 1rem 1.5rem 1.75rem;
  border: 0;
  border-top: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  overflow: auto;
}
.sheet::backdrop { background: rgba(var(--black-rgb), 0.18); }
@media (prefers-color-scheme: dark) {
  .sheet::backdrop { background: rgba(0, 0, 0, 0.55); }
}
.sheet[open] { animation: rise 220ms ease; }
@keyframes rise { from { transform: translateY(1.5rem); opacity: 0; } }

.sheet-header {
  position: sticky;
  top: -1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin: -1rem -1.5rem 0.75rem;
  padding: 1rem 1.5rem 0.6rem;
  background: var(--bg);
}
.sheet-title {
  margin: 0;
  font-size: 1.3rem;
  font-style: italic;
  font-weight: 400;
  color: var(--accent);
}
.sheet .toc > h2 { display: none; }
.contents-sheet .reading-prefs { margin: 0 0 2.25rem; }
.contents-sheet .sheet-title { margin: 0 0 0.5rem; }

.note-sheet .note-body > :last-child { margin-bottom: 0; }
.note-sheet .note-body dt { margin-top: 0; }
.note-sheet .note-body li { list-style: none; }
.note-sheet .note-body ol,
.note-sheet .note-body ul { padding: 0; margin: 0; }
.note-go { display: inline-block; margin-top: 1rem; }

@media (max-width: 640px) {
  body { padding: 1.75rem 1.15rem 6rem; }
  .sheet { padding-left: 1.15rem; padding-right: 1.15rem; }
  .sheet-header { margin-left: -1.15rem; margin-right: -1.15rem; padding-left: 1.15rem; padding-right: 1.15rem; }
  .contents-button { right: 1rem; bottom: 1rem; }
  main h2 { font-size: 1.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet[open] { animation: none; }
}
