/* DigiPrep site chrome — shared header and footer */

@import url("design-tokens.css");
@import url("page-shells.css");
@import url("lesson-notes.css");

:root {
    --dp-header-height: 64px;
    --dp-header-bg: var(--dp-surface);
    --dp-header-border: var(--dp-border);
    --dp-header-shadow: 0 1px 0 rgba(255, 255, 255, 0.04), 0 4px 16px rgba(0, 0, 0, 0.4);
    --dp-header-text: #ffffff;
    --dp-header-link: var(--dp-text-soft);
    --dp-header-link-hover: var(--dp-text);
}

/* ── Header ── */
header.dp-site-header {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    height: var(--dp-header-height) !important;
    min-height: var(--dp-header-height) !important;
    max-height: var(--dp-header-height) !important;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: var(--dp-header-bg) !important;
    border-bottom: 1px solid var(--dp-header-border);
    box-shadow: var(--dp-header-shadow);
    box-sizing: border-box;
    font-family: 'Open Sans', sans-serif;
    transform: none !important;
    text-align: left;
    width: 100%;
    display: block;
}

header.dp-site-header .dp-site-header__inner {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
    background: transparent !important;
}

header.dp-site-header .dp-site-header__logo {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--dp-header-text) !important;
    text-decoration: none;
    letter-spacing: -0.025em;
    line-height: 1;
    background: transparent !important;
    flex-shrink: 0;
    cursor: pointer;
    position: static !important;
    transform: none !important;
    width: auto !important;
    height: auto !important;
    padding: 0;
    margin: 0;
}

header.dp-site-header .dp-site-header__logo:hover {
    color: var(--dp-header-text) !important;
    text-decoration: none;
    opacity: 0.9;
}

header.dp-site-header .dp-site-header__auth {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

header.dp-site-header .dp-site-header__nav {
    display: flex;
    align-items: center;
    gap: 28px;
    background: transparent !important;
    position: static !important;
    transform: none !important;
    padding: 0;
    margin: 0;
    margin-left: auto;
    height: auto !important;
    width: auto !important;
    font-size: inherit;
}

header.dp-site-header .dp-site-header__link {
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--dp-header-link) !important;
    text-decoration: none;
    background: transparent !important;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s ease;
}

header.dp-site-header .dp-site-header__link:hover {
    color: var(--dp-header-link-hover) !important;
    text-decoration: none;
}

/* ── Lesson back link ── */
.dp-lesson-back {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    width: fit-content;
    margin-bottom: 1.25rem;
    padding: 0.45rem 0.85rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--dp-text-soft) !important;
    text-decoration: none;
    background-color: var(--dp-card);
    border: 1px solid var(--dp-border);
    border-radius: var(--dp-radius-sm);
    transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
    cursor: pointer;
}

.dp-lesson-back:hover {
    color: var(--dp-text) !important;
    border-color: var(--dp-border-strong);
    background-color: var(--dp-card-hover);
    text-decoration: none;
}

.dp-lesson-back__icon {
    font-size: 1rem;
    line-height: 1;
    background: transparent !important;
}

header.dp-site-header .dp-lesson-back--header {
    display: inline-flex;
    margin-bottom: 0;
    padding: 0;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--dp-header-link) !important;
    background: transparent !important;
    border: none;
    border-radius: 0;
}

header.dp-site-header .dp-lesson-back--header:hover {
    color: var(--dp-header-link-hover) !important;
    background: transparent !important;
}

header.dp-site-header .dp-lesson-back--header.is-suppressed {
    display: none !important;
}

/* ── Page layout: fixed header clearance ── */
body.dp-has-site-header:not([data-digiprep-viewer="true"]):not(.dp-page-home) {
    padding-top: var(--dp-header-height) !important;
    box-sizing: border-box;
}

body.dp-has-site-header:not([data-digiprep-viewer="true"]):not(.dp-page-home) .mainarea {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

/* Home landing: fixed header + margin clearance, flex mainarea */
body.dp-has-site-header.dp-page-home header.dp-site-header {
    position: fixed !important;
    top: 0;
}

body.dp-has-site-header.dp-page-home {
    padding-top: 0 !important;
    overflow-x: hidden;
}

body.dp-has-site-header.dp-page-home .mainarea {
    display: flex;
    align-items: stretch;
    justify-content: flex-start;
    margin-top: var(--dp-header-height) !important;
    padding: clamp(20px, 4vh, 32px) 20px clamp(24px, 5vh, 40px) !important;
    min-height: calc(100vh - var(--dp-header-height)) !important;
    height: auto !important;
    max-height: none !important;
    overflow-x: hidden;
    overflow-y: visible;
    box-sizing: border-box;
}

/* Lesson pages without side ads: scroll naturally (FAQ, etc.) */
body.dp-page-lesson:not(:has(.mainarea .ad-space)) {
    display: block !important;
    height: auto !important;
    min-height: 100vh;
    overflow-x: hidden;
}

body.dp-page-lesson:not(:has(.mainarea .ad-space)) .mainarea {
    display: flex !important;
    flex: none !important;
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    align-items: flex-start !important;
}

body.dp-page-lesson:not(:has(.mainarea .ad-space)) .lesson-content {
    max-height: none !important;
    overflow-y: visible !important;
}

/* Lesson pages with side ads: lock viewport height, scroll lesson content only */
body.dp-has-site-header.dp-page-lesson:has(.mainarea .ad-space) {
    height: 100vh;
    overflow: hidden;
    box-sizing: border-box;
}

body.dp-page-lesson .mainarea:has(.ad-space) {
    display: flex !important;
    flex-direction: row;
    align-items: stretch !important;
    height: calc(100vh - var(--dp-header-height)) !important;
    max-height: calc(100vh - var(--dp-header-height)) !important;
    min-height: 0 !important;
    overflow: hidden !important;
}

body.dp-page-lesson .mainarea:has(.ad-space) .ad-space {
    width: 15%;
    flex-shrink: 0;
    align-self: stretch;
    min-height: calc(100vh - var(--dp-header-height));
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: clamp(1rem, 2.5vh, 1.75rem) 0.65rem 1rem;
    background-color: var(--dp-lesson-bg);
    border: none;
    font-size: 0;
    line-height: 0;
    color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

/* Placeholder slot — styled via pseudo-elements; live ad markup replaces inner content */
body.dp-page-lesson .mainarea:has(.ad-space) .ad-space::before {
    content: "";
    display: block;
    width: min(100%, 11rem);
    min-height: clamp(12rem, 38vh, 22rem);
    flex-shrink: 0;
    border-radius: var(--dp-radius-md);
    border: 1px dashed var(--dp-border-strong);
    background-color: var(--dp-card);
    background-image:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 24 24' fill='none' stroke='rgba(255%2C255%2C255%2C0.18)' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='2'/%3E%3Ccircle cx='8.5' cy='8.5' r='1.5'/%3E%3Cpath d='m21 15-5-5L5 21'/%3E%3C/svg%3E"),
        linear-gradient(
            135deg,
            rgba(255, 255, 255, 0.025) 25%,
            transparent 25%,
            transparent 50%,
            rgba(255, 255, 255, 0.025) 50%,
            rgba(255, 255, 255, 0.025) 75%,
            transparent 75%,
            transparent
        );
    background-position: center, 0 0;
    background-size: 2.25rem 2.25rem, 10px 10px;
    background-repeat: no-repeat, repeat;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), var(--dp-shadow-card);
}

body.dp-page-lesson .mainarea:has(.ad-space) .ad-space::after {
    content: "Advertisement";
    display: block;
    margin-top: 0.65rem;
    font-size: 0.625rem;
    line-height: 1.35;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--dp-muted);
    text-align: center;
}

/* Live ad units: drop placeholder chrome when real markup is injected */
body.dp-page-lesson .mainarea:has(.ad-space) .ad-space:has(ins, iframe, .adsbygoogle) {
    padding: 0.65rem 0.5rem;
    font-size: inherit;
    line-height: inherit;
    color: inherit;
}

body.dp-page-lesson .mainarea:has(.ad-space) .ad-space:has(ins, iframe, .adsbygoogle)::before,
body.dp-page-lesson .mainarea:has(.ad-space) .ad-space:has(ins, iframe, .adsbygoogle)::after {
    content: none;
    display: none;
}

body.dp-page-lesson .mainarea:has(.ad-space) .lesson-content {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    max-height: 100%;
    overflow-y: auto !important;
    overflow-x: hidden;
}

/* Long-form pages (FAQ, privacy, chapter lists) */
body.dp-page-scroll .mainarea {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    min-height: calc(100vh - var(--dp-header-height));
}

/* ── Viewer pages ── */
body.dp-has-site-header[data-digiprep-viewer="true"] {
    padding-top: 0 !important;
}

body.dp-has-site-header[data-digiprep-viewer="true"] .app-layout {
    height: calc(100vh - var(--dp-header-height)) !important;
    margin-top: var(--dp-header-height) !important;
    max-height: calc(100vh - var(--dp-header-height));
}

@media (max-width: 960px) {
    body.dp-page-lesson .mainarea:has(.ad-space) .ad-space {
        display: none;
    }

    body.dp-has-site-header.dp-page-lesson:has(.mainarea .ad-space) {
        height: auto;
        overflow-x: hidden;
        overflow-y: visible;
    }

    body.dp-page-lesson .mainarea:has(.ad-space) {
        height: auto !important;
        max-height: none !important;
        min-height: calc(100vh - var(--dp-header-height)) !important;
        overflow: visible !important;
    }

    body.dp-page-lesson .mainarea:has(.ad-space) .lesson-content {
        max-height: none;
        overflow-y: visible !important;
    }
}

@media (max-width: 768px) {
    header.dp-site-header .dp-site-header__inner {
        padding: 0 10px;
    }

    header.dp-site-header .dp-site-header__logo {
        font-size: 1.2rem;
    }

    header.dp-site-header .dp-site-header__link {
        font-size: 0.875rem;
    }
}

/* ── Footer ── */
.dp-site-footer,
footer.dp-site-footer {
    text-align: center;
    padding: 24px 16px 32px;
    color: var(--dp-text-soft);
    font-family: 'Open Sans', sans-serif;
    font-size: 14px;
    margin-top: 2rem;
    flex-shrink: 0;
}

.dp-site-footer p {
    margin: 0 0 8px;
}

.dp-site-footer a {
    color: #9cf;
    text-decoration: none;
}

.dp-site-footer a:hover {
    text-decoration: underline;
}

.dp-site-footer .dp-bug-footer-link {
    margin-top: 4px;
}

/* ── iPad landscape-only guard ── */
html.is-ipad-portrait-locked body {
    overflow: hidden;
}

#dp-ipad-orientation-lock {
    display: none;
}

html.is-ipad-portrait-locked #dp-ipad-orientation-lock {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 100000;
    align-items: center;
    justify-content: center;
    background: var(--dp-bg, #0b0b0b);
    padding: 24px;
    text-align: center;
}

.dp-ipad-orientation-lock__content {
    max-width: 20rem;
}

.dp-ipad-orientation-lock__icon {
    display: block;
    font-size: 3rem;
    line-height: 1;
    margin-bottom: 1rem;
    transform: rotate(90deg);
    color: rgba(255, 255, 255, 0.85);
}

.dp-ipad-orientation-lock__title {
    font-family: 'Open Sans', sans-serif;
    font-size: 1.25rem;
    font-weight: 600;
    color: #fff;
    margin: 0 0 0.5rem;
}

.dp-ipad-orientation-lock__hint {
    font-family: 'Open Sans', sans-serif;
    font-size: 0.95rem;
    color: rgba(255, 255, 255, 0.65);
    margin: 0;
}
