:root {
    --primary: #6e2639;
    --primary-dark: #4e1828;
    --primary-light: #8d4053;
    --text: #343434;
    --muted: #66615f;
    --border: #c8c3bd;
    --panel: #e5e2de;
    --page: #f7f3ea;
    --card: #fffdf8;
    --hover: #f5e7a8;
    --selected: #eed36b;
    --focus: #faf0be;
    --match: #ffe58a;
    --success: #456a50;
    --warning: #8a651f;
    --error: #8b2f35;
    --shadow: 0 18px 44px rgb(41 41 41 / 16%);
    color-scheme: light;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    background: var(--page);
    color: var(--text);
    font-family: Inter, "Source Sans 3", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

button,
input,
select {
    font: inherit;
}

button,
select {
    min-height: 42px;
}

button {
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    font-weight: 700;
}

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

button:disabled {
    cursor: not-allowed;
    opacity: .5;
}

a {
    color: var(--primary);
}

.result-open {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: .65rem .9rem;
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #fff;
    font-weight: 800;
    text-decoration: none;
}

.result-open:hover {
    background: var(--primary-dark);
    color: #fff;
}

:focus-visible {
    outline: 3px solid var(--selected);
    outline-offset: 3px;
}

.skip-link {
    position: absolute;
    left: 1rem;
    top: .5rem;
    z-index: 10;
    transform: translateY(-140%);
    background: var(--primary-dark);
    color: #fff;
    padding: .65rem .9rem;
}

.skip-link:focus {
    transform: translateY(0);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 4;
    display: grid;
    grid-template-columns: minmax(170px, auto) minmax(260px, 620px) auto;
    gap: 1rem;
    align-items: center;
    padding: .8rem clamp(1rem, 4vw, 2.5rem);
    background: rgb(255 253 248 / 94%);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(14px);
}

.attribution-header {
    grid-template-columns: minmax(170px, auto) 1fr;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: .65rem;
    text-decoration: none;
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary-dark);
}

.brand img {
    display: block;
    border-radius: 8px;
}

.top-search {
    display: grid;
    grid-template-columns: 1fr auto;
    border: 1px solid var(--border);
    background: #fff;
}

.top-search input {
    min-width: 0;
    border: 0;
    padding: .75rem .9rem;
    background: transparent;
}

.top-search button,
#goButton,
#chapterCommentary,
#copyPassageLink,
.bottom-nav button,
#navigatorGo {
    padding: .65rem .9rem;
}

.header-nav {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    font-weight: 700;
}

.header-nav a {
    color: var(--text);
    text-decoration: none;
}

.reader-shell {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: calc(100vh - 72px);
    min-height: 560px;
    overflow: hidden;
}

.reader-toolbar {
    display: grid;
    grid-template-columns: auto minmax(120px, 160px) minmax(150px, 220px) minmax(105px, 140px) auto auto auto 1fr;
    gap: .75rem;
    align-items: end;
    padding: 1rem clamp(1rem, 4vw, 2.5rem);
    border-bottom: 1px solid var(--border);
    background: var(--panel);
}

.select-group {
    display: grid;
    gap: .25rem;
}

.select-group label {
    color: var(--muted);
    font-size: .78rem;
    font-weight: 800;
    text-transform: uppercase;
}

select,
input[type="number"] {
    width: 100%;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    padding: .55rem .65rem;
}

.icon-button {
    width: 44px;
    min-width: 44px;
    padding: 0;
    font-size: 1.3rem;
    line-height: 1;
}

.data-note {
    margin: 0 0 .55rem;
    color: var(--muted);
    font-size: .9rem;
}

.reading-stage {
    position: relative;
    display: grid;
    grid-template-columns: minmax(70px, 12vw) minmax(0, 800px) minmax(70px, 12vw);
    justify-content: center;
    gap: 1rem;
    min-height: 0;
    padding: clamp(1rem, 3vw, 2.5rem);
}

.scripture-page {
    display: grid;
    grid-template-rows: auto auto auto minmax(0, 1fr);
    max-width: 800px;
    width: 100%;
    min-height: 0;
    padding: clamp(1.3rem, 4vw, 3rem);
    background: var(--card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.translation-label {
    margin: 0;
    color: var(--primary);
    font-weight: 900;
    letter-spacing: 0;
    text-transform: uppercase;
}

.scripture-page h1 {
    margin: .25rem 0 .2rem;
    color: var(--primary-dark);
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(2rem, 6vw, 3.6rem);
    line-height: 1.05;
}

.chapter-meta {
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}

.verses {
    --reader-page-width: 100%;
    --reader-column-gap: 3rem;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    columns: var(--reader-page-width) 1;
    column-gap: var(--reader-column-gap);
    column-fill: auto;
    scroll-behavior: smooth;
    font-family: Georgia, "Times New Roman", "Noto Serif", serif;
    font-size: 1.056rem;
    line-height: 1.82;
}

.verse {
    break-inside: avoid;
    margin: .15rem 0;
}

.verse.focused {
    background: var(--focus);
    box-shadow: 0 0 0 .35rem var(--focus);
}

.verse-number {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    min-width: 36px;
    min-height: 36px;
    margin-right: .15rem;
    border: 0;
    background: transparent;
    color: var(--primary);
    vertical-align: .25rem;
    font-family: Inter, "Source Sans 3", sans-serif;
    font-size: .68rem;
    font-weight: 900;
}

.verse-number:hover {
    background: var(--hover);
    color: var(--primary-dark);
}

.tagged-word {
    border: 0;
    border-bottom: 2px dotted var(--primary-light);
    background: transparent;
    color: inherit;
    min-height: 0;
    padding: 0 .05rem;
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
}

.tagged-word:hover,
.tagged-word[aria-expanded="true"] {
    background: var(--selected);
    color: var(--text);
}

.edge-controls {
    display: grid;
    align-self: center;
    gap: .55rem;
}

.edge-nav {
    width: 100%;
    min-width: 52px;
    min-height: 56px;
    padding: 0 .4rem;
    border: 1px solid transparent;
    background: transparent;
    color: var(--primary);
    font-size: 1.35rem;
    letter-spacing: 0;
}

.edge-nav:hover {
    border-color: var(--border);
    background: rgb(255 253 248 / 62%);
}

.bottom-nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(48px, auto)) minmax(150px, 1fr) repeat(3, minmax(48px, auto));
    gap: .5rem;
    align-items: center;
    max-width: 960px;
    margin: 0 auto;
    padding: .75rem clamp(1rem, 4vw, 2.5rem) 1rem;
    text-align: center;
    color: var(--muted);
    font-weight: 800;
}

.search-band,
.commentary-band,
.study-band,
.sources-band,
.about-band,
.policy-band {
    padding: clamp(2rem, 5vw, 4rem) clamp(1rem, 4vw, 2.5rem);
    border-top: 1px solid var(--border);
}

.search-band {
    background: #f0ede6;
}

.commentary-band {
    background: #fffdf8;
}

.section-heading {
    max-width: 920px;
    margin: 0 auto 1.3rem;
}

.section-heading p {
    margin: 0 0 .15rem;
    color: var(--primary);
    font-weight: 900;
    text-transform: uppercase;
}

.section-heading h2 {
    margin: 0;
    color: var(--primary-dark);
    font-size: clamp(1.7rem, 3vw, 2.5rem);
    line-height: 1.1;
}

.filter-row,
.results-list,
.search-guide,
.tool-grid,
.source-list,
.info-grid,
.narrow-copy {
    max-width: 920px;
    margin-inline: auto;
}

.filter-row {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.filter {
    background: #fff;
    color: var(--primary);
}

.filter.active {
    background: var(--primary);
    color: #fff;
}

.results-list {
    display: grid;
    gap: .75rem;
    max-height: min(58vh, 620px);
    overflow: auto;
    padding: 0 1.25rem 1.25rem;
}

.result-item,
.search-guide article,
.tool-grid article,
.source-card,
.info-grid article,
.narrow-copy {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 1rem;
}

.result-item {
    font-size: .8rem;
}

.result-item h3,
.search-guide h3,
.tool-grid h3,
.source-card h3,
.info-grid h3 {
    margin: 0 0 .35rem;
    color: var(--primary-dark);
}

.result-item p,
.search-guide p,
.tool-grid p,
.source-card p,
.info-grid p,
.narrow-copy p {
    margin: .25rem 0;
    color: var(--muted);
}

.result-item mark {
    background: var(--match);
    color: var(--text);
}

.tool-grid,
.search-guide,
.source-list,
.info-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
}

.example-row {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-top: .8rem;
}

.example-row button {
    min-height: 38px;
    padding: .45rem .7rem;
    background: #fff;
    color: var(--primary);
}

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

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

.build-manifest {
    max-width: 920px;
    margin: 1rem auto 0;
    padding: 1rem;
    background: var(--card);
    border: 1px solid var(--border);
}

.build-manifest h3 {
    margin: 0 0 .75rem;
    color: var(--primary-dark);
}

.build-manifest dl {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: .75rem;
    margin: 0;
}

.build-manifest div {
    min-width: 0;
    padding: .75rem;
    background: #fff;
    border: 1px solid var(--border);
}

.build-manifest dt {
    color: var(--muted);
    font-size: .75rem;
    font-weight: 900;
    text-transform: uppercase;
}

.build-manifest dd {
    margin: .15rem 0 0;
    overflow-wrap: anywhere;
    font-weight: 800;
}

.policy-band {
    background: #fff;
}

.attribution-hero {
    padding: clamp(2rem, 5vw, 4rem) clamp(1rem, 4vw, 2.5rem);
    background: var(--card);
    border-bottom: 1px solid var(--border);
}

.attribution-hero h1 {
    margin: 0;
    color: var(--primary-dark);
    font-size: clamp(2rem, 4vw, 3.2rem);
    line-height: 1.08;
}

.attribution-note {
    margin-top: 1rem;
}

.attribution-list {
    align-items: start;
}

.attribution-list code,
.static-manifest code {
    overflow-wrap: anywhere;
}

dialog {
    border: 1px solid var(--border);
    padding: 0;
    color: var(--text);
    background: var(--card);
    box-shadow: var(--shadow);
    max-height: calc(100vh - 2rem);
    overflow: auto;
}

.search-dialog {
    width: min(820px, calc(100vw - 2rem));
}

.search-dialog .section-heading {
    margin: 1rem 1.25rem .75rem;
}

.search-dialog .filter-row {
    margin: 0 1.25rem 1rem;
}

dialog::backdrop {
    background: rgb(41 41 41 / 52%);
}

.sheet-dialog {
    width: min(760px, calc(100vw - 2rem));
}

.study-dialog {
    width: min(560px, calc(100vw - 2rem));
}

#wordContent,
#commentaryContent {
    max-height: calc(100vh - 8rem);
    overflow: auto;
}

.dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--primary);
    color: #fff;
}

.dialog-header h2 {
    margin: 0;
    font-size: 1.2rem;
}

.dialog-header .icon-button {
    border-color: #fff;
}

.tabs {
    display: flex;
    gap: .5rem;
    padding: 1rem 1rem 0;
}

.tab {
    background: #fff;
    color: var(--primary);
}

.tab.active {
    background: var(--primary);
    color: #fff;
}

.book-grid,
.chapter-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: .5rem;
    padding: 1rem;
}

.chapter-grid {
    grid-template-columns: repeat(7, minmax(0, 1fr));
    padding-top: 0;
}

.book-grid button,
.chapter-grid button {
    background: #fff;
    color: var(--primary);
}

.book-grid button.active,
.chapter-grid button.active,
.book-grid button.available,
.chapter-grid button.available {
    background: var(--primary);
    color: #fff;
}

.book-grid button:not(.available),
.chapter-grid button:not(.available) {
    border-color: var(--border);
    color: var(--muted);
}

.verse-jump {
    display: grid;
    gap: .25rem;
    padding: 0 1rem 1rem;
    color: var(--muted);
    font-weight: 800;
}

#navigatorGo {
    margin: 0 1rem 1rem;
}

.recent-list {
    padding: 0 1rem 1rem;
}

.recent-list button {
    margin: .25rem .25rem 0 0;
    background: #fff;
    color: var(--primary);
}

#wordContent,
#commentaryContent {
    padding: 1.25rem;
}

#commentaryContent {
    font-size: .8rem;
}

.study-heading {
    display: grid;
    gap: .25rem;
    margin-bottom: 1rem;
}

.study-heading .original {
    font-family: "Noto Serif", Georgia, serif;
    font-size: 2.2rem;
    color: var(--primary-dark);
}

.study-details {
    display: grid;
    gap: .65rem;
}

.study-details dt {
    color: var(--muted);
    font-size: .78rem;
    font-weight: 900;
    text-transform: uppercase;
}

.study-details dd {
    margin: 0;
}

.source-footnote {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: .9rem;
}

@media (max-width: 860px) {
    .site-header {
        grid-template-columns: 1fr auto;
    }

    .top-search {
        order: 3;
        grid-column: 1 / -1;
    }

    .reader-toolbar {
        grid-template-columns: auto 1fr 1fr auto;
        align-items: end;
    }

    .chapter-control,
    .data-note {
        grid-column: span 2;
    }

    .reading-stage {
        grid-template-columns: 1fr;
        gap: 0;
        padding: 0;
    }

    .scripture-page {
        border-left: 0;
        border-right: 0;
        box-shadow: none;
    }

    .edge-controls {
        display: none;
    }

    .tool-grid,
    .search-guide,
    .source-list,
    .info-grid,
    .build-manifest dl {
        grid-template-columns: 1fr;
    }

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

@media (max-width: 560px) {
    .site-header {
        padding: .65rem .9rem;
    }

    .brand span {
        font-size: 1.05rem;
    }

    .header-nav {
        gap: .7rem;
        font-size: .9rem;
    }

    .reader-toolbar {
        grid-template-columns: 44px minmax(0, 1fr) minmax(70px, .45fr) auto;
        gap: .6rem;
        overflow: auto;
    }

    .reader-toolbar .select-group:first-of-type,
    .data-note {
        display: none;
    }

    .reader-toolbar .select-group,
    .chapter-control {
        grid-column: auto;
    }

    #goButton {
        grid-column: auto;
    }

    #chapterCommentary {
        grid-column: 2 / 4;
    }

    #copyPassageLink {
        grid-column: 4;
    }

    .verses {
        font-size: .92rem;
        line-height: 1.72;
    }

    .bottom-nav {
        grid-template-columns: repeat(3, minmax(38px, 1fr)) minmax(76px, 1.4fr) repeat(3, minmax(38px, 1fr));
        gap: .5rem;
        margin-bottom: 0;
        padding: .75rem;
        background: rgb(255 253 248 / 96%);
        border-top: 1px solid var(--border);
    }

    .bottom-nav button {
        padding: .55rem .45rem;
        font-size: .88rem;
    }

    #chapterPosition {
        font-size: .82rem;
        line-height: 1.2;
    }

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

    .study-dialog,
    .sheet-dialog {
        width: 100vw;
        max-width: 100vw;
        margin: auto 0 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
    }
}
