/* ==========================================================================
   Layout — page wrappers, containers, the course sidebar grid.
   ========================================================================== */

/* Sticky footer: the site column fills the viewport, main takes up the slack. */
.stsed-site {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.stsed-site__main {
    flex: 1;
    padding-block: var( --stsed-space-lg ) var( --stsed-space-2xl );
}

/* --- Containers --------------------------------------------------------- */

.stsed-container {
    width: 100%;
    max-width: var( --stsed-container );
    margin-inline: auto;
    padding-inline: var( --stsed-space-sm );
}

.stsed-container--narrow {
    max-width: var( --stsed-container-narrow );
}

.stsed-container--flush {
    padding-inline: 0;
}

/* --- The content card --------------------------------------------------
   Pages sit on a white surface above the off-white page background. */

.stsed-content-area {
    background: var( --stsed-color-surface );
    border: 1px solid var( --stsed-color-border );
    border-radius: var( --stsed-radius-lg );
    box-shadow: var( --stsed-shadow-sm );
    padding: var( --stsed-space-lg );
}

@media ( min-width: 48em ) {
    .stsed-content-area {
        padding: var( --stsed-space-xl );
    }
}

/* Long-form reading measure. Wide/full blocks opt out via the rules below. */
.stsed-content > * {
    /* max-width: var( --stsed-measure ); */
}

.stsed-content > .alignwide,
.stsed-content > .alignfull,
.stsed-content > .stsed-lms-outline,
.stsed-content > figure,
.stsed-content > table,
.stsed-content > .wp-block-table,
.stsed-content > .wp-block-columns,
.stsed-content > .wp-block-gallery,
.stsed-content > .wp-block-embed {
    max-width: none;
}

.stsed-content > .alignfull {
    /* Break out of the padded card to the full card width. */
    margin-inline: calc( var( --stsed-space-lg ) * -1 );
}

@media ( min-width: 48em ) {
    .stsed-content > .alignfull {
        margin-inline: calc( var( --stsed-space-xl ) * -1 );
    }
}

.stsed-content > .aligncenter {
    margin-inline: auto;
}

/* --- Page header -------------------------------------------------------- */

.stsed-page-header {
    margin-block-end: var( --stsed-space-md );
}

.stsed-page-header__title {
    font-size: var( --stsed-text-3xl );
}

.stsed-page-header__meta {
    color: var( --stsed-color-text-muted );
    font-size: var( --stsed-text-sm );
    margin-block-start: var( --stsed-space-3xs );
}

/* ==========================================================================
   Course sidebar layout

   LMS lessons and quizzes only (body.stsed-has-course-sidebar, set by
   inc/template.php). Everything else on the site is a single column.

   The sidebar is a SIBLING of the article, never a wrapper — the lesson body
   has to keep rendering through the_content() inside the main loop or the
   plugin's Mark Complete control (appended via the_content filter) disappears.
   ========================================================================== */

.stsed-course-layout {
    display: grid;
    gap: var( --stsed-space-md );
    align-items: start;
}

@media ( min-width: 62em ) {
    .stsed-course-layout {
        grid-template-columns: minmax( 0, var( --stsed-sidebar-width ) ) minmax( 0, 1fr );
        gap: var( --stsed-space-lg );
    }
}

.stsed-course-layout__sidebar {
    min-width: 0;
}

@media ( min-width: 62em ) {
    .stsed-course-layout__sidebar {
        position: sticky;
        /* Clears the sticky header, plus a little breathing room. */
        top: var( --stsed-space-sm );
        max-height: calc( 100vh - var( --stsed-space-lg ) );
        overflow-y: auto;
        overscroll-behavior: contain;
    }
}

.stsed-course-layout__content {
    min-width: 0;
}

/* Below the breakpoint the sidebar becomes a collapsible disclosure above the
   lesson, so the content stays the first thing you see on a phone. */
.stsed-course-nav {
    background: var( --stsed-color-surface );
    border: 1px solid var( --stsed-color-border );
    border-radius: var( --stsed-radius-lg );
    box-shadow: var( --stsed-shadow-sm );
    overflow: hidden;
}

.stsed-course-nav__summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var( --stsed-space-2xs );
    padding: var( --stsed-space-xs ) var( --stsed-space-sm );
    font-weight: var( --stsed-weight-semibold );
    cursor: pointer;
    list-style: none;
    background: var( --stsed-color-surface-sunken );
    border-block-end: 1px solid var( --stsed-color-border );
}

.stsed-course-nav__summary::-webkit-details-marker {
    display: none;
}

.stsed-course-nav__summary::after {
    content: "";
    width: 0.5em;
    height: 0.5em;
    border-inline-end: 2px solid currentColor;
    border-block-end: 2px solid currentColor;
    transform: rotate( 45deg );
    transition: transform var( --stsed-transition );
    flex: none;
}

.stsed-course-nav[open] .stsed-course-nav__summary::after {
    transform: rotate( -135deg );
}

.stsed-course-nav__body {
    padding: var( --stsed-space-xs );
}

.stsed-course-nav__course {
    display: block;
    font-size: var( --stsed-text-sm );
    color: var( --stsed-color-text-muted );
    padding: var( --stsed-space-2xs ) var( --stsed-space-2xs ) var( --stsed-space-xs );
}

/* On wide screens the disclosure is always open and the toggle is irrelevant. */
@media ( min-width: 62em ) {
    .stsed-course-nav__summary {
        cursor: default;
        pointer-events: none;
    }

    .stsed-course-nav__summary::after {
        display: none;
    }
}

/* --- Screen-reader-only ------------------------------------------------- */

.screen-reader-text {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset( 50% );
    white-space: nowrap;
    border: 0;
}

.screen-reader-text:focus {
    position: fixed !important;
    top: var( --stsed-space-2xs );
    left: var( --stsed-space-2xs );
    z-index: 1000;
    width: auto;
    height: auto;
    clip-path: none;
    padding: var( --stsed-space-2xs ) var( --stsed-space-sm );
    background: var( --stsed-color-surface );
    color: var( --stsed-color-link );
    border-radius: var( --stsed-radius-sm );
    box-shadow: var( --stsed-shadow-md );
}

/* WordPress admin bar offset for the sticky header. */
.admin-bar .stsed-header {
    top: 32px;
}

@media screen and ( max-width: 782px ) {
    .admin-bar .stsed-header {
        top: 46px;
    }
}
