:root {
  --bg: #F7F0E3;
  --card-bg: #FFFFFF;
  --text: #1A1008;
  --text-soft: #2A1F12;
  --sub: rgba(26, 16, 8, 0.45);
  --border: rgba(0, 0, 0, 0.06);
  --divider: rgba(0, 0, 0, 0.06);
  --tab-bg: rgba(0, 0, 0, 0.06);
  --tab-active-bg: #FFFFFF;
  --search-bg: rgba(0, 0, 0, 0.07);

  --accent: #7B2D3E;
  --accent-light: #F5E8EA;
  --accent-strong: #5e1d2d;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: 'Noto Sans TC', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
.serif { font-family: 'Noto Serif TC', Georgia, '新細明體', 'PingFang TC', serif; }

/* ── App shell ── */
#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  max-width: 720px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

.screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

/* ── Header ── */
.header {
  padding: 12px 20px 8px;
}
@supports (padding: max(0px)) {
  .header { padding-top: max(12px, calc(env(safe-area-inset-top) + 4px)); }
}
.title-block { margin-bottom: 16px; }
.kicker {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.h1 {
  font-size: 28px;
  font-weight: 700;
  font-family: 'Noto Serif TC', serif;
  line-height: 1.2;
  color: var(--text);
}
.h1.lg {
  font-size: 30px;
}
.h1.md {
  font-size: 26px;
}
.subline {
  font-size: 14px;
  color: var(--sub);
  margin-top: 4px;
}

.back-btn {
  background: none;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--accent);
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 14px;
  padding: 4px 0;
}

.accent-rule {
  margin-top: 12px;
  height: 2px;
  width: 36px;
  background: var(--accent);
  border-radius: 2px;
}

/* ── Search ── */
.search {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--search-bg);
  border-radius: 14px;
  padding: 10px 14px;
  margin-bottom: 12px;
}
.search input {
  border: none;
  background: transparent;
  outline: none;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  flex: 1;
  min-width: 0;
}

/* ── OT/NT tabs ── */
.tab-row {
  display: flex;
  background: var(--tab-bg);
  border-radius: 10px;
  padding: 3px;
}
.tab-btn {
  flex: 1;
  padding: 8px 0;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--sub);
  font-weight: 400;
  font-size: 14px;
  transition: background 0.18s, color 0.18s, box-shadow 0.18s;
}
.tab-btn.active {
  background: var(--tab-active-bg);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0,0,0,0.10);
}

/* ── Body scroll area ── */
.scroller {
  flex: 1;
  overflow-y: auto;
  padding: 6px 20px 32px;
}

/* ── Categories & books ── */
.cat-block + .cat-block { margin-top: 24px; }
.cat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.cat-tag {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-light);
  padding: 4px 10px;
  border-radius: 20px;
  letter-spacing: 1.2px;
}
.cat-rule {
  flex: 1;
  height: 1px;
  background: var(--divider);
}
.cat-count {
  font-size: 14px;
  color: var(--sub);
}
.book-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.book-card {
  background: var(--card-bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 10px 12px 11px;
  text-align: left;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  font-family: 'Noto Serif TC', serif;
  line-height: 1.3;
  word-break: keep-all;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.book-card:active { transform: scale(0.98); opacity: 0.85; }

/* ── Chapter screen ── */
.intro-cards {
  padding: 0 20px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.intro-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.intro-card-icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-light);
  color: var(--accent);
}
.intro-card-icon.solid {
  background: var(--accent);
  color: white;
  box-shadow: 0 3px 10px rgba(123,45,62,0.25);
}
.intro-card-text { flex: 1; }
.intro-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  font-family: 'Noto Serif TC', serif;
  margin-bottom: 3px;
}
.intro-card-sub { font-size: 14px; color: var(--sub); }
.intro-card-arrow { color: var(--sub); }

.chapter-grid {
  padding: 0 20px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.chapter-card {
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
  font-family: 'Noto Serif TC', serif;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease;
}
.chapter-card:active { transform: scale(0.95); }
.home-updated-at {
  margin: 22px 2px 0;
  padding-top: 12px;
  border-top: 1px solid var(--divider);
  color: var(--sub);
  font-size: 13px;
  text-align: center;
  letter-spacing: 0.2px;
}

/* ── Intro detail ── */
.intro-section { margin-bottom: 28px; }
.intro-section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.intro-section-tag {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-light);
  border-radius: 6px;
  padding: 3px 10px;
  letter-spacing: 0.3px;
  font-family: 'Noto Serif TC', serif;
  white-space: nowrap;
}
.intro-section-rule {
  flex: 1;
  height: 1px;
  background: var(--divider);
}
.intro-section-body {
  font-size: 17px;
  line-height: 1.95;
  color: var(--text-soft);
  font-family: 'Noto Serif TC', serif;
  letter-spacing: 0.2px;
  word-break: normal;
  overflow-wrap: anywhere;
  line-break: auto;
}
/* Each intro line is rendered as a regular body paragraph — no heading
   typography, just a small gap between enumerated items. The visual
   structure is already provided by the burgundy section "tag" header. */
.intro-section-body .intro-line {
  margin: 0;
}
.intro-section-body .intro-line + .intro-line {
  margin-top: 0.4em;
}
.intro-section-body .body-spacer {
  height: 0.6em;
}
.intro-empty-divider {
  margin-bottom: 16px;
}
.intro-empty-divider .intro-section-body { display: none; }

.preface-body {
  font-size: 16px;
  line-height: 2.1;
  color: var(--text-soft);
  font-family: 'Noto Serif TC', serif;
  white-space: pre-wrap;
  letter-spacing: 0.3px;
}

/* ── Reading screen ── */
.reading-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tool-row {
  display: flex;
  gap: 12px;
  align-items: center;
}
.icon-btn {
  background: none;
  border: none;
  color: var(--sub);
  padding: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn.accent { color: var(--accent); }
.font-toggle-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 12px;
}

.font-controls {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(0,0,0,0.05);
  border-radius: 12px;
  padding: 10px 16px;
}
.font-controls span { font-size: 14px; color: var(--sub); }
.font-controls .stepper {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.font-controls button {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--divider);
  background: var(--bg);
  font-size: 18px;
  color: var(--text);
}

.chapter-title-block {
  margin-bottom: 24px;
}

.chapter-body {
  font-size: 17px;
  line-height: 1.95;
  color: var(--text-soft);
  font-family: 'Noto Serif TC', serif;
  letter-spacing: 0.3px;
  word-break: normal;
  overflow-wrap: anywhere;
  line-break: auto;
}
/* Each logical line is its own block with semantic class; visual hierarchy is
   conveyed through typography (size / weight / color / spacing) instead of
   left-indentation, which reads better on a narrow phone screen. */
.ln {
  margin: 0;
}
.ln-h1 {
  font-family: 'Noto Serif TC', serif;
  font-size: 1.2em;
  font-weight: 700;
  color: var(--accent);
  margin-top: 1.5em;
  margin-bottom: 0.15em;
  letter-spacing: 0.4px;
  line-height: 1.55;
}
.ln-h2 {
  font-size: 1.1em;
  font-weight: 700;
  color: var(--text);
  margin-top: 1.15em;
  margin-bottom: 0.1em;
  line-height: 1.6;
}
.ln-h3 {
  font-size: 1.02em;
  font-weight: 700;
  color: var(--text);
  margin-top: 0.95em;
  margin-bottom: 0.05em;
  line-height: 1.65;
}
.ln-h4 {
  font-size: 1em;
  font-weight: 700;
  color: var(--text);
  margin-top: 0.75em;
  line-height: 1.7;
}
.ln-h5 {
  font-size: 1em;
  font-weight: 600;
  color: var(--text);
  margin-top: 0.5em;
  line-height: 1.85;
}
/* The first heading in a chapter shouldn't push down from a non-existent
   sibling; this avoids an awkward gap below the chapter title block. */
.commentary-body > .ln:first-child { margin-top: 0; }
.commentary-body > .body-spacer:first-child { display: none; }

.ln-bullet { margin-top: 0.25em; line-height: 1.95; }
.ln-thought {
  margin-top: 0.25em;
  line-height: 1.95;
  color: var(--text-soft);
}
.ln-ref {
  font-size: 0.92em;
  color: var(--sub);
  margin-top: 0.2em;
  line-height: 1.65;
}
.ln-note {
  color: var(--accent);
  font-weight: 600;
  margin-top: 0.5em;
  line-height: 1.85;
}
.ln-body { margin-top: 0.25em; line-height: 1.95; }
.body-spacer {
  height: 0.6em;
}

/* Inline markup styling — see renderInline() in the JS section.
   .xref      = scripture cross-reference (raw markup #路 3:23-38|).
                Burgundy accent + nowrap so a reference never breaks across lines.
   .strong    = Hebrew/Greek Strong number (raw markup SNG05207 / SNH03091).
                Slightly smaller and muted so they read as inline annotations
                without competing with the body text. */
.xref {
  color: var(--accent);
  white-space: nowrap;
}
.strong {
  font-size: 0.82em;
  color: var(--sub);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ── Persistent bottom chapter nav bar ── */
.chapter-nav-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px 8px;
  border-top: 1px solid var(--divider);
  z-index: 100;
  background: rgba(247, 240, 227, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.chapter-nav-bar .nav-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.14s, opacity 0.14s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.chapter-nav-bar .nav-btn:active { background: var(--accent-light); }
.chapter-nav-bar .nav-btn[disabled], .chapter-nav-bar .nav-btn[aria-disabled="true"] { opacity: 0.28; cursor: default; box-shadow: none; }
.chapter-nav-bar .nav-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.chapter-nav-bar .nav-chapter {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  font-family: 'Noto Serif TC', serif;
  line-height: 1.2;
}
.chapter-nav-bar .nav-book {
  font-size: 12px;
  color: var(--sub);
  letter-spacing: 0.3px;
}

/* ── Full-text search results ── */
.search-results {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.search-results-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 6px 2px 4px;
}
.search-results-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 1px;
}
.search-results-count {
  font-size: 13px;
  color: var(--sub);
}
.search-result {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px 12px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.search-result:active { transform: scale(0.99); opacity: 0.85; }
.search-result-loc {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  font-family: 'Noto Serif TC', serif;
}
.search-result-loc .chapter-tag {
  color: var(--accent);
  margin-left: 6px;
  font-weight: 600;
}
.search-result-snippet {
  font-size: 13px;
  color: var(--text-soft);
  line-height: 1.65;
  font-family: 'Noto Serif TC', serif;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.search-result-snippet mark {
  background: var(--accent-light);
  color: var(--accent-strong);
  padding: 0 2px;
  border-radius: 3px;
  font-weight: 700;
}

/* Empty state */
.empty {
  margin: 32px 0;
  padding: 16px;
  border-radius: 14px;
  background: rgba(123,45,62,0.06);
  border: 1px solid var(--divider);
  font-size: 14px;
  color: var(--sub);
  line-height: 1.7;
  font-family: 'Noto Serif TC', serif;
  text-align: center;
}

/* ── Bottom tab bar ── */
.tab-bar {
  flex-shrink: 0;
  display: flex;
  border-top: 1px solid var(--divider);
  background: rgba(247, 240, 227, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 100;
}
.tab-bar-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 8px 0 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--sub);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.5px;
  transition: color 0.14s;
}
.tab-bar-btn.active {
  color: var(--accent);
  font-weight: 700;
}
.tab-bar-btn .icon { display: inline-flex; }

/* ── Dedicated full-text search screen ── */
.search-screen-empty {
  margin: 48px 16px;
  text-align: center;
  color: var(--sub);
  font-size: 14px;
  line-height: 1.8;
  font-family: 'Noto Serif TC', serif;
}

/* SVG icons inherit currentColor */
svg { display: block; }

/* ── About / 資料來源頁 ── */
.about-section { margin-bottom: 20px; }
.about-section-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
}
.about-section-tag {
  font-size: 15px; font-weight: 700;
  color: var(--accent); background: var(--accent-light);
  padding: 3px 10px; border-radius: 20px;
  letter-spacing: 1px; white-space: nowrap;
}
.about-section-rule { flex: 1; height: 1px; background: var(--divider); }

.about-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.about-card + .about-card { margin-top: 10px; }
.about-card-title {
  font-size: 16px; font-weight: 700;
  color: var(--text); font-family: 'Noto Serif TC', serif;
  margin-bottom: 6px;
}
.about-card-body {
  font-size: 15px; line-height: 1.8;
  color: var(--text-soft); font-family: 'Noto Serif TC', serif;
}
.about-card-link {
  font-size: 14px; color: var(--accent); font-weight: 600;
  text-decoration: none; display: inline-flex;
  align-items: center; gap: 4px;
  margin-bottom: 10px;
}
.donate-btn {
  width: 100%; background: var(--accent); color: white;
  border: none; border-radius: 12px; padding: 14px 16px;
  font-size: 15px; font-weight: 700; font: inherit;
  cursor: pointer; display: flex; align-items: center;
  justify-content: center; gap: 6px;
  letter-spacing: 0.5px; margin-top: 10px;
  transition: background 0.15s;
}
.donate-btn:active { background: var(--accent-strong); }

.dev-row { display: flex; align-items: center; gap: 12px; }
.dev-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent-light); color: var(--accent);
  font-size: 18px; font-weight: 700;
  font-family: 'Noto Serif TC', serif;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.dev-name { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.dev-email { font-size: 14px; color: var(--accent); font-weight: 500; }
.dev-note {
  font-size: 15px; line-height: 1.8;
  color: var(--text-soft); font-family: 'Noto Serif TC', serif;
  margin-top: 12px;
}

.github-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--tab-bg); border-radius: 12px;
  padding: 10px 14px; margin-top: 10px;
  cursor: pointer; border: none; width: 100%;
  font-family: inherit; text-align: left;
  transition: background 0.12s;
}
.github-pill:active { background: rgba(0,0,0,0.10); }
.github-pill-label { flex: 1; }
.github-pill-title { font-size: 14px; font-weight: 600; color: var(--text); }
.github-pill-sub { font-size: 13px; color: var(--sub); margin-top: 1px; }

.version-tag {
  text-align: center; font-size: 12px;
  color: var(--sub); margin-top: 8px;
  padding-bottom: 4px; font-family: 'Noto Sans TC', sans-serif;
}

/* About 入口：首頁標題列右側 */
.home-title-row {
  display: flex; align-items: baseline;
  justify-content: space-between;
}
.about-entry-btn {
  background: none; border: none; cursor: pointer;
  color: var(--accent); font-size: 14px; font-weight: 600;
  font-family: inherit; padding: 4px 0 4px 8px;
  letter-spacing: 0.3px; flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

/* Crawlable initial HTML and link semantics */
a.book-card, a.chapter-card, a.intro-card, a.search-result,
a.back-btn, a.nav-btn, a.tab-bar-btn, a.about-entry-btn {
  text-decoration: none;
}
.static-shell { min-height: 100%; }
.static-shell .header p { color: var(--sub); margin-top: 8px; line-height: 1.7; }
.seo-book-section { margin-bottom: 28px; }
.seo-book-section h2, .seo-article h2 {
  color: var(--accent); font-family: 'Noto Serif TC', serif;
  font-size: 18px; margin-bottom: 12px;
}
.seo-book-section ul {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px; list-style: none;
}
.seo-book-section a { color: var(--text); text-decoration: none; }
.seo-breadcrumbs {
  display: flex; align-items: center; flex-wrap: wrap; gap: 7px;
  padding: 14px 20px 0; color: var(--sub); font-size: 13px;
}
.seo-breadcrumbs a { color: var(--accent); text-decoration: none; }
.seo-article { padding: 22px 22px 40px; }
.seo-article > .h1 { margin-bottom: 22px; }
.seo-article section { margin-bottom: 24px; }
.seo-article p { color: var(--text-soft); line-height: 1.85; margin-bottom: 10px; }

/* PWA install, offline-ready, and update feedback */
.pwa-status {
  position: fixed; z-index: 1000; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%); width: min(90vw, 520px);
  padding: 12px 14px; border-radius: 14px;
  background: #2a1f12; color: white; box-shadow: 0 8px 28px rgba(0,0,0,0.24);
  font-size: 14px; line-height: 1.5; display: flex; align-items: center; gap: 12px;
}
.pwa-status[hidden] { display: none; }
.pwa-status button {
  margin-left: auto; flex-shrink: 0; border: 0; border-radius: 999px;
  padding: 7px 11px; background: white; color: var(--accent-strong); font-weight: 700;
}
.pwa-install-steps { margin: 10px 0 0 20px; color: var(--text-soft); line-height: 1.9; }
.pwa-capability { margin-top: 10px; color: var(--accent); font-size: 13px; font-weight: 600; }

/* Wider screens: keep iPhone-ish max width and add a subtle frame */
@media (min-width: 600px) {
  body { background: #ece1cb; }
  #app {
    margin: 24px auto;
    border-radius: 28px;
    box-shadow: 0 6px 28px rgba(0,0,0,0.10);
    overflow: hidden;
    min-height: calc(100vh - 48px);
  }
}
