/* ---------- themes ---------- */
:root {
  --serif-display: "Fraunces", Georgia, serif;
  --serif-read: "Literata", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --read-size: 1.15rem;
  --read-face: var(--serif-read);
  --measure: 38rem;
  --radius: 10px;
}
[data-theme="paper"] {
  --bg: #f3ede2; --bg-2: #ebe3d4; --card: #faf6ee; --ink: #221d17; --ink-2: #5e554a;
  --line: #d9cfbe; --accent: #8c2f2b; --accent-ink: #fff8f0;
}
[data-theme="sepia"] {
  --bg: #efe0c4; --bg-2: #e5d2b0; --card: #f6ead3; --ink: #3a2a18; --ink-2: #6e5638;
  --line: #d4bd95; --accent: #7a3b16; --accent-ink: #fff4e3;
}
[data-theme="night"] {
  --bg: #15130f; --bg-2: #1d1a15; --card: #211e18; --ink: #e9e1d3; --ink-2: #a39888;
  --line: #3a342b; --accent: #d9776c; --accent-ink: #1a0f0d;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); color: var(--ink); }
body { margin: 0; font-family: var(--sans); line-height: 1.5; min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; width: 100%; max-width: 72rem; margin: 0 auto; padding: 0 1.25rem 4rem; }
a { color: inherit; }
img { max-width: 100%; }
code { background: var(--bg-2); padding: .1em .35em; border-radius: 4px; }

/* ---------- header / footer ---------- */
.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  max-width: 72rem; width: 100%; margin: 0 auto; padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--serif-display); font-weight: 800; font-size: 1.25rem; text-decoration: none; letter-spacing: -.01em; }
.site-header nav { display: flex; gap: 1.25rem; flex-wrap: wrap; }
.site-header nav a { text-decoration: none; color: var(--ink-2); font-size: .95rem; }
.site-header nav a:hover { color: var(--accent); }
.site-footer {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
  max-width: 72rem; width: 100%; margin: 0 auto; padding: 1.5rem 1.25rem; color: var(--ink-2);
  font-size: .85rem; border-top: 1px solid var(--line);
}
.site-footer p { margin: 0; }

/* ---------- shared bits ---------- */
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: .72rem; color: var(--accent); margin: 0 0 .4rem; font-weight: 600; }
.eyebrow a { text-decoration: none; }
.meta { color: var(--ink-2); font-size: .85rem; margin: .25rem 0; }
.status { text-transform: capitalize; color: var(--accent); }
.tags { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.tag {
  font-size: .75rem; text-decoration: none; padding: .2rem .6rem; border-radius: 999px;
  background: var(--bg-2); color: var(--ink-2); border: 1px solid var(--line);
}
.tag:hover { border-color: var(--accent); color: var(--accent); }
.btn, .reader-tools button, .theme-toggle, .chip {
  font: inherit; cursor: pointer; border-radius: var(--radius);
}
.btn {
  display: inline-block; padding: .6rem 1.1rem; background: var(--accent); color: var(--accent-ink);
  border: 1px solid var(--accent); text-decoration: none; font-weight: 600; font-size: .95rem;
}
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle { background: none; border: 1px solid var(--line); color: var(--ink-2); padding: .35rem .7rem; }

/* ---------- library ---------- */
.hero { padding: 3.5rem 0 2rem; }
.hero h1 { font-family: var(--serif-display); font-size: clamp(2.6rem, 7vw, 4.6rem); line-height: 1; margin: 0; letter-spacing: -.03em; font-weight: 800; }
.tagline { font-family: var(--serif-read); font-style: italic; color: var(--ink-2); font-size: 1.2rem; max-width: 36rem; margin: .9rem 0 0; }
.controls { display: flex; gap: .75rem; margin: 1rem 0 .75rem; }
.controls input, .controls select {
  font: inherit; padding: .65rem .9rem; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--card); color: var(--ink);
}
.controls input { flex: 1; }
.tag-filter { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { font-size: .8rem; padding: .3rem .75rem; border: 1px solid var(--line); background: transparent; color: var(--ink-2); border-radius: 999px; }
.chip.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.result-count { color: var(--ink-2); font-size: .85rem; margin: 1.25rem 0 .75rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 30rem), 1fr)); gap: 1.25rem; }
.card {
  display: grid; grid-template-columns: 8.5rem 1fr; gap: 1.1rem; padding: 1rem;
  background: var(--card); border: 1px solid var(--line); border-radius: calc(var(--radius) + 4px);
}
.card[hidden] { display: none; }
.card h2 { font-family: var(--serif-display); font-size: 1.35rem; margin: 0; line-height: 1.15; letter-spacing: -.01em; }
.card h2 a { text-decoration: none; }
.card h2 a:hover { color: var(--accent); }
.synopsis { font-family: var(--serif-read); font-size: .95rem; margin: .5rem 0 0; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.synopsis.big { font-size: 1.1rem; -webkit-line-clamp: unset; display: block; }

/* covers */
.cover { width: 100%; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 6px; display: block; box-shadow: 0 6px 18px rgb(0 0 0 / .18); }
.cover-type {
  display: flex; flex-direction: column; justify-content: space-between; padding: .8rem .7rem;
  background: linear-gradient(160deg, hsl(var(--hue) 35% 30%), hsl(calc(var(--hue) + 40) 40% 16%));
  color: #f6efe2; text-align: center;
}
.ct-series { font-size: .55rem; letter-spacing: .14em; text-transform: uppercase; opacity: .8; }
.ct-title { font-family: var(--serif-display); font-weight: 800; font-size: 1.05rem; line-height: 1.1; }
.ct-author { font-size: .6rem; letter-spacing: .1em; text-transform: uppercase; opacity: .8; }
.cover.big .ct-title { font-size: 1.8rem; }
.cover.big .ct-series, .cover.big .ct-author { font-size: .75rem; }

/* ---------- story page ---------- */
.story-head { display: grid; grid-template-columns: 16rem 1fr; gap: 2.5rem; padding: 3rem 0 2rem; }
.story-head h1 { font-family: var(--serif-display); font-size: clamp(2.2rem, 5vw, 3.4rem); margin: 0; line-height: 1.02; letter-spacing: -.02em; }
.byline { font-family: var(--serif-read); font-style: italic; color: var(--ink-2); margin: .5rem 0; font-size: 1.1rem; }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.5rem; }
.intro { margin-top: 1rem; }
.toc { max-width: 46rem; }
.toc h2 { font-family: var(--serif-display); font-size: 1.4rem; border-bottom: 1px solid var(--line); padding-bottom: .5rem; }
.toc ol { list-style: none; padding: 0; margin: 0; }
.toc a { display: grid; grid-template-columns: 2.5rem 1fr auto; gap: .5rem; padding: .7rem .25rem; text-decoration: none; border-bottom: 1px dashed var(--line); }
.toc a:hover .toc-title { color: var(--accent); }
.toc-num { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.toc-title { font-family: var(--serif-read); }
.toc-words { color: var(--ink-2); font-size: .8rem; }
.toc a.read .toc-num::after { content: " ✓"; color: var(--accent); }

/* ---------- reader ---------- */
.progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 20; }
#progress-bar { height: 100%; width: 0; background: var(--accent); }
.reader-tools {
  position: fixed; right: 1rem; bottom: 1rem; display: flex; gap: .3rem; z-index: 15;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: .3rem;
  box-shadow: 0 6px 20px rgb(0 0 0 / .15);
}
.reader-tools button { background: none; border: none; color: var(--ink); padding: .4rem .65rem; border-radius: 999px; font-size: .85rem; }
.reader-tools button:hover { background: var(--bg-2); }
.chapter { max-width: var(--measure); margin: 0 auto; }
.chapter-head { text-align: center; padding: 3.5rem 0 1.5rem; }
.chapter-head h1 { font-family: var(--serif-display); font-size: clamp(2rem, 5vw, 2.8rem); margin: .2rem 0; letter-spacing: -.02em; line-height: 1.1; }
.prose { font-family: var(--read-face); font-size: var(--read-size); line-height: 1.75; }
.chapter .prose p { margin: 0 0 1.1em; }
.prose hr { border: none; text-align: center; margin: 2em 0; }
.prose hr::after { content: "⁂"; color: var(--ink-2); letter-spacing: .5em; }
.prose blockquote { margin: 1.2em 0; padding-left: 1em; border-left: 3px solid var(--line); color: var(--ink-2); }
.pager { max-width: var(--measure); margin: 3rem auto 0; display: grid; grid-template-columns: 1fr auto 1fr; gap: .6rem; align-items: center; }
.pager a:first-child { justify-self: start; }
.pager a:last-child { justify-self: end; }
.pager .btn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.page { max-width: var(--measure); margin: 3rem auto; }
.page h1 { font-family: var(--serif-display); }

/* ---------- age gate ---------- */
.age-gate { position: fixed; inset: 0; z-index: 100; background: rgb(10 8 6 / .88); backdrop-filter: blur(8px); display: grid; place-items: center; padding: 1rem; }
.age-gate[hidden] { display: none; }
.age-card { max-width: 26rem; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 2rem; text-align: center; }
.age-card h2 { font-family: var(--serif-display); font-size: 2rem; margin: 0 0 .5rem; }
.age-card p { color: var(--ink-2); }
.age-actions { display: flex; justify-content: center; gap: .6rem; margin-top: 1.25rem; }

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  .card { grid-template-columns: 6rem 1fr; gap: .85rem; }
  .story-head { grid-template-columns: 1fr; gap: 1.5rem; padding-top: 2rem; }
  .story-cover { max-width: 12rem; }
  .controls { flex-direction: column; }
  .pager { grid-template-columns: 1fr 1fr; }
  .pager a:nth-child(2) { display: none; }
  .site-header { flex-direction: column; align-items: flex-start; gap: .4rem; }
}
