:root {
  --bg: #141416; --panel: #1e1e21; --text: #ececee; --muted: #8a8a8e; --line: #333338;
  color-scheme: dark;
}
/* Dark is the default; the toggle can switch to light (data-theme on <html>). */
:root[data-theme="light"] {
  --bg: #f6f5f2; --panel: #ffffff; --text: #1d1d1f; --muted: #8a8a8e; --line: #dcdcdf;
  color-scheme: light;
}
/* Accent colours (data-accent on <html>; also on each Settings swatch so it shows its own colour).
   light-dark() picks the light or dark shade from the active color-scheme.
   --accent: buttons/fills, --pivot: the highlighted letter, --hl: current-word highlight. */
:root, [data-accent="red"] {
  --accent: light-dark(#c62f28, #c93a32); --pivot: light-dark(#e0322b, #ff5a4f); --hl: light-dark(#f7cfcb, #7d2e29);
}
[data-accent="orange"] {
  --accent: light-dark(#c2570c, #c95f14); --pivot: light-dark(#e8650f, #ff8a3d); --hl: light-dark(#fbd9c0, #7a3a12);
}
[data-accent="green"] {
  --accent: light-dark(#1f8a4c, #1f8a4c); --pivot: light-dark(#1f9d55, #4ccf7f); --hl: light-dark(#c8ecd5, #1d5a36);
}
[data-accent="teal"] {
  --accent: light-dark(#0f7f86, #12858c); --pivot: light-dark(#0e949c, #3cc7cf); --hl: light-dark(#c3ebee, #155a5e);
}
[data-accent="blue"] {
  --accent: light-dark(#2a62d6, #3366d6); --pivot: light-dark(#2f6fe8, #6b9bff); --hl: light-dark(#cfdcfa, #24407a);
}
[data-accent="purple"] {
  --accent: light-dark(#7a3fc7, #7e47cc); --pivot: light-dark(#8b4fe0, #b38bff); --hl: light-dark(#e2d3f7, #4b2f78);
}
[data-accent="pink"] {
  --accent: light-dark(#c42a72, #c8327a); --pivot: light-dark(#e0368a, #ff6aa8); --hl: light-dark(#f8cde0, #74244a);
}
* { box-sizing: border-box; }
html { touch-action: manipulation; } /* no double-tap zoom; scrolling still works */
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
main { max-width: 820px; margin: 0 auto; padding: 32px 16px; }
h1 { font-size: 20px; font-weight: 600; margin: 0 0 20px; }

.reader {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 56px 0; position: relative; user-select: none;
}
/* guide ticks above and below the pivot column */
.reader::before, .reader::after {
  content: ""; position: absolute; left: 50%; width: 2px; height: 14px;
  background: var(--line); transform: translateX(-1px);
}
.reader::before { top: 24px; }
.reader::after { bottom: 24px; }
.word {
  display: grid; grid-template-columns: 1fr auto 1fr;
  font: 500 clamp(32px, 7vw, 56px)/1.2 Georgia, "Times New Roman", serif;
  white-space: pre;
  min-height: 1.2em; /* one line tall even with no word, so the box doesn't jump when text loads */
}
.word .l { text-align: right; }
.word .p { color: var(--pivot); }
.word .r { text-align: left; }
.word.placeholder { color: var(--muted); } /* the pivot letter keeps its accent colour */

.progress { height: 4px; background: var(--line); border-radius: 2px; margin: 16px 0 6px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); }
.status { display: grid; grid-template-columns: 1fr auto 1fr; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
#remaining { text-align: right; }
/* Chapter reading time: shown only while stopped, so nothing ticks while you read. */
#timer { display: inline-flex; align-items: center; gap: 4px; }
#timer svg { width: 13px; height: 13px; }
#timer.hidden { visibility: hidden; }
/* ✓ after the time for chapters already read (tooltip: "Read"). */
#readMark { display: inline-flex; align-items: center; gap: 4px; margin-left: 2px; }
#readMark svg { color: var(--pivot); }
#readMark[hidden] { display: none; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 20px 0; }
.buttons { display: flex; gap: 12px; }
button {
  font: inherit; padding: 8px 16px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button svg { width: 16px; height: 16px; flex: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; min-width: 136px; }
input { accent-color: var(--accent); } /* slider and checkbox */
/* Red focus ring instead of the browser's default blue. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
header h1 { margin: 0; user-select: none; -webkit-tap-highlight-color: transparent; }
header h1 .bar { color: var(--pivot); }
.header-actions { display: flex; gap: 4px; }
.icon { padding: 6px; border: none; background: none; color: var(--muted); line-height: 0; }
.icon:hover { color: var(--text); }
.icon[hidden] { display: none; }
/* Shared tooltip for anything with data-tip (header icons, chapter boxes). It's a popover, so it sits
   in the top layer above open dialogs; app.js positions it below (or above) the item, kept on screen. */
#tip {
  position: fixed; inset: auto; margin: 0; padding: 5px 9px; border: none; border-radius: 7px; overflow: visible;
  font: 500 12px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; white-space: nowrap;
  color: var(--panel); background: var(--text); box-shadow: 0 4px 14px rgb(0 0 0 / 0.2); pointer-events: none;
}
#tip:popover-open { animation: tip-in 0.15s ease-out; }
@keyframes tip-in { from { opacity: 0; translate: 0 var(--tip-shift, -4px); } }
#tip[data-side="above"] { --tip-shift: 4px; }
#tip::before {
  content: ""; position: absolute; left: var(--arrow-x, 50%); translate: -50% 0; border: 5px solid transparent;
}
#tip[data-side="below"]::before { bottom: 100%; border-top: 0; border-bottom-color: var(--text); }
#tip[data-side="above"]::before { top: 100%; border-bottom: 0; border-top-color: var(--text); }
#devMode[aria-pressed="true"] { color: var(--accent); }
.icon svg { width: 22px; height: 22px; }

dialog {
  padding: 0; width: min(360px, calc(100% - 32px));
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog .inner { padding: 16px 20px 20px; }
dialog .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
dialog h2 { font-size: 17px; margin: 0; }
dialog .sub { color: var(--muted); font-size: 13px; }
#progressCount .num { color: var(--pivot); font-weight: 600; }
dialog .field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; font-size: 14px; color: var(--muted); }
dialog .field select { width: 100%; }
dialog .field .opt { color: var(--text); } /* options read as normal text under the grey section name */
dialog .row { display: flex; gap: 8px; }
dialog .row button { flex: 1; font-size: 14px; }
/* Reset: always red, whatever the accent colour, since it deletes data. */
:root { --danger: light-dark(#c62f28, #ff5a4f); }
dialog .danger-outline { font-size: 14px; color: var(--danger); }
dialog .danger { background: var(--danger); border-color: var(--danger); color: #fff; }
dialog .danger:disabled { opacity: 0.4; cursor: default; }
dialog .warn { margin: 0 0 16px; font-size: 14px; line-height: 1.5; }
dialog input[type=text] {
  font: inherit; color: var(--text); background: var(--panel); padding: 7px 12px;
  border: 1px solid var(--line); border-radius: 8px;
}
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 30px; height: 30px; padding: 0; border-radius: 50%; border: none; background: var(--accent); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }

/* Progress: every chapter as a numbered box; filled = read. */
dialog.wide { width: min(980px, calc(100% - 32px)); max-height: calc(100% - 64px); overflow: auto; }
dialog.wide .head { position: sticky; top: 0; z-index: 1; background: var(--panel); padding: 16px 0 12px; margin: -16px 0 4px; }
dialog.wide .head { flex-wrap: wrap; align-items: flex-start; }
/* One pill-shaped bar; the Old and New Testament sections are divided by a thin line. */
.split-bar {
  flex-basis: 100%; display: flex; height: 28px; margin-top: 10px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 999px; overflow: hidden;
}
.split-bar .seg { position: relative; min-width: 0; overflow: hidden; }
.split-bar .seg + .seg { border-left: 1px solid var(--line); }
.split-bar .fill { position: absolute; inset: 0 auto 0 0; overflow: hidden; background: color-mix(in srgb, var(--accent) 78%, black); }
.split-bar .fill .label { position: absolute; inset: 0 auto 0 0; color: #fff; }
.split-bar .fill .count { color: rgb(255 255 255 / 0.75); }
.split-bar .label {
  position: relative; display: flex; justify-content: space-between; gap: 8px;
  padding: 0 14px; line-height: 26px; font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.split-bar .name { overflow: hidden; text-overflow: ellipsis; }
.split-bar .count { flex: none; color: color-mix(in srgb, var(--text) 55%, transparent); }
.split-bar .short { display: none; }
@media (max-width: 720px) {
  .split-bar .full { display: none; }
  .split-bar .short { display: inline; }
  .split-bar .label { padding: 0 10px; }
  .split-bar .seg { min-width: 116px; } /* the NT section is only ~22% wide; keep its label readable */
}
.testaments { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }
.testaments h3 { font-size: 22px; margin: 4px 0 8px; }
.testaments h4 { font-size: 14px; margin: 14px 0 6px; }
.chapters { display: flex; flex-wrap: wrap; gap: 6px; }
.chapters button {
  width: 36px; height: 36px; padding: 0; border-radius: 8px; font-size: 13px; font-variant-numeric: tabular-nums;
  background: transparent; border: 1.5px solid var(--line);
}
.chapters button:hover { border-color: var(--muted); }
.chapters button.read { background: var(--accent); border-color: var(--accent); color: #fff; }
.chapters button.current { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--text); }
.chapters button:disabled { opacity: 0.3; cursor: default; }
@media (max-width: 720px) {
  .testaments { grid-template-columns: 1fr; gap: 8px; }
}
.opt { display: flex; align-items: center; gap: 10px; cursor: pointer; }
/* Custom checkbox: rounded box with a smaller tick inset from the edges. */
.opt input {
  appearance: none; flex: none; width: 22px; height: 22px; margin: 0; cursor: pointer;
  display: grid; place-content: center;
  border: 2px solid var(--muted); border-radius: 7px; background: var(--panel);
}
.opt input:checked { background: var(--accent); border-color: var(--accent); }
.opt input:checked::after {
  content: ""; width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0;
  transform: translateY(-1px) rotate(45deg);
}
.wpm { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.wpm input { width: 180px; }
.wpm output { font-variant-numeric: tabular-nums; min-width: 72px; }

/* Own chevron instead of the native arrow, so it gets the same inset as the text. */
select {
  appearance: none; font: inherit; padding: 7px 38px 7px 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); color: var(--text);
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a8a8e' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center / 16px;
}
.pickers { display: flex; gap: 8px; margin-bottom: 8px; }
.pickers #book { flex: 1; min-width: 0; }
/* Previous/next chapter: square buttons the same height as the dropdowns. */
.pickers .step { width: 40px; padding: 0; flex: none; }
.pickers .step svg { width: 18px; height: 18px; }
.pickers .step:disabled, .pickers select:disabled { opacity: 0.4; cursor: default; }
.attribution { margin: 8px 0 0; color: var(--muted); font-size: 12px; white-space: pre-line; }
/* The textarea is transparent over a backdrop that mirrors its text, so the current word can be highlighted. */
.text-wrap { position: relative; background: var(--panel); border-radius: 8px; }
textarea, .backdrop {
  font: inherit; padding: 12px; border: 1px solid transparent; border-radius: 8px;
  white-space: pre-wrap; overflow-wrap: break-word; scrollbar-gutter: stable;
}
textarea {
  position: relative; display: block; width: 100%; min-height: 200px; resize: vertical;
  color: var(--text); background: transparent; border-color: var(--line);
}
textarea:focus { outline: none; border-color: var(--accent); } /* softer than a ring */
textarea::placeholder { color: var(--muted); }
.backdrop { position: absolute; inset: 0; overflow: hidden; color: transparent; }
.backdrop mark { background: var(--hl); color: transparent; border-radius: 3px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 8px; }
kbd {
  display: inline-flex; align-items: center; justify-content: center; vertical-align: middle;
  height: 20px; padding: 0 5px; line-height: 1;
  font: 12px ui-monospace, monospace; border: 1px solid var(--line); border-radius: 5px;
}
/* Arrow keys: square, with smaller system-font arrows (monospace arrows sit low). */
kbd.arrow { width: 20px; padding: 0; font: 10px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }

/* Phones: keep the three control buttons on one row; WPM wraps below. */
@media (max-width: 600px) {
  .buttons { width: 100%; gap: 8px; }
  .buttons button { flex: 1 1 auto; min-width: 0; padding: 8px 10px; white-space: nowrap; }
  .wpm { margin-left: 0; width: 100%; }
  .wpm input { flex: 1; width: auto; }
}
/* Narrow phones: icon-only Sentence and Restart so the row fits. */
@media (max-width: 400px) {
  .buttons .label { display: none; }
  .buttons button:not(.primary) { flex: none; padding: 8px 14px; }
}
/* Touch-only devices have no keyboard shortcuts to show. */
@media (hover: none) and (pointer: coarse) {
  .hint { display: none; }
}
dialog .credits { margin: 4px 0 0; font-size: 12px; color: var(--muted); opacity: 0.55; }
dialog .credits a { color: inherit; }

/* "New version available" notice, bottom centre. */
.toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); translate: -50% 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 16px; white-space: nowrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.3); font-size: 14px;
  animation: toast-in 0.2s ease-out;
}
.toast[hidden] { display: none; }
.toast .primary { min-width: 0; padding: 6px 14px; border-radius: 999px; font-size: 14px; }
@keyframes toast-in { from { opacity: 0; translate: -50% 8px; } }
