/* קורא הספרים של טוביה */
:root {
    --paper: #fbf9f4;
    --ink: #1d1c33;
    --muted: #6a6880;
    --bar: rgba(251, 249, 244, 0.94);
    --line: #e4e0d6;
    --accent: #2f2a86;
    --gold: #f2b43a;
    --hl: rgba(242, 180, 58, 0.22);
    --hl-word: rgba(242, 180, 58, 0.55);
    --panel: #ffffff;
    --font-size: 21px;
    --face: 'Frank Ruhl Libre', 'David Libre', 'Times New Roman', serif;
}
body.tr-theme-sepia {
    --paper: #f4ecd8;
    --ink: #3b2f22;
    --muted: #7a6a55;
    --bar: rgba(244, 236, 216, 0.95);
    --line: #e0d3b5;
    --panel: #fbf5e6;
    --hl: rgba(180, 120, 40, 0.18);
    --hl-word: rgba(200, 140, 40, 0.45);
}
body.tr-theme-night {
    --paper: #0b0e33;
    --ink: #e6e3f5;
    --muted: #a9a6c8;
    --bar: rgba(11, 14, 51, 0.95);
    --line: #262a5a;
    --accent: #ffe29a;
    --panel: #14174a;
    --hl: rgba(255, 226, 154, 0.14);
    --hl-word: rgba(255, 226, 154, 0.38);
}
body.tr-face-sans { --face: 'Assistant', system-ui, sans-serif; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    background: var(--paper);
    color: var(--ink);
    font-family: 'Assistant', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.3s, color 0.3s;
}
button, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.tr-app { min-height: 100%; display: flex; flex-direction: column; }

/* סרגל עליון */
.tr-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top));
    background: var(--bar);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
}
.tr-icon-btn {
    width: 40px;
    height: 40px;
    flex: none;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--ink);
    text-decoration: none;
}
.tr-icon-btn:hover { background: var(--hl); }
.tr-icon-btn svg, .tr-nav-btn svg, .tr-listen svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.tr-aa { font-family: var(--face); font-weight: 700; font-size: 1.05rem; }
.tr-bar-title {
    flex: 1;
    min-width: 0;
    text-align: center;
    line-height: 1.2;
}
.tr-bar-title strong {
    display: block;
    font-family: 'Frank Ruhl Libre', serif;
    font-size: 1.05rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tr-bar-title span {
    display: block;
    font-size: 0.82rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tr-listen {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: none;
    height: 40px;
    padding: 0 16px;
    border: 0;
    border-radius: 99px;
    background: var(--accent);
    color: var(--paper);
    font-weight: 700;
}
.tr-listen svg { fill: currentColor; stroke: none; width: 18px; height: 18px; }
.tr-listen .i-pause { display: none; }
.tr-listen[aria-pressed="true"] .i-play { display: none; }
.tr-listen[aria-pressed="true"] .i-pause { display: inline; }
.tr-progress {
    position: absolute;
    inset-inline: 0;
    bottom: -1px;
    height: 3px;
}
.tr-progress span {
    display: block;
    height: 100%;
    width: 0;
    margin-inline-start: 0;
    background: var(--gold);
    transition: width 0.4s ease;
}

/* חלוניות */
.tr-panel {
    position: fixed;
    z-index: 30;
    top: 64px;
    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
    padding: 16px;
    max-height: calc(100vh - 90px);
    overflow-y: auto;
}
.tr-toc { right: 12px; width: min(360px, calc(100vw - 24px)); }
.tr-settings { left: 12px; width: min(340px, calc(100vw - 24px)); }
.tr-panel-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.tr-panel-head strong { display: block; font-family: 'Frank Ruhl Libre', serif; font-size: 1.15rem; }
.tr-panel-head span { color: var(--muted); font-size: 0.9rem; }
.tr-toc-cover { width: 58px; border-radius: 4px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); }
.tr-toc ol { list-style: none; margin: 0; padding: 0; }
.tr-toc li button {
    width: 100%;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    text-align: right;
    padding: 10px 8px;
    border: 0;
    border-top: 1px solid var(--line);
    background: transparent;
}
.tr-toc li button:hover { background: var(--hl); }
.tr-toc li.is-current button { font-weight: 700; color: var(--accent); }
.tr-toc li small { color: var(--muted); white-space: nowrap; }
.tr-toc li .tr-lock { font-size: 0.8rem; }
.tr-set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.tr-seg { display: inline-flex; background: var(--hl); border-radius: 10px; padding: 3px; }
.tr-seg button {
    border: 0;
    background: transparent;
    padding: 6px 12px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.92rem;
}
.tr-seg button.is-on { background: var(--panel); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15); color: var(--accent); }
.tr-face-serif { font-family: 'Frank Ruhl Libre', serif; }
.tr-voice-row select {
    max-width: 190px;
    padding: 6px 8px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--panel);
}
.tr-voice-note { margin: 0; font-size: 0.88rem; color: var(--muted); line-height: 1.5; }

/* דף הספר */
.tr-stage {
    flex: 1;
    position: relative;
    padding: 34px 20px 40px;
    overflow: hidden;
}
.tr-page {
    max-width: 680px;
    margin: 0 auto;
    font-family: var(--face);
    font-size: var(--font-size);
    line-height: 1.9;
    text-align: justify;
    text-justify: inter-word;
    hyphens: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    position: relative;
    z-index: 1;
}
.tr-page.is-turning-next { animation: tr-in-next 0.32s ease; }
.tr-page.is-turning-prev { animation: tr-in-prev 0.32s ease; }
@keyframes tr-in-next { from { opacity: 0; transform: translateX(-26px); } to { opacity: 1; transform: none; } }
@keyframes tr-in-prev { from { opacity: 0; transform: translateX(26px); } to { opacity: 1; transform: none; } }
.tr-page p { margin: 0 0 1em; text-indent: 1.4em; }
.tr-page p.tr-first, .tr-page p.tr-bold { text-indent: 0; }
.tr-page p.tr-bold { font-weight: 700; }
.tr-page h2 {
    font-family: 'Frank Ruhl Libre', serif;
    font-weight: 900;
    font-size: 1.55em;
    line-height: 1.3;
    text-align: center;
    margin: 0.4em 0 1.2em;
}
.tr-page h2::after {
    content: "";
    display: block;
    width: 64px;
    height: 2px;
    margin: 0.6em auto 0;
    background: var(--gold);
}
.tr-page .tr-front {
    min-height: 58vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}
.tr-page .tr-front p { text-indent: 0; margin: 0 0 0.5em; }
.tr-page .tr-front p.tr-title { font-weight: 900; font-size: 2.2em; line-height: 1.2; }
.tr-page .tr-front p.tr-small { font-size: 0.85em; color: var(--muted); }
.tr-page .tr-front img { width: min(240px, 60vw); margin-bottom: 1.4em; border-radius: 4px; box-shadow: 0 14px 34px rgba(0, 0, 0, 0.25); }
.tr-s { border-radius: 4px; transition: background 0.2s; }
.tr-s.is-reading { background: var(--hl); box-shadow: 0 0 0 3px var(--hl); }
.tr-w.is-word { background: var(--hl-word); border-radius: 3px; }
.tr-page .tr-s { cursor: pointer; }

/* סימן מים: שם הקורא על הדף */
.tr-mark {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
    opacity: 0.07;
    background-repeat: repeat;
}

/* דף נעול */
.tr-locked {
    text-align: center;
    font-family: 'Assistant', sans-serif;
    padding: 40px 10px;
}
.tr-locked .tr-lock-icon { font-size: 2.4rem; }
.tr-locked h2::after { display: none; }
.tr-locked p { text-indent: 0; font-size: 1.05rem; color: var(--muted); }
.tr-locked .tr-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 18px; }
.tr-btn {
    display: inline-flex;
    align-items: center;
    padding: 12px 22px;
    border-radius: 8px;
    font-weight: 800;
    text-decoration: none;
    font-size: 1rem;
}
.tr-btn-gold { background: var(--gold); color: #14133f; }
.tr-btn-line { border: 2px solid currentColor; color: var(--ink); }
.tr-loading { text-align: center; color: var(--muted); padding: 60px 0; font-family: 'Assistant', sans-serif; }

/* ניווט תחתון */
.tr-nav {
    position: sticky;
    bottom: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 12px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    background: var(--bar);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
}
.tr-nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-width: 96px;
    justify-content: center;
    height: 42px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 99px;
    background: transparent;
    font-weight: 700;
}
.tr-nav-btn:hover:not([disabled]) { background: var(--hl); }
.tr-nav-btn[disabled] { opacity: 0.35; cursor: default; }
.tr-page-no { color: var(--muted); font-size: 0.92rem; }

@media (max-width: 560px) {
    :root { --font-size: 19px; }
    .tr-stage { padding: 22px 18px 30px; }
    .tr-listen span { display: none; }
    .tr-listen { padding: 0 12px; }
    .tr-nav-btn { min-width: 0; }
    .tr-nav-btn span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    .tr-page.is-turning-next, .tr-page.is-turning-prev { animation: none; }
}
@media print {
    body * { display: none !important; }
    body::after { content: "הדפסת הספר אינה זמינה."; display: block !important; }
}

/* ספר מאויר */
.tr-page .tr-illus { margin: 0 0 1.2em; }
.tr-page .tr-illus img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 12px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
    -webkit-user-drag: none;
    user-select: none;
    pointer-events: none;
}
.tr-page .tr-illus + h2 { margin-top: 0.6em; }
