:root {
  --bg: #140e0c;
  --bg-elev: #1d1613;
  --bg-card: #241c18;
  --bg-soft: #2c221d;
  --wine: #6b1d2a;
  --wine-bright: #8a2838;
  --gold: #c9a227;
  --gold-soft: #e0c36a;
  --cream: #f4ead5;
  --muted: #b8aa94;
  --line: rgba(201, 162, 39, 0.22);
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --nav-h: 64px;
  --tab-h: 68px;
  --max: 1180px;
  --font: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --ui: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--ui);
  background: radial-gradient(1200px 700px at 10% -10%, #2a1614 0%, var(--bg) 55%);
  color: var(--cream);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--gold-soft); text-decoration: none; }
button, input, select, textarea { font: inherit; }

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Top bar — desktop / tablet */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 28px;
  background: rgba(20, 14, 12, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.brand img {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--line);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong {
  font-family: var(--font);
  letter-spacing: 0.14em;
  font-size: 15px;
}
.brand-text span {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.desk-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}
.desk-nav button {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
}
.desk-nav button:hover { color: var(--cream); background: var(--bg-soft); }
.desk-nav button.active {
  color: var(--bg);
  background: var(--gold);
  font-weight: 600;
}

.top-actions { display: flex; align-items: center; gap: 8px; }
.pill {
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--cream);
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 13px;
}
.pill:hover { border-color: var(--gold); }
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #3ecf6a; display: inline-block; margin-right: 6px;
}
.status-dot.off { background: #c45c4a; }

/* Layout */
.main {
  flex: 1;
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 28px 28px 40px;
}
.view { display: none; }
.view.active { display: block; animation: fade .28s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

h1, h2, h3 { font-family: var(--font); font-weight: 600; margin: 0 0 10px; }
h1 { font-size: 34px; letter-spacing: 0.02em; }
h2 { font-size: 24px; }
.lede { color: var(--muted); max-width: 62ch; margin-bottom: 24px; }

.grid-2 {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.card {
  background: linear-gradient(180deg, var(--bg-card), var(--bg-elev));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card h3 { font-size: 18px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; }
.card.action { cursor: pointer; transition: transform .15s ease, border-color .15s; }
.card.action:hover { transform: translateY(-2px); border-color: var(--gold); }

.verse {
  background:
    linear-gradient(180deg, rgba(107,29,42,.35), rgba(20,14,12,.2)),
    var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px;
}
.verse blockquote {
  font-family: var(--font);
  font-size: 22px;
  line-height: 1.45;
  margin: 0 0 14px;
}
.verse cite { color: var(--gold-soft); font-style: normal; font-size: 13px; letter-spacing: .08em; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--gold);
  color: #1a140c;
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 650;
  cursor: pointer;
}
.btn.ghost {
  background: transparent;
  color: var(--cream);
  border: 1px solid var(--line);
}
.btn:hover { filter: brightness(1.06); }
.row { display: flex; gap: 10px; flex-wrap: wrap; }

/* Reader */
.reader-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  align-items: start;
}
.side-panel, .reader, .library-list {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.side-panel { padding: 16px; position: sticky; top: calc(var(--nav-h) + 16px); }
.side-panel h3 { font-size: 14px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.search {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--cream);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 8px 0 14px;
}
.book-list { max-height: 58vh; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.book-btn, .lib-item {
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--cream);
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.book-btn:hover, .lib-item:hover { background: var(--bg-soft); }
.book-btn.active, .lib-item.active { background: var(--wine); }

.reader { padding: 28px 32px 40px; min-height: 70vh; }
.reader .meta { color: var(--gold-soft); font-size: 13px; letter-spacing: .1em; text-transform: uppercase; margin-bottom: 8px; }
.scripture p {
  font-family: var(--font);
  font-size: 19px;
  line-height: 1.7;
  margin: 0 0 12px;
}
.scripture .v { color: var(--gold); font-size: 12px; padding-right: 6px; vertical-align: super; }

.chapter-nav { display: flex; gap: 8px; margin-top: 22px; }

/* Prayer */
.prayer-grid {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 20px;
}
.prayer-body {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
}
.prayer-body p { font-family: var(--font); font-size: 18px; line-height: 1.7; }

/* Support */
.give-hero {
  display: grid;
  grid-template-columns: 1.2fr .8fr;
  gap: 20px;
}

/* Bottom tabs — mobile */
.tabbar {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: var(--tab-h);
  background: rgba(20,14,12,.94);
  border-top: 1px solid var(--line);
  z-index: 50;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabbar button {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  cursor: pointer;
}
.tabbar button.active { color: var(--gold-soft); }
.tabbar svg { width: 20px; height: 20px; }

.offline-banner {
  display: none;
  background: #3a1c16;
  color: var(--gold-soft);
  text-align: center;
  padding: 8px;
  font-size: 13px;
}
.offline-banner.show { display: block; }

/* Tablet */
@media (max-width: 1024px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-2, .give-hero { grid-template-columns: 1fr; }
  .reader-layout, .prayer-grid { grid-template-columns: 1fr; }
  .side-panel { position: static; }
  .main { padding: 20px 18px 36px; }
}

/* Phone */
@media (max-width: 768px) {
  .desk-nav { display: none; }
  .top-actions .hide-sm { display: none; }
  .tabbar { display: flex; }
  .main { padding: 16px 14px calc(var(--tab-h) + 20px); }
  h1 { font-size: 26px; }
  .cards, .grid-3 { grid-template-columns: 1fr; }
  .verse blockquote { font-size: 18px; }
  .reader { padding: 18px 16px 28px; }
  .topbar { padding: 0 14px; }
}

@media (min-width: 1440px) {
  :root { --max: 1320px; }
  .scripture p { font-size: 20px; }
}

.muted { color: var(--muted); font-size: 12px; font-weight: 500; }
.chapter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 16px;
}
.chip {
  min-width: 34px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--cream);
  cursor: pointer;
}
.chip:hover { border-color: var(--gold); }
.chip.active { background: var(--gold); color: #1a140c; font-weight: 700; }
.lib-cat { margin: 18px 0 28px; }
.lib-cat > h3 { font-size: 15px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 12px; }
.lib-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
blockquote.mini {
  font-family: var(--font);
  font-size: 15px;
  margin: 8px 0 0;
  color: var(--cream);
}
blockquote.mini cite { display: block; color: var(--gold-soft); font-style: normal; font-size: 12px; margin-top: 6px; letter-spacing: .06em; }
@media (max-width: 1024px) {
  .lib-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
  .lib-grid { grid-template-columns: 1fr; }
  .book-list { max-height: 240px; }
}


/* Listen headphones control */
.reader, .prayer-body { position: relative; }
.reader-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}
.reader-top .reader-meta,
.reader-top #prayer-title { flex: 1; min-width: 0; }
.listen-icon {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(212, 175, 55, 0.45);
  background: rgba(212, 175, 55, 0.12);
  color: #e8c547;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
}
.listen-icon:hover {
  background: rgba(212, 175, 55, 0.28);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.15);
}
.listen-icon:active { transform: scale(0.96); }
.listen-icon.stop-btn {
  border-color: rgba(220, 80, 80, 0.5);
  background: rgba(220, 80, 80, 0.15);
  color: #f0a0a0;
}
.listen-icon.speaking {
  animation: listen-pulse 1.4s ease-in-out infinite;
}
@keyframes listen-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(212, 175, 55, 0.35); }
  50% { box-shadow: 0 0 0 8px rgba(212, 175, 55, 0); }
}


/* ---- Themes + e-ink ---- */
.theme-row { display: flex; flex-wrap: wrap; gap: 8px; }
.theme-btn {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid rgba(232, 196, 120, 0.4);
  background: transparent;
  color: var(--text, #f3e8d3);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.theme-btn.active {
  background: rgba(107, 29, 42, 0.85);
  border-color: rgba(240, 217, 160, 0.75);
  color: #f0d9a0;
}

/* Chapel = default burgundy */
html[data-theme="chapel"], html:not([data-theme]) {
  --bg: #140e0c;
  --panel: #1c1412;
  --text: #f3e8d3;
  --muted: #b9a894;
  --gold: #e8c478;
  --gold-soft: #d4b483;
  --accent: #6b1d2a;
}
html[data-theme="night"] {
  --bg: #05070b;
  --panel: #0c121c;
  --text: #e8eef8;
  --muted: #8b9bb0;
  --gold: #c9a227;
  --gold-soft: #b8973a;
  --accent: #1a3a5c;
}
html[data-theme="paper"] {
  --bg: #f4efe4;
  --panel: #fffdf8;
  --text: #1c1410;
  --muted: #6b5e4e;
  --gold: #8a6a28;
  --gold-soft: #6b531f;
  --accent: #6b1d2a;
}
html[data-theme="paper"] body,
html[data-theme="paper"] .app {
  background: var(--bg);
  color: var(--text);
}
html[data-theme="night"] body,
html[data-theme="night"] .app {
  background: var(--bg);
  color: var(--text);
}

/* Map existing CSS variables if present */
html[data-theme] body { background: var(--bg); color: var(--text); }
html[data-theme] .app { background: var(--bg); }
html[data-theme] .topbar,
html[data-theme] .tabbar,
html[data-theme] .side-panel,
html[data-theme] .reader,
html[data-theme] .card {
  background: var(--panel);
  color: var(--text);
}
html[data-theme] .muted { color: var(--muted); }
html[data-theme] .meta,
html[data-theme] .reader-meta { color: var(--gold-soft); }

/* E-ink: high contrast, no soft gradients */
html.eink body,
html.eink .app {
  background: #000 !important;
  color: #fff !important;
}
html.eink .topbar,
html.eink .tabbar,
html.eink .side-panel,
html.eink .reader,
html.eink .card {
  background: #000 !important;
  color: #fff !important;
  border-color: #fff !important;
  box-shadow: none !important;
}
html.eink .muted,
html.eink .meta,
html.eink .reader-meta { color: #ddd !important; }
html.eink .btn,
html.eink .icon-listen,
html.eink .theme-btn {
  background: #000 !important;
  color: #fff !important;
  border: 2px solid #fff !important;
}
html.eink .scripture,
html.eink .reader-body { color: #fff !important; }
html.eink .v { color: #fff !important; }


/* Library card actions — Read + Listen */
.card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}
.card-actions .btn {
  margin: 0;
}
.btn.listen-book {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid rgba(232, 196, 120, 0.5);
  background: linear-gradient(145deg, rgba(107, 29, 42, 0.35), rgba(20, 14, 12, 0.9));
  color: #f0d9a0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.03em;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(240, 217, 160, 0.12);
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.btn.listen-book:hover {
  border-color: rgba(240, 217, 160, 0.85);
  background: linear-gradient(145deg, rgba(107, 29, 42, 0.65), rgba(30, 18, 16, 0.95));
  transform: translateY(-1px);
}
.btn.listen-book:active {
  transform: translateY(0) scale(0.98);
}
.btn.listen-book .ico-headphones {
  flex-shrink: 0;
  opacity: 0.95;
}
.btn.listen-book.loading {
  opacity: 0.75;
  pointer-events: none;
}
.lib-card .card-actions {
  margin-top: 14px;
}
html.eink .btn.listen-book {
  background: #000 !important;
  color: #fff !important;
  border: 2px solid #fff !important;
  box-shadow: none !important;
}
