/* @pivotal/ui-reader — the paged reader. Uses the theme tokens (ui-theme) with fallbacks. */

/* ---- core pager ---- */
.pg-view { position: relative; overflow-x: auto; overflow-y: hidden; height: 100%; scroll-snap-type: x mandatory; overscroll-behavior-x: contain; touch-action: pan-x; scrollbar-width: none; -ms-overflow-style: none; }
.pg-view::-webkit-scrollbar { display: none; }
.pg-strip { position: relative; height: 100%; }
.pg-cols { --pg-pad: 18px; height: 100%; box-sizing: border-box; padding: 10px var(--pg-pad) 8px; column-fill: auto; position: absolute; top: 0; inset-inline-start: 0; }
.pg-cols p { orphans: 2; widows: 2; }
.pg-cols h1, .pg-cols h2, .pg-cols h3, .pg-cols h4, .pg-cols .instr { break-after: avoid; break-inside: avoid; }
.pg-cols h4:first-child { margin-top: 0; }
.pg-cols img, .pg-cols table { max-width: 100%; break-inside: avoid; }
.pg-end { display: inline-block; width: 1px; height: 1px; }
.pg-snaps { position: absolute; inset: 0; pointer-events: none; }
.pg-snaps i { position: absolute; top: 0; height: 100%; scroll-snap-align: start; scroll-snap-stop: always; }
@media (min-width: 900px) { .pg-cols { --pg-pad: 40px; } }

/* ---- scrolling layout (scroller.js) ---- */
.pg-scroll { position: relative; overflow-y: auto; overflow-x: hidden; height: 100%; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.pg-flow { --pg-pad: 18px; padding: 10px var(--pg-pad) 48px; }
@media (min-width: 900px) { .pg-flow { --pg-pad: 40px; } }
.rd[data-layout="scroll"] .rd-arrow { font-size: 20px; }

/* ---- the reader shell ---- */
html.rd-open, html.rd-open body { overflow: hidden; height: 100%; }
.rd { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; background: var(--bg, #f7f1e3); color: var(--ink, #1d1a14); padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
.rd-top, .rd-bot { flex: 0 0 auto; display: flex; align-items: center; gap: 4px; padding: 6px 8px; max-width: 780px; width: 100%; margin: 0 auto; box-sizing: border-box; user-select: none; -webkit-user-select: none; }
.rd-ttl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--hfont, serif); font-size: 19px; padding: 0 4px; }
.rd-ttl small { color: var(--mute, #8a7f6a); font-size: 12px; font-family: var(--f-ui, -apple-system, 'Segoe UI', Roboto, sans-serif); margin-inline-start: 8px; }
.rd-marker { font-size: 13px; color: var(--mute, #8a7f6a); border: 1px solid var(--line, #e4dac3); border-radius: 999px; padding: 1px .55em; margin: 0 4px; white-space: nowrap; }
.rd-marker:empty { display: none; }
.rd-ibtn { background: none; border: 0; color: var(--mute, #8a7f6a); font: inherit; font-size: 18px; padding: 6px 9px; border-radius: 8px; line-height: 1; cursor: pointer; }
.rd-ibtn:disabled { opacity: .3; }
.rd-arrow { font-size: 26px; padding: 2px 14px; }
.rd-rail { height: 3px; background: var(--line, #e4dac3); }
.rd-rail i { display: block; height: 100%; background: var(--gold, #9a6b12); transition: width .25s ease-out; }
.rd-view { flex: 1; min-height: 0; max-width: 780px; width: 100%; margin: 0 auto; }
.rd-bot { border-top: 1px solid var(--line, #e4dac3); justify-content: space-between; font-size: 13px; color: var(--mute, #8a7f6a); min-height: 48px; }
.rd-pos { flex: 1; text-align: center; }
.rd-pos b { color: var(--ink, #1d1a14); font-weight: 600; }
.rd-next.rd-fin { background: var(--ink, #1d1a14); color: var(--bg, #f7f1e3); border: 1px solid var(--ink, #1d1a14); border-radius: 10px; padding: 8px 14px; font-size: 14px; white-space: nowrap; }
.rd-next.rd-fin.rd-done { background: none; color: var(--targ, var(--ok, #2f6b4f)); border-color: var(--line, #e4dac3); }
.rd .mark { background: var(--mark, #f1d98c66); border-radius: 8px; }

/* commentary sheet */
.rd-sheet { position: absolute; inset-inline: 0; bottom: 0; max-height: 64%; background: var(--paper, #fbf7ec); border-top: 1px solid var(--line, #e4dac3); border-radius: 16px 16px 0 0; box-shadow: 0 -6px 24px #0003; display: flex; flex-direction: column; z-index: 2; user-select: text; -webkit-user-select: text; touch-action: pan-y; animation: rd-up .22s ease-out; }
@keyframes rd-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.rd-sh { display: flex; justify-content: space-between; align-items: center; padding: 8px 16px 4px; font-size: 13px; color: var(--mute, #8a7f6a); }
.rd-sh b { font-weight: 600; }
.rd-sb { overflow: auto; padding: 0 16px 16px; }
.rd-sb p { font-family: var(--tfont, var(--hfont, serif)); font-size: calc(var(--fs, 23px) * .72); line-height: 1.75; margin: .3em 0; }
.rd-none { color: var(--mute, #8a7f6a); font-size: 14px !important; }
.rd-loading { color: var(--mute, #8a7f6a); }

/* first-use tip */
.rd-tip { position: absolute; left: 50%; bottom: 64px; transform: translateX(-50%); background: var(--ink, #1d1a14); color: var(--bg, #f7f1e3); font-size: 13px; padding: 8px 14px; border-radius: 12px; max-width: 90%; text-align: center; opacity: 0; transition: opacity .3s; pointer-events: none; z-index: 3; }
.rd-tip.on { opacity: .95; }

@media (prefers-reduced-motion: reduce) { .rd-rail i, .rd-sheet { transition: none; animation: none; } }

/* ---- segments (segments.js) ---- */
.text .seg-p { position: relative; margin: 0 0 .55em; padding: 0 4px; border-radius: 8px; }
.text .seg-p p.he { font-family: var(--f-text, var(--hfont, serif)); font-size: var(--fs, 23px); line-height: var(--lh, 1.7); margin: 0; }
.text .seg-p p.tr { font-family: var(--f-text, var(--hfont, serif)); font-size: calc(var(--fs, 23px) * .82); line-height: 1.65; color: var(--ink-2, var(--ink, #1d1a14)); margin: .15em 0 0; }
.text .seg-p p.en { font-family: var(--f-ui, Georgia, serif); font-size: calc(var(--fs, 23px) * .7); line-height: 1.55; color: var(--ink-2, var(--ink, #1d1a14)); margin: .15em 0 0; }
.text .seg-p[data-comm]::after { content: ''; position: absolute; inset-inline-end: -2px; top: .55em; width: 4px; height: 4px; border-radius: 50%; background: var(--line, #e4dac3); }
.text h4.seg-head { font-family: var(--f-display, var(--hfont, serif)); font-size: calc(var(--fs, 23px) * .9); color: var(--accent, #7a3e12); font-weight: normal; margin: 1.2em 0 .3em; padding-top: .5em; border-top: 1px solid var(--line, #e4dac3); break-after: avoid; }
.text h4.seg-head:first-child { border-top: 0; margin-top: .2em; }
.text .seg-marker { font-family: var(--f-ui, sans-serif); font-size: 12px; color: var(--mute, #8a7f6a); border: 1px solid var(--line, #e4dac3); border-radius: 999px; padding: 0 .45em; margin-inline-end: .4em; vertical-align: .25em; white-space: nowrap; }
.text .seg-n { font-size: .6em; color: var(--mute, #8a7f6a); margin-inline-end: .35em; vertical-align: .45em; }
.text .seg-notes { margin: .3em 0 .7em; padding: .2em .8em .5em; border-inline-start: 3px solid var(--line, #e4dac3); background: var(--chipbg, #efe5cd); border-radius: 8px 0 0 8px; font-size: calc(var(--fs, 23px) * .72); }

/* ---- commentary (commentary.js) ---- */
.cm-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: 0 0 .4em; }
.cm-tabs button { background: var(--chipbg, #efe5cd); border: 1px solid var(--line, #e4dac3); color: var(--ink, #1d1a14); border-radius: 999px; padding: 3px 10px; font: inherit; font-size: 13px; cursor: pointer; }
.cm-tabs button.on { background: var(--ink, #1d1a14); color: var(--bg, #f7f1e3); border-color: var(--ink, #1d1a14); }
.cm-select { font: inherit; font-size: 13px; color: var(--ink, #1d1a14); background: var(--bg, #f7f1e3); border: 1px solid var(--line, #e4dac3); border-radius: 8px; padding: 4px 8px; margin: 0 0 .4em; max-width: 100%; }
.cm-body p { font-family: var(--f-text, var(--tfont, var(--hfont, serif))); font-size: calc(var(--fs, 23px) * .72); line-height: 1.75; margin: .3em 0; }
.cm-body.rashi p { font-family: var(--f-rashi, 'Noto Rashi Hebrew', serif); }
.cm-body b { color: var(--targ, var(--ok, #2f6b4f)); }

/* ---- highlights (highlights.js) ---- */
::highlight(hl-chidush) { background: var(--hl-chidush, #f1d98c88); }
::highlight(hl-kushya) { background: var(--hl-kushya, #e9b4b488); }
::highlight(hl-halacha) { background: var(--hl-halacha, #c9dfb888); }
::highlight(hl-dvar) { background: var(--hl-dvar, #b9d3e888); }
mark.hl-mark { color: inherit; border-radius: 3px; }
mark.hl-chidush { background: var(--hl-chidush, #f1d98c88); } mark.hl-kushya { background: var(--hl-kushya, #e9b4b488); }
mark.hl-halacha { background: var(--hl-halacha, #c9dfb888); } mark.hl-dvar { background: var(--hl-dvar, #b9d3e888); }
.hl-bar { position: absolute; z-index: 5; display: flex; gap: 4px; padding: 6px; background: var(--paper, #fbf7ec); border: 1px solid var(--line, #e4dac3); border-radius: 12px; box-shadow: 0 6px 20px #0003; user-select: none; -webkit-user-select: none; }
.hl-bar button { display: flex; align-items: center; gap: 6px; font: inherit; font-size: 13px; color: var(--ink, #1d1a14); background: var(--chipbg, #efe5cd); border: 0; border-radius: 8px; padding: 6px 10px; cursor: pointer; white-space: nowrap; }
.hl-bar button i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.hl-bar .hl-chidush i { background: var(--hl-chidush, #f1d98c); } .hl-bar .hl-kushya i { background: var(--hl-kushya, #e9b4b4); }
.hl-bar .hl-halacha i { background: var(--hl-halacha, #c9dfb8); } .hl-bar .hl-dvar i { background: var(--hl-dvar, #b9d3e8); }
.pg-cols { user-select: text; -webkit-user-select: text; }
