/* Family Chronicle — Chronicle-wide search
   Search box, results sheet, and the in-chapter find bar.

   Type scale (four sizes, nothing else):
     13px  labels — badges, counts, scope buttons, find-bar text
     15px  body   — snippets, inputs, buttons
     17px  group headings
     20px  dialog title
   Radii: pills 999px, controls 10px, panel 14px, dialog 18px.

   The theme styles bare `button`, `h2`, `h3` and `input` at (0,1,1) via the
   Elementor kit, so every control here is qualified with its container and
   element to win without !important. */

:root {
    --fc-s-violet:   #7c3aed;
    --fc-s-violet-d: #6d28d9;
    --fc-s-ink:      #18181b;
    --fc-s-text:     #3f3f46;
    --fc-s-muted:    #6b7280;
    --fc-s-line:     #e4e4e7;
    --fc-s-tint:     #f5f3ff;
    --fc-s-hit:      #fde68a;
    --fc-s-hit-now:  #f59e0b;

    --fc-s-label: 13px;
    --fc-s-body:  15px;
    --fc-s-head:  17px;
    --fc-s-title: 20px;

    --fc-s-r-ctl:   10px;
    --fc-s-r-panel: 14px;
    --fc-s-r-sheet: 18px;
}

/* ---------------- Trigger in the chapter eyebrow ---------------- */
/* Same pill as every other eyebrow tag (style.css owns the look); this only
   beats the Elementor kit's bare `button` rules. */

.fc-chapter-eyebrow button.fc-meta-search {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    margin: 0;
    padding: 0 16px;
    box-sizing: border-box;
    font-family: inherit;
    font-size: var(--fc-s-body);
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0;
    text-transform: none;
    color: #3f3f46;
    background: #fff;
    border: 1px solid var(--fc-s-line);
    border-radius: 999px;
    box-shadow: none;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.16s ease, background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.fc-chapter-eyebrow button.fc-meta-search:hover,
.fc-chapter-eyebrow button.fc-meta-search:focus-visible {
    color: #6d28d9;
    background: var(--fc-s-tint);
    border-color: #ddd6fe;
    outline: none;
}
.fc-chapter-eyebrow button.fc-meta-search:hover .fc-icon,
.fc-chapter-eyebrow button.fc-meta-search:focus-visible .fc-icon { color: #6d28d9; }

.fc-chapter-eyebrow button.fc-meta-search:focus-visible {
    border-color: #6d28d9;
    box-shadow: 0 0 0 3px rgba(109, 40, 217, 0.22);
}

/* ---------------- Small search box ---------------- */

.fc-search-panel {
    position: absolute;
    z-index: 9996;
    background: #fff;
    border: 1px solid var(--fc-s-line);
    border-radius: var(--fc-s-r-panel);
    box-shadow: 0 18px 44px rgba(24, 24, 27, 0.16);
    padding: 12px;
    direction: rtl;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s;
}

.fc-search-panel.fc-search-panel-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.fc-search-form,
.fc-search-refine {
    display: flex;
    align-items: stretch;
    gap: 6px;
}

.fc-search-panel input.fc-search-input,
.fc-search-dialog input.fc-search-input {
    flex: 1;
    min-width: 0;
    margin: 0;
    height: 40px;
    font-family: inherit;
    font-size: var(--fc-s-body);
    line-height: 1.4;
    padding: 0 12px;
    border: 1px solid var(--fc-s-line);
    border-radius: var(--fc-s-r-ctl);
    background: #fafafa;
    color: var(--fc-s-ink);
    outline: none;
    box-shadow: none;
    transition: border-color 0.16s, background 0.16s, box-shadow 0.16s;
}

.fc-search-panel input.fc-search-input:focus,
.fc-search-dialog input.fc-search-input:focus {
    border-color: var(--fc-s-violet);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.14);
}

.fc-search-panel button.fc-search-go,
.fc-search-dialog button.fc-search-go {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    margin: 0;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--fc-s-r-ctl);
    background: var(--fc-s-violet);
    color: #fff;
    cursor: pointer;
    transition: background 0.16s;
}

.fc-search-panel button.fc-search-go:hover,
.fc-search-dialog button.fc-search-go:hover { background: var(--fc-s-violet-d); }

.fc-search-go-icon {
    width: 18px;
    height: 18px;
    display: block;
}

.fc-search-scope {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.fc-search-panel button.fc-search-scope-btn {
    flex: 1;
    margin: 0;
    padding: 7px 8px;
    font-family: inherit;
    font-size: var(--fc-s-label);
    font-weight: 600;
    line-height: 1.4;
    border: 1px solid var(--fc-s-line);
    border-radius: var(--fc-s-r-ctl);
    background: #fff;
    color: var(--fc-s-muted);
    cursor: pointer;
    transition: background 0.16s, border-color 0.16s, color 0.16s;
}

.fc-search-panel button.fc-search-scope-btn:hover {
    border-color: rgba(124, 58, 237, 0.4);
    color: var(--fc-s-violet-d);
    background: #fff;
}

.fc-search-panel button.fc-search-scope-btn.fc-scope-active {
    background: var(--fc-s-tint);
    border-color: rgba(124, 58, 237, 0.5);
    color: var(--fc-s-violet-d);
}

.fc-search-panel-msg,
.fc-search-refine-msg {
    font-size: var(--fc-s-label);
    line-height: 1.4;
    color: var(--fc-s-muted);
}

.fc-search-panel-msg:not(:empty) { margin-top: 9px; }

.fc-search-spinner {
    display: inline-block;
    width: 11px;
    height: 11px;
    border: 2px solid rgba(124, 58, 237, 0.25);
    border-top-color: var(--fc-s-violet);
    border-radius: 50%;
    animation: fc-search-spin 0.7s linear infinite;
    vertical-align: -1px;
}

@keyframes fc-search-spin { to { transform: rotate(360deg); } }

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

.fc-search-modal {
    position: fixed;
    inset: 0;
    z-index: 9998;
    display: none;
}

.fc-search-modal.fc-search-modal-open { display: block; }

body.fc-search-locked { overflow: hidden; }

.fc-search-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(24, 24, 27, 0.5);
    backdrop-filter: blur(2px);
    animation: fc-search-fade 0.18s ease;
}

@keyframes fc-search-fade { from { opacity: 0; } to { opacity: 1; } }

.fc-search-dialog {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(680px, calc(100vw - 32px));
    max-height: min(78vh, 800px);
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: var(--fc-s-r-sheet);
    box-shadow: 0 30px 70px rgba(24, 24, 27, 0.32);
    direction: rtl;
    overflow: hidden;
    animation: fc-search-rise 0.2s ease;
}

@keyframes fc-search-rise {
    from { opacity: 0; transform: translate(-50%, calc(-50% + 12px)); }
}

.fc-search-dialog-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    padding: 18px 22px 14px;
    border-bottom: 1px solid var(--fc-s-line);
}

.fc-search-dialog h2.fc-search-dialog-title {
    margin: 0;
    padding: 0;
    font-family: inherit;
    font-size: var(--fc-s-title);
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: 0;
    color: var(--fc-s-ink);
}

.fc-search-dialog-sub {
    margin: 4px 0 0;
    font-size: var(--fc-s-label);
    line-height: 1.5;
    color: var(--fc-s-muted);
}

.fc-search-dialog-sub strong { color: var(--fc-s-violet-d); font-weight: 700; }

.fc-search-dialog button.fc-search-dialog-close {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: var(--fc-s-r-ctl);
    background: #f4f4f5;
    color: var(--fc-s-muted);
    font-size: var(--fc-s-label);
    line-height: 1;
    cursor: pointer;
    transition: background 0.16s, color 0.16s;
}

.fc-search-dialog button.fc-search-dialog-close:hover { background: #e4e4e7; color: var(--fc-s-ink); }

.fc-search-dialog-body {
    flex: 1;
    overflow-y: auto;
    padding: 6px 12px 12px;
    overscroll-behavior: contain;
}

.fc-search-empty {
    margin: 0;
    padding: 34px 12px;
    text-align: center;
    color: var(--fc-s-muted);
    font-size: var(--fc-s-body);
    line-height: 1.7;
}

.fc-search-group { padding: 12px 0 6px; }
.fc-search-group + .fc-search-group { border-top: 1px solid #f4f4f5; }

.fc-search-dialog h3.fc-search-group-head {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 0 0 6px;
    padding: 0 10px;
    font-family: inherit;
    font-size: var(--fc-s-head);
    font-weight: 700;
    line-height: 1.4;
    letter-spacing: 0;
    color: var(--fc-s-ink);
}

.fc-search-ch-num {
    flex: 0 0 auto;
    font-size: var(--fc-s-label);
    font-weight: 700;
    line-height: 1.4;
    letter-spacing: 0.3px;
    color: #fff;
    background: var(--fc-s-violet);
    padding: 3px 12px;
    border-radius: 999px;
}

.fc-search-ch-title { flex: 1; min-width: 120px; }

.fc-search-ch-count {
    font-size: var(--fc-s-label);
    font-weight: 500;
    color: var(--fc-s-muted);
    white-space: nowrap;
}

.fc-search-hits {
    list-style: none;
    margin: 0;
    padding: 0;
}

.fc-search-dialog button.fc-search-hit {
    display: flex;
    align-items: baseline;
    gap: 10px;
    width: 100%;
    margin: 0;
    padding: 8px 10px;
    text-align: right;
    font-family: inherit;
    font-size: var(--fc-s-body);
    font-weight: 400;
    line-height: 1.7;
    color: var(--fc-s-text);
    background: none;
    border: none;
    border-radius: var(--fc-s-r-ctl);
    cursor: pointer;
    transition: background 0.14s;
}

.fc-search-dialog button.fc-search-hit:hover,
.fc-search-dialog button.fc-search-hit:focus-visible {
    background: #faf5ff;
    color: var(--fc-s-ink);
    outline: none;
}

.fc-search-hit-page {
    flex: 0 0 auto;
    font-size: var(--fc-s-label);
    font-weight: 700;
    line-height: 1.4;
    color: var(--fc-s-violet-d);
    background: var(--fc-s-tint);
    border: 1px solid rgba(124, 58, 237, 0.18);
    border-radius: 999px;
    padding: 2px 10px;
    white-space: nowrap;
}

.fc-search-hit-note {
    color: #0f766e;
    background: #f0fdfa;
    border-color: rgba(13, 148, 136, 0.3);
}

.fc-search-hit-page-none,
.fc-search-hit-badge {
    color: #92400e;
    background: #fffbeb;
    border-color: rgba(245, 158, 11, 0.3);
}

/* The theme sets button { white-space: nowrap } — snippets must wrap. */
.fc-search-dialog button.fc-search-hit,
.fc-search-dialog .fc-search-hit-text {
    white-space: normal;
    overflow-wrap: anywhere;
}

.fc-search-hit-text { flex: 1; min-width: 0; }

.fc-search-hit-text mark {
    background: var(--fc-s-hit);
    color: #78350f;
    font-weight: 700;
    border-radius: 3px;
    padding: 0 2px;
}

.fc-search-dialog button.fc-search-hit-title .fc-search-hit-text { font-weight: 600; color: var(--fc-s-ink); }

.fc-search-dialog button.fc-search-more {
    display: block;
    margin: 2px 10px 0;
    padding: 6px 0;
    font-family: inherit;
    font-size: var(--fc-s-label);
    font-weight: 600;
    line-height: 1.4;
    color: var(--fc-s-violet-d);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.fc-search-dialog button.fc-search-more:hover { color: var(--fc-s-violet); background: none; }

.fc-search-dialog-foot {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 18px;
    border-top: 1px solid var(--fc-s-line);
    background: #fafafa;
}

.fc-search-refine { flex: 1; min-width: 200px; }

.fc-search-dialog button.fc-search-back-origin {
    margin: 0;
    padding: 6px 2px;
    font-family: inherit;
    font-size: var(--fc-s-label);
    font-weight: 600;
    line-height: 1.4;
    color: var(--fc-s-muted);
    background: none;
    border: none;
    cursor: pointer;
    white-space: nowrap;
}

.fc-search-dialog button.fc-search-back-origin:hover { color: var(--fc-s-violet-d); background: none; }

/* ---------------- In-chapter hits + find bar ---------------- */

.fc-text-content mark.fc-hit {
    background: var(--fc-s-hit);
    color: inherit;
    border-radius: 3px;
    padding: 0 1px;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

.fc-text-content mark.fc-hit.fc-hit-current {
    background: var(--fc-s-hit-now);
    color: #1c1917;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.28);
}

.fc-findbar {
    position: fixed;
    bottom: 22px;
    left: 50%;
    transform: translateX(-50%) translateY(18px);
    z-index: 9992;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: calc(100vw - 24px);
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid var(--fc-s-line);
    border-radius: 999px;
    box-shadow: 0 14px 38px rgba(24, 24, 27, 0.2);
    backdrop-filter: blur(6px);
    font-size: var(--fc-s-label);
    line-height: 1.4;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.fc-findbar.fc-findbar-open {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.fc-findbar button.fc-findbar-back {
    margin: 0;
    padding: 7px 14px;
    font-family: inherit;
    font-size: var(--fc-s-label);
    font-weight: 600;
    line-height: 1.4;
    color: var(--fc-s-violet-d);
    background: var(--fc-s-tint);
    border: 1px solid rgba(124, 58, 237, 0.22);
    border-radius: 999px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.16s, color 0.16s;
}

.fc-findbar button.fc-findbar-back:hover {
    background: var(--fc-s-violet-d);
    border-color: var(--fc-s-violet-d);
    color: #fff;
}

.fc-findbar-q {
    font-size: var(--fc-s-label);
    font-weight: 700;
    color: var(--fc-s-ink);
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fc-findbar-nav {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.fc-findbar button.fc-findbar-step {
    width: 32px;
    height: 32px;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: var(--fc-s-r-ctl);
    background: var(--fc-s-violet);
    color: #fff;
    font-size: var(--fc-s-body);
    line-height: 1;
    cursor: pointer;
    transition: background 0.16s;
}

.fc-findbar button.fc-findbar-step:hover:not(:disabled) { background: var(--fc-s-violet-d); }
.fc-findbar button.fc-findbar-step:disabled { background: #e5e7eb; color: #9ca3af; cursor: default; }

.fc-findbar-count {
    font-size: var(--fc-s-label);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--fc-s-text);
    min-width: 76px;
    text-align: center;
    white-space: nowrap;
}

.fc-findbar button.fc-findbar-close {
    width: 32px;
    height: 32px;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: var(--fc-s-r-ctl);
    background: #f4f4f5;
    color: var(--fc-s-muted);
    font-size: var(--fc-s-label);
    line-height: 1;
    cursor: pointer;
    transition: background 0.16s, color 0.16s;
}

.fc-findbar button.fc-findbar-close:hover { background: #e4e4e7; color: var(--fc-s-ink); }

/* Keep the find bar clear of the back-to-top button on small screens. */
body.fc-findbar-visible #fc-back-to-top { bottom: 86px; }

/* iOS Safari zooms the page into any input under 16px when it takes focus —
   and that zoom is itself a resize that jolts the page. Touch screens get 16px. */
@media (pointer: coarse), (max-width: 640px) {
    .fc-search-panel input.fc-search-input,
    .fc-search-dialog input.fc-search-input { font-size: 16px; }
}

/* ================= Touch screens =================
   44px is the smallest target a finger (and an older reader's finger) hits
   reliably. No grey/blue tap flash — a short press-down fade instead — and
   `manipulation` so tapping "next" twice quickly never zooms the page. */
@media (pointer: coarse) {
    #fc-chronicle-search-btn,
    .fc-search-panel button,
    .fc-search-dialog button,
    .fc-findbar button {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    .fc-search-panel button:active,
    .fc-search-dialog button:active,
    .fc-findbar button:active { opacity: 0.72; }

    .fc-search-panel input.fc-search-input,
    .fc-search-dialog input.fc-search-input { height: 44px; }
    .fc-search-panel button.fc-search-go,
    .fc-search-dialog button.fc-search-go { width: 44px; height: 44px; }
    .fc-search-panel button.fc-search-scope-btn { min-height: 44px; }
    .fc-search-dialog button.fc-search-dialog-close { width: 44px; height: 44px; }
    .fc-search-dialog button.fc-search-more,
    .fc-search-dialog button.fc-search-back-origin { min-height: 44px; }
}

/* ================= Phones ================= */
@keyframes fc-search-up { from { opacity: 0; transform: translateY(16px); } }

@media (max-width: 640px) {
    /* Results: a full-screen sheet with the search field right under the
       title. At the bottom of a centred card the keyboard covered it. */
    .fc-search-dialog {
        top: 0;
        left: 0;
        transform: none;
        width: 100%;
        height: 100%;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
        box-shadow: none;
        animation: fc-search-up 0.2s ease;
    }
    .fc-search-dialog-head { padding: max(14px, env(safe-area-inset-top)) 16px 12px; }
    .fc-search-dialog-foot {
        order: 1;
        padding: 10px 12px;
        gap: 4px 12px;
        border-top: 0;
        border-bottom: 1px solid var(--fc-s-line);
    }
    .fc-search-refine { flex-basis: 100%; min-width: 0; }
    .fc-search-dialog-body {
        order: 2;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
    .fc-search-dialog button.fc-search-hit { flex-wrap: wrap; gap: 6px; }

    /* Find bar: one full-width row on the bottom edge instead of a
       three-row block floating over the text. */
    .fc-findbar {
        left: 0;
        right: 0;
        bottom: 0;
        max-width: none;
        transform: translateY(100%);
        flex-wrap: nowrap;
        justify-content: space-between;
        gap: 6px;
        padding: 8px 10px max(8px, env(safe-area-inset-bottom));
        border-width: 1px 0 0;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -8px 24px rgba(24, 24, 27, 0.12);
    }
    .fc-findbar.fc-findbar-open { transform: none; }
    .fc-findbar-q,
    .fc-findbar-long { display: none; }
    .fc-findbar-nav { flex: 1 1 auto; justify-content: center; min-width: 0; }
    .fc-findbar-count { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
    .fc-findbar button.fc-findbar-back { min-height: 44px; padding: 0 12px; flex: 0 0 auto; }
    .fc-findbar button.fc-findbar-step,
    .fc-findbar button.fc-findbar-close { width: 44px; height: 44px; flex: 0 0 auto; }

    body.fc-findbar-visible { padding-bottom: 72px; }   /* last lines stay reachable */
    body.fc-findbar-visible #fc-back-to-top { bottom: 84px; }
}
