/* ---------- tokens ---------- */
:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-2: #f3f1ec;
  --text: #1f1d1a;
  --muted: #6b665e;
  --line: #e4e0d8;
  --accent: #8a3b12;
  --accent-contrast: #ffffff;
  --accent-soft: #f6e7dc;
  --danger: #b42318;
  --vn: #a0522d;
  --shadow: 0 10px 30px rgba(31, 29, 26, .14), 0 2px 6px rgba(31, 29, 26, .08);
  --hl-yellow: #fde68a; --hl-green: #bbf7d0; --hl-blue: #bfdbfe; --hl-pink: #fbcfe8; --hl-orange: #fed7aa;
  --flash: #fff2b3;
  --reader-font: 'Noto Serif Malayalam', 'Nirmala UI', 'Kartika', serif;
  --ui-font: 'Noto Sans Malayalam', 'Nirmala UI', system-ui, sans-serif;
  --fs: 20px;
  --lh: 1.9;
  --radius: 14px;
  color-scheme: light;
}
:root[data-theme="sepia"] {
  --bg: #f4ecd8; --surface: #fbf5e6; --surface-2: #ebe1c8; --text: #3b2f23; --muted: #7a6a55;
  --line: #dccfb2; --accent: #7a4a1c; --accent-soft: #eadcc0; --vn: #8b5a2b; --flash: #f5dc9a;
}
:root[data-theme="dark"] {
  --bg: #121212; --surface: #1c1c1e; --surface-2: #26262a; --text: #e8e6e1; --muted: #a09b92;
  --line: #34343a; --accent: #f0a868; --accent-contrast: #1a1208; --accent-soft: #3a2a1c; --danger: #ff8a7a;
  --vn: #e0a070; --shadow: 0 10px 30px rgba(0, 0, 0, .5);
  --hl-yellow: rgba(250, 204, 21, .32); --hl-green: rgba(74, 222, 128, .28); --hl-blue: rgba(96, 165, 250, .32);
  --hl-pink: rgba(244, 114, 182, .3); --hl-orange: rgba(251, 146, 60, .32); --flash: rgba(250, 204, 21, .25);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #121212; --surface: #1c1c1e; --surface-2: #26262a; --text: #e8e6e1; --muted: #a09b92;
    --line: #34343a; --accent: #f0a868; --accent-contrast: #1a1208; --accent-soft: #3a2a1c; --danger: #ff8a7a;
    --vn: #e0a070; --shadow: 0 10px 30px rgba(0, 0, 0, .5);
    --hl-yellow: rgba(250, 204, 21, .32); --hl-green: rgba(74, 222, 128, .28); --hl-blue: rgba(96, 165, 250, .32);
    --hl-pink: rgba(244, 114, 182, .3); --hl-orange: rgba(251, 146, 60, .32); --flash: rgba(250, 204, 21, .25);
    color-scheme: dark;
  }
}
:root[data-font="noto-sans"] { --reader-font: 'Noto Sans Malayalam', 'Nirmala UI', sans-serif; }
:root[data-font="manjari"] { --reader-font: 'Manjari', 'Nirmala UI', sans-serif; }
:root[data-font="gayathri"] { --reader-font: 'Gayathri', 'Nirmala UI', sans-serif; }

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--ui-font); font-size: 16px; line-height: 1.5;
  transition: background-color .2s, color .2s;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.spacer { flex: 1; }
.hint { color: var(--muted); font-size: 13px; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 50%;
  border: 0; background: transparent; color: var(--text);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn.sm svg { width: 18px; height: 18px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; min-height: 38px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-size: 15px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:disabled { opacity: .45; cursor: default; filter: none; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 14px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 4px; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid transparent; transition: border-color .2s, transform .25s;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar-right { margin-left: auto; display: flex; align-items: center; }
/* shown while there is no internet (the app keeps working from its offline copy) */
.net-pill {
  font-size: 12px; font-weight: 600; line-height: 1; padding: 5px 9px; margin-right: 2px; border-radius: 999px;
  color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap;
}
.net-pill[hidden] { display: none; }
.ref-btn {
  position: absolute; left: 50%; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 4px; padding: 7px 14px 7px 18px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  font-weight: 700; font-size: 16px; max-width: calc(100% - 200px);
}
.ref-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref-btn svg { width: 18px; height: 18px; color: var(--muted); }
.ref-btn:hover { background: var(--surface-2); }

/* ---------- reader ---------- */
main { padding: 8px 16px 140px; }
.reader {
  max-width: 720px; margin: 0 auto;
  font-family: var(--reader-font); font-size: var(--fs); line-height: var(--lh);
}
.reader .ch-title { text-align: center; margin: 28px 0 24px; font-family: var(--ui-font); }
.reader .ch-title small { display: block; color: var(--muted); font-size: 15px; letter-spacing: .02em; }
.reader .ch-title span { display: block; font-size: 2.1em; font-weight: 700; line-height: 1.3; font-family: var(--reader-font); }
.reader h3.sec {
  font-family: var(--ui-font); font-size: .86em; font-weight: 700; line-height: 1.5;
  margin: 1.6em 0 .5em; color: var(--text);
}
.reader p { margin: 0 0 .9em; text-align: start; }
.reader .v { border-radius: 4px; transition: background-color .25s; -webkit-tap-highlight-color: transparent; cursor: pointer; }
.reader .vn {
  font-family: var(--ui-font); font-size: .58em; font-weight: 700; color: var(--vn);
  vertical-align: super; line-height: 0; margin: 0 .22em 0 .1em; user-select: none;
}
.reader .v.sel { text-decoration: underline dotted var(--accent); text-decoration-thickness: 2px; text-underline-offset: .28em; }
.reader .v.flash { background: var(--flash); }
.reader .mark-icons { display: inline-flex; gap: 2px; vertical-align: middle; margin: 0 2px; }
.reader .mark-icons svg { width: .8em; height: .8em; color: var(--accent); }
.reader .mark-icons .note-ic { cursor: pointer; }
.reader.hide-numbers .vn { display: none; }
.reader.hide-headings h3.sec { display: none; }
.reader.layout-verse p { margin: 0; }
.reader.layout-verse .v { display: block; margin-bottom: .45em; }
.reader.layout-verse .v.cont { margin-top: -.45em; }
/* AI translation: Original | AI | താരതമ്യം under the chapter title; താരതമ്യം puts it under each verse */
.reader .ver-switch {
  display: flex; width: fit-content; margin: 14px auto 0; padding: 3px; gap: 2px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2);
}
.reader .ver-switch button {
  border: 0; background: transparent; color: var(--muted); font-family: var(--ui-font);
  font-size: 14px; font-weight: 600; line-height: 1.4; padding: 6px 16px; border-radius: 999px; min-height: 34px;
}
.reader .ver-switch button[aria-pressed="true"] { background: var(--accent); color: var(--accent-contrast); }
.reader .ver-switch button:not([aria-pressed="true"]):hover { color: var(--text); }
.reader .ver-switch .ver-off { display: inline-flex; align-items: center; padding: 6px 10px; }
.reader .ver-switch .ver-off svg { width: 16px; height: 16px; }
.reader.compare p { margin: 0; }
.reader.compare .v { display: block; margin-bottom: .8em; }
.reader.compare .v.cont { margin-top: -.8em; }
.reader .ai-line {
  display: block; margin-top: .25em; padding-left: .7em; border-left: 3px solid var(--accent-soft);
  color: var(--muted); font-size: .9em;
}
.reader .ai-line::before {
  content: 'AI'; font-family: var(--ui-font); font-size: .6em; font-weight: 700; color: var(--accent);
  margin-right: .5em; vertical-align: .15em; letter-spacing: .04em;
}
.reader .ai-line ins, .reader .ai-note ins { background: color-mix(in srgb, #2e7d32 22%, transparent); color: var(--text); text-decoration: none; border-radius: 3px; }
.ai-list-sum { color: var(--muted); font-size: 14px; margin: 2px 0 14px; line-height: 1.6; }
.book-group h4 small { font-weight: 500; opacity: .85; }
.reader .ai-note {
  font-family: var(--ui-font); font-size: 14px; line-height: 1.6; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin: 28px 0 0;
}
.reader .empty { text-align: center; color: var(--muted); padding: 60px 10px; font-family: var(--ui-font); }
.reader .ch-foot { display: flex; justify-content: space-between; gap: 10px; margin: 40px 0 0; font-family: var(--ui-font); font-size: 15px; }
.hl-yellow { background: var(--hl-yellow); } .hl-green { background: var(--hl-green); } .hl-blue { background: var(--hl-blue); }
.hl-pink { background: var(--hl-pink); } .hl-orange { background: var(--hl-orange); }
mark { background: var(--hl-yellow); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ---------- chapter nav ---------- */
.chapter-nav { position: fixed; inset: auto 0 0 0; pointer-events: none; z-index: 15; }
.fab {
  pointer-events: auto; position: absolute; bottom: max(20px, env(safe-area-inset-bottom));
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); box-shadow: var(--shadow);
  transition: opacity .2s, transform .2s;
}
.fab:hover { background: var(--surface-2); }
.fab:disabled { opacity: 0; pointer-events: none; }
#btnPrev { left: 16px; } #btnNext { right: 16px; }
@media (min-width: 900px) { #btnPrev { left: calc(50% - 420px); } #btnNext { right: calc(50% - 420px); } }
body.selecting .chapter-nav { opacity: 0; pointer-events: none; }

/* ---------- action bar ---------- */
.actionbar {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); z-index: 30;
  width: min(560px, 100%); background: var(--surface); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 18px 18px 0 0; box-shadow: var(--shadow); padding: 10px 14px max(12px, env(safe-area-inset-bottom));
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translate(-50%, 100%); } }
.actionbar-head { display: flex; align-items: center; justify-content: space-between; font-size: 15px; }
.swatches { display: flex; gap: 10px; padding: 8px 0 10px; overflow-x: auto; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; background-clip: padding-box; }
.swatch.none { background: var(--surface-2); }
.swatch.none svg { width: 16px; height: 16px; color: var(--muted); }
.swatch.active { border-color: var(--text); }
.actions { display: flex; gap: 4px; }
.actions button { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 2px; border: 0; background: transparent; border-radius: 10px; font-size: 12px; color: var(--text); }
.actions button:hover { background: var(--surface-2); }
.actions button.on svg { fill: var(--accent); stroke: var(--accent); }
.actions button:disabled { opacity: .35; cursor: default; }

/* ---------- dialogs ---------- */
dialog { border: 0; padding: 0; color: var(--text); background: var(--surface); max-width: none; max-height: none; }
dialog::backdrop { background: rgba(10, 8, 5, .42); }
dialog[open] { animation: fade .16s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } }

.sheet {
  width: min(680px, 100%); height: min(760px, 100dvh); margin: auto; border-radius: var(--radius);
  display: none; flex-direction: column; box-shadow: var(--shadow);
}
.sheet[open] { display: flex; }
@media (max-width: 700px) { .sheet { height: 100dvh; border-radius: 0; margin: 0; width: 100%; } }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 8px 14px; border-bottom: 1px solid var(--line); }
.sheet-body { flex: 1; overflow: auto; padding: 12px 14px 24px; overscroll-behavior: contain; }

.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 8px 12px; border-radius: 999px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }

input[type="text"], input[type="search"], input[type="number"], input[type="email"], input[type="password"], select, textarea {
  padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); min-height: 40px;
}
textarea { width: 100%; resize: vertical; line-height: 1.7; }

/* book picker: six short names per row under a coloured band per testament */
.book-group { margin: 0 0 14px; }
.book-group h4 { margin: 0; padding: 5px 8px; text-align: center; font-size: 15px; font-weight: 600; background: var(--accent); color: var(--accent-contrast); border-radius: 8px 8px 0 0; }
.book-grid { display: grid; grid-template-columns: repeat(6, 1fr); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 8px 8px; overflow: hidden; }
.book-grid button { min-width: 0; min-height: 50px; padding: 4px 1px; border: 0; border-radius: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--surface); font-size: 15px; font-weight: 700; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: clip; }
.book-grid button:nth-child(6n) { border-right: 0; }
.book-grid button:hover { background: var(--surface-2); }
.book-grid button.cur { background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.book-grid button:disabled { color: color-mix(in srgb, var(--muted) 55%, transparent); font-weight: 500; cursor: default; }
.book-grid button:disabled:hover { background: var(--surface); }
@media (max-width: 480px) {
  .book-group { margin-inline: -8px; }   /* use the sheet's side padding: 6 names must fit a phone width */
  .book-grid button { font-size: 12.5px; font-weight: 600; min-height: 46px; letter-spacing: -.01em; }
}
@media (max-width: 340px) { .book-grid button { font-size: 11px; letter-spacing: -.02em; white-space: normal; } }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 8px; }
.grid button { aspect-ratio: 1; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 16px; }
.grid button:hover { background: var(--surface-2); }
.grid button.cur { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.grid button.edited { box-shadow: inset 0 -3px 0 var(--accent); }
.grid button:disabled { opacity: .3; cursor: default; }
.picker-title { margin: 2px 0 12px; font-size: 18px; }

/* search */
.search-head { gap: 6px; }
.search-box { flex: 1; display: flex; align-items: center; gap: 8px; padding: 0 12px; border-radius: 12px; background: var(--surface-2); }
.search-box svg { color: var(--muted); width: 20px; height: 20px; }
.search-box input { flex: 1; border: 0; background: transparent; padding: 11px 0; min-width: 0; outline: none; font-size: 17px; }
.search-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
.search-opts select { min-height: 34px; padding: 4px 8px; }
.chk { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.chk input { width: 18px; height: 18px; accent-color: var(--accent); }
.result-summary { color: var(--muted); font-size: 14px; margin: 2px 0 10px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); background: var(--surface); padding: 3px 10px; border-radius: 999px; font-size: 13px; }
.chip:hover { background: var(--surface-2); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.result { display: block; width: 100%; text-align: start; border: 0; background: transparent; padding: 12px 10px; border-bottom: 1px solid var(--line); border-radius: 8px; }
.result:hover { background: var(--surface-2); }
.result .r-ref { font-weight: 700; color: var(--accent); font-size: 14px; margin-bottom: 2px; }
.result .r-text { font-family: var(--reader-font); font-size: 17px; line-height: 1.75; }
.ref-card { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; }
.ref-card .r-ref { font-size: 16px; }
.more { display: block; margin: 14px auto; }
.empty-state { text-align: center; color: var(--muted); padding: 40px 10px; }
.empty-state svg { width: 40px; height: 40px; opacity: .5; }
.recent { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tips { color: var(--muted); font-size: 14px; line-height: 1.9; margin-top: 18px; }
.tips b { color: var(--text); }

/* settings popover */
.popover {
  position: fixed; top: 56px; right: 10px; left: auto; margin: 0; width: min(360px, calc(100% - 20px));
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; border: 1px solid var(--line);
}
.popover::backdrop { background: transparent; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; font-size: 15px; }
.set-row.col { flex-direction: column; align-items: stretch; gap: 8px; }
.set-note { margin: 8px 0 0; padding-top: 8px; border-top: 1px solid var(--line); font-size: 12px; line-height: 1.6; }
.set-row input[type="range"] { flex: 1; max-width: 180px; accent-color: var(--accent); }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper output { min-width: 28px; text-align: center; font-weight: 700; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1; min-width: 70px; padding: 7px 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; }
.seg button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.themes .t-light { background: #fbfaf7; color: #1f1d1a; }
.themes .t-sepia { background: #f4ecd8; color: #3b2f23; }
.themes .t-dark { background: #1c1c1e; color: #e8e6e1; }
.themes button.on { outline: 2px solid var(--accent); outline-offset: 1px; }

/* drawer */
.drawer { margin: 0; height: 100dvh; width: min(330px, 88vw); inset: 0 auto 0 0; display: none; flex-direction: column; box-shadow: var(--shadow); }
.drawer[open] { display: flex; animation: slide .2s ease-out; }
@keyframes slide { from { transform: translateX(-100%); } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 12px 16px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand svg { width: 30px; height: 30px; color: var(--accent); }
.brand img { width: 32px; height: 32px; border-radius: 7px; flex: none; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.menu { overflow: auto; padding: 6px 8px 20px; }
.menu-label { font-size: 12px; font-weight: 700; color: var(--muted); padding: 14px 10px 4px; letter-spacing: .04em; }
.menu button { display: flex; align-items: center; gap: 12px; width: 100%; text-align: start; padding: 10px; border: 0; background: transparent; border-radius: 10px; font-size: 15px; }
.menu button:hover { background: var(--surface-2); }
.menu button svg { color: var(--muted); }
.menu button small { color: var(--muted); font-size: 12px; }
.menu button .count { margin-left: auto; color: var(--muted); font-size: 13px; }
.menu button.danger, .menu button.danger svg { color: var(--danger); }

/* modal */
.modal { width: min(520px, calc(100% - 24px)); margin: auto; border-radius: var(--radius); box-shadow: var(--shadow); }
.modal form { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.modal h2 { margin: 0; font-size: 18px; }
.modal-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.quote { margin: 0; padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 8px 8px 0; font-family: var(--reader-font); font-size: 16px; line-height: 1.7; max-height: 160px; overflow: auto; }

/* share sheet (js/app.js, openShare) */
.share-link { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.share-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.share-grid a, .share-grid button {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 2px; min-width: 0;
  border: 0; border-radius: 10px; background: transparent; color: var(--text); font-size: 12px; text-decoration: none; text-align: center;
}
.share-grid a:hover, .share-grid button:hover { background: var(--surface-2); }
.share-ic {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: var(--c, var(--surface-2)); color: #fff; font: 700 15px/1 system-ui, sans-serif;
}
.share-ic:not([style]) { color: var(--text); border: 1px solid var(--line); }
.share-ic svg { width: 20px; height: 20px; }
:root[data-theme="dark"] .share-ic[style*="#000"] { box-shadow: inset 0 0 0 1px var(--line); }
@media (max-width: 380px) { .share-grid { grid-template-columns: repeat(4, 1fr); } }

/* full-screen editor / upload */
.fullscreen { width: 100%; height: 100dvh; margin: 0; display: none; flex-direction: column; background: var(--bg); }
.fullscreen[open] { display: flex; }
.fs-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; }
.fs-head h2 { margin: 0; font-size: 18px; }
.ed-toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; font-size: 13px; }
.ed-help { color: var(--muted); }
.ed-view { margin-left: auto; flex-wrap: nowrap; }
.ed-view button { min-width: 0; padding: 4px 10px; }
.ed-warn { padding: 8px 14px; background: color-mix(in srgb, var(--danger) 10%, var(--surface)); color: var(--danger); font-size: 14px; border-bottom: 1px solid var(--line); }
.ed-panes { flex: 1; display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
.ed-panes textarea { height: 100%; border: 0; border-right: 1px solid var(--line); border-radius: 0; resize: none; padding: 16px; font-family: var(--reader-font); font-size: 17px; line-height: 1.8; background: var(--surface); }
.ed-preview { overflow: auto; padding: 0 20px 40px; font-size: 18px; max-width: none; }
.ed-panes.v-text { grid-template-columns: 1fr; } .ed-panes.v-text .ed-preview { display: none; }
.ed-panes.v-preview { grid-template-columns: 1fr; } .ed-panes.v-preview textarea { display: none; }
@media (max-width: 800px) {
  .ed-panes { grid-template-columns: 1fr; }
  .ed-panes:not(.v-preview) .ed-preview { display: none; }
  .ed-panes.v-preview textarea { display: none; }
  .ed-panes.v-preview .ed-preview { display: block; }
  .fs-head .btn span { display: none; }
  .ed-help { display: none; }
  .ed-view button[data-v="split"] { display: none; }
}

.up-body { flex: 1; overflow: auto; padding: 16px; max-width: 980px; width: 100%; margin: 0 auto; }
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 32px 16px; border: 2px dashed var(--line); border-radius: var(--radius); background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone svg { width: 40px; height: 40px; color: var(--accent); }
.dropzone small { color: var(--muted); max-width: 520px; }
.up-default { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 14px 0; }
.up-default small { color: var(--muted); }
.up-list { display: flex; flex-direction: column; gap: 10px; }
.up-item { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
.up-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; flex-wrap: wrap; }
.up-row .fname { font-weight: 600; flex: 1; min-width: 160px; word-break: break-word; }
.up-row .fname small { display: block; font-weight: 400; color: var(--muted); }
.up-row input[type="number"] { width: 84px; }
.up-row select { max-width: 200px; }
.status { font-size: 13px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.status.ok { background: color-mix(in srgb, #16a34a 16%, var(--surface)); color: #15803d; }
.status.warn { background: color-mix(in srgb, #d97706 18%, var(--surface)); color: #b45309; }
.status.err { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger); }
:root[data-theme="dark"] .status.ok { color: #86efac; } :root[data-theme="dark"] .status.warn { color: #fcd34d; }
.up-warn { padding: 0 12px 10px; color: #b45309; font-size: 13px; }
:root[data-theme="dark"] .up-warn { color: #fcd34d; }
.up-preview { border-top: 1px solid var(--line); max-height: 360px; overflow: auto; padding: 0 16px; font-size: 17px; background: var(--bg); }
.scan-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.scan-bar small { color: var(--muted); flex: 1; min-width: 200px; }
.scan-item .scan-ic { width: 22px; height: 22px; color: var(--accent); flex: none; }
.scan-pages { display: flex; gap: 10px; overflow-x: auto; padding: 0 12px 12px; }
.scan-pages figure { position: relative; margin: 0; flex: none; }
.scan-pages img { display: block; height: 120px; width: auto; max-width: 160px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }
.scan-pages figcaption { position: absolute; left: 6px; bottom: 6px; font-size: 12px; padding: 0 6px; border-radius: 999px; background: var(--surface); color: var(--muted); }
.scan-pages .icon-btn { position: absolute; top: 4px; right: 4px; background: var(--surface); }
.up-text { display: block; width: calc(100% - 24px); margin: 0 12px; min-height: 220px; resize: vertical; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; font-size: 16px; line-height: 1.7; }
.up-hint { display: block; padding: 6px 12px 10px; color: var(--muted); font-size: 13px; }
.src-intro { margin: 0 0 4px; color: var(--muted); font-size: 15px; line-height: 1.6; }
.src-note { display: flex; flex-direction: column; gap: 4px; margin: 0 0 14px; }
.src-note input { width: 100%; box-sizing: border-box; }
#srcChapter { width: 84px; }
.spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* library */
.lib-item { display: flex; gap: 10px; align-items: flex-start; border-bottom: 1px solid var(--line); }
.lib-item .result { border: 0; flex: 1; }
.lib-item .icon-btn { margin-top: 8px; color: var(--muted); }
.lib-note { margin-top: 6px; font-size: 15px; background: var(--surface-2); padding: 6px 10px; border-radius: 8px; white-space: pre-wrap; font-family: var(--ui-font); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

/* "install as app" bar: under the reader, the chapter buttons move up above it */
.install-bar {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); z-index: 25;
  width: min(560px, 100%); display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  background: var(--surface); border: 1px solid var(--line); border-bottom: 0; border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow); padding: 10px max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  animation: up .2s ease-out;
}
.install-bar[hidden], body.selecting .install-bar { display: none; }
.install-bar img { border-radius: 10px; flex: none; }
.install-text { flex: 1 1 calc(100% - 64px); min-width: 0; display: flex; flex-direction: column; line-height: 1.35; }
.install-text strong { font-size: 15px; }
.install-text small { color: var(--muted); font-size: 13px; }
.install-actions { flex: 1 1 100%; display: flex; justify-content: flex-end; gap: 8px; }
.install-actions .btn { min-height: 38px; padding: 6px 16px; }
body.has-install .chapter-nav { bottom: var(--install-h, 0px); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 20px); z-index: 100;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 20px; font-size: 15px; overflow-wrap: anywhere;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; width: max-content; max-width: min(560px, calc(100% - 32px)); box-sizing: border-box; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- bold chapter / verse numbers ---------- */
.reader .vn { font-weight: 800; font-size: .64em; }
.reader .ch-title .ch-num { font-weight: 800; }
.grid button { font-weight: 800; font-size: 17px; }
.result .r-ref, .ref-card .r-ref { font-weight: 800; }


/* ---------- account / login / admin ---------- */
.account { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.acct { display: flex; align-items: center; gap: 10px; }
.acct-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.acct-info strong, .acct-info small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-info small, .acct-hint { color: var(--muted); font-size: 12px; }
.acct-note { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.acct-note small { display: block; color: var(--muted); font-size: 12px; }
.acct-note svg { color: var(--muted); }
.acct-verify small { opacity: .85; overflow-wrap: anywhere; }
.acct-verify { font-size: 13px; background: color-mix(in srgb, #d97706 14%, var(--surface)); padding: 8px 10px; border-radius: 10px; display: flex; flex-direction: column; gap: 6px; }
.acct-logout { align-self: flex-start; color: var(--muted); }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-contrast); font-weight: 800; flex: none; }
.avatar.sm { width: 32px; height: 32px; font-size: 14px; }
.role-badge { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.role-badge.role-admin { background: var(--accent); color: var(--accent-contrast); }
.role-badge.role-editor { background: var(--accent-soft); color: var(--accent); }
.btn.block { width: 100%; justify-content: center; }

.acct-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.acct-actions .btn { color: var(--muted); }
.acct-blocked { font-size: 13px; background: color-mix(in srgb, var(--danger) 10%, var(--surface)); color: var(--danger); padding: 8px 10px; border-radius: 10px; }
.role-badge.role-none { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger); }
.role-badge.role-local { background: var(--accent-soft); color: var(--accent); }

/* access code dialog (auth-ui.js; reader + admin portal) */
.redeem .hint { margin: 0; line-height: 1.6; }
.redeem .modal-actions .spacer { display: none; }
.redeem .modal-actions .btn { flex: 1 1 auto; justify-content: center; }
input.code-input {
  width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 24px; font-weight: 700; letter-spacing: .12em;
  text-align: center; text-transform: uppercase; padding: 12px; min-height: 52px;
}
input.code-input::placeholder { color: var(--muted); opacity: .5; font-weight: 400; }
.redeem-msg { margin: 0; font-size: 14px; color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, var(--surface)); padding: 8px 10px; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: default; }

/* ---------- login screen (auth-ui.js; shared by the reader and the admin portal) ---------- */
.auth-screen {
  --a-bg: #eef0f3; --a-card: #ffffff; --a-text: #101828; --a-muted: #667085; --a-line: #d0d5dd;
  --a-blue: #0037e0; --a-blue-text: #ffffff; --a-link: #0037e0; --a-gray: #eef0f3; --a-gray-hover: #e2e5ea;
  --a-input: #ffffff; --a-err: #b42318; --a-ok: #067647; --a-gh: #181717; --a-shadow: 0 12px 40px rgba(16, 24, 40, .12), 0 2px 6px rgba(16, 24, 40, .06);
  width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0;
  background: var(--a-bg); color: var(--a-text); overflow: auto; overscroll-behavior: contain;
}
:root[data-theme="sepia"] .auth-screen { --a-bg: #efe6cf; }
:root[data-theme="dark"] .auth-screen {
  --a-bg: #0e0e10; --a-card: var(--surface); --a-text: var(--text); --a-muted: var(--muted); --a-line: #3a3a42;
  --a-blue: #3d63ff; --a-link: #8ea6ff; --a-gray: var(--surface-2); --a-gray-hover: #303036; --a-input: var(--bg);
  --a-err: var(--danger); --a-ok: #6ce9a6; --a-gh: #f0f0f0; --a-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .auth-screen {
    --a-bg: #0e0e10; --a-card: var(--surface); --a-text: var(--text); --a-muted: var(--muted); --a-line: #3a3a42;
    --a-blue: #3d63ff; --a-link: #8ea6ff; --a-gray: var(--surface-2); --a-gray-hover: #303036; --a-input: var(--bg);
    --a-err: var(--danger); --a-ok: #6ce9a6; --a-gh: #f0f0f0; --a-shadow: 0 12px 40px rgba(0, 0, 0, .5);
  }
}
.auth-screen[open] { display: block; }
.auth-screen::backdrop { background: rgba(10, 8, 5, .5); }
.auth-wrap {
  min-height: 100%; display: flex; position: relative;
  padding: max(56px, calc(env(safe-area-inset-top) + 48px)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.auth-close {
  position: absolute; top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right));
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: transparent; color: var(--a-muted);
  display: grid; place-items: center;
}
.auth-close:hover { background: var(--a-gray); color: var(--a-text); }
.auth-card {
  margin: auto; width: 100%; max-width: 460px; background: var(--a-card); color: var(--a-text);
  border-radius: 20px; padding: 36px 32px 28px; box-shadow: var(--a-shadow);
  display: flex; flex-direction: column; gap: 16px;
}
.auth-title { margin: 0; font-size: 32px; line-height: 1.25; font-weight: 800; letter-spacing: -.01em; }
.auth-sub { margin: -6px 0 4px; color: var(--a-muted); font-size: 15px; }
.auth-link {
  border: 0; background: none; padding: 4px 2px; margin: -4px 0; color: var(--a-link); font-weight: 600;
  font-size: inherit; text-decoration: none; min-height: 32px;
}
.auth-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.auth-sub .auth-link { min-height: 44px; margin: -10px 0; padding: 4px 6px; }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-form.off { opacity: .6; }
.auth-sso { display: flex; align-items: center; gap: 8px; }
.auth-google {
  flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 48px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--a-line);
  background: var(--a-card); color: var(--a-text); font-weight: 600; font-size: 15px;
}
.auth-google span { line-height: 1.3; text-align: center; overflow-wrap: anywhere; }
.auth-google:hover:not(:disabled) { background: var(--a-gray); }
.auth-icon { width: 48px; height: 48px; flex: none; border: 0; border-radius: 10px; background: transparent; display: grid; place-items: center; }
.auth-icon:hover:not(:disabled) { background: var(--a-gray); }
.auth-logo { width: 22px; height: 22px; stroke: none; }
.auth-icon .auth-logo { width: 26px; height: 26px; }
.auth-logo.gh { color: var(--a-gh); }
.auth-or { display: flex; align-items: center; gap: 12px; color: var(--a-muted); font-size: 13px; }
.auth-or::before, .auth-or::after { content: ''; flex: 1; height: 1px; background: var(--a-line); }
.auth-emailbox { display: flex; flex-direction: column; gap: 14px; }
.auth-field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.auth-field small { font-weight: 400; color: var(--a-muted); }
.auth-field input {
  font-weight: 400; font-size: 16px; min-height: 48px; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--a-line); background: var(--a-input); color: var(--a-text);
}
.auth-field input::placeholder { color: var(--a-muted); opacity: .8; }
.auth-field input:focus { outline: none; border-color: var(--a-blue); box-shadow: 0 0 0 3px color-mix(in srgb, var(--a-blue) 22%, transparent); }
.auth-primary, .auth-secondary {
  width: 100%; min-height: 50px; border-radius: 10px; border: 0; font-weight: 700; font-size: 16px;
  display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px;
}
.auth-primary { background: var(--a-blue); color: var(--a-blue-text); }
.auth-primary:hover:not(:disabled) { filter: brightness(1.12); }
.auth-secondary { background: var(--a-gray); color: var(--a-text); margin-top: -6px; }
.auth-secondary:hover:not(:disabled) { background: var(--a-gray-hover); }
.auth-screen button:disabled, .auth-screen input:disabled { cursor: default; }
.auth-primary:disabled, .auth-secondary:disabled, .auth-google:disabled, .auth-icon:disabled { opacity: .5; }
.auth-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px; font-size: 14px; }
.auth-links .auth-link { min-height: 44px; margin: 0; }
.auth-msg { margin: 0; font-size: 14px; padding: 10px 12px; border-radius: 10px; line-height: 1.55; }
.auth-msg.error { color: var(--a-err); background: color-mix(in srgb, var(--a-err) 9%, var(--a-card)); }
.auth-msg small { display: block; margin-top: 6px; font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
.auth-msg.ok { color: var(--a-ok); background: color-mix(in srgb, var(--a-ok) 10%, var(--a-card)); }
.auth-notice { margin: 0; font-size: 14px; color: var(--a-muted); background: var(--a-gray); padding: 10px 12px; border-radius: 10px; line-height: 1.6; }
.auth-notice.warn { color: #93370d; background: #fef0c7; }
:root[data-theme="dark"] .auth-notice.warn { color: #fedf89; background: #4e3a0b; }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] .auth-notice.warn { color: #fedf89; background: #4e3a0b; } }
.auth-local { display: flex; flex-direction: column; gap: 12px; padding: 16px; border: 1px solid var(--a-line); border-radius: 14px; }
.auth-local h2 { margin: 0; font-size: 17px; }
.auth-hint { margin: 0; font-size: 13px; color: var(--a-muted); line-height: 1.6; }
.auth-back { align-self: center; color: var(--a-link); font-weight: 600; font-size: 15px; padding: 10px; text-decoration: none; }
.auth-back:hover { text-decoration: underline; }
@media (max-width: 480px) {
  .auth-card { padding: 28px 20px 22px; border-radius: 18px; gap: 14px; }
  .auth-title { font-size: 27px; }
  .auth-google { font-size: 14px; gap: 8px; padding: 8px 10px; }
  .auth-sso { gap: 4px; }
  .auth-icon { width: 46px; }
}
@media (max-width: 340px) { .auth-google span { font-size: 13px; } }

/* ---------- touch & phones ---------- */
/* scroll only: no pinch-zoom or double-tap zoom (text size lives in settings) */
html, body { touch-action: pan-x pan-y; }
button, .v, a { -webkit-tap-highlight-color: transparent; }
body:has(dialog[open]) { overflow: hidden; }
.menu button small { display: block; }
.menu button .m-text { display: flex; flex-direction: column; }
.set-row.chk { justify-content: flex-start; }
.menu button.install { background: var(--accent-soft); color: var(--accent); margin: 6px 0 2px; }
.menu button.install svg { color: var(--accent); }
@media (hover: none) { .desk-only { display: none; } }
.fs-head h2 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fs-head .spacer { display: none; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

@media (max-width: 600px) {
  .topbar { gap: 0; padding-left: max(4px, env(safe-area-inset-left)); padding-right: max(4px, env(safe-area-inset-right)); }
  .topbar .icon-btn { width: 44px; height: 44px; }
  .ref-btn {
    position: static; transform: none; margin: 0 auto; min-width: 0; max-width: none; flex: 0 1 auto;
    font-size: 16px; min-height: 40px; padding: 6px 10px 6px 16px;
  }
  .topbar-right { margin-left: 0; }
  main { padding: 4px max(16px, env(safe-area-inset-right)) 150px max(16px, env(safe-area-inset-left)); }
  .reader .ch-title { margin: 16px 0 18px; }
  .reader .ch-title span { font-size: 1.8em; }
  .fab { width: 52px; height: 52px; bottom: max(18px, calc(env(safe-area-inset-bottom) + 10px)); }
  #btnPrev { left: max(14px, env(safe-area-inset-left)); } #btnNext { right: max(14px, env(safe-area-inset-right)); }

  /* dialogs become full-height sheets that respect the notch / home bar */
  .sheet { height: 100vh; height: 100dvh; }
  .sheet-head, .fs-head { padding-top: max(8px, env(safe-area-inset-top)); }
  .sheet-body { padding-bottom: max(24px, env(safe-area-inset-bottom)); }
  .tabs button { padding: 10px 12px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); }

  /* settings: bottom sheet */
  .popover {
    top: auto; bottom: 0; left: 0; right: 0; width: 100%; max-height: 85dvh; overflow: auto;
    border-radius: 20px 20px 0 0; border-bottom: 0; padding: 8px 18px max(18px, env(safe-area-inset-bottom));
    animation: sheet-up .22s ease-out;
  }
  .popover::before { content: ''; display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 4px auto 8px; }
  .popover::backdrop { background: rgba(10, 8, 5, .35); }
  .set-row { min-height: 48px; }
  .stepper .btn { min-width: 52px; min-height: 44px; justify-content: center; }
  .seg button { min-height: 44px; }

  /* search options on one line */
  .search-opts { gap: 8px 12px; padding: 8px 14px; }
  .search-opts .hint { display: none; }
  .search-opts select { flex: 1; min-width: 0; min-height: 40px; }

  /* small modals sit near the top so the on-screen keyboard doesn't cover them */
  .modal { margin: max(12px, env(safe-area-inset-top)) auto auto; max-height: calc(100dvh - 24px); overflow: auto; }
  .modal-actions .btn { min-height: 44px; }

  /* editor + upload headers stay on one row: icon buttons + labelled primary action */
  .fs-head { flex-wrap: nowrap; gap: 4px; padding-left: 6px; padding-right: 10px; }
  .fs-head h2 { font-size: 16px; }
  .fs-head .btn:not(.primary) { padding: 0; width: 44px; min-height: 44px; justify-content: center; }
  .fs-head .btn:not(.primary) span { display: none; }
  .fs-head .btn.primary { min-height: 40px; }
  .fs-head .btn.primary span { display: inline; }
  .ed-toolbar { flex-wrap: nowrap; overflow-x: auto; padding: 8px 10px; }
  .ed-toolbar .btn { flex: none; min-height: 38px; }
  .ed-view { margin-left: auto; flex: none; }
  .ed-panes textarea { font-size: 17px; padding: 14px max(14px, env(safe-area-inset-left)) 60px; }
  .ed-preview { padding: 0 16px 60px; }

  .up-body { padding: 12px 14px max(24px, env(safe-area-inset-bottom)); }
  .dropzone { padding: 22px 14px; }
  .up-default select { flex: 1; min-width: 0; }
  .up-row { display: grid; grid-template-columns: auto 1fr; gap: 8px 10px; }
  .up-row .fname { min-width: 0; }
  .up-row select, .up-row label, .up-row .status, .up-row .up-prev, .up-row .up-edit { grid-column: 1 / -1; }
  .up-row select { max-width: none; width: 100%; }
  .up-row label { display: flex; align-items: center; gap: 10px; }
  .up-row .status { justify-self: start; }
  .up-row .up-prev, .up-row .up-edit { justify-self: start; min-height: 40px; }
  .scan-item .up-row { display: flex; }
  .scan-bar .btn { width: 100%; justify-content: center; min-height: 44px; }

  .actionbar { border-radius: 20px 20px 0 0; padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  .swatches { justify-content: space-between; }
  .swatch { width: 40px; height: 40px; }
  .actions button { min-height: 56px; font-size: 11.5px; }
  .toast { bottom: calc(96px + env(safe-area-inset-bottom)); border-radius: 14px; }
  .menu button { min-height: 48px; }
  .drawer { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
}
@keyframes sheet-up { from { transform: translateY(100%); } }
@media (max-width: 360px) {
  .reader { font-size: calc(var(--fs) - 1px); }
  .actions button span { font-size: 10.5px; }
}
/* installed app (standalone) */
@media (display-mode: standalone) {
  .topbar { padding-top: max(8px, env(safe-area-inset-top)); }
}
@media print {
  .topbar, .chapter-nav, .actionbar, .toast { display: none !important; }
  main { padding: 0; }
  .reader .v { background: none !important; }
}
