/* ============================================================================
   Printable worksheets (worksheet.js): the #screen-worksheet controls, the
   on-screen paper preview, and the @media print rules that print only the
   sheet on A4 (Chrome and Safari). Themes follow the year's pack:
   junior = big type and pictures, teen = calm and light (the sky palette), system font.
   ============================================================================ */

/* ---- Hub entry (For Parents area) ---- */
.ws-open {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    min-height: var(--tap);
    margin-top: var(--sp-3);
    padding: var(--sp-3) var(--sp-5);
    border-radius: var(--r-lg);
    background: var(--c-surface);
    border: 2px solid var(--blue-line);
    box-shadow: var(--sh-clay);
    color: var(--blue-ink);
    text-decoration: none;
    line-height: 1.35;
}
.parents-section .ws-open { color: var(--blue-ink); font-weight: 600; }
.ws-open:hover { box-shadow: var(--sh-clay-hover); }
.ws-open-icon { font-size: 1.8rem; flex-shrink: 0; }
.ws-open b { display: block; font-size: var(--fs-lg); font-weight: 900; }
.ws-open small { display: block; font-size: var(--fs-sm); color: var(--c-ink-soft); }

/* ---- Screen ---- */
#screen-worksheet.active {
    display: block;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--c-surface-soft);
    padding: 0 var(--sp-4) var(--sp-10);
}
.ws-header { max-width: 210mm; }

.ws-controls {
    max-width: 210mm;
    margin: 0 auto var(--sp-4);
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--sp-3);
    padding: var(--sp-4);
    background: var(--c-surface);
    border: 2px solid var(--c-line);
    border-radius: var(--r-md);
}
.ws-controls label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1 1 140px;
    font-size: var(--fs-sm);
    font-weight: 800;
    color: var(--c-ink);
}
.ws-controls select {
    min-height: var(--tap);
    padding: 0 var(--sp-3);
    border: 2px solid var(--c-line);
    border-radius: var(--r-sm);
    background: var(--c-surface);
    font-weight: 700;
}
.ws-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); flex: 1 1 100%; }
.ws-actions .btn { flex: 1 1 160px; }
.ws-tip { flex: 1 1 100%; font-size: var(--fs-xs); color: var(--c-ink-soft); }

/* ---- The paper ---- */
.ws-sheet {
    max-width: 210mm;
    margin: 0 auto;
    padding: 12mm;
    background: var(--c-surface);
    color: var(--c-ink);
    border-radius: 4px;
    box-shadow: var(--sh-card);
    font-size: 11.5pt;
    line-height: 1.45;
}
.ws-status { padding: var(--sp-8) 0; text-align: center; color: var(--c-ink-soft); }

.ws-head { display: flex; align-items: center; gap: var(--sp-3); }
.ws-logo { width: auto; height: 64px; }
.ws-wordmark { width: auto; height: 30px; }
.ws-title { font-size: 1.35em; margin-top: 2px; }

.ws-fields {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2) var(--sp-5);
    margin: var(--sp-4) 0 var(--sp-5);
    padding-bottom: var(--sp-3);
    border-bottom: 2px solid var(--c-ink);
    font-weight: 800;
}
.ws-fields p { display: flex; align-items: flex-end; gap: 6px; flex: 1 1 150px; }
.ws-fields p:first-child { flex: 2 1 240px; }
.ws-fields .ws-score { flex: 0 0 auto; }
.ws-fields .ws-score .ws-line { min-width: 3em; flex: 0 0 3em; }
.ws-line {
    display: inline-block;
    flex: 1 1 auto;
    min-width: 6em;
    height: 1.4em;
    border-bottom: 1.5px solid var(--c-ink);
}

/* Questions */
.ws-q {
    display: grid;
    grid-template-columns: 2em 1fr;
    gap: var(--sp-3);
    padding: var(--sp-3) 0;
    border-bottom: 1px solid var(--c-line);
    break-inside: avoid;
    page-break-inside: avoid;
}
.ws-num {
    width: 1.8em;
    height: 1.8em;
    border: 2px solid var(--c-ink);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 0.95em;
}
.ws-q-body { min-width: 0; }
.ws-prompt { font-weight: 700; }
.ws-hint { font-weight: 600; font-size: 0.9em; color: var(--c-ink-soft); }
.ws-tag {
    display: inline-block;
    margin-bottom: 4px;
    padding: 0 6px;
    border: 1px solid var(--c-ink-soft);
    border-radius: 4px;
    font-size: 0.78em;
    font-weight: 800;
    color: var(--c-ink-soft);
}
.ws-say {
    margin-bottom: 6px;
    padding: 4px 8px;
    border: 1.5px dashed var(--c-ink-soft);
    border-radius: 6px;
    font-size: 0.9em;
}
.ws-visual { margin: var(--sp-2) 0; }
.ws-visual svg, .ws-visual img { max-width: 100%; max-height: 220px; width: auto; height: auto; }
.ws-visual > svg:only-child { max-width: 320px; }
.ws-sheet .nq-sentence, .ws-sheet .nq-blank { background: none; }
.ws-sheet .nq-sentence { display: inline-block; margin-top: 4px; padding: 2px 0; font-weight: 600; }

.ws-choices {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px var(--sp-4);
    margin-top: var(--sp-2);
}
.ws-choices-long { grid-template-columns: 1fr; }
.ws-choices li, .ws-tiles li { display: flex; align-items: center; gap: 8px; }
.ws-letter {
    flex-shrink: 0;
    width: 1.6em;
    height: 1.6em;
    border: 1.5px solid var(--c-ink);
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 0.85em;
}

.ws-tiles { list-style: none; display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-top: var(--sp-2); }
.ws-tiles li {
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 5.5em;
    padding: 6px 10px;
    border: 1.5px solid var(--c-line);
    border-radius: 10px;
}
.ws-tiles .ws-letter { align-self: flex-start; }
.ws-tile-emoji { font-size: 2.2em; line-height: 1.1; }
.ws-tile-html svg { max-height: 90px; width: auto; }
.ws-tiles img { max-height: 90px; width: auto; }
.ws-tile-label { font-weight: 700; font-size: 0.9em; }

.ws-multi, .ws-order { list-style: none; margin-top: var(--sp-2); display: grid; gap: 6px; }
.ws-multi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ws-multi li, .ws-order li { display: flex; align-items: flex-start; gap: 8px; }
.ws-tick, .ws-box {
    flex-shrink: 0;
    width: 1.3em;
    height: 1.3em;
    border: 1.5px solid var(--c-ink);
    border-radius: 3px;
}
.ws-box { width: 1.8em; height: 1.6em; }

.ws-sentence { margin-top: var(--sp-2); font-size: 1.12em; line-height: 2; font-weight: 600; }
.ws-read-word { font-family: 'Andika', 'Nunito', sans-serif; font-size: 2.6rem; font-weight: 700; margin: var(--sp-2) 0 0; }
.ws-read-word span { display: block; }
.ws-letters { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--sp-2); }
.ws-letters span {
    width: 1.8em;
    height: 1.8em;
    border: 1.5px solid var(--c-ink);
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 1.2em;
}
.ws-answer { display: flex; align-items: flex-end; gap: 6px; margin-top: var(--sp-3); max-width: 70%; font-weight: 800; }

.ws-passage {
    margin: var(--sp-4) 0 var(--sp-2);
    padding: var(--sp-3) var(--sp-4);
    border: 1.5px solid var(--c-ink-soft);
    border-radius: 8px;
}
.ws-passage h3 { font-size: 1.1em; margin-bottom: 6px; break-after: avoid; page-break-after: avoid; }
.ws-passage h3 em { font-weight: 700; font-size: 0.8em; color: var(--c-ink-soft); }
.ws-sheet .nq-passage-body { max-height: none; overflow: visible; padding: 0; background: none; border: 0; font-size: 1em; }

.ws-foot { margin-top: var(--sp-5); font-size: 0.75em; color: var(--c-ink-soft); text-align: center; }

/* Answer key: its own page when printed */
.ws-key {
    margin-top: var(--sp-8);
    padding-top: var(--sp-5);
    border-top: 3px dashed var(--c-line);
    font-size: 0.92em;
}
.ws-key-title { font-size: 1.25em; margin-bottom: var(--sp-3); }
.ws-dictation { margin-bottom: var(--sp-4); padding: var(--sp-3); border: 1.5px dashed var(--c-ink-soft); border-radius: 8px; }
.ws-dictation h3 { font-size: 1em; margin-bottom: 4px; }
.ws-dictation ol, .ws-key-list { padding-left: 2em; }
.ws-dictation li span { color: var(--c-ink-soft); }
.ws-key-list > li { padding: 4px 0; border-bottom: 1px solid var(--c-line); break-inside: avoid; page-break-inside: avoid; }
.ws-key-ans { display: block; font-weight: 800; }
.ws-key-why { display: block; color: var(--c-ink-soft); }
.ws-key-why ol, .ws-key-why ul, .ws-key-order { padding-left: 1.4em; }

/* Prep to Year 2: large type and bigger pictures */
.ws-sheet[data-theme="junior"] { font-size: 15pt; }
.ws-sheet[data-theme="junior"] .ws-tile-emoji { font-size: 3em; }
.ws-sheet[data-theme="junior"] .ws-tiles li { min-width: 6.5em; }
.ws-sheet[data-theme="junior"] .ws-q { padding: var(--sp-4) 0; }
.ws-sheet[data-theme="junior"] .ws-line { height: 1.8em; }
.ws-sheet[data-theme="junior"] .ws-key { font-size: 0.8em; }

/* Years 7 and 9: calm, light sky palette, squarer, system font, no mascot */
.ws-sheet[data-theme="teen"] {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    font-size: 10.5pt;
    color: var(--c-ink);
}
.ws-sheet[data-theme="teen"] .ws-logo { display: none; }
.ws-sheet[data-theme="teen"] .ws-wordmark { height: 24px; }
.ws-sheet[data-theme="teen"] .ws-title { color: var(--c-brand-dark); font-weight: 800; }
.ws-sheet[data-theme="teen"] .ws-num { border-radius: 4px; border-color: var(--c-brand-dark); color: var(--c-brand-dark); }
.ws-sheet[data-theme="teen"] .ws-letter { border-radius: 3px; }
.ws-sheet[data-theme="teen"] .ws-fields { border-bottom-color: var(--c-brand-dark); }
.ws-sheet[data-theme="teen"] .ws-passage,
.ws-sheet[data-theme="teen"] .ws-tiles li { border-radius: 2px; }

@media (max-width: 600px) {
    .ws-sheet { padding: var(--sp-4); font-size: 11pt; }
    .ws-choices, .ws-multi { grid-template-columns: 1fr; }
    .ws-answer { max-width: none; }
}

/* ---- Print: only the sheet, on A4 ---- */
@page { size: A4; margin: 12mm 12mm 14mm; }

@media print {
    html, body {
        background: #FFFFFF !important;
        min-height: 0 !important;
        height: auto !important;
        overflow: visible !important;
    }
    body > *:not(#screen-worksheet) { display: none !important; }
    #screen-worksheet,
    #screen-worksheet.active {
        display: block !important;
        position: static !important;
        inset: auto;
        width: auto;
        height: auto !important;
        overflow: visible !important;
        padding: 0 !important;
        background: #FFFFFF !important;
        animation: none !important;
    }
    #screen-worksheet > :not(#ws-sheet) { display: none !important; }
    .ws-sheet {
        max-width: none;
        margin: 0;
        padding: 0;
        box-shadow: none;
        border-radius: 0;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .ws-key {
        break-before: page;
        page-break-before: always;
        margin-top: 0;
        padding-top: 0;
        border-top: 0;
    }
    .ws-foot { break-after: avoid; }
}
