:root {
  --paper: #f7f0dd;
  --surface: #fffaf0;
  --surface-2: #efe3c8;
  --ink: #1d1710;
  --muted: #6b5d45;
  --gold: #a87c1f;
  --gold-bright: #e9c46a;
  --red: #9b2226;
  --border: #d8c9a3;
  --shadow: 0 10px 30px rgba(29, 23, 16, 0.14);
  --serif: "EB Garamond", Georgia, "Times New Roman", serif;
  --reader-size: 20px;
}
html[data-theme="dark"] {
  --paper: #171208;
  --surface: #241a0d;
  --surface-2: #2f2212;
  --ink: #f3e9d2;
  --muted: #c9b896;
  --gold: #e9c46a;
  --gold-bright: #e9c46a;
  --red: #e07a5f;
  --border: #4a3a20;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.55;
}
a { color: var(--gold); }
button, input, select, textarea { font-family: inherit; font-size: 1rem; }
h1, h2, h3 { line-height: 1.15; margin: 0 0 0.4em; }
.loading { text-align: center; color: var(--muted); padding: 3rem 1rem; font-style: italic; }

/* Header */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--surface); border-bottom: 2px solid var(--gold);
}
.brand { text-decoration: none; color: var(--ink); display: flex; flex-direction: column; }
.brand-tag {
  align-self: flex-start; background: var(--red); color: #f7f0dd;
  font-size: 0.62rem; letter-spacing: 0.28em; padding: 0.15rem 0.5rem; font-weight: 700;
}
.brand-name { font-size: 1.25rem; font-weight: 800; }
.brand-name em { color: var(--gold); font-style: italic; }
.topnav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; justify-content: flex-end; }
.topnav a { color: var(--ink); text-decoration: none; font-weight: 600; }
.topnav a:hover { color: var(--gold); }
.account-email { color: var(--muted); font-size: 0.9rem; }

.view { max-width: 1080px; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
.footer { text-align: center; padding: 2rem 1rem 3rem; color: var(--muted); border-top: 1px solid var(--border); }
.footer-brand { letter-spacing: 0.3em; font-size: 0.75rem; color: var(--gold); font-weight: 700; }

/* Buttons & chips */
.btn {
  display: inline-block; border: 1px solid var(--gold); background: var(--ink); color: var(--paper);
  padding: 0.55rem 1.1rem; border-radius: 4px; cursor: pointer; font-weight: 700; text-decoration: none;
}
.btn:hover { background: var(--gold); color: #1d1710; }
.btn.secondary { background: transparent; color: var(--ink); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.small { padding: 0.3rem 0.7rem; font-size: 0.9rem; }
.btn:disabled { opacity: 0.5; cursor: default; }
.chip {
  display: inline-block; font-size: 0.72rem; letter-spacing: 0.12em; font-weight: 700;
  padding: 0.18rem 0.55rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--muted); text-transform: uppercase;
}
.chip.owned { background: var(--gold); color: #1d1710; border-color: var(--gold); }
.chip.activating { background: var(--red); color: #f7f0dd; border-color: var(--red); }

/* Hero */
.hero {
  background: var(--ink); color: #f7f0dd; border-radius: 8px; padding: 1.6rem;
  margin-bottom: 1.4rem; box-shadow: var(--shadow);
}
html[data-theme="dark"] .hero { background: var(--surface-2); }
.hero h1 { font-size: 2rem; }
.hero .price { color: var(--gold-bright); font-weight: 800; }
.hero p { max-width: 46rem; }
.hero .actions { display: flex; gap: 0.7rem; flex-wrap: wrap; margin-top: 1rem; }
.hero .btn { background: var(--gold-bright); color: #1d1710; border-color: var(--gold-bright); }
.hero .btn.secondary { background: transparent; color: #f7f0dd; border-color: #f7f0dd; }

.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.8rem; margin: 1rem 0; }
.step { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.9rem; }
.step b { color: var(--red); letter-spacing: 0.1em; font-size: 0.75rem; text-transform: uppercase; }
@media (max-width: 640px) { .steps { grid-template-columns: 1fr; } }

/* Library grid */
.section-title { font-size: 1.5rem; margin-top: 1.6rem; }
.section-sub { color: var(--muted); margin-top: -0.3rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 1.1rem; margin-top: 1rem; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.card .cover { aspect-ratio: 2 / 3; width: 100%; object-fit: cover; display: block; background: var(--surface-2); }
.card .body { padding: 0.8rem; display: flex; flex-direction: column; gap: 0.45rem; flex: 1; }
.card h3 { font-size: 1.08rem; margin: 0; }
.card .subtitle { color: var(--muted); font-style: italic; font-size: 0.92rem; margin: 0; }
.card .actions { margin-top: auto; display: flex; gap: 0.45rem; flex-wrap: wrap; }
.progress-track { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--gold); }
.progress-label { font-size: 0.8rem; color: var(--muted); }

.bible-card {
  margin-top: 1.6rem; border: 2px solid var(--gold); border-radius: 8px; padding: 1.2rem;
  background: var(--surface); display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
}

/* Book page */
.book-head { display: grid; grid-template-columns: 220px 1fr; gap: 1.4rem; }
.book-head .cover { width: 100%; border-radius: 6px; box-shadow: var(--shadow); }
@media (max-width: 640px) { .book-head { grid-template-columns: 140px 1fr; } }
.record-line { color: var(--muted); font-size: 0.95rem; }
.notice {
  background: var(--surface-2); border-left: 4px solid var(--red); padding: 0.8rem 1rem;
  border-radius: 4px; margin: 1rem 0;
}
.notice.gold { border-left-color: var(--gold); }
.sample-box, .chapter-list-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1.2rem; margin-top: 1.2rem;
}
.sample-box p, .reader-text p { margin: 0 0 1em; }
.chapter-list { list-style: none; margin: 0; padding: 0; }
.chapter-list li { border-bottom: 1px solid var(--border); }
.chapter-list button {
  width: 100%; text-align: left; background: none; border: none; padding: 0.6rem 0.2rem;
  color: var(--ink); cursor: pointer; font-size: 1rem;
}
.chapter-list button:hover { color: var(--gold); }
.chapter-list .current { font-weight: 800; color: var(--gold); }

/* Reader */
.reader-bar {
  position: sticky; top: 57px; z-index: 15; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 0.55rem 0.8rem;
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
}
.reader-bar .where { font-weight: 700; margin-right: auto; }
.reader-progress { position: sticky; top: 57px; height: 5px; background: var(--surface-2); border-radius: 99px; margin: 0.5rem 0 1rem; overflow: hidden; z-index: 14; }
.reader-progress .fill { height: 100%; background: var(--red); width: 0%; transition: width 0.2s; }
.reader-text { max-width: 42rem; margin: 0 auto; font-size: var(--reader-size); line-height: 1.75; }
.reader-text h2 { font-size: 1.6em; text-align: center; margin: 1.2em 0 1em; }
.reader-nav { display: flex; justify-content: space-between; gap: 1rem; max-width: 42rem; margin: 2rem auto 0; }
.icon-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  border-radius: 4px; padding: 0.3rem 0.6rem; cursor: pointer; font-weight: 700;
}
.icon-btn:hover { border-color: var(--gold); }

/* Forms */
.form-card { max-width: 30rem; margin: 0 auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1.4rem; box-shadow: var(--shadow); }
.form-card label { display: block; font-weight: 700; margin: 0.9rem 0 0.3rem; }
.form-card input, .form-card select, .form-card textarea {
  width: 100%; padding: 0.6rem; border: 1px solid var(--border); border-radius: 4px;
  background: var(--paper); color: var(--ink);
}
.form-card .btn { width: 100%; margin-top: 1.1rem; text-align: center; }
.form-error { color: var(--red); font-weight: 700; margin-top: 0.8rem; }
.form-note { color: var(--muted); font-size: 0.92rem; }
.return-code {
  font-size: 2.2rem; letter-spacing: 0.35em; text-align: center; font-weight: 800;
  background: var(--surface-2); border: 2px dashed var(--gold); border-radius: 8px; padding: 0.8rem; margin: 1rem 0;
}

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%);
  background: var(--ink); color: #f7f0dd; padding: 0.7rem 1.2rem; border-radius: 6px;
  box-shadow: var(--shadow); z-index: 50; max-width: 92vw; text-align: center;
}

/* Admin */
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
.admin-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; }
.admin-card textarea, .admin-card input, .admin-card select {
  width: 100%; padding: 0.5rem; border: 1px solid var(--border); border-radius: 4px; background: var(--paper); color: var(--ink); margin: 0.3rem 0 0.7rem;
}
.admin-card textarea { min-height: 7rem; }
.gate-row { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; padding: 0.45rem 0; border-bottom: 1px solid var(--border); }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 0.85rem; white-space: pre-wrap; word-break: break-word; }
