/* Matches auto-reader.com tokens: Sepia Parchment (light) / Midnight Gold (dark). */
:root {
  --bg: #D9C8A2; --bg-elev: #EAE0C3; --bg-elev-2: #F3EBD6;
  --ink: #2B2115; --ink-dim: #5E4C35; --ink-faint: #8A7658;
  --accent: #8F5A24; --accent-hi: #A96D2E; --on-accent: #FBF2DF;
  --border: rgba(60,40,15,.12); --border-strong: rgba(60,40,15,.24);
  --shadow: rgba(70,45,15,.18); --topbar-bg: rgba(226,212,176,.84);
  --warn: #8a3b12;
  --paper: linear-gradient(90deg, rgba(85,55,15,.20), rgba(85,55,15,.06) 12%, transparent 26%, transparent 74%, rgba(85,55,15,.06) 88%, rgba(85,55,15,.20)), url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='720' height='360'%3E%3Cfilter id='f' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.008 0.30' numOctaves='2' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .33 0 0 0 0 .21 0 0 0 0 .06 0 0 0 .17 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E"), url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='900' height='900'%3E%3Cfilter id='f' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.0035' numOctaves='3' seed='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .33 0 0 0 0 .21 0 0 0 0 .06 0 0 0 .34 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E"), url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1100' height='1100'%3E%3Cfilter id='f' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.003' numOctaves='2' seed='11' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 .97 0 0 0 0 .88 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E"), url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='f' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' seed='1' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .33 0 0 0 0 .21 0 0 0 0 .06 0 0 0 .16 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");
  --serif: Georgia, "Times New Roman", "Noto Serif", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="sepia"]) {
    --bg: #0D0907; --bg-elev: #15100D; --bg-elev-2: #1F1813;
    --ink: #F5E6D3; --ink-dim: #BDA88E; --ink-faint: #7A6A57;
    --accent: #D4A574; --accent-hi: #E7C49C; --on-accent: #14100B;
    --border: rgba(245,230,211,.08); --border-strong: rgba(245,230,211,.18);
    --shadow: rgba(0,0,0,.45); --topbar-bg: rgba(13,9,7,.82); --warn: #f0a070;
    --paper: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #0D0907; --bg-elev: #15100D; --bg-elev-2: #1F1813;
    --ink: #F5E6D3; --ink-dim: #BDA88E; --ink-faint: #7A6A57;
    --accent: #D4A574; --accent-hi: #E7C49C; --on-accent: #14100B;
    --border: rgba(245,230,211,.08); --border-strong: rgba(245,230,211,.18);
    --shadow: rgba(0,0,0,.45); --topbar-bg: rgba(13,9,7,.82); --warn: #f0a070;
    --paper: none; color-scheme: dark;
}
/* The parchment texture lives on one fixed, GPU-composited layer instead of
   the scrolling body: the four noise tiles are rasterised once and never
   repainted on scroll (the body-background version repainted them on every
   scroll frame and made the sepia theme feel heavy). */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: var(--paper);
  transform: translateZ(0);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--sans); line-height: 1.5; overflow-x: hidden; }
a { color: var(--accent); }
a:hover { color: var(--accent-hi); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; inset-inline-start: 8px; top: 8px; transform: translateY(-200%); background: var(--accent); color: var(--on-accent); padding: 8px 12px; z-index: 10; }
.skip:focus { transform: none; }
.topbar { position: sticky; top: 0; z-index: 5; background: var(--topbar-bg); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.bar { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; color: var(--ink); text-decoration: none; }
.brand img { border-radius: 6px; }
.pill { font: inherit; background: var(--bg-elev); color: var(--ink); border: 1px solid var(--border-strong); border-radius: 999px; padding: 6px 14px; cursor: pointer; }
h1, h2 { font-family: var(--serif); font-weight: 300; letter-spacing: -.5px; }
.hero { padding: 32px 0 16px; }
.hero h1 { font-size: clamp(30px, 6vw, 48px); }
.hero p { color: var(--ink-dim); max-width: 640px; margin-top: 8px; }
.cta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.btn { display: inline-block; font: inherit; font-weight: 600; text-decoration: none; background: var(--accent); color: var(--on-accent); border: 1px solid var(--accent); border-radius: 999px; padding: 9px 18px; cursor: pointer; }
.btn:hover { background: var(--accent-hi); color: var(--on-accent); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { padding: 5px 12px; font-size: 13px; }
.controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; padding: 16px 0 8px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-dim); min-width: 0; flex: 1 1 140px; }
.field.grow { flex: 3 1 240px; }
.field input, .field select { font: inherit; font-size: 16px; color: var(--ink); background: var(--bg-elev-2); border: 1px solid var(--border-strong); border-radius: 10px; padding: 9px 12px; width: 100%; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--ink-dim); flex-basis: 100%; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.status { font-size: 14px; color: var(--ink-faint); min-height: 1.5em; margin-bottom: 8px; }
.grid { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
@media (max-width: 420px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; } }
.book { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 2px 10px var(--shadow); min-width: 0; }
.cover { aspect-ratio: 2 / 3; background: var(--bg-elev-2); position: relative; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 12px; text-align: center; background: linear-gradient(160deg, var(--accent), var(--ink-dim)); color: var(--on-accent); font-family: var(--serif); }
.ph b { font-size: 44px; line-height: 1; }
.ph span { font-size: 13px; margin-top: 8px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.info { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.info h3 { font-size: 15px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.author { font-size: 13px; color: var(--ink-dim); overflow-wrap: anywhere; }
.meta { font-size: 12px; color: var(--ink-faint); }
.dl { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.dl a { font-size: 12px; font-weight: 600; text-decoration: none; border: 1px solid var(--border-strong); border-radius: 6px; padding: 3px 8px; }
.dl a.pref { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.dl a.blocked { opacity: .75; border-style: dashed; }
.dl a.mirror::before { content: '⚡ '; }
.note { font-size: 11px; color: var(--warn); }
.src { font-size: 11px; color: var(--ink-faint); }
.open { margin-top: auto; padding-top: 8px; }
.more { text-align: center; padding: 20px 0; }
.credits { border-top: 1px solid var(--border); margin-top: 24px; padding: 24px 0; font-size: 14px; color: var(--ink-dim); }
.credits h2 { font-size: 24px; color: var(--ink); margin-bottom: 8px; }
.credits p + p { margin-top: 8px; }
footer { border-top: 1px solid var(--border); padding: 24px 0; font-size: 14px; }
.foot { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; }
.foot nav { display: flex; flex-wrap: wrap; gap: 16px; }
.foot nav a { color: var(--ink-dim); text-decoration: none; }
[dir="rtl"] body, [dir="rtl"] { font-family: var(--sans); }
@media (prefers-reduced-motion: no-preference) { .book { transition: transform .15s; } .book:hover { transform: translateY(-2px); } }

/* ---- Theme switch (Sepia Parchment default, Midnight Gold on request) ---- */
.themefab {
  display: inline-flex; align-items: center; padding: 3px; gap: 2px;
  background: var(--bg-elev); border: 1px solid var(--border-strong); border-radius: 50px;
  box-shadow: 0 2px 10px var(--shadow); flex: none;
}
.themefab button {
  border: 0; background: none; color: var(--ink-dim); cursor: pointer;
  font: 600 12.5px/1 var(--sans, system-ui, sans-serif); letter-spacing: 0.2px;
  padding: 7px 12px; border-radius: 50px; white-space: nowrap;
  transition: background 0.18s ease, color 0.18s ease;
}
.themefab button:hover { color: var(--ink); }
.themefab button.on { background: var(--accent); color: var(--on-accent); box-shadow: 0 1px 6px var(--shadow); }
.themefab button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.themefab button span { margin-inline-start: 5px; }
@media (max-width: 480px) { .themefab button span { display: none; } .themefab button { padding: 7px 10px; font-size: 14px; } }
.bar { gap: 12px; }
.bar .themefab { margin-inline-start: auto; }
