:root {
    --canvas: #f4f2ed;
    --surface: #ffffff;
    --surface-soft: #faf9f6;
    --ink: #182233;
    --ink-soft: #3e4a5c;
    --muted: #687386;
    --line: #dcdedb;
    --line-strong: #c9ccc8;
    --accent: #713646;
    --accent-dark: #562534;
    --accent-soft: #f3e9ec;
    --navy: #172235;
    --navy-light: #27364d;
    --gold: #aa8950;
    --danger: #9a3441;
    --shadow-sm: 0 1px 2px rgba(24, 34, 51, .05);
    --shadow-md: 0 12px 32px rgba(24, 34, 51, .08);
    --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
    --sans: "Avenir Next", Avenir, "Segoe UI", Helvetica, Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    background: var(--canvas);
}

body {
    margin: 0;
    background:
        linear-gradient(rgba(255, 255, 255, .34), rgba(255, 255, 255, 0) 260px),
        var(--canvas);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
    color: var(--ink);
    font-family: var(--serif);
    font-weight: 600;
    letter-spacing: -.018em;
}

a {
    color: var(--accent);
    text-underline-offset: 3px;
}

a:hover {
    color: var(--accent-dark);
}

.site-header {
    min-height: 78px;
    padding: 0 clamp(20px, 4vw, 56px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 28px;
    background: rgba(23, 34, 53, .98);
    border-bottom: 1px solid rgba(255, 255, 255, .1);
    box-shadow: 0 2px 12px rgba(10, 18, 30, .14);
}

.logo {
    color: #fff;
    text-decoration: none;
    font-family: var(--serif);
    font-size: 28px;
    font-weight: 600;
    letter-spacing: .025em;
}

.logo::after {
    content: "PRIVATE ARCHIVE";
    display: block;
    margin-top: -3px;
    color: #c7b48e;
    font-family: var(--sans);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .2em;
}

nav {
    display: flex;
    gap: 4px;
    align-items: center;
}

nav a:not(.button) {
    padding: 9px 12px;
    color: #dfe4ec;
    border-radius: 7px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: .01em;
}

nav a:not(.button):hover {
    color: #fff;
    background: rgba(255, 255, 255, .08);
}

nav form {
    margin: 0;
}

.page {
    width: min(1220px, 100%);
    margin: 0 auto;
    padding: 48px clamp(20px, 4vw, 52px) 88px;
}

.home-hero {
    position: relative;
    overflow: hidden;
    padding: clamp(38px, 6vw, 68px);
    margin-bottom: 26px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-top: 3px solid var(--gold);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
}

.home-hero::after {
    content: "S";
    position: absolute;
    right: 42px;
    top: -48px;
    color: rgba(113, 54, 70, .055);
    font-family: var(--serif);
    font-size: 280px;
    line-height: 1;
    pointer-events: none;
}

.eyebrow {
    margin: 0 0 14px;
    color: var(--accent);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .18em;
    text-transform: uppercase;
}

.home-hero h1 {
    position: relative;
    z-index: 1;
    max-width: 780px;
    margin: 0;
    font-size: clamp(40px, 5.5vw, 62px);
    line-height: 1.03;
}

.home-subtitle {
    position: relative;
    z-index: 1;
    max-width: 720px;
    margin: 22px 0 0;
    color: var(--ink-soft);
    font-size: 18px;
    line-height: 1.7;
}

.hero {
    margin: 0 0 24px;
}

.hero h1,
.page-header h1 {
    margin: 0 0 8px;
    font-size: clamp(36px, 4.4vw, 50px);
    line-height: 1.08;
}

.hero p,
.page-header p {
    margin: 0;
    color: var(--muted);
    font-size: 17px;
}

.hero.compact {
    margin-top: 46px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.compact h1 {
    font-size: 29px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 30px;
}

.stats div {
    padding: 22px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
}

.stats strong {
    display: block;
    margin-bottom: 3px;
    font-family: var(--serif);
    font-size: 34px;
    font-weight: 600;
}

.stats span,
.muted {
    color: var(--muted);
}

.collection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 14px;
    margin: 28px 0 40px;
}

.collection-card {
    position: relative;
    min-height: 220px;
    padding: 26px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
    color: var(--ink);
    text-decoration: none;
    transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.collection-card:hover {
    color: var(--ink);
    border-color: #b8afb1;
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.collection-icon {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    margin-bottom: 22px;
    background: var(--accent-soft);
    border: 1px solid #e5cfd5;
    border-radius: 50%;
    color: var(--accent);
    font-family: var(--serif);
    font-size: 16px;
    font-weight: 700;
}

.collection-card h2 {
    margin: 0 0 8px;
    font-size: 25px;
}

.collection-card p {
    margin: 0 0 12px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.55;
}

.collection-card span {
    color: var(--accent);
    font-size: 13px;
    font-weight: 750;
    letter-spacing: .01em;
}

.coming-soon {
    opacity: .72;
}

.search {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 28px;
    padding: 10px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
}

.home-search {
    margin-top: -6px;
}

.search input[type="search"] {
    flex: 1;
    min-width: 260px;
    border-color: transparent;
    background: transparent;
    font-size: 16px;
}

.search select {
    width: 190px;
}

.search-highlight {
    padding: 0 3px;
    background: #f1df9a;
    color: var(--ink);
    border-radius: 2px;
}

input,
textarea,
select {
    width: 100%;
    padding: 11px 13px;
    background: #fff;
    border: 1px solid var(--line-strong);
    border-radius: 7px;
    color: var(--ink);
    font: inherit;
    transition: border-color .15s ease, box-shadow .15s ease;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(113, 54, 70, .12);
}

textarea {
    line-height: 1.6;
    resize: vertical;
}

button,
.button {
    min-height: 39px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 17px;
    background: var(--accent);
    border: 1px solid transparent;
    border-radius: 7px;
    color: #fff !important;
    cursor: pointer;
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    text-decoration: none !important;
    transition: background .15s ease, border-color .15s ease, transform .15s ease;
}

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

button:active,
.button:active {
    transform: translateY(1px);
}

.button.secondary {
    background: var(--navy-light);
}

.button.secondary:hover {
    background: var(--navy);
}

.button.small {
    min-height: 34px;
    padding: 8px 13px;
    font-size: 13px;
}

.site-header .button {
    margin-left: 5px;
    background: transparent;
    border-color: rgba(255, 255, 255, .3);
}

.site-header .button:hover {
    background: #fff;
    color: var(--navy) !important;
}

.danger {
    background: transparent;
    border-color: #d7aeb4;
    color: var(--danger) !important;
}

.danger:hover {
    background: var(--danger);
    color: #fff !important;
}

.actions {
    display: flex;
    gap: 9px;
    align-items: center;
    flex-wrap: wrap;
}

.book-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 15px;
}

.book-card,
.panel,
.empty,
.empty-state,
.form,
.form-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
}

.book-card {
    display: block;
    min-height: 190px;
    padding: 22px;
    color: inherit;
    text-decoration: none;
    transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.book-card:hover {
    color: inherit;
    border-color: #b8afb1;
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.book-card h2 {
    margin: 0 0 6px;
    font-size: 22px;
    line-height: 1.18;
}

.book-card img,
.panel img {
    display: block;
    border: 1px solid rgba(24, 34, 51, .12);
    box-shadow: 0 8px 20px rgba(24, 34, 51, .16);
}

.form,
.form-card {
    padding: 28px;
}

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

label {
    display: block;
    margin-bottom: 18px;
    color: var(--ink-soft);
    font-size: 13px;
    font-weight: 750;
    letter-spacing: .01em;
}

label input,
label textarea,
label select {
    margin-top: 7px;
    color: var(--ink);
    font-size: 15px;
    font-weight: 400;
}

.detail-header,
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
    margin-bottom: 24px;
}

.detail-header h1 {
    max-width: 850px;
    margin: 0 0 7px;
    font-size: clamp(36px, 4.6vw, 52px);
    line-height: 1.06;
}

.detail-grid {
    display: grid;
    grid-template-columns: minmax(270px, 350px) minmax(0, 1fr);
    gap: 16px;
    align-items: start;
}

.panel,
.empty,
.empty-state {
    padding: 25px;
}

.panel h2 {
    margin: 0 0 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
    font-size: 24px;
}

.panel p {
    margin: 10px 0;
}

.research-entry {
    padding: 18px 0;
    border-top: 1px solid var(--line);
}

.research-entry:first-of-type {
    border-top: 0;
}

.longtext {
    white-space: pre-wrap;
    line-height: 1.72;
}

.snippet {
    color: var(--ink-soft);
    line-height: 1.65;
}

.messages {
    margin-bottom: 20px;
    padding: 10px 16px;
    background: #f8f0da;
    border: 1px solid #ddc88f;
    border-radius: 8px;
    color: #5f4c23;
}

.messages p {
    margin: 4px 0;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    margin-top: 30px;
    color: var(--muted);
    font-size: 14px;
}

.lectionary-season {
    margin-bottom: 12px;
    padding: 3px 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 9px;
    box-shadow: var(--shadow-sm);
}

.lectionary-season summary {
    padding: 15px 0;
    color: var(--ink);
    cursor: pointer;
    font-family: var(--serif);
    font-size: 19px;
    font-weight: 600;
    list-style: none;
}

.lectionary-season summary::-webkit-details-marker {
    display: none;
}

.lectionary-season summary::before {
    content: "›";
    display: inline-block;
    margin-right: 10px;
    color: var(--accent);
    font-family: var(--sans);
    transition: transform .14s ease;
}

.lectionary-season[open] summary::before {
    transform: rotate(90deg);
}

.lectionary-season .book-list {
    padding-bottom: 18px;
}

.scanner-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 42px 18px;
    background: rgba(10, 18, 30, .78);
}

.scanner-box {
    width: min(760px, 100%);
    padding: 24px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .28);
}

.scanner-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 16px;
}

.scanner-header h2 {
    margin: 0 0 6px;
}

.scanner-header p,
.scanner-help {
    margin: 0;
    color: var(--muted);
}

#scanner-video {
    width: 100%;
    max-height: 62vh;
    background: #05070a;
    border: 1px solid var(--line);
    border-radius: 9px;
}

@media (max-width: 820px) {
    .site-header {
        min-height: auto;
        padding-top: 17px;
        padding-bottom: 17px;
        flex-direction: column;
        align-items: flex-start;
    }

    nav {
        width: 100%;
        overflow-x: auto;
        padding-bottom: 3px;
    }

    nav a:not(.button) {
        padding-left: 8px;
        padding-right: 8px;
    }

    .detail-header,
    .page-header,
    .scanner-header {
        flex-direction: column;
        align-items: stretch;
    }

    .grid,
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .home-hero::after {
        right: -25px;
    }
}

@media (max-width: 560px) {
    .page {
        padding-top: 30px;
    }

    .home-hero {
        padding: 32px 24px;
    }

    .home-hero h1 {
        font-size: 39px;
    }

    .search {
        align-items: stretch;
    }

    .search input[type="search"],
    .search select {
        width: 100%;
        min-width: 100%;
    }

    .collection-grid,
    .book-list {
        grid-template-columns: 1fr;
    }

    .scanner-modal {
        padding: 16px;
    }
}
