/* ==== Public printable book page (print-to-PDF via Ctrl+P) ==== */
/* Watermark tokens are IDENTICAL to the exam print watermark
   (wwwroot/css/teacherportal/teacher-portal.css) so the filigran LOOKS
   the same. Do not change these values. */
:root {
    --watermark-logo-opacity: 0.20;
    --watermark-logo-tile-width: 600px;
    --watermark-logo-rotation: -15deg;
    --watermark-side-text-color: #000000;
    --watermark-print-bg: #ffffff;

    /* Book printable surface + component tokens */
    --book-print-ink: #16233a;
    --book-print-muted: #4a5568;
    --book-print-surface: #ffffff;
    --book-print-cover-bg: #0f2942;
    --book-print-cover-ink: #ffffff;
    --book-print-shadow: hsl(220 30% 18% / 22%);

    --revision-note-bg: #f1f6fb;
    --revision-note-border: #1f6feb;
    --revision-note-ink: #16233a;

    --book-download-btn-bg: #0d7a6f;
    --book-download-btn-bg-hover: #0a5e56;
    --book-download-btn-ink: #ffffff;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--book-print-surface);
    color: var(--book-print-ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Root printable container — watermark JS appends absolute tiles here,
   so it MUST be position: relative. */
#book-printable-page {
    position: relative;
    max-width: 820px;
    margin: 0 auto;
    padding: 24px 32px 64px;
    overflow-x: hidden; /* Safari < 16 fallback */
    overflow-x: clip;   /* rotated logo tiles yatay scrollbar yaratmasin */
}

/* ---- Watermark: copied faithfully from the exam print watermark ---- */
.watermark-side-text {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    writing-mode: vertical-rl;
    text-orientation: upright;
    font-size: 14px;
    color: var(--watermark-side-text-color);
    opacity: 0.2;
    font-weight: 700;
    pointer-events: none;
    user-select: none;
}

    .watermark-side-text.left {
        left: 0;
    }

    .watermark-side-text.right {
        right: 0;
    }

.watermark-logo-tile {
    position: absolute;
    pointer-events: none;
    opacity: var(--watermark-logo-opacity);
    width: var(--watermark-logo-tile-width);
    height: auto;
    transform: rotate(var(--watermark-logo-rotation));
    transform-origin: center center;
    user-select: none;
}

/* ---- Cover page ---- */
.book-cover {
    position: relative;
    z-index: 2;
    background: var(--book-print-surface);
    min-height: 100vh;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 0;
    text-align: center;
    page-break-after: always;
    break-after: page;
}

.book-cover__img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100vh;
    object-fit: contain;
}

.book-cover__placeholder {
    width: min(100%, 460px);
    aspect-ratio: 2 / 3;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    border-radius: 8px;
    background: var(--book-print-cover-bg);
    color: var(--book-print-cover-ink);
}

.book-cover__placeholder-title {
    font-size: clamp(1.8rem, 5vw, 3rem);
    font-weight: 900;
    line-height: 1.1;
}

.book-cover__title {
    margin: 0;
    font-size: clamp(1.6rem, 4vw, 2.4rem);
    font-weight: 900;
    line-height: 1.15;
}

.book-cover__subtitle {
    margin: 0;
    color: var(--book-print-muted);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-size: 0.9rem;
}

/* ---- Book sections ---- */
.book-section {
    position: relative;
    z-index: 1;
    break-inside: auto;
}

/* Each chapter change starts on a fresh page (Razor sets this class when
   the chapter value differs from the previous section). */
.book-section--chapter-start {
    break-before: page;
    page-break-before: always;
}

.book-section__chapter {
    margin: 0 0 16px;
    font-size: clamp(1.4rem, 3vw, 2rem);
    font-weight: 800;
    line-height: 1.2;
}

/* ---- Revision-questions callout ---- */
.revision-note {
    margin: 20px 0 8px;
    padding: 14px 18px;
    border-left: 4px solid var(--revision-note-border);
    border-radius: 0 6px 6px 0;
    background: var(--revision-note-bg);
    color: var(--revision-note-ink);
    font-size: 0.98rem;
    line-height: 1.5;
}

    .revision-note a {
        color: var(--revision-note-border);
        font-weight: 700;
    }

/* ---- On-screen Download button (hidden when printing) ---- */
.book-download-btn {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 1000;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    padding: 0 22px;
    border: none;
    border-radius: 999px;
    background: var(--book-download-btn-bg);
    color: var(--book-download-btn-ink);
    font-weight: 800;
    font-size: 0.98rem;
    cursor: pointer;
    box-shadow: 0 10px 30px var(--book-print-shadow);
    transition: transform 160ms ease, background-color 160ms ease;
}

    .book-download-btn:hover,
    .book-download-btn:focus {
        transform: translateY(-1px);
        background: var(--book-download-btn-bg-hover);
    }

/* ---- Print rules: clean PDF output + watermark protection ---- */
@page {
    margin: 14mm 12mm;
}

@media print {
    /* Keep watermark + callout colours in the PDF. Adding .reader-content forces
       the browser to honour the reader's callout/solution background colours
       (info/tip/warn/accent soft + details.solution / .book-question-solution)
       inside the printed content — one selector covers all descendants. */
    .watermark-side-text,
    .watermark-logo-tile,
    .revision-note,
    .book-cover,
    .reader-content {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Solutions are force-opened by JS, so the collapsible toggle is redundant. */
    #book-printable-page details > summary {
        display: none;
    }

    /* Absolute tiles must not be clipped at page edges */
    #book-printable-page {
        overflow: visible !important;
        max-width: none;
        margin: 0;
        padding: 0;
    }

    /* Inset only the flowing content so text isn't cramped against the paper
       edge (or the side watermark). Watermark tiles stay on #book-printable-page
       and still reach the page edges; the cover is untouched (full-bleed). */
    .reader-content {
        padding-top: 6mm;
        padding-left: 16mm;
        padding-right: 16mm;
    }

    /* Cover fills one full printed page; content starts on page 2.
       Subtract the top+bottom @page margins (14mm + 14mm = 28mm) so the
       cover fits the margined content area and never spills onto a 3rd
       (blank) page. */
    .book-cover {
        min-height: calc(100vh - 28mm);
        height: calc(100vh - 28mm);
    }

    .book-cover__img {
        max-height: calc(100vh - 28mm);
    }

    body {
        background: var(--watermark-print-bg) !important;
    }

    /* Never print the on-screen download button */
    #book-printable-page .book-download-btn,
    .book-download-btn {
        display: none !important;
    }
}
