:root {
    --background: #f6f2ea;
    --surface: #ffffff;
    --primary: #4c392b;
    --primary-dark: #35271e;
    --text: #28231f;
    --muted: #70675f;
    --border: #ded5c9;
    --success: #2d7a47;
    --offline: #a43f37;
    --shadow: 0 16px 42px rgba(55, 42, 31, 0.08);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--background);
}

body {
    min-height: 100vh;
    margin: 0;
    background: var(--background);
    color: var(--text);
    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
}

a {
    color: inherit;
}

.site-header {
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.96);
}

.site-header-inner,
.main-navigation-inner,
.page-container {
    width: min(100% - 32px, 1100px);
    margin: 0 auto;
}

.site-header-inner {
    display: flex;
    min-height: 70px;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    color: var(--text);
    text-decoration: none;
}

.brand-icon {
    display: grid;
    width: 44px;
    height: 44px;
    place-items: center;
    border-radius: 12px;
    background: var(--primary);
    color: #ffffff;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 1.4rem;
    font-weight: 700;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    margin-top: 2px;
    color: var(--muted);
    font-size: 0.74rem;
}

.network-status {
    padding: 7px 11px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
}

.network-status.is-online {
    color: var(--success);
}

.network-status.is-offline {
    color: var(--offline);
}

.main-navigation {
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.main-navigation-inner {
    display: flex;
    gap: 8px;
    padding: 8px 0;
}

.main-navigation a {
    padding: 9px 13px;
    border-radius: 9px;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
    text-decoration: none;
}

.main-navigation a:hover {
    background: var(--background);
    color: var(--primary);
}

.page-container {
    padding-top: 42px;
    padding-bottom: 70px;
}

.welcome-card,
.empty-card {
    padding: clamp(25px, 6vw, 55px);
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.eyebrow {
    margin: 0 0 10px;
    color: var(--primary);
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

h1,
h2 {
    font-family: Georgia, "Times New Roman", serif;
}

.welcome-card h1,
.page-heading h1 {
    margin: 0;
    font-size: clamp(2.3rem, 9vw, 4.4rem);
    line-height: 1.05;
}

.lead,
.page-heading p,
.empty-card p {
    max-width: 680px;
    color: var(--muted);
    line-height: 1.7;
}

.action-row {
    margin-top: 24px;
}

.button {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 10px 17px;
    border-radius: 11px;
    font-weight: 700;
    text-decoration: none;
}

.button-primary {
    background: var(--primary);
    color: #ffffff;
}

.button-primary:hover {
    background: var(--primary-dark);
}

.setup-status {
    display: grid;
    gap: 12px;
    margin-top: 30px;
}

.setup-status article {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 15px;
    border: 1px solid var(--border);
    border-radius: 14px;
}

.setup-status strong,
.setup-status small {
    display: block;
}

.setup-status small {
    margin-top: 3px;
    color: var(--muted);
}

.status-dot {
    width: 11px;
    height: 11px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 5px rgba(45, 122, 71, 0.12);
}

.empty-card {
    margin-top: 28px;
}

@media (min-width: 700px) {
    .setup-status {
        grid-template-columns: repeat(2, 1fr);
    }
}

.library-section {
    margin-top: 34px;
}

.section-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.section-heading h2 {
    margin: 0;
    font-size: 1.75rem;
}

.collection-count {
    color: var(--muted);
    font-size: 0.9rem;
}

.commentary-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
}

.commentary-card {
    display: grid;
    grid-template-columns: 86px minmax(0, 1fr);
    gap: 18px;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.commentary-cover {
    display: grid;
    min-height: 128px;
    place-items: center;
    border-radius: 12px;
    background:
        linear-gradient(
            145deg,
            var(--primary),
            #765b42
        );
    color: #ffffff;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 2.7rem;
    font-weight: 700;
}

.commentary-cover-large {
    width: 130px;
    min-height: 185px;
}

.commentary-card-content h2 {
    margin: 8px 0 4px;
    font-size: 1.35rem;
}

.commentary-subtitle,
.commentary-author {
    margin: 4px 0;
    color: var(--muted);
}

.commentary-author {
    font-weight: 700;
}

.commentary-description {
    color: var(--muted);
    line-height: 1.65;
}

.commentary-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.badge {
    display: inline-flex;
    padding: 5px 9px;
    border-radius: 999px;
    background: #eee8df;
    color: var(--primary);
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
}

.badge-success {
    background: #e4f2e8;
    color: #27633b;
}

.commentary-statistics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 18px 0;
}

.commentary-statistics div {
    padding: 10px;
    border-radius: 10px;
    background: var(--background);
}

.commentary-statistics dt {
    color: var(--muted);
    font-size: 0.7rem;
    text-transform: uppercase;
}

.commentary-statistics dd {
    margin: 4px 0 0;
    font-size: 1.1rem;
    font-weight: 800;
}

.commentary-card-actions {
    margin-top: 12px;
}

.full-width {
    grid-column: 1 / -1;
}

.breadcrumb {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 26px;
    color: var(--muted);
    font-size: 0.9rem;
}

.breadcrumb a {
    color: var(--primary);
    font-weight: 700;
}

.commentary-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 26px;
    padding: 26px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.commentary-header h1 {
    margin: 8px 0;
    font-size: clamp(2rem, 7vw, 3.5rem);
}

.volume-grid,
.book-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
}

.volume-card,
.book-card,
.rights-card {
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
}

.volume-card h3,
.book-card h3 {
    margin: 5px 0;
}

.volume-card p,
.book-card p,
.rights-card p {
    color: var(--muted);
    line-height: 1.6;
}

.card-label,
.coming-soon-label {
    color: var(--primary) !important;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.rights-card {
    margin-top: 34px;
}

@media (min-width: 700px) {
    .commentary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .volume-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .book-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 560px) {
    .commentary-card {
        grid-template-columns: 68px minmax(0, 1fr);
        gap: 13px;
        padding: 14px;
    }

    .commentary-cover {
        min-height: 105px;
    }

    .commentary-header {
        grid-template-columns: 1fr;
    }

    .commentary-cover-large {
        width: 105px;
        min-height: 145px;
    }
}

.book-card-link {
    display: flex;
    min-height: 175px;
    flex-direction: column;
    justify-content: space-between;
    color: var(--text);
    text-decoration: none;
    transition:
        transform 160ms ease,
        box-shadow 160ms ease,
        border-color 160ms ease;
}

.book-card-link:hover {
    transform: translateY(-3px);
    border-color: var(--primary);
    box-shadow: var(--shadow);
}

.book-card-action {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 20px;
    color: var(--primary);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.book-header {
    padding: clamp(28px, 6vw, 52px);
    border: 1px solid var(--border);
    border-radius: 24px;
    background:
        linear-gradient(
            135deg,
            rgba(76, 57, 43, 0.98),
            rgba(112, 82, 58, 0.94)
        );
    box-shadow: var(--shadow);
    color: #ffffff;
}

.book-header h1 {
    margin: 0;
    color: #ffffff;
    font-size: clamp(2.6rem, 9vw, 4.8rem);
}

.book-header > p:not(.eyebrow) {
    margin: 14px 0 24px;
    color: rgba(255, 255, 255, 0.82);
}

.book-header .button-primary {
    background: #ffffff;
    color: var(--primary);
}

.book-introduction {
    margin-top: 34px;
    padding: clamp(22px, 5vw, 38px);
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface);
}

.chapter-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.chapter-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 15px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    transition:
        border-color 160ms ease,
        transform 160ms ease;
}

.chapter-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
}

.chapter-number {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 10px;
    background: var(--background);
    color: var(--primary);
    font-weight: 800;
}

.chapter-label {
    font-weight: 700;
}

.chapter-arrow {
    color: var(--primary);
    font-size: 1.2rem;
}

.reader-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 22px;
    margin-bottom: 24px;
}

.reader-header h1 {
    margin: 5px 0;
    font-size: clamp(2.2rem, 7vw, 4rem);
}

.reader-author {
    margin: 0;
    color: var(--muted);
}

.chapter-selector {
    display: grid;
    gap: 6px;
    min-width: 150px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
}

.chapter-selector select {
    min-height: 44px;
    padding: 8px 34px 8px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.reader-layout {
    display: grid;
    grid-template-columns: 190px minmax(0, 1fr);
    align-items: start;
    gap: 24px;
}

.reader-sidebar {
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
}

.sidebar-title {
    margin: 0 0 10px;
    color: var(--primary);
    font-weight: 800;
}

.chapter-navigation {
    display: grid;
    gap: 3px;
}

.chapter-navigation a {
    padding: 9px 10px;
    border-radius: 8px;
    color: var(--muted);
    font-size: 0.88rem;
    text-decoration: none;
}

.chapter-navigation a:hover,
.chapter-navigation a.active {
    background: var(--primary);
    color: #ffffff;
}

.reader-paper {
    min-width: 0;
    padding: clamp(24px, 6vw, 64px);
    border: 1px solid var(--border);
    border-radius: 20px;
    background:
        linear-gradient(
            rgba(255, 253, 248, 0.97),
            rgba(255, 253, 248, 0.97)
        );
    box-shadow: var(--shadow);
}

.reader-paper-header {
    margin-bottom: 36px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
    text-align: center;
}

.reader-paper-header h2 {
    margin: 6px 0;
    font-size: clamp(2rem, 6vw, 3.3rem);
}

.reader-paper-header > p:last-child {
    color: var(--muted);
    font-size: 0.8rem;
}

.reader-volume {
    margin: 0;
    color: var(--primary);
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.commentary-content {
    max-width: 760px;
    margin: 0 auto;
    color: #302a25;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(1.05rem, 2.5vw, 1.18rem);
    line-height: 1.85;
}

.commentary-content h1,
.commentary-content h2,
.commentary-content h3,
.commentary-content h4 {
    margin: 1.8em 0 0.65em;
    color: var(--text);
    line-height: 1.3;
}

.commentary-content h3 {
    font-size: 1.35em;
}

.commentary-content p {
    margin: 0 0 1.25em;
}

.commentary-content blockquote {
    margin: 1.5em 0;
    padding: 14px 20px;
    border-left: 4px solid var(--primary);
    background: rgba(76, 57, 43, 0.05);
}

.commentary-content ul,
.commentary-content ol {
    padding-left: 1.6em;
}

.commentary-content li {
    margin-bottom: 0.5em;
}

.commentary-content .scripture-reference {
    font-weight: 700;
}

.commentary-content .commentary-note {
    margin: 1.5em 0;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--background);
    font-size: 0.92em;
}

.reader-footer {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 14px;
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.reader-navigation-next {
    text-align: right;
}

.reader-navigation-link {
    display: inline-flex;
    flex-direction: column;
    color: var(--primary);
    text-decoration: none;
}

.reader-navigation-label {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.back-to-book {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}

@media (min-width: 700px) {
    .chapter-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (min-width: 1000px) {
    .chapter-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 780px) {
    .reader-layout {
        grid-template-columns: 1fr;
    }

    .reader-sidebar {
        display: none;
    }

    .reader-header {
        align-items: stretch;
        flex-direction: column;
    }

    .chapter-selector {
        width: 100%;
    }

    .reader-footer {
        grid-template-columns: 1fr 1fr;
    }

    .reader-footer .back-to-book {
        display: none;
    }
}

@media (max-width: 480px) {
    .chapter-grid {
        grid-template-columns: 1fr;
    }

    .reader-paper {
        padding: 24px 18px;
        border-right: 0;
        border-left: 0;
        border-radius: 0;
    }

    .commentary-content {
        font-size: 1.05rem;
        line-height: 1.78;
    }
}

[hidden] {
    display: none !important;
}


/* =========================================================
   Install application
   ========================================================= */

.install-app-button {
    min-height: 38px;
    margin-left: auto;
    padding: 7px 14px;
    border: 1px solid var(--primary);
    border-radius: 9px;
    background: var(--primary);
    color: #ffffff;
    cursor: pointer;
    font: inherit;
    font-size: 0.82rem;
    font-weight: 800;
}

.install-app-button:hover {
    background: var(--primary-dark);
}

.install-app-button:focus-visible {
    outline: 3px solid rgba(76, 57, 43, 0.25);
    outline-offset: 2px;
}


/* =========================================================
   Installation instructions dialog
   ========================================================= */

.install-help-dialog {
    width: min(100% - 32px, 540px);
    max-height: min(85vh, 720px);
    padding: 0;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.install-help-dialog::backdrop {
    background: rgba(24, 19, 16, 0.68);
}

.install-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.install-dialog-header h2 {
    margin: 0;
}

.dialog-close-button {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: var(--background);
    color: var(--text);
    cursor: pointer;
    font-size: 1.45rem;
}

.install-dialog-content {
    display: grid;
    gap: 18px;
    padding: 20px;
}

.install-dialog-content section {
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.install-dialog-content section:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.install-dialog-content h3 {
    margin: 0 0 6px;
}

.install-dialog-content p {
    margin: 0;
    color: var(--muted);
    line-height: 1.65;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    padding: 0 20px 20px;
}


/* =========================================================
   Offline downloads
   ========================================================= */

.book-header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 22px;
}

.offline-download-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 18px;
}

.offline-download-controls button:disabled,
.book-header-actions button:disabled {
    cursor: wait;
    opacity: 0.72;
}

.offline-download-status {
    display: block;
    max-width: 520px;
    margin-top: 12px;
    color: var(--muted);
    line-height: 1.5;
}

.book-header .offline-download-status {
    color: rgba(255, 255, 255, 0.82);
}


/* =========================================================
   Offline fallback page
   ========================================================= */

.offline-page-card {
    padding: clamp(25px, 6vw, 55px);
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.offline-page-card h1 {
    margin: 0;
    font-size: clamp(2.2rem, 8vw, 4rem);
}


@media (max-width: 560px) {
    .main-navigation-inner {
        flex-wrap: wrap;
    }

    .install-app-button {
        margin-left: 0;
    }

    .book-header-actions,
    .offline-download-controls {
        align-items: stretch;
        flex-direction: column;
    }

    .book-header-actions .button,
    .offline-download-controls .button {
        width: 100%;
    }
}