/* ==========================================================================
   LESSON PAGE STYLES
   ========================================================================== */

body {
    background-color: #030005;
    color: #e2e8f0;
    font-family: var(--font-main);
    overflow-x: hidden;
}

.lesson-main {
    min-height: 70vh;
}

.lesson-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 120px 0;
}

.loader-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(192, 132, 252, 0.2);
    border-top-color: #c026d3;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.lesson-body {
    max-width: 820px;
    margin: 0 auto;
    padding: 30px 24px 80px 24px;
}

/* ---- Topbar ---- */
.lesson-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 0 24px 0;
    border-bottom: 1px solid rgba(192, 132, 252, 0.14);
    margin-bottom: 34px;
    flex-wrap: wrap;
}

.back-link {
    color: #c084fc;
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: color 0.2s ease;
}

.back-link:hover {
    color: #f43f5e;
}

.lesson-progress-mini {
    flex: 1;
    min-width: 160px;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.lesson-breadcrumb {
    font-size: 0.78rem;
    color: #94a3b8;
}

.progress-track.small {
    height: 6px;
    width: 100%;
}

.lesson-xp-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(250, 204, 21, 0.12);
    border: 1px solid rgba(250, 204, 21, 0.3);
    color: #facc15;
    font-size: 0.82rem;
    font-weight: 700;
    padding: 6px 12px;
    border-radius: 20px;
}

/* ---- Article ---- */
.lesson-article {
    background: rgba(15, 2, 18, 0.6);
    border: 1px solid rgba(192, 132, 252, 0.18);
    border-radius: 16px;
    padding: 40px 44px;
    margin-bottom: 30px;
}

.lesson-title {
    font-size: 2rem;
    font-weight: 800;
    color: #ffffff;
    margin: 0 0 24px 0;
}

.lesson-content {
    font-size: 1.02rem;
    line-height: 1.75;
    color: #e2e8f0;
}

.lesson-content p {
    margin: 0 0 18px 0;
}

.lesson-content b {
    color: #f3e8ff;
}

.lesson-content code {
    background: rgba(192, 132, 252, 0.14);
    color: #f0abfc;
    padding: 2px 7px;
    border-radius: 5px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.92em;
}

/* ---- Code block ---- */
.lesson-code-block {
    margin: 26px 0;
    background: #0a0310;
    border: 1px solid rgba(192, 132, 252, 0.22);
    border-radius: 12px;
    overflow: hidden;
}

.code-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: #150420;
    border-bottom: 1px solid rgba(192, 132, 252, 0.14);
}

.code-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.code-dot:nth-child(1) { background: #f43f5e; }
.code-dot:nth-child(2) { background: #facc15; }
.code-dot:nth-child(3) { background: #10b981; }

.code-lang {
    margin-left: auto;
    font-size: 0.72rem;
    color: #c084fc;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.lesson-code-block pre {
    margin: 0;
    padding: 18px 20px;
    overflow-x: auto;
}

.lesson-code-block code {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.92rem;
    color: #e9d5ff;
    line-height: 1.6;
    background: transparent;
    padding: 0;
}

/* ---- Quiz ---- */
.lesson-quiz {
    margin-top: 34px;
    border-top: 1px dashed rgba(192, 132, 252, 0.3);
    padding-top: 26px;
}

.quiz-title {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #facc15;
    font-size: 1.25rem;
    margin: 0 0 20px 0;
}

.quiz-question {
    display: flex;
    gap: 14px;
    background: rgba(192, 132, 252, 0.07);
    border: 1px solid rgba(192, 132, 252, 0.18);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
}

.quiz-q-num {
    width: 26px;
    height: 26px;
    min-width: 26px;
    border-radius: 50%;
    background: linear-gradient(135deg, #c026d3, #9f1239);
    color: #ffffff;
    font-size: 0.82rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.quiz-q-text {
    line-height: 1.8;
    font-size: 1rem;
    color: #f3e8ff;
}

.quiz-q-text code {
    background: rgba(192, 132, 252, 0.14);
    color: #f0abfc;
    padding: 2px 7px;
    border-radius: 5px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.92em;
}

.blank-input {
    width: 150px;
    max-width: 60%;
    background: #0a0310;
    border: 2px solid rgba(192, 132, 252, 0.4);
    border-radius: 6px;
    color: #ffffff;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1rem;
    padding: 6px 10px;
    margin: 0 4px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.blank-input:focus {
    border-color: #c026d3;
    box-shadow: 0 0 10px rgba(192, 38, 211, 0.35);
}

.blank-input.correct {
    border-color: #10b981;
    background: rgba(16, 185, 129, 0.12);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.3);
}

.blank-input.wrong {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.12);
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.3);
}

.quiz-check-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #c026d3, #9f1239);
    color: #ffffff;
    font-weight: 700;
    font-size: 0.95rem;
    border: none;
    padding: 11px 22px;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 6px 18px rgba(159, 18, 57, 0.3);
}

.quiz-check-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 26px rgba(192, 38, 211, 0.4);
}

.quiz-result {
    margin-top: 18px;
    border-radius: 10px;
    padding: 16px 18px;
}

.quiz-result.success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.4);
}

.quiz-result.error {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.4);
}

.quiz-result-title {
    font-weight: 700;
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.quiz-result.success .quiz-result-title { color: #34d399; }
.quiz-result.error .quiz-result-title { color: #f87171; }

.quiz-explanation {
    color: #cbd5e1;
    line-height: 1.6;
    font-size: 0.95rem;
    margin-bottom: 8px;
}

.quiz-explanation:last-child {
    margin-bottom: 0;
}

.quiz-explanation strong {
    color: #f3e8ff;
}

.quiz-xp-note {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(250, 204, 21, 0.1);
    border: 1px solid rgba(250, 204, 21, 0.3);
    color: #facc15;
    font-weight: 700;
    font-size: 0.95rem;
}

/* ---- Nav ---- */
.lesson-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.lesson-nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 22px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 700;
    font-size: 0.95rem;
    border: 1px solid rgba(192, 132, 252, 0.3);
    color: #d8b4fe;
    background: transparent;
    transition: all 0.2s ease;
}

.lesson-nav-btn:hover {
    background: rgba(192, 132, 252, 0.1);
    border-color: #c084fc;
}

.next-btn {
    background: linear-gradient(135deg, #c026d3, #9f1239);
    color: #ffffff;
    border: none;
    box-shadow: 0 6px 18px rgba(159, 18, 57, 0.35);
    margin-left: auto;
}

.next-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 26px rgba(192, 38, 211, 0.45);
}

.next-btn.locked {
    background: rgba(51, 65, 85, 0.5);
    color: #64748b;
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
    pointer-events: none;
}

/* ---- Layout with sidebar ---- */
.lesson-body {
    max-width: 1180px;
}

.lesson-layout {
    display: flex;
    gap: 24px;
    align-items: flex-start;
}

.lesson-layout-main {
    flex: 1;
    min-width: 0;
}

/* ---- Sidebar ---- */
.lesson-sidebar {
    width: 290px;
    min-width: 290px;
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    background: rgba(15, 2, 18, 0.92);
    border: 1px solid rgba(192, 132, 252, 0.2);
    border-radius: 14px;
    padding: 14px;
}

.lesson-sidebar::-webkit-scrollbar { width: 6px; }
.lesson-sidebar::-webkit-scrollbar-thumb { background: rgba(192, 132, 252, 0.25); border-radius: 6px; }

.sidebar-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 12px;
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(192, 132, 252, 0.16);
}

.sidebar-course-link {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    min-width: 0;
}

.sidebar-course-icon {
    font-size: 1.3rem;
    min-width: 22px;
    text-align: center;
}

.sidebar-course-title {
    color: #f3e8ff;
    font-weight: 700;
    font-size: 0.98rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-close {
    display: none;
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 1rem;
    cursor: pointer;
    padding: 4px 8px;
}

.sidebar-chapter {
    border-bottom: 1px solid rgba(192, 132, 252, 0.1);
}

.sidebar-chapter:last-child { border-bottom: none; }

.sidebar-chapter-head {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    background: transparent;
    border: none;
    color: #e2e8f0;
    padding: 11px 6px;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
}

.sidebar-chapter-head:hover { color: #f0abfc; }

.sidebar-chapter-index {
    font-family: var(--font-main);
    font-size: 0.72rem;
    color: #f43f5e;
}

.sidebar-chapter-title {
    flex: 1;
    font-size: 0.86rem;
    font-weight: 600;
}

.sidebar-chevron {
    font-size: 0.7rem;
    color: #64748b;
    transition: transform 0.25s ease;
}

.sidebar-chapter.open .sidebar-chevron { transform: rotate(180deg); }

.sidebar-lessons {
    display: none;
    padding: 0 0 8px 0;
}

.sidebar-chapter.open .sidebar-lessons { display: block; }

.sidebar-lesson {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    color: #a792a9;
    text-decoration: none;
    font-size: 0.84rem;
    transition: background 0.18s ease, color 0.18s ease;
}

.sidebar-lesson:hover {
    background: rgba(192, 132, 252, 0.1);
    color: #e2e8f0;
}

.sidebar-lesson.current {
    background: rgba(192, 38, 211, 0.18);
    color: #ffffff;
    font-weight: 600;
}

.sidebar-lesson-check {
    width: 16px;
    height: 16px;
    min-width: 16px;
    border-radius: 50%;
    border: 1.5px solid rgba(192, 132, 252, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.55rem;
    color: transparent;
}

.sidebar-lesson.done .sidebar-lesson-check {
    background: #10b981;
    border-color: #10b981;
    color: #ffffff;
}

.outline-toggle {
    display: none;
    background: rgba(192, 132, 252, 0.12);
    border: 1px solid rgba(192, 132, 252, 0.3);
    color: #d8b4fe;
    border-radius: 8px;
    padding: 9px 13px;
    cursor: pointer;
    font-size: 0.95rem;
}

/* ---- Streak chip ---- */
.lesson-xp-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(250, 204, 21, 0.12);
    border: 1px solid rgba(250, 204, 21, 0.3);
    color: #facc15;
    font-size: 0.82rem;
    font-weight: 700;
    padding: 6px 12px;
    border-radius: 20px;
}
.lesson-streak-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(249, 115, 22, 0.12);
    border: 1px solid rgba(249, 115, 22, 0.3);
    color: #fb923c;
    font-size: 0.82rem;
    font-weight: 700;
    padding: 6px 12px;
    border-radius: 20px;
}

/* ---- Code runner ---- */
.lesson-runner {
    margin: 26px 0;
    background: #0a0310;
    border: 1px solid rgba(192, 132, 252, 0.22);
    border-radius: 12px;
    overflow: hidden;
}

.runner-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    background: #150420;
    border-bottom: 1px solid rgba(192, 132, 252, 0.14);
}

.runner-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #f0abfc;
    font-weight: 700;
    font-size: 0.92rem;
}

.run-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #10b981, #059669);
    color: #ffffff;
    border: none;
    font-weight: 700;
    font-size: 0.88rem;
    padding: 8px 18px;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
}

.run-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 22px rgba(16, 185, 129, 0.45);
}

.run-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.runner-notice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  margin: 0 20px 16px;
  border: 1px dashed var(--border, #3a3f4b);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted, #a6adbb);
  font-size: 14px;
  line-height: 1.5;
}
.runner-notice i {
  color: var(--accent, #58a6ff);
  font-size: 16px;
}
.runner-notice[hidden] { display: none; }
.code-editor-wrap .CodeMirror {
    height: auto;
    min-height: 120px;
    font-size: 0.9rem;
}

#code-editor {
    width: 100%;
    min-height: 120px;
    background: #0a0310;
    color: #e9d5ff;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9rem;
    padding: 14px;
    border: none;
    outline: none;
    resize: vertical;
    line-height: 1.6;
    box-sizing: border-box;
}

.runner-output {
    display: none;
    border-top: 1px solid rgba(192, 132, 252, 0.14);
}

.runner-output.active { display: block; }

.runner-output-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 14px;
    background: #0d0412;
    color: #94a3b8;
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.clear-btn {
    background: transparent;
    border: none;
    color: #64748b;
    cursor: pointer;
    font-size: 0.85rem;
}

.clear-btn:hover { color: #f43f5e; }

#runner-console {
    margin: 0;
    padding: 14px 16px;
    max-height: 300px;
    overflow-y: auto;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.86rem;
    line-height: 1.6;
    color: #d1fae5;
    white-space: pre-wrap;
    word-break: break-word;
    background: #08010d;
}

#runner-console .console-err {
    color: #fca5a5;
}

#runner-console .console-ok {
    color: #34d399;
}

#runner-console .console-run {
    color: #c084fc;
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
    .lesson-layout {
        display: block;
    }

    .lesson-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 200;
        width: 310px;
        max-width: 86vw;
        max-height: 100vh;
        border-radius: 0;
        transform: translateX(-102%);
        transition: transform 0.3s ease;
        box-shadow: none;
    }

    .lesson-sidebar.open {
        transform: translateX(0);
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.85);
    }

    .sidebar-close { display: block; }
    .outline-toggle { display: inline-flex; }
}

@media (max-width: 600px) {
    .lesson-article {
        padding: 26px 22px;
    }

    .lesson-title {
        font-size: 1.5rem;
    }

    .lesson-nav {
        flex-wrap: wrap;
    }

    .lesson-topbar {
        gap: 10px;
    }
}