:root {
    --purple: #57068c;
    --link: #6b2d91;
    --text: #222;
    --muted: #666;
    --max: 920px;
    --header-h: 72px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: #fff;
    color: var(--text);
    font-family: "Segoe UI", Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.65;
}

body.lightbox-open,
body.nav-open {
    overflow: hidden;
}

img, video, iframe {
    max-width: 100%;
}

.wrap {
    width: 100%;
    max-width: var(--max);
    margin: 0 auto;
    padding: 0 20px;
}

.site-header {
    padding: 18px 0;
    border-bottom: 1px solid #eee;
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 40;
}

.site-header .wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    position: relative;
}

.logo {
    text-decoration: none;
    color: var(--purple);
    min-width: 0;
}

.logo-name {
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(20px, 4vw, 28px);
    font-weight: 700;
    letter-spacing: 0.02em;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.site-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 22px;
    justify-content: flex-end;
}

.site-nav a {
    color: var(--text);
    text-decoration: none;
    font-size: 15px;
    padding: 6px 0;
}

.site-nav a:hover,
.site-nav a.is-active {
    color: var(--purple);
}

.nav-toggle {
    display: none;
    width: 44px;
    height: 44px;
    padding: 10px;
    border: 1px solid #ddd;
    background: #fff;
    cursor: pointer;
    border-radius: 6px;
}

.nav-toggle span,
.nav-toggle span::before,
.nav-toggle span::after {
    display: block;
    width: 20px;
    height: 2px;
    background: #333;
    position: relative;
}

.nav-toggle span::before,
.nav-toggle span::after {
    content: "";
    position: absolute;
    left: 0;
}

.nav-toggle span::before { top: -6px; }
.nav-toggle span::after { top: 6px; }

.site-main {
    padding: 28px 0 56px;
    min-height: calc(100vh - 180px);
}

.page-title {
    font-family: Georgia, serif;
    font-weight: 600;
    font-size: clamp(22px, 4vw, 26px);
    margin: 0 0 20px;
    color: var(--purple);
}

.page-body {
    overflow-wrap: anywhere;
}

.page-body a {
    color: var(--link);
}

.page-body h1,
.page-body h2,
.page-body h3 {
    color: var(--purple);
    font-weight: 600;
}

.page-body ul,
.page-body ol {
    padding-left: 1.2em;
}

.page-body table {
    width: 100%;
    display: block;
    overflow-x: auto;
}

.page-body figure.alignright {
    float: right;
    margin: 0 0 16px 28px;
    text-align: center;
}

.page-body img {
    height: auto;
}

.page-body p {
    margin: 0 0 0.9em;
}

.home-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(180px, 240px);
    gap: 40px;
    align-items: start;
}

.home-aside {
    text-align: center;
    font-size: 15px;
}

.home-aside img {
    display: block;
    margin: 0 auto 12px;
    width: min(214px, 100%);
}

.pdf-open-btn,
.btn-download {
    display: inline-block;
    margin: 0 0 16px;
    padding: 10px 16px;
    background: var(--purple);
    color: #fff !important;
    text-decoration: none;
    border: 0;
    cursor: pointer;
    font: inherit;
    border-radius: 4px;
}

.book-toc {
    background: #faf7fd;
    padding: 16px 20px;
    margin-bottom: 28px;
    border: 1px solid #eee;
}

.site-footer {
    border-top: 1px solid #eee;
    padding: 20px 0 28px;
    color: var(--muted);
    font-size: 14px;
}

.site-footer .wrap {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px 24px;
}

.site-footer p {
    margin: 0;
}

.pdf-lightbox {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.pdf-lightbox[hidden] {
    display: none !important;
}

.pdf-lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(20, 10, 30, 0.72);
}

.pdf-lightbox-dialog {
    position: relative;
    z-index: 1;
    width: min(1100px, 100%);
    height: min(92vh, 920px);
    background: #fff;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.pdf-lightbox-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    border-bottom: 1px solid #eee;
    background: #faf7fd;
}

.pdf-lightbox-title {
    color: var(--purple);
    font-size: 15px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pdf-lightbox-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.pdf-lightbox-download {
    color: var(--purple);
    text-decoration: none;
    font-size: 14px;
}

.pdf-lightbox-close {
    width: 40px;
    height: 40px;
    border: 0;
    background: transparent;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    color: #333;
}

.pdf-lightbox-frame {
    flex: 1;
    width: 100%;
    border: 0;
    background: #f3f3f3;
}

@media (max-width: 800px) {
    .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }

    .site-nav {
        display: none;
        position: absolute;
        left: 0;
        width: 100vw;
        margin-left: calc(50% - 50vw);
        top: 100%;
        flex-direction: column;
        gap: 0;
        background: #fff;
        border-bottom: 1px solid #eee;
        padding: 8px 20px 16px;
        box-shadow: 0 12px 24px rgba(0, 0, 0, 0.06);
    }

    .site-nav.is-open { display: flex; }

    .site-nav a {
        padding: 12px 0;
        border-bottom: 1px solid #f2f2f2;
        font-size: 16px;
    }

    .site-header { position: sticky; }

    .home-layout {
        grid-template-columns: 1fr;
        justify-items: center;
        text-align: left;
        gap: 24px;
    }

    .home-copy { width: 100%; }

    .page-body figure.alignright {
        float: none;
        margin: 0 auto 20px;
        display: block;
    }

    .pdf-lightbox {
        padding: 0;
    }

    .pdf-lightbox-dialog {
        width: 100%;
        height: 100%;
        max-height: none;
    }
}

@media (max-width: 480px) {
    .site-main { padding: 20px 0 40px; }
    .wrap { padding: 0 16px; }
}
