@font-face {
    font-family: 'Balsamiq Sans';
    src: url('./BalsamiqSans-Bold.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
    font-display: swap; /* Prevent invisible text during font load */
}

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

body, h1, .tool-link, .button-description {
    font-family: 'Balsamiq Sans', Arial, sans-serif;
}

body {
    background: #62CECC;
    min-height: 100vh;
    position: relative;
}

/* Use flex layout only at large desktop size: width > 1200px AND height > 1100px */
@media (min-width: 1201px){
    body {
        display: flex;
        flex-direction: column;
    }
}

/* Personalizer pages: different background and always flex */
body:has(.back-button),
body:has(.container) {
    font-family: 'Balsamiq Sans', sans-serif;
    background: #42d1cd;
    display: flex;
    flex-direction: column;
    padding: 20px;
}

@media (min-width: 1201px) {
    body:has(.back-button),
    body:has(.container) {
        display: flex;
        flex-direction: column;
    }
}

/* Page Header */
.page-header {
    text-align: center;
    margin: 20px auto 30px;
    max-width: 500px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

/* Personalizer page header */
.page-header.page-form-header {
    margin-bottom: 20px;
    padding: 0;
}

@media (min-width: 768px) {
    .page-header.page-form-header {
        margin: 20px auto;
    }
}

/* Header/H1 Styles - Index page */
.page-header h1 {
    position: relative;
    width: 100%;
    text-align: center;
    color: #333;
    font-size: 2.2em;
    background-image: url('./images/bugs-mega-pack-personalized-pre-k-worksheets.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center bottom;
    min-height: 122px;
}

/* Personalizer h1 styles */
body:has(.back-button) .page-header h1,
body:has(.container) .page-header h1 {
    position: relative;
    color: #000;
    margin-bottom: 10px;
    font-size: 2.5em;
    font-weight: 700;
    font-family: 'Balsamiq Sans', sans-serif;
    background-image: none;
    min-height: auto;
}

h1 span {
    opacity: 0;
    height: 90px;
    font-size: 1.2em;
    line-height: 1;
    display: block;
    overflow: hidden;
}

/* Animation for title bug icons - 3 degree step rotation */
@keyframes rotateStep {
    0%, 49.99% { transform: translateY(-50%) rotate(0deg); }
    50%, 100% { transform: translateY(-50%) rotate(3deg); }
}

/* Mobile version without translateY */
@keyframes rotateStepMobile {
    0%, 49.99% { transform: rotate(0deg); }
    50%, 100% { transform: rotate(3deg); }
}

/* Desktop/Tablet: Show bugs on both sides - Index page */
@media (min-width: 768px) {
    .page-header{
        margin: 45px auto 30px;
    }

    .page-header h1::before {
        content: '';
        position: absolute;
        left: -183px;
        top: 53px;
        transform: translateY(-50%);
        width: 233px;
        height: 143px;
        background-image: url('./images/title-bug-2.png');
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center;
        animation: rotateStep 1400ms steps(2) infinite;
    }
    .page-header h1::after {
        content: '';
        position: absolute;
        right: -130px;
        top: 47px;
        transform: translateY(-50%);
        width: 178px;
        height: 139px;
        background-image: url('./images/title-bug-1.png');
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center;
        animation: rotateStep 1400ms steps(2) infinite;
    }
}

/* Desktop/Tablet: Show bugs on both sides - Personalizer pages */
@media (min-width: 768px) {
    body:has(.back-button) h1::before,
    body:has(.container) h1::before {
        content: '';
        position: absolute;
        left: -100px;
        top: 50%;
        transform: translateY(-50%);
        width: 60px;
        height: 60px;
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center;
        animation: rotateStep 1400ms steps(2) infinite;
    }
    body:has(.back-button) h1::after,
    body:has(.container) h1::after {
        content: '';
        position: absolute;
        right: -100px;
        top: 50%;
        transform: translateY(-50%);
        width: 60px;
        height: 60px;
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center;
        animation: rotateStep 1400ms steps(2) infinite;
    }
}

@media (min-width: 1201px) {
    .page-header{
        margin: 90px auto 30px;
    }
}

/* Mobile: Show only one bug before title - Index page */
@media (max-width: 767px) {
    .page-header h1 {
        font-size: 1.3em;
        min-height: 120px;
    }

    .page-header h1 span{
        height: 19vw;
    }

    .page-header h1::before {
        content: '';
        display: block;
        height: 35vw;
        border-left: 14vw solid transparent;
        background-image: url('./images/title-bug-1.png');
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center;
        animation: rotateStepMobile 1400ms steps(2) infinite;
    }
}

/* Mobile: Show only one bug before title - Personalizer pages */
@media (max-width: 767px) {
    body:has(.back-button) h1,
    body:has(.container) h1 {
        font-size: 2em;
    }
    
    body:has(.back-button) h1::before,
    body:has(.container) h1::before {
        content: '';
        display: block;
        width: 50px;
        height: 50px;
        margin: 0 auto 10px;
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center;
        animation: rotateStepMobile 1400ms steps(2) infinite;
    }

    body:has(.back-button) .page-header.page-form-header h1::before,
    body:has(.container) .page-header.page-form-header h1::before {
        width: 300px;
        height: 60px;
        background-size: auto 100%;
        animation: rotateStepMobile 1400ms steps(2) infinite;
    }

    body:has(.back-button) h1::after,
    body:has(.container) h1::after {
        display: none;
    }
}

@media (min-width: 501px) and (max-width: 767px) {
    .page-header h1 span{
        height: 105px;
    }

    .page-header h1::before {
        height: 160px;
        border-left: 73px solid transparent;
        animation: rotateStepMobile 1400ms steps(2) infinite;
    }
}

/* Page-specific bug icon styles */

/* Words page */
@media (min-width: 768px) {

    body:has(.back-button) .page-words::before,
    body:has(.container) .page-words::before {
        background-image: url('./images/icon-bug-02.png');
        width: 100px;
        height: 100px;
        left: -35px;
    }
    body:has(.back-button) .page-words::after,
    body:has(.container) .page-words::after {
        background-image: url('./images/icon-bug-03.png'); 
        width: 130px;
        height: 90px;
        right: -95px;
    }
}

@media (max-width: 767px) {
    body:has(.back-button) .page-words::before,
    body:has(.container) .page-words::before {
        background-image: url('./images/icon-bug-03.png');
        border-left: 0 solid transparent;
    }
}

/* Math page */
@media (min-width: 768px) {
    body:has(.back-button) .page-math::before,
    body:has(.container) .page-math::before {
        background-image: url('./images/icon-bug-04.png');
        width: 100px;
        height: 40px;
        left: -45px;
    }
    body:has(.back-button) .page-math::after,
    body:has(.container) .page-math::after {
        background-image: url('./images/icon-bug-05.png');
        width: 130px;
        height: 50px;
        right: -75px;
    }
}

@media (max-width: 767px) {
    body:has(.back-button) .page-math::before,
    body:has(.container) .page-math::before {
        background-image: url('./images/icon-bug-05.png');
        border-left: 0 solid transparent;
    }
}

/* Drawing page */
@media (min-width: 768px) {
    body:has(.back-button) .page-drawing::before,
    body:has(.container) .page-drawing::before {
        background-image: url('./images/icon-bug-06.png');
        width: 70px;
        height: 60px;
        top: 20px;
        left: 85px;
    }
    body:has(.back-button) .page-drawing::after,
    body:has(.container) .page-drawing::after {
        background-image: url('./images/icon-bug-07.png');
        width: 80px;
        height: 70px;
        right: 75px;
        top: 20px;
    }
}

@media (max-width: 767px) {
    body:has(.back-button) .page-drawing::before,
    body:has(.container) .page-drawing::before {
        background-image: url('./images/icon-bug-07.png');
        border-left: 0 solid transparent;
    }
}

/* Puzzles page */
@media (min-width: 768px) {
    body:has(.back-button) .page-puzzles::before,
    body:has(.container) .page-puzzles::before {
        background-image: url('./images/icon-bug-10.png');
        width: 70px;
        height: 70px;
        left: 85px;
        top: 15px;
    }
    body:has(.back-button) .page-puzzles::after,
    body:has(.container) .page-puzzles::after {
        background-image: url('./images/icon-bug-12.png');
        width: 70px;
        height: 70px;
        right: 85px;
        top: 20px;
    }
}

@media (max-width: 767px) {
    body:has(.back-button) .page-puzzles::before,
    body:has(.container) .page-puzzles::before {
        background-image: url('./images/icon-bug-11.png');
        border-left: 0 solid transparent;
    }
}

/* MiniBook page */
@media (min-width: 768px) {
    body:has(.back-button) .page-minibook::before,
    body:has(.container) .page-minibook::before {
        background-image: url('./images/icon-bug-16.png');
        width: 70px;
        height: 70px;
        left: 55px;
        top: 15px;
    }
    body:has(.back-button) .page-minibook::after,
    body:has(.container) .page-minibook::after {
        background-image: url('./images/icon-bug-13.png');
        width: 80px;
        height: 80px;
        right: 55px;
        top: 10px;
    }
}

@media (max-width: 767px) {
    body:has(.back-button) .page-minibook::before,
    body:has(.container) .page-minibook::before {
        background-image: url('./images/icon-bug-13.png');
        border-left: 0 solid transparent;
    }
}

.page-description {
    color: #000;
    font-size: 1.1em;
    margin-top: 10px;
    font-weight: 400;
    font-family: 'Balsamiq Sans', sans-serif;
}

/* Main Content - Buttons Container - Index page */
.links {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 40px;
    justify-content: center;
    flex: 1;
    padding: 30px 20px;
}

/* Vertically center links only at desktop size: width > 1200px AND height > 1100px */
@media (min-width: 1201px){
    .links {
        align-items: center;
        flex: 0 0 auto;
        margin: auto;
        gap: 60px;
    }
}

/* Button Container - Now an anchor element */
.tool-link-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 230px;
    text-decoration: none;
}

/* Animated Background Images - Spritesheet approach */
.tool-link-wrapper::before {
    content: '';
    position: absolute;
    transform: translate(-50%, -50%);
    top: 39%;
    left: 50%;
    width: 100%;
    height: 100%;
    background-size: 200% auto;
    background-repeat: no-repeat;
    background-position: 0 0;
    z-index: 0;
    animation: toggleSpritesheet 1400ms infinite;
    will-change: background-position; /* Optimize animation performance */
}

/* Set background images for each button (spritesheet versions) */
.tool-link-wrapper.words::before {
    background-image: url('./images/tool-preview-words.png');
}

.tool-link-wrapper.math::before {
    background-image: url('./images/tool-preview-math.png');
}

.tool-link-wrapper.drawing::before {
    background-image: url('./images/tool-preview-drawing.png');
}

.tool-link-wrapper.puzzles::before {
    background-image: url('./images/tool-preview-puzzles.png');
}

.tool-link-wrapper.books::before {
    background-image: url('./images/tool-preview-books.png');
}

/* Animation keyframes - shift background position every 700ms */
/* Button width is 300px. With background-size: 200% auto, image is 600px wide */
/* Each frame is 300px, so shift by -300px to show second frame */
/* Use 49.999% to ensure clean transition at exactly 50% */
@keyframes toggleSpritesheet {
    0%, 49.999% { background-position: 0 0; }
    50%, 100% { background-position: -300px 0; }
}

/* Button Styles */
.tool-link {
    position: relative;
    z-index: 1;
    display: block;
    padding: 18px 40px;
    width: 300px;
    background: #247674;
    color: white;
    text-decoration: none;
    border-radius: 3px;
    font-size: 1.5em;
    font-weight: bold;
    box-shadow: 0 4px 16px rgba(59,184,180,0.08);
    transition: background 0.2s, transform 0.2s;
    text-align: center;
}

.tool-link-wrapper:hover .tool-link {
    background: #2d6a6a;
    transform: translateY(-2px);
}

/* Button Description */
.tool-link-wrapper .button-description {
    position: relative;
    z-index: 1;
    margin-top: 10px;
    color: #185251;
    font-size: 1.1em;
    font-weight: 400;
    text-align: center;
    width: 300px;
}

/* Personalizer page styles */
.back-button {
    position: absolute;
    left: 24px;
    top: 24px;
    text-decoration: none;
    color: white;
    font-weight: bold;
    font-size: 1.1em;
    background: #247674;
    padding: 8px 18px;
    border-radius: 3px;
    box-shadow: 0 4px 16px rgba(59,184,180,0.08);
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 1000;
    transition: background 0.2s, transform 0.2s;
}

.back-button:hover {
    background: #2d6a6a;
    transform: translateY(-2px);
}

@media (max-width: 1023px) {
    .back-button {
        position: static;
        margin: 0 auto;
        display: flex;
        justify-content: center;
        width: fit-content;
    }
}

.container {
    background: white;
    border-radius: 3px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    padding: 40px;
    max-width: 500px;
    width: 100%;
    margin: 0 auto;
    text-align: center;
}

.subtitle {
    color: #3bb8b4;
    font-size: 1em;
    font-weight: 700;
    font-family: 'Balsamiq Sans', sans-serif;
    margin-bottom: 30px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.input-group {
    margin-bottom: 25px;
    text-align: left;
}

.input-group.hidden {
    display: none;
}

.input-group-with-icon {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    position: relative;
}

.input-group-with-icon label {
    flex: 1;
}

.input-group-icon-wrapper {
    position: relative;
    display: flex;
    gap: 10px;
    align-items: center;
}

.input-group-icon-wrapper .input-group-icon {
    width: 60px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-group-icon {
    width: 60px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-group-icon img {
    width: 40px;
    height: auto;
    object-fit: contain;
}

select {
    width: 100%;
    padding: 15px;
    border: 2px solid #e1e5e9;
    border-radius: 3px;
    font-size: 16px;
    transition: all 0.3s ease;
    background: #f8f9fa;
    font-family: 'Balsamiq Sans', sans-serif;
    font-weight: 400;
    cursor: pointer;
}

select:focus {
    outline: none;
    border-color: #667eea;
    background: white;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

label {
    display: block;
    margin-bottom: 8px;
    color: #222;
    font-weight: 700;
    font-size: 1.1em;
    font-family: 'Balsamiq Sans', sans-serif;
}

input[type="text"] {
    width: 100%;
    padding: 15px;
    border: 2px solid #e1e5e9;
    border-radius: 3px;
    font-size: 16px;
    transition: all 0.3s ease;
    background: #f8f9fa;
    font-family: 'Balsamiq Sans', sans-serif;
    font-weight: 400;
}

input[type="text"]:focus {
    outline: none;
    border-color: #667eea;
    background: white;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.placeholder-text {
    color: #999;
    font-size: 0.9em;
    margin-top: 5px;
    font-family: 'Balsamiq Sans', sans-serif;
    font-weight: 400;
}

.download-btn {
    background: #247674;
    color: white;
    border: none;
    padding: 18px 40px;
    border-radius: 3px;
    font-size: 1.6em;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    box-shadow: 0 4px 16px rgba(59,184,180,0.08);
    width: 100%;
    margin-top: 0;
    font-family: 'Balsamiq Sans', sans-serif;
}

.download-btn:hover {
    background: #2d6a6a;
    transform: translateY(-2px);
}

.download-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.loading {
    display: none;
    margin-top: 20px;
    color: #667eea;
    font-weight: 700;
    font-family: 'Balsamiq Sans', sans-serif;
}

.error {
    color: #e74c3c;
    margin-top: 15px;
    padding: 10px;
    background: #fdf2f2;
    border-radius: 3px;
    display: none;
    font-family: 'Balsamiq Sans', sans-serif;
    font-weight: 400;
}

.success {
    color: #27ae60;
    margin-top: 15px;
    padding: 10px;
    background: #f0f9f4;
    border-radius: 3px;
    display: none;
    font-family: 'Balsamiq Sans', sans-serif;
    font-weight: 400;
}

@media (max-width: 600px) {
    .container {
        padding: 30px 20px;
    }
    
    body:has(.back-button) h1,
    body:has(.container) h1 {
        font-size: 2em;
    }
}

.input-row {
    display: flex;
    align-items: stretch;
    gap: 20px;
}

.input-image {
    flex-shrink: 0;
    order: 2;
}

.placeholder-square {
    width: 60px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.placeholder-square img {
    width: 60px;
    height: 60px;
    object-fit: contain;
}

img#colorIcon {
    max-width: 80%;
    margin-top: 27px;
    height: 56px;
}

img#colorIcon[alt="Black & White"] {
    transform: rotate(7deg);  
}

img#colorIcon[alt="Full Color"] {
    transform: rotate(-7deg);  
}

img#sizeIcon {
    max-width: 60%;
    margin-top: 27px;
    height: 56px;
    transform: rotate(7deg);  
}

img#sizeIcon[alt="A4"] {
    transform: rotate(7deg);  
}

img#sizeIcon[alt="Letter"] {
    transform: rotate(-7deg);  
}

.input-content {
    flex: 1;
    order: 1;
}

.input-content label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #222;
}

.input-content input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e1e5e9;
    border-radius: 3px;
    font-size: 16px;
    transition: border-color 0.3s ease;
    box-sizing: border-box;
}

.input-content input:focus {
    outline: none;
    border-color: #3bb8b4;
}

.input-content .placeholder-text {
    margin-top: 6px;
    font-size: 14px;
    color: #7f8c8d;
}

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    color: #2d6a6a;
    font-family: 'Balsamiq Sans', Arial, sans-serif;
    font-weight: 400;
}

/* Fixed footer only for index page */
@media (min-width: 1024px) and (min-height: 800px) {
    body:has(.links) footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #62CECC;
    }
    body:has(.links) {
        padding-bottom: 80px; /* Space for fixed footer */
    }
}

@media (max-width: 767px) {
    .links {
        gap: 45px;
    }
}

/* —— Classroom gallery —— */
.pilot-banner {
    max-width: 640px;
    margin: 8px auto 0;
    padding: 0 16px;
    font-family: 'Balsamiq Sans', Arial, sans-serif;
    font-size: 1.05em;
    color: #185251;
    text-align: center;
}

.mode-switch {
    display: inline-flex;
    margin: 14px auto 0;
    padding: 3px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.55);
    gap: 0;
}

.page-header .mode-switch {
    display: flex;
    width: fit-content;
}

.mode-switch-btn {
    appearance: none;
    border: none;
    background: transparent;
    color: #185251;
    font-family: 'Balsamiq Sans', Arial, sans-serif;
    font-size: 1em;
    font-weight: 700;
    padding: 5px 12px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.mode-switch-btn.is-active {
    background: #247674;
    color: #fff;
}

.mode-switch-btn:not(.is-active):hover {
    background: rgba(36, 118, 116, 0.12);
}

.mode-blurb {
    max-width: 520px;
    margin: 10px auto 0;
    padding: 0 16px;
    font-family: 'Balsamiq Sans', Arial, sans-serif;
    font-size: 1.05em;
    color: #185251;
    text-align: center;
}

.form-mode-blurb {
    max-width: none;
    margin: 0 0 18px;
    padding: 0;
    text-align: left;
    color: #185251;
}

.pilot-footer-note {
    max-width: 520px;
    margin: 0 auto 10px;
    padding: 0 16px;
    font-family: 'Balsamiq Sans', Arial, sans-serif;
    font-size: 0.95em;
    line-height: 1.35;
    color: #2d6a6a;
}

.pilot-footer-note.pilot-disclaimer {
    font-size: 0.9em;
    margin-bottom: 16px;
}

.gallery-controls {
    max-width: 1100px;
    margin: 0 auto 16px;
    padding: 0 16px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
}

@media (min-width: 1200px) {
    .gallery-controls {
        width: min(1400px, calc(100% - 32px));
        max-width: 1400px;
        padding-left: 0;
        padding-right: 0;
    }
}

.filter-chips {
    display: contents; /* chips share one wrap line with Clear */
}

.chip {
    flex: 0 0 auto;
    border: none;
    background: rgba(255, 255, 255, 0.55); /* match mode-switch track */
    color: #185251;
    font-family: 'Balsamiq Sans', Arial, sans-serif;
    font-size: 0.95em;
    padding: 6px 11px;
    border-radius: 3px;
    cursor: pointer;
}

.chip-active,
.chip:hover {
    background: #247674;
    color: #fff;
}

.chip-clear {
    margin-top: 0;
    background: transparent;
    color: #185251;
}

.chip-clear[hidden] {
    display: none !important;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    max-width: 1100px;
    margin: 0 auto 24px;
    padding: 0 16px;
}

@media (min-width: 768px) {
    .gallery-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (min-width: 1200px) {
    .gallery-grid {
        width: min(1400px, calc(100% - 32px));
        max-width: 1400px;
        gap: 12px;
        padding-left: 0;
        padding-right: 0;
    }
}

@media (min-width: 1300px) {
    .gallery-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
}

.worksheet-card {
    --thumb-inset-x: 16px;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: #222;
    background: transparent;
    border-radius: 3px;
    overflow: visible;
    border: none;
    transition: background-color 0.2s ease, transform 0.15s ease;
}

.worksheet-card:hover,
.worksheet-card:focus-visible {
    background: rgba(255, 255, 255, 0.55);
    outline: none;
    transform: translateY(-2px);
}

.worksheet-card:has(.worksheet-card-media.has-pages) {
    --thumb-inset-x: 22px;
}

.worksheet-card img {
    width: 100%;
    height: auto;
    aspect-ratio: 8.5 / 11;
    object-fit: cover;
    background: #fff;
    display: block;
}

.worksheet-card-title {
    font-family: 'Balsamiq Sans', Arial, sans-serif;
    font-weight: 700;
    font-size: 20px; /* match .brand-title-main */
    line-height: 1.2;
    color: #185251;
    padding: 8px var(--thumb-inset-x) 2px;
}

@media (min-width: 768px) {
    .worksheet-card-title {
        font-size: 22px;
    }
}

.worksheet-card-skills {
    font-family: 'Balsamiq Sans', Arial, sans-serif;
    font-size: 0.8em;
    color: #247674;
    padding: 0 var(--thumb-inset-x) 10px;
}

/* Gallery thumbs: same inset size + drop shadow for single pages and stack front pages.
   Multi-page: back page offset behind-left with a slight tilt; fade when swapping. */
.worksheet-card-media {
    display: block;
    position: relative;
    --page-stack-shadow: 0 3px 10px rgba(0, 0, 0, 0.22);
    /* even L/R for single-page thumbs; room for shadow */
    padding: 14px var(--thumb-inset-x) 12px;
}

.worksheet-card-media.has-pages {
    /* extra left/top for back page peek */
    padding: 14px 12px 12px 22px;
}

.worksheet-card-stage {
    display: block;
    position: relative;
    aspect-ratio: 8.5 / 11;
    width: 100%;
}

/* Hover/focus CTA over the thumb — visual only; the card link is the real control.
   Soft white wash (not a dark dim) so the button reads clearly. */
.worksheet-card-stage::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 3;
    background: rgba(255, 255, 255, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.worksheet-card-cta {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 4;
    transform: translate(-50%, -50%) scale(0.96);
    background: #62CECC; /* match page window bg */
    color: #185251; /* match .brand-title-main */
    font-family: 'Balsamiq Sans', Arial, sans-serif;
    font-weight: 700;
    font-size: 20px; /* match .brand-title-main */
    line-height: 1.2;
    padding: 10px 18px;
    border-radius: 3px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

@media (min-width: 768px) {
    .worksheet-card-cta {
        font-size: 22px;
    }
}

@media (hover: hover) {
    .worksheet-card:hover .worksheet-card-stage::after,
    .worksheet-card:focus-visible .worksheet-card-stage::after {
        opacity: 1;
    }

    .worksheet-card:hover .worksheet-card-cta,
    .worksheet-card:focus-visible .worksheet-card-cta {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

@media (hover: none) {
    .worksheet-card:focus-visible .worksheet-card-stage::after {
        opacity: 1;
    }

    .worksheet-card:focus-visible .worksheet-card-cta {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

@media (prefers-reduced-motion: reduce) {
    .worksheet-card-stage::after,
    .worksheet-card-cta {
        transition: none;
    }
}

.worksheet-card-media:not(.has-pages) img,
.worksheet-card-media.has-pages img.worksheet-card-page {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background: #fff;
    box-shadow: var(--page-stack-shadow);
}

.worksheet-card-media.has-pages img.worksheet-card-page {
    opacity: 0;
    transform: translate(0, 0) rotate(0deg);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.worksheet-card-media.has-pages img[data-stack="front"] {
    z-index: 2;
    opacity: 1;
    transform: translate(0, 0) rotate(0deg);
}

.worksheet-card-media.has-pages img[data-stack="back"] {
    z-index: 1;
    opacity: 1;
    /* peek behind-left, slight tilt */
    transform: translate(-16px, -10px) rotate(-5deg);
}

.worksheet-card-media.has-pages img[data-stack="hidden"] {
    z-index: 0;
    opacity: 0;
    transform: translate(0, 0) rotate(0deg);
}

@media (prefers-reduced-motion: reduce) {
    .worksheet-card-media.has-pages img.worksheet-card-page {
        transition: none;
    }
}

/* Gallery multipage cards: no page dots (auto-cycle only). Page toggle lives on the form. */

.gallery-empty {
    text-align: center;
    font-family: 'Balsamiq Sans', Arial, sans-serif;
    color: #185251;
    padding: 40px 16px;
}

.pilot-footer {
    text-align: center;
    padding: 24px 16px 40px;
    color: #2d6a6a;
    font-family: 'Balsamiq Sans', Arial, sans-serif;
}

.pilot-footer a {
    color: #185251;
}

.worksheet-title-visible {
    opacity: 1 !important;
    background: none !important;
    color: #222 !important;
    font-size: 1.8em !important;
}

.container.worksheet-form-layout {
    /* Preview sits on page teal; only the form panel is white. */
    max-width: 980px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 28px;
    align-items: start;
    text-align: left;
    background: transparent;
    box-shadow: none;
    padding: 0;
}

@media (min-width: 860px) {
    .container.worksheet-form-layout {
        grid-template-columns: minmax(260px, 380px) minmax(280px, 1fr);
        gap: 36px;
        padding: 0;
    }
}

.worksheet-form-fields {
    min-width: 0;
    background: #fff;
    border-radius: 3px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    padding: 28px 24px 32px;
}

.worksheet-form-fields .download-btn {
    width: 100%;
}

.worksheet-preview {
    text-align: center;
    margin: 0;
    width: 100%;
    max-width: 380px;
    justify-self: center;
}

@media (min-width: 860px) {
    .worksheet-preview {
        justify-self: stretch;
        max-width: none;
        position: sticky;
        top: 16px;
    }
}

.worksheet-preview-stage {
    position: relative;
    width: 100%;
}

.worksheet-preview img {
    width: 100%;
    height: auto;
    aspect-ratio: 8.5 / 11;
    object-fit: cover;
    background: #fff;
    border-radius: 3px;
    border: none;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.22); /* match gallery thumb --page-stack-shadow */
    display: block;
}

.preview-page-toggle {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin: 12px 0 0;
}

.preview-page-toggle[hidden] {
    display: none !important;
}

.preview-page-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 8px 14px;
    border: 2px solid #247674;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.85);
    color: #185251;
    font-family: 'Balsamiq Sans', Arial, sans-serif;
    font-size: 1.05em;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
}

.preview-page-btn:hover,
.preview-page-btn:focus-visible {
    background: #fff;
    outline: none;
}

.preview-page-btn.is-active {
    background: #247674;
    color: #fff;
}

/* Preview sample captions omitted — thumbs speak for themselves. */

.page-description {
    text-align: center;
    color: #222;
    font-family: 'Balsamiq Sans', Arial, sans-serif;
    margin-top: 8px;
}

.field-help {
    margin-top: 6px;
    font-size: 0.9em;
    color: #555;
}

.input-content textarea {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e1e5e9;
    border-radius: 3px;
    font-size: 16px;
    font-family: 'Balsamiq Sans', Arial, sans-serif;
    box-sizing: border-box;
    resize: vertical;
    min-height: 140px;
}

.input-content textarea:focus {
    outline: none;
    border-color: #3bb8b4;
}

.post-download-note {
    position: relative;
    margin-top: 16px;
    padding: 12px 36px 12px 14px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 3px;
    font-family: 'Balsamiq Sans', Arial, sans-serif;
    color: #185251;
    font-size: 0.95em;
}

.note-dismiss {
    position: absolute;
    right: 8px;
    top: 8px;
    border: none;
    background: transparent;
    font-size: 1.4em;
    cursor: pointer;
    color: #185251;
}

.simple-form-page {
    max-width: 480px;
    margin: 40px auto;
    padding: 24px;
    background: rgba(255, 255, 255, 0.75);
    border-radius: 3px;
    font-family: 'Balsamiq Sans', Arial, sans-serif;
}

.simple-form-page label {
    display: block;
    margin: 12px 0 4px;
    color: #222;
}

.simple-form-page input,
.simple-form-page textarea {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #e1e5e9;
    border-radius: 3px;
    box-sizing: border-box;
    font-size: 16px;
}

.simple-form-page button {
    margin-top: 16px;
    width: 100%;
}

/* ==========================================================================
   Classroom pilot site chrome (nav / footer / UI font)
   Scoped to body.pilot-page so legacy pack pdf-personalizer pages are untouched.
   UI font only — PDF drawing fonts (Balsamiq / Doodlipoop TTFs) live in JS.
   Google Sans is not freely licensed: stack prefers it if installed, then
   Product Sans, then DM Sans (loaded from Google Fonts in each page <head>).
   ========================================================================== */
:root {
    --ui-font: "Google Sans", "Product Sans", "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    --chrome-height: 60px;
    --ink: #202124;
    --ink-soft: #5f6368;
    --teal-dark: #185251;
    --teal: #247674;
}

body.pilot-page {
    font-family: var(--ui-font);
    background: #62CECC;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 0;
}

/* One UI font everywhere on pilot pages (nav, gallery chrome, forms, about). */
body.pilot-page,
body.pilot-page * {
    font-family: var(--ui-font);
}

/* Neutralise legacy header bug decorations / hidden-span title trick on pilot pages. */
body.pilot-page h1::before,
body.pilot-page h1::after {
    content: none !important;
    display: none !important;
}

body.pilot-page h1 span {
    opacity: 1;
    height: auto;
    overflow: visible;
    display: inline;
    font-size: inherit;
    line-height: inherit;
}

.pilot-main {
    flex: 1 0 auto;
    width: 100%;
    padding: 28px 0 48px;
}

/* —— Top nav —— */
.site-nav {
    flex: 0 0 var(--chrome-height);
    height: var(--chrome-height);
    background: #fff;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    position: relative;
    z-index: 50;
}

.site-nav-inner {
    height: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.site-nav-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    margin-right: auto;
    color: var(--ink);
    font-size: 18px;
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.01em;
    text-decoration: none;
}

.site-nav-logo-tag {
    font-weight: 500;
    color: var(--ink-soft);
}

.site-nav-logo-text {
    min-width: 0;
}

/* Header bug mark: title-bug-1.png cropped to the bug (no "hi!"), ~38px tall, same
   3-degree two-step wiggle as the old page-header bugs. Wrapper clips; img is offset. */
.site-nav-logo-bug {
    position: relative;
    flex: 0 0 auto;
    width: 32px;
    height: 38px;
    overflow: hidden;
    animation: navBugWiggle 1400ms steps(2) infinite;
}

.site-nav-logo-bug img {
    position: absolute;
    top: -3px;
    left: -4px;
    width: 56px;
    height: auto;
    max-width: none;
}

@keyframes navBugWiggle {
    0%, 49.99% { transform: rotate(0deg); }
    50%, 100% { transform: rotate(3deg); }
}

@media (prefers-reduced-motion: reduce) {
    .site-nav-logo-bug {
        animation: none;
    }
}

.site-nav-logo:hover .site-nav-logo-name {
    color: var(--teal);
}

/* Mode switch lives in the nav (gallery + worksheet), right of Worksheets / About. */
.site-nav .mode-switch {
    flex: 0 0 auto;
    display: inline-flex;
    margin: 0 0 0 8px;
    padding: 3px;
    background: #f1f3f4;
}

.site-nav .mode-switch-btn {
    min-height: 34px;
    padding: 6px 12px;
    color: var(--ink);
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
}

.site-nav .mode-switch-btn.is-active {
    background: var(--teal);
    color: #fff;
    font-weight: 700;
}

.site-nav .mode-switch-btn:not(.is-active):hover {
    background: rgba(36, 118, 116, 0.12);
}

.site-nav .mode-switch-btn:focus-visible {
    outline: 2px solid var(--teal);
    outline-offset: 1px;
}

.site-nav-links {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    list-style: none;
}

.site-nav-link,
.site-nav-dropdown-toggle {
    appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    padding: 8px 12px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--ink);
    font-size: 15px;
    font-weight: 500;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
}

.site-nav-link:hover,
.site-nav-dropdown-toggle:hover,
.site-nav-dropdown-toggle[aria-expanded="true"] {
    background: #f1f3f4;
}

.site-nav-link[aria-current="page"],
.site-nav-dropdown-toggle.is-current {
    color: var(--teal);
    font-weight: 700;
}

.site-nav-link:focus-visible,
.site-nav-dropdown-toggle:focus-visible,
.site-nav-menu a:focus-visible,
.site-nav-logo:focus-visible,
.site-footer a:focus-visible {
    outline: 2px solid var(--teal);
    outline-offset: 2px;
}

.site-nav-dropdown {
    position: relative;
}

.site-nav-dropdown-toggle::after {
    content: '';
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid currentColor;
    transition: transform 0.15s ease;
}

.site-nav-dropdown-toggle[aria-expanded="true"]::after {
    transform: rotate(180deg);
}

.site-nav-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 230px;
    padding: 6px 0;
    list-style: none;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.site-nav-menu[hidden] {
    display: none;
}

.site-nav-menu a {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 10px 16px;
    color: var(--ink);
    font-size: 15px;
    text-decoration: none;
}

.site-nav-menu a:hover {
    background: #f1f3f4;
}

.site-nav-menu a[aria-current="page"] {
    color: var(--teal);
    font-weight: 700;
}

/* —— Footer —— */
.site-footer {
    flex: 0 0 var(--chrome-height);
    height: var(--chrome-height);
    background: #3c4043;
    color: #bdc1c6;
    text-align: left;
    padding: 0;
    font-size: 13px;
}

.site-footer-inner {
    height: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.site-footer-copy {
    color: #9aa0a6;
    white-space: nowrap;
}

.site-footer-links {
    display: flex;
    align-items: center;
    gap: 24px;
    list-style: none;
}

.site-footer a {
    color: #e8eaed;
    text-decoration: none;
}

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

@media (max-width: 720px) {
    .site-footer-copy {
        display: none;
    }
    .site-footer-inner {
        justify-content: center;
        padding: 0 12px;
    }
    .site-footer-links {
        gap: 16px;
    }
}

/* Tablet: logo text wraps to two lines so the mode switch still fits. */
@media (max-width: 900px) {
    .site-nav-logo {
        font-size: 15px;
    }
    .site-nav-logo-tag {
        display: block;
        font-size: 12px;
    }
}

/* Below ~760px the bug stays as the logo mark and the text goes screen-reader-only
   so Worksheets + About + mode switch fit in one 60px row. */
@media (max-width: 760px) {
    .site-nav-logo {
        flex: 0 0 auto;
    }
    .site-nav-logo-text {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }
}

/* Phone: tighter links + short mode labels ("Classroom" / "Parent"). */
@media (max-width: 640px) {
    .site-nav-inner {
        padding: 0 10px;
        gap: 4px;
    }
    .site-nav-logo {
        flex: 0 0 auto;
        margin-right: auto;
    }
    .site-nav-link,
    .site-nav-dropdown-toggle {
        padding: 8px 6px;
        gap: 4px;
        font-size: 13px;
    }
    .site-nav .mode-switch {
        margin-left: 0;
        padding: 2px;
    }
    .site-nav .mode-switch-btn {
        min-height: 34px;
        padding: 6px;
        font-size: 12px;
    }
    .site-nav .mode-word {
        display: none;
    }
    .site-footer {
        font-size: 12px;
    }
    .site-footer-links {
        gap: 12px;
    }
}

/* Very narrow phones (~320px): drop the About caret and tighten further. */
@media (max-width: 360px) {
    .site-nav-dropdown-toggle::after {
        display: none;
    }
    .site-nav-link,
    .site-nav-dropdown-toggle {
        padding: 8px 4px;
    }
    .site-nav .mode-switch-btn {
        padding: 6px 5px;
        font-size: 11px;
    }
}

/* —— Page intro (gallery + worksheet form), below the nav —— */
.pilot-intro {
    max-width: 720px;
    margin: 0 auto 20px;
    padding: 0 16px;
    text-align: center;
}

.pilot-intro h1 {
    margin: 0;
    padding: 0;
    min-height: 0;
    background: none;
    color: var(--teal-dark);
    font-size: clamp(22px, 2.4vw + 12px, 32px);
    font-weight: 700;
    line-height: 1.2;
    text-wrap: balance;
    overflow-wrap: break-word;
}

.pilot-intro .page-description {
    margin-top: 6px;
    color: var(--teal-dark);
    font-size: 15px;
}

body.pilot-page .worksheet-title-visible {
    color: var(--teal-dark) !important;
    font-size: clamp(22px, 2.4vw + 12px, 32px) !important;
}

body.pilot-page .container.worksheet-form-layout {
    width: calc(100% - 40px);
}

@media (min-width: 860px) {
    body.pilot-page .worksheet-preview {
        top: 24px;
    }
}

/* —— Simple pages: feedback, email signup, about, terms —— */
body.pilot-page .simple-form-page,
.content-page {
    width: calc(100% - 32px);
    margin: 0 auto;
    padding: 28px 28px 32px;
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    color: var(--ink);
}

body.pilot-page .simple-form-page {
    max-width: 520px;
}

.content-page {
    max-width: 720px;
    line-height: 1.55;
}

.content-page h1,
body.pilot-page .simple-form-page h1 {
    margin: 0 0 12px;
    color: var(--teal-dark);
    font-size: 28px;
    font-weight: 700;
    line-height: 1.2;
}

.content-page .about-subtitle {
    margin: -2px 0 0;
    color: var(--ink-soft);
    font-size: 17px;
}

.content-page h2 {
    margin: 24px 0 8px;
    color: var(--teal-dark);
    font-size: 20px;
    font-weight: 700;
}

.content-page p,
.content-page li {
    font-size: 16px;
}

.content-page p + p {
    margin-top: 0.9em;
}

.content-page ul {
    margin: 0.5em 0 0 1.25em;
}

.content-page a,
body.pilot-page .simple-form-page a {
    color: var(--teal);
    text-decoration: underline;
}

.content-page .content-note {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid #e1e5e9;
    color: var(--ink-soft);
    font-size: 14px;
}

body.pilot-page .simple-form-page label {
    font-size: 15px;
    font-weight: 500;
}

body.pilot-page .simple-form-page .download-btn {
    font-size: 1.1em;
    padding: 14px 24px;
}

@media (max-width: 520px) {
    body.pilot-page .simple-form-page,
    .content-page {
        padding: 20px 18px 24px;
    }
}
