:root {
    --reader-bg: #f3efe7;
    --reader-paper: #fffdf8;
    --reader-text: #27231f;
    --reader-muted: #746c62;
    --reader-accent: #9d3b2e;
    --reader-accent-2: #d8a64e;
    --reader-line: rgba(54, 45, 37, .14);
    --reader-font-size: 20px;
    --reader-shadow: 0 24px 70px rgba(61, 47, 33, .13);
}

body.reader-night {
    --reader-bg: #15191c;
    --reader-paper: #1c2226;
    --reader-text: #e9e1d4;
    --reader-muted: #aaa195;
    --reader-accent: #e37c68;
    --reader-accent-2: #e2b45f;
    --reader-line: rgba(255, 255, 255, .11);
    --reader-shadow: 0 24px 70px rgba(0, 0, 0, .28);
}

html {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    scroll-behavior: smooth;
}

body {
    position: relative;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    background: var(--reader-bg) !important;
    color: var(--reader-text) !important;
    font-family: Inter, "Segoe UI", Arial, sans-serif !important;
    font-weight: 400 !important;
    padding-top: 72px;
    box-sizing: border-box;
    transition: background .25s ease, color .25s ease;
}

.reading-progress {
    position: fixed;
    inset: 0 0 auto;
    height: 3px;
    z-index: 30;
    background: transparent;
}

#reading-progress-bar {
    display: block;
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--reader-accent), var(--reader-accent-2));
}

.reader-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
    height: 72px;
    width: 100%;
    padding: 0 clamp(18px, 4vw, 68px);
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: color-mix(in srgb, var(--reader-paper) 88%, transparent);
    border-bottom: 1px solid var(--reader-line);
    backdrop-filter: blur(18px);
}

.reader-brand, .reader-actions, .reader-font-controls, .book-hero-actions, .book-meta {
    display: flex;
    align-items: center;
}

.reader-brand {
    gap: 11px;
    color: var(--reader-text);
    font-weight: 700;
    letter-spacing: -.02em;
    text-decoration: none;
}

.reader-brand-mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    color: #fff;
    font: 700 12px/1 Georgia, serif;
    background: var(--reader-accent);
}

.reader-actions {
    gap: 8px;
    flex-shrink: 0;
}
.reader-font-controls { gap: 2px; }

.reader-button, .reader-icon-button, .book-secondary-action {
    border: 1px solid var(--reader-line);
    color: var(--reader-text);
    background: var(--reader-paper);
    cursor: pointer;
    font: 600 14px/1 inherit;
}

.reader-bookmark-link {
    display: inline-flex;
    flex: 0 0 auto;
    height: 40px;
    padding: 0 16px;
    gap: 8px;
    align-items: center;
    border: 0;
    border-radius: 999px;
    color: #fff;
    background: var(--reader-accent);
    cursor: pointer;
    font: 700 14px/1 inherit;
    box-shadow: 0 7px 18px color-mix(in srgb, var(--reader-accent) 23%, transparent);
}

.reader-bookmark-link[hidden] { display: none; }
.reader-bookmark-link:hover { transform: translateY(-1px); }

.reader-support-button {
    display: inline-flex;
    height: 40px;
    padding: 0 16px;
    gap: 7px;
    align-items: center;
    border: 1px solid color-mix(in srgb, var(--reader-accent) 35%, var(--reader-line));
    border-radius: 999px;
    color: var(--reader-accent);
    background: color-mix(in srgb, var(--reader-accent) 7%, var(--reader-paper));
    cursor: pointer;
    font: 750 14px/1 inherit;
}

.reader-support-button:hover {
    color: #fff;
    background: var(--reader-accent);
}

.reader-button {
    height: 40px;
    padding: 0 17px;
    border-radius: 999px;
}

.reader-icon-button {
    min-width: 40px;
    height: 40px;
    border-radius: 12px;
}

.reader-button:hover, .reader-icon-button:hover, .book-secondary-action:hover {
    border-color: var(--reader-accent);
    color: var(--reader-accent);
}

.book-hero {
    width: min(1120px, calc(100% - 40px));
    min-height: 610px;
    margin: 46px auto 70px;
    padding: clamp(34px, 6vw, 76px);
    box-sizing: border-box;
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(260px, .75fr);
    gap: clamp(40px, 7vw, 90px);
    align-items: center;
    overflow: hidden;
    border: 1px solid var(--reader-line);
    border-radius: 34px;
    background:
        radial-gradient(circle at 85% 10%, rgba(216, 166, 78, .25), transparent 32%),
        linear-gradient(145deg, var(--reader-paper), color-mix(in srgb, var(--reader-paper) 90%, var(--reader-accent)));
    box-shadow: var(--reader-shadow);
}

.book-kicker, .reader-contents-kicker {
    color: var(--reader-accent);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .16em;
    text-transform: uppercase;
}

.book-hero h1 {
    margin: 14px 0 12px;
    max-width: 650px;
    font: 700 clamp(52px, 7vw, 92px)/.92 Georgia, "Times New Roman", serif;
    letter-spacing: -.055em;
    color: var(--reader-text);
}

.book-subtitle {
    margin: 0 0 25px;
    font: italic 500 clamp(21px, 2.5vw, 30px)/1.25 Georgia, serif;
    color: var(--reader-accent);
}

.book-description {
    max-width: 610px;
    margin: 0 0 32px;
    color: var(--reader-muted);
    font-size: 17px;
    line-height: 1.65;
}

.book-hero-actions { gap: 12px; flex-wrap: wrap; }

.book-primary-action, .book-secondary-action {
    display: inline-flex;
    min-height: 50px;
    padding: 0 23px;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    border-radius: 999px;
    text-decoration: none;
}

.book-primary-action {
    color: #fff;
    background: var(--reader-accent);
    font-weight: 700;
    box-shadow: 0 10px 24px color-mix(in srgb, var(--reader-accent) 28%, transparent);
}

.book-primary-action:hover { transform: translateY(-1px); }
.book-secondary-action { font-size: 15px; }

.book-meta {
    gap: 0;
    margin-top: 38px;
    color: var(--reader-muted);
    font-size: 13px;
    font-weight: 650;
}

.book-meta span + span::before {
    content: "•";
    margin: 0 11px;
    color: var(--reader-accent-2);
}

.book-cover-wrap { perspective: 1100px; }

.book-cover-modern {
    display: block;
    width: min(100%, 330px);
    max-height: 470px;
    margin: auto;
    object-fit: cover;
    border-radius: 5px 14px 14px 5px;
    transform: rotateY(-6deg) rotateZ(1.5deg);
    box-shadow: 4px 2px 0 #e3d8c7, 12px 18px 42px rgba(31, 24, 18, .28);
}

/* The legacy introduction and order bar are replaced by the focused reader header. */
#book_order, #form_order, #widescreen > h3, #top-sintez, #title, #book, #ps,
#autor-redactor, #cover, #paragraphs > .aria, #paragraphs > .pozhertvovanie,
#paragraphs > a[name="to_pozhertvovanie"], #paragraphs > #links,
#paragraphs > #links + br, #paragraphs > #title_paragraph, #public_oferta,
#text_oferta, #from-autor { display: none !important; }

#widescreen {
    width: min(1180px, calc(100% - 40px));
    margin: 0 auto !important;
    padding: 0 0 100px !important;
}

/* Remove spacing left by the hidden legacy intro above the modern contents. */
#widescreen > br {
    display: none;
}

#paragraphs > br:first-child {
    display: none;
}

#paragraphs {
    font-size: 16px !important;
}

#paragraphs > div:nth-of-type(2) {
    width: min(860px, 100%);
    margin: 0 auto 46px;
    padding: 26px 30px;
    box-sizing: border-box;
    border: 1px solid var(--reader-line);
    border-radius: 20px;
    background: var(--reader-paper);
}

#paragraphs > div:nth-of-type(2) .a1 {
    display: block;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--reader-text);
    font: 600 15px/1.35 inherit;
}

#paragraphs > div:nth-of-type(2) .a1:hover {
    padding: 10px 12px;
    color: var(--reader-accent);
    background: color-mix(in srgb, var(--reader-accent) 8%, transparent);
}

#my-book {
    width: min(860px, 100%);
    margin: 0 auto;
    padding: clamp(34px, 7vw, 82px);
    box-sizing: border-box;
    color: var(--reader-text);
    background: var(--reader-paper);
    border: 1px solid var(--reader-line);
    border-radius: 26px;
    box-shadow: var(--reader-shadow);
}

#my-book *,
#paragraphs *,
#widescreen * {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    overflow-wrap: anywhere;
    word-break: break-word;
}

#my-book table {
    width: 100% !important;
    table-layout: fixed;
}

#my-book td,
#my-book th,
#my-book pre,
#my-book code {
    min-width: 0 !important;
    overflow-wrap: anywhere;
    word-break: break-word;
}

#my-book p, #my-book li, #my-book div {
    color: var(--reader-text) !important;
    font-family: Georgia, "Times New Roman", serif !important;
    font-size: var(--reader-font-size) !important;
    line-height: 1.78 !important;
}

#my-book p { margin: 0 0 1.15em !important; }

#my-book span {
    color: inherit !important;
    background: transparent !important;
    font-family: inherit !important;
    font-size: inherit !important;
}

#my-book strong { color: var(--reader-text); }

#my-book a[name^="chapt"] {
    display: block;
    scroll-margin-top: 92px;
    border-top: 1px solid var(--reader-line);
}

.div-book-img { margin: 54px 0 !important; }
.book-img {
    width: min(100%, 680px) !important;
    max-height: 620px;
    object-fit: contain;
    border-radius: 14px;
    box-shadow: 0 18px 42px rgba(38, 31, 25, .16);
}

.reader-contents {
    position: fixed;
    z-index: 41;
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: min(440px, 92dvw);
    max-width: 100%;
    padding: 30px;
    box-sizing: border-box;
    overflow-y: auto;
    color: var(--reader-text);
    background: var(--reader-paper);
    border-left: 1px solid var(--reader-line);
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transform: none;
    transition: visibility .25s ease, opacity .25s ease;
    box-shadow: -24px 0 70px rgba(20, 17, 14, .18);
}

.reader-contents.open {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}
.reader-contents-head { display: flex; justify-content: space-between; align-items: flex-start; }
.reader-contents h2 { margin: 7px 0 24px; font: 700 36px/1 Georgia, serif; }
.reader-close {
    border: 0; color: var(--reader-text); background: transparent;
    font-size: 35px; cursor: pointer;
}

#reader-contents-links a {
    display: block;
    padding: 13px 11px;
    border-top: 1px solid var(--reader-line);
    color: var(--reader-muted);
    text-decoration: none;
    font-size: 14px;
    line-height: 1.35;
}

#reader-contents-links a:hover { color: var(--reader-accent); }

.reader-scrim {
    position: fixed;
    z-index: 40;
    inset: 0;
    width: 100dvw;
    max-width: 100%;
    visibility: hidden;
    opacity: 0;
    background: rgba(12, 10, 8, .42);
    backdrop-filter: blur(3px);
    transition: .25s ease;
}

.reader-scrim.open { visibility: visible; opacity: 1; }

.support-dialog {
    position: fixed;
    z-index: 42;
    top: 50%;
    left: 50%;
    width: min(520px, calc(100% - 28px));
    max-height: calc(100vh - 36px);
    padding: 38px;
    box-sizing: border-box;
    overflow-y: auto;
    visibility: hidden;
    opacity: 0;
    transform: translate(-50%, -47%) scale(.97);
    border: 1px solid var(--reader-line);
    border-radius: 26px;
    color: var(--reader-text);
    background: var(--reader-paper);
    box-shadow: 0 30px 90px rgba(20, 15, 11, .3);
    transition: .22s ease;
}

.support-dialog.open {
    visibility: visible;
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.support-close {
    position: absolute;
    top: 14px;
    right: 17px;
    border: 0;
    color: var(--reader-muted);
    background: transparent;
    cursor: pointer;
    font-size: 32px;
}

.support-heart {
    display: grid;
    width: 54px;
    height: 54px;
    margin-bottom: 22px;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: var(--reader-accent);
    font-size: 28px;
}

.support-dialog h2 {
    margin: 8px 0 12px;
    color: var(--reader-text);
    font: 700 38px/1.05 Georgia, serif;
}

.support-lead {
    margin: 0 0 25px;
    color: var(--reader-muted);
    font-size: 15px;
    line-height: 1.55;
}

.support-method {
    margin-top: 12px;
    padding: 17px;
    display: flex;
    gap: 7px;
    flex-direction: column;
    border: 1px solid var(--reader-line);
    border-radius: 16px;
    background: color-mix(in srgb, var(--reader-bg) 60%, var(--reader-paper));
}

.support-method-label {
    color: var(--reader-muted);
    font-size: 12px;
    font-weight: 750;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.support-method strong { font-size: 21px; }
.support-method > span:last-of-type { color: var(--reader-muted); font-size: 12px; }
.support-method code {
    overflow-wrap: anywhere;
    color: var(--reader-text);
    font-size: 13px;
    line-height: 1.45;
}

.support-copy {
    align-self: flex-start;
    margin-top: 6px;
    padding: 9px 13px;
    border: 0;
    border-radius: 9px;
    color: #fff;
    background: var(--reader-accent);
    cursor: pointer;
    font-weight: 700;
}

.bookmark-save {
    position: fixed;
    z-index: 18;
    left: 50%;
    bottom: 22px;
    min-height: 48px;
    padding: 0 20px;
    display: inline-flex;
    gap: 9px;
    align-items: center;
    transform: translateX(-50%);
    border: 1px solid var(--reader-line);
    border-radius: 999px;
    color: var(--reader-text);
    background: color-mix(in srgb, var(--reader-paper) 92%, transparent);
    backdrop-filter: blur(16px);
    cursor: pointer;
    font: 700 14px/1 inherit;
    box-shadow: 0 10px 35px rgba(38, 30, 23, .16);
}

.bookmark-save:hover {
    color: var(--reader-accent);
    border-color: var(--reader-accent);
    transform: translateX(-50%) translateY(-2px);
}

.bookmark-save.saved .bookmark-save-icon {
    color: var(--reader-accent);
}

.bookmark-toast {
    position: fixed;
    z-index: 50;
    left: 50%;
    bottom: 82px;
    max-width: calc(100% - 30px);
    padding: 11px 16px;
    transform: translate(-50%, 12px);
    visibility: hidden;
    opacity: 0;
    border-radius: 12px;
    color: #fff;
    background: #29241f;
    font-size: 13px;
    box-shadow: 0 10px 32px rgba(0, 0, 0, .25);
    transition: .2s ease;
}

.bookmark-toast.show {
    visibility: visible;
    opacity: 1;
    transform: translate(-50%, 0);
}

#to_top {
    width: 46px !important;
    height: 46px !important;
    right: max(12px, env(safe-area-inset-right)) !important;
    bottom: 22px !important;
    padding: 0 !important;
    color: #fff !important;
    background: var(--reader-accent) !important;
    border: 0 !important;
    border-radius: 999px !important;
    font-size: 21px !important;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
}

#to_top.is-visible {
    display: block !important;
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}

#to_top:hover {
    transform: translateY(-2px);
}

@media (max-width: 900px) {
    .reader-actions { gap: 4px; }
    .reader-font-controls { display: flex; }
    .reader-font-controls .reader-icon-button {
        min-width: 38px;
        width: 38px;
        padding: 0;
    }
}

@media (max-width: 760px) {
    body { padding-top: 62px; }
    .reader-header { height: 62px; padding: 0 14px; }
    .reader-brand > span:last-child { display: none; }
    .reader-button { padding: 0 13px; }
    .reader-bookmark-link {
        flex: 0 0 40px;
        width: 40px;
        padding: 0;
        justify-content: center;
    }
    .reader-bookmark-link span:last-child { display: none; }
    .reader-support-button {
        width: 40px;
        padding: 0;
        justify-content: center;
    }
    .reader-support-button span:last-child { display: none; }
    .book-hero {
        width: calc(100% - 24px);
        min-height: 0;
        margin: 20px auto 42px;
        padding: 34px 24px;
        grid-template-columns: 1fr;
        border-radius: 24px;
    }
    .book-hero-copy { order: 2; }
    .book-cover-wrap { order: 1; }
    .book-cover-modern { width: 190px; max-height: 285px; }
    .book-hero h1 { font-size: 50px; }
    .book-description { font-size: 15px; }
    .book-meta { flex-wrap: wrap; row-gap: 7px; }
    #widescreen {
        width: calc(100% - 20px);
        max-width: calc(100% - 20px);
        overflow: hidden;
    }
    #paragraphs > div:nth-of-type(2) { padding: 17px 13px; }
    #my-book { padding: 34px 21px; border-radius: 18px; }
    #my-book p, #my-book li, #my-book div { line-height: 1.68 !important; }
    .bookmark-save { bottom: 14px; }
    .support-dialog { padding: 31px 21px 23px; border-radius: 21px; }
    #to_top {
        right: max(10px, env(safe-area-inset-right)) !important;
        bottom: 72px !important;
        padding: 0 !important;
    }
}

@media (max-width: 480px) {
    .reader-header { padding: 0 8px; }
    .reader-brand-mark { width: 30px; height: 30px; }
    .reader-actions { gap: 3px; }
    .reader-support-button {
        display: inline-flex;
        width: 36px;
        height: 38px;
    }
    .reader-button {
        height: 38px;
        padding: 0 10px;
        font-size: 13px;
    }
    .reader-icon-button,
    .reader-font-controls .reader-icon-button {
        min-width: 36px;
        width: 36px;
        height: 38px;
        padding: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    * { transition: none !important; }
}
