/* ============================================================
   在线圣经 · 和合本 — 样式表
   设计：暖色纸质阅读风格；支持明亮 / 护眼 / 夜间三套主题
   ============================================================ */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", Georgia, serif;

  --bg: #f7f4ee;
  --surface: #fffdf9;
  --surface-2: #f1ece2;
  --surface-3: #eae3d6;
  --text: #302a23;
  --text-2: #6c6155;
  --text-3: #948a7d;
  --border: #e2dacd;
  --accent: #9b6b43;
  --accent-strong: #7b5232;
  --accent-soft: #f0e4d5;
  --shadow: 0 12px 40px rgba(74, 54, 30, 0.12);
  --header-bg: #fffdf9;
  --overlay-bg: rgba(40, 32, 24, 0.45);

  --verse-size: 19px;
  --verse-line: 1.9;
  --sidebar-w: 286px;
}

:root[data-theme="sepia"] {
  --bg: #f3e8d2;
  --surface: #f8efdc;
  --surface-2: #ecdcc0;
  --surface-3: #e3d0ad;
  --text: #4a3826;
  --text-2: #7b664b;
  --text-3: #9d8b70;
  --border: #dcc8a6;
  --accent: #966036;
  --accent-strong: #744827;
  --accent-soft: #e9d5b7;
  --shadow: 0 12px 40px rgba(90, 65, 30, 0.16);
  --header-bg: #f8efdc;
  --overlay-bg: rgba(60, 45, 25, 0.5);
}

:root[data-theme="dark"] {
  --bg: #1c1a18;
  --surface: #24211e;
  --surface-2: #2e2a26;
  --surface-3: #3a352f;
  --text: #eae3d8;
  --text-2: #b3a999;
  --text-3: #8c8275;
  --border: #3b362f;
  --accent: #d5a878;
  --accent-strong: #e6bf94;
  --accent-soft: #3b3025;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --header-bg: #24211e;
  --overlay-bg: rgba(0, 0, 0, 0.65);
}

* { box-sizing: border-box; }

/* 组件自身设置了 display 时，必须显式压过它，否则 hidden 属性失效 */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: -60px; left: 12px;
  z-index: 200;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  transition: top 0.2s;
}
.skip-link:focus { top: 12px; }

kbd {
  font-family: var(--font-sans);
  font-size: 11px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text-2);
}

/* ---------- 顶栏 ---------- */
.topbar {
  height: 68px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 190px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  font-size: 21px;
  line-height: 1;
}

.brand-text h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 1px;
}

.top-search {
  flex: 1;
  min-width: 0;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 9px;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-3);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.top-search:hover {
  border-color: var(--accent);
  background: var(--surface);
}
.top-search svg { width: 17px; height: 17px; color: var(--text-3); }
.top-search-hint {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.top-actions { display: flex; gap: 4px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-2);
  transition: background 0.18s, color 0.18s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--accent); }

.menu-toggle { display: none; }

/* ---------- 布局 ---------- */
.layout {
  display: flex;
  height: calc(100dvh - 68px);
  min-height: 0;
}

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex: none;
  border-right: 1px solid var(--border);
  background: var(--surface);
  position: relative;
  transition: width 0.26s ease;
}
.sidebar.collapsed { width: 96px; }

/* 收起后侧栏留一条较宽的竖条，竖排文字靠右 */
.collapsed-label {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  writing-mode: vertical-rl;
  letter-spacing: 5px;
  color: var(--text-3);
  font-size: 15px;
  white-space: nowrap;
}
.sidebar.collapsed .collapsed-label { display: block; }
.sidebar.collapsed .sidebar-inner { opacity: 0; pointer-events: none; overflow: hidden; }

/* 跨在右侧竖条上的三横线开关 */
.sidebar-collapse {
  position: absolute;
  z-index: 12;
  top: 50%;
  right: -15px;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-3);
  box-shadow: 0 2px 8px rgba(74, 54, 30, 0.08);
  transition: color 0.18s, border-color 0.18s, right 0.26s ease;
}
.sidebar-collapse svg { width: 16px; height: 16px; }
.sidebar-collapse:hover { color: var(--accent); border-color: var(--accent); }
.sidebar.collapsed .sidebar-collapse { right: -15px; }

.sidebar-inner {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity 0.2s;
}

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 14px 10px;
  padding: 0 11px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
}
.sidebar-search svg { width: 15px; height: 15px; color: var(--text-3); }
.sidebar-search input {
  flex: 1; min-width: 0;
  border: 0; background: transparent; outline: none;
  font-size: 13px;
}
.sidebar-search input::placeholder { color: var(--text-3); }

#bookNav {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.testament { margin-bottom: 14px; }

.testament-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  text-align: left;
}
.testament-head .chev {
  transition: transform 0.2s;
  width: 14px; height: 14px;
}
.testament.collapsed .chev { transform: rotate(-90deg); }
.testament.collapsed .book-list { display: none; }

.book-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
}

.book-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  transition: background 0.15s, color 0.15s;
}
.book-item:hover { background: var(--surface-2); color: var(--text); }
.book-item.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
}
.book-item .num {
  flex: none;
  width: 19px;
  color: var(--text-3);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.book-item.active .num { color: var(--accent); }
.book-item .name { overflow: hidden; text-overflow: ellipsis; }

.no-books {
  padding: 20px 10px;
  color: var(--text-3);
  font-size: 13px;
  text-align: center;
}

.sidebar-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: 11px;
}

/* ---------- 阅读区 ---------- */
.reader {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.reader-inner {
  max-width: 800px;
  margin: 0 auto;
  padding: 38px 40px 60px;
  transition: max-width 0.26s ease;
}
/* 侧栏收起后，经文区自适应变宽，占满释放出的空间 */
body.sidebar-collapsed .reader-inner { max-width: 1080px; }

.breadcrumb {
  color: var(--text-3);
  font-size: 12px;
  letter-spacing: 1px;
  margin-bottom: 14px;
}

.reader-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 18px;
  border-bottom: 2px solid var(--accent);
  margin-bottom: 22px;
}
.reader-head h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 2px;
}
.subtitle {
  margin: 5px 0 0;
  color: var(--text-2);
  font-size: 14px;
  letter-spacing: 1px;
}

.head-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.text-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 12px;
  transition: all 0.18s;
}
.text-btn svg { width: 15px; height: 15px; }
.text-btn:hover { border-color: var(--accent); color: var(--accent); }
.text-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
}
.text-btn[aria-pressed="true"] svg { fill: var(--accent); }

/* 章节 / 节选择面板 */
.chapter-panel {
  padding: 24px 28px 28px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.pick-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.pick-hint {
  margin: 0 0 14px;
  font-size: 11px;
  color: var(--text-3);
}
.panel-title {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-2);
  letter-spacing: 1px;
}
.chapter-grid, .verse-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 9px;
}
.chapter-btn, .verse-btn {
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  transition: all 0.15s;
}
.chapter-btn:hover, .verse-btn:hover { border-color: var(--accent); color: var(--accent); }
.chapter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}
.verse-pick {
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}
.verse-grid { grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); }
.verse-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
  font-weight: 700;
}

/* 目标节号：跳转后短暂加粗放大，再恢复 */
.verse-num.bold-flash {
  font-size: 17px;
  font-weight: 900;
  color: var(--accent-strong);
}

/* 翻章按钮 */
.chapter-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 26px;
}
.chapter-nav.bottom { margin: 36px 0 0; justify-content: space-between; }

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  transition: all 0.18s;
}
.nav-btn svg { width: 16px; height: 16px; }
.nav-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.nav-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.chapter-count {
  color: var(--text-3);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* 经文正文 */
.scripture { font-family: var(--font-serif); }

.verse {
  display: flex;
  gap: 14px;
  padding: 5px 0;
  line-height: var(--verse-line);
  border-radius: 6px;
  transition: background 0.3s;
}
.verse:hover { background: var(--surface-2); }
.verse.flash { background: var(--accent-soft); }

.verse-num {
  flex: 0 0 26px;
  padding-top: 0.28em;
  text-align: right;
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.verse-text {
  flex: 1;
  min-width: 0;
  font-size: var(--verse-size);
  color: var(--text);
  word-break: break-word;
  white-space: pre-wrap;
}
.verse-text mark {
  background: #f2d98a;
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}
:root[data-theme="dark"] .verse-text mark { background: #8a6d2f; color: #fff; }

.reader-foot {
  margin-top: 46px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: 11px;
  line-height: 1.9;
  text-align: center;
}
.reader-foot p { margin: 0; }

/* ---------- 遮罩与浮层面板 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--overlay-bg);
  backdrop-filter: blur(2px);
}

.search-panel, .settings-panel, .fav-panel {
  position: fixed;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.search-panel {
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(760px, calc(100vw - 32px));
  max-height: min(80dvh, 720px);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.settings-panel, .fav-panel {
  top: 62px; right: 18px;
  width: min(360px, calc(100vw - 36px));
  border-radius: 14px;
  padding: 20px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.settings-panel .panel-head, .fav-panel .panel-head { padding: 0 0 14px; }
.panel-head h2 { margin: 0; font-size: 16px; }
.panel-head p { margin: 5px 0 0; font-size: 12px; color: var(--text-3); }

/* 搜索面板顶部：真正的搜索输入框 */
.search-head { align-items: center; padding: 16px 18px 14px; }
.search-box {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-box svg { width: 18px; height: 18px; color: var(--text-3); }
.search-box input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  outline: none;
  font-size: 15px;
  color: var(--text);
}
.search-box input::placeholder { color: var(--text-3); }
.search-summary {
  margin: 0;
  padding: 0 20px 12px;
  font-size: 12px;
  color: var(--text-3);
}

.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px 18px;
}
.result-item {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  text-align: left;
  transition: background 0.15s;
}
.result-item:hover { background: var(--surface-2); }
.result-ref {
  display: block;
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.result-text {
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.result-text mark { background: #f2d98a; color: inherit; border-radius: 2px; }
:root[data-theme="dark"] .result-text mark { background: #8a6d2f; color: #fff; }
.result-empty {
  padding: 50px 20px;
  text-align: center;
  color: var(--text-3);
  font-size: 14px;
  line-height: 1.8;
}

/* 设置项 */
.setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.setting-row > label, .setting-row > span:first-child {
  flex: 0 0 68px;
  color: var(--text-2);
}
.setting-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  min-width: 0;
}
.setting-row output {
  flex: 0 0 46px;
  text-align: right;
  color: var(--text-3);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.theme-options { display: flex; gap: 6px; flex: 1; }
.theme-chip {
  flex: 1;
  padding: 6px 4px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
}
.theme-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.reset-btn {
  width: 100%;
  margin-top: 18px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
}
.reset-btn:hover { border-color: var(--accent); color: var(--accent); }

/* 收藏列表 */
.fav-list { max-height: 55dvh; overflow-y: auto; padding-top: 10px; }
.fav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}
.fav-item:hover { background: var(--surface-2); }
.fav-item .fav-name { flex: 1; font-size: 14px; }
.fav-item .fav-remove {
  border: 0;
  background: transparent;
  color: var(--text-3);
  font-size: 11px;
  padding: 4px;
}
.fav-item .fav-remove:hover { color: #c05252; }
.fav-empty { padding: 30px 10px; color: var(--text-3); font-size: 13px; text-align: center; }

/* 提示条 */
.toast {
  position: fixed;
  bottom: 28px; left: 50%;
  transform: translate(-50%, 20px);
  z-index: 100;
  padding: 10px 18px;
  border-radius: 9px;
  background: var(--text);
  color: var(--surface);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 68px; left: 0; bottom: 0;
    z-index: 45;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar.collapsed { width: var(--sidebar-w); }
  .sidebar-collapse, .collapsed-label { display: none !important; }
  .menu-toggle { display: grid; }
  .brand { min-width: 0; }
  .reader-inner { padding: 28px 22px 50px; }
  .topbar { padding: 0 14px; gap: 8px; }
  .top-search { max-width: none; }
  .top-search kbd { display: none; }
}

@media (max-width: 620px) {
  .topbar { padding: 0 10px; gap: 6px; }
  .icon-btn { width: 34px; height: 34px; }
  .brand-text p { display: none; }
  .brand-text h1 { font-size: 15px; }
  .brand { flex: none; }
  .brand-mark { width: 32px; height: 32px; font-size: 18px; }
  .top-search { height: 36px; }
  .top-search-hint { font-size: 12px; }
  #favNavBtn { display: none; }
  .reader-head { flex-direction: column; align-items: flex-start; }
  .reader-head h2 { font-size: 28px; }
  .head-actions { justify-content: flex-start; }
  .reader-inner { padding: 22px 16px 44px; }
  .verse { gap: 10px; }
  .verse-num { flex-basis: 22px; }
  .chapter-nav.bottom { margin-top: 28px; }
  .nav-btn { padding: 7px 10px; font-size: 12px; }
  .chapter-count { display: none; }
  :root { --verse-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
