/* ==========================================================================
   Torah Book — siddur / sacred-text reader. Handle: `tb-reader` (registered;
   map-core enqueues it, or lists it as a dependency of the siddur block).
   Font: David Libre — chosen in a 360px niqqud bake-off vs Frank Ruhl Libre
   and Noto Serif Hebrew (clearest vowel separation, no shin-dot/holam clash).
   ========================================================================== */

.tb-reader {
	--rd-size: var(--tb-reader-size, 22px);
	--rd-bg: #FBF7EE; --rd-ink: #1A1F2A; --rd-muted: #6A6458; --rd-rule: #E7DDCB;
	--rd-insert-bg: #F7EBCB; --rd-insert-edge: #B8862B; --rd-insert-ink: #6F4A08;
	--rd-accent: #855A0E; --rd-bar: rgb(251 247 238 / .9);
	background: var(--rd-bg); color: var(--rd-ink);
	border-radius: var(--tb-r-lg); position: relative;
	transition: background-color var(--tb-base) var(--tb-ease), color var(--tb-base) var(--tb-ease);
}
.tb-reader[data-reader-theme="sepia"] {
	--rd-bg: #F2E6CC; --rd-ink: #3A2A16; --rd-muted: #6F5A3E; --rd-rule: #DCCAA6;
	--rd-insert-bg: #E9D3A3; --rd-insert-edge: #9C6B1C; --rd-insert-ink: #5A3A08; --rd-accent: #7A4E0B; --rd-bar: rgb(242 230 204 / .92);
}
/* Night: warm, low-blue (amber on near-black) — for Arvit and bedtime Shema. */
.tb-reader[data-reader-theme="night"] {
	--rd-bg: #14110C; --rd-ink: #DCC9A3; --rd-muted: #9C8B6C; --rd-rule: #2C261C;
	--rd-insert-bg: #2A2112; --rd-insert-edge: #C99A45; --rd-insert-ink: #E8C27A; --rd-accent: #D9AE5F; --rd-bar: rgb(20 17 12 / .92);
}
:root[data-theme="dark"] .tb-reader:not([data-reader-theme]) {
	--rd-bg: #14110C; --rd-ink: #DCC9A3; --rd-muted: #9C8B6C; --rd-rule: #2C261C;
	--rd-insert-bg: #2A2112; --rd-insert-edge: #C99A45; --rd-insert-ink: #E8C27A; --rd-accent: #D9AE5F; --rd-bar: rgb(20 17 12 / .92);
}
.tb-reader--full { border-radius: 0; margin-inline: calc(50% - 50vw); min-height: 100dvh; }

/* Sticky mini-header */
.tb-reader__bar {
	position: sticky; top: var(--tb-reader-top, calc(var(--tb-header-h) + env(safe-area-inset-top, 0px))); z-index: 20;
	display: flex; align-items: center; gap: 4px; min-height: 52px; padding: 2px 6px;
	background: var(--rd-bar); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
	border-block-end: 1px solid var(--rd-rule); border-radius: inherit; border-end-start-radius: 0; border-end-end-radius: 0;
}
.tb-reader__bar .tb-iconbtn { color: var(--rd-ink); }
.tb-reader__where { flex: 1; min-width: 0; text-align: center; line-height: 1.2; }
.tb-reader__where b { display: block; font: 700 .9375rem/1.25 var(--tb-sans); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-reader__where span { font-size: .75rem; color: var(--rd-muted); }
.tb-reader__progress { position: absolute; inset-inline: 0; bottom: -1px; height: 2px; }
.tb-reader__progress > span { display: block; height: 100%; width: var(--p, 0%); background: var(--rd-accent); margin-inline-start: 0; transition: width .15s linear; }

/* Body */
.tb-reader__body { max-width: 36rem; margin-inline: auto; padding: 20px 20px 48px; }
@media (min-width: 640px) { .tb-reader__body { padding: 32px 32px 64px; } }
.tb-reader__section {
	margin: 36px 0 14px; font: 700 calc(var(--rd-size) * .82)/1.3 var(--wp--preset--font-family--reader, "David Libre", serif);
	color: var(--rd-accent); text-align: center; scroll-margin-top: calc(var(--tb-header-h) + 72px);
}
.tb-reader__section:first-child { margin-top: 8px; }
.tb-reader__section::after { content: ""; display: block; width: 40px; height: 1.5px; margin: 10px auto 0; background: currentColor; opacity: .5; border-radius: 2px; }
.tb-reader__text {
	margin: 0 0 .9em; font-family: var(--wp--preset--font-family--reader, "David Libre", serif);
	font-size: var(--rd-size); line-height: 1.9; font-weight: 400; color: var(--rd-ink);
	font-feature-settings: "kern", "mark", "mkmk"; text-wrap: pretty; hanging-punctuation: first;
}
.tb-reader__text b, .tb-reader__text strong { font-weight: 700; }
.tb-reader__text--lead::first-line { font-weight: 700; }  /* opening word(s) of a blessing */
.tb-reader__response { color: var(--rd-accent); font-weight: 500; }  /* קהל: אמן / ברוך הוא */
.tb-reader__name { white-space: nowrap; }  /* keep the Divine name unbroken */

/* Rubrics — small grey instructions */
.tb-reader__instruction {
	display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin: 18px 0 8px;
	font: 500 .875rem/1.5 var(--tb-sans); color: var(--rd-muted);
}
.tb-reader__instruction .tb-icon { width: 17px; height: 17px; }
.tb-reader__instruction .tb-chip { height: 26px; font-size: .75rem; }
[data-reader-theme="night"] .tb-reader__instruction .tb-chip, :root[data-theme="dark"] .tb-reader:not([data-reader-theme]) .tb-reader__instruction .tb-chip { background: transparent; border-color: var(--rd-rule); color: var(--rd-muted); }
.tb-reader__instruction--inline { display: inline; margin: 0 .25em; font-size: .7em; vertical-align: .15em; }

/* Today-only inserts (יעלה ויבוא, על הניסים, הלל...) */
.tb-reader__insert {
	position: relative; margin: 14px -12px 18px; padding: 12px 14px 4px;
	background: var(--rd-insert-bg); border-inline-start: 3px solid var(--rd-insert-edge); border-radius: 4px 14px 14px 4px;
	animation: tb-fade var(--tb-base) var(--tb-ease);
}
[dir="rtl"] .tb-reader__insert { border-radius: 14px 4px 4px 14px; }
.tb-reader__insert-label {
	display: inline-flex; align-items: center; gap: 6px; margin-bottom: 4px;
	font: 700 .75rem/1.4 var(--tb-sans); letter-spacing: .02em; color: var(--rd-insert-ink);
}
.tb-reader__insert-label::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--rd-insert-edge); }
.tb-reader__insert .tb-reader__text:last-child { margin-bottom: .5em; }
.tb-reader__skip { opacity: .45; } /* text NOT said today (e.g. תחנון) — shown dimmed, never hidden */
.tb-reader__skip .tb-reader__text { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--rd-muted), transparent 50%); text-decoration-thickness: 1px; }

/* Nusach secondary note (Ashkenaz text toggle) */
.tb-reader__alt { margin: 6px 0 14px; padding: 8px 12px; border: 1px dashed var(--rd-rule); border-radius: 10px; font-size: .875rem; color: var(--rd-muted); }

/* Reader settings sheet: theme swatches + size slider */
.tb-reader-themes { display: flex; gap: 10px; }
.tb-reader-themes button {
	width: 48px; height: 48px; border-radius: 50%; cursor: pointer; padding: 0;
	border: 2px solid var(--tb-border); font: 700 1rem/1 "David Libre", serif;
}
.tb-reader-themes [data-reader-set="light"] { background: #FBF7EE; color: #1A1F2A; }
.tb-reader-themes [data-reader-set="sepia"] { background: #F2E6CC; color: #3A2A16; }
.tb-reader-themes [data-reader-set="night"] { background: #14110C; color: #DCC9A3; }
.tb-reader-themes button[aria-pressed="true"] { border-color: var(--tb-accent); box-shadow: 0 0 0 3px var(--tb-accent-soft); }
.tb-range-row { display: flex; align-items: center; gap: 12px; }
.tb-range-row .tb-range-a { font-family: "David Libre", serif; color: var(--tb-muted); }
.tb-range-row .tb-range-a--big { font-size: 1.5rem; }
.tb-range {
	-webkit-appearance: none; appearance: none; flex: 1; height: 48px; background: transparent; cursor: pointer; margin: 0;
	--p: 30%;
}
.tb-range::-webkit-slider-runnable-track { height: 6px; border-radius: 6px; background: linear-gradient(to left, var(--tb-accent) var(--p), var(--tb-surface-2) var(--p)); }
[dir="ltr"] .tb-range::-webkit-slider-runnable-track { background: linear-gradient(to right, var(--tb-accent) var(--p), var(--tb-surface-2) var(--p)); }
.tb-range::-moz-range-track { height: 6px; border-radius: 6px; background: var(--tb-surface-2); }
.tb-range::-moz-range-progress { height: 6px; border-radius: 6px; background: var(--tb-accent); }
.tb-range::-webkit-slider-thumb { -webkit-appearance: none; width: 28px; height: 28px; margin-top: -11px; border-radius: 50%; background: var(--tb-surface); border: 2px solid var(--tb-accent); box-shadow: var(--tb-shadow-md); }
.tb-range::-moz-range-thumb { width: 24px; height: 24px; border-radius: 50%; background: var(--tb-surface); border: 2px solid var(--tb-accent); box-shadow: var(--tb-shadow-md); }
.tb-reader__preview { margin: 8px 0 0; padding: 12px; border-radius: var(--tb-r-md); background: var(--tb-surface-2); font: 400 var(--tb-reader-size, 22px)/1.9 "David Libre", serif; text-align: center; }

/* TOC (inside .tb-sheet) */
.tb-toc { list-style: none; margin: 0; padding: 0; }
.tb-toc a {
	display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 12px; border-radius: var(--tb-r-md);
	color: var(--tb-ink); text-decoration: none; font-weight: 500;
}
.tb-toc a:active { background: var(--tb-hover); }
.tb-toc a[aria-current="true"] { background: var(--tb-primary-soft); color: var(--tb-primary); font-weight: 700; }
.tb-toc__n { width: 26px; height: 26px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--tb-surface-2); font: 700 .75rem/1 var(--tb-sans); color: var(--tb-muted); }
.tb-toc a[aria-current="true"] .tb-toc__n { background: var(--tb-primary); color: var(--tb-on-primary); }
.tb-toc__meta { margin-inline-start: auto; display: flex; gap: 4px; }
.tb-toc ol, .tb-toc ul { list-style: none; margin: 0; padding-inline-start: 38px; }
.tb-toc ol a, .tb-toc ul a { min-height: 44px; font-weight: 400; font-size: .9375rem; color: var(--tb-muted); }
.tb-toc__group { margin: 14px 12px 4px; font-size: .75rem; font-weight: 700; color: var(--tb-accent-ink); letter-spacing: .02em; }

/* Focus mode ("while praying"): hide site chrome, larger text */
:root.tb-focus .tb-header, :root.tb-focus .tb-tabbar, :root.tb-focus .tb-footer { display: none; }
:root.tb-focus body { padding-bottom: 0; }
:root.tb-focus .tb-reader { --tb-reader-top: env(safe-area-inset-top, 0px); }
