/* study.css — the verse study panel (js/study.js), its cross-references section (js/xrefs.js),
   the study hub (#/study) and the reader's small study hooks. Tokens come from base.css.

   The panel docks to the right on wide screens, beside the reader's text; on phones it is a
   bottom sheet positioned by --y (set from JS while snapping and dragging), like the detail sheet.
   Sections from other features may use .sp-list / .sp-row / .sp-row-ref / .sp-row-text / .sp-more. */

:root { --study-w: min(420px, 42vw); }

/* ── Frame ──────────────────────────────────────────────────────────── */
.study-panel {
    --pad: var(--s5);
    position: fixed; top: var(--topbar-h); right: 0; bottom: 0; z-index: 24;
    width: var(--study-w);
    display: flex; flex-direction: column;
    background:
        radial-gradient(120% 220px at 0% 0%, color-mix(in srgb, var(--gold) 10%, transparent), transparent 72%),
        var(--bg-1);
    border-left: 1px solid var(--line);
    box-shadow: var(--shadow);
    transform: translateX(calc(100% + 24px));
    transition: transform var(--t-slow) var(--ease-out);
}
.study-panel.is-open { transform: none; }

/* The reader makes room for the panel, so its text stays readable beside it. */
@media (min-width: 761px) {
    #view-read { transition: right var(--t-slow) var(--ease-out); }
    body.study-open[data-view='read'] #view-read { right: var(--study-w); }
}
/* Between tablet and very wide, the chapter's rail folds back above the text while studying. */
@media (min-width: 1020px) and (max-width: 1499px) {
    body.study-open .read-chapter { grid-template-columns: minmax(0, 44rem); }
    body.study-open .read-rail { grid-column: 1; grid-row: auto; position: static; margin-top: 0; max-height: none; }
    body.study-open .read-rail summary { pointer-events: auto; }
    body.study-open .read-rail summary .icon { display: block; }
}

/* Bar: label, the reference once the heading has scrolled away, verse steps and close. */
.sp-bar {
    position: relative; flex: none;
    display: flex; align-items: center; gap: var(--s2);
    height: 56px; padding: 0 var(--s2) 0 var(--pad);
    border-bottom: 1px solid var(--line);
}
.sp-bar-label { flex: none; }
.sp-bar-ref {
    flex: 1; min-width: 0;
    font-family: var(--font-display); font-size: 1.02rem; font-variation-settings: 'opsz' 30;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    opacity: 0; transform: translateY(6px);
    transition: opacity var(--t-med) var(--ease), transform var(--t-med) var(--ease-out);
}
.sp-bar.is-titled .sp-bar-ref { opacity: 1; transform: none; }
.sp-bar-tools { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.sp-step:disabled { opacity: .3; cursor: default; background: none; }
.sp-handle { display: none; }

.sp-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.sp-body { padding: var(--s5) var(--pad) var(--s8); }

/* ── The verse ──────────────────────────────────────────────────────── */
.sp-head { display: grid; gap: var(--s3); padding-bottom: var(--s5); border-bottom: 1px solid var(--line); }
.sp-title { font-size: clamp(1.9rem, 1.6rem + 1vw, 2.4rem); line-height: 1.05; letter-spacing: -.02em; outline: none; }
.sp-verse {
    margin: 0; padding-left: var(--s4);
    border-left: 2px solid var(--gold);
    font-size: 1.15rem; line-height: 1.65; text-wrap: pretty;
}
.sp-verse[aria-busy] { display: grid; gap: var(--s2); }
.sp-missing { color: var(--text-dim); font-family: var(--font-ui); font-size: var(--fs-sm); }
.sp-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s4); font-size: var(--fs-xs); color: var(--text-dim); }
.sp-version { font-weight: 700; letter-spacing: .1em; }
.sp-version:empty { display: none; }
.sp-meta-link {
    position: relative;
    color: var(--text-dim); text-decoration: underline; text-underline-offset: 3px;
    text-decoration-color: color-mix(in srgb, var(--gold) 50%, transparent);
}
.sp-meta-link:hover { color: var(--gold-bright); text-decoration-color: var(--gold); }
.sp-meta-link::after { content: ''; position: absolute; inset: min(0px, calc(50% - 22px)) 0; }

/* ── Sections ───────────────────────────────────────────────────────── */
.sp-sec { padding: var(--s5) 0; border-bottom: 1px solid var(--line); animation: rise var(--t-med) var(--ease-out) both; }
.sp-sec-title { margin-bottom: var(--s3); font-size: var(--fs-xs); font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--text-dim); }
.sp-sec-body[aria-busy] { display: grid; gap: var(--s2); }
.sp-empty { padding-top: var(--s5); font-size: var(--fs-sm); color: var(--text-faint); }
.sp-skel {
    display: block; height: 1em; border-radius: 4px;
    background: linear-gradient(90deg, var(--bg-2), var(--bg-3), var(--bg-2)); background-size: 200% 100%;
    animation: read-shimmer 1.6s linear infinite;
}
.sp-skel.is-short { width: 60%; }
@keyframes read-shimmer { to { background-position: -200% 0; } }

/* Rows of references with a line of text: shared by the panel's sections. */
.sp-list { display: grid; }
.sp-list > li + li { border-top: 1px solid var(--line); }
.sp-row {
    display: grid; gap: 2px; min-height: 44px; padding: var(--s2) var(--s2);
    margin: 0 calc(-1 * var(--s2)); border-radius: var(--r-sm);
    transition: background var(--t-fast) var(--ease);
}
a.sp-row:hover, a.sp-row:focus-visible { background: var(--bg-2); }
.sp-row-ref { font-family: var(--font-display); font-size: 1.05rem; line-height: 1.3; }
a.sp-row:hover .sp-row-ref { color: var(--gold-bright); }
.sp-row-text {
    font-family: var(--font-scripture); font-size: .95rem; line-height: 1.5; color: var(--text-dim);
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.sp-row-text:empty { display: none; }
.sp-more { margin-top: var(--s2); margin-left: calc(-1 * var(--s3)); }
.sp-note { margin-top: var(--s3); font-size: var(--fs-xs); color: var(--text-faint); }
.sp-note a { text-decoration: underline; text-underline-offset: 2px; }

/* A reference link anywhere (Study.refLink). */
.study-ref {
    color: var(--text); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px;
    text-decoration-color: color-mix(in srgb, var(--gold) 55%, transparent);
    transition: color var(--t-fast) var(--ease), text-decoration-color var(--t-fast) var(--ease);
}
.study-ref:hover { color: var(--gold-bright); text-decoration-color: var(--gold); }
.study-ref.is-plain { text-decoration: none; }

/* ── In the reader ──────────────────────────────────────────────────── */
#view-read .verse.is-studied {
    background: color-mix(in srgb, var(--gold) 16%, transparent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 16%, transparent);
}
.study-rail-slot { display: contents; }

.study-readlink {
    display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap;
    width: fit-content; max-width: 100%; min-height: 44px; margin: calc(-1 * var(--s5)) 0 var(--s7);
    padding: var(--s2) var(--s4); border: 1px solid var(--line); border-radius: var(--r-pill);
    font-size: var(--fs-sm); color: var(--text-dim);
    transition: border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.study-readlink > .icon:first-child { color: var(--gold); }
.study-readlink-title { font-weight: 600; color: var(--text); }
.study-readlink:hover { border-color: var(--gold); background: var(--bg-1); color: var(--text); }
.study-readlink:hover .study-readlink-title { color: var(--gold-bright); }

/* ── The hub ────────────────────────────────────────────────────────── */
.study-page { max-width: 1120px; }
.study-hero { display: grid; gap: var(--s4); max-width: 46rem; margin-bottom: var(--s7); }
.study-hero h1 { font-size: clamp(2.6rem, 1.6rem + 4vw, 4.6rem); line-height: 1; letter-spacing: -.03em; }

a.study-verse {
    display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: var(--s6); align-items: center;
    padding: var(--s6);
    background: linear-gradient(120deg, var(--gold-soft), transparent 70%), var(--bg-1);
    border-color: var(--line-strong);
}
.study-verse-copy { display: grid; gap: var(--s3); justify-items: start; }
.study-verse-title { font-size: var(--fs-h2); line-height: 1.1; }
.study-verse-text { color: var(--text-dim); max-width: 46ch; text-wrap: pretty; }
.study-verse-text strong { color: var(--text); font-weight: 600; }
.study-verse-go { display: inline-flex; align-items: center; gap: var(--s2); margin-top: var(--s2); font-size: var(--fs-sm); font-weight: 600; color: var(--gold-bright); }
.study-verse-mock {
    display: grid; gap: 10px; padding: var(--s5);
    border: 1px solid var(--line); border-left: 2px solid var(--gold); border-radius: var(--r-md);
    background: var(--bg-2); box-shadow: var(--shadow);
    transform: rotate(1.2deg); transition: transform var(--t-slow) var(--ease-out);
}
a.study-verse:hover .study-verse-mock { transform: rotate(0deg) translateY(-2px); }
.study-verse-ref { font-family: var(--font-display); font-size: 1.4rem; line-height: 1.1; }
.study-verse-line { height: 9px; border-radius: 5px; background: var(--bg-3); }
.study-verse-line.is-short { width: 62%; }
.study-verse-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--s2); }
.study-verse-chips > span {
    padding: 4px 10px; border: 1px solid var(--line-strong); border-radius: var(--r-pill);
    font-size: var(--fs-xs); color: var(--text-dim);
}

.study-tools { margin-top: var(--s8); }
.study-tools-title { padding-bottom: var(--s4); margin-bottom: var(--s5); border-bottom: 1px solid var(--line-strong); }
.study-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr)); gap: var(--s4); }
.study-grid > li { display: flex; }
a.study-card {
    --tone-c: var(--tone, var(--gold));
    display: flex; flex-direction: column; gap: var(--s2); width: 100%;
    background: radial-gradient(140% 120px at 0% 0%, color-mix(in srgb, var(--tone-c) 10%, transparent), transparent 70%), var(--bg-1);
}
.study-card-icon {
    display: grid; place-items: center; width: 44px; height: 44px; margin-bottom: var(--s2);
    border-radius: var(--r-md); color: var(--tone-c);
    background: color-mix(in srgb, var(--tone-c) 14%, transparent);
}
.study-card-title { font-size: 1.5rem; line-height: 1.15; }
.study-card-text { flex: 1; color: var(--text-dim); font-size: var(--fs-sm); text-wrap: pretty; }
.study-card-go {
    display: inline-flex; align-items: center; gap: var(--s1); margin-top: var(--s2);
    font-size: var(--fs-xs); font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--tone-c);
}
.study-card:hover .study-card-go .icon { transform: translateX(3px); }
.study-card-go .icon { transition: transform var(--t-med) var(--ease-out); }
.study-foot { margin-top: var(--s7); color: var(--text-dim); }
.study-foot a { color: var(--text); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--gold); }
.study-foot a:hover { color: var(--gold-bright); }

/* ── Phones: bottom sheet, one-column hub ───────────────────────────── */
@media (max-width: 760px) {
    .study-panel {
        --pad: var(--s5);
        top: calc(var(--topbar-h) + 8px); left: 0; right: 0; bottom: 0; z-index: 34;
        width: auto;
        border-left: 0; border-top: 1px solid var(--line-strong);
        border-radius: var(--r-lg) var(--r-lg) 0 0;
        transform: translateY(var(--y, 100%));
    }
    .study-panel.is-open { transform: translateY(var(--y, 0)); }
    .study-panel.is-dragging { transition: none; }
    .sp-bar { padding-top: 10px; touch-action: none; cursor: grab; }
    .study-panel.is-dragging .sp-bar { cursor: grabbing; }
    .sp-handle {
        display: block; position: absolute; top: 8px; left: 50%;
        width: 40px; height: 5px; border-radius: var(--r-pill);
        background: var(--line-strong);
        transform: translateX(-50%);
    }
    .sp-body { padding-top: var(--s4); padding-bottom: calc(var(--s8) + env(safe-area-inset-bottom, 0px)); }
    .sp-title { font-size: 1.9rem; }

    .study-hero h1 { font-size: clamp(2.4rem, 12vw, 3.4rem); }
    a.study-verse { grid-template-columns: 1fr; padding: var(--s5); gap: var(--s5); }
    .study-verse-mock { display: none; }
    .study-tools { margin-top: var(--s7); }
    .study-readlink { margin-top: calc(-1 * var(--s4)); border-radius: var(--r-lg); }
}
