/* Deep Reader — calm paper design. One font pairing, one accent, no gradients. */
:root {
  --paper: #faf6ec;
  --paper-deep: #f3eddd;
  --ink: #2b2620;
  --muted: #7a7163;
  --faint: #b3a894;
  --accent: #8c5e1a;
  --accent-soft: #f0e6cf;
  --line: #e4dac4;
  --card: #fffdf7;
  --danger: #a03d2d;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  min-height: 100vh;
}

/* Top bar */
#topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px; letter-spacing: 0.5px;
  background: none; border: none; color: var(--ink);
  cursor: pointer; padding: 4px 0;
}
.top-actions { display: flex; gap: 6px; }
.icon-btn {
  background: none; border: none; color: var(--muted);
  width: 38px; height: 38px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.icon-btn:hover { background: var(--paper-deep); color: var(--ink); }

#search-bar { padding: 10px 18px 0; }
#search-bar input {
  width: 100%; padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--ink);
}
#search-bar input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

/* Views */
main { max-width: 720px; margin: 0 auto; padding: 8px 18px 90px; }
.view[hidden] { display: none; }

.library-sub { color: var(--muted); font-size: 13px; margin: 14px 2px 4px; }
.testament-head {
  font-family: Georgia, serif; font-weight: normal;
  font-size: 19px; margin: 22px 2px 10px; color: var(--ink);
}
.book-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 560px) { .book-grid { grid-template-columns: repeat(4, 1fr); } }
.book-btn {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 8px; font-size: 15px; color: var(--ink);
  cursor: pointer; text-align: center;
}
.book-btn:hover { border-color: var(--accent); background: var(--accent-soft); }

.back-link {
  background: none; border: none; color: var(--accent);
  font-size: 15px; cursor: pointer; padding: 14px 0 2px;
}
.reader-title {
  font-family: Georgia, serif; font-weight: normal;
  font-size: 30px; margin: 6px 0 2px;
}
.reader-sub { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.reader-sub { margin-bottom: 12px; }

.reader-notice {
  background: var(--accent-soft); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px;
  font-size: 14px; color: var(--ink); margin: 0 0 16px;
}
.reader-notice[hidden] { display: none; }

.attrib {
  color: var(--faint); font-size: 12px; line-height: 1.6;
  border-top: 1px solid var(--line); padding-top: 14px; margin: 26px 0 0;
}
.attrib[hidden] { display: none; }

.esv-heading {
  font-family: Georgia, serif; font-weight: normal; font-style: italic;
  font-size: 17px; color: var(--muted); margin: 1.2em 0 0.6em;
}
.esv-heading:first-child { margin-top: 0; }

.loading { color: var(--muted); font-family: -apple-system, sans-serif; font-size: 15px; }

.chapter-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 12px; }
@media (min-width: 560px) { .chapter-grid { grid-template-columns: repeat(8, 1fr); } }
.chapter-btn {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 0; font-size: 15px; color: var(--ink); cursor: pointer;
}
.chapter-btn:hover { border-color: var(--accent); background: var(--accent-soft); }

/* Reader */
.reader-text {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 19px; line-height: 1.75; color: var(--ink);
}
.verse { margin: 0 0 0.85em; }
.verse-num {
  color: var(--faint); font-size: 12px; font-family: -apple-system, sans-serif;
  vertical-align: super; margin-right: 6px; user-select: none;
}
.reader-text ::selection { background: var(--accent-soft); }

.chapter-nav { display: flex; justify-content: space-between; margin: 30px 0 10px; }
.nav-btn {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 18px; font-size: 15px; color: var(--ink); cursor: pointer;
}
.nav-btn:hover:not(:disabled) { border-color: var(--accent); }
.nav-btn:disabled { opacity: 0.35; cursor: default; }

/* Search results */
.result {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 10px; cursor: pointer;
}
.result:hover { border-color: var(--accent); }
.result-ref { font-size: 13px; color: var(--accent); font-weight: 600; margin-bottom: 4px; }
.result-text { font-family: Georgia, serif; font-size: 16px; line-height: 1.6; }

/* Ask FAB */
#ask-fab {
  position: fixed; z-index: 60;
  background: var(--ink); color: var(--paper);
  border: none; border-radius: 999px;
  padding: 10px 18px; font-size: 15px; font-weight: 600;
  box-shadow: 0 4px 18px rgba(0,0,0,0.25);
  cursor: pointer; transform: translate(-50%, -130%);
}
#ask-fab[hidden] { display: none; }

/* Bottom sheet */
#sheet-scrim {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(43, 38, 32, 0.35);
}
#sheet-scrim[hidden], #ask-sheet[hidden] { display: none; }
#ask-sheet {
  position: fixed; z-index: 71; left: 0; right: 0; bottom: 0;
  background: var(--card);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  max-height: 82vh; overflow-y: auto;
  padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0,0,0,0.15);
}
.sheet-handle {
  width: 44px; height: 5px; border-radius: 3px;
  background: var(--line); margin: 6px auto 12px;
}
.ask-passage {
  background: var(--paper); border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 10px 14px; margin-bottom: 12px;
}
.ask-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 4px; }
.ask-passage p {
  font-family: Georgia, serif; font-size: 16px; line-height: 1.65; margin: 0;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  background: var(--paper); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 14px; font-size: 14px; color: var(--ink); cursor: pointer;
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.ask-answer {
  font-size: 16px; line-height: 1.7; margin-bottom: 12px;
  border-top: 1px solid var(--line); padding-top: 12px;
}
.ask-answer[hidden] { display: none; }
.ask-answer p { margin: 0 0 0.8em; }
#ask-form { display: flex; gap: 8px; }
#ask-input {
  flex: 1; padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
}
#ask-input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.send-btn {
  background: var(--accent); color: #fff; border: none; border-radius: 12px;
  padding: 0 20px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.send-btn:disabled { opacity: 0.5; }
.ask-hint { font-size: 13px; color: var(--muted); margin: 10px 2px 0; }
.link-btn { background: none; border: none; color: var(--accent); font-size: 13px; cursor: pointer; padding: 0; text-decoration: underline; }
.typing { color: var(--muted); }

/* Settings modal */
#settings-modal {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(43, 38, 32, 0.4);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
#settings-modal[hidden] { display: none; }
.modal-card {
  background: var(--card); border-radius: 16px; padding: 24px;
  width: 100%; max-width: 440px; position: relative;
  border: 1px solid var(--line);
}
.modal-card h2 { font-family: Georgia, serif; font-weight: normal; margin: 0 0 16px; }
.modal-close { position: absolute; top: 12px; right: 12px; }
.field-label { display: block; font-size: 14px; font-weight: 600; margin: 14px 0 6px; }
.modal-card input[type="password"], .modal-card input[type="text"] {
  width: 100%; padding: 11px 13px; font-size: 15px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
  font-family: ui-monospace, monospace;
}
.field-hint { font-size: 13px; color: var(--muted); margin: 8px 0 0; line-height: 1.6; }
.field-hint a { color: var(--accent); }
.modal-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 20px; }
.clear-row { display: flex; gap: 8px; }
.clear-row .ghost-btn { padding: 11px 12px; font-size: 13px; }
.primary-btn {
  background: var(--accent); color: #fff; border: none; border-radius: 10px;
  padding: 11px 26px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.ghost-btn {
  background: none; border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 18px; font-size: 15px; color: var(--muted); cursor: pointer;
}

/* Toast */
#toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  padding: 11px 20px; border-radius: 999px; font-size: 14px; z-index: 90;
}
#toast[hidden] { display: none; }
