/* ==========================================================================
   Space → Study tab (js/study/pages/tabs/study.js)
   Left column: hero, stats, mode cards, continue strip.
   Right rail: needs-review list and the tutor mini-chat.
   Tokens only — see css/study/study.css for the definitions.
   ========================================================================== */

.st-study-main {
    display: flex;
    flex-direction: column;
    gap: 22px;
    min-width: 0;
}

/* Background coverage continuation — non-blocking, removed when complete. */
.st-study-gen-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 14px;
    padding: 10px 14px;
    border: 1px solid var(--st-border);
    border-radius: var(--st-radius-card-sm);
    background: var(--st-surface-2);
    font-size: 13px;
    line-height: 1.4;
    color: var(--st-ink-2);
}
.st-study-gen-banner[hidden] {
    display: none !important;
}
.st-study-gen-banner__title {
    font-size: 13px;
    font-weight: 700;
    color: var(--st-ink);
}
.st-study-gen-banner__count {
    font-variant-numeric: tabular-nums;
}

/* The space page owns `.st-space-body--rail`, but if a tab body is ever mounted
   in the plain body wrapper the two columns would stack; keep the grid either
   way rather than depend on a class this file does not own. */
.st-space-body:not(.st-space-body--rail):has(> .st-study-main) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--st-rail-w);
    gap: 24px;
    align-items: start;
}

/* --- Hero ---------------------------------------------------------------- */

.st-study-hero {
    padding: 22px 24px;
}

/* --- First run: "Set this space up" -------------------------------------
   Shown until something has been generated from the board's notes, which is
   the normal state of a new space rather than an error. */

.st-study-setup {
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.st-study-setup__head {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.st-study-setup__title {
    font-size: 26px;
    line-height: 1.15;
    letter-spacing: -0.02em;
}
.st-study-setup__sub {
    font-size: 14px;
    color: var(--st-ink-2);
}
.st-study-setup__body {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.st-study-setup__lead {
    font-size: 15px;
    line-height: 1.55;
    color: var(--st-ink-2);
    max-width: 62ch;
}
.st-study-setup__pick {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    padding: 12px 14px;
    border: 1px solid var(--st-border);
    border-radius: var(--st-radius-card-sm);
    background: var(--st-surface-2);
}
.st-study-setup__count {
    font-size: 14px;
    font-weight: 700;
}
.st-study-setup__actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.st-study-setup__ai { max-width: 62ch; }
.st-study-setup__error { margin-bottom: 2px; }
.st-study-setup__status {
    font-size: 16px;
    font-weight: 700;
}

.st-study-setup__queue {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
}
.st-study-setup__note {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    font-size: 13px;
    border-top: 1px solid var(--st-border-soft);
}
.st-study-setup__note:first-child { border-top: 0; }
.st-study-setup__note > .st-truncate { flex: 1 1 auto; min-width: 0; }
.st-study-setup__mark {
    display: inline-flex;
    flex: 0 0 auto;
    color: var(--st-ink-4);
}
.st-study-setup__note.is-done .st-study-setup__mark { color: var(--st-green-ink); }
.st-study-setup__note.is-reading .st-study-setup__mark { color: var(--st-accent); }
.st-study-setup__note.is-reading { font-weight: 700; }
.st-study-setup__note.is-queued { color: var(--st-ink-3); }

/* Per-output progress for the first-run / autogenerate path (concepts →
   flashcards → quiz). Same row chrome as the note queue above. */
.st-study-setup__outputs {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
}
.st-study-setup__output {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    font-size: 13px;
    border-top: 1px solid var(--st-border-soft);
}
.st-study-setup__output:first-child { border-top: 0; }
.st-study-setup__output-label { flex: 1 1 auto; min-width: 0; font-weight: 600; }
.st-study-setup__output.is-done .st-study-setup__mark { color: var(--st-green-ink); }
.st-study-setup__output.is-running .st-study-setup__mark { color: var(--st-accent); }
.st-study-setup__output.is-running { font-weight: 700; }
.st-study-setup__output.is-pending { color: var(--st-ink-3); }
.st-study-setup__output.is-failed .st-study-setup__mark { color: var(--st-danger-ink); }
.st-study-setup__writing {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    color: var(--st-accent);
    font-weight: 700;
    animation: st-setup-writing 1.1s ease-in-out infinite;
}
@keyframes st-setup-writing {
    0%, 100% { opacity: 0.45; }
    50% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
    .st-study-setup__writing { animation: none; opacity: 1; }
}

/* --- Take a new quiz: length picker -------------------------------------- */

.st-study-quizlen {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.st-study-quizlen__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.st-study-quizlen__chips .st-btn--chip {
    min-width: 44px;
    justify-content: center;
}
.st-study-quizlen__composition {
    margin: 0;
    font-size: 14px;
    line-height: 1.45;
    color: var(--st-ink-2);
}
.st-study-quizlen__coverage {
    margin: 0;
    font-size: 12px;
    line-height: 1.4;
    color: var(--st-ink-4);
}
.st-study-quizlen__grade-label {
    margin: 8px 0 0;
}
.st-study-quizlen .st-help {
    margin: 0;
}
.st-study-quizlen__loading {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    min-height: 1.4em;
}
.st-study-quizlen__loading svg {
    flex: 0 0 auto;
    color: var(--st-accent);
}
.st-study-quizlen__chips.is-loading {
    pointer-events: none;
}
.st-study-quizlen__skel-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 36px;
    padding: 0 14px;
    border-radius: 999px;
    background: var(--st-fill-2, rgba(0, 0, 0, 0.06));
    color: transparent;
    font-size: 14px;
    font-weight: 600;
    animation: st-study-quizlen-pulse 1.2s ease-in-out infinite;
}
.st-study-quizlen__grade-skel {
    display: flex;
    gap: 6px;
    pointer-events: none;
}
.st-study-quizlen__skel-seg {
    flex: 1;
    min-height: 36px;
    border-radius: 8px;
    background: var(--st-fill-2, rgba(0, 0, 0, 0.06));
    animation: st-study-quizlen-pulse 1.2s ease-in-out infinite;
}
.st-study-quizlen__error {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.st-study-quizlen__error-text {
    margin: 0;
    font-size: 14px;
    line-height: 1.45;
    color: var(--st-ink-2);
}
@keyframes st-study-quizlen-pulse {
    0%, 100% { opacity: 0.55; }
    50% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
    .st-study-quizlen__skel-chip,
    .st-study-quizlen__skel-seg {
        animation: none;
        opacity: 0.7;
    }
}

/* --- Take a new quiz: in-progress modal ---------------------------------
   Same language as the first-run setup progress (status + material + bar),
   sized for the shared modal rather than the full setup card. */

.st-study-quizgen {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.st-study-quizgen__status {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.35;
}
.st-study-quizgen__status svg {
    flex: 0 0 auto;
    color: var(--st-accent);
}
.st-study-quizgen__material {
    margin: 0;
    font-size: 14px;
    line-height: 1.4;
    color: var(--st-ink-2);
}
.st-study-quizgen__meta {
    margin: 0;
    font-variant-numeric: tabular-nums;
}
.st-study-quizgen .st-progress {
    width: 100%;
}
.st-study-quizgen .st-help {
    margin-top: 4px;
}

/* --- Notes with nothing generated from them ------------------------------ */

.st-study-remaining {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    padding: 12px 16px;
    border: 1px dashed var(--st-border-strong);
    border-radius: var(--st-radius-card-sm);
    background: var(--st-surface-2);
}
.st-study-remaining__text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.st-study-remaining__text strong { font-size: 14px; font-weight: 700; }

/* --- Scope --------------------------------------------------------------- */

.st-study-scope {
    gap: 8px;
    font-size: 13px;
}
.st-study-scope .st-seg {
    flex-wrap: wrap;
    max-width: 100%;
}
/* The third segment takes a material's name, which can be long. */
.st-study-scope .st-seg__btn {
    max-width: 180px;
}

/* --- Mode cards ---------------------------------------------------------- */

.st-study-mode {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    height: 100%;
    text-align: left;
    overflow: hidden;
    transition: transform 0.14s ease, box-shadow 0.14s ease;
}
.st-study-mode:hover:not(:disabled) {
    transform: var(--st-lift);
    box-shadow: var(--st-shadow-soft-hover);
    border-color: var(--st-border-strong);
}
.st-study-mode:disabled {
    cursor: not-allowed;
    opacity: 0.72;
    transform: none;
    box-shadow: var(--st-shadow-card);
}
/* Keep copy above the decorative corner mark. */
.st-study-mode > :not(.st-study-mode__mark) {
    position: relative;
    z-index: 1;
}
/* Upper-right balance: soft wash + radial dots + faded icon glyph.
   Colour matches the card's icon tile (accent / warm-ink / violet). */
.st-study-mode__mark {
    position: absolute;
    top: -18px;
    right: -22px;
    width: 108px;
    height: 108px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 0;
    color: var(--st-mode-mark, var(--st-accent));
}
.st-study-mode__mark::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background:
        radial-gradient(circle at 50% 50%, var(--st-mode-mark, var(--st-accent)) 1.35px, transparent 1.45px),
        var(--st-mode-mark-soft, var(--st-accent-soft));
    background-size: 11px 11px, auto;
    opacity: 0.85;
}
.st-study-mode__mark::after {
    /* Small hard-edged sticker chip — MiDOTs chrome, not a soft glow. */
    content: "";
    position: absolute;
    top: 22px;
    left: 14px;
    width: 22px;
    height: 22px;
    border-radius: 7px;
    border: 2px solid currentColor;
    opacity: 0.2;
    transform: rotate(14deg);
}
.st-study-mode__mark svg {
    position: relative;
    opacity: 0.16;
}
.st-study-mode__chip {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.4em;
    padding: 5px 9px;
    border-radius: 999px;
    border: 1.5px solid currentColor;
    background: var(--st-surface);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.01em;
    line-height: 1;
    box-shadow: var(--st-shadow-card);
    transform: rotate(-6deg) translate(-6px, 10px);
}
.st-study-mode__chip--accent { color: var(--st-accent); }
.st-study-mode__chip--warm { color: var(--st-warm-ink); }
.st-study-mode__chip--violet { color: var(--st-violet); }
.st-study-mode__chip--muted { color: var(--st-ink-4); }
.st-study-mode__mark--accent {
    --st-mode-mark: var(--st-accent);
    --st-mode-mark-soft: var(--st-accent-soft);
}
.st-study-mode__mark--warm {
    --st-mode-mark: var(--st-warm-ink);
    --st-mode-mark-soft: var(--st-warm-soft);
}
.st-study-mode__mark--violet {
    --st-mode-mark: var(--st-violet);
    --st-mode-mark-soft: var(--st-violet-soft);
}
.st-study-mode__title {
    font-size: 19px;
    line-height: 1.2;
    padding-right: 48px;
}
.st-study-mode__desc {
    font-size: 13px;
    line-height: 1.45;
    color: var(--st-ink-2);
    padding-right: 12px;
}
.st-study-mode__status {
    margin-top: auto;
    font-size: 12px;
    font-weight: 700;
}
.st-study-mode__status--accent { color: var(--st-accent); }
.st-study-mode__status--warm { color: var(--st-warm-ink); }
.st-study-mode__status--violet { color: var(--st-violet); }
.st-study-mode__status--muted { color: var(--st-ink-4); }

/* --- Continue strip ------------------------------------------------------ */

.st-study-continue {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    border-radius: var(--st-radius-card-sm);
    border: 1px solid var(--st-border);
    background: var(--st-surface-2);
    color: var(--st-ink);
    min-height: var(--st-tap);
}
.st-study-continue:hover {
    background: var(--st-fill);
    color: var(--st-ink);
}
.st-study-continue__icon {
    color: var(--st-ink-2);
    flex: 0 0 auto;
}
.st-study-continue__text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1 1 auto;
    min-width: 0;
}
.st-study-continue__text strong {
    font-size: 14px;
    font-weight: 700;
}
.st-study-continue .st-progress {
    flex: 0 0 auto;
}

/* --- Rail ---------------------------------------------------------------- */

.st-study-rail-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 18px;
}

.st-study-flagged {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 12px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--st-border);
}
.st-study-flagged:focus {
    outline: none;
}
.st-study-flagged:focus-visible {
    outline: 2px solid var(--st-accent);
    outline-offset: 2px;
    border-radius: 8px;
}
.st-study-flagged__actions {
    flex-wrap: wrap;
    gap: 8px;
}
.st-study-flagged__row strong {
    font-weight: 650;
}

.st-study-weak {
    gap: 6px;
}
.st-study-weak__pct {
    font-size: 12px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.st-study-weak__pct--danger { color: var(--st-danger-ink); }
.st-study-weak__pct--warm { color: var(--st-warm-ink); }
.st-study-weak__pct--accent { color: var(--st-accent); }
.st-study-weak__pct--green { color: var(--st-green-ink); }

.st-study-dot--danger { background: var(--st-danger); }
.st-study-dot--warm { background: var(--st-warm); }
.st-study-dot--accent { background: var(--st-accent); }
.st-study-dot--green { background: var(--st-green); }
.st-study-weak .st-dot {
    width: 8px;
    height: 8px;
}

/* --- Tutor --------------------------------------------------------------- */

.st-study-tutor {
    flex: 1 1 auto;
}
/* The log scrolls on its own so a long thread never grows the page or hands
   its scroll back to the document. */
.st-study-tutor__log {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1 1 auto;
    min-height: 64px;
    max-height: 260px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 2px;
}
.st-study-bubble {
    max-width: 92%;
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.45;
}
.st-study-bubble--user {
    align-self: flex-end;
    max-width: 90%;
    border-radius: 12px 12px 2px 12px;
    background: var(--st-accent);
    color: var(--st-on-accent);
}
.st-study-bubble--tutor {
    align-self: flex-start;
    border-radius: 12px 12px 12px 2px;
    background: var(--st-bg);
    color: var(--st-ink);
    white-space: pre-line;
}
.st-study-bubble--tutor a {
    font-weight: 700;
}
.st-study-bubble--typing {
    color: var(--st-ink-3);
    font-style: italic;
}
.st-study-tutor__suggestions {
    gap: 6px;
}
.st-study-tutor__composer {
    display: flex;
    gap: 8px;
}
.st-study-tutor__input {
    font-size: 13px;
    padding: 10px 12px;
}
.st-study-tutor__more {
    align-self: flex-end;
}

/* --- Material picker ----------------------------------------------------- */

.st-study-pick {
    gap: 8px;
    max-height: 52vh;
    overflow-y: auto;
}
.st-study-pick__text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

/* --- Responsive ---------------------------------------------------------- */

@media (max-width: 1100px) {
    .st-study-tutor__log { max-height: 220px; }
}

@media (max-width: 900px) {
    .st-space-body:not(.st-space-body--rail):has(> .st-study-main) {
        grid-template-columns: minmax(0, 1fr);
    }
    .st-study-mode__title { font-size: 18px; }
}

@media (max-width: 760px) {
    .st-study-hero { padding: 18px 20px; }
    .st-study-setup__title { font-size: 22px; }
    .st-study-setup__actions .st-btn { flex: 1 1 auto; justify-content: center; }
    .st-study-remaining .st-btn-row { width: 100%; }
    .st-study-remaining .st-btn-row .st-btn { flex: 1 1 auto; justify-content: center; }
    .st-study-scope {
        width: 100%;
        justify-content: space-between;
    }
    .st-study-scope .st-seg { flex: 1 1 auto; }
    .st-study-scope .st-seg__btn { flex: 1 1 auto; }
    .st-study-mode__mark {
        width: 88px;
        height: 88px;
        top: -14px;
        right: -18px;
    }
    .st-study-mode__title { padding-right: 40px; }
    .st-study-continue {
        flex-wrap: wrap;
        padding: 14px;
    }
    .st-study-continue .st-progress {
        flex: 1 1 100%;
        width: 100% !important;
    }
    .st-study-tutor__log { max-height: 200px; }
}
