.learning-shell {
    width: min(1100px, calc(100% - 2rem));
    margin: 0 auto;
}

.learning-hero {
    padding: 5rem 0 3rem;
    background: #f8fafc;
}

.learning-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-weight: 700;
    color: #64748b;
}

.topic-page h1,
.learning-hero h1 {
    /*font-family: Georgia, "Times New Roman", "Songti SC", serif;*/
    font-size: clamp(3rem, 6vw, 5rem);
    font-weight: 600;
    letter-spacing: -0.03em;
    line-height: 1.05;
}

.learning-hero p {
    max-width: 700px;
    color: #475569;
    font-size: 1.1rem;
}

.learning-section {
    padding: 3rem 0;
}

.course-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
}

.course-card,
.topic-card {
    display: block;
    text-decoration: none;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 22px;
    padding: 1.5rem;
    color: #0f172a;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.04);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.course-card:hover,
.topic-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

.course-card h3 {
    margin-top: 0;
}

.course-card p {
    color: #64748b;
}

.module-block {
    margin-bottom: 3rem;
}

.module-title {
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f1f5f9;
    padding: 0.8rem 1.2rem;
    border-radius: 16px;
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    transition: background 0.2s ease;
}

.module-title:hover {
    background: #e2e8f0;
}

.toggle-indicator {
    font-size: 1.2rem;
    transition: transform 0.2s ease;
}

/* Collapsed state */
.topic-list.collapsed {
    display: none;
}

.topic-list {
    display: grid;
    gap: 0.8rem;
}

.topic-page {
    padding: 5rem 0;
}

.study-content {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 24px;
    padding: 2rem;
    line-height: 1.75;
}

.study-content h2 {
    margin-top: 2rem;
}

.study-content h3 {
    margin-top: 1.5rem;
}

.study-content h2:first-child {
    margin-top: 0;
}

/* Hide lesson slide buttons from users who are not signed in */
.study-content.slides-locked .lesson-slide-btn {
    display: none !important;
}

.slide-access-notice {
    margin-bottom: 1rem;
    padding: 0.8rem 1rem;

    border-radius: 16px;
    border: 1px solid #cbd5e1;

    background: #f8fafc;
    color: #475569;

    font-size: 0.9rem;
    font-weight: 700;
}

.small-button,
.small-button:visited,
.small-button:hover,
.small-button:active {
    text-decoration: none;
}

.small-button {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;

    padding: 0.6rem 1.2rem;
    border-radius: 999px;

    font-size: 0.9rem;
    font-weight: 500;

    background: #0f172a;
    color: white;

    border: none;
    cursor: pointer;

    transition: all 0.25s ease;
}

/* Hover */
.small-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.2);
}

/* Active click */
.small-button:active {
    transform: scale(0.98);
}

/* ===== Lesson anchor navigation with scroll buttons ===== */

.lesson-anchor-nav-wrapper {
    position: sticky;
    top: 5rem;
    z-index: 30;

    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.4rem;

    background: rgba(248, 250, 252, 0.94);
    backdrop-filter: blur(10px);

    border: 1px solid #e2e8f0;
    border-radius: 16px;

    padding: 0.45rem;
    margin: 0 0 2rem;

    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.06);
}

.lesson-anchor-nav {
    position: static;
    z-index: auto;

    display: flex;
    flex-wrap: nowrap;
    gap: 0.5rem;

    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;

    background: transparent;
    backdrop-filter: none;

    border: none;
    border-radius: 0;

    padding: 0;
    margin: 0;

    box-shadow: none;

    scrollbar-width: none;
}

.lesson-anchor-nav::-webkit-scrollbar {
    display: none;
}

.lesson-anchor-nav a {
    flex: 0 0 auto;

    text-decoration: none;
    color: #334155;

    font-size: 0.84rem;
    font-weight: 600;

    padding: 0.4rem 0.75rem;
    border-radius: 999px;

    transition: all 0.2s ease;
}

.lesson-anchor-nav a:hover {
    background: #0f172a;
    color: white;
}

.lesson-nav-scroll-btn {
    width: 32px;
    height: 32px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    border: 1px solid #cbd5e1;
    border-radius: 999px;

    background: white;
    color: #334155;

    font-size: 1.15rem;
    font-weight: 800;
    line-height: 1;

    cursor: pointer;

    transition: all 0.2s ease;
}

.lesson-nav-scroll-btn:hover {
    background: #0f172a;
    color: white;
    border-color: #0f172a;
}

.lesson-nav-scroll-btn:disabled {
    opacity: 0.35;
    cursor: default;
    background: #f8fafc;
    color: #94a3b8;
    border-color: #e2e8f0;
}

.lesson-section {
    scroll-margin-top: 8rem;
    padding: 2rem 0;
    border-top: 1px solid #e5e7eb;
}

@media (max-width: 640px) {
    .lesson-anchor-nav-wrapper {
        grid-template-columns: minmax(0, 1fr);
    }

    .lesson-nav-scroll-btn {
        display: none;
    }

    .lesson-anchor-nav {
        scrollbar-width: thin;
    }

    .lesson-anchor-nav::-webkit-scrollbar {
        display: block;
        height: 4px;
    }
}

.lesson-slide-btn {
    appearance: none;
    border: none;
    cursor: pointer;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    padding: 0.65rem 1.1rem;
    border-radius: 999px;

    background: #0f172a;
    color: white;

    font-size: 0.95rem;
    font-weight: 600;

    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.16);
    transition: all 0.25s ease;

    margin-top: 1rem;
    margin-bottom: 1.5rem;
}

.lesson-slide-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.22);
}

.lesson-slide-btn:active {
    transform: scale(0.98);
}

.slides-controls {
    margin-top: 1.5rem;
    margin-bottom: 1rem;

    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
}

/* space above slide controls */
#backToStudyBtn,
#fullscreenBtn,
#slideThemeBtn.
 printPdfBtn {
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
    margin-right: 0.6rem;
}

#backToStudyBtn {
    background: transparent;
    color: #334155;

    border: 1px solid rgba(148, 163, 184, 0.4);

    white-space: nowrap;

    transition: all 0.2s ease;
}

#backToStudyBtn:hover {
    border-color: #0f172a;
    color: #0f172a;
}
.hidden {
    display: none !important;
}

/* ===== Study Tables ===== */
.study-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;

    font-size: 0.95rem;
    border-radius: 12px;
    overflow: hidden;

    box-shadow: 0 8px 25px rgba(15, 23, 42, 0.06);
}

/* Header row */
.study-table thead th {
    background: #EBEBEB;
    color: #475569;
    font-weight: 600;
    text-align: left;
    padding: 0.75rem 1rem;
}

/* Normal cells */
.study-table td {
    padding: 0.7rem 1rem;
    border-bottom: 1px solid #e5e7eb;
    color: #334155;
}

/* First column (labels like "Place value") */
.study-table tbody td:first-child {
    font-weight: 600;
    background: #f8fafc;
}

/* Zebra striping */
.study-table tr:nth-child(even) td {
    background: #f9fafb;
}

/* Hover effect (nice touch) */
.study-table tr:hover td {
    background: #f1f5f9;
}

.topic-top-nav {
    margin-bottom: 2rem;
}

.secondary-button {
    background: transparent;
    color: #334155;
    border: 1px solid #cbd5e1;
}

.secondary-button:hover {
    background: #f8fafc;
    border-color: #94a3b8;
    color: #0f172a;
}

.learning-label a {
    color: inherit;
    text-decoration: none;
}

.learning-label a:hover {
    text-decoration: underline;
}

/* ===== Pedagogical Content Boxes ===== */

.learning-objectives-box,
.key-term-box,
.warning-box,
.exam-tip-box,
.practice-box {
    margin: 1.25rem 0;
    padding: 1rem 1.15rem;
    border-radius: 18px;
    line-height: 1.65;
}

/* Learning objectives */
.learning-objectives-box {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e3a8a;
}

/* Key terms / definitions */
.key-term-box {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    color: #334155;
}

/* Important warnings / common mistakes */
.warning-box {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    color: #7c2d12;
}

/* Exam advice */
.exam-tip-box {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #14532d;
}

/* Practice questions */
.practice-box {
    background: #faf5ff;
    border: 1px solid #e9d5ff;
    color: #581c87;
}

.learning-objectives-box h3,
.practice-box h3,
.warning-box h3,
.exam-tip-box h3 {
    margin-top: 0;
}

.clickable-study-image {
    max-width: 760px;
    margin: 1.5rem auto;
    text-align: center;
}

.clickable-study-image img {
    width: 100%;
    height: auto;
    border-radius: 18px;
    display: block;
    margin: 0 auto;
    cursor: zoom-in;
}

.study-image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: rgba(15, 23, 42, 0.94);

    display: none;
    align-items: center;
    justify-content: center;

    padding: 1rem;
}

.study-image-lightbox.active {
    display: flex;
}

.study-image-lightbox img {
    width: auto;
    height: auto;
    max-width: 98vw;
    max-height: 94vh;
    object-fit: contain;
    border-radius: 18px;
    background: white;
}

.study-image-lightbox button {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1000000;

    width: 48px;
    height: 48px;
    border-radius: 999px;
    border: none;

    background: white;
    color: #0f172a;

    font-size: 1.8rem;
    cursor: pointer;
}


/* ===== Previous / Next topic navigation ===== */
.topic-sequence-nav {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: stretch;
    gap: 0.8rem;

    margin: 1.5rem 0 2rem;
}

.topic-sequence-link,
.topic-sequence-home {
    text-decoration: none;
    border-radius: 20px;
    border: 1px solid #e2e8f0;
    background: white;
    color: #0f172a;

    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.05);
    transition: all 0.2s ease;
}

.topic-sequence-link {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 1rem 1.1rem;
}

.topic-sequence-link span {
    color: #64748b;
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.topic-sequence-link strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    font-size: 0.98rem;
    line-height: 1.3;
}

.topic-sequence-link.next {
    text-align: right;
    align-items: flex-end;
}

.topic-sequence-home {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    padding: 0 1.1rem;
    font-size: 0.9rem;
    font-weight: 800;
    white-space: nowrap;
}

.topic-sequence-link:hover,
.topic-sequence-home:hover {
    transform: translateY(-2px);
    border-color: #0f172a;
    box-shadow: 0 16px 38px rgba(15, 23, 42, 0.10);
}

.topic-sequence-link.disabled {
    opacity: 0.45;
    background: #f8fafc;
    box-shadow: none;
}

.topic-sequence-link.disabled:hover {
    transform: none;
    border-color: #e2e8f0;
}

@media (max-width: 720px) {
    .topic-sequence-nav {
        grid-template-columns: 1fr;
    }

    .topic-sequence-link.next {
        text-align: left;
        align-items: flex-start;
    }

    .topic-sequence-home {
        min-height: 46px;
    }
}

/* ===== Back to Top button ===== */
/* ===== Fixed Back to Top button - fancy version ===== */
.back-to-top-btn {
    position: fixed;
    right: 1.6rem;
    bottom: 1.6rem;
    z-index: 9999;

    width: 56px;
    height: 56px;
    border-radius: 999px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    border: 1px solid rgba(255, 255, 255, 0.35);

    background:
        radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.35), transparent 28%),
        linear-gradient(135deg, #5b5fa8, #0f172a);

    color: white;

    font-size: 1.55rem;
    font-weight: 900;
    line-height: 1;

    cursor: pointer;

    box-shadow:
        0 18px 38px rgba(15, 23, 42, 0.28),
        0 0 0 6px rgba(91, 95, 168, 0.10);

    opacity: 0;
    visibility: hidden;

    transform: translateY(14px) scale(0.92);

    transition:
        opacity 0.25s ease,
        visibility 0.25s ease,
        transform 0.25s ease,
        box-shadow 0.25s ease,
        background 0.25s ease;
}

.back-to-top-btn.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.back-to-top-btn:hover {
    transform: translateY(-5px) scale(1.05);

    background:
        radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.42), transparent 28%),
        linear-gradient(135deg, #e6004f, #5b5fa8);

    box-shadow:
        0 22px 46px rgba(15, 23, 42, 0.34),
        0 0 0 8px rgba(230, 0, 79, 0.12);
}

.back-to-top-btn:active {
    transform: translateY(-2px) scale(0.96);
}

.back-to-top-btn::before {
    content: "";
    position: absolute;
    inset: -7px;

    border-radius: 999px;
    border: 1px solid rgba(91, 95, 168, 0.22);

    opacity: 0;
    transform: scale(0.85);

    transition:
        opacity 0.25s ease,
        transform 0.25s ease;
}

.back-to-top-btn:hover::before {
    opacity: 1;
    transform: scale(1);
}

@media (max-width: 640px) {
    .back-to-top-btn {
        right: 1rem;
        bottom: 1rem;

        width: 48px;
        height: 48px;

        font-size: 1.3rem;
    }
}

/* ===== Course topic search ===== */

.course-search-box {
    margin-bottom: 2rem;
    padding: 1.25rem;
    border-radius: 22px;

    background: white;
    border: 1px solid #e2e8f0;

    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.06);
}

.course-search-box label {
    display: block;
    margin-bottom: 0.55rem;

    color: #334155;
    font-size: 0.9rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.course-search-input-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.5rem;
    align-items: center;
}

.course-search-input-row input {
    width: 100%;

    padding: 0.85rem 1rem;
    border-radius: 999px;

    border: 1px solid #cbd5e1;
    background: #f8fafc;

    color: #0f172a;
    font-size: 1rem;

    outline: none;
    transition: all 0.2s ease;
}

.course-search-input-row input:focus {
    border-color: #5b5fa8;
    background: white;

    box-shadow:
        0 0 0 4px rgba(91, 95, 168, 0.12),
        0 10px 24px rgba(15, 23, 42, 0.06);
}

.course-search-input-row button {
    width: 42px;
    height: 42px;

    border-radius: 999px;
    border: 1px solid #cbd5e1;

    background: white;
    color: #64748b;

    font-size: 1.45rem;
    font-weight: 700;
    line-height: 1;

    cursor: pointer;
    transition: all 0.2s ease;
}

.course-search-input-row button:hover {
    background: #0f172a;
    color: white;
    border-color: #0f172a;
}

.course-search-summary {
    margin: 0.75rem 0 0;
    color: #64748b;
    font-size: 0.92rem;
}

.course-no-results {
    margin-bottom: 2rem;
    padding: 1.2rem;

    border-radius: 18px;
    background: #fff7ed;
    border: 1px solid #fed7aa;
    color: #7c2d12;

    font-weight: 700;
}

.course-search-hidden {
    display: none !important;
}

.topic-card.search-match {
    border-color: rgba(91, 95, 168, 0.45);
    box-shadow:
        0 14px 34px rgba(91, 95, 168, 0.12),
        inset 4px 0 0 #5b5fa8;
}

/* ===== ChatGPT-style left lesson contents sidebar ===== */

/* Wider shell only for topic pages */
.topic-wide-shell {
    width: min(100%, 1680px);
    padding-left: 1.25rem;
    padding-right: 1.25rem;
}

/* Main reading layout */
.topic-reading-layout {
    position: relative;
    display: block;
}

/* Fixed/sticky left contents area */
.topic-side-toc {
    position: fixed;
    top: 5.5rem;
    left: 1.25rem;
    z-index: 40;

    width: 250px;
    max-width: 250px;
}

/* Contents card */
.topic-side-toc-card {
    max-height: calc(100vh - 7rem);
    overflow-y: auto;

    padding: 1rem;
    border-radius: 22px;

    background: rgba(248, 250, 252, 0.96);
    border: 1px solid #e2e8f0;

    box-shadow: 0 14px 36px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(10px);
}

/* Header */
.topic-side-toc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;

    padding-bottom: 0.75rem;
    margin-bottom: 0.75rem;

    border-bottom: 1px solid #e2e8f0;
}

.topic-side-toc-header strong {
    color: #0f172a;
    font-size: 1rem;
    font-weight: 900;
}

.topic-side-toc-header button {
    border: none;
    border-radius: 8px;

    padding: 0.25rem 0.55rem;

    background: #e5e7eb;
    color: #334155;

    font-size: 0.8rem;
    cursor: pointer;
}

.topic-side-toc-header button:hover {
    background: #0f172a;
    color: white;
}

/* Auto-generated links */
.auto-lesson-toc {
    display: grid;
    gap: 0.15rem;
}

.auto-lesson-toc a {
    display: block;

    padding: 0.42rem 0.55rem;
    border-radius: 10px;

    color: #475569;
    text-decoration: none;

    font-size: 0.9rem;
    line-height: 1.35;

    border-left: 3px solid transparent;

    transition: all 0.18s ease;
}

.auto-lesson-toc a:hover {
    background: #eef2ff;
    color: #34387f;
}

.auto-lesson-toc a.active {
    background: #eef2ff;
    color: #34387f;

    font-weight: 900;
    border-left-color: #5b5fa8;
}

/* The content gets most of the available space */
.topic-reading-main {
    width: min(calc(100vw - 340px), 1120px);
    margin-left: 290px;
    margin-right: 1.25rem;
    min-width: 0;
}

/* Let the study card use the available width nicely */
.topic-reading-main .study-content {
    width: 100%;
    box-sizing: border-box;
}

.topic-reading-main .topic-sequence-nav {
    gap: 0.65rem;
}

.topic-reading-main .topic-sequence-link {
    padding: 0.9rem 1rem;
}

.topic-reading-main .topic-sequence-home {
    padding: 0 1rem;
}

/* Hide/collapse state */
.topic-reading-layout.toc-collapsed .topic-side-toc {
    display: none;
}

.topic-reading-layout.toc-collapsed .topic-reading-main {
    margin-left: auto;
    margin-right: auto;
}

/* Hide sidebar when slides are open */
.topic-side-toc.hidden-for-slides {
    display: none;
}

/* Old top lesson navigation should disappear */
.study-content > .lesson-anchor-nav,
.study-content > .lesson-anchor-nav-wrapper {
    display: none !important;
}

/* Medium screens: reduce menu width but keep it if possible */
@media (max-width: 1280px) {
    .topic-side-toc {
        width: 220px;
        max-width: 220px;
    }

    .topic-reading-main {
        margin-left: 250px;
        margin-right: 1rem;
        width: calc(100vw - 290px);
    }

    .auto-lesson-toc a {
        font-size: 0.84rem;
    }
}

/* Smaller screens: remove the side menu and use full width */
@media (max-width: 980px) {
    .topic-wide-shell {
        width: min(100%, calc(100% - 1rem));
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .topic-side-toc {
        display: none;
    }

    .topic-reading-main {
        width: 100%;
        margin-left: 0;
        margin-right: 0;
    }
}

/* ===== Show contents button after sidebar is hidden ===== */

.show-topic-toc-btn {
    position: fixed;
    top: 5.5rem;
    left: 1.25rem;
    z-index: 45;

    padding: 0.65rem 1rem;
    border-radius: 999px;

    border: 1px solid #e2e8f0;
    background: white;
    color: #34387f;

    font-size: 0.9rem;
    font-weight: 900;

    cursor: pointer;

    box-shadow: 0 14px 34px rgba(15, 23, 42, 0.12);
    transition: all 0.2s ease;
}

.show-topic-toc-btn:hover {
    transform: translateY(-2px);
    background: #0f172a;
    color: white;
    border-color: #0f172a;
}

/* When the sidebar is collapsed, show the restore button */
.topic-reading-layout.toc-collapsed .show-topic-toc-btn {
    display: inline-flex !important;
}

/* When the sidebar is visible, keep the restore button hidden */
.topic-reading-layout:not(.toc-collapsed) .show-topic-toc-btn {
    display: none !important;
}

/* Do not show it on smaller screens where the sidebar is removed anyway */
@media (max-width: 980px) {
    .show-topic-toc-btn {
        display: none !important;
    }
}

/* ===== Centre slide mode and minimise sidebar automatically ===== */

/* When slides are open, hide the left contents menu */
.topic-reading-layout.slides-open .topic-side-toc {
    display: none;
}

/* Also hide the small restore button while slides are open */
.topic-reading-layout.slides-open .show-topic-toc-btn {
    display: none !important;
}

/* When slides are open, centre the main column */
.topic-reading-layout.slides-open .topic-reading-main {
    width: min(100%, 1280px);
    margin-left: auto;
    margin-right: auto;
}

/* In slide mode, allow the slide wrapper to use more space */
.topic-reading-layout.slides-open .slides-wrapper {
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

/* Optional: make the slide frame a little wider than the study notes */
.topic-reading-layout.slides-open #slidesMode {
    max-width: 1280px;
}

/* Keep the top controls centred with the slide area */
.topic-reading-layout.slides-open .slides-controls {
    justify-content: flex-start;
}

/* Hide study-only navigation while slides are open if needed */
.topic-reading-layout.slides-open #studyMode {
    display: none !important;
}

/* On smaller screens, keep everything full width */
@media (max-width: 980px) {
    .topic-reading-layout.slides-open .topic-reading-main {
        width: 100%;
        margin-left: 0;
        margin-right: 0;
    }
}

/* ===== Disclaimer of the origin of the material ===== */

.resource-disclaimer {
    max-width: 700px;
    margin-top: 1rem;
    padding-top: 0.9rem;
    border-top: 1px solid #e2e8f0;

    color: #64748b;
    font-size: 0.82rem;
    line-height: 1.5;
}
