/* The lesson is a cover; every section opens above it as a page of its own. */

/* The ears hang from the book, not from the page: this anchor is the book. */
.lesson-book-anchor {
    position: relative;
}

/* The book is the top page: whatever comes out of its edges has to pass
   underneath it, not sit beside it. */
.book-page {
    position: relative;
    z-index: 10;
    transform-origin: left center;
    transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* At rest the leaves already tilt a hair, so the edges below the cover are
   visible: an ear the visitor cannot see is an ear that does not exist. */
.lesson-cover-stack span:nth-child(1) {
    transform: translateX(-50%) rotate(-0.5deg);
}

.lesson-cover-stack span:nth-child(2) {
    transform: translateX(-51%) rotate(-1deg);
}

.lesson-cover-stack span:nth-child(3) {
    transform: translateX(-52%) rotate(-1.5deg);
}


/* Each ear is the edge of its own leaf, so it turns on the spine instead of
   sliding: the same gesture as a page coming out of a book. */
.lesson-tabs {
    perspective: 900px;
    transform-style: preserve-3d;
}

.lesson-tab {
    transform-origin: left center;
    backface-visibility: hidden;
}



/* The cover closes like a book: the cream page rests on stacked leaves. */
.lesson-cover-stack {
    position: relative;
    z-index: 8;
    height: 1.4rem;
    max-width: 96%;
    margin: 0 auto;
    pointer-events: none;
}

.lesson-cover-stack span {
    position: absolute;
    left: 50%;
    bottom: 0;
    height: 0.7rem;
    border-radius: 0 0 0.35rem 0.35rem;
    box-shadow: 0 12px 20px rgba(0, 0, 0, 0.3);
    transform: translateX(-50%);
}

.lesson-cover-stack span:nth-child(1) {
    width: 100%;
    background: #e6dac3;
}

.lesson-cover-stack span:nth-child(2) {
    width: 97.5%;
    bottom: 0.32rem;
    background: #f2e9d7;
}

.lesson-cover-stack span:nth-child(3) {
    width: 95%;
    bottom: 0.64rem;
    background: #fdfbf7;
}

/* The breadcrumb lives on the page, not on its edge. */
.lesson-breadcrumb {
    padding: 1.75rem 2rem 0;
}

@media (min-width: 768px) {
    .lesson-breadcrumb {
        padding: 2.5rem 3.5rem 0;
    }
}

/* Section buttons live inside the cover, at its foot: a single card, not a
   book spread. They read as the page's own index. */
.lesson-tabs {
    position: relative;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.6rem;
    padding: 1.5rem 1rem 2rem;
    margin: 0 auto;
    max-width: 40rem;
}

.lesson-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.1rem;
    border: 1px solid rgba(28, 24, 19, 0.16);
    border-left-width: 3px;
    border-radius: 0.55rem;
    background: linear-gradient(160deg, #fdfbf7, #efe4cd);
    color: #4a4034;
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    transform: none;
    transition: transform 0.2s ease, box-shadow 0.2s ease,
        background 0.2s ease, color 0.2s ease;
}

.lesson-tab i {
    font-size: 0.9rem;
    opacity: 0.8;
}

.lesson-tab:hover,
.lesson-tab:focus-visible {
    background: #fdfbf7;
    color: #2a2620;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.18);
    outline: none;
}

/* The button that opened the page that is currently open. */
.lesson-tab.is-active {
    transform: none;
    background: linear-gradient(160deg, #b08d57, #96764a);
    color: #fffdf8;
}

/* Each section keeps the ink of its leaf, so the ears read at a glance. */
.lesson-tab--theory {
    border-left: 3px solid #8a6d3b;
}

.lesson-tab--tools {
    border-left: 3px solid #1e3a5f;
}

.lesson-tab--video {
    border-left: 3px solid #a14242;
}

.lesson-tab--quiz {
    border-left: 3px solid #3d6b4f;
}

/* Modal page */

/* Closed pages stay laid out but invisible: the score renderers measure their
   container on load, and a display:none ancestor would leave them blank. */
.lesson-modal[hidden] {
    display: flex;
    visibility: hidden;
    pointer-events: none;
}

.lesson-modal {
    position: fixed;
    inset: 0;
    /* Above the site header (200001) and the mobile bar, so the X is always
       reachable on every screen. */
    z-index: 300000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
}

.lesson-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(16, 13, 10, 0.62);
    backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 0.22s ease;
}

.lesson-modal.is-open .lesson-modal-backdrop {
    opacity: 1;
}

.lesson-modal-page {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100rem;
    max-height: calc(100dvh - 2.5rem);
    height: calc(100dvh - 2.5rem);
    border-radius: 1rem;
    /* The page is not blank paper: the topic's own artwork sits under it, pale
       enough to write on and present enough to belong to the lesson. */
    background-color: #fffdf8;
    background-image: linear-gradient(
            180deg,
            rgba(255, 253, 248, 0.93) 0%,
            rgba(250, 246, 236, 0.96) 100%
        ),
        var(--lesson-art, none);
    background-size: cover;
    background-position: center;
    border: 1px solid #e2d9c7;
    box-shadow: 0 40px 90px rgba(0, 0, 0, 0.45);
    opacity: 0;
    /* The page is pulled out of the book by the ear on its right edge, so it
       enters from that side and returns there when it closes. */
    transform-origin: right center;
    transform: translate(16%, 12px) scale(0.985) rotate(0.4deg);
    transition: opacity 0.24s ease, transform 0.24s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.lesson-modal.is-open .lesson-modal-page {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.lesson-modal-head {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.1rem 1.5rem;
    border-bottom: 1px solid #ece3d2;
    border-radius: 1rem 1rem 0 0;
    background: linear-gradient(180deg, #f8f2e5, #fffdf8);
}

.lesson-modal-title {
    font-family: ui-serif, Georgia, serif;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: #8a6f43;
}

.lesson-modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.2rem;
    height: 2.2rem;
    border: 1px solid #e2d9c7;
    border-radius: 999px;
    background: #fffdf8;
    color: #8b7e6d;
    cursor: pointer;
    transition: color 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.lesson-modal-close:hover,
.lesson-modal-close:focus-visible {
    color: #2a2620;
    border-color: #b08d57;
    transform: rotate(90deg);
    outline: none;
}

.lesson-modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 1.5rem;
}

html.lesson-modal-open,
html.lesson-modal-open body {
    overflow: hidden;
}

@media (max-width: 768px) {
    /* On a phone the buttons keep their in-flow row, just a bit tighter. */
    .lesson-tabs {
        gap: 0.45rem;
        padding: 1rem 0.5rem 1.5rem;
    }

    .lesson-tab {
        padding: 0.6rem 0.9rem;
        font-size: 0.6rem;
    }

    /* On a phone the page sits between the site bars instead of under them: the
       header (1.75rem) and the bottom menu (3.75rem) keep their space, so the
       close button is always tappable and nothing is hidden behind the chrome. */
    .lesson-modal {
        padding: 1.75rem 0 3.75rem;
        align-items: stretch;
    }

    .lesson-modal-page {
        width: 100%;
        max-width: none;
        max-height: none;
        height: 100%;
        border: 0;
        border-radius: 0;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .lesson-modal-head {
        padding-top: calc(0.9rem + env(safe-area-inset-top));
        padding-bottom: 0.9rem;
    }

    .lesson-modal-close {
        width: 2.6rem;
        height: 2.6rem;
    }

    .lesson-modal-body {
        padding: 1rem;
    }
}

