/* HavenHub Math - Print Stylesheet */
/* Optimized for US Letter (8.5 x 11) */

@import url('https://fonts.googleapis.com/css2?family=Comic+Neue:wght@400;700&family=Lora:ital,wght@0,400;0,700;1,400&display=swap');

/* GLOBAL RESET FOR SIZING */
* {
    box-sizing: border-box;
}

:root {
    --primary-color: #2c3e50;
    --accent-color: #3498db;
    --line-color: #bdc3c7;
}

body {
    font-family: 'Lora', serif;
    font-size: 14pt;
    line-height: 1.6;
    color: #333;
    max-width: 8.5in;
    margin: 0 auto;
    padding: 0;
    background: white;
}

/* Page Setup */
@page {
    size: letter;
    margin: 0.5in; /* Reduced margin to prevent overflow */
}

.page-break {
    page-break-before: always;
}

/* Hide trailing page breaks to prevent blank end pages */
body > .page-break:last-of-type {
    display: none;
}

/* Cover Page */
.cover-page {
    height: 9in;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    border: 5px double var(--primary-color);
    margin-bottom: 2in;
}

.cover-title {
    font-family: 'Comic Neue', cursive;
    font-size: 48pt;
    font-weight: bold;
    color: var(--primary-color);
    margin: 0;
}

.cover-subtitle {
    font-size: 24pt;
    color: var(--accent-color);
    margin-top: 20px;
}

.cover-edition {
    font-size: 18pt;
    margin-top: 50px;
    font-style: italic;
}

/* Headers */
h1 {
    font-family: 'Comic Neue', cursive;
    color: var(--primary-color);
    border-bottom: 3px solid var(--accent-color);
    padding-bottom: 10px;
    margin-top: 0;
}

h2 {
    font-family: 'Comic Neue', cursive;
    color: var(--accent-color);
    margin-top: 30px;
    border-bottom: 1px solid var(--line-color);
}

h3 {
    font-size: 16pt;
    color: #555;
    margin-top: 20px;
    background-color: #f9f9f9;
    padding: 5px 10px;
    border-left: 5px solid var(--accent-color);
}

/* Question Styles */
.problem-set {
    margin-left: 20px;
}

.problem {
    margin-bottom: 25px; /* Space for writing */
    display: flex;
    align-items: baseline;
}

.problem-number {
    font-weight: bold;
    margin-right: 15px;
    min-width: 25px;
}

.problem-text {
    flex-grow: 1;
}

/* Writing Spaces */
.answer-line {
    display: inline-block;
    border-bottom: 2px solid #333;
    width: 100px;
    margin-left: 10px;
}

.answer-box {
    border: 2px solid #7f8c8d;
    width: 50px;
    height: 50px;
    display: inline-block;
    vertical-align: middle;
    margin: 5px;
}

.big-answer-space {
    height: 100px;
    border: 1px dashed #ccc;
    margin-top: 10px;
    width: 100%;
}

/* Special Elements */
.hundred-chart {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 5px;
    margin: 20px 0;
    font-size: 10pt;
}

.chart-cell {
    border: 1px solid #ccc;
    padding: 5px;
    text-align: center;
}

.footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    text-align: center;
    font-size: 10pt;
    color: #999;
}

/* ========================================= */
/* PRINT OPTIMIZATION LAYER                  */
/* ========================================= */
@media print {
    /* 1. Reset Body for Paper */
    body {
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        background-color: white !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* 2. Prevent Box Fragmentation */
    /* This forces the printer to keep these containers whole */
    .script-box, 
    .repair-bench, 
    .signet-box, 
    .signet-challenge,
    .echad-box,
    .echad-extension,
    .prep-grid,
    .materials-box,
    .theology-box,
    .assessment-box,
    .problem-set,
    .problem,
    .visual-box,
    .digit-teaching,
    .digit-story,
    .trace-grid,
    .draw-box,
    .verification-node,
    .vow-box,
    .rhyme-box,
    .story-block,
    .principle-box,
    .highlight-box,
    .try-it {
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }

    /* 3. Header Gluing */
    /* Keeps headers attached to the content below them */
    h1, h2, h3, h4, .box-title {
        break-after: avoid !important;
        page-break-after: avoid !important;
    }

    /* 4. Explicit Page Breaks */
    /* Ensures .page-break class forces a new page */
    .page-break {
        break-after: page !important;
        page-break-after: always !important;
        height: 0;
        margin: 0;
    }

    /* 5. Clean Up */
    /* Hide screen-only elements if any exist */
    .no-print {
        display: none !important;
    }
}
