:root {
    --bg: #f7f6f2;
    --surface: #ffffff;
    --surface-2: #f0eee8;
    --text: #1f2328;
    --muted: #6b6f76;
    --border: #e2dfd6;
    --accent: #4f46e5;
    --accent-text: #ffffff;
    --accent-soft: #eef0ff;
    --hl: #fff3c4;
    --mark: #ffe58a;
    --verse-size: 18px;
    --radius: 10px;
    --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "PT Serif", serif;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #14161a;
    --surface: #1c1f24;
    --surface-2: #252930;
    --text: #e6e6e3;
    --muted: #9aa0a8;
    --border: #2f343c;
    --accent: #8b8cf7;
    --accent-text: #14161a;
    --accent-soft: #262a45;
    --hl: #3a3420;
    --mark: #6b5a17;
    color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 var(--sans);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 860px; margin: 0 auto; padding: 16px 16px 64px; }

/* ── top bar ── */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 8px;
    padding: 8px 16px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; font-size: 1.1rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.spacer { flex: 1; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 40px; padding: 8px 16px;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text);
    font: inherit; cursor: pointer;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: .9rem; }
.icon-btn {
    min-width: 40px; min-height: 40px;
    border: 0; border-radius: var(--radius); background: transparent; color: var(--text);
    font-size: 1.2rem; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.link-btn { border: 0; background: none; color: var(--accent); font: inherit; padding: 0; cursor: pointer; }

.muted { color: var(--muted); }
.notice { padding: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }

h2 { font-size: 1.15rem; margin: 28px 0 12px; }

/* ── settings ── */
.settings {
    position: fixed; z-index: 30; top: 58px; right: 16px;
    width: min(340px, calc(100vw - 32px));
    max-height: calc(100vh - 80px); overflow: auto;
    padding: 4px 16px 16px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: 0 12px 32px rgba(0, 0, 0, .18);
}
.settings h2 { margin: 12px 0 4px; font-size: 1rem; }
.settings h3 { margin: 16px 0 8px; font-size: .95rem; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; border-bottom: 1px solid var(--border); cursor: pointer; }
.set-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }
.stepper { display: inline-flex; align-items: center; gap: 8px; }
.stepper output { min-width: 2ch; text-align: center; }

/* ── search ── */
.search { margin: 8px 0 16px; }
.search-row { display: flex; gap: 8px; }
.search-row input {
    flex: 1; min-width: 0; min-height: 48px; padding: 10px 14px;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text); font: inherit; font-size: 16px;
}
.search-row input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.search-opts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: inline-block; padding: 7px 12px; font-size: .9rem; }
.seg input:checked + span { background: var(--accent); color: var(--accent-text); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
select {
    min-height: 36px; max-width: 100%; padding: 4px 8px;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text); font: inherit; font-size: .9rem;
}

.results-head { font-size: 1rem; color: var(--muted); font-weight: 500; margin: 16px 0 8px; }
.result-list { list-style: none; margin: 0; padding: 0; }
.result-list li { margin-bottom: 8px; }
.result-list a {
    display: block; padding: 12px 14px; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.result-list a:hover { border-color: var(--accent); text-decoration: none; }
.result-ref { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; color: var(--accent); margin-bottom: 4px; }
.rel { font-weight: 400; color: var(--muted); font-size: .85rem; white-space: nowrap; }
.result-text { font-family: var(--serif); font-size: 1.05rem; }
mark { background: var(--mark); color: inherit; border-radius: 2px; }
.more-btn { display: block; margin: 12px auto; }

/* ── home ── */
.continue {
    display: flex; flex-direction: column; margin: 8px 0 0; padding: 14px 16px;
    background: var(--accent-soft); border-radius: var(--radius); color: var(--text);
}
.continue:hover { text-decoration: none; outline: 1px solid var(--accent); }
.continue .label { font-size: .85rem; color: var(--muted); }
.continue .ref { font-weight: 600; font-size: 1.1rem; }
.panel .marks { list-style: none; margin: 0; padding: 0; }
.marks li { display: flex; align-items: flex-start; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.marks li a { flex: 1; color: var(--text); }
.marks li b { color: var(--accent); }

.books { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.book { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.book-name { display: block; padding: 10px 12px 0; font-weight: 600; color: var(--text); }
.book-ch { display: block; padding: 0 12px 10px; font-size: .85rem; color: var(--muted); }
.book.open { grid-column: 1 / -1; border-color: var(--accent); }
.ch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; padding: 0 12px 12px; }
.ch-grid a {
    display: flex; align-items: center; justify-content: center; min-height: 40px;
    border: 1px solid var(--border); border-radius: 8px; color: var(--text); background: var(--bg);
}
.ch-grid a:hover { border-color: var(--accent); text-decoration: none; }

/* ── chapter ── */
.chapter-head { margin: 8px 0 12px; }
.crumb { font-size: .9rem; }
.chapter-head h1 { margin: 4px 0 6px; font-family: var(--serif); font-size: 1.9rem; line-height: 1.2; }
.chapter-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.chapter-nav { display: flex; justify-content: space-between; gap: 8px; margin: 12px 0; }

.chapter { font-family: var(--serif); font-size: var(--verse-size); line-height: 1.65; }
.verse { position: relative; padding: 6px 8px; margin: 0 -8px; border-radius: 8px; cursor: pointer; scroll-margin-top: 80px; }
.verse:hover { background: var(--surface); }
.verse.hl { background: var(--hl); }
.verse.marked .vn::after { content: "★"; font-size: .7em; margin-left: 2px; color: var(--accent); }
.vn { font-family: var(--sans); font-size: .7em; font-weight: 600; color: var(--muted); vertical-align: .35em; margin-right: 2px; }
.vn:hover { color: var(--accent); text-decoration: none; }
.vref { font-family: var(--sans); font-size: .75em; color: var(--muted); }
.xr { font-family: var(--sans); font-size: .82rem; color: var(--muted); margin-top: 2px; line-height: 1.5; }
.xr-label { margin-right: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; font-family: var(--sans); }

.chapter.parallel .verse { display: grid; grid-template-columns: 1fr 1fr; column-gap: 20px; }
.chapter.parallel .vt2 { color: var(--muted); }
.chapter.parallel .xr, .chapter.parallel .actions { grid-column: 1 / -1; }

body.no-refs .xr { display: none; }

/* reading mode: continuous text, no clutter */
body.reading .chapter:not(.parallel) .verse { display: inline; padding: 0; margin: 0; cursor: text; }
body.reading .chapter:not(.parallel) .verse .vt { display: inline; }
body.reading .verse:hover { background: none; }
body.reading .verse.hl { background: var(--hl); }
body.reading .xr, body.reading .actions { display: none; }
body.reading .chapter { line-height: 1.8; }

.toast {
    position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 40;
    padding: 10px 16px; border-radius: var(--radius);
    background: var(--text); color: var(--bg); font-size: .9rem;
}

@media (max-width: 600px) {
    .chapter-head h1 { font-size: 1.5rem; }
    .chapter.parallel .verse { grid-template-columns: 1fr; }
    .chapter.parallel .vt2 { margin-top: 4px; padding-left: 10px; border-left: 2px solid var(--border); }
    .books { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
    .search-row .btn { padding: 8px 12px; }
}
