/* 聖經好閱讀版 — 閱讀區優先、工具抽屜 */

:root {
  --bg: #f2efe6;
  --bg-elev: #faf8f3;
  --fg: #1a1712;
  --muted: #5e574c;
  --accent: #6b4c2d;
  --accent-2: #8a6a45;
  --accent-soft: rgba(107, 76, 45, 0.12);
  --border: #d9d0c0;
  --vn-bg: #e4dccf;
  --focus: #2563a8;
  --shadow: rgba(26, 23, 18, 0.08);
  --sheet: #fbf9f4;
  --hit: rgba(255, 214, 120, 0.55);
  --hit-dark: rgba(180, 130, 40, 0.35);
  --font: "Songti TC", "Noto Serif TC", "Source Han Serif TC", PMingLiU, serif;
  --ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", sans-serif;
  --fs: 112.5%;
  --lh: 1.85;
  --read-max: min(calc(100vw - 1.25rem), max(36rem, min(76rem, 92vw)));
  --read-pad-x: clamp(0.75rem, 3vw, 1.75rem);
  --bar-h: 3.25rem;
  /* 工具抽屜寬度（右側欄；盡量把寬度還給閱讀區） */
  --tool-sheet-w: min(20rem, 32vw);
  color-scheme: light dark;
}

html[data-theme="light"] {
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12110f;
  --bg-elev: #1a1815;
  --fg: #ebe7df;
  --muted: #9d9588;
  --accent: #d4b896;
  --accent-2: #e8cc9e;
  --accent-soft: rgba(212, 184, 150, 0.14);
  --border: #353028;
  --vn-bg: #2c2822;
  --focus: #7cb8f0;
  --shadow: rgba(0, 0, 0, 0.4);
  --sheet: #1e1c19;
  --hit: var(--hit-dark);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    color-scheme: dark;
    --bg: #12110f;
    --bg-elev: #1a1815;
    --fg: #ebe7df;
    --muted: #9d9588;
    --accent: #d4b896;
    --accent-2: #e8cc9e;
    --accent-soft: rgba(212, 184, 150, 0.14);
    --border: #353028;
    --vn-bg: #2c2822;
    --focus: #7cb8f0;
    --shadow: rgba(0, 0, 0, 0.4);
    --sheet: #1e1c19;
    --hit: var(--hit-dark);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: var(--fs);
  scroll-behavior: auto;
}

body {
  margin: 0;
  font-family: var(--font);
  line-height: var(--lh);
  color: var(--fg);
  background: var(--bg);
}

a:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.skip {
  position: absolute;
  left: -9999px;
  top: 0.5rem;
  z-index: 200;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: var(--bg-elev);
  border-radius: 8px;
  font-family: var(--ui-font);
  font-size: 0.9rem;
}

.skip:focus {
  left: 0.5rem;
}

/* —— 頂欄：極簡 —— */
.read-shell {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--shadow);
}

.read-bar {
  max-width: var(--read-max);
  margin: 0 auto;
  padding: 0.45rem var(--read-pad-x);
  min-height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: 0.5rem 0.75rem;
  font-family: var(--ui-font);
}

.read-bar__tools {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  padding: 0.4rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--accent);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.read-bar__tools-icon {
  font-size: 1rem;
  line-height: 1;
  opacity: 0.9;
}

.read-bar__loc {
  flex: 1;
  min-width: 0;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent-2);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.read-bar__nav {
  flex-shrink: 0;
  display: flex;
  gap: 0.3rem;
}

/* 手機：頂欄不擠換章，改由底欄操作（可邊讀邊切） */
@media (max-width: 720px) {
  :root {
    --tool-sheet-w: min(14rem, 56vw);
  }

  .read-bar__nav {
    display: none;
  }
}

/* —— 手機底欄：換章（工具開啟時仍留在可讀區一側） —— */
.read-bottom-nav {
  display: none;
}

@media (max-width: 720px) {
  .read-bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 105;
    align-items: center;
    justify-content: flex-start;
    gap: 0.4rem;
    padding: 0.4rem var(--read-pad-x) calc(0.45rem + env(safe-area-inset-bottom, 0px));
    font-family: var(--ui-font);
    background: color-mix(in srgb, var(--bg) 94%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 16px var(--shadow);
    transition: right 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  }

  body.sheet-open .read-bottom-nav {
    right: var(--tool-sheet-w);
  }

  .read-bottom-nav__loc {
    flex: 1;
    min-width: 0;
    text-align: center;
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--accent-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .read-bottom-nav__actions {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 0.3rem;
  }

  .read-bottom-nav__btn {
    flex-shrink: 0;
    padding: 0.38rem 0.5rem;
    font-size: 0.76rem;
  }

  #to-top {
    bottom: calc(3.45rem + env(safe-area-inset-bottom, 0px));
  }

  .toast {
    bottom: calc(4.1rem + env(safe-area-inset-bottom, 0px));
  }
}

/* —— 經文主區 —— */
.read-main {
  max-width: var(--read-max);
  margin: 0 auto;
  padding: 1.15rem var(--read-pad-x) 4.5rem;
}

@media (max-width: 720px) {
  .read-main {
    padding-bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px));
  }
}

.ch {
  margin-bottom: 2.75rem;
  scroll-margin-top: calc(var(--bar-h) + 0.75rem);
}

/* 略過螢幕外章節內文的排版／繪製（章標題在 .verses 外，不影響 sticky） */
.ch .verses {
  content-visibility: auto;
  contain-intrinsic-size: auto 36rem;
}

.ch-title {
  margin: 0 0 1.05rem;
  padding: 0.4rem 0 0.55rem;
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: var(--bar-h);
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 93%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.ch-title-text {
  font-size: 1.22rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.03em;
}

.v {
  margin: 0 0 0.72rem;
  display: flex;
  gap: 0.65rem;
  align-items: baseline;
}

.vn {
  flex: 0 0 2.4rem;
  font-family: var(--ui-font);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-align: right;
  line-height: 1.35;
  padding: 0.12rem 0.38rem;
  border-radius: 6px;
  background: var(--vn-bg);
  user-select: none;
  font-variant-numeric: tabular-nums;
}

.vt {
  flex: 1;
  min-width: 0;
  text-align: justify;
  text-justify: inter-ideograph;
}

.read-footer {
  text-align: center;
  font-family: var(--ui-font);
  font-size: 0.72rem;
  color: var(--muted);
  padding: 1rem var(--read-pad-x) 2rem;
  max-width: var(--read-max);
  margin: 0 auto;
}

/* —— 工具抽屜（靠右；閱讀區不變暗、不加遮罩） —— */
.tool-sheet {
  position: fixed;
  z-index: 100;
  top: 0;
  right: 0;
  left: auto;
  width: var(--tool-sheet-w);
  max-width: 100%;
  height: 100%;
  height: 100dvh;
  background: var(--sheet);
  color: var(--fg);
  border-left: 1px solid var(--border);
  border-right: 0;
  box-shadow: -8px 0 28px var(--shadow);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  font-family: var(--ui-font);
  contain: layout style;
}

.tool-sheet.is-on {
  transform: translateX(0);
}

.tool-sheet[hidden] {
  display: none !important;
}

.tool-sheet:not([hidden]) {
  display: flex;
}

.tool-sheet__head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elev) 80%, var(--sheet));
}

.tool-sheet__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.tool-sheet__close {
  margin: 0;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--muted);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.tool-tabs {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border-bottom: 1px solid var(--border);
}

.tool-tabs button {
  margin: 0;
  padding: 0.55rem 0.35rem;
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  line-height: 1.25;
}

.tool-tabs button:last-child {
  border-right: 0;
}

.tool-tabs button[aria-selected="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}

.tool-panels {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tool-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.7rem 0.85rem 1rem;
  -webkit-overflow-scrolling: touch;
}

.tool-panel.is-hidden {
  display: none !important;
}

.tool-lead {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.55;
}

.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.tool-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.65rem;
}

.tool-field label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.tool-grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

select,
input[type="text"],
input[type="search"] {
  font: inherit;
  font-size: 0.88rem;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--fg);
  width: 100%;
}

.btn {
  font: inherit;
  font-size: 0.86rem;
  font-weight: 700;
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--border) 65%, var(--accent));
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
}

.btn:hover {
  filter: brightness(0.98);
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}

.btn-compact {
  padding: 0.35rem 0.55rem;
  font-size: 0.78rem;
}

.ref-row {
  display: flex;
  gap: 0.35rem;
  align-items: stretch;
}

.ref-row .btn {
  flex-shrink: 0;
  width: auto;
}

.theme-seg {
  display: flex;
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
  margin-top: 0.35rem;
}

.theme-seg button {
  flex: 1;
  margin: 0;
  border: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  padding: 0.4rem 0.35rem;
  cursor: pointer;
}

.theme-seg button:last-child {
  border-right: 0;
}

.theme-seg button[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.font-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.font-row .btn {
  min-width: 2.4rem;
}

.font-row span {
  font-size: 0.75rem;
  color: var(--muted);
  min-width: 2.75rem;
  text-align: center;
}

.book-index-stack {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 0.35rem;
}

.book-index-group-title {
  margin: 0 0 0.35rem;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--accent);
}

.book-index-subgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(3rem, 1fr));
  gap: 0.35rem;
}

.book-pill {
  margin: 0;
  padding: 0.4rem 0.2rem;
  font: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev);
  color: var(--fg);
  cursor: pointer;
}

.book-pill:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.book-pill.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.kw-meta {
  margin: 0.45rem 0 0.35rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.search-hit {
  margin: 0;
  padding: 0.55rem 0.65rem;
  text-align: left;
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--fg);
  font: inherit;
  font-size: 0.8rem;
  line-height: 1.45;
  cursor: pointer;
}

.search-hit:hover {
  border-color: var(--accent);
}

.search-hit strong {
  display: block;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 0.2rem;
}

.search-hit .excerpt {
  display: block;
  color: var(--fg);
}

mark.search-mark {
  background: var(--hit);
  color: inherit;
  font-weight: 700;
  padding: 0 0.08em;
  border-radius: 2px;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%) translateY(140%);
  z-index: 120;
  padding: 0.55rem 1rem;
  border-radius: 10px;
  background: var(--fg);
  color: var(--bg);
  font-family: var(--ui-font);
  font-size: 0.82rem;
  box-shadow: 0 6px 28px var(--shadow);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.2s ease;
  pointer-events: none;
  max-width: min(90vw, 22rem);
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

#to-top {
  position: fixed;
  right: max(0.75rem, env(safe-area-inset-right));
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  z-index: 40;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--accent);
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: 0 2px 14px var(--shadow);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

#to-top.visible {
  opacity: 1;
  visibility: visible;
}
