:root {
    --mishna: #1a5276;
    --question: #c0392b;
    --answer: #1e8449;
    --challenge: #8b0000;
    --drasha: #b9770e;
    --alternative: #2471a3;
    --source: #6c3483;
    --rule: #117a65;
    --gemara: #2c3e50;
    --aggada: #b9770e;
    --story: #b9770e;
    --opinion: #2471a3;
    --halacha: #117a65;
    --summary: #566573;
    --tosfot: #7c3f99;
    --flow-line: #bdc3c7;
    --memorial-color: var(--mishna);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 100%; }

body {
    font-family: 'David', 'Noto Sans Hebrew', 'Segoe UI', Arial, sans-serif;
    background: #f7f9fc;
    color: #2c3e50;
    line-height: 2;
}

h1 {
    text-align: center;
    font-size: 1.7em;
    color: var(--mishna);
    margin-bottom: 4px;
    letter-spacing: 1px;
}
.subtitle {
    text-align: center;
    color: #7f8c8d;
    font-size: 1em;
    margin-bottom: 35px;
}

/* ── Legend ── */
.legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-bottom: 14px;
    padding: 10px 14px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,.07);
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: .88em;
}
.legend-dot {
    width: 14px; height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ── Generic block ── */
.block {
    position: relative;
    border-right: 5px solid;
    border-radius: 10px;
    padding: 14px 18px;
    padding-right: 58px;
    margin-right: calc(var(--auto-indent-level, 0) * 35px);
    margin-bottom: 14px;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0,0,0,.06);
    transition: transform .15s, box-shadow .15s;
}
.block:hover { transform: translateX(-3px); box-shadow: 0 0 0 3px rgba(44,62,80,.25); }

/* ── Block type icon with label ── */
.block-type-icon-wrap {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    pointer-events: none;
    user-select: none;
    opacity: .85;
    z-index: 1;
}
.block-type-icon {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: .72em;
    line-height: 1;
    text-align: center;
}
.block-type-icon.icon-text {
    font-size: .58em;
    letter-spacing: .3px;
}
.block-type-icon.icon-symbol {
    font-size: 1.05em;
}
.block-type-label {
    font-size: .72em;
    font-weight: 600;
    color: #1a1a1a;
    white-space: pre-line;
    letter-spacing: .3px;
    line-height: 1.05;
}
.b-mishna  .block-type-icon { background: var(--mishna); }
.b-gemara  .block-type-icon { background: var(--gemara); }
.b-question .block-type-icon { background: var(--question); }
.b-answer  .block-type-icon { background: var(--answer); }
.b-challenge .block-type-icon { background: var(--challenge); }
.b-drasha  .block-type-icon { background: var(--drasha); }
.b-source  .block-type-icon { background: var(--source); }
.b-rule    .block-type-icon { background: var(--rule); }
.b-aggada  .block-type-icon { background: var(--aggada); }
.b-story   .block-type-icon { background: var(--story); }
.b-opinion .block-type-icon { background: var(--opinion); }
.b-alternative .block-type-icon { background: var(--alternative); }
.b-halacha .block-type-icon { background: var(--halacha); }
.b-summary .block-type-icon { background: var(--summary); }

.block-tag {
    display: inline-block;
    padding: 2px 14px;
    border-radius: 20px;
    color: #fff;
    font-size: .78em;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: .5px;
}

/* ── Block header: tag + icon ── */
.block-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.block-header .block-tag {
    margin-bottom: 0;
}
.trans-switcher {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    justify-content: flex-start;
    position: relative;
    z-index: 3;
}
.trans-mode-btn {
    font-family: inherit;
    font-size: .62em;
    padding: 1px 7px;
    border: 1.5px solid #bbb;
    border-radius: 12px;
    background: #fff;
    color: #555;
    cursor: pointer;
    transition: all .15s;
    line-height: 1.4;
    position: relative;
    z-index: 4;
    pointer-events: auto;
}
.trans-mode-btn:hover {
    background: #f0f4f8;
    border-color: #7ba3c9;
}
.trans-mode-btn.active {
    font-size: .72em;
    padding: 2px 10px;
    background: #2c5f8a;
    color: #fff;
    border-color: #2c5f8a;
}

.block-text {
    font-size: 1.15em;
    line-height: 2.1;
}
.block-text .source-quote {
    background: #fef9e7;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
}
/* TEST: sentence-split rendering — highlight hugs each line, no empty
   leading/trailing highlighted line. */
.block-text .source-quote.has-sentence-lines {
    display: block;
    background: none;
    padding: 0;
    border-radius: 0;
}
.block-text .source-quote.has-sentence-lines .sentence-line {
    display: flex;
    align-items: baseline;
    width: fit-content;
    max-width: 100%;
    background: #fef9e7;
    padding: 2px 8px;
    border-radius: 4px;
    margin: 3px 0;
}
.block-text .source-quote.has-sentence-lines .sentence-icon {
    flex: 0 0 4.4em;
    font-size: 0.68em;
    font-weight: 700;
    white-space: nowrap;
    text-align: start;
}
.block-text .source-quote.has-sentence-lines .sentence-body {
    flex: 1 1 auto;
    min-width: 0;
}
.block-text .source-quote .aramit-word,
.block-explanation .source-quote .aramit-word {
    border-bottom: 1px dotted #c49b2a;
    cursor: help;
}

.aramit-tooltip {
    position: fixed;
    top: 0;
    left: 0;
    padding: 6px 10px;
    border-radius: 8px;
    background: #1f2933;
    color: #f8fafc;
    font-size: .86em;
    line-height: 1.4;
    box-shadow: 0 10px 24px rgba(15, 23, 42, .25);
    opacity: 0;
    transform: translate(-9999px, -9999px);
    transition: opacity .12s ease-out;
    pointer-events: none;
    z-index: 9999;
    white-space: nowrap;
}

.aramit-tooltip.is-visible {
    opacity: 1;
}

.block-translation-box {
    position: relative;
    display: block;
    margin-top: 6px;
    padding: 6px 10px 40px;
    background: #eaf2f8;
    border-radius: 4px;
    font-size: .92em;
    color: #2c3e50;
    border-right: 3px solid #85c1e9;
    min-height: 42px;
}

.block-translation-box .trans-switcher {
    position: absolute;
    left: 10px;
    bottom: 8px;
    margin-right: 0;
    direction: ltr;
}

.trans-switcher-fallback {
    display: flex;
    gap: 4px;
    margin-top: 8px;
    margin-right: auto;
    margin-left: 0;
    width: fit-content;
    direction: ltr;
}

.block-translation {
    display: block;
    margin-top: 0;
    padding: 0;
}

.block-explanation {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed #ddd;
    color: #555;
    font-size: .95em;
}

/* ── Specific colours ── */
.b-mishna        { border-color: var(--mishna); }
.b-mishna .block-tag { background: var(--mishna); }

.b-question      { border-color: var(--question); }
.b-question .block-tag { background: var(--question); }

.b-answer        { border-color: var(--answer); }
.b-answer .block-tag { background: var(--answer); }

.b-challenge     { border-color: var(--challenge); }
.b-challenge .block-tag { background: var(--challenge); }

.b-drasha        { border-color: var(--drasha); }
.b-drasha .block-tag { background: var(--drasha); }

.b-alternative   { border-color: var(--alternative); }
.b-alternative .block-tag { background: var(--alternative); }

.b-source        { border-color: var(--source); }
.b-source .block-tag { background: var(--source); }

.b-rule          { border-color: var(--rule); }
.b-rule .block-tag { background: var(--rule); }

.b-gemara        { border-color: var(--gemara); }
.b-gemara .block-tag { background: var(--gemara); }

.b-aggada        { border-color: var(--aggada); }
.b-aggada .block-tag { background: var(--aggada); }

.b-story         { border-color: var(--story); }
.b-story .block-tag { background: var(--story); }

.b-opinion       { border-color: var(--opinion); }
.b-opinion .block-tag { background: var(--opinion); }

.b-halacha       { border-color: var(--halacha); }
.b-halacha .block-tag { background: var(--halacha); }

.b-summary       { border-color: var(--summary); }
.b-summary .block-tag { background: var(--summary); }

.b-tosfot        { border-color: var(--tosfot); }
.b-tosfot .block-tag { background: var(--tosfot); }
.b-tosfot .block-type-icon { background: var(--tosfot); }

/* ── Flow arrows ── */
.flow-arrow {
    text-align: center;
    font-size: 1.6em;
    color: var(--flow-line);
    margin: -8px 0;
    user-select: none;
}

/* ── Section divider ── */
.section-title {
    font-size: 1.25em;
    font-weight: 700;
    color: #34495e;
    margin: 24px 0 10px;
    padding-bottom: 4px;
    border-bottom: 3px double #bdc3c7;
}

/* ── Summary table ── */
.summary-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0 40px;
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(0,0,0,.06);
}
.summary-table th {
    background: #2c3e50;
    color: #fff;
    padding: 12px 16px;
    font-weight: 600;
}
.summary-table td {
    padding: 10px 16px;
    border-bottom: 1px solid #ecf0f1;
}
.summary-table tr:last-child td { border-bottom: none; }
.summary-table tr:hover td { background: #f0f4f8; }

/* ── Flow diagram ── */
.flow-diagram {
    background: #fff;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 2px 8px rgba(0,0,0,.07);
    margin: 30px 0;
}
.flow-node {
    display: inline-block;
    padding: 8px 18px;
    border-radius: 8px;
    color: #fff;
    font-weight: 600;
    margin: 4px;
    font-size: .9em;
}
.flow-connector {
    display: block;
    text-align: center;
    font-size: 1.3em;
    color: #95a5a6;
    margin: 2px 0;
}

/* ── Mermaid diagrams ── */
.mermaid-wrap {
    background: #fff;
    border-radius: 12px;
    padding: 30px 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,.07);
    margin: 30px 0;
    text-align: center;
    overflow-x: auto;
}
.mermaid-wrap .mermaid { direction: ltr; }
.mermaid-wrap .mermaid svg { height: auto; }

.dir-arrow {
    display: inline-block;
    direction: ltr;
    unicode-bidi: isolate;
    margin: 0 .18em;
}

/* ── Navigation ── */
.nav-links {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 16px;
}
.nav-links a {
    display: inline-block;
    padding: 8px 24px;
    background: var(--mishna);
    color: #fff;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: .95em;
    transition: background .2s;
    direction: rtl;
    unicode-bidi: isolate;
}
.nav-links a:hover { background: #154360; }
.nav-arrow {
    font-weight: bold;
    font-size: 1.1em;
}

/* ── Page dropdown (center of nav row) ── */
.nav-page-select {
    font-family: inherit;
    font-size: 1.15em;
    font-weight: 600;
    padding: 8px 14px 8px 34px;
    background: var(--mishna);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    direction: rtl;
    text-align: right;
    text-align-last: right;
    transition: background .2s;
    max-width: 45vw;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23ffffff' d='M2 4l4 4 4-4z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 12px center;
    background-size: 12px 12px;
}
.nav-page-select:hover { background-color: #154360; }
.nav-page-select:focus { outline: 2px solid #7ba3c9; outline-offset: 1px; }
.nav-page-select option {
    background: #fff;
    color: #1a2b3a;
    direction: rtl;
    text-align: right;
}

/* ── "סיימתי" read-page button ── */
.read-page-btn {
    display: inline-block;
    padding: 10px 32px;
    font-size: 1.1em;
    font-weight: 700;
    border: 2px solid #2c6faa;
    border-radius: 24px;
    background: #fff;
    color: #2c6faa;
    cursor: pointer;
    transition: all .25s;
    letter-spacing: 1px;
}
.read-page-btn:hover {
    background: #e8f0f8;
}
.read-page-btn.read {
    background: #2c6faa;
    color: #fff;
    box-shadow: inset 0 2px 6px rgba(0,0,0,.15);
}
.read-page-btn.read:hover {
    background: #1a5a94;
}

/* ── Rashi left-column ── */
.block:has(.rashi-wrapper) {
    padding-left: 260px;
}
.rashi-wrapper {
    position: absolute;
    top: 20px;
    left: 26px;
    width: 220px;
    bottom: 20px;
    overflow-y: auto;
    border-right: 2px solid #d4a574;
    padding-right: 12px;
}
.rashi-label {
    font-size: .8em;
    font-weight: 700;
    color: #8b4513;
    margin-bottom: 6px;
}
.rashi-label::before { content: '📖 '; }
.rashi-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}
.rashi-label-row .rashi-label { margin-bottom: 0; }
.rashi-switcher {
    display: inline-flex;
    gap: 4px;
}
.rashi-mode-btn {
    font-family: inherit;
    font-size: .72em;
    padding: 1px 8px;
    border: 1px solid #d4a574;
    border-radius: 10px;
    background: transparent;
    color: #8b4513;
    cursor: pointer;
    line-height: 1.6;
    position: relative;
    z-index: 5;
    pointer-events: auto;
}
.rashi-mode-btn:hover { background: #f3e3cf; }
.rashi-mode-btn.active {
    background: #8b4513;
    color: #fff;
    border-color: #8b4513;
}
.rashi-content {
    font-size: .82em;
    line-height: 1.8;
    color: #5a3e1b;
    background: #fdf6ee;
    padding: 10px 12px;
    border: 1px solid #e0c9a6;
    border-radius: 8px;
}
.rashi-content strong { color: #8b4513; }

/* ── Rashi deselected (no mode chosen): free the column, keep only the
      label + buttons pinned to the top-left corner of the block ── */
.block.rashi-hidden .rashi-content { display: none; }
.block.rashi-hidden .rashi-label-row { margin-bottom: 0; }
@media (min-width: 701px) {
    .block.rashi-hidden:has(.rashi-wrapper) {
        padding-left: 18px;
    }
    .block.rashi-hidden .rashi-wrapper {
        position: absolute;
        top: 12px;
        left: 14px;
        width: auto;
        bottom: auto;
        overflow: visible;
        border-right: none;
        padding-right: 0;
        background: rgba(253, 246, 238, .92);
        border: 1px solid #e0c9a6;
        border-radius: 8px;
        padding: 3px 8px;
        z-index: 2;
    }
}

/* ── Tosafot collapsible panel ── */
.tosafot-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 6px 12px;
    margin-top: 8px;
    background: #f3e8f9;
    border: 1px solid #c9a0dc;
    border-radius: 6px;
    width: fit-content;
    user-select: none;
    transition: background .2s;
}
.tosafot-toggle:hover {
    background: #e8d4f3;
}
.tosafot-toggle-arrow {
    display: inline-block;
    font-size: .75em;
    color: #7b2d8b;
    transition: transform .25s;
}
.tosafot-toggle.open .tosafot-toggle-arrow {
    transform: rotate(180deg);
}
.tosafot-toggle-label {
    font-size: .82em;
    font-weight: 700;
    color: #7b2d8b;
}
.tosafot-panel {
    display: grid;
    grid-template-rows: 0fr;
    margin-top: 0;
    padding: 0 14px;
    background: #faf4fd;
    border: 1px solid #d4b0e8;
    border-width: 0 1px;
    border-right: 0 solid #9b59b6;
    border-radius: 8px;
    opacity: 0;
    overflow: hidden;
    transition: grid-template-rows .32s ease, opacity .3s ease,
                padding .32s ease, margin .32s ease, border-width .32s ease;
}
.tosafot-inner {
    min-height: 0;
    overflow: hidden;
}
.tosafot-panel.open {
    grid-template-rows: 1fr;
    margin-top: 8px;
    padding: 12px 14px;
    border-width: 1px;
    border-right: 3px solid #9b59b6;
    opacity: 1;
}
.tosafot-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: .8em;
    font-weight: 700;
    color: #7b2d8b;
    margin-bottom: 6px;
}
.tosafot-label-text::before { content: '\1F4D6 '; }
.tosafot-collapse-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 2px 8px;
    background: #f3e8f9;
    border: 1px solid #c9a0dc;
    border-radius: 6px;
    color: #7b2d8b;
    font-size: .9em;
    line-height: 1;
    cursor: pointer;
    transition: background .2s;
}
.tosafot-collapse-btn:hover {
    background: #e8d4f3;
}
.tosafot-collapse-arrow {
    display: inline-block;
    font-size: .75em;
}
.tosafot-content {
    font-size: .82em;
    line-height: 1.8;
    color: #4a2060;
}
.tosafot-content strong { color: #7b2d8b; }

/* ── Steinsaltz commentary (hidden; content shown inline via toggle) ── */
.steinsaltz-wrapper {
    display: none;
}
.steinsaltz-label {
    font-size: .8em;
    font-weight: 700;
    color: #2c5f8a;
    margin-bottom: 6px;
}
.steinsaltz-label::before { content: '📘 '; }
.steinsaltz-content {
    font-size: .82em;
    line-height: 1.8;
    color: #2a3d52;
    background: #eef4fa;
    padding: 10px 12px;
    border: 1px solid #b8d0e8;
    border-radius: 8px;
}
.steinsaltz-content b { color: #1a3a5c; }
.steinsaltz-content small { color: #3a7abd; }

/* ── Settings overlay & panel ── */
.settings-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 10000;
    justify-content: center;
    align-items: center;
}
.settings-overlay.is-open { display: flex; }
.settings-panel {
    background: #fff;
    border-radius: 16px;
    padding: 24px 28px;
    min-width: 260px;
    max-width: 340px;
    width: 90vw;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 12px 40px rgba(0,0,0,.25);
    direction: rtl;
    font-size: .95em;
}
.settings-title {
    font-size: 1.2em;
    font-weight: 700;
    text-align: center;
    margin-bottom: 16px;
    color: #1a2636;
}
.settings-group {
    margin-bottom: 14px;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}
.settings-group:last-of-type { border-bottom: none; }
.settings-label {
    font-weight: 700;
    font-size: .92em;
    color: #34495e;
    margin-bottom: 6px;
}
.settings-option {
    display: block;
    padding: 6px 12px;
    margin: 3px 0;
    border-radius: 8px;
    cursor: pointer;
    transition: background .15s;
    color: #333;
}
.settings-option:hover { background: #f0f4f8; }
.settings-option.active {
    background: #e8f0fe;
    color: #1a5276;
    font-weight: 600;
}
.settings-option input[type="radio"] {
    accent-color: #1a5276;
    margin-left: 6px;
}
.settings-close {
    display: block;
    margin: 12px auto 0;
    padding: 8px 32px;
    border: none;
    border-radius: 10px;
    background: #1a2636;
    color: #fff;
    font-family: inherit;
    font-size: .95em;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s;
}
.settings-close:hover { background: #2c3e50; }

/* ── Flat settings bar ── */
.settings-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 12px 18px;
    padding: 8px 12px;
    background: #f5f7fa;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    margin: 10px 0;
    direction: rtl;
}
.sb-group {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.sb-label {
    font-size: .82em;
    font-weight: 700;
    color: #34495e;
    margin-left: 2px;
}
.sb-btn {
    font-family: inherit;
    font-size: .78em;
    padding: 3px 10px;
    border: 1px solid #c0c8d0;
    border-radius: 12px;
    background: #fff;
    color: #555;
    cursor: pointer;
    transition: all .15s;
}
.sb-btn:hover { background: #eef2f7; }
.sb-btn.sb-active {
    background: #2c5f8a;
    color: #fff;
    border-color: #2c5f8a;
}
@media (max-width: 1000px) {
    .page-layout { flex-direction: column; }
    .source-panel { display: none !important; }
    .main-col { max-width: 100%; }
    .source-drawer-btn { display: none; }
}

@media (max-width: 700px) {
    .settings-bar { display: none; }
}
@media print {
    .settings-bar { display: none; }
}

/* ── Settings button (mobile only) ── */
.settings-btn {
    font-family: inherit;
    font-size: .82em;
    padding: 5px 16px;
    border: 1.5px solid #7ba3c9;
    border-radius: 16px;
    background: #fff;
    color: #2c5f8a;
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
    z-index: 1;
}
.settings-btn:hover {
    background: #2c5f8a;
    color: #fff;
}

/* ── Title row (h1 + print button) ── */
.page-controls {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}
.page-controls .print-btn { grid-column: 1; justify-self: start; }
.page-controls .home-btn { grid-column: 2; justify-self: center; }
.page-controls .settings-btn { grid-column: 3; justify-self: end; }

/* ── Home / index button (top row, centered) ── */
.home-btn {
    font-family: inherit;
    font-size: .82em;
    padding: 5px 16px;
    border: 1.5px solid #b08a4f;
    border-radius: 16px;
    background: #fff;
    color: #8a6528;
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    z-index: 1;
}
.home-btn:hover {
    background: #8a6528;
    color: #fff;
}
.page-banner {
    display: block;
    width: min(100%, 820px);
    margin: 0 auto 12px;
    height: auto;
}
.title-row {
    margin-bottom: 0;
}
.title-row h1 {
    margin-bottom: 0;
}
.memorial-line {
    text-align: center;
    color: var(--memorial-color);
    font-weight: 700;
    letter-spacing: 0.2px;
    line-height: 1.3;
}
.memorial-line-top {
    margin: -2px 0 10px;
    font-size: 1.02rem;
}
.memorial-line-bottom {
    margin: 30px 0 12px;
    font-size: 1.06rem;
}

/* ── Print button ── */
.print-btn {
    font-family: inherit;
    font-size: .82em;
    padding: 5px 16px;
    border: 1.5px solid #5a9e6f;
    border-radius: 16px;
    background: #fff;
    color: #2d6e3f;
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
    z-index: 1;
}
.print-btn:hover {
    background: #2d6e3f;
    color: #fff;
}
@media print {
    .print-btn,
    .source-drawer-btn { display: none; }
}
.steinsaltz-toggle-btn {
    font-family: inherit;
    font-size: .95em;
    padding: 6px 20px;
    border: 2px solid #7ba3c9;
    border-radius: 20px;
    background: #fff;
    color: #2c5f8a;
    cursor: pointer;
    transition: all .2s;
}
.steinsaltz-toggle-btn:hover {
    background: #eef4fa;
}
.steinsaltz-toggle-btn.active {
    background: #2c5f8a;
    color: #fff;
}

/* ── Steinsaltz inline mode (replaces source-quote) ── */
.source-quote.steinsaltz-inline {
    background: #f0f6fc;
    font-weight: normal;
    line-height: 2.2;
}
.source-quote.steinsaltz-inline b {
    font-weight: 700;
    background: #fef9e7;
    padding: 1px 4px;
    border-radius: 3px;
}

/* ── Book index page ── */
.book-index {
    max-width: 1100px;
    margin: 0 auto;
}
.book-index h1 {
    margin-bottom: 0;
}
.book-index-memorial {
    text-align: center;
    margin: -2px 0 16px;
    color: var(--memorial-color);
    font-weight: 700;
    font-size: 1.02rem;
    line-height: 1.3;
}
.page-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(75px, 1fr));
    gap: 10px;
    margin: 30px 0;
}

.page-grid .daf-book {
    display: flex;
    gap: 0;
    overflow: hidden;
    min-width: 0;
    grid-column: span 2;
}

.page-grid .daf-book .daf-page {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    margin: 0;
    border-radius: 0;
}

/* Page a on the right (order 1 in RTL = rightmost), page b on the left */
.page-grid .daf-book .daf-page-a {
    order: 1;
    border-top-right-radius: 10px;
    border-bottom-right-radius: 10px;
    border-right-width: 2px;
    border-left-width: 1px;
}

.page-grid .daf-book .daf-page-b {
    order: 2;
    border-top-left-radius: 10px;
    border-bottom-left-radius: 10px;
    border-left-width: 2px;
    border-right-width: 1px;
}

.page-grid .daf-book .daf-page:hover {
    background: var(--mishna);
    color: #fff;
    border-color: var(--mishna);
    box-shadow: 0 4px 12px rgba(0,0,0,.12);
    transform: none;
    z-index: 1;
}

.page-grid a {
    display: block;
    padding: 10px 8px;
    background: #fff;
    border: 2px solid #dce1e6;
    border-radius: 8px;
    text-align: center;
    text-decoration: none;
    color: #2c3e50;
    font-weight: 600;
    font-size: 1.15em;
    transition: all .15s;
}
.page-grid a:hover {
    background: var(--mishna);
    color: #fff;
    border-color: var(--mishna);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,.12);
}
/* ── Disabled page links (no data file) ── */
.page-grid a.disabled {
    opacity: 0.35;
    color: #aaa;
    background: #f5f5f5;
    border-color: #e0e0e0;
    cursor: default;
    pointer-events: none;
}
/* ── Read page links ── */
.page-grid a.page-read {
    background: #e8f5e9;
    border-color: #81c784;
    color: #2e7d32;
}

.page-grid .daf-book a.page-read-partial {
    background: #fff3e0;
    border-color: #f0b46a;
    color: #ad6400;
}

.page-grid .daf-book a.page-read-complete {
    background: #e8f5e9;
    border-color: #81c784;
    color: #2e7d32;
}

/* ── Masechet reading progress bar ── */
.masechet-progress {
    max-width: 400px;
    margin: 8px auto 16px;
    text-align: center;
}
.masechet-progress .bar-track {
    height: 8px;
    background: #d6e2ee;
    border-radius: 4px;
    overflow: hidden;
}
.masechet-progress .bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width .5s ease;
}
.masechet-progress .pct-label {
    font-size: .82em;
    font-weight: 600;
    margin-top: 4px;
    color: #5a7a96;
}
.masechet-progress.progress-complete .bar-fill { background: #27ae60; }
.masechet-progress.progress-high .bar-fill { background: #7dbb4a; }
.masechet-progress.progress-mid .bar-fill { background: #e8a838; }
.masechet-progress.progress-low .bar-fill { background: #e07a3a; }

/* ── Chapter (Perek) navigation on index page ── */
.perek-nav {
    margin: 24px 0 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}
.perek-nav a {
    display: inline-block;
    padding: 7px 16px;
    background: linear-gradient(135deg, #f7f1e5, #ede5d5);
    border: 1.5px solid #c8bfa8;
    border-radius: 20px;
    text-decoration: none;
    color: #4a3c2a;
    font-weight: 600;
    font-size: .92em;
    transition: all .2s;
    white-space: nowrap;
}
.perek-nav a:hover {
    background: var(--mishna);
    color: #fff;
    border-color: var(--mishna);
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0,0,0,.15);
}

/* ── Pages / Sugyot view toggle (index page) ── */
.view-toggle {
    display: flex;
    justify-content: center;
    gap: 0;
    margin: 22px auto 4px;
    max-width: 320px;
    border: 2px solid var(--mishna);
    border-radius: 24px;
    overflow: hidden;
}
.view-toggle-btn {
    flex: 1 1 0;
    padding: 9px 18px;
    background: #fff;
    color: var(--mishna);
    border: none;
    font-family: inherit;
    font-size: 1em;
    font-weight: 700;
    cursor: pointer;
    transition: all .18s;
}
.view-toggle-btn:hover { background: #eaf1f7; }
.view-toggle-btn.active {
    background: var(--mishna);
    color: #fff;
}

/* ── Sugyot mode: chapter selector ── */
.sugyot-chapter-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    margin: 20px 0 6px;
}
.sugyot-chapter-label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: min(100%, 360px);
    color: #1f4e79;
    font-weight: 700;
    font-size: .95em;
}
.sugyot-chapter-select {
    width: 100%;
    padding: 10px 14px;
    background: linear-gradient(135deg, #eaf4ff, #cfe5ff);
    border: 1.5px solid #78a9d4;
    border-radius: 12px;
    color: #143a5c;
    font: inherit;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(36, 113, 163, .12);
}
.sugyot-chapter-select:focus {
    outline: none;
    border-color: #2471a3;
    box-shadow: 0 0 0 3px rgba(36, 113, 163, .18);
}
.sugyot-chapter-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 15px;
    background: linear-gradient(135deg, #f7f1e5, #ede5d5);
    border: 1.5px solid #c8bfa8;
    border-radius: 20px;
    color: #4a3c2a;
    font-family: inherit;
    font-weight: 600;
    font-size: .92em;
    cursor: pointer;
    transition: all .2s;
}
.sugyot-chapter-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0,0,0,.15);
}
.sugyot-chapter-btn.active {
    background: var(--mishna);
    border-color: var(--mishna);
    color: #fff;
}
.sugyot-chapter-num {
    background: rgba(0,0,0,.12);
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .85em;
    flex-shrink: 0;
}
.sugyot-chapter-btn.active .sugyot-chapter-num { background: rgba(255,255,255,.28); }

/* ── Sugyot mode: page containers + sugya lists ── */
.sugyot-container { margin: 18px 0 30px; }
.sugyot-loading,
.sugya-empty {
    text-align: center;
    color: #7a8a99;
    padding: 10px;
    font-size: .95em;
}
.sugyot-chapter-heading {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25em;
    font-weight: 800;
    color: var(--mishna);
    margin: 8px 0 14px;
}
.sugya-page-group {
    border: 1.5px solid #dce1e6;
    border-radius: 10px;
    margin: 0 0 14px;
    overflow: hidden;
    background: #fff;
}
.sugya-page-head {
    display: block;
    padding: 9px 16px;
    background: linear-gradient(135deg, #1a5276 0%, #2471a3 100%);
    color: #fff;
    text-decoration: none;
    font-weight: 700;
}
.sugya-page-head:hover { filter: brightness(1.08); }
.sugya-page-head.page-read-partial {
    background: linear-gradient(135deg, #f7b560 0%, #e08a1e 100%);
    color: #fff8ef;
}
.sugya-page-head.page-read-complete,
.sugya-page-head.page-read {
    background: linear-gradient(135deg, #4fa767 0%, #2e7d32 100%);
    color: #f5fff6;
}
.sugya-page-head.disabled {
    background: #e9edf1;
    color: #9aa7b2;
    cursor: default;
    pointer-events: none;
}
.sugya-list { display: flex; flex-direction: column; }
.sugya-link {
    display: block;
    padding: 10px 18px;
    border-top: 1px solid #eef1f4;
    color: #2c3e50;
    text-decoration: none;
    font-size: 1.02em;
    transition: background .15s, color .15s;
}
.sugya-link:hover {
    background: var(--mishna);
    color: #fff;
}

/* Two-column daf rows on wide screens: amud א (right) + amud ב (left) */
.sugya-daf-row { display: block; }
.sugya-page-spacer { display: none; }
@media (min-width: 900px) {
    .sugya-daf-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0 18px;
        align-items: start;
    }
    .sugya-daf-row .amud-a { grid-column: 1; }
    .sugya-daf-row .amud-b { grid-column: 2; }
    .sugya-page-spacer { display: block; }
}
.perek-group-header {
    grid-column: 1 / -1;
    padding: 10px 16px 6px;
    margin-top: 10px;
    border-bottom: 2px solid var(--mishna);
    font-size: 1.08em;
    font-weight: 700;
    color: var(--mishna);
    display: flex;
    align-items: baseline;
    gap: 8px;
}
.perek-group-header .perek-num {
    background: var(--mishna);
    color: #fff;
    border-radius: 50%;
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .82em;
    flex-shrink: 0;
}

/* ── Chapter header inside daf page ── */
.perek-banner {
    background: linear-gradient(135deg, #1a5276 0%, #2471a3 100%);
    color: #fff;
    padding: 16px 24px;
    margin: 28px 0 18px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 4px 16px rgba(26,82,118,.25);
}
.perek-banner .perek-banner-num {
    font-size: .88em;
    opacity: .85;
    margin-bottom: 2px;
}
.perek-banner .perek-banner-title {
    font-size: 1.35em;
    font-weight: 700;
    letter-spacing: 1px;
}


@media (max-width: 700px) {
    body.daf-page-view { font-size: 75%; }
    body { padding: 12px; }
    .block { margin-right: calc(var(--auto-indent-level, 0) * 16px); padding: 14px 16px; padding-right: 16px; }
    .block:has(.rashi-wrapper) { padding-left: 16px; }
    .block-type-icon-wrap {
        position: static;
        transform: none;
        flex-direction: row;
        gap: 5px;
        opacity: 1;
    }
    .block-type-icon {
        width: 26px;
        height: 26px;
        font-size: .6em;
    }
    .block-type-icon.icon-text {
        font-size: .48em;
    }
    .block-type-icon.icon-symbol {
        font-size: .85em;
    }
    body.daf-page-view .block-type-label {
        display: inline;
    }
    body.daf-page-view .block-header {
        gap: 8px;
    }
    .rashi-wrapper {
        position: static;
        width: auto;
        border-right: none;
        border-top: 2px solid #d4a574;
        padding-right: 0;
        padding-top: 12px;
        margin-top: 10px;
        overflow-y: visible;
    }
    .block.rashi-hidden .rashi-wrapper {
        border-top: none;
        padding-top: 0;
        margin-top: 8px;
    }
    .page-grid { grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); }
    .page-layout { flex-direction: column; }
    .source-panel { display: none !important; }
    .main-col { max-width: 100%; }
    body { padding-top: 0; }
    .page-controls {
        gap: 10px;
        margin-bottom: 10px;
    }
    .btn-label { display: none; }
    .home-btn .btn-label { display: inline; }
    .print-btn, .settings-btn {
        padding: 9px 14px;
        font-size: .98em;
        border-radius: 18px;
    }
    .home-btn {
        padding: 9px 14px;
        font-size: .9em;
        border-radius: 18px;
        max-width: 40vw;
        overflow: hidden;
    }
    .home-btn .btn-label {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .memorial-line-top,
    .memorial-line-bottom,
    .book-index-memorial {
        font-size: .94rem;
        padding-inline: 10px;
    }
}

/* ── Narrow phones: fit 6 page buttons per row (~390px screens) ── */
@media (max-width: 480px) {
    .page-grid {
        grid-template-columns: repeat(6, 1fr);
        gap: 5px;
    }
    .page-grid a {
        padding: 8px 1px;
        font-size: .8em;
        border-width: 1.5px;
        border-radius: 6px;
    }
}

/* ── Mobile sticky header ── */
.mobile-header {
    display: none;
}
@media (max-width: 700px) {
    .mobile-header {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 9000;
        background: #1a2636;
        color: #f0f0f0;
        align-items: center;
        justify-content: space-between;
        padding: 10px 12px;
        min-height: 58px;
        gap: 6px;
        box-shadow: 0 2px 8px rgba(0,0,0,.25);
        transform: translateY(-100%);
        transition: transform .25s ease, opacity .25s ease;
        opacity: 0;
        direction: rtl;
    }
    .mobile-header.is-visible {
        transform: translateY(0);
        opacity: 1;
    }
    .mobile-header-title {
        font-weight: 700;
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        flex: 1;
        text-align: center;
        min-width: 0;
    }
    .mobile-header a {
        color: #f0f0f0;
        text-decoration: none;
        font-size: 1rem;
        font-weight: 600;
        min-width: 40px;
        min-height: 40px;
        padding: 8px 10px;
        border-radius: 10px;
        background: rgba(255,255,255,.12);
        white-space: nowrap;
        flex-shrink: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .mobile-header a:active { background: rgba(255,255,255,.25); }
    .mobile-header-settings {
        background: rgba(255,255,255,.12);
        color: #f0f0f0;
        border: none;
        font-size: 1.28em;
        min-width: 42px;
        min-height: 42px;
        padding: 8px 10px;
        border-radius: 10px;
        cursor: pointer;
        flex-shrink: 0;
    }
    .mobile-header-settings:active { background: rgba(255,255,255,.25); }
    body.daf-page-view .mobile-header-title,
    body.daf-page-view .mobile-header a {
        font-size: .82rem;
    }
    body.daf-page-view .mobile-header-settings {
        font-size: 1.08em;
    }
}

/* ── Source text side panel ── */
.page-layout {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    max-width: 1800px;
    margin: 0 auto;
}
.page-layout.source-panel-collapsed .source-panel {
    width: 0;
    min-width: 0;
    border-width: 0;
    box-shadow: none;
    background: transparent;
}
.page-layout.source-panel-collapsed .source-panel-header,
.page-layout.source-panel-collapsed .source-panel-scroll {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.main-col {
    flex: 1;
    min-width: 0;
}
.source-panel {
    width: 480px;
    min-width: 0;
    flex-shrink: 0;
    position: sticky;
    top: 12px;
    max-height: calc(100vh - 24px);
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,.05);
    display: flex;
    flex-direction: column;
    overflow: visible;
    transition: width .24s ease, border-width .2s ease, box-shadow .2s ease, background .2s ease;
}
.source-panel-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 16px;
    font-weight: 700;
    font-size: 1em;
    color: #34495e;
    border-bottom: 1px solid #e0e0e0;
    text-align: center;
    flex-shrink: 0;
}
.source-panel-title {
    line-height: 1.2;
}
.source-drawer-btn {
    position: absolute;
    right: -16px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 84px;
    border: 1px solid #cfd8df;
    border-right: none;
    border-radius: 12px 0 0 12px;
    background: #f7fafc;
    color: #34495e;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,.12);
    z-index: 10;
    transition: background .2s ease, color .2s ease;
}
.source-drawer-btn:hover {
    background: #34495e;
    color: #fff;
}
.source-panel-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    direction: ltr;
    transition: opacity .18s ease;
}
.source-panel-body {
    direction: rtl;
    font-size: 1.05em;
    line-height: 2.2;
}
.source-line {
    display: inline;
    padding: 1px 4px;
    border-radius: 3px;
    transition: background .15s;
    cursor: default;
}
.source-line-faded {
    opacity: .4;
}
.source-section-title {
    display: block;
    margin-top: 14px;
    margin-bottom: 4px;
    font-weight: 700;
    font-size: .88em;
    color: #7f8c8d;
    border-bottom: 1px dashed #ddd;
    padding-bottom: 2px;
}
.source-section-title:first-child { margin-top: 0; }

.inline-faded-text {
    opacity: .5;
    font-style: italic;
}

.faded-hole-block {
    opacity: .58;
    border-style: dashed;
    border-color: #c7b79b;
    background: linear-gradient(180deg, rgba(253, 248, 236, .95), rgba(247, 240, 224, .92));
}

.faded-hole-block .block-text {
    margin-top: 0;
}

.faded-hole-block .source-quote {
    display: inline-block;
    background: #f6eedf;
    font-weight: 500;
}

.faded-hole-block .faded-cont-icon {
    background: none;
    color: inherit;
}
