/* ===== Design tokens ===== */
:root {
  --bg: #F6F4EE;
  --bg-raised: #FFFFFF;
  --ink: #2B2A24;
  --ink-soft: #5B5849;
  --ink-faint: #8B8878;
  --rule: #DEDACB;
  --accent: #A97C3F;       /* warm brown/gold, matching the title color family */
  --accent-ink: #FFFFFF;
  --accent-soft: #F1E4CC;
  --gold: #A98150;         /* muted ochre for subtitles/highlights */
  --footnote: #8B5E3C;     /* rust for footnote markers */
  --link: var(--accent);
  --shadow: 0 1px 2px rgba(43,42,36,0.06), 0 4px 16px rgba(43,42,36,0.06);
  --radius: 6px;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --reading-size: 1.125rem;
  --topbar-h: 60px;
}

[data-theme="dark"] {
  --bg: #1C1B17;
  --bg-raised: #24231D;
  --ink: #EDEAE0;
  --ink-soft: #B9B5A4;
  --ink-faint: #837E6C;
  --rule: #3A3830;
  --accent: #D3A96A;
  --accent-ink: #1C1B17;
  --accent-soft: #4A3B22;
  --gold: #D3A96A;
  --footnote: #D08A5F;
  --link: var(--accent);
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--rule);
  height: var(--topbar-h);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1rem;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--ink);
  flex-shrink: 0;
}
.brand-mark {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.65rem;
  letter-spacing: 0.02em;
}
.brand-full {
  font-size: 0.9rem;
  color: var(--ink-faint);
  display: none;
}
@media (min-width: 720px) {
  .brand-full { display: inline; }
}

.main-nav {
  display: flex;
  gap: 0.25rem;
  flex: 1;
  overflow-x: auto;
}
.main-nav a {
  text-decoration: none;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  white-space: nowrap;
}
.main-nav a:hover { color: var(--ink); background: var(--accent-soft); }
.main-nav a.active { color: var(--accent-ink); background: var(--accent); }

.topbar-tools {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}
.icon-btn {
  border: 1px solid var(--rule);
  background: var(--bg-raised);
  color: var(--ink-soft);
  border-radius: var(--radius);
  padding: 0.4rem 0.55rem;
  font-size: 0.85rem;
  cursor: pointer;
  line-height: 1;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--ink); }
.nav-toggle { display: none; }
@media (max-width: 860px) {
  .nav-toggle { display: inline-block; }
}

/* ===== App shell / sidebar ===== */
.app-shell {
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
}
.sidebar {
  width: 260px;
  flex-shrink: 0;
  border-right: 1px solid var(--rule);
  height: calc(100vh - var(--topbar-h));
  position: sticky;
  top: var(--topbar-h);
  overflow-y: auto;
  padding: 1rem;
  display: none;
}
.sidebar.open { display: block; }
@media (min-width: 860px) {
  .sidebar { display: block; }
}
/* On narrow screens the sidebar must overlay the content, not sit
   beside it as a flex sibling - otherwise opening it would squeeze
   the reading column down to an unusable sliver. */
@media (max-width: 859px) {
  .sidebar.open {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: calc(100vh - var(--topbar-h));
    z-index: 50;
    background: var(--bg);
    box-shadow: var(--shadow);
  }
}
.sidebar-search input {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}
.book-group-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  margin: 1rem 0 0.35rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--rule);
}
.book-group-title:first-child { border-top: none; margin-top: 0; }
.book-link {
  display: block;
  padding: 0.3rem 0.4rem;
  border-radius: var(--radius);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.88rem;
}
.book-link:hover { background: var(--accent-soft); color: var(--ink); }
.book-link.active { background: var(--accent); color: var(--accent-ink); }

.main-content {
  flex: 1;
  min-width: 0;
  padding: 2rem 1.25rem 4rem;
}
@media (min-width: 860px) {
  .main-content { padding: 2.5rem 3rem 5rem; }
}

/* ===== Reading content ===== */
.page-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.8rem;
  margin: 0 0 0.25rem;
}
.page-sub {
  color: var(--ink-faint);
  font-size: 0.9rem;
  margin-bottom: 2rem;
}

.reader {
  max-width: 680px;
}
.chapter-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.chapter-nav select {
  font-family: var(--sans);
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--rule);
  background: var(--bg-raised);
  color: var(--ink);
}

.chapter-title {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
}
.reader-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
@media (max-width: 480px) {
  .reader-actions .btn-outline { padding: 0.5rem 0.7rem; font-size: 0.78rem; }
}

.verse-block {
  font-family: var(--serif);
  font-size: var(--reading-size);
  line-height: 1.75;
  color: var(--ink);
  margin-bottom: 0;
  position: relative;
}
.verse-subtitle {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  color: var(--gold);
  text-transform: uppercase;
  margin: 1.75rem 0 0.5rem;
}
.verse-subtitle:first-child { margin-top: 0; }
.verse-num {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 0.7rem;
  color: var(--accent);
  vertical-align: super;
  margin-right: 0.15em;
  cursor: default;
}
.footnote-marker {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 0.7rem;
  color: var(--footnote);
  vertical-align: super;
  cursor: pointer;
  padding: 0 0.1em;
  border-bottom: 1px dotted var(--footnote);
}
.crossref-link {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
}
.crossref-link:hover { border-bottom-color: var(--accent); }

.crossref-popover { max-width: 320px; }
.crossref-popover-title {
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-faint);
  margin-bottom: 0.6rem;
}
.crossref-pill-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.crossref-pill {
  display: inline-block;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.crossref-pill:hover { background: var(--accent); color: var(--accent-ink); }
.verse-text.highlighted { background: var(--accent-soft); border-radius: 3px; }
.verse-text.hl-yellow { background: #F5E38C; }
.verse-text.hl-green { background: #BEE3C4; }
.verse-text.hl-blue { background: #BFD8EA; }
.verse-text.hl-pink { background: #F2C9D8; }
[data-theme="dark"] .verse-text.hl-yellow { background: #6B5E2A; }
[data-theme="dark"] .verse-text.hl-green { background: #2E4A34; }
[data-theme="dark"] .verse-text.hl-blue { background: #2A4258; }
[data-theme="dark"] .verse-text.hl-pink { background: #4A2E3C; }
.verse-text.bookmarked { box-shadow: inset 3px 0 0 var(--accent); padding-left: 0.5rem; }

.hl-popover { max-width: 200px; }
.hl-picker-grid {
  display: flex;
  gap: 0.4rem;
}
.hl-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.15);
  cursor: pointer;
  padding: 0;
}
.hl-swatch-yellow { background: #F5E38C; }
.hl-swatch-green { background: #BEE3C4; }
.hl-swatch-blue { background: #BFD8EA; }
.hl-swatch-pink { background: #F2C9D8; }
.hl-swatch-none { background: var(--bg); color: var(--ink-faint); font-size: 0.7rem; }

.verse-toolbar {
  position: absolute;
  right: 0;
  top: 0;
  left: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.3rem;
  max-width: min(320px, 90vw);
  z-index: 5;
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.3rem;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}
/* Floats at the SAME vertical position as the verse's own text (not
   below it) so the mouse never has to travel down through empty space
   to reach it - moving down from the text used to cross straight into
   the next verse-block's hover area, "jumping" to the wrong verse
   before the toolbar could be reached. */
/* Taking the toolbar fully out of flow (position: absolute) means it
   can NEVER affect the verse-block's own height - previously, even
   while invisible, it still occupied layout space and could wrap onto
   its own line depending on how much room was left after that verse's
   text, making some verses taller than others for no visible reason.
   Desktop: reveal on hover/focus. Touch: reveal via tap (see app.js),
   since there's no hover state to rely on. */
@media (hover: hover) and (pointer: fine) {
  .verse-block:hover .verse-toolbar,
  .verse-block:focus-within .verse-toolbar { opacity: 1; pointer-events: auto; }
}
.verse-block.toolbar-open .verse-toolbar { opacity: 1; pointer-events: auto; }
.verse-toolbar button {
  font-family: var(--sans);
  font-size: 0.7rem;
  border: 1px solid var(--rule);
  background: var(--bg-raised);
  color: var(--ink-faint);
  border-radius: 4px;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  min-height: 28px;
  flex-shrink: 0;
}
.verse-toolbar button:hover { color: var(--ink); border-color: var(--accent); }

.footnote-popover {
  position: fixed;
  max-width: 320px;
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.75rem 0.9rem;
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink-soft);
  z-index: 60;
  line-height: 1.5;
}

/* ===== Buttons ===== */
.btn {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.85rem;
  border: none;
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.btn:hover { filter: brightness(1.08); }
.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

/* ===== Book grid (Ekstras / landing) ===== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}
.card {
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  text-decoration: none;
  color: var(--ink);
  display: block;
}
.card:hover { border-color: var(--accent); }
.card-title { font-family: var(--serif); font-weight: 600; font-size: 1.05rem; margin: 0 0 0.3rem; }
.card-desc { font-size: 0.82rem; color: var(--ink-faint); margin: 0; }

/* ===== Writings (Deel 3) ===== */
.writing-body { max-width: 680px; font-family: var(--serif); font-size: var(--reading-size); line-height: 1.75; }
.writing-body h2 { font-family: var(--sans); font-size: 1rem; font-weight: 700; margin: 2rem 0 0.75rem; color: var(--accent); }
.writing-body h3 { font-family: var(--sans); font-size: 0.9rem; font-weight: 600; margin: 1.5rem 0 0.5rem; color: var(--ink-soft); }
.writing-body p { margin: 0 0 1rem; }
.writing-body blockquote {
  margin: 1rem 0;
  padding: 0.25rem 1rem;
  border-left: 3px solid var(--gold);
  color: var(--ink-soft);
  font-style: italic;
}

/* ===== Search ===== */
.search-box { max-width: 480px; display: flex; gap: 0.5rem; margin-bottom: 1.5rem; }
.search-box input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.95rem;
}
.search-result {
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--rule);
}
.search-result-ref { font-family: var(--sans); font-weight: 600; font-size: 0.82rem; color: var(--accent); }
.search-result-text { font-family: var(--serif); margin-top: 0.2rem; }
.search-result mark { background: var(--gold); color: #fff; border-radius: 2px; padding: 0 0.1em; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 0.85rem;
  z-index: 80;
}

/* ===== Voorwoord title page ===== */
.titlepage-box {
  max-width: 680px;
  text-align: center;
  padding: 2.5rem 1.5rem;
  margin-bottom: 2.5rem;
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.titlepage-box p {
  font-family: var(--serif);
  color: var(--ink-soft);
  margin: 0.15rem 0;
}
.titlepage-heading {
  font-family: var(--sans);
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--accent);
  margin: 1.5rem 0 0.4rem;
  font-size: 0.95rem;
}
.titlepage-heading:first-child { margin-top: 0; }

/* ===== Chapter grid picker ===== */
.chapter-picker-group {
  font-family: var(--sans);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
  margin: 2rem 0 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
}
.chapter-picker-group:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.chapter-picker-book { margin-bottom: 1.5rem; }
.chapter-picker-book h3 {
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 0.5rem;
}
.chapter-picker-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.chapter-picker-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 0.4rem;
  border-radius: var(--radius);
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  text-decoration: none;
  font-family: var(--sans);
  font-size: 0.85rem;
}
.chapter-picker-btn:hover { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ===== Woordelys ===== */
.woordelys-index {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 1rem 0 2rem;
  position: sticky;
  top: calc(var(--topbar-h) + 0.5rem);
  background: var(--bg);
  padding: 0.5rem 0;
  z-index: 10;
}
.woordelys-index a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  text-decoration: none;
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 600;
}
.woordelys-index a:hover { background: var(--accent-soft); color: var(--ink); }
.woordelys-letter {
  font-family: var(--serif);
  font-size: 1.6rem;
  color: var(--accent);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.3rem;
  margin: 2.5rem 0 1rem;
  scroll-margin-top: calc(var(--topbar-h) + 3.5rem);
}
.woordelys-term { max-width: 680px; margin-bottom: 1.25rem; }
.woordelys-term-name {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
  margin-bottom: 0.3rem;
}
.woordelys-lines { font-family: var(--serif); font-size: 0.95rem; line-height: 1.6; color: var(--ink-soft); }
.woordelys-line { margin-bottom: 0.15rem; }
.text-faint { color: var(--ink-faint); }
.mt-2 { margin-top: 1.5rem; }
.book-desc-box {
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  font-size: 0.88rem;
  color: var(--ink-soft);
  margin-bottom: 1.5rem;
  max-width: 680px;
}
.book-intro-box {
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--ink-soft);
  margin-bottom: 1.75rem;
  max-width: 680px;
}
.book-intro-box p { margin: 0 0 0.75rem; }
.book-intro-box p:last-child { margin-bottom: 0; }
