/* Course purpose.
   .cpurpose - the "why this course" panel students see at the top of a course
               page (coursePurposePanel).
   .cpe      - the tutor's view of it in the course editor, with its edit
               dialog (coursePurposeEditor + content_dashboard/course_purpose.js).
   Class names deliberately avoid "card": theme.css paints [class*="card"]
   dark in dark mode. */

/* ---- Student panel -------------------------------------------------- */
.cpurpose {
    margin: 0.25rem 0 1.25rem;
    border-radius: 18px;
    border: 1px solid var(--tt-line, #e2e8f0);
    background: var(--tt-surface, #fff);
    box-shadow: 0 10px 28px -22px rgba(99, 102, 241, 0.6);
    animation: cpurposeIn 0.5s cubic-bezier(0.2, 0.8, 0.25, 1) both;
}
@keyframes cpurposeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: none; }
}
.cpurpose-row {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.8rem 1rem;
    cursor: pointer;
    list-style: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.cpurpose-row::-webkit-details-marker { display: none; }
.cpurpose-icon {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 12px;
    color: #fff;
    font-size: 0.95rem;
    background: linear-gradient(135deg, #6366f1, #a855f7 60%, #ec4899);
    box-shadow: 0 8px 18px -8px rgba(139, 92, 246, 0.8);
}
.cpurpose-text { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; flex: 1 1 auto; }
.cpurpose-kicker {
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: #6366f1;
}
.cpurpose-headline {
    font-size: 0.95rem;
    font-weight: 800;
    line-height: 1.3;
    color: var(--tt-ink, #0f172a);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.cpurpose[open] .cpurpose-headline { -webkit-line-clamp: unset; }
.cpurpose-chev {
    flex: 0 0 auto;
    color: var(--tt-muted, #94a3b8);
    font-size: 0.8rem;
    transition: transform 0.25s ease;
}
.cpurpose[open] .cpurpose-chev { transform: rotate(180deg); }

.cpurpose-body {
    padding: 0 1rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    animation: cpurposeIn 0.3s ease both;
}
.cpurpose-why {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.55;
    font-weight: 500;
    color: var(--tt-muted, #475569);
}
.cpurpose-goals { display: flex; flex-direction: column; gap: 0.4rem; }
.cpurpose-goals-label {
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--tt-muted, #64748b);
}
.cpurpose-goal {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    font-size: 0.86rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--tt-ink, #0f172a);
}
.cpurpose-num {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    margin-top: 0.05rem;
    border-radius: 7px;
    font-size: 0.68rem;
    font-weight: 800;
    color: #fff;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
}
.cpurpose-goal:nth-child(3) .cpurpose-num { background: linear-gradient(135deg, #a78bfa, #c084fc); }
.cpurpose-goal:nth-child(4) .cpurpose-num { background: linear-gradient(135deg, #f472b6, #fb7185); }
.cpurpose-goal:nth-child(5) .cpurpose-num { background: linear-gradient(135deg, #fbbf24, #fb923c); }
.cpurpose-source {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--tt-muted, #94a3b8);
}

html[data-theme="dark"] .cpurpose {
    background: var(--tt-surface, #111a2e);
    border-color: var(--tt-line, #263450);
    box-shadow: 0 14px 30px -24px rgba(0, 0, 0, 0.8);
}
html[data-theme="dark"] .cpurpose-kicker { color: #a5b4fc; }
html[data-theme="dark"] .cpurpose-headline { color: #e6ebf5; }
html[data-theme="dark"] .cpurpose-why { color: #b6c0d4; }
html[data-theme="dark"] .cpurpose-goal { color: #e6ebf5; }

/* ---- Tutor panel (course editor) ------------------------------------ */
.cpe {
    position: relative;
    overflow: hidden;
    isolation: isolate;
    margin: 0 0 2rem; /* same rhythm as .cd-course-hero above and .cd-topic below */
    padding: 1.25rem 1.5rem 1rem;
    /* Same chrome as the cards around it (.cd-course-hero, .cd-topic): the
       soft glow behind the icon is all that marks it out. */
    border-radius: var(--cd-radius, 16px);
    border: 1px solid var(--cd-line, var(--tt-line, #e2e8f0));
    background: var(--cd-card, var(--tt-surface, #fff));
    box-shadow: var(--cd-shadow-sm, 0 1px 3px 0 rgb(0 0 0 / 0.1));
}
.cpe::before {
    content: "";
    position: absolute;
    z-index: -1;
    width: 300px;
    height: 300px;
    left: -140px;
    top: -210px;
    border-radius: 50%;
    filter: blur(70px);
    background: rgba(99, 102, 241, 0.16);
    pointer-events: none;
}
.cpe-body:empty { min-height: 72px; }
.cpe-head { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.cpe-icon {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 13px;
    font-size: 1.05rem;
    color: #fff;
    background: linear-gradient(135deg, #6366f1, #a855f7 55%, #ec4899);
    box-shadow: 0 10px 22px -10px rgba(139, 92, 246, 0.9);
}
.cpe-title { display: flex; flex-direction: column; gap: 0.12rem; min-width: 0; }
.cpe-kicker { font-size: 0.7rem; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; color: #6366f1; }
.cpe-sub { font-size: 0.8rem; font-weight: 600; color: var(--tt-muted, #64748b); }
.cpe-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.22rem 0.6rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 800;
    color: #047857;
    background: rgba(16, 185, 129, 0.12);
}
.cpe-badge.cpe-badge-edited { color: #b45309; background: rgba(245, 158, 11, 0.14); }
.cpe-actions { display: flex; gap: 0.5rem; margin-left: auto; }
.cpe-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.48rem 0.95rem;
    border-radius: 999px;
    border: 1px solid var(--tt-line, #e2e8f0);
    background: var(--tt-surface, #fff);
    color: var(--tt-ink, #334155);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.cpe-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 18px -12px rgba(15, 23, 42, 0.5); }
.cpe-btn[disabled] { opacity: 0.6; cursor: progress; transform: none; }
.cpe-btn-primary {
    border-color: transparent;
    color: #fff;
    background: linear-gradient(120deg, #6366f1, #a855f7 55%, #ec4899);
    box-shadow: 0 10px 22px -12px rgba(168, 85, 247, 0.95);
}
.cpe-btn-ai {
    border-color: transparent;
    color: #7c3aed;
    background:
        linear-gradient(var(--tt-surface, #fff), var(--tt-surface, #fff)) padding-box,
        linear-gradient(120deg, #6366f1, #a855f7 55%, #ec4899) border-box;
}
.cpe-btn-ai:hover { box-shadow: 0 10px 22px -12px rgba(168, 85, 247, 0.9); }
.cpe-lead { margin-top: 1.1rem; }
.cpe-headline {
    margin: 0;
    font-size: clamp(1.15rem, 1.6vw, 1.45rem);
    font-weight: 800;
    line-height: 1.22;
    letter-spacing: -0.015em;
    text-wrap: pretty;
    color: #4f46e5;
    background: linear-gradient(115deg, #4f46e5 10%, #9333ea 55%, #db2777 95%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.cpe-why {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    margin: 0.6rem 0 0;
}
.cpe-why > i {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    margin-top: 1px;
    border-radius: 7px;
    font-size: 0.66rem;
    color: #fff;
    background: linear-gradient(135deg, #f59e0b, #f97316);
}
.cpe-why > div { min-width: 0; font-size: 0.9rem; line-height: 1.5; }
.cpe-why b { margin-right: 0.5rem; font-size: 0.66rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: #b45309; }
.cpe-why span { font-weight: 600; color: var(--cd-muted, var(--tt-muted, #64748b)); }
.cpe-goals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; margin-top: 1.1rem; }
.cpe-goals-label { grid-column: 1 / -1; font-size: 0.68rem; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; color: var(--tt-muted, #64748b); }
.cpe-goal {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.55rem 0.8rem;
    border-radius: 12px;
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1.35;
    color: var(--tt-ink, #1e293b);
    background: var(--tt-surface-2, #f8fafc);
    border: 1px solid var(--tt-line, #e8ecf3);
    transition: border-color 0.18s ease;
}
.cpe-goal:hover { border-color: rgba(139, 92, 246, 0.55); }
.cpe-goal b {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 8px;
    font-size: 0.74rem;
    font-weight: 900;
    color: #fff;
    background: linear-gradient(135deg, #60a5fa, #818cf8);
}
.cpe-goal:nth-child(3) b { background: linear-gradient(135deg, #a78bfa, #c084fc); }
.cpe-goal:nth-child(4) b { background: linear-gradient(135deg, #f472b6, #fb7185); }
.cpe-goal:nth-child(5) b { background: linear-gradient(135deg, #fbbf24, #fb923c); }
.cpe-dots { display: none; } /* phone slideshow only */
.cpe-note {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.9rem 0 0;
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--tt-muted, #94a3b8);
}
.cpe-note i { flex: none; color: #8b5cf6; }
.cpe.cpe-fresh .cpe-headline, .cpe.cpe-fresh .cpe-why, .cpe.cpe-fresh .cpe-goal { animation: cpeRise 0.55s cubic-bezier(0.2, 0.8, 0.25, 1) both; }
.cpe.cpe-fresh .cpe-why { animation-delay: 0.1s; }
.cpe.cpe-fresh .cpe-goal:nth-child(2) { animation-delay: 0.12s; }
.cpe.cpe-fresh .cpe-goal:nth-child(3) { animation-delay: 0.2s; }
.cpe.cpe-fresh .cpe-goal:nth-child(4) { animation-delay: 0.28s; }
.cpe.cpe-fresh .cpe-goal:nth-child(5) { animation-delay: 0.36s; }
@keyframes cpeRise {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: none; }
}
.cpe-empty-title { margin: 0; font-size: 1.05rem; font-weight: 800; color: var(--tt-ink, #0f172a); }
.cpe-empty-text { margin: 0.2rem 0 0; font-size: 0.86rem; font-weight: 600; line-height: 1.45; color: var(--tt-muted, #64748b); }
.cpe-empty { display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap; }
.cpe-empty > div { flex: 1; min-width: 220px; }
.cpe-spin { animation: cpeSpin 0.9s linear infinite; }
@keyframes cpeSpin { to { transform: rotate(360deg); } }
.cpe.cpe-fresh { animation: cpeFresh 1.4s ease-out; }
@keyframes cpeFresh {
    0% { box-shadow: 0 0 0 0 rgba(168, 85, 247, 0.55); }
    100% { box-shadow: 0 0 0 16px rgba(168, 85, 247, 0); }
}

/* Edit dialog */
.cpe-dialog .modal-content { border: 0; border-radius: 24px; overflow: hidden; }
.cpe-dialog-head { padding: 1.4rem 1.5rem 1.1rem; color: #fff; background: linear-gradient(120deg, #4f46e5, #9333ea 55%, #db2777); }
.cpe-dialog-head h5 { margin: 0; font-size: 1.15rem; font-weight: 800; color: #fff; }
.cpe-dialog-head p { margin: 0.25rem 0 0; font-size: 0.84rem; font-weight: 600; color: rgba(255, 255, 255, 0.85); }
.cpe-dialog-body { padding: 1.25rem 1.5rem 0.5rem; }
.cpe-field { margin-bottom: 1rem; }
.cpe-field label { display: flex; justify-content: space-between; margin-bottom: 0.35rem; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--tt-muted, #64748b); }
.cpe-field label span { font-weight: 600; letter-spacing: 0; text-transform: none; }
.cpe-field input, .cpe-field textarea {
    width: 100%;
    padding: 0.65rem 0.85rem;
    border-radius: 12px;
    border: 1.5px solid var(--tt-line, #e2e8f0);
    background: var(--tt-surface, #fff);
    color: var(--tt-ink, #0f172a);
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 600;
}
.cpe-field input:focus, .cpe-field textarea:focus { outline: 0; border-color: #8b5cf6; box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.16); }
.cpe-goal-input { display: flex; align-items: center; gap: 0.55rem; margin-bottom: 0.45rem; }
.cpe-goal-input b { flex: none; width: 26px; height: 26px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: 0.78rem; color: #fff; background: linear-gradient(135deg, #818cf8, #c084fc); }
.cpe-dialog-foot { display: flex; align-items: center; gap: 0.6rem; padding: 0.75rem 1.5rem 1.4rem; }
.cpe-dialog-foot .cpe-clear { margin-right: auto; border: 0; background: none; padding: 0; font-size: 0.8rem; font-weight: 700; color: var(--tt-muted, #94a3b8); text-decoration: underline; cursor: pointer; }

html[data-theme="dark"] .cpe-kicker { color: #a5b4fc; }
html[data-theme="dark"] .cpe-headline {
    color: #c7d2fe;
    background: linear-gradient(115deg, #a5b4fc 10%, #d8b4fe 55%, #f9a8d4 95%);
    -webkit-background-clip: text;
    background-clip: text;
}
html[data-theme="dark"] .cpe-btn-ai {
    color: #d8b4fe;
    background:
        linear-gradient(var(--tt-surface, #111a2e), var(--tt-surface, #111a2e)) padding-box,
        linear-gradient(120deg, #6366f1, #a855f7 55%, #ec4899) border-box;
}
html[data-theme="dark"] .cpe-why b { color: #fcd34d; }
html[data-theme="dark"] .cpe-goal { color: var(--tt-ink, #e6ebf5); background: var(--tt-surface-2, #17233b); border-color: var(--tt-line, #263450); }
html[data-theme="dark"] .cpe-badge { color: #6ee7b7; }
html[data-theme="dark"] .cpe-badge.cpe-badge-edited { color: #fcd34d; }
html[data-theme="dark"] .cpe-dialog .modal-content { background: var(--tt-surface, #111a2e); }

@media (max-width: 991.98px) {
    .cpe-goals { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 767.98px) {
    .cpe { padding: 1.2rem 1.1rem 1rem; }
    .cpe-actions { margin-left: 0; width: 100%; }

    /* Phone: a slideshow instead of one long column. The wrapper becomes a
       scroll-snap track and its two blocks dissolve, so the headline, the
       "why" and each goal are a slide of their own (dots: course_purpose.js). */
    .cpe-slides {
        display: flex;
        align-items: stretch;
        gap: 1.1rem;
        margin-top: 1.1rem;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        scroll-snap-type: x mandatory;
        scrollbar-width: none;
    }
    .cpe-slides::-webkit-scrollbar { display: none; }
    .cpe-lead, .cpe-goals { display: contents; }
    .cpe-goals-label, .cpe-note { display: none; }
    .cpe-headline, .cpe-why, .cpe-goal {
        flex: 0 0 100%;
        min-width: 0;
        margin: 0;
        scroll-snap-align: start;
        scroll-snap-stop: always;
    }
    .cpe-headline { align-self: center; font-size: 1.5rem; }
    .cpe-why { align-items: center; }
    .cpe-why span { font-size: 1rem; }
    .cpe-goal { flex-wrap: wrap; align-content: center; padding: 1rem; font-size: 1.05rem; }
    .cpe-goal::before {
        content: "By the end, students will be able to";
        flex: 0 0 100%;
        margin-bottom: 0.15rem;
        font-size: 0.66rem;
        font-weight: 800;
        letter-spacing: 0.16em;
        text-transform: uppercase;
        color: var(--tt-muted, #64748b);
    }
    .cpe-goal span { flex: 1 1 0; min-width: 0; }
    .cpe-goal:hover { transform: none; }
    .cpe-dots { display: flex; justify-content: center; gap: 0.4rem; margin-top: 0.9rem; }
    .cpe-dots:empty { display: none; }
    .cpe-dots button {
        width: 8px;
        height: 8px;
        padding: 0;
        border: 0;
        border-radius: 999px;
        background: var(--tt-line, #e2e8f0);
        transition: width 0.25s ease;
    }
    .cpe-dots button.is-on { width: 22px; background: linear-gradient(120deg, #6366f1, #a855f7 55%, #ec4899); }

    /* Student panel: the goals swipe sideways, the next one peeking in. */
    .cpurpose-goals {
        display: grid;
        grid-template-rows: auto 1fr;
        grid-auto-flow: column;
        grid-auto-columns: 86%;
        gap: 0.55rem 0.7rem;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        scroll-snap-type: x mandatory;
        scrollbar-width: none;
    }
    .cpurpose-goals::-webkit-scrollbar { display: none; }
    .cpurpose-goals-label { grid-row: 1; grid-column: 1; position: sticky; left: 0; margin: 0; white-space: nowrap; }
    .cpurpose-goal { grid-row: 2; scroll-snap-align: start; }
}
@media (prefers-reduced-motion: reduce) {
    .cpurpose, .cpurpose-goal, .cpe.cpe-fresh, .cpe.cpe-fresh .cpe-headline, .cpe.cpe-fresh .cpe-why, .cpe.cpe-fresh .cpe-goal { animation: none; }
    .cpe-dots button { transition: none; }
}
