* {
    box-sizing: border-box;
}


body {
    margin: 0;
    font-family: Arial, sans-serif;
    background: #f5f5f5;
    color: #222;
}


.container {
    width: min(1000px, 92%);
    margin: 0 auto;
}


header {
    padding: 50px 0 30px;
    text-align: center;
}


h1 {
    margin: 0;
    font-size: 42px;
}


.subtitle {
    margin-top: 10px;
    color: #666;
}


/* ---------------------------------------------------------
   Search
--------------------------------------------------------- */


.search-box {
    background: white;
    padding: 25px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}


.search-row {
    display: flex;
    gap: 10px;
}


.search-input {
    flex: 1;
    padding: 13px 15px;
    font-size: 16px;
    border: 1px solid #ccc;
    border-radius: 6px;
    outline: none;
}


.search-input:focus {
    border-color: #777;
}


.search-button {
    padding: 13px 24px;
    font-size: 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}


.search-options {
    margin-top: 15px;
    font-size: 14px;
    color: #555;
}


/* ---------------------------------------------------------
   Results
--------------------------------------------------------- */


.results-header {
    margin: 32px 0 15px;
}


.results-header h2 {
    margin: 0;
    font-size: 22px;
}


.results {
    display: flex;
    flex-direction: column;
    gap: 15px;
}


/* ---------------------------------------------------------
   Book groups
--------------------------------------------------------- */


.book-results {
    margin-bottom: 35px;
}


.book-header {
    display: flex;
    align-items: baseline;
    gap: 10px;

    width: 100%;

    padding: 12px 0;

    border: none;
    border-bottom: 2px solid #ddd;

    background: transparent;

    cursor: pointer;

    color: #222;

    text-align: left;

    font-family: inherit;
}


/* Remove the browser's default triangle */

.book-header::-webkit-details-marker {
    display: none;
}


.book-header::before {
    content: "▸";

    width: 18px;

    font-size: 15px;

    flex-shrink: 0;
}


.book-results[open] .book-header::before {
    content: "▾";
}


.book-title {
    font-size: 21px;
    font-weight: 600;
}


.book-year {
    font-size: 15px;
    color: #777;
}


.book-result-count {
    margin-left: auto;

    font-size: 14px;
    color: #888;

    white-space: nowrap;
}


.book-content {
    padding-top: 15px;
}


/* ---------------------------------------------------------
   Individual result
--------------------------------------------------------- */


.result {
    background: white;

    padding: 22px 24px;

    border-radius: 8px;

    box-shadow:
        0 1px 5px rgba(0, 0, 0, 0.06);
}


.result-header {
    display: flex;

    justify-content: space-between;

    align-items: baseline;

    gap: 20px;

    margin-bottom: 15px;
}


.result-location {
    font-size: 14px;
    color: #666;
}


.chapter {
    font-weight: 600;
    color: #333;
}


.separator {
    margin: 0 5px;
    color: #aaa;
}


.footnote-label {
    font-weight: 600;
    color: #555;
}


.result-score {
    white-space: nowrap;

    font-size: 13px;

    color: #888;
}


.result-context {
    font-size: 16px;

    line-height: 1.75;
}


.result-context strong {
    font-weight: 700;
}


/* ---------------------------------------------------------
   Mobile
--------------------------------------------------------- */


@media (max-width: 650px) {

    .search-row {
        flex-direction: column;
    }


    .search-button {
        width: 100%;
    }


    .result-header {
        flex-direction: column;

        gap: 8px;
    }


    .result-score {
        white-space: normal;
    }


    .book-header {
        flex-wrap: wrap;

        align-items: center;
    }


    .book-result-count {
        margin-left: 28px;
    }


    h1 {
        font-size: 34px;
    }


    .result {
        padding: 18px;
    }

}

/* ---------------------------------------------------------
   Single-word search controls
--------------------------------------------------------- */

.results-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.results-summary h2 {
    margin: 0;
}

.sort-control {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #666;
}

.sort-control select {
    padding: 7px 30px 7px 9px;
    border: 1px solid #ccc;
    border-radius: 6px;
    background: white;
    color: #333;
    font: inherit;
    cursor: pointer;
}

.match-count {
    font-weight: 600;
    color: #555;
}


/* ---------------------------------------------------------
   Mobile adjustments for single-word controls
--------------------------------------------------------- */

@media (max-width: 650px) {

    .results-summary {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .sort-control {
        width: 100%;
        justify-content: space-between;
    }

}


/* ---------------------------------------------------------
   Notes visibility control
--------------------------------------------------------- */

.notes-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-left: 18px;
    font-size: 14px;
    color: #666;
    cursor: pointer;
}

.notes-toggle input {
    margin: 0;
}


/* ---------------------------------------------------------
   Footnote results — intentionally subtler than body results
--------------------------------------------------------- */

.result.note-result {
    padding: 16px 20px;
    background: #fafafa;
    border: 1px solid #e8e8e8;
    box-shadow: none;
}

.note-result .result-header {
    margin-bottom: 9px;
}

.note-result .result-location {
    font-size: 13px;
    color: #888;
}

.note-result .footnote-label {
    color: #777;
}

.note-result .result-context {
    font-size: 14px;
    line-height: 1.6;
    color: #555;
}

@media (max-width: 650px) {
    .notes-toggle {
        margin-left: 0;
        margin-top: 12px;
        width: 100%;
    }

    .result.note-result {
        padding: 14px 16px;
    }
}


/* Grouped multi-word result count */
.match-count {
    font-weight: 600;
    color: #555;
}


.exact-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-top: 12px;
    font-size: 14px;
    color: #555;
    cursor: pointer;
}

.exact-toggle input {
    margin: 0;
}

.match-count {
    font-weight: 600;
    color: #555;
}


.exact-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    color: #555;
    font-size: 14px;
}

.exact-toggle input {
    margin: 0;
}


.sort-control {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.sort-control select {
    font: inherit;
}


.cache-status {
    font-size: 12px;
    color: #777;
    margin-bottom: 4px;
}


/* ---------------------------------------------------------
   Two-level result ordering
--------------------------------------------------------- */

.book-local-controls {
    padding: 12px 0 4px 28px;
}

.local-sort-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    color: #777;
    cursor: pointer;
}

.local-sort-toggle input {
    margin: 0;
}

@media (max-width: 650px) {
    .book-local-controls {
        padding-left: 28px;
    }

    .local-sort-toggle {
        font-size: 13px;
    }
}


/* ---------------------------------------------------------
   Full paragraph and "Ver más" context
--------------------------------------------------------- */

.full-paragraph-context,
.exact-full-paragraph-context {
    white-space: normal;
}

.exact-full-paragraph-context {
    display: none;
}

.expanded-paragraph {
    margin: 14px 0;
    padding: 16px 18px;
    border-left: 3px solid #ddd;
    background: #fafafa;
    border-radius: 5px;
}

.expanded-paragraph[hidden] {
    display: none;
}

.adjacent-paragraph-label {
    margin-bottom: 8px;
    font-size: 12px;
    color: #888;
}

.adjacent-paragraph-text {
    font-size: 15px;
    line-height: 1.75;
    color: #444;
}

.more-context-button {
    margin-top: 15px;
    padding: 0;
    border: none;
    background: transparent;
    color: #666;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.more-context-button:hover {
    color: #222;
}

@media (max-width: 650px) {
    .expanded-paragraph {
        padding: 14px 15px;
    }

    .adjacent-paragraph-text {
        font-size: 14px;
    }
}


/* ---------------------------------------------------------
   Phase 3A/B — Result hierarchy and adjacent context
--------------------------------------------------------- */

.result-header {
    align-items: flex-start;
}

.result-location {
    flex: 1;
}

.chapter-line {
    margin-bottom: 5px;
}

.chapter {
    font-weight: 600;
    color: #333;
}

.result-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    font-size: 13px;
    color: #888;
    line-height: 1.5;
}

.result-meta .separator {
    margin: 0 6px;
    color: #bbb;
}

.result-meta .match-count {
    color: #666;
}

/* The hit paragraph remains the main reading surface.
   Adjacent paragraphs are deliberately quieter and recessed. */

.expanded-paragraph {
    margin: 16px 0;
    padding: 14px 18px;
    border-left: 2px solid #ddd;
    background: #fafafa;
    border-radius: 5px;
}

.expanded-paragraph-before {
    margin-top: 0;
    margin-bottom: 18px;
}

.expanded-paragraph-after {
    margin-top: 18px;
    margin-bottom: 0;
}

.adjacent-paragraph-label {
    margin-bottom: 7px;
    font-size: 12px;
    color: #999;
}

.adjacent-paragraph-text {
    font-size: 15px;
    line-height: 1.7;
    color: #666;
}

/* Keep the actual result paragraph visually dominant. */
.full-paragraph-context {
    color: #222;
}

@media (max-width: 650px) {
    .result-meta {
        font-size: 12px;
    }

    .expanded-paragraph {
        padding: 13px 15px;
    }

    .adjacent-paragraph-text {
        font-size: 14px;
    }
}


/* Phase 3 A2: clear hierarchy between chapter title and metadata */
.chapter-line {
    display: block;
    margin-bottom: 2px;
    line-height: 1.35;
}

.chapter-line .chapter {
    display: block;
    font-size: 1.02rem;
    font-weight: 700;
}

.result-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0;
    margin-top: 0;
    margin-bottom: 14px;
    padding-left: 0;
    font-size: 0.82rem;
    line-height: 1.3;
    color: #777;
}

.result-meta .separator {
    margin: 0 7px;
    color: #aaa;
}

.result-meta .match-count {
    color: #777;
}

@media (max-width: 700px) {
    .chapter-line .chapter {
        font-size: 0.98rem;
    }

    .result-meta {
        font-size: 0.79rem;
        margin-bottom: 12px;
    }
}



/* Phase 3 C: floating previous / next result navigation */
.floating-result-navigation {
    position: fixed;
    right: 24px;
    bottom: 22px;
    z-index: 1000;

    display: flex;
    align-items: center;
    gap: 8px;

    padding: 7px 9px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid #d8d8d8;
    border-radius: 7px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.10);
}

.floating-result-navigation .result-nav-button {
    border: 1px solid #d4d4d4;
    background: #fff;
    color: #333;
    border-radius: 5px;
    padding: 5px 9px;
    font-size: 0.82rem;
    cursor: pointer;
}

.floating-result-navigation .result-nav-button:hover:not(:disabled) {
    background: #f4f4f4;
}

.floating-result-navigation .result-nav-button:disabled {
    opacity: 0.4;
    cursor: default;
}

.floating-result-navigation .result-position {
    min-width: 82px;
    text-align: center;
    font-size: 0.82rem;
    color: #777;
}

.result-navigation-target {
    animation: result-navigation-highlight 1.2s ease-out;
}

@keyframes result-navigation-highlight {
    0% {
        box-shadow: 0 0 0 3px rgba(90, 90, 90, 0.18);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(90, 90, 90, 0);
    }
}

@media (max-width: 700px) {
    .floating-result-navigation {
        right: 12px;
        bottom: 12px;
        gap: 5px;
        padding: 6px 7px;
    }

    .floating-result-navigation .result-nav-button {
        padding: 5px 7px;
        font-size: 0.78rem;
    }

    .floating-result-navigation .result-position {
        min-width: 70px;
        font-size: 0.78rem;
    }
}

/* Phase 3.2.1: refined coincidence highlighting */
.highlight,
mark.highlight {
    background: #fff1a8;
    color: inherit;
    font-weight: 600;
    padding: 0 2px;
    border-radius: 3px;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

.highlight:hover,
mark.highlight:hover {
    background: #ffe680;
}

/* Phase 3.2.4: keyboard shortcut hint */
.keyboard-hint {
    margin-left: 2px;
    padding-left: 8px;
    border-left: 1px solid #e2e2e2;
    font-size: 0.72rem;
    color: #999;
    white-space: nowrap;
}

@media (max-width: 700px) {
    .keyboard-hint {
        display: none;
    }
}

/* Phase 4.3: copy citation */
.copy-citation {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 8px;
    border: 1px solid #d8d8d8;
    border-radius: 4px;
    background: #fff;
    color: #777;
    font-size: 0.76rem;
    line-height: 1.3;
    cursor: pointer;
}

.copy-citation:hover {
    background: #f5f5f5;
    color: #444;
}

.copy-citation.copied {
    color: #555;
    border-color: #bbb;
}

/* Phase 4.1: compact bibliographic book card */
.book-bibliographic {
    margin: 10px 0 14px;
    padding: 11px 14px;
    border: 1px solid #e3e3e3;
    border-radius: 6px;
    background: #fafafa;
    font-size: 0.84rem;
    color: #666;
}

.book-bibliographic-title {
    margin-bottom: 7px;
    color: #333;
    font-weight: 600;
    font-size: 0.9rem;
}

.book-bibliographic-row {
    display: flex;
    gap: 10px;
    line-height: 1.55;
}

.book-bibliographic-label {
    flex: 0 0 72px;
    color: #999;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

@media (max-width: 700px) {
    .book-bibliographic {
        padding: 9px 11px;
        font-size: 0.8rem;
    }

    .book-bibliographic-row {
        display: block;
        line-height: 1.45;
        margin-bottom: 3px;
    }

    .book-bibliographic-label {
        display: inline-block;
        margin-right: 6px;
    }
}

.book-toc {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #e5e5e5;
}
.book-toc-title {
    margin-bottom: 6px;
    color: #555;
    font-weight: 600;
    font-size: 0.8rem;
}
.book-toc-list {
    max-height: 320px;
    overflow-y: auto;
    padding-right: 5px;
}
.book-toc-part {
    margin-top: 8px;
    margin-bottom: 3px;
    color: #444;
    font-weight: 600;
}
.book-toc-chapter {
    padding: 2px 0 2px 12px;
    line-height: 1.45;
    color: #666;
}
