/* The Malfoid Saga — parchment, forest and a little gold. System fonts only. */
:root {
  --parchment: #f4ecd8;
  --parchment-2: #ebe0c4;
  --ink: #2a2620;
  --ink-soft: #5c5446;
  --forest: #1f3a2e;
  --forest-2: #2d5141;
  --gold: #8a6a1f;
  --gold-bright: #c9a54c;
  --rule: #d6c7a1;

  --bg: var(--parchment);
  --bg-raised: #f8f2e3;
  --fg: var(--ink);
  --fg-soft: var(--ink-soft);
  --link: var(--forest-2);
  --accent: var(--gold);
  --header-bg: var(--forest);
  --header-fg: #f1e8d0;
  --border: var(--rule);

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L", P052, Georgia, Cambria, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --size-step: 0;
  --reading-size: calc(1.1875rem * pow(1.08, var(--size-step)));
  --measure: 36em;
  --leading: 1.7;
  color-scheme: light;
}
@supports not (width: calc(1px * pow(2, 2))) {
  :root { --reading-size: calc(1.1875rem + var(--size-step) * 0.09rem); }
}

:root[data-width="narrow"] { --measure: 30em; }
:root[data-width="wide"] { --measure: 44em; }
:root[data-leading="tight"] { --leading: 1.5; }
:root[data-leading="loose"] { --leading: 1.95; }

:root[data-theme="dark"] {
  --bg: #14201a;
  --bg-raised: #1b2a22;
  --fg: #e6dcc3;
  --fg-soft: #b3a98f;
  --link: #d7b866;
  --accent: #d7b866;
  --header-bg: #0e1712;
  --header-fg: #e6dcc3;
  --border: #33463b;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"], :root:not([data-theme]) {
    --bg: #14201a;
    --bg-raised: #1b2a22;
    --fg: #e6dcc3;
    --fg-soft: #b3a98f;
    --link: #d7b866;
    --accent: #d7b866;
    --header-bg: #0e1712;
    --header-fg: #e6dcc3;
    --border: #33463b;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.6;
  overflow-wrap: break-word;
}
main { flex: 1; width: 100%; }
img { max-width: 100%; height: auto; }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--gold-bright); outline-offset: 2px; border-radius: 2px; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.2; letter-spacing: 0.005em; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 0.5rem; top: -3rem; z-index: 100;
  background: var(--gold-bright); color: #1a1a1a; padding: 0.5rem 1rem; border-radius: 0 0 6px 6px;
}
.skip-link:focus { top: 0; }

/* Header */
.site-header { background: var(--header-bg); color: var(--header-fg); border-bottom: 2px solid var(--gold-bright); position: relative; z-index: 10; }
.site-header__inner {
  max-width: 72rem; margin: 0 auto; padding: 0.7rem 1.25rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.wordmark { color: var(--header-fg); text-decoration: none; font-family: var(--display); font-size: 1.15rem; letter-spacing: 0.04em; white-space: nowrap; }
.wordmark__mark { color: var(--gold-bright); }
.crumbs { flex: 1; min-width: 0; font-family: var(--sans); font-size: 0.85rem; }
.crumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 0.25rem; margin: 0; padding: 0; }
.crumbs li + li::before { content: "›"; margin-right: 0.35rem; color: var(--gold-bright); }
.crumbs a { color: var(--header-fg); opacity: 0.85; }
.crumbs [aria-current] { opacity: 0.75; }
.crumbs li:first-child { display: none; }
.settings-toggle {
  margin-left: auto; min-width: 2.75rem; min-height: 2.75rem;
  font: 600 1rem var(--display); color: var(--header-fg);
  background: transparent; border: 1px solid rgba(201, 165, 76, 0.6); border-radius: 6px; cursor: pointer;
}
.settings-toggle[aria-expanded="true"], .settings-toggle:hover { background: rgba(201, 165, 76, 0.18); }

.settings {
  position: absolute; right: max(1.25rem, calc((100vw - 72rem) / 2 + 1.25rem)); top: calc(100% + 0.25rem);
  width: min(23rem, calc(100vw - 1.5rem));
  background: var(--bg-raised); color: var(--fg); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22); padding: 1rem 1.1rem 0.6rem; font-family: var(--sans); font-size: 0.9rem;
}
@media (max-width: 30rem) { .settings { right: 0.75rem; } }
.settings__title { font: 600 0.75rem var(--sans); text-transform: uppercase; letter-spacing: 0.1em; color: var(--fg-soft); margin: 0 0 0.75rem; }
.settings__row { display: flex; align-items: center; gap: 0.35rem; margin-bottom: 0.65rem; flex-wrap: wrap; }
.settings__label { width: 5.2rem; color: var(--fg-soft); }
.settings button {
  min-height: 2.25rem; padding: 0.25rem 0.65rem; font: inherit; color: var(--fg);
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px; cursor: pointer;
}
.settings button[aria-checked="true"] { background: var(--forest); color: #f4ecd8; border-color: var(--forest); }
:root[data-theme="dark"] .settings button[aria-checked="true"] { background: var(--gold-bright); color: #14201a; border-color: var(--gold-bright); }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .settings button[aria-checked="true"] { background: var(--gold-bright); color: #14201a; border-color: var(--gold-bright); }
}
.settings output { min-width: 3.2rem; text-align: center; font-variant-numeric: tabular-nums; }

/* Shared bits */
.eyebrow { font-family: var(--sans); font-size: 0.78rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); margin: 0 0 0.5rem; }
.eyebrow a { color: inherit; text-decoration: none; }
.eyebrow a:hover { text-decoration: underline; }
.ornament { color: var(--gold-bright); font-size: 1.5rem; text-align: center; margin: 1rem 0; }
.section-title { font-size: 1.5rem; text-align: center; margin: 0 0 1.75rem; }
.section-title::after { content: ""; display: block; width: 3rem; height: 2px; background: var(--gold-bright); margin: 0.75rem auto 0; }
.button {
  display: inline-block; padding: 0.6rem 1.15rem; border-radius: 6px; font-family: var(--sans); font-size: 0.92rem; font-weight: 600;
  text-decoration: none; background: var(--forest); color: #f6efdc; border: 1px solid var(--forest); margin: 0 0.35rem 0.5rem 0;
}
.button:hover { background: var(--forest-2); }
.button--quiet { background: transparent; color: var(--link); border-color: var(--border); }
.button--quiet:hover { background: var(--bg-raised); }
.button--accent { background: transparent; color: var(--accent); border-color: var(--accent); }
:root[data-theme="dark"] .button:not(.button--quiet):not(.button--accent) { background: var(--gold-bright); color: #14201a; border-color: var(--gold-bright); }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .button:not(.button--quiet):not(.button--accent) { background: var(--gold-bright); color: #14201a; border-color: var(--gold-bright); }
}
.badge { font-family: var(--sans); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; padding: 0.12rem 0.5rem; border-radius: 999px; border: 1px solid currentColor; }
.badge--complete { color: var(--link); }
.badge--ongoing { color: var(--accent); }
.book-meta { font-family: var(--sans); font-size: 0.85rem; color: var(--fg-soft); margin: 0.25rem 0 0.75rem; }

/* Home */
.hero { text-align: center; padding: clamp(2.5rem, 7vw, 5rem) 1.25rem 2rem; max-width: 48rem; margin: 0 auto; }
.hero__title { font-size: clamp(2.6rem, 8vw, 4.4rem); font-weight: 500; margin: 0.25rem 0; letter-spacing: 0.01em; }
.hero__byline { font-style: italic; font-size: 1.15rem; margin: 0; color: var(--fg-soft); }
.hero__stats { font-family: var(--sans); font-size: 0.9rem; color: var(--fg-soft); }
.continue { font-style: italic; }
.books { max-width: 64rem; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.book-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2rem; }
.book-card {
  display: grid; grid-template-columns: 9.5rem 1fr; gap: 1.5rem; align-items: start;
  background: var(--bg-raised); border: 1px solid var(--border); border-radius: 12px; padding: 1.25rem;
}
.book-card__cover img { display: block; width: 100%; border-radius: 4px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); }
.book-card__title { font-size: 1.45rem; margin: 0; }
.book-card__title a { color: var(--fg); text-decoration: none; }
.book-card__title a:hover { text-decoration: underline; }
.book-card__blurb { margin: 0 0 1rem; color: var(--fg); display: -webkit-box; -webkit-line-clamp: 6; line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.book-card__actions { margin: 0; }
@media (max-width: 36rem) {
  .book-card { grid-template-columns: 6rem 1fr; gap: 1rem; padding: 1rem; }
  .book-card__body { display: contents; }
  .book-card__body > .eyebrow, .book-card__title, .book-card__body > .book-meta { grid-column: 2; }
  .book-card__cover { grid-row: 1 / span 3; }
  .book-card__blurb, .book-card__actions { grid-column: 1 / -1; }
}

/* Book page */
.book-hero { max-width: 64rem; margin: 0 auto; padding: 2.5rem 1.25rem 1rem; display: grid; grid-template-columns: 15rem 1fr; gap: 2.5rem; align-items: start; }
.book-hero__cover { border-radius: 4px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3); width: 100%; }
.book-hero h1 { font-size: clamp(1.9rem, 4.5vw, 2.7rem); margin: 0 0 0.25rem; }
.byline { font-style: italic; color: var(--fg-soft); margin: 0; }
.blurb { font-size: 1.08rem; line-height: 1.7; max-width: 38em; }
.status-note { font-family: var(--sans); font-size: 0.88rem; color: var(--fg-soft); border-left: 3px solid var(--gold-bright); padding-left: 0.75rem; }
@media (max-width: 44rem) {
  .book-hero { grid-template-columns: 1fr; gap: 1.5rem; padding-top: 1.75rem; }
  .book-hero__cover { width: 11rem; margin: 0 auto; }
}
.toc { max-width: 44rem; margin: 0 auto; padding: 2rem 1.25rem 1rem; }
.toc__list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }
.toc__list li { border-bottom: 1px solid var(--border); }
.toc__list a { display: flex; align-items: baseline; gap: 0.9rem; padding: 0.8rem 0.25rem; text-decoration: none; color: var(--fg); }
.toc__list a:hover { background: var(--bg-raised); }
.toc__list a:hover .toc__title { text-decoration: underline; }
.toc__num { font-family: var(--sans); font-size: 0.85rem; color: var(--accent); min-width: 1.6rem; text-align: right; font-variant-numeric: tabular-nums; }
.toc__title { flex: 1; font-size: 1.08rem; }
.toc__words { font-family: var(--sans); font-size: 0.78rem; color: var(--fg-soft); white-space: nowrap; }
.toc__state { font-family: var(--sans); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); white-space: nowrap; }
.toc__list a.is-read .toc__title { color: var(--fg-soft); }
@media (max-width: 30rem) { .toc__words { display: none; } }
.source-note { max-width: 44rem; margin: 1.5rem auto 2.5rem; padding: 0 1.25rem; text-align: center; font-family: var(--sans); font-size: 0.82rem; color: var(--fg-soft); }

/* Reader */
.progress { position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 50; pointer-events: none; }
.progress__bar { height: 100%; background: var(--gold-bright); transform-origin: 0 50%; transform: scaleX(0); }
.reader { padding: 0 1.25rem; }
.reader article { max-width: var(--measure); margin: 0 auto; font-size: var(--reading-size); }
:root[data-font="sans"] .reader article { font-family: var(--sans); }
.chapter-head { text-align: center; padding: clamp(2rem, 6vw, 4rem) 0 0.5rem; }
.chapter-head .eyebrow { font-size: 0.72rem; }
.chapter-head__num { font-family: var(--sans); font-size: 0.85rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--fg-soft); margin: 1.25rem 0 0.5rem; }
.chapter-head__title { font-size: clamp(1.8rem, 5vw, 2.5rem); font-weight: 500; margin: 0 0 0.75rem; }
.chapter-head__meta { font-family: var(--sans); font-size: 0.8rem; color: var(--fg-soft); margin: 0; }
.prose { line-height: var(--leading); hyphens: auto; -webkit-hyphens: auto; text-wrap: pretty; }
.prose p { margin: 0; text-indent: 1.5em; }
.prose p:first-child, .prose .scene-break + p { text-indent: 0; }
.prose p:first-child::first-letter {
  font-family: var(--display); float: left; font-size: 3.4em; line-height: 0.85; padding: 0.06em 0.08em 0 0; color: var(--accent);
}
.prose .scene-break { text-indent: 0; text-align: center; color: var(--accent); margin: 1.2em 0; letter-spacing: 0.5em; }
.end-note { text-align: center; font-style: italic; color: var(--fg-soft); margin: 3rem 0 0; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.chapter-nav {
  max-width: 44rem; margin: 3rem auto 0; display: grid; grid-template-columns: 1fr auto 1fr; gap: 1rem; align-items: stretch;
  font-family: var(--sans);
}
.chapter-nav a { text-decoration: none; border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem 1rem; display: flex; flex-direction: column; gap: 0.2rem; color: var(--fg); background: var(--bg-raised); min-width: 0; }
.chapter-nav a:hover { border-color: var(--accent); }
.chapter-nav__next { text-align: right; }
.chapter-nav__toc { justify-content: center; align-self: center; color: var(--link) !important; }
.chapter-nav__dir { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); }
.chapter-nav__label { font-family: var(--serif); font-size: 0.98rem; }
@media (max-width: 36rem) {
  .chapter-nav { grid-template-columns: 1fr 1fr; }
  .chapter-nav__toc { grid-column: 1 / -1; grid-row: 2; text-align: center; }
}
.resume-toast {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); z-index: 60;
  display: flex; align-items: center; gap: 0.75rem; max-width: calc(100vw - 1.5rem);
  background: var(--forest); color: #f4ecd8; border: 1px solid var(--gold-bright); border-radius: 10px;
  padding: 0.6rem 0.6rem 0.6rem 1rem; font-family: var(--sans); font-size: 0.9rem; box-shadow: 0 10px 28px rgba(0, 0, 0, 0.3);
}
.resume-toast[hidden] { display: none; }
.resume-toast button { font: inherit; font-weight: 600; cursor: pointer; border-radius: 6px; min-height: 2.25rem; padding: 0.3rem 0.8rem; border: 1px solid var(--gold-bright); background: var(--gold-bright); color: #14201a; }
.resume-toast .resume-toast__close { background: transparent; color: #f4ecd8; border-color: transparent; font-size: 1.2rem; padding: 0.2rem 0.6rem; }

/* Plain pages */
.page { max-width: 42rem; margin: 0 auto; padding: 2.5rem 1.25rem 3rem; }
.page h1 { font-size: clamp(1.9rem, 5vw, 2.5rem); margin-top: 0; }
.page--center { text-align: center; padding-top: 5rem; }
.inventory { width: 100%; border-collapse: collapse; font-family: var(--sans); font-size: 0.88rem; margin: 1rem 0; display: block; overflow-x: auto; }
.inventory caption { text-align: left; color: var(--fg-soft); padding-bottom: 0.5rem; }
.inventory th, .inventory td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: top; }

/* Footer */
.site-footer { border-top: 1px solid var(--border); padding: 1.75rem 1.25rem 2.25rem; text-align: center; font-family: var(--sans); font-size: 0.82rem; color: var(--fg-soft); margin-top: 2rem; }
.site-footer p { max-width: 44rem; margin: 0.3rem auto; }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
@media print {
  .site-header, .site-footer, .chapter-nav, .progress, .resume-toast, .source-note { display: none; }
  body { background: #fff; color: #000; }
}
