@import url('https://fonts.googleapis.com/css2?family=EB+Garamond:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500&family=Roboto:wght@400;500;700&display=swap');

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ═══════════════════════════════════════════════════════════════
   Палітра "палітурної книги": шкіряна обкладинка, позолота,
   старий папір. html.dark — читання при свічці ввечері.
   ═══════════════════════════════════════════════════════════════ */
:root {
    --leather:      #3b1f1a;   /* шкіряна обкладинка (шапка, підвал) */
    --leather-edge: #241210;   /* темніший край обкладинки */
    --gold:         #9c7a2e;   /* позолота: посилання, номери, лінії */
    --gold-bright:  #b8934a;
    --crimson:      #7a1a1a;   /* сургучевий акцент: бейджі, наведення */
    --crimson-bright: #9a2233;
    --page:         #fffdf9;   /* аркуш (контейнер, картки змісту) */
    --paper:        #efe6d4;   /* тло довкола книги (стіл під книгою) */
    --cream:        #f3ead4;   /* "стара" врізка: передмова, парні рядки */
    --heading:      #2c1810;   /* заголовки — теплий чорно-брунатний "чорнило" */
    --text:         #241a12;
    --muted:        #6b5d4a;
    --border:       #ddd0b0;
    --rule:         #c3ad7c;   /* тонкі лінії, крапкові лідери */
    --shadow:       0 2px 10px rgba(43, 24, 10, 0.14);

    --font-display: 'EB Garamond', Georgia, 'Times New Roman', serif;
    --font-body: 'Bookman Old Style', 'URW Bookman', Georgia, 'Times New Roman', serif;
    --font-ui: 'Roboto', Arial, sans-serif;
}

html.dark {
    --leather:      #1b0e0c;
    --leather-edge: #0e0605;
    --gold:         #d1a94f;
    --gold-bright:  #e8c884;
    --crimson:      #d3676c;
    --crimson-bright: #e78187;
    --page:         #1c160f;
    --paper:        #100b07;
    --cream:        #241c12;
    --heading:      #f0e5cd;
    --text:         #e9ddc6;
    --muted:        #a99a7d;
    --border:       #3c3020;
    --rule:         #5c4a2c;
    --shadow:       0 6px 22px rgba(0, 0, 0, 0.6);
}

html { scroll-behavior: smooth; }

body {
    position: relative;
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.75;
    color: var(--text);
    background-color: var(--paper);
    padding: 2.5rem 1rem;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Ледь помітна текстура паперу на тлі сторінки (SVG-шум, без зображень) */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0.045;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

html.dark body::before {
    opacity: 0.1;
    mix-blend-mode: overlay;
}

/* ── Обкладинка книги (контейнер) ── */
.container {
    position: relative;
    z-index: 1;
    max-width: 1000px;
    margin: 0 auto;
    background: var(--page);
    border: 1px solid var(--border);
    box-shadow:
        0 1px 0 1px var(--cream),
        0 2px 0 2px var(--border),
        var(--shadow);
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* Загнутий кутик сторінки внизу праворуч — маленька книжкова деталь */
.container::after {
    content: '';
    position: absolute;
    right: 0;
    bottom: 0;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 0 30px 30px;
    border-color: transparent transparent var(--cream) transparent;
    box-shadow: -3px -3px 6px rgba(43, 24, 10, 0.18);
    transition: border-color 0.3s ease;
}

/* Стрічка-закладка, що звисає з верху обкладинки */
.container::before {
    content: '';
    position: absolute;
    top: -14px;
    left: 64px;
    width: 26px;
    height: 76px;
    z-index: 3;
    background: linear-gradient(180deg, var(--gold-bright), var(--gold));
    clip-path: polygon(0 0, 100% 0, 100% 82%, 50% 100%, 0 82%);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

/* ── Шапка (титульна сторінка книги) ── */
.pdf-hero {
    position: relative;
    background: var(--leather);
    background-image:
        radial-gradient(ellipse at top, rgba(255,255,255,0.06), transparent 60%),
        linear-gradient(180deg, var(--leather) 0%, var(--leather-edge) 100%);
    color: #e8e0d0;
    padding: 3.2rem 3rem 2.5rem;
    border-bottom: 3px solid var(--gold);
    text-align: center;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* Тонка подвійна рамка "тиснення" всередині обкладинки */
.pdf-hero::after {
    content: '';
    position: absolute;
    inset: 10px;
    border: 1px solid rgba(184, 147, 74, 0.35);
    pointer-events: none;
}

.pdf-hero h1 {
    font-family: var(--font-display);
    font-size: 2.5rem;
    font-weight: 600;
    letter-spacing: 0.015em;
    margin-bottom: 0.4rem;
    color: #f2ead8;
    text-shadow: 0 1px 0 rgba(0,0,0,0.35);
}

.pdf-hero .subtitle {
    font-family: var(--font-ui);
    font-size: 0.92rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.32em;
    color: var(--gold-bright);
    margin-bottom: 1.6rem;
}

.pdf-hero .hero-rule {
    width: 90px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    margin: 0 auto 1.8rem;
    position: relative;
}

.pdf-hero .hero-rule::before {
    content: '❦';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -55%);
    background: var(--leather);
    color: var(--gold-bright);
    padding: 0 10px;
    font-size: 0.95rem;
}

.pdf-button {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    background: transparent;
    color: #ece4d4;
    padding: 0.7rem 1.8rem;
    border: 1px solid var(--gold);
    text-decoration: none;
    font-family: var(--font-ui);
    font-weight: 500;
    font-size: 0.9rem;
    letter-spacing: 0.06em;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
    cursor: pointer;
    position: relative;
    z-index: 1;
}

.pdf-button:hover {
    background: rgba(209, 169, 79, 0.14);
    border-color: var(--gold-bright);
    color: #fff;
}

.pdf-button .btn-icon {
    font-size: 0.9rem;
    opacity: 0.85;
    color: var(--gold-bright);
}

.pdf-hero .pdf-note {
    margin-top: 0.8rem;
    font-family: var(--font-ui);
    font-size: 0.7rem;
    color: #9c8f77;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    position: relative;
    z-index: 1;
}

/* ── Перемикач теми ── */
.theme-toggle {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid rgba(209, 169, 79, 0.4);
    background: rgba(255, 255, 255, 0.04);
    color: #e8e0d0;
    font-size: 1.05rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: background 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--gold-bright);
    transform: scale(1.07);
}

/* ── Основний контент ── */
.content {
    padding: 2.6rem 3.2rem;
}

@media (max-width: 720px) {
    .content { padding: 1.6rem 1.3rem; }
    .pdf-hero { padding: 2.8rem 1.4rem 2.1rem; }
    .pdf-hero h1 { font-size: 1.7rem; }
    .theme-toggle { top: 12px; right: 12px; }
    .container::before { left: 32px; }
}

/* ── Заголовки секцій ── */
.section {
    margin-bottom: 2.9rem;
}

.section-heading {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--heading);
    letter-spacing: 0.015em;
    padding-bottom: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    position: relative;
    transition: color 0.3s ease, border-color 0.3s ease;
}

.section-heading::after {
    content: '';
    display: block;
    position: absolute;
    bottom: -3px;
    left: 0;
    width: 46px;
    height: 2px;
    background: var(--gold);
}

.part-num {
    font-family: var(--font-ui);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--crimson-bright);
    margin-right: 0.5em;
}

/* ── Передмова ── */
.preface {
    background: var(--cream);
    border: 1px solid var(--border);
    border-left: 3px solid var(--gold);
    padding: 1.6rem 1.85rem;
    margin-bottom: 2.5rem;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.preface h2 {
    font-family: var(--font-display);
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--heading);
    margin-bottom: 1rem;
    letter-spacing: 0.02em;
}

.preface p {
    margin-bottom: 0.9rem;
    text-align: justify;
    font-size: 0.97rem;
    color: var(--muted);
    hyphens: auto;
}

.preface p:last-child { margin-bottom: 0; }

.preface strong {
    color: var(--text);
    font-weight: 600;
}

/* ── Розширена передмова: буквиця першого абзацу, як у старих книгах ── */
.preface-extended p:first-of-type::first-letter {
    float: left;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 3.6em;
    line-height: 0.78;
    padding: 0.03em 0.09em 0 0;
    color: var(--gold);
    text-shadow: 1px 1px 0 rgba(0,0,0,0.06);
}

.preface-extended em {
    color: var(--text);
    font-style: italic;
}

.preface-extended strong {
    color: var(--heading);
}

.preface-extended sub {
    font-size: 0.7em;
    vertical-align: sub;
}

/* ── Система позначок ── */
.notation-list {
    list-style: none;
    padding: 0;
    margin: 1.4em 0 1.8em;
    display: grid;
    gap: 0.7em;
}

.notation-list li {
    display: flex;
    align-items: flex-start;
    gap: 0.85em;
    padding: 0.7em 0.9em;
    background: var(--page);
    border: 1px solid var(--border);
    border-left: 3px solid var(--rule);
    border-radius: 2px;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.notation-list li:hover {
    background: var(--cream);
    border-left-color: var(--crimson);
}

.notation-list li span:last-child {
    font-size: 0.94rem;
    line-height: 1.55;
    color: var(--muted);
}

.notation-list li strong {
    color: var(--text);
    font-weight: 600;
}

/* ── Бейджі позначок ── */
.notation-badge {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.55em;
    height: 1.55em;
    border-radius: 50%;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1em;
    line-height: 1;
    color: #fff;
    box-shadow: 0 1px 2px rgba(0,0,0,0.18);
    margin-top: 0.05em;
}

.notation-important {
    background: linear-gradient(180deg, #d1a94f, #9c7a2e);
    color: #2c2005;
    text-shadow: 0 1px 0 rgba(255,255,255,0.25);
}

.notation-task {
    background: linear-gradient(180deg, #9a2233, #7a1a1a);
    color: #fff;
}

.notation-star {
    background: linear-gradient(180deg, #4a352a, #241210);
    color: #f2ead8;
    font-size: 1.15em;
    padding-bottom: 0.15em;
}

.notation-question {
    background: linear-gradient(180deg, #9a2233, #7a1a1a);
    color: #fff;
}

/* ── Автори ── */
.authors {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin: 1.2rem 0 2rem;
    justify-content: center;
}

.author-card {
    flex: 1;
    min-width: 240px;
    max-width: 300px;
    background: var(--cream);
    border: 1px solid var(--border);
    padding: 1.4rem 1.2rem 1.2rem;
    text-align: center;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.author-photo {
    width: 108px;
    height: 108px;
    object-fit: cover;
    border-radius: 50%;
    margin-bottom: 0.9rem;
    border: 3px solid var(--gold);
    box-shadow: 0 0 0 1px var(--border);
    filter: grayscale(15%) sepia(8%);
}

.author-card strong {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--heading);
    display: block;
    margin-bottom: 0.4rem;
    line-height: 1.3;
}

.author-card a {
    color: var(--gold);
    text-decoration: none;
    border-bottom: 1px dotted var(--border);
    transition: border-color 0.15s, color 0.15s;
}

.author-card a:hover {
    border-bottom-color: var(--crimson);
    color: var(--crimson);
}

.author-card p {
    font-size: 0.82rem;
    color: var(--muted);
    margin-top: 0.5rem;
    line-height: 1.5;
    font-style: italic;
}

/* ── Панель керування змістом ── */
.toc-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin: -0.4rem 0 1.6rem;
}

.toc-ctrl-btn {
    font-family: var(--font-ui);
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    color: var(--gold);
    background: var(--cream);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 0.4rem 1rem;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.toc-ctrl-btn:hover {
    background: var(--leather);
    border-color: var(--leather);
    color: var(--gold-bright);
}

/* ── Зміст (у стилі друкованого змісту книги) ── */
.toc-list {
    list-style: none;
    margin: 0.5rem 0;
    border: 1px solid var(--border);
    transition: border-color 0.3s ease;
}

.toc-list > li {
    border-bottom: 1px solid var(--paper);
    font-size: 0.97rem;
    background: var(--page);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.toc-list > li:last-child {
    border-bottom: none;
}

.toc-list > li:nth-child(odd) {
    background: var(--cream);
}

.toc-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.65rem 1rem;
}

.toc-num {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.9rem;
    height: 1.7rem;
    padding: 0 0.25rem;
    border: 1px solid var(--rule);
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--gold);
}

.toc-title {
    font-family: var(--font-display);
    font-size: 1.05rem;
    color: var(--heading);
    font-weight: 500;
    text-decoration: none;
}

.toc-title:hover { color: var(--crimson); }

/* Крапковий "лідер" між назвою розділу і стрілкою/краєм — класичний
   елемент друкованого змісту книги */
.toc-dots {
    flex: 1 1 24px;
    align-self: flex-end;
    min-width: 16px;
    height: 0;
    margin: 0 0.2rem 0.4rem;
    border-bottom: 2px dotted var(--rule);
}

/* Кнопка розгортання підрозділів (стрілка) */
.toc-toggle {
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s ease, transform 0.25s ease, color 0.2s ease;
}

.toc-toggle:hover {
    background: rgba(156, 122, 46, 0.15);
    color: var(--gold);
}

.toc-toggle svg {
    width: 12px;
    height: 12px;
    transition: transform 0.25s ease;
}

li.toc-open > .toc-row .toc-toggle svg {
    transform: rotate(90deg);
}

.sub-list-wrap {
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height 0.3s ease, opacity 0.25s ease;
}

li.toc-open > .sub-list-wrap {
    opacity: 1;
}

.sub-list {
    list-style: none;
    width: 100%;
    padding: 0.2rem 1rem 0.85rem 2.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.sub-list li {
    font-size: 0.84rem;
    color: var(--muted);
    font-style: italic;
    padding: 0.1rem 0;
    border: none;
    background: transparent;
    line-height: 1.4;
}

.sub-list li::before {
    content: '–\00a0';
    color: var(--rule);
}

.sub-list a {
    color: inherit;
    text-decoration: none;
}

.sub-list a:hover {
    color: var(--crimson);
    text-decoration: underline;
}

/* ── Роздільник між частинами: подвійна лінія з орнаментом ── */
hr {
    margin: 2.4rem 0;
    border: none;
    height: 1px;
    background: var(--border);
    position: relative;
    transition: background-color 0.3s ease;
}

hr::after {
    content: '❧';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: var(--page);
    color: var(--gold);
    padding: 0 14px;
    font-size: 1.05rem;
}

.ref-links {
    text-align: center;
    font-size: 0.88rem;
    color: var(--muted);
    margin: 0.5rem 0 1.5rem;
    font-family: var(--font-display);
    font-style: italic;
    letter-spacing: 0.01em;
}

.ref-links a {
    color: var(--gold);
    text-decoration: none;
    border-bottom: 1px dotted var(--border);
}

.ref-links a:hover {
    color: var(--crimson);
}

/* ── Кнопка "нагору" ── */
.back-to-top {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--leather);
    color: var(--gold-bright);
    font-size: 1.15rem;
    cursor: pointer;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
    transition: opacity 0.25s ease, transform 0.25s ease, background 0.2s ease;
    z-index: 999;
}

.back-to-top.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.back-to-top:hover { background: var(--crimson); color: #fff; }

/* ── Підвал ── */
footer {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 1.2rem 2rem;
    background: var(--leather);
    color: #9c8f77;
    font-size: 0.78rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-family: var(--font-ui);
    border-top: 2px solid var(--gold);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

@media (max-width: 768px) {
    .authors { gap: 1rem; }
    .author-card { min-width: 200px; }
    .author-photo { width: 90px; height: 90px; }
}

@media (max-width: 480px) {
    .pdf-hero h1 { font-size: 1.5rem; }
    .author-card { padding: 1rem; }
    .notation-list li { padding: 0.6em 0.7em; }
    .notation-badge { width: 1.4em; height: 1.4em; font-size: 0.95em; }
    .sub-list { padding-left: 2.2rem; }
    .preface-extended p:first-of-type::first-letter { font-size: 2.8em; }
}
