/* ---------- Colour theme ---------- */
:root {
  --bg: #f1f2f4;
  --panel: #fff;
  --text: #222;
  --muted: #999;
  --border: #d8dadf;
  --hover: #f3f6fb;
  --accent: #3b6fd8;
  --mark: #ffe58a;
  --diff-added: #d4f5d4;
  --diff-removed: #c0392b;
  --font-size: 18px;
}

[data-theme="dark"] {
  color-scheme: dark; /* dark scrollbars, dropdown lists and form controls */
  --bg: #17181b;
  --panel: #222327;
  --text: #ddd;
  --muted: #777;
  --border: #36383d;
  --hover: #2b2f38;
  --accent: #7aa2f7;
  --mark: #6b5a1e;
  --diff-added: #234a2a;
  --diff-removed: #e57373;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

/* dvh leaves out the mobile address bar */
body { height: 100dvh; }

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}

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

/* No double-tap zoom, so tapping < > quickly turns pages */
button, select, input { touch-action: manipulation; }

select {
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
  font-size: 13px;
  cursor: pointer;
}

[hidden] { display: none !important; }

.spacer { flex: 1; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover { background: var(--hover); color: var(--accent); }

.icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Light mode shows a moon (switch to dark), dark mode a sun */
.icon-sun, [data-theme="dark"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: block; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
}

.topbar > select { margin-right: 6px; }

.menu { position: relative; }

/* Centred between the left and right controls */
.search {
  position: relative;
  flex: 1;
  display: flex;
  justify-content: center;
}

#search-input {
  width: min(420px, 100%);
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  color: inherit;
  font: inherit;
  font-size: 13px;
}

.search-results {
  position: absolute;
  top: 34px;
  z-index: 20;
  width: min(600px, 90vw);
  max-height: 70vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
  font-size: 14px;
}

.search-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-right: 8px;
}

.search-header .search-status { flex: 1; }

.scope-btn {
  padding: 1px 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: none;
  font-size: 12px;
  cursor: pointer;
}

.scope-btn.on {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--panel);
}

.search-status { padding: 8px 12px; color: var(--muted); }

.search-result {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-top: 1px solid var(--border);
  background: none;
  text-align: left;
  line-height: 1.5;
  cursor: pointer;
}

.search-result:hover { background: var(--hover); }
.result-ref { margin-right: 8px; font-weight: 600; }
.result-version { color: var(--muted); font-size: 12px; }
.result-text { display: block; }

mark {
  border-radius: 2px;
  background: var(--mark);
  color: inherit;
}

.popup {
  z-index: 10;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .15);
  font-size: 13px;
}

.text-btn {
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: none;
  font-size: 13px;
  cursor: pointer;
}

.text-btn:hover { background: var(--hover); }

.font-popup {
  position: absolute;
  top: 30px;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  white-space: nowrap;
}

.bookmarks-popup {
  position: absolute;
  top: 30px;
  right: 0;
  width: min(360px, 92vw);
}

#bookmark-list {
  max-height: 60vh;
  overflow-y: auto;
}

.bookmark-item {
  display: flex;
  align-items: flex-start;
  border-bottom: 1px solid var(--border);
}

.bookmark-item .icon-btn { margin: 6px; font-size: 12px; color: var(--muted); }

.bookmark-open {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border: none;
  background: none;
  text-align: left;
  line-height: 1.5;
  cursor: pointer;
}

.bookmark-open:hover { background: var(--hover); }

.bookmark-note {
  display: block;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.popup-footer {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
}

.verse-menu {
  position: fixed;
  z-index: 30;
  width: 270px;
  padding: 10px;
}

.verse-menu-title { margin-bottom: 8px; font-weight: 600; }

.verse-menu-actions {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

#note-input {
  display: block;
  width: 100%;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: inherit;
  font: inherit;
  resize: vertical;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 40;
  padding: 6px 14px;
  border-radius: 16px;
  background: var(--text);
  color: var(--panel);
  font-size: 14px;
  transform: translateX(-50%);
  pointer-events: none;
}

/* ---------- Panes ---------- */
.panes {
  --split: 0.5;
  flex: 1;
  min-height: 0;
  display: flex;
  padding: 0 6px 6px;
}

.pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
}

/* Together the two grow to fill the row */
.pane:first-child { flex-grow: var(--split); }
.pane:last-child { flex-grow: calc(1 - var(--split)); }
/* A flex-grow below 1 only takes that share of the space, so a pane left alone needs a full 1 */
.panes.single .pane { flex-grow: 1; }

/* Also the gap between the panes */
.pane-divider {
  flex: none;
  width: 8px;
  cursor: col-resize;
  touch-action: none;
}

.pane-divider:hover, .pane-divider:active {
  background: linear-gradient(var(--accent), var(--accent)) center / 2px 100% no-repeat;
}

.pane-head {
  display: flex;
  align-items: center;
  padding: 6px 8px 2px;
}

.pane-head select { padding-left: 2px; border: none; font-weight: 600; }
.pane-head .icon-btn { width: 26px; height: 26px; color: var(--muted); }
.pane-head .icon { width: 16px; height: 16px; }

.progress {
  margin-left: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

/* Makes offsetTop relative to the pane (scroll sync) */
.pane-body {
  position: relative;
  flex: 1;
  overflow-y: auto;
  padding: 8px 18px 40px 14px;
  font-size: var(--font-size);
  line-height: 2;
}

/* Set by alignVerses */
.pane-body::after {
  content: "";
  display: block;
  height: var(--tail, 0px);
}

.verse {
  margin: 0;
  padding: 0 4px;
  border-radius: 3px;
}

.verse.highlighted { background: var(--hover); }

/* A verse reached from a link, search result or bookmark */
.verse.target {
  background: var(--mark);
  transition: background 1s;
}

.verse-number {
  position: relative;
  margin-right: 2px;
  color: var(--accent);
  opacity: .8;
  font-size: .55em;
  vertical-align: .6em;
  user-select: none;
  cursor: pointer;
}

/* A larger tap area for the tiny number */
.verse-number::before {
  content: "";
  position: absolute;
  inset: -10px -8px;
}

.verse-number:hover { text-decoration: underline; }

.verse.bookmarked .verse-number {
  padding: 0 3px;
  border-radius: 3px;
  background: var(--accent);
  color: var(--panel);
  opacity: 1;
}

.note-marker {
  margin-left: 4px;
  color: var(--accent);
  font-size: .75em;
  cursor: pointer;
  user-select: none;
}

/* 我的翻译 against 新标点和合本 */
ins.diff {
  border-radius: 2px;
  background: var(--diff-added);
  text-decoration: none;
}

del.diff {
  color: var(--diff-removed);
  opacity: .8;
  font-size: .85em;
}

.note {
  padding: 20px 4px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.note code {
  padding: 1px 4px;
  border-radius: 3px;
  background: var(--hover);
}

/* Phones: the search box gets its own row, and the panes are stacked */
@media (max-width: 700px) {
  /* Row 1: dropdowns and buttons, never wrapping (the chapter dropdown shrinks). Row 2: search. */
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, max-content) minmax(0, 1fr) repeat(7, auto);
    align-items: center;
    gap: 6px 0;
    padding: 6px;
  }
  .topbar > * { grid-row: 1; }
  .topbar > :not(:first-child) { margin-left: 2px; }
  .topbar > select { margin-right: 0; }
  /* The book list gives up space first, so the chapter number stays visible */
  #book-select { max-width: clamp(70px, calc(100vw - 260px), 130px); }
  #chapter-select { justify-self: start; max-width: 100%; }
  .search { grid-row: 2; grid-column: 1 / -1; margin-left: 0 !important; }
  #search-input { width: 100%; }
  .search-results { width: calc(100vw - 12px); }
  .panes { flex-direction: column; padding: 0 4px 4px; }
  .pane { min-height: 0; }
  .pane-divider { width: auto; height: 8px; cursor: row-resize; }
  .pane-divider:hover, .pane-divider:active { background-size: 100% 2px; }
  .pane-body { padding: 4px 12px 30px 8px; }
  .icon-btn { width: 30px; height: 32px; }
  /* 16px stops iOS from zooming in */
  select, #search-input, #note-input { font-size: 16px; }
  .bookmarks-popup { position: fixed; top: 44px; left: 6px; right: 6px; width: auto; }
  /* The verse menu becomes a bottom sheet */
  .verse-menu {
    top: auto !important;
    right: 0;
    bottom: 0;
    left: 0 !important;
    width: auto;
    padding: 14px;
    border-radius: 12px 12px 0 0;
  }
  .verse-menu .text-btn { flex: 1; padding: 8px 4px; }
}
