@import url('https://fonts.googleapis.com/css2?family=Crimson+Text:wght@400;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Dancing+Script:wght@400;500;600;700&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Crimson Text', serif;
    background-color: white;
    padding: 0;
    margin: 0;
}

.container {
    width: 148mm;
    height: 210mm;
    margin: 0;
    background-color: white;
    border: none;
    padding: 3mm;
    box-sizing: border-box;
    page-break-inside: avoid;
}

.header {
    background-color: #4a6741;
    color: white;
    text-align: center;
    padding: 8px;
    margin-bottom: 10px;
    position: relative;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 1px;
}

.header-icon {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
}

.header-icon.left {
    left: 20px;
}

.header-icon.right {
    right: 20px;
}

.section {
    margin-bottom: 6px;
    page-break-inside: avoid;
    page-break-before: auto;
    break-inside: avoid;
    orphans: 8;
    widows: 8;
}

/* Stronger grouping for subject sections */
.section + .section {
    page-break-before: avoid-page;
    break-before: avoid-page;
}

.section-title {
    color: #4a6741;
    font-size: 15px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 4px;
    padding-bottom: 2px;
    border-bottom: 1px solid #4a6741;
    position: relative;
    page-break-after: avoid;
    break-after: avoid;
    orphans: 3;
    widows: 3;
}

.section-title::before,
.section-title::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 40px;
    height: 2px;
    background-color: #4a6741;
}

.section-title::before {
    left: 20px;
}

.section-title::after {
    right: 20px;
}

.keywords-list {
    width: 100%;
    margin-bottom: 4px;
    page-break-inside: avoid;
}

.keyword-item {
    padding: 3px 5px;
    border-bottom: 1px solid #4a6741;
    font-size: 10px;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    margin-bottom: 1px;
    page-break-inside: avoid;
}

.keyword-item:nth-child(even) {
    background-color: #f9f7f2;
}

.keyword-term {
    font-weight: 600;
    color: #4a6741;
    margin-right: 10px;
}

.keyword-definition {
    font-weight: normal;
}

.section-icon {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
}

.decorative-icon {
    position: absolute;
    bottom: 20px;
    width: 60px;
    height: 60px;
}

.decorative-icon.left {
    left: 20px;
}

.decorative-icon.right {
    right: 20px;
}

.container {
    position: relative;
}

.motivational-text {
    position: absolute;
    bottom: 3mm;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    text-align: center;
    font-family: 'Dancing Script', cursive;
    font-size: 28px;
    color: #4a6741;
    font-weight: 700;
    background-color: rgba(255, 255, 255, 0.9);
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #4a6741;
    box-shadow: 0 2px 4px rgba(74, 103, 65, 0.2);
}

.english-section {
    position: relative;
}

.tripod-icon {
    position: absolute;
    right: 20px;
    top: 100px;
    width: 50px;
    height: 50px;
}

@media print {
    @page {
        size: A5;
        margin: 0mm;
    }
    
    body {
        margin: 0;
        padding: 0;
        background-color: white;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .container {
        width: 148mm;
        height: 210mm;
        margin: 0;
        border: none;
        padding: 3mm;
        box-sizing: border-box;
        background-color: white;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .section {
        margin-bottom: 3mm;
        page-break-inside: avoid;
        break-inside: avoid;
        orphans: 10;
        widows: 10;
    }

    /* Ensure subject sections stay together */
    .section:has(.section-title) {
        page-break-before: auto;
        break-before: auto;
        page-break-inside: avoid-page;
        break-inside: avoid-page;
    }

    /* Prevent section titles from being orphaned */
    .section-title {
        page-break-after: avoid;
        break-after: avoid;
        orphans: 3;
    }
    
    .keywords-table {
        page-break-inside: avoid;
    }
    
    .keywords-table tr {
        page-break-inside: avoid;
    }
    
    .keywords-table tr:nth-child(even) {
        background-color: #f9f7f2;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .keywords-table th {
        background-color: #2c3e2a;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .motivational-text {
        background-color: rgba(255, 255, 255, 0.9);
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        font-family: 'Dancing Script', cursive;
        font-size: 22px;
        padding: 6px 10px;
    }
}

/* Word Search Styles */
.word-search-section {
    margin-top: 20px;
}

.word-search-grid {
    width: 100%;
    border-collapse: collapse;
    margin: 15px auto;
    table-layout: fixed;
}

.word-search-grid td {
    width: calc(100% / 18);
    height: 28px;
    border: 1px solid #4a6741;
    text-align: center;
    vertical-align: middle;
    font-size: 16px;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    padding: 0;
    aspect-ratio: 1/1;
    box-sizing: border-box;
}

.word-list {
    margin-top: 8px;
}

.word-list h3 {
    color: #4a6741;
    font-size: 12px;
    margin-bottom: 6px;
}

.words {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.word-item {
    background-color: #f9f7f2;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: 600;
    color: #4a6741;
}

@media print {
    .word-search-grid {
        width: 100%;
    }
    
    .word-search-grid td {
        width: calc(100% / 18);
        height: 25px;
        font-size: 14px;
    }
    
    .word-list h3 {
        font-size: 12px;
    }
    
    .word-item {
        font-size: 9px;
        padding: 2px 6px;
    }
}
