/* ─────────────────────────────────────────────────────────────────────────
   Book Flow Reader — עיצוב.
   שלד נייטרלי (Heebo, אפורים חמים) + "ערכת ספר": --accent מגיע מהספר.
   טקסט הספר: --font-book (פרנק-ריהל של הגילדה אם הקבצים ב-/fonts, אחרת
   Frank Ruhl Libre), דוד, או ללא-סריף — לפי בחירת הקורא.
   ───────────────────────────────────────────────────────────────────────── */

/* גופני הבית (רישיון ההוצאה, לא בגיט — הקבצים ב-/fonts בשרת): FrankG לטקסט הספר, Simpler לממשק */
@font-face { font-family: "FrankG"; src: url("/fonts/frankg-regular.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "FrankG"; src: url("/fonts/frankg-bold.woff2") format("woff2"); font-weight: 500 700; font-display: swap; }
@font-face { font-family: "FrankG"; src: url("/fonts/frankg-black.woff2") format("woff2"); font-weight: 800 900; font-display: swap; }
@font-face { font-family: "Simpler"; src: url("/fonts/simpler-regular.woff2") format("woff2"); font-weight: 300 500; font-display: swap; }
@font-face { font-family: "Simpler"; src: url("/fonts/simpler-black.woff2") format("woff2"); font-weight: 600 900; font-display: swap; }

:root {
  --ground: #F3F2EE; --surface: #FFFFFF; --surface-2: #ECEAE4;
  --ink: #1B1A17; --ink-2: #5C5A52; --ink-3: #8E8B80;
  --line: #DDDAD1; --line-2: #C9C5B9;
  --accent: #2E5E63; --accent-ink: #FFFFFF; --accent-soft: #DCE9EA;
  --danger: #A2432F;
  --shadow: 0 16px 40px -22px rgba(27,26,23,.45);
  --radius: 14px;
  --font-ui: Simpler, Heebo, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --font-book: FrankG, "Frank Ruhl Libre", "Times New Roman", serif;
  --font-david: "David Libre", "Frank Ruhl Libre", serif;
  --font-sans: Simpler, Heebo, system-ui, sans-serif;
  --paper: #FBFAF6; --paper-ink: #1C1B18; --paper-mute: rgba(28,27,24,.55); --paper-line: rgba(28,27,24,.12); --paper-sel: rgba(46,94,99,.22);
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
html[data-ui="dark"] {
  --ground: #191A1D; --surface: #22242A; --surface-2: #2B2E35;
  --ink: #ECEAE3; --ink-2: #B4B1A6; --ink-3: #7E7B72;
  --line: #33363E; --line-2: #454955;
  --accent-ink: #0F1E20; --accent-soft: #223639;
  --shadow: 0 16px 40px -22px rgba(0,0,0,.8);
  color-scheme: dark;
}
/* נייר */
html[data-paper="light"] { --paper: #FBFAF6; --paper-ink: #1C1B18; --paper-mute: rgba(28,27,24,.55); --paper-line: rgba(28,27,24,.12); }
html[data-paper="sepia"] { --paper: #EFE6D3; --paper-ink: #2A241C; --paper-mute: rgba(42,36,28,.6); --paper-line: rgba(42,36,28,.14); }
html[data-paper="night"] { --paper: #15171B; --paper-ink: #D6D3CA; --paper-mute: rgba(214,211,202,.55); --paper-line: rgba(214,211,202,.14); --paper-sel: rgba(127,184,189,.3); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body { margin: 0; background: var(--ground); color: var(--ink); font-family: var(--font-ui); font-size: 16px; line-height: 1.5; direction: rtl; overscroll-behavior-y: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
button:focus-visible, a:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
a { color: var(--accent); }
input, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-2); border-radius: 10px; padding: 12px 14px; width: 100%; }
input:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
@media print { body { display: none !important; } }

/* ── כללי ─────────────────────────────────────────────────────────── */
.app { min-height: 100%; display: flex; flex-direction: column; }
.boot { flex: 1; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; color: var(--ink-3); font-size: 14px; min-height: 60vh; }
.boot-mark { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .boot-mark { animation: none; } * { transition: none !important; } }

.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 18px; border-radius: 999px; font-weight: 500; font-size: 15px; background: var(--surface-2); color: var(--ink); border: 1px solid transparent; transition: background .15s, transform .05s; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: var(--line-2); }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger), transparent 60%); background: transparent; }
.btn[disabled] { opacity: .5; cursor: default; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: inherit; }
.icon-btn:hover { background: color-mix(in srgb, currentColor, transparent 90%); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn[aria-pressed="true"] { color: var(--accent); }

.toast { position: fixed; bottom: calc(24px + var(--safe-b)); inset-inline: 0; margin: 0 auto; width: max-content; max-width: min(92vw, 520px); background: var(--ink); color: var(--ground); padding: 12px 18px; border-radius: 12px; font-size: 14px; z-index: 100; box-shadow: var(--shadow); display: flex; gap: 14px; align-items: center; }
.toast button { color: var(--accent-soft); font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }
html[data-ui="dark"] .toast { background: var(--surface-2); color: var(--ink); }

.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 90; display: flex; align-items: flex-end; justify-content: center; padding: 0; }
.modal { background: var(--surface); color: var(--ink); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; padding: 20px 22px calc(20px + var(--safe-b)); box-shadow: var(--shadow); max-height: 88vh; overflow: auto; }
.modal h2 { font-size: 19px; margin: 0 0 12px; font-weight: 500; }
.modal .row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
@media (min-width: 640px) { .modal-back { align-items: center; padding: 20px; } .modal { border-radius: 22px; padding-bottom: 20px; } }

/* ── מסכי שער: כניסה וספרייה ─────────────────────────────────────── */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: calc(14px + var(--safe-t)) 20px 10px; max-width: 1080px; margin: 0 auto; width: 100%; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 500; color: var(--ink); text-decoration: none; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.brand span { font-size: 15px; }
.page { flex: 1; max-width: 1080px; margin: 0 auto; width: 100%; padding: 8px 20px calc(40px + var(--safe-b)); }

.login { max-width: 420px; margin: 8vh auto 0; text-align: start; }
.login h1 { font-family: var(--font-book); font-weight: 500; font-size: 34px; line-height: 1.15; margin: 0 0 8px; }
.login p { color: var(--ink-2); margin: 0 0 22px; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.login label { font-size: 13px; color: var(--ink-2); display: block; margin-bottom: 6px; }
.login .code { letter-spacing: .5em; font-size: 26px; text-align: center; direction: ltr; font-variant-numeric: tabular-nums; }
.login .hint { font-size: 13px; color: var(--ink-3); }
.login .err { color: var(--danger); font-size: 14px; }
.login .links { display: flex; gap: 14px; flex-wrap: wrap; font-size: 14px; margin-top: 8px; }
.login .links button { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }

.lib-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 10px 0 18px; flex-wrap: wrap; }
.lib-head h1 { font-family: var(--font-book); font-weight: 500; font-size: 30px; margin: 0; }
.lib-head .sub { color: var(--ink-3); font-size: 14px; }
.continue { display: grid; grid-template-columns: 96px 1fr; gap: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 26px; align-items: center; box-shadow: var(--shadow); }
.continue .cover { aspect-ratio: 2/3; border-radius: 6px; overflow: hidden; background: var(--surface-2); box-shadow: 0 6px 16px -8px rgba(0,0,0,.4); }
.continue .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.continue .cover .ph { height: 100%; display: flex; align-items: center; justify-content: center; padding: 8px; text-align: center; font-family: var(--font-book); font-size: 13px; line-height: 1.2; color: var(--paper-ink); background: linear-gradient(160deg, color-mix(in srgb, var(--accent), white 70%), color-mix(in srgb, var(--accent), white 30%)); }
.continue .cover .ph { height: 100%; display: flex; align-items: center; justify-content: center; padding: 8px; text-align: center; font-family: var(--font-book); font-size: 13px; line-height: 1.2; color: var(--paper-ink); background: linear-gradient(160deg, color-mix(in srgb, var(--accent), white 70%), color-mix(in srgb, var(--accent), white 30%)); }
.continue .eyebrow { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); font-weight: 500; }
.continue h2 { font-family: var(--font-book); font-weight: 500; font-size: 22px; margin: 4px 0 2px; }
.continue .meta { color: var(--ink-2); font-size: 14px; margin-bottom: 12px; }
.continue .actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.bar { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; position: relative; }
.bar i { position: absolute; inset-block: 0; right: 0; background: var(--accent); border-radius: 2px; }

/* המדף */
.shelf { --shelf: #D9CFBF; --shelf-dark: #B9AB94; --cover-w: 148px; --cover-gap: 24px; display: flex; flex-direction: column; gap: 34px; padding: 10px 6px 0; }
html[data-ui="dark"] .shelf { --shelf: #3A3D45; --shelf-dark: #23252B; }
.shelf-row { position: relative; }
.shelf-books { display: flex; align-items: flex-end; gap: var(--cover-gap); padding: 0 12px; min-height: 40px; }
.shelf-book { position: relative; flex: none; width: var(--cover-w); aspect-ratio: 2 / 3; border-radius: 3px 6px 6px 3px; overflow: hidden; background: var(--surface-2); text-decoration: none; color: var(--paper-ink); transform-origin: bottom center; transition: transform .18s ease, box-shadow .18s ease; box-shadow: -8px 10px 22px -10px rgba(20,18,14,.55), 0 1px 0 rgba(255,255,255,.4) inset; }
.shelf-book:hover, .shelf-book:focus-visible { transform: translateY(-8px) rotate(-.6deg); box-shadow: -12px 22px 30px -12px rgba(20,18,14,.6); outline: none; }
.shelf-book img { width: 100%; height: 100%; object-fit: cover; display: block; }
.shelf-book .spine { position: absolute; inset-block: 0; right: 0; width: 7px; background: linear-gradient(to left, rgba(0,0,0,.28), rgba(255,255,255,.12) 40%, rgba(0,0,0,.08)); z-index: 2; pointer-events: none; }
.shelf-book .ph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 12px; text-align: center; font-family: var(--font-book); font-size: 15px; line-height: 1.25; background: linear-gradient(160deg, color-mix(in srgb, var(--accent), white 72%), color-mix(in srgb, var(--accent), white 25%)); }
.shelf-book .ribbon { position: absolute; left: 0; bottom: 0; height: 4px; width: var(--p, 0%); background: var(--accent); z-index: 2; }
.shelf-book .tick { position: absolute; top: 8px; inset-inline-start: 8px; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 13px; display: flex; align-items: center; justify-content: center; z-index: 2; }
.shelf-ledge { height: 14px; margin-top: -2px; background: linear-gradient(var(--shelf), var(--shelf-dark)); border-radius: 2px 2px 4px 4px; box-shadow: 0 10px 18px -10px rgba(0,0,0,.45), 0 -1px 0 rgba(255,255,255,.35) inset; position: relative; z-index: 1; }
.shelf-ledge::after { content: ""; position: absolute; inset-inline: 6px; top: 100%; height: 10px; background: linear-gradient(rgba(0,0,0,.14), transparent); }
.shelf-caps { display: flex; gap: var(--cover-gap); padding: 12px 12px 0; }
.shelf-caps .cap { width: var(--cover-w); flex: none; font-size: 12px; line-height: 1.3; display: flex; flex-direction: column; gap: 1px; }
.shelf-caps .cap b { font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-book); font-size: 14px; }
.shelf-caps .cap span { color: var(--ink-3); }
.continue .cover { display: block; text-decoration: none; }
.empty { text-align: center; color: var(--ink-2); padding: 60px 20px; }
.empty a { display: inline-block; margin-top: 12px; }

.devices { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.devices li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; }
.devices li .when { color: var(--ink-3); font-size: 12px; }
.devices li.cur { border-color: var(--accent); }

/* ── הקורא ────────────────────────────────────────────────────────── */
.reader { position: fixed; inset: 0; background: var(--paper); color: var(--paper-ink); display: flex; flex-direction: column; overflow: hidden; touch-action: pan-y; }
.reader.mode-paged { touch-action: none; }
.rd-top, .rd-bottom { position: absolute; inset-inline: 0; z-index: 5; display: flex; align-items: center; gap: 6px; padding-inline: 8px; color: var(--paper-ink); background: color-mix(in srgb, var(--paper), transparent 6%); backdrop-filter: blur(10px); transition: transform .22s ease, opacity .22s ease; }
.rd-top { top: 0; padding-top: var(--safe-t); height: calc(52px + var(--safe-t)); border-bottom: 1px solid var(--paper-line); }
.rd-bottom { bottom: 0; padding-bottom: var(--safe-b); min-height: calc(58px + var(--safe-b)); border-top: 1px solid var(--paper-line); flex-direction: column; align-items: stretch; gap: 4px; padding-block: 8px calc(8px + var(--safe-b)); padding-inline: 16px; }
.reader.chrome-hidden .rd-top { transform: translateY(-100%); opacity: 0; pointer-events: none; }
.reader.chrome-hidden .rd-bottom { transform: translateY(100%); opacity: 0; pointer-events: none; }
.rd-title { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; line-height: 1.2; font-size: 12px; color: var(--paper-mute); }
.rd-title b { font-weight: 500; color: var(--paper-ink); font-size: 13px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rd-title span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rd-bottom .row { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--paper-mute); gap: 10px; font-variant-numeric: tabular-nums; }
.rd-bottom input[type=range] { width: 100%; direction: rtl; accent-color: var(--accent); margin: 0; padding: 0; background: transparent; border: 0; height: 28px; }
.rd-wm { font-size: 10.5px; color: var(--paper-mute); opacity: .8; text-align: center; letter-spacing: .02em; }
.reader.chrome-hidden .rd-wm-float { opacity: .55; }
.rd-wm-float { position: absolute; bottom: calc(6px + var(--safe-b)); inset-inline: 0; text-align: center; font-size: 10px; color: var(--paper-mute); opacity: 0; transition: opacity .3s; pointer-events: none; z-index: 2; }

/* אזור הקריאה */
.rd-stage { position: absolute; inset: 0; display: flex; justify-content: center; }
.rd-frame { position: relative; width: 100%; max-width: var(--rd-maxw, 720px); height: 100%; padding: calc(56px + var(--safe-t)) var(--rd-pad, 22px) calc(64px + var(--safe-b)); }
.reader[data-width="narrow"] { --rd-maxw: 560px; }
.reader[data-width="wide"] { --rd-maxw: 1120px; }
.rd-viewport { position: relative; width: 100%; height: 100%; overflow: hidden; }
.mode-scroll .rd-viewport { overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; padding-bottom: 30vh; }
.rd-flow { will-change: transform; }
.mode-paged .rd-flow { height: 100%; column-fill: auto; transition: transform .28s cubic-bezier(.2,.7,.2,1); }
.mode-paged .rd-flow.no-anim { transition: none; }
.mode-paged .rd-flow > * { break-inside: avoid-column; }
.mode-paged .rd-flow > h1, .mode-paged .rd-flow > h2, .mode-paged .rd-flow > h3 { break-after: avoid; }
.mode-paged .rd-flow img { max-height: 80vh; }
.rd-tap { position: absolute; top: calc(56px + var(--safe-t)); bottom: calc(64px + var(--safe-b)); width: 30%; z-index: 3; }
.rd-tap.next { left: 0; } .rd-tap.prev { right: 0; }
.rd-tap.center { left: 30%; width: 40%; }
.mode-scroll .rd-tap.next, .mode-scroll .rd-tap.prev { display: none; }
.mode-scroll .rd-tap.center { display: none; }
.rd-edge { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .2s; background: linear-gradient(to left, transparent 70%, color-mix(in srgb, var(--accent), transparent 85%)); }
.rd-edge.start { background: linear-gradient(to right, transparent 70%, color-mix(in srgb, var(--accent), transparent 85%)); }
.rd-edge.on { opacity: 1; }
.rd-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--paper-mute); font-size: 13px; gap: 10px; background: var(--paper); z-index: 4; }

/* טקסט הספר */
.book-text { font-family: var(--rd-font, var(--font-book)); font-size: var(--rd-size, 19px); line-height: var(--rd-lh, 1.65); color: var(--paper-ink); text-align: var(--rd-align, start); hyphens: none; -webkit-font-smoothing: antialiased; }
.book-text > * { margin: 0; }
.book-text p { margin: 0 0 var(--rd-para, .55em); text-indent: 0; }
.book-text p + p { text-indent: var(--rd-indent, 0); }
.book-text h1, .book-text h2, .book-text h3, .book-text h4 { font-weight: 500; line-height: 1.2; text-align: start; letter-spacing: -.01em; margin: 0 0 .8em; text-wrap: balance; }
.book-text h1 { font-size: 1.7em; margin-top: 1.2em; } .book-text h2 { font-size: 1.4em; margin-top: 1em; } .book-text h3 { font-size: 1.15em; margin-top: .8em; }
.book-text blockquote { margin: .8em 1.2em; padding-inline-start: 1em; border-inline-start: 2px solid var(--paper-line); color: var(--paper-ink); font-style: normal; }
.book-text ul, .book-text ol { padding-inline-start: 1.4em; margin: 0 0 .6em; }
.book-text img { max-width: 100%; height: auto; display: block; margin: .6em auto; border-radius: 3px; }
.book-text figure { margin: .8em 0; } .book-text figcaption { font-size: .8em; color: var(--paper-mute); text-align: center; margin-top: .4em; font-family: var(--font-ui); }
.book-text hr { border: 0; text-align: center; margin: 1.4em 0; }
.book-text hr::after { content: "❦"; color: var(--paper-mute); font-size: .9em; }
.book-text sup { font-size: .7em; line-height: 0; } .book-text sup a { text-decoration: none; color: var(--accent); }
.book-text a { color: var(--accent); text-decoration: none; }
.book-text table { border-collapse: collapse; font-size: .9em; width: 100%; } .book-text td, .book-text th { border: 1px solid var(--paper-line); padding: .3em .5em; }
.book-text ::selection { background: var(--paper-sel); }
.book-text mark.hl { background: transparent; color: inherit; border-radius: 2px; box-decoration-break: clone; -webkit-box-decoration-break: clone; padding: .05em 0; cursor: pointer; }
.book-text mark.hl.c1 { background: rgba(246,208,74,.45); } .book-text mark.hl.c2 { background: rgba(120,200,140,.4); } .book-text mark.hl.c3 { background: rgba(120,170,240,.4); } .book-text mark.hl.c4 { background: rgba(240,140,160,.4); }
html[data-paper="night"] .book-text mark.hl.c1 { background: rgba(246,208,74,.28); } html[data-paper="night"] .book-text mark.hl.c2 { background: rgba(120,200,140,.28); } html[data-paper="night"] .book-text mark.hl.c3 { background: rgba(120,170,240,.3); } html[data-paper="night"] .book-text mark.hl.c4 { background: rgba(240,140,160,.3); }
.book-text mark.hl.has-note::after { content: "✎"; font-size: .65em; color: var(--accent); margin-inline-start: 2px; vertical-align: super; font-family: var(--font-ui); }
.book-text .flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0% { background: var(--paper-sel); } 100% { background: transparent; } }
.book-text .chapter-end { margin-top: 2.5em; padding-top: 1.4em; border-top: 1px solid var(--paper-line); font-family: var(--font-ui); font-size: 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px; color: var(--paper-mute); break-inside: avoid; }
.book-text .chapter-end button { color: var(--accent); border: 1px solid currentColor; border-radius: 999px; padding: 7px 16px; font-weight: 500; }
.book-text .book-end { text-align: center; font-family: var(--font-ui); margin-top: 3em; color: var(--paper-mute); font-size: 14px; }
.book-text .book-end b { display: block; font-family: var(--font-book); font-size: 1.4em; color: var(--paper-ink); font-weight: 500; margin-bottom: 8px; }

/* פאנלים (מגירה בצד/למטה) */
.rd-panel { position: absolute; z-index: 8; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); display: flex; flex-direction: column; inset-inline-end: 0; top: 0; bottom: 0; width: min(420px, 100%); transform: translateX(-100%); transition: transform .25s ease; }
.rd-panel.open { transform: none; }
.rd-panel-back { position: absolute; inset: 0; z-index: 7; background: rgba(0,0,0,.25); opacity: 0; pointer-events: none; transition: opacity .25s; }
.rd-panel-back.open { opacity: 1; pointer-events: auto; }
.rd-panel header { display: flex; align-items: center; justify-content: space-between; padding: calc(10px + var(--safe-t)) 10px 10px 14px; border-bottom: 1px solid var(--line); }
.rd-panel header h2 { font-size: 17px; font-weight: 500; margin: 0; }
.rd-panel .body { flex: 1; overflow: auto; padding: 8px 0 calc(16px + var(--safe-b)); }
@media (max-width: 640px) { .rd-panel { inset-inline: 0; top: auto; bottom: 0; width: 100%; max-height: 82vh; border-radius: 20px 20px 0 0; transform: translateY(100%); } .rd-panel header { padding-top: 10px; } }

.toc { list-style: none; margin: 0; padding: 0; }
.toc li button { width: 100%; text-align: start; padding: 11px 18px; display: flex; gap: 10px; align-items: baseline; border-bottom: 1px solid color-mix(in srgb, var(--line), transparent 40%); }
.toc li button:hover { background: var(--surface-2); }
.toc li.l2 button { padding-inline-start: 34px; font-size: 14px; color: var(--ink-2); }
.toc li.l3 button { padding-inline-start: 50px; font-size: 13px; color: var(--ink-3); }
.toc li.cur button { color: var(--accent); font-weight: 500; }
.toc li .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line-2); flex: none; position: relative; top: -2px; }
.toc li.read .dot { background: var(--accent); }
.toc li .mins { margin-inline-start: auto; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.settings { padding: 4px 18px; display: flex; flex-direction: column; gap: 18px; }
.settings .grp { display: flex; flex-direction: column; gap: 8px; }
.settings .grp > label { font-size: 12px; color: var(--ink-3); letter-spacing: .06em; text-transform: uppercase; font-weight: 500; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 999px; overflow: hidden; background: var(--surface); width: 100%; }
.seg button { flex: 1; padding: 9px 8px; font-size: 14px; color: var(--ink-2); display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.seg .sw { width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--line-2); }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button { width: 44px; height: 40px; border: 1px solid var(--line-2); border-radius: 10px; font-family: var(--font-book); }
.stepper .val { flex: 1; text-align: center; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.stepper .a-small { font-size: 14px; } .stepper .a-big { font-size: 22px; }
.settings .fnt-book { font-family: var(--font-book); } .settings .fnt-david { font-family: var(--font-david); } .settings .fnt-sans { font-family: var(--font-sans); }

.anns { list-style: none; margin: 0; padding: 0 }
.anns .grp-title { padding: 10px 18px 4px; font-size: 12px; color: var(--ink-3); letter-spacing: .06em; }
.anns li { padding: 10px 18px; border-bottom: 1px solid color-mix(in srgb, var(--line), transparent 40%); display: flex; flex-direction: column; gap: 6px; }
.anns li .q { font-family: var(--font-book); font-size: 16px; line-height: 1.45; border-inline-start: 3px solid var(--line-2); padding-inline-start: 10px; text-align: start; cursor: pointer; }
.anns li .q.c1 { border-color: #E3B93A; } .anns li .q.c2 { border-color: #5DB27A; } .anns li .q.c3 { border-color: #5E8FE0; } .anns li .q.c4 { border-color: #D97A93; }
.anns li .note { font-size: 14px; color: var(--ink-2); white-space: pre-wrap; }
.anns li .meta { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--ink-3); }
.anns li .meta .acts { display: flex; gap: 12px; } .anns li .meta .acts button { color: var(--accent); }
.anns li.bm .q { border-color: var(--accent); font-family: var(--font-ui); font-size: 14px; }

.search { padding: 8px 18px; display: flex; flex-direction: column; gap: 10px; }
.search .res { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; }
.search .res li button { width: 100%; text-align: start; padding: 10px 0; border-bottom: 1px solid color-mix(in srgb, var(--line), transparent 40%); font-size: 14px; line-height: 1.5; color: var(--ink-2); }
.search .res li button b { color: var(--ink); background: rgba(246,208,74,.45); border-radius: 2px; padding: 0 1px; font-weight: 500; }
.search .res li button small { display: block; color: var(--ink-3); font-size: 12px; margin-bottom: 2px; }
.search .none { color: var(--ink-3); font-size: 14px; padding: 12px 0; }

/* פופאובר לבחירת טקסט */
.sel-pop { position: absolute; z-index: 9; background: var(--ink); color: var(--ground); border-radius: 12px; padding: 6px; display: flex; gap: 2px; align-items: center; box-shadow: var(--shadow); transform: translate(-50%, -100%); white-space: nowrap; }
html[data-ui="dark"] .sel-pop { background: var(--surface-2); color: var(--ink); }
.sel-pop::after { content: ""; position: absolute; left: 50%; bottom: -6px; width: 12px; height: 12px; background: inherit; transform: translateX(-50%) rotate(45deg); border-radius: 2px; }
.sel-pop button { width: 38px; height: 38px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; color: inherit; }
.sel-pop button:hover { background: rgba(255,255,255,.12); }
.sel-pop button svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sel-pop .c { width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255,255,255,.6); }
.sel-pop .c.c1 { background: #F6D04A; } .sel-pop .c.c2 { background: #78C88C; } .sel-pop .c.c3 { background: #78AAF0; } .sel-pop .c.c4 { background: #F08CA0; }
.sel-pop .sep { width: 1px; height: 22px; background: rgba(255,255,255,.2); margin: 0 4px; }
.sel-pop.below { transform: translate(-50%, 0); }
.sel-pop.below::after { bottom: auto; top: -6px; }

.note-box textarea { min-height: 110px; resize: vertical; font-family: var(--font-ui); }
.share-preview { width: 100%; border-radius: 12px; display: block; box-shadow: var(--shadow); }
.share-hint { font-size: 13px; color: var(--ink-3); margin: 10px 0 0; text-align: center; }

/* דסקטופ: שני טורים אפשריים, פאנל בצד */
@media (min-width: 900px) { .reader[data-cols="2"] .rd-frame, .reader[data-cols="auto"] .rd-frame { --rd-maxw: 1120px; } }
