/* =============================================================
   Chapter Jump — direct navigation dialog for the reader surfaces.

   Shared by the Katha reader (views/katha/reader.ejs) and the
   Chitra reader (views/chitra/reader.ejs). Behaviour lives in
   public/js/chapter-jump.js; markup in views/partials/chapter-jump.ejs.

   Theming: every colour resolves through a --cj-* custom property.
   The values declared on .cjump below are the Katha defaults; a host
   page overrides them by redeclaring --cj-* on .cjump.
   ============================================================= */

.cjump {
    /* Accent */
    --cj-accent: #a78bfa;
    --cj-accent-soft: rgba(168, 85, 247, 0.14);
    --cj-accent-line: rgba(168, 85, 247, 0.38);
    --cj-accent-ink: #150724;

    /* Surfaces */
    --cj-panel: #101014;
    --cj-raise: rgba(255, 255, 255, 0.035);
    --cj-raise-hi: rgba(255, 255, 255, 0.065);
    --cj-border: rgba(255, 255, 255, 0.08);
    --cj-border-hi: rgba(255, 255, 255, 0.15);

    /* Ink */
    --cj-ink: #f3f3f6;
    --cj-ink-dim: rgba(243, 243, 246, 0.5);
    --cj-ink-faint: rgba(243, 243, 246, 0.3);

    /* Geometry + motion */
    --cj-r-panel: 18px;
    --cj-r-row: 12px;
    --cj-ease: cubic-bezier(0.16, 1, 0.3, 1);
    --cj-spring: cubic-bezier(0.22, 1.4, 0.36, 1);

    position: fixed;
    inset: 0;
    z-index: 20000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    font-family: inherit;
}

.cjump[hidden] { display: none; }

.cjump-backdrop {
    position: absolute;
    inset: 0;
    background: radial-gradient(120% 80% at 50% 0%, rgba(8, 8, 12, 0.6), rgba(4, 4, 6, 0.82));
    -webkit-backdrop-filter: blur(14px) saturate(115%);
    backdrop-filter: blur(14px) saturate(115%);
    opacity: 0;
    transition: opacity 0.26s var(--cj-ease);
}

.cjump.is-open .cjump-backdrop { opacity: 1; }

.cjump-panel {
    position: relative;
    width: min(540px, 100%);
    max-height: min(700px, calc(100dvh - 48px));
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0) 180px), var(--cj-panel);
    border: 1px solid var(--cj-border);
    border-radius: var(--cj-r-panel);
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.07) inset,
        0 40px 80px -20px rgba(0, 0, 0, 0.75),
        0 0 0 1px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    opacity: 0;
    transform: translateY(12px) scale(0.975);
    transition: opacity 0.24s var(--cj-ease), transform 0.34s var(--cj-spring);
}

.cjump-panel:focus { outline: none; }
.cjump.is-open .cjump-panel { opacity: 1; transform: none; }

/* Accent hairline across the top edge of the panel. */
.cjump-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 12%;
    right: 12%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--cj-accent-line), transparent);
    pointer-events: none;
}

/* ── Header ────────────────────────────────────────────────── */
.cjump-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 18px 18px 0;
}

.cjump-head-text { flex: 1; min-width: 0; }

.cjump-eyebrow {
    display: block;
    margin: 0 0 5px;
    font-size: 0.6rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--cj-accent);
}

.cjump-head h2 {
    margin: 0;
    font-size: 1.06rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    line-height: 1.2;
    color: var(--cj-ink);
}

.cjump-sub {
    margin: 5px 0 0;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: -0.005em;
    color: var(--cj-ink-dim);
    font-variant-numeric: tabular-nums;
}

.cjump-icon {
    flex: none;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    border: 1px solid var(--cj-border);
    background: var(--cj-raise);
    color: var(--cj-ink-dim);
    cursor: pointer;
    transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease, transform 0.18s var(--cj-ease);
}

.cjump-icon:hover {
    color: var(--cj-ink);
    border-color: var(--cj-border-hi);
    background: var(--cj-raise-hi);
}

.cjump-icon:active { transform: scale(0.94); }
.cjump-icon svg { width: 15px; height: 15px; }

.cjump-icon.is-active {
    color: var(--cj-accent);
    border-color: var(--cj-accent-line);
    background: var(--cj-accent-soft);
}

/* ── Search + sort ─────────────────────────────────────────── */
.cjump-tools {
    display: flex;
    gap: 8px;
    padding: 14px 18px 10px;
}

.cjump-search { position: relative; flex: 1; min-width: 0; }

.cjump-search svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 15px;
    height: 15px;
    color: var(--cj-ink-faint);
    pointer-events: none;
    transition: color 0.18s ease;
}

.cjump-search:focus-within svg { color: var(--cj-accent); }

.cjump-search input {
    width: 100%;
    height: 42px;
    padding: 0 12px 0 35px;
    border-radius: 12px;
    border: 1px solid var(--cj-border);
    background: var(--cj-raise);
    color: var(--cj-ink);
    font-size: 0.86rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    font-family: inherit;
    outline: none;
    transition: border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
    -webkit-appearance: none;
    appearance: none;
}

.cjump-search input::placeholder { color: var(--cj-ink-faint); font-weight: 500; }
.cjump-search input::-webkit-search-cancel-button { -webkit-appearance: none; }

.cjump-search input:focus {
    border-color: var(--cj-accent-line);
    background: var(--cj-raise-hi);
    box-shadow: 0 0 0 3px var(--cj-accent-soft);
}

/* ── Range selector ────────────────────────────────────────── */
.cjump-ranges {
    display: flex;
    gap: 6px;
    padding: 2px 18px 12px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 14px, #000 calc(100% - 14px), transparent);
    mask-image: linear-gradient(90deg, transparent, #000 14px, #000 calc(100% - 14px), transparent);
}

.cjump-ranges::-webkit-scrollbar { display: none; }
.cjump-ranges:empty { display: none; }

.cjump-range {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    padding: 0 13px;
    border-radius: 999px;
    border: 1px solid var(--cj-border);
    background: var(--cj-raise);
    color: var(--cj-ink-dim);
    font-size: 0.73rem;
    font-weight: 700;
    font-family: inherit;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.005em;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.cjump-range:hover { color: var(--cj-ink); border-color: var(--cj-border-hi); }

.cjump-range.is-active {
    color: var(--cj-accent);
    background: var(--cj-accent-soft);
    border-color: var(--cj-accent-line);
}

.cjump-range-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--cj-accent);
    box-shadow: 0 0 0 3px var(--cj-accent-soft);
}

/* ── List ──────────────────────────────────────────────────── */
.cjump-list {
    flex: 1;
    min-height: 0;
    margin: 0;
    padding: 0 10px 10px;
    list-style: none;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: 1px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
}

.cjump-list::-webkit-scrollbar { width: 10px; }
.cjump-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.13);
    border-radius: 99px;
    border: 3px solid transparent;
    background-clip: content-box;
}

.cjump-item[hidden] { display: none; }

.cjump-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px 9px 10px;
    border-radius: var(--cj-r-row);
    border: 1px solid transparent;
    text-decoration: none;
    color: var(--cj-ink);
    transition: background 0.14s ease, border-color 0.14s ease;
}

.cjump-link:hover,
.cjump-link:focus-visible {
    background: var(--cj-raise);
    border-color: var(--cj-border);
    outline: none;
}

.cjump-n {
    flex: none;
    min-width: 32px;
    height: 32px;
    padding: 0 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    background: var(--cj-raise);
    border: 1px solid var(--cj-border);
    font-size: 0.78rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
    color: var(--cj-ink-dim);
    transition: color 0.14s ease, background 0.14s ease, border-color 0.14s ease;
}

.cjump-link:hover .cjump-n { color: var(--cj-ink); border-color: var(--cj-border-hi); }

.cjump-body { flex: 1; min-width: 0; }

.cjump-title {
    display: block;
    font-size: 0.855rem;
    font-weight: 650;
    letter-spacing: -0.015em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cjump-meta {
    display: block;
    margin-top: 2px;
    font-size: 0.685rem;
    font-weight: 600;
    letter-spacing: -0.005em;
    color: var(--cj-ink-faint);
    font-variant-numeric: tabular-nums;
}

.cjump-badge {
    flex: none;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.6rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--cj-accent);
    background: var(--cj-accent-soft);
    border: 1px solid var(--cj-accent-line);
}

.cjump-badge.is-draft {
    color: #f5b942;
    background: rgba(245, 185, 66, 0.12);
    border-color: rgba(245, 185, 66, 0.34);
}

/* Enter affordance, revealed on pointer hover only. */
.cjump-enter {
    flex: none;
    display: none;
    width: 22px;
    height: 22px;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 1px solid var(--cj-border-hi);
    color: var(--cj-ink-dim);
    font-size: 0.65rem;
    line-height: 1;
}

@media (hover: hover) and (min-width: 561px) {
    .cjump-link:hover .cjump-enter,
    .cjump-link:focus-visible .cjump-enter { display: inline-flex; }
    .cjump-link:hover .cjump-badge,
    .cjump-link:focus-visible .cjump-badge { display: none; }
}

/* Row for the item currently open in the reader. */
.cjump-item.is-current .cjump-link {
    background: var(--cj-accent-soft);
    border-color: var(--cj-accent-line);
}

.cjump-item.is-current .cjump-n {
    color: var(--cj-accent-ink);
    background: var(--cj-accent);
    border-color: var(--cj-accent);
}

.cjump-empty {
    padding: 36px 20px 42px;
    text-align: center;
    font-size: 0.83rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--cj-ink-dim);
}

.cjump-empty[hidden] { display: none; }

/* ── Footer: shortcut legend + pager ───────────────────────── */
.cjump-foot {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px calc(11px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--cj-border);
    background: rgba(0, 0, 0, 0.22);
}

.cjump-hints {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
    font-size: 0.66rem;
    font-weight: 600;
    color: var(--cj-ink-faint);
    white-space: nowrap;
    overflow: hidden;
}

.cjump-hints kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 5px;
    border: 1px solid var(--cj-border-hi);
    background: var(--cj-raise);
    font-family: inherit;
    font-size: 0.62rem;
    font-weight: 700;
    color: var(--cj-ink-dim);
}

.cjump-hints .cjump-hint-sep { opacity: 0.4; margin: 0 2px; }

.cjump-pager {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: none;
}

.cjump-pager[hidden] { display: none; }

.cjump-page-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 32px;
    padding: 0 11px;
    border-radius: 9px;
    border: 1px solid var(--cj-border);
    background: var(--cj-raise);
    color: var(--cj-ink-dim);
    font-size: 0.73rem;
    font-weight: 700;
    letter-spacing: -0.005em;
    font-family: inherit;
    cursor: pointer;
    transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.cjump-page-btn:hover:not(:disabled) {
    color: var(--cj-ink);
    border-color: var(--cj-border-hi);
    background: var(--cj-raise-hi);
}

.cjump-page-btn:disabled { opacity: 0.3; cursor: default; }
.cjump-page-btn svg { width: 14px; height: 14px; }

.cjump-pageinfo {
    padding: 0 4px;
    font-size: 0.71rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--cj-ink-dim);
    white-space: nowrap;
}

/* =============================================================
   Trigger control. Two variants: the default pill sits in a
   footer navigation row; .is-chip is the compact form for a
   sticky reader header.
   ============================================================= */
.cjump-trigger {
    --cj-border: rgba(255, 255, 255, 0.09);
    --cj-border-hi: rgba(255, 255, 255, 0.19);
    --cj-ink: #f3f3f6;
    --cj-ink-dim: rgba(243, 243, 246, 0.5);
    --cj-ease: cubic-bezier(0.16, 1, 0.3, 1);

    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 13px 20px;
    border-radius: 999px;
    border: 1px solid var(--cj-border);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.025));
    color: var(--cj-ink);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: -0.015em;
    cursor: pointer;
    transition: border-color 0.22s ease, background 0.22s ease, transform 0.24s var(--cj-ease);
}

.cjump-trigger:hover {
    border-color: var(--cj-border-hi);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.045));
    transform: translateY(-1px);
}

.cjump-trigger:active { transform: translateY(0) scale(0.985); }
.cjump-trigger svg { width: 15px; height: 15px; color: var(--cj-ink-dim); flex: none; }
.cjump-trigger .cjump-trigger-count { color: var(--cj-ink-dim); font-weight: 700; }

.cjump-trigger.is-chip {
    gap: 6px;
    padding: 6px 13px;
    font-size: 0.73rem;
}

.cjump-trigger.is-chip svg { width: 13px; height: 13px; }

/* Scroll lock applied to <html> while the dialog is open. */
html.cjump-locked, html.cjump-locked body { overflow: hidden !important; }

/* ── Small screens: bottom sheet ───────────────────────────── */
@media (max-width: 560px) {
    .cjump { padding: 0; align-items: flex-end; }

    .cjump-panel {
        width: 100%;
        max-height: 86dvh;
        border-radius: 22px 22px 0 0;
        border-bottom: none;
        transform: translateY(28px);
    }

    /* Sheet grabber */
    .cjump-panel::after {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 38px;
        height: 4px;
        border-radius: 99px;
        background: var(--cj-border-hi);
    }

    .cjump-head { padding: 20px 16px 0; }
    .cjump-tools { padding: 12px 16px 8px; }
    .cjump-ranges { padding: 2px 16px 10px; }
    .cjump-list { padding: 0 8px 8px; }
    .cjump-hints { display: none; }
    .cjump-pager { flex: 1; justify-content: space-between; }
    .cjump-foot { padding: 10px 14px calc(12px + env(safe-area-inset-bottom, 0px)); }
}

@media (prefers-reduced-motion: reduce) {
    .cjump-backdrop,
    .cjump-panel,
    .cjump-trigger,
    .cjump-icon { transition: none; }
    .cjump-panel { transform: none; }
}
