:root {
    /* Bible Study color mapping to brand colors */
    --study-ink: var(--brand-black, #010000);
    --study-muted: var(--brand-light-gray, #9398a7);
    --study-surface: #ffffff;
    --study-border: #e2e8f0;
    --study-accent: var(--brand-navy, #2b3a7f);
    --study-accent-strong: var(--brand-navy-dark, #1e2b69);
    --study-accent-soft: rgba(43, 58, 127, 0.08);
    --study-highlight: var(--brand-orange, #FA8334);
    --study-shadow: 0 18px 45px rgba(15, 23, 42, 0.1);
    --study-radius-lg: 22px;
    --study-radius-md: 16px;
    /* Typography using brand fonts */
    --study-font-body: var(--font-sans, 'Inter', sans-serif);
    --study-font-display: var(--font-serif, 'Libre Baskerville', serif);
    --study-font-serif: var(--font-serif, 'Libre Baskerville', serif);
}

.site-header {
    background-color: var(--brand-header, #11192c);
}

.nav-secondary-row {
    background-color: var(--brand-header-secondary-bg, #1e2b69);
}

.site-header .nav-primary-link,
.site-header .user-info-text {
    color: #ffffff;
}

.site-header .nav-secondary-link {
    color: var(--brand-header-secondary-text, #e2e8f0);
}

/* Preserve the yellow "Let the word light your way" treatment on Bible Study pages */
.site-header .nav-secondary-link.glow-text {
    color: #fcd34d !important;
    text-shadow:
        0 0 8px rgba(252, 211, 77, 0.35),
        0 0 18px rgba(252, 211, 77, 0.22);
}

.study-shell {
    padding-top: 2.5rem;
    padding-bottom: 3rem;
    color: var(--study-ink);
    font-family: var(--study-font-body);
}

/* Preview conversion banner: keep CTA visible while scrolling */
.study-preview-banner {
    position: sticky;
    top: calc(env(safe-area-inset-top, 0px) + 0.75rem);
    z-index: 55;
}

/* Keep sizing predictable in the study UI */
.study-shell,
.study-shell * {
    box-sizing: border-box;
}

.study-shell.is-chat-active {
    padding-bottom: 8rem;
}

.study-hero {
    position: relative;
    overflow: hidden;
    border-radius: var(--study-radius-lg);
    background: linear-gradient(130deg, var(--brand-navy) 0%, var(--brand-dark, #11192c) 65%);
    color: #ffffff;
    padding: 3rem 3.5rem;
    box-shadow: var(--study-shadow);
    text-align: center;
}

.study-hero::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at top right, rgba(250, 204, 21, 0.12), transparent 60%);
    opacity: 0.9;
}

.study-hero > * {
    position: relative;
    z-index: 1;
}

.study-kicker {
    text-transform: uppercase;
    letter-spacing: 0.22em;
    font-size: 0.85rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 0.5rem;
}

.study-title {
    font-family: var(--study-font-display);
    font-size: clamp(2.25rem, 4vw, 3.5rem);
    margin: 0.5rem 0 1rem;
    letter-spacing: -0.01em;
    line-height: 1.1;
}

.study-shell h1,
.study-shell h2,
.study-shell h3,
.study-shell h4,
.study-shell h5,
.study-shell h6 {
    font-family: var(--study-font-display);
    color: var(--brand-navy);
}

.study-hero .study-title,
.study-hero h1,
.study-hero h2,
.study-hero h3,
.study-hero h4 {
    color: #ffffff;
}

.study-subtitle {
    font-size: 1.15rem;
    color: var(--study-muted);
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

.text-white { color: #ffffff !important; }

.study-hero .study-subtitle {
    color: rgba(255, 255, 255, 0.9);
    font-style: italic;
    font-family: var(--study-font-display);
}

.study-grid {
    display: grid;
    gap: 1.5rem;
}

.study-grid.cols-3 {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.study-grid.cols-2 {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.study-card {
    background: var(--study-surface);
    border-radius: var(--study-radius-md);
    border: 1px solid var(--study-border);
    padding: 1.5rem;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.06);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.study-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.12);
}

.study-card h3 {
    font-family: var(--study-font-display);
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
}

.study-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 1rem;
    border-radius: 999px;
    background: var(--brand-navy);
    color: #ffffff;
    font-size: 0.8rem;
    font-weight: 700;
    box-shadow: 0 2px 4px rgba(43, 58, 127, 0.2);
}

.study-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
    color: var(--study-muted);
}

.study-cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.85rem 2rem;
    border-radius: 0.75rem;
    background: var(--brand-navy);
    color: #ffffff;
    font-weight: 700;
    font-size: 1.1rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    box-shadow: var(--shadow-md, 0 4px 6px -1px rgba(0, 0, 0, 0.1));
    cursor: pointer;
}

.study-cta:hover {
    background: var(--brand-navy-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg, 0 10px 15px -3px rgba(0, 0, 0, 0.1));
}

.study-cta:active {
    transform: translateY(0);
}

.study-link {
    color: var(--brand-navy);
    font-weight: 700;
    text-decoration: none;
    transition: color 0.2s ease;
}

.study-link:hover {
    color: var(--brand-navy-light);
    text-decoration: none;
}

/* Pagination hover: subtle color shift, no underline */
.study-pagination .study-link:hover {
    text-decoration: none;
    opacity: 0.9;
}

.study-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    background: var(--study-surface);
    border-radius: var(--study-radius-md);
    border: 1px solid var(--study-border);
    padding: 1rem;
}

.study-filter label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--study-muted);
}

.study-filter select,
.study-filter input[type="text"] {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border-radius: 10px;
    border: 1px solid var(--study-border);
    background: var(--study-surface);
    font-family: var(--study-font-body);
    transition: var(--transition-fast, all 0.2s ease);
}

.study-filter select:focus,
.study-filter input[type="text"]:focus {
    outline: none;
    border-color: var(--brand-navy);
    box-shadow: 0 0 0 3px rgba(43, 58, 127, 0.1);
}

.study-session-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    align-items: start;
}

@media (min-width: 1024px) {
    .study-session-layout {
        /* Always two columns on desktop: main content + sticky chat */
        /* 66% verses, 33% side content */
        grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    }
}

.study-pane {
    background: var(--study-surface);
    border-radius: var(--study-radius-md);
    border: 1px solid var(--study-border);
    padding: 2.25rem;
    min-height: 280px;
    box-shadow: 0 4px 25px rgba(15, 23, 42, 0.05);
    height: 100%;
}

.study-commentary-full p {
    margin: 0 0 1.1rem 0 !important;
}

.study-commentary-full p:last-child {
    margin-bottom: 0 !important;
}

/* Some commentary sources use single newlines (rendered as <br>) for paragraph breaks.
   Make <br><br> produce real vertical separation. */
.study-commentary-full br {
    display: block;
    content: "";
    height: 0.35rem;
}

.study-commentary-full br + br {
    height: 1.1rem;
}

/* Small hover tooltip */
.study-tooltip {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.study-tooltip-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.15rem;
    height: 1.15rem;
    border-radius: 999px;
    border: 1px solid rgba(100, 116, 139, 0.35);
    color: rgba(71, 85, 105, 0.9);
    background: rgba(255, 255, 255, 0.8);
}

.study-tooltip-bubble {
    position: absolute;
    left: 0;
    top: calc(100% + 0.5rem);
    width: min(320px, 70vw);
    padding: 0.65rem 0.8rem;
    border-radius: 0.75rem;
    border: 1px solid rgba(15, 23, 42, 0.12);
    background: #ffffff;
    color: rgba(15, 23, 42, 0.85);
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.12);
    font-size: 0.85rem;
    line-height: 1.35;
    text-transform: none;
    letter-spacing: normal;
    z-index: 50;
    display: none;
}

.study-tooltip:hover .study-tooltip-bubble,
.study-tooltip:focus-within .study-tooltip-bubble {
    display: block;
}

.study-card-public {
    background: #ffffff;
    border-radius: var(--study-radius-md);
    border: 1px solid var(--study-border);
    padding: 1.75rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
}

.study-grid .study-card-public {
    height: 100%;
}

.study-resume-card {
    background: var(--study-accent-soft);
    border: 1px solid var(--study-border);
    padding: 2rem;
    border-radius: var(--study-radius-md);
}

.study-header-group {
    margin-bottom: 1.5rem;
}

.study-kicker-dark {
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--brand-navy);
    opacity: 0.6;
    margin-bottom: 0.5rem;
}

.study-section-title {
    font-family: var(--study-font-display);
    font-size: 1.75rem;
    color: var(--brand-navy);
    margin-bottom: 1.5rem;
}

.study-column {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.study-breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--study-muted);
    margin-bottom: 1.25rem;
}

.study-breadcrumbs a {
    color: var(--brand-navy);
    font-weight: 600;
}

.study-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 1.5rem 0;
    padding: 1rem 0;
    border-top: 1px solid var(--study-border);
    border-bottom: 1px solid var(--study-border);
    font-size: 0.95rem;
}

.study-muted {
    color: var(--study-muted);
}

.study-verse-line {
    margin-bottom: 0.5rem;
    padding: 0.6rem 0.8rem;
    border-radius: 12px;
    cursor: pointer;
    border: 1px solid transparent;
    position: relative;
    transition: all 0.2s ease;
}

.study-verse-line:hover {
    background: rgba(43, 58, 127, 0.04);
}

.study-verse-line strong {
    color: var(--brand-navy);
    opacity: 0.7;
    margin-right: 0.5rem;
}

.study-verse-line.has-note {
    box-shadow: inset 4px 0 0 var(--brand-navy);
}

/* Scope-specific note indicators */
#study-passage-grid[data-notes-scope="church"] .study-verse-line.has-note {
    box-shadow: inset 4px 0 0 #fa8334;
}

#study-passage-grid[data-notes-scope="denomination"] .study-verse-line.has-note {
    box-shadow: inset 4px 0 0 #fcd34d;
}

/* Saved scope: green */
#study-passage-grid[data-notes-scope="saved"] .study-verse-line.has-note {
    box-shadow: inset 4px 0 0 #22c55e;
}

.study-verse-line.is-in-range {
    background: rgba(43, 58, 127, 0.08);
}

.study-verse-line.is-selected {
    border-color: var(--brand-navy);
    background: rgba(43, 58, 127, 0.06);
}

#study-passage-grid[data-notes-scope="church"] .study-verse-line.is-selected {
    border-color: #fa8334;
}

#study-passage-grid[data-notes-scope="denomination"] .study-verse-line.is-selected {
    border-color: #fcd34d;
}

#study-passage-grid[data-notes-scope="saved"] .study-verse-line.is-selected {
    border-color: #22c55e;
}

.study-highlight-focus {
    background: rgba(250, 204, 21, 0.15);
}

.study-highlight-word {
    background: rgba(59, 130, 246, 0.12);
}

.study-highlight-theme {
    background: rgba(16, 185, 129, 0.12);
}

.study-highlight-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    font-size: 0.85rem;
    color: var(--study-muted);
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: #f8fafc;
    border-radius: 12px;
}

.study-ai-marker {
    color: var(--brand-navy);
    background: rgba(43, 58, 127, 0.08);
    border-radius: 999px;
    padding: 0.25rem;
    font-size: 1rem;
    margin-top: 0.2rem;
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.study-ai-marker.is-avatar {
    color: transparent;
    background-color: rgba(43, 58, 127, 0.12);
}

.study-highlight-clear {
    margin-left: auto;
    border: none;
    background: transparent;
    color: var(--brand-navy);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    transition: background 0.2s ease, color 0.2s ease;
}

.study-highlight-clear:hover {
    background: rgba(43, 58, 127, 0.08);
    color: var(--brand-navy-light);
}

.study-highlight-clear .material-icons {
    font-size: 1rem;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.legend-swatch {
    width: 18px;
    height: 18px;
    border-radius: 6px;
    display: inline-block;
}

.legend-swatch.focus {
    background: rgba(250, 204, 21, 0.35);
}

.legend-swatch.word {
    background: rgba(59, 130, 246, 0.3);
}

.legend-swatch.theme {
    background: rgba(16, 185, 129, 0.3);
}

.study-pane h3 {
    font-family: var(--study-font-display);
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--brand-navy);
}

.study-passage {
    padding: 1.5rem 2rem;
    border-radius: 18px;
    background: var(--brand-light-bg, #f8fafc);
    border: 1px solid var(--study-border);
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm, 0 2px 8px rgba(0, 0, 0, 0.02));
}

.study-notes-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.study-notes-filter {
    margin: 0;
}

.study-segmented {
    display: inline-flex;
    gap: 0.25rem;
    padding: 0.25rem;
    border-radius: 999px;
    border: 1px solid var(--study-border);
    background: #f8fafc;
    align-items: center;
}

.study-segment {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--study-muted);
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 0 !important;
}

.study-segment input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.study-segment span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 2.25rem;
    padding: 0 1.1rem;
    border-radius: 999px;
}

.study-segment.is-disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.study-segment input:checked + span {
    background: var(--brand-navy);
    color: #ffffff;
    box-shadow: 0 2px 4px rgba(43, 58, 127, 0.2);
}

.study-passage-grid {
    display: grid;
    gap: 0.75rem 1.25rem;
}

.study-verse-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem 1.25rem;
    align-items: start;
    border-bottom: 1px solid #f1f5f9;
    padding-bottom: 0.75rem;
}

.verse-num {
    width: 2.25rem;
    flex: 0 0 2.25rem;
    text-align: right;
    font-weight: 800;
    color: var(--study-muted);
    line-height: 1.4;
    padding-top: 0.1rem;
    font-variant-numeric: tabular-nums;
    position: relative;
}

.study-verse-note-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.05rem;
    height: 1.05rem;
    padding: 0 0.3rem;
    margin-left: 0;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 800;
    line-height: 1;
    border: 1px solid currentColor;
    color: var(--brand-navy);
    background: rgba(43, 58, 127, 0.08);
    font-variant-numeric: tabular-nums;
}

/* When rendered inside the verse card, center it vertically between the left stripe and verse number */
.study-verse-note-count--center {
    position: absolute;
    left: 0.55rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 3;
}

#study-passage-grid[data-notes-scope="church"] .study-verse-note-count {
    color: #fa8334;
    background: rgba(250, 131, 52, 0.12);
}

#study-passage-grid[data-notes-scope="denomination"] .study-verse-note-count {
    color: #fcd34d;
    background: rgba(252, 211, 77, 0.16);
}

#study-passage-grid[data-notes-scope="saved"] .study-verse-note-count {
    color: #22c55e;
    background: rgba(34, 197, 94, 0.14);
}

/* Application card (avoid Tailwind v3-only slate classes) */
.study-application-card {
    background: linear-gradient(135deg, rgba(17, 25, 44, 0.96) 0%, rgba(43, 58, 127, 0.92) 100%);
    color: #ffffff;
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: 0 16px 40px rgba(17, 25, 44, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.study-application-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--brand-orange) !important;
    margin: 0 0 0.75rem 0;
}

.study-application-help {
    font-size: 0.95rem;
    line-height: 1.55;
    color: rgba(255, 255, 255, 0.86);
    margin-bottom: 0.9rem;
}

.study-application-form {
    margin-top: 0.75rem;
}

.study-application-textarea {
    width: 100%;
    border-radius: 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    padding: 0.85rem 0.9rem;
    font-family: var(--study-font-body);
    line-height: 1.5;
    resize: vertical;
    box-sizing: border-box;
}

.study-application-textarea::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.study-application-textarea:focus {
    outline: none;
    border-color: rgba(250, 131, 52, 0.6);
    box-shadow: 0 0 0 4px rgba(250, 131, 52, 0.18);
}

.study-application-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.75rem;
}

.study-application-actions.is-preview {
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
}

.study-application-preview-note {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.25rem;
    color: rgba(255, 255, 255, 0.82);
}

.study-application-preview-cta {
    width: 100%;
    text-align: center;
    white-space: nowrap;
    padding: 0.95rem 1rem;
    font-size: 0.95rem;
}

.study-application-card .study-cta {
    background: rgba(255, 255, 255, 0.92);
    color: rgba(17, 25, 44, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 10px 22px rgba(17, 25, 44, 0.22);
}

.study-application-card .study-cta:hover {
    background: #ffffff;
    color: rgba(17, 25, 44, 0.98);
    transform: translateY(-1px);
}

/* Hide empty notes slots only on mobile (desktop uses the slot as a sliding drawer). */
@media (max-width: 767px) {
    /* Prevent any accidental horizontal overflow (makes content feel wider than header) */
    .study-shell,
    .study-session-page,
    .study-session-layout,
    .study-pane {
        max-width: 100%;
        overflow-x: hidden;
    }

    /* Notes scope selector: never cut off on mobile */
    .study-notes-toolbar {
        align-items: flex-start;
    }

    .study-notes-filter {
        width: 100%;
    }

    .study-segmented {
        width: 100%;
        max-width: 100%;
        display: flex;
        flex-wrap: wrap;          /* wrap instead of horizontal clipping */
        overflow-x: visible;      /* no scroll needed */
        gap: 0.35rem;
        padding: 0.35rem;
    }

    .study-segment {
        flex: 1 1 calc(50% - 0.35rem);
        justify-content: center;
    }

    .study-segment span {
        width: 100%;
        height: 2.05rem;
        padding: 0 0.6rem;
        white-space: nowrap;
        font-size: 0.82rem;
    }

    /* Meta row (Joshua 1 / Verses / Page...) can overflow on small screens */
    .study-meta {
        flex-wrap: wrap;
    }

    .study-meta .ml-auto {
        margin-left: 0 !important;
        width: 100%;
        text-align: left;
    }
    .study-verse-notes:empty {
        display: none;
    }
}

/* ==========================================================================
   Notes drawer (desktop): click verse -> note editor slides over the verse box
   (same height/shape as the verse) from the right with a white background.
   ========================================================================== */

@media (min-width: 768px) {
    .study-verse-line {
        position: relative;
        overflow: hidden;
        border-radius: 0.75rem;
        transition: min-height 220ms ease;
    }

    /* When a verse drawer is opened, give it a consistent, usable panel height. */
    .study-verse-row.is-drawer-open .study-verse-line {
        min-height: 310px;
    }

    /* The drawer is clipped to the verse box */
    .study-verse-line .study-verse-notes {
        position: absolute;
        top: 0;
        bottom: 0;
        right: 0;
        height: auto;
        width: 100%;
        background: #ffffff;
        border: 1px solid rgba(15, 23, 42, 0.10);
        border-radius: inherit;
        transform: translateX(102%);
        transition: transform 1200ms ease;
        z-index: 4;
        pointer-events: none;
        overflow: hidden; /* inner thread/editor handles scroll */
        box-sizing: border-box;
        padding: 0.9rem 1rem;
        display: flex;
        flex-direction: column;
        min-height: 250px; /* safety: ensure drawer doesn't collapse if parent sizing changes */
    }

    .study-verse-row.is-drawer-open .study-verse-line .study-verse-notes {
        transform: translateX(0);
        pointer-events: auto;
        /* Keep the panel “inside” the verse shape (no outside shadow bleed) */
        box-shadow: none;
    }

    /* While closing, keep the drawer intercepting clicks so it doesn't "click-through"
       and accidentally re-open while the close timer is running. */
    .study-verse-row.is-drawer-closing .study-verse-line .study-verse-notes {
        pointer-events: auto;
    }

    /* Keep copy button clickable when drawer is closed */
    .study-verse-row:not(.is-drawer-open) .study-verse-copy {
        position: relative;
        z-index: 5;
    }

    /* Make the embedded note editor feel like a panel (white) */
    .study-verse-line .study-verse-notes .study-note-editor {
        background: #ffffff;
        border: 1px solid rgba(15, 23, 42, 0.10);
        box-shadow: none;
        margin: 0;
    }

    /* Notes display should scroll inside the verse drawer (handles long notes + many notes) */
    .study-verse-line .study-verse-notes .study-note-thread {
        height: 100%;
        max-height: 100%;
        overflow-y: auto;
        overflow-x: hidden;
        margin: 0;
        padding: 0;
        display: block;
    }

    /* Editor can also scroll if content is tall */
    .study-verse-line .study-verse-notes .study-note-editor {
        height: 100%;
        max-height: 100%;
        overflow-y: auto;
        overflow-x: hidden;
        box-sizing: border-box;
    }

    .study-verse-line .study-verse-notes .study-note-item {
        padding: 0 !important;
        margin: 0 !important;
        border: 0 !important;
        border-radius: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
    }

    /* Ensure long note text wraps instead of overflowing */
    .study-verse-line .study-verse-notes p,
    .study-verse-line .study-verse-notes .study-note-item p {
        white-space: normal;
        overflow-wrap: anywhere;
        word-break: break-word;
    }
}

/* Note: We used to render notes in a second column beside the verse.
   Notes are now a drawer overlay inside `.study-verse-line`, so keep the row
   single-column to avoid “dead space”. */

.study-verse-row:last-child {
    border-bottom: none;
}

.study-verse-line {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
}

.study-verse-line p {
    font-family: var(--study-font-serif);
    line-height: 1.8;
    font-size: 1.15rem;
    flex: 1;
    color: var(--study-ink);
}

.study-verse-copy {
    border: none;
    background: transparent;
    color: var(--study-muted);
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.study-verse-copy .material-icons {
    font-size: 1.1rem;
}

.study-verse-copy:hover {
    color: var(--brand-navy);
    background: #e2e8f0;
}

.study-verse-copy.is-copied {
    color: var(--brand-navy);
    background: #dbeafe;
}

.study-verse-notes {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.study-note-thread {
    display: grid;
    gap: 0.5rem;
}

.study-note-editor-home {
    display: none;
}

.study-note-editor {
    width: 100%;
    background: #f8fafc;
    padding: 0.9rem;
    border-radius: 14px;
    border: 1px solid var(--study-border);
    margin: 0.6rem 0;
}

.study-note-editor textarea {
    width: 100%;
    min-height: 50px !important;
    border-radius: 12px;
    border: 1px solid var(--study-border);
    padding: 0.85rem;
    font-family: var(--study-font-body);
    font-size: 0.95rem;
    line-height: 1.5;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
    transition: var(--transition-fast, all 0.2s ease);
}

.study-note-editor textarea:focus {
    outline: none;
    border-color: var(--brand-navy);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02), 0 0 0 3px rgba(43, 58, 127, 0.1);
}

.study-note-target-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
    flex-wrap: wrap;
}

.study-note-target {
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    background: #e2e8f0;
    color: #334155;
    font-weight: 700;
    font-size: 0.78rem;
    box-shadow: none;
}

.study-clear-selection {
    font-size: 0.85rem;
    color: var(--study-muted);
    font-weight: 500;
    padding: 0.1rem 0.3rem;
    border-radius: 999px;
}

.study-note-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    font-size: 0.8rem;
    color: var(--study-muted);
    margin: 0.5rem 0 0.35rem;
}

.study-note-author {
    font-weight: 700;
    color: var(--brand-navy);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.study-note-visibility {
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    background: #f1f5f9;
    color: var(--study-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
}

.study-note-action-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-top: 0.75rem;
}

.study-note-action {
    border: 1px solid var(--study-border);
    background: #ffffff;
    color: var(--study-muted);
    font-weight: 600;
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    line-height: 1;
}

.study-note-action:hover {
    border-color: var(--brand-navy);
    color: var(--brand-navy);
    background: #f8fafc;
}

.study-note-action.is-active {
    background: var(--brand-navy);
    border-color: var(--brand-navy);
    color: #ffffff;
}

.study-note-action.is-flagged {
    border-color: #ef4444;
    color: #ef4444;
}

.study-note-action.is-saved {
    border-color: #22c55e;
    color: #16a34a;
}

.study-note-action.is-danger {
    border-color: #ef4444;
    color: #ef4444;
}

.study-note-action.is-danger:hover {
    background: #fef2f2;
}

.study-note-visibility-form {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed #e2e8f0;
}

.study-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--study-muted);
}

.study-toggle input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.study-toggle-track {
    width: 44px;
    height: 24px;
    border-radius: 999px;
    background: var(--study-border);
    position: relative;
    transition: all 0.3s ease;
}

.study-toggle-track::after {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ffffff;
    top: 3px;
    left: 3px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.study-toggle input:checked + .study-toggle-track {
    background: var(--brand-navy);
}

.study-toggle input:checked + .study-toggle-track::after {
    transform: translateX(20px);
}

.study-toggle-label {
    font-weight: 600;
}

.study-toggle input:checked ~ .study-toggle-label {
    color: var(--brand-navy);
}

.study-general-notes {
    margin-bottom: 2rem;
    display: grid;
    gap: 1rem;
}

.study-note-item {
    padding: 1.25rem;
    border-radius: 14px;
    border: 1px solid var(--study-border);
    background: #ffffff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.02);
    transition: all 0.2s ease;
}

.study-note-item:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.study-session-actions {
    display: flex;
    justify-content: center;
    margin: 2.5rem 0;
}

.study-session-page {
    /* Make room for the fixed bottom chat dock */
    padding-bottom: 7.5rem;
}

.study-chat-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid rgba(15, 23, 42, 0.12);
    box-shadow: 0 -10px 28px rgba(15, 23, 42, 0.10);
    padding: 0.75rem 0;
}

.study-chat-inner {
    width: 100%;
}

.study-pane.study-chat-dock {
    min-height: 0;
    background: var(--study-surface);
    border: 1px solid var(--study-border);
    padding: 1.25rem;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ==========================================================================
   Study chat composer: compact, single-row (persona + input + share + send)
   ========================================================================== */

.study-chat-dock .tab-pane.is-study-context .grid {
    gap: 0 !important;
}

/* Ensure the study chat pane is visible even if global tab styles hide `.tab-pane` by default */
.study-chat-dock .tab-pane.is-study-context {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.study-chat-dock .tab-pane.is-study-context .card {
    border: none;
    box-shadow: none;
    background: transparent;
}

.study-chat-dock .tab-pane.is-study-context .card-body {
    padding: 0 !important;
}

/* Keep hidden persona radios in DOM for JS, but don't show the grid in study chat */
.study-chat-dock .tab-pane.is-study-context .persona-selection-hidden {
    display: none !important;
}

/* Hide secondary UI in study chat dock (keep it minimal) */
.study-chat-dock .tab-pane.is-study-context .credit-notice,
.study-chat-dock .tab-pane.is-study-context .question-header,
.study-chat-dock .tab-pane.is-study-context .voice-button {
    display: none !important;
}

/* Allow advisor popover to escape the composer (avoid clipping in the bottom dock) */
.study-chat-dock .tab-pane.is-study-context .card,
.study-chat-dock .tab-pane.is-study-context .card-body {
    overflow: visible !important;
}

.study-chat-dock .tab-pane.is-study-context .study-persona-popover {
    z-index: 120 !important;
}

/* Expanded messages panel (appears above the composer when chat is active) */
.study-chat-dock .tab-pane.is-study-context #dashboard-chat-container.chat-container:not(.hidden) {
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.10);
    border-radius: 16px;
    overflow: hidden;
    max-height: 42vh;
    margin-bottom: 0.6rem;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

.study-chat-dock .tab-pane.is-study-context #dashboard-chat-container.is-collapsed {
    display: none !important;
}

.study-chat-dock .tab-pane.is-study-context #dashboard-chat-container .chat-header {
    display: none !important;
}

.study-chat-dock .tab-pane.is-study-context #dashboard-chat-container .chat-messages {
    padding: 1rem;
    overflow-y: auto;
}

.study-chat-dock .tab-pane.is-study-context #dashboard-chat-status {
    padding: 0 1rem 0.75rem;
}

/* Remove extra container chrome so composer is one-line tall */
.study-chat-dock .tab-pane.is-study-context .question-input-container {
    background: transparent !important;
    padding: 0 !important;
    margin-top: 0 !important;
}

.study-chat-dock .tab-pane.is-study-context .question-input-wrapper {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    border-radius: 999px;
    border: 1px solid var(--study-border);
    background: #ffffff;
    padding: 0.35rem 0.5rem;
    box-shadow: 0 10px 28px rgb(15 23 42 / 33%);
}

.study-chat-dock .tab-pane.is-study-context .study-persona-compact {
    margin-right: 0;
}

.study-chat-dock .tab-pane.is-study-context .study-persona-current {
    border-radius: 999px;
    padding: 0.4rem 0.6rem;
    background: #f8fafc;
    border: 1px solid var(--study-border);
    box-shadow: none;
}

.study-chat-dock .tab-pane.is-study-context .textarea-inner-wrapper {
    flex: 1;
    min-width: 0;
}

.study-chat-dock .tab-pane.is-study-context .question-textarea {
    padding: 0.55rem 0.6rem !important;
    min-height: 44px;
    max-height: 140px;
    line-height: 1.35;
    font-family: var(--study-font-body);
    overflow-y: auto;
}

/* Mobile chat composer layout: textarea on top, persona + buttons row underneath */
@media (max-width: 767px) {
    .study-chat-dock .tab-pane.is-study-context .question-input-wrapper {
        flex-direction: row !important; /* override inline pane CSS (@media max-width:720px) */
        flex-wrap: wrap;
        border-radius: 16px;
        padding: 0.6rem 0.65rem;
        gap: 0.55rem;
        align-items: stretch;
    }

    .study-chat-dock .tab-pane.is-study-context .textarea-inner-wrapper {
        order: 1;
        flex: 0 0 100%;
        width: 100%;
    }

    .study-chat-dock .tab-pane.is-study-context .question-textarea {
        min-height: 88px; /* ~2x taller on mobile */
        max-height: 220px;
        padding: 0.65rem 0.75rem !important;
        border-radius: 14px;
        background: rgba(248, 250, 252, 0.8);
    }

    .study-chat-dock .tab-pane.is-study-context .study-persona-compact {
        order: 2;
        flex: 0 0 auto;
        align-self: center;
    }

    /* Make persona selector behave like an icon button on mobile */
    .study-chat-dock .tab-pane.is-study-context .study-persona-current {
        width: 42px;
        height: 42px;
        padding: 0;
        border-radius: 999px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0;
        overflow: hidden;
        box-shadow: none !important; /* remove desktop ring/shadows so it matches other buttons */
    }

    .study-chat-dock .tab-pane.is-study-context .study-persona-current[aria-expanded="true"],
    .study-chat-dock .tab-pane.is-study-context .study-persona-current.is-selected,
    .study-chat-dock .tab-pane.is-study-context .study-persona-compact.is-open .study-persona-current {
        box-shadow: none !important;
    }

    .study-chat-dock .tab-pane.is-study-context .study-persona-current .study-persona-name {
        display: none;
    }

    .study-chat-dock .tab-pane.is-study-context .study-persona-current .study-persona-avatar {
        width: 42px !important;
        height: 42px !important;
        border-radius: 999px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-weight: 800;
        box-shadow: none !important;
        background-size: cover;
        background-position: center;
    }

    /* Override inline styles that size/shadow the avatar */
    .study-chat-dock .tab-pane.is-study-context .study-persona-avatar {
        width: 42px !important;
        height: 42px !important;
        box-shadow: none !important;
        font-size: 0.85rem !important;
    }

    /* Ensure the compact selector itself doesn't wrap to its own line */
    .study-chat-dock .tab-pane.is-study-context .study-persona-compact {
        margin-right: 0 !important;
        align-self: center;
    }

    .study-chat-dock .tab-pane.is-study-context .input-buttons {
        order: 2; /* same row as persona */
        flex: 0 0 auto !important; /* don't take full row */
        width: auto !important;
        margin-left: auto; /* push buttons to the right */
        justify-content: flex-end;
        flex-wrap: nowrap;
        gap: 0.5rem;
        align-self: center;
    }
}

/* Put buttons to the right of the input (no overlay) */
.study-chat-dock .tab-pane.is-study-context .input-buttons {
    position: static !important;
    transform: none !important;
    right: auto !important;
    bottom: auto !important;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    z-index: auto;
}

.study-chat-dock .tab-pane.is-study-context .input-button {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border-radius: 999px;
}

.study-chat-dock .tab-pane.is-study-context .btn-share {
    background: #f1f5f9;
}

.study-chat-dock .tab-pane.is-study-context .chat-toggle-button {
    background: #f1f5f9;
    color: var(--brand-navy);
}

.study-chat-dock .tab-pane.is-study-context .chat-toggle-button .material-icons {
    margin: 0 !important;
}

.study-chat-dock .tab-pane.is-study-context .submit-button {
    background: var(--brand-navy);
}

.study-chat-dock .tab-pane.is-study-context .button-tooltip {
    display: none !important;
}

.study-chat-dock .card {
    display: flex;
    flex-direction: column;
    box-shadow: none;
    border: none;
    background: transparent;
    flex: 1;
    min-height: 0;
}

.study-chat-dock .card-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 0;
    padding: 0;
    background: transparent;
    overflow: hidden;
    flex: 1;
}

.study-chat-dock.is-chat-active {
    margin-bottom: 0;
}

.study-pane.study-chat-dock.is-chat-active {
    box-shadow: 0 14px 34px rgba(15, 23, 42, 0.12);
}

.study-chat-dock.is-chat-active .chat-container:not(.hidden) {
    flex: 1;
    min-height: 0;
    margin-bottom: 0.5rem;
    display: flex;
    flex-direction: column;
}

.study-chat-dock.is-chat-active .chat-messages {
    max-height: none;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.study-chat-dock.is-chat-active.is-chat-expanded .chat-container,
.study-chat-dock.is-chat-active.is-chat-expanded .chat-container:not(.hidden) {
    flex: 1;
}

.study-chat-dock.is-chat-active.is-chat-expanded .chat-messages {
    max-height: none;
    overflow-y: auto;
    flex: 1;
}

.study-chat-dock.is-chat-active .chat-container:not(.hidden) + .question-input-container {
    position: static;
    border-top: none;
}

.study-pane.study-chat-dock.is-chat-active {
    padding: 1.25rem;
}

.study-pane.study-chat-dock.is-preview-chat.is-chat-active {
    background: transparent;
    border: none;
}

.study-chat-dock.is-chat-active .card-body {
    padding: 0;
    gap: 0.75rem;
}

.study-chat-dock.is-chat-active .chat-container:not(.hidden) {
    margin-bottom: 0.5rem;
}

.study-chat-dock .question-input-container {
    position: static !important;
    bottom: auto !important;
    z-index: auto;
}

.study-chat-preview-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    padding: 2rem;
    z-index: 3;
}

.study-chat-preview-card {
    background: #ffffff;
    border-radius: 18px;
    padding: 2rem;
    text-align: center;
    max-width: 360px;
    width: 100%;
    box-shadow: 0 14px 28px rgba(15, 23, 42, 0.2);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.study-chat-preview-card .material-icons {
    font-size: 2rem;
    color: var(--brand-navy);
}

.study-chat-preview-card h3 {
    margin: 0;
    font-size: 1.35rem;
    color: var(--study-ink);
}

.study-chat-preview-card p {
    margin: 0;
    color: var(--study-muted);
    font-size: 0.95rem;
}

.study-chat-dock.is-preview-locked .study-chat-preview-overlay {
    opacity: 1;
    pointer-events: all;
}

.study-note-preview-hint {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(15, 118, 110, 0.08);
    border: 1px dashed rgba(15, 118, 110, 0.4);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    margin-bottom: 1.5rem;
    color: var(--study-muted);
    font-size: 0.9rem;
}

.study-note-preview-hint .material-icons {
    color: var(--brand-navy);
}

.study-note-disclaimer {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--study-muted);
}

.study-note-disclaimer a {
    color: var(--brand-navy);
    font-weight: 600;
}

.study-note-item.is-preview-note {
    border-style: dashed;
    background: rgba(59, 130, 246, 0.05);
}

.study-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.study-actions button {
    min-height: 44px;
}

.study-note-editor .study-cta {
    padding: 0.75rem 1.4rem;
    font-size: 0.95rem;
}

.study-card .tab-pane {
    display: block;
}

.study-soft-panel {
    background: #f8fafc;
    border-radius: 18px;
    padding: 1.75rem;
    border: 1px solid var(--study-border);
    margin-top: 2rem;
}

.study-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--brand-navy);
    background: #e2e8f0;
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Advisor & Chat Overrides for Study Context */
.study-pane .persona-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.study-pane .persona-heading label {
    font-family: var(--study-font-display);
    font-size: 1.25rem;
    color: var(--brand-navy);
}

.study-pane .persona-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
}

.study-pane .persona-card {
    border: 1px solid var(--study-border);
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.study-pane .persona-card:hover {
    border-color: var(--brand-navy-light);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.study-pane .persona-card.selected {
    border-color: var(--brand-navy);
    background-color: #f0f4ff;
    box-shadow: 0 4px 12px rgba(43, 58, 127, 0.1);
}

.study-pane .persona-name {
    font-family: var(--study-font-body);
    font-size: 1rem;
    font-weight: 700;
    color: var(--brand-navy);
}

.study-pane .persona-profession {
    font-size: 0.8rem;
    color: var(--study-muted);
}

.study-pane .chat-container {
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--study-border);
    margin-top: 1.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
}

.study-pane .chat-header {
    background: var(--brand-navy);
    padding: 1rem 1.25rem;
    color: #ffffff;
}

.study-pane .chat-messages {
    background: #ffffff;
    padding: 1.5rem;
    font-family: var(--study-font-body);
    font-size: 1rem;
    line-height: 1.6;
}

.study-pane .question-input-container {
    padding: 0.75rem;
    background: #f1f5f9;
    border-top: none;
    border-radius: 16px;
    margin-top: 0;
}

.study-pane .question-wrapper textarea {
    border-radius: 12px;
    border: none;
    background: transparent;
    padding: 0.75rem 1rem;
    font-family: var(--study-font-body);
}

.study-pane .question-wrapper {
    gap: 0.5rem;
}

.study-pane .question-input-wrapper {
    background: transparent;
    border: none;
    box-shadow: none;
}

.study-pane .question-input-wrapper:focus-within {
    border: none;
    box-shadow: none;
}

/* Mobile-first responsive design */
@media (max-width: 767px) {
    /* Mobile baseline typography (so you don't have to tune every component) */
    .study-shell {
        font-size: .9rem;
        line-height: 1.2rem;
    }

    .study-shell p,
    .study-shell li {
        font-size: inherit;
        line-height: inherit;
    }

    /* Normalize common Tailwind type sizes used throughout study templates */
    .study-shell .text-4xl { font-size: 1.6rem !important; line-height: 1.9rem !important; }
    .study-shell .text-3xl { font-size: 1.35rem !important; line-height: 1.6rem !important; }
    .study-shell .text-2xl { font-size: 1.15rem !important; line-height: 1.4rem !important; }
    .study-shell .text-xl  { font-size: 1rem !important; line-height: 1.25rem !important; }
    .study-shell .text-lg  { font-size: .95rem !important; line-height: 1.2rem !important; }
    .study-shell .text-base{ font-size: .9rem !important; line-height: 1.2rem !important; }
    .study-shell .text-sm  { font-size: .85rem !important; line-height: 1.15rem !important; }
    .study-shell .text-xs  { font-size: .78rem !important; line-height: 1.05rem !important; }

    /* Headings: reduce margins/padding so content is denser on mobile */
    .study-shell h1,
    .study-shell h2,
    .study-shell h3,
    .study-shell h4 {
        line-height: 1.25 !important;
        margin-top: 0 !important;
        margin-bottom: 0.6rem !important;
    }

    /* Tighten common heading wrappers */
    .study-shell .border-b {
        padding-bottom: 0.6rem !important;
        margin-bottom: 0.8rem !important;
    }

    /* Historical commentary: both the truncated summary and expanded content */
    .study-commentary-summary {
        font-size: .9rem !important;
        line-height: 1.2rem !important;
        margin-bottom: 0.6rem !important;
    }

    .study-commentary-full {
        font-size: .85rem !important;
        line-height: 1.15rem !important;
    }

    /* Extra space so fixed bottom chat doesn't cover content (plus iOS safe-area) */
    .study-session-page {
        padding-bottom: calc(9.5rem + env(safe-area-inset-bottom));
    }

    .study-chat-dock {
        padding-bottom: calc(0.65rem + env(safe-area-inset-bottom));
        padding-top: 0.65rem;
    }

    .study-shell {
        padding: 1.5rem 1rem 2rem;
    }

    .study-hero {
        padding: 2rem 1.5rem;
        border-radius: var(--study-radius-md);
    }

    .study-title {
        font-size: clamp(2rem, 5vw, 2.5rem);
        line-height: 1.15;
    }

    .study-subtitle {
        font-size: 1rem;
        margin-bottom: 1.5rem;
    }

    .study-session-layout {
        gap: 1.5rem;
        display: flex;
        flex-direction: column;
    }

    /* Two-column DOM: main content then chat */
    .study-session-layout .study-column:nth-child(1) { order: 1; }
    .study-session-layout .study-column:nth-child(2) { order: 2; }

    .study-verse-row {
        grid-template-columns: 1fr;
        gap: 0.25rem;
        padding-bottom: 0.45rem;
    }

    /* On mobile the notes slot is *not* absolutely positioned (desktop-only),
       so ensure it drops below the verse text instead of squeezing the row. */
    .study-verse-line {
        flex-wrap: wrap;
        width: 100%;
        min-width: 0;
    }

    .study-verse-line p {
        min-width: 0;
        overflow-wrap: anywhere;
        word-break: break-word;
        font-size: .9rem;
        line-height: 1.2rem;
        text-align: left;
    }

    .study-passage-grid {
        gap: 0.275rem;
    }

    .study-verse-line {
        gap: 0.55rem;
        padding: 0.65rem 0.7rem;
        border-radius: 14px;
    }

    .verse-num {
        width: 1.75rem;
        flex: 0 0 1.75rem;
        font-size: 0.95rem;
        padding-top: 0.05rem;
    }

    .study-verse-note-count--center {
        left: 0.35rem;
        transform: translateY(-50%) scale(0.92);
    }

    .study-verse-copy {
        padding: 0.35rem !important;
        width: 36px;
        height: 36px;
        border-radius: 12px;
        align-self: flex-start;
    }

    .study-verse-copy .material-icons {
        font-size: 18px !important;
    }

    /* Collapsed by default on mobile; only show when the verse is opened */
    .study-verse-line .study-verse-notes {
        display: none;
    }

    .study-verse-row.is-drawer-open .study-verse-line .study-verse-notes {
        display: block;
    }

    .study-verse-line .study-verse-notes {
        flex: 0 0 100%;
        width: 100%;
        order: 10;
        margin-top: 0.75rem;
        background: #ffffff;
        border: 1px solid rgba(15, 23, 42, 0.10);
        border-radius: 14px;
        padding: 0;
        box-sizing: border-box;
        max-width: 100%;
        max-height: 340px;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    /* Action rows: prevent `ml-auto` from pushing buttons off-screen on narrow widths */
    .study-verse-line .study-verse-notes .ml-auto {
        margin-left: 0 !important;
    }

    .study-verse-line .study-verse-notes .study-note-action-form {
        flex-wrap: wrap;
        max-width: 100%;
    }

    .study-verse-line .study-verse-notes .study-note-action {
        max-width: 100%;
    }

    /* Mobile note action buttons: consistent grid (prevents giant pills / awkward wrapping) */
    .study-note-actions {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        grid-auto-rows: 52px;
        gap: 0.6rem;
        align-items: stretch;
    }

    /* Treat forms as transparent wrappers so each button becomes a grid item.
       (Otherwise the whole form is one grid cell and buttons stack inside it.) */
    .study-note-actions form {
        display: contents !important;
        margin: 0 !important;
    }

    .study-note-actions .study-note-action {
        width: 100%;
        justify-content: center;
        height: 100%;
        padding: 0.55rem 0.55rem;
        border-radius: 14px;
        font-size: 0.85rem;
        box-shadow: 0 10px 22px rgba(15, 23, 42, 0.10);
    }

    .study-note-actions .study-note-action .material-icons {
        font-size: 18px !important;
    }

    /* On smaller phones, 2 columns is more readable/tappable */
    @media (max-width: 420px) {
        .study-note-actions {
            grid-template-columns: repeat(2, minmax(0, 1fr));
            grid-auto-rows: 54px;
        }
    }

    /* Keep the thread readable on mobile (we remove padding in the desktop drawer) */
    .study-verse-line .study-verse-notes .study-note-item {
        padding: 1rem !important;
        border-radius: 12px !important;
        border: 1px solid rgba(15, 23, 42, 0.06) !important;
        background: #ffffff !important;
        box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04) !important;
    }

    .study-verse-line .study-verse-notes .study-note-item + .study-note-item {
        margin-top: 0.75rem !important;
    }

    /* Mobile editor should also feel like a card inside the notes panel */
    .study-verse-line .study-verse-notes .study-note-editor {
        background: #ffffff;
        border: 1px solid rgba(15, 23, 42, 0.10);
        border-radius: 14px;
        box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
    }

    .study-pane {
        padding: 1.1rem 1rem;
    }

    .study-passage {
        padding: 0rem;
    }

    .study-grid.cols-3,
    .study-grid.cols-2 {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .study-filter {
        flex-direction: column;
        gap: 0.75rem;
    }
}

@media (min-width: 768px) {
    .site-header .md\:flex {
        display: flex;
    }

    .site-header .md\:block {
        display: block;
    }

    .site-header .hidden.md\:flex {
        display: flex !important;
    }

    .site-header .hidden.md\:block {
        display: block !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .study-card,
    .study-cta {
        transition: none;
    }

    .study-animate .study-passage,
    .study-animate .study-note-editor,
    .study-animate .study-pagination,
    .study-animate .study-highlight-legend,
    .study-animate .study-soft-panel,
    .study-animate .study-general-notes {
        animation: none;
    }
}

/* ==========================================================================
   Tailwind v3 compatibility shims (Bible Study templates use v3-style classes,
   while the app loads Tailwind v2 CDN CSS). These shims map the few
   v3-only syntaxes we rely on to brand variables/colors.
   ========================================================================== */

/* Arbitrary font sizes */
.text-\[9px\] { font-size: 9px !important; }
.text-\[10px\] { font-size: 10px !important; }
.text-\[11px\] { font-size: 11px !important; }

/* Arbitrary min-height */
.min-h-\[120px\] { min-height: 120px !important; }

/* Arbitrary backdrop blur */
.backdrop-blur-\[2px\] {
    backdrop-filter: blur(2px) !important;
    -webkit-backdrop-filter: blur(2px) !important;
}

/* Color/opacity shorthand (slash syntax) */
.border-white\/10 { border-color: rgba(255, 255, 255, 0.10) !important; }
.border-white\/30 { border-color: rgba(255, 255, 255, 0.30) !important; }
.bg-white\/5 { background-color: rgba(255, 255, 255, 0.05) !important; }
.bg-white\/10 { background-color: rgba(255, 255, 255, 0.10) !important; }
.bg-white\/20 { background-color: rgba(255, 255, 255, 0.20) !important; }

.bg-slate-900 { background-color: #0f172a !important; }
.bg-slate-50 { background-color: #f8fafc !important; }
.bg-slate-100 { background-color: #f1f5f9 !important; }
.bg-slate-200 { background-color: #e2e8f0 !important; }

.text-slate-800 { color: #1e293b !important; }
.text-slate-600 { color: #475569 !important; }
.text-slate-500 { color: #64748b !important; }
.text-slate-400 { color: #94a3b8 !important; }
.text-slate-300 { color: #cbd5e1 !important; }
.text-slate-200 { color: #e2e8f0 !important; }

.border-slate-100 { border-color: #f1f5f9 !important; }
.border-slate-200 { border-color: #e2e8f0 !important; }

.bg-slate-900\/40 { background-color: rgba(15, 23, 42, 0.40) !important; }
.bg-slate-50\/50 { background-color: rgba(248, 250, 252, 0.50) !important; }

/* Brand navy with opacity (brand-navy is #2b3a7f in base.css) */
.bg-brand-navy { background-color: var(--brand-navy) !important; }
.text-brand-navy { color: var(--brand-navy) !important; }
.text-brand-navy\/40 { color: rgba(43, 58, 127, 0.40) !important; }
.bg-brand-navy\/5 { background-color: rgba(43, 58, 127, 0.05) !important; }
.border-brand-navy\/10 { border-color: rgba(43, 58, 127, 0.10) !important; }

/* Text white opacity variants used in study UIs */
.text-white\/90 { color: rgba(255, 255, 255, 0.90) !important; }
.text-white\/80 { color: rgba(255, 255, 255, 0.80) !important; }
.text-white\/70 { color: rgba(255, 255, 255, 0.70) !important; }
.text-white\/60 { color: rgba(255, 255, 255, 0.60) !important; }
.text-white\/50 { color: rgba(255, 255, 255, 0.50) !important; }
.text-white\/40 { color: rgba(255, 255, 255, 0.40) !important; }
.text-white\/10 { color: rgba(255, 255, 255, 0.10) !important; }

/* Hover/focus variant shims */
.hover\:bg-white\/10:hover { background-color: rgba(255, 255, 255, 0.10) !important; }
.hover\:bg-slate-50\/50:hover { background-color: rgba(248, 250, 252, 0.50) !important; }
.hover\:bg-slate-50:hover { background-color: #f8fafc !important; }
.hover\:border-brand-navy\/20:hover { border-color: rgba(43, 58, 127, 0.20) !important; }

.focus\:border-brand-navy:focus { border-color: var(--brand-navy) !important; }
.focus\:ring-2:focus {
    outline: 2px solid transparent;
    outline-offset: 2px;
}
.focus\:ring-brand-navy\/20:focus {
    box-shadow: 0 0 0 3px rgba(43, 58, 127, 0.20) !important;
}
/* Accessibility - Focus states */
.study-cta:focus-visible,
.study-link:focus-visible,
.study-filter select:focus-visible,
.study-filter input[type="text"]:focus-visible,
.study-note-editor textarea:focus-visible,
.study-verse-line:focus-visible {
    outline: 3px solid var(--brand-orange);
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(250, 131, 52, 0.2);
}

/* Button and link states */
.study-cta:disabled,
.study-segment.is-disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

@keyframes studyFadeUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Dashboard: keep Resume Session on one line on mobile */
@media (max-width: 767px) {
    .study-resume-session-btn {
        white-space: nowrap;
        font-size: 0.95rem;
        padding: 0.9rem 1.1rem;
    }
}

/* Dashboard: keep Resume Session on one line at all sizes */
.study-resume-session-btn {
    white-space: nowrap;
    flex-wrap: nowrap;
}

.study-animate .study-passage,
.study-animate .study-note-editor,
.study-animate .study-pagination,
.study-animate .study-highlight-legend,
.study-animate .study-soft-panel,
.study-animate .study-general-notes {
    animation: studyFadeUp 240ms ease both;
}

.study-animate .study-note-editor {
    animation-delay: 50ms;
}

.study-animate .study-general-notes {
    animation-delay: 90ms;
}

/* Community Insights */
.insight-grid {
    display: grid;
    gap: 1.25rem;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    margin-top: 1.5rem;
}

.insight-card {
    background: #ffffff;
    border-radius: var(--study-radius-md);
    border: 1px solid var(--study-border);
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.insight-card:hover {
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.06);
    border-color: var(--brand-navy-light);
}

.insight-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
}

.insight-card.is-trending::before { background: var(--accent-growth, #10b981); }
.insight-card.is-confusing::before { background: var(--accent-love, #ef4444); }
.insight-card.is-prayer::before { background: var(--accent-peace, #3b82f6); }

.insight-kicker {
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--study-muted);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.insight-title {
    font-family: var(--study-font-display);
    font-size: 1.15rem;
    color: var(--brand-navy);
    margin: 0;
}

.insight-desc {
    font-size: 0.9rem;
    color: var(--study-muted);
    line-height: 1.5;
}

.insight-stats {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid #f1f5f9;
}

.stat-item {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--study-muted);
}

.stat-item .material-icons {
    font-size: 0.9rem;
}

.verified-badge {
    display: inline-flex;
    align-items: center;
    color: var(--brand-navy);
    margin-left: 0.4rem;
}

.verified-badge .material-icons {
    font-size: 1rem !important;
}

@media (max-width: 768px) {
    .study-micro-priority {
        display: block;
    }
}
