/* =========================================================
   KIDDIE BLOCKS PH - RESPONSIVE WORKSHEET VIEWER SYSTEM
   Standard: US Letter (8.5in x 11in)
   Optimizes printable worksheets for mobile & tablet screens
   so viewers can appreciate the COMPLETE full page on any device.
========================================================= */

:root {
    --page-width-px: 816px;
    --page-height-px: 1056px;
    --page-aspect-ratio: 1.2941176;
    --page-scale: 1;
    --page-scaled-height: 1056px;
}

/* Screen Mode Optimization */
@media screen {
    html {
        -webkit-text-size-adjust: 100%;
        box-sizing: border-box;
        scroll-behavior: smooth;
    }

    body {
        overflow-x: hidden;
        width: 100%;
        min-height: 100vh;
        background-color: #f1f5f9;
        -webkit-overflow-scrolling: touch;
    }

    /* Screen Wrapper */
    .screen-container {
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
        display: flex;
        flex-direction: column;
        align-items: center;
        padding-top: 10px;
        padding-bottom: 50px;
    }

    /* Responsive Floating Toolbar */
    .web-nav {
        position: sticky;
        top: 10px;
        z-index: 1000;
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border: 2px solid #091951;
        border-radius: 50px;
        padding: 8px 18px;
        display: flex;
        gap: 10px;
        align-items: center;
        justify-content: space-between;
        box-shadow: 0 8px 24px rgba(9, 25, 81, 0.15);
        max-width: 816px;
        width: calc(100% - 24px);
        margin-bottom: 12px;
        transition: all 0.25s ease;
    }

    .web-nav .back-btn {
        color: #091951;
        text-decoration: none;
        font-weight: 700;
        font-size: 9pt;
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 6px 14px;
        border-radius: 20px;
        background: #eef4fc;
        transition: all 0.2s;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .web-nav .back-btn:hover {
        background: #9DB6DA;
        color: #091951;
    }

    .web-nav .toolbar-title {
        font-family: 'ABeeZee', 'Montserrat', sans-serif;
        font-weight: 700;
        color: #091951;
        font-size: 10.5pt;
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        flex: 1;
        padding: 0 6px;
    }

    .web-nav-actions {
        display: flex;
        align-items: center;
        gap: 6px;
        flex-shrink: 0;
    }

    /* Toolbar Mode Switcher Buttons */
    .btn-view-toggle,
    .btn-layout-toggle {
        background: #f1f5f9;
        color: #091951;
        border: 1.5px solid #cbd5e1;
        padding: 6px 11px;
        border-radius: 20px;
        font-family: 'Montserrat', sans-serif;
        font-weight: 700;
        font-size: 8.5pt;
        cursor: pointer;
        display: flex;
        align-items: center;
        gap: 5px;
        transition: all 0.2s ease;
        white-space: nowrap;
    }

    .btn-view-toggle:hover,
    .btn-layout-toggle:hover {
        background: #e2e8f0;
        border-color: #94a3b8;
    }

    .btn-print {
        background: #F12020;
        color: #ffffff;
        border: none;
        padding: 7px 16px;
        border-radius: 30px;
        font-family: 'Montserrat', sans-serif;
        font-weight: 700;
        font-size: 9pt;
        cursor: pointer;
        display: flex;
        align-items: center;
        gap: 6px;
        box-shadow: 0 4px 12px rgba(241, 32, 32, 0.35);
        transition: all 0.2s ease;
        white-space: nowrap;
    }

    .btn-print:hover {
        background: #d01414;
        transform: translateY(-1px);
        box-shadow: 0 6px 16px rgba(241, 32, 32, 0.45);
    }

    /* Floating Sheet Pagination Bar on Mobile */
    .kb-sheet-navigator {
        display: none; /* Managed by JS on mobile */
        align-items: center;
        justify-content: center;
        gap: 12px;
        margin: 0 auto 12px auto;
        padding: 6px 16px;
        background: #ffffff;
        border: 1.5px solid #e2e8f0;
        border-radius: 30px;
        box-shadow: 0 4px 16px rgba(9, 25, 81, 0.08);
        z-index: 900;
    }

    .sheet-nav-btn {
        background: #eef4fc;
        color: #091951;
        border: 1px solid #cbd5e1;
        border-radius: 50%;
        width: 32px;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 11pt;
        font-weight: 800;
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .sheet-nav-btn:hover:not(:disabled) {
        background: #9DB6DA;
        transform: scale(1.06);
    }

    .sheet-nav-btn:disabled {
        opacity: 0.35;
        cursor: not-allowed;
    }

    .sheet-nav-info {
        font-family: 'ABeeZee', 'Montserrat', sans-serif;
        font-weight: 700;
        font-size: 9pt;
        color: #091951;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .sheet-nav-dots {
        display: flex;
        gap: 5px;
        align-items: center;
    }

    .sheet-dot {
        width: 7px;
        height: 7px;
        border-radius: 50%;
        background: #cbd5e1;
        transition: all 0.2s ease;
    }

    .sheet-dot.active {
        background: #F12020;
        transform: scale(1.25);
    }

    /* Page Scaler Wrapper */
    .page-scaler-wrapper {
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: flex-start;
        margin: 0 auto 20px auto;
        position: relative;
        overflow: visible !important; /* CRITICAL: Never create nested scroll container */
        transition: height 0.2s ease;
    }

    /* The Printable Sheet on Screen */
    .page {
        width: 8.5in;
        height: 11in;
        min-height: 11in;
        max-height: 11in;
        background: #ffffff;
        box-shadow: 0 10px 30px rgba(9, 25, 81, 0.12), 0 1px 4px rgba(0, 0, 0, 0.06);
        border-radius: 8px;
        flex-shrink: 0;
        transition: transform 0.2s ease;
    }

    /* =========================================================
       MOBILE & TABLET OPTIMIZATION (< 860px)
       Smooth viewing without scroll fighting or awkward gaps
    ========================================================= */
    @media (max-width: 860px) {
        .screen-container {
            padding-top: 8px;
            padding-bottom: 40px;
        }

        .kb-sheet-navigator {
            display: flex; /* Active on mobile */
        }

        /* Default on mobile: SINGLE SHEET PRESENTATION (1-by-1) */
        body.mode-single-sheet .page-scaler-wrapper {
            display: none;
            margin-bottom: 0;
        }

        body.mode-single-sheet .page-scaler-wrapper.active-sheet {
            display: flex;
            height: var(--page-scaled-height);
            animation: fadeInSheet 0.22s ease-out;
        }

        @keyframes fadeInSheet {
            from { opacity: 0.65; transform: scale(0.985); }
            to { opacity: 1; transform: scale(1); }
        }

        /* CONTINUOUS SCROLL MODE (when toggled to All Sheets) */
        body.mode-continuous .page-scaler-wrapper {
            display: flex;
            height: var(--page-scaled-height);
            margin-bottom: 16px;
            scroll-snap-align: start;
        }

        body.mode-continuous .kb-sheet-navigator {
            display: none;
        }

        /* Scaled Page Transform */
        .page {
            transform-origin: top center;
            transform: scale(var(--page-scale));
            margin: 0 !important;
            border-radius: 6px;
        }

        /* 100% Zoom Mode */
        body.mode-actual-size .page-scaler-wrapper {
            height: 11in !important;
            overflow-x: auto !important;
            -webkit-overflow-scrolling: touch;
            justify-content: flex-start;
            padding: 0 12px;
        }

        body.mode-actual-size .page {
            transform: scale(1) !important;
            margin: 0 auto !important;
        }

        /* Mobile Toolbar Adjustments */
        .web-nav {
            padding: 6px 12px;
            gap: 6px;
            top: 6px;
            width: calc(100% - 16px);
        }

        .web-nav .back-btn {
            padding: 5px 9px;
            font-size: 8pt;
        }

        .web-nav .toolbar-title,
        .print-toggle-wrap {
            display: none !important;
        }

        .btn-view-toggle,
        .btn-layout-toggle {
            padding: 5px 8px;
            font-size: 7.8pt;
        }

        .btn-print {
            padding: 6px 11px;
            font-size: 8.2pt;
        }
    }

    /* Very compact phones (<= 380px) */
    @media (max-width: 380px) {
        .web-nav {
            padding: 5px 8px;
        }
        .btn-view-toggle span.btn-text,
        .btn-layout-toggle span.btn-text {
            display: none;
        }
    }
}

/* =========================================================
   WORKSHEET EXPLORATION & SEO CARDS (Screen Only)
========================================================= */
.kb-worksheet-web-seo {
    max-width: 8.5in;
    width: calc(100% - 32px);
    margin: 32px auto 60px auto;
    font-family: 'Montserrat', system-ui, -apple-system, sans-serif;
    box-sizing: border-box;
}

.kb-seo-breadcrumbs {
    font-size: 8.5pt;
    font-weight: 500;
    color: #64748B;
    margin-bottom: 16px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

.kb-seo-breadcrumbs a {
    color: #091951;
    text-decoration: none;
    font-weight: 600;
    transition: color 0.15s ease;
}

.kb-seo-breadcrumbs a:hover {
    color: #F12020;
    text-decoration: underline;
}

.kb-seo-breadcrumbs span {
    color: #475569;
    font-weight: 600;
}

.kb-seo-card {
    background: #FFFFFF;
    border: 1.5px solid #E2E8F0;
    border-radius: 14px;
    padding: 24px 28px;
    margin-bottom: 20px;
    box-shadow: 0 4px 18px rgba(9, 25, 81, 0.05), 0 1px 3px rgba(0, 0, 0, 0.04);
    box-sizing: border-box;
}

.kb-seo-card-title {
    font-family: 'ABeeZee', 'Montserrat', sans-serif;
    font-size: 13pt;
    font-weight: 800;
    color: #091951;
    margin: 0 0 8px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.kb-seo-desc {
    font-size: 9pt;
    color: #475569;
    margin: 0 0 18px 0;
    line-height: 1.55;
}

.kb-related-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.kb-related-link {
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: #F8FAFC;
    border: 1.5px solid #E2E8F0;
    border-radius: 10px;
    padding: 12px 14px;
    text-decoration: none;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.kb-related-link:hover {
    background: #EEF4FC;
    border-color: #091951;
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(9, 25, 81, 0.08);
}

.kb-related-cat {
    font-size: 7pt;
    font-weight: 800;
    color: #DC2626;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    display: block;
}

.kb-related-name {
    font-size: 9pt;
    font-weight: 700;
    color: #091951;
    line-height: 1.35;
}

.kb-related-link:hover .kb-related-name {
    color: #091951;
}

.kb-quick-nav-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px dashed #CBD5E1;
}

.kb-quick-nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 8.5pt;
    font-weight: 700;
    color: #091951;
    background: #EEF4FC;
    border: 1.5px solid #CBD5E1;
    padding: 8px 16px;
    border-radius: 9999px;
    text-decoration: none;
    transition: all 0.2s ease;
}

.kb-quick-nav-btn:hover {
    background: #091951;
    color: #FFFFFF;
    border-color: #091951;
    transform: translateY(-1px);
}

@media (max-width: 640px) {
    .kb-worksheet-web-seo {
        width: calc(100% - 24px);
        margin: 20px auto 40px auto;
    }
    .kb-seo-card {
        padding: 16px 16px;
    }
    .kb-related-grid {
        grid-template-columns: 1fr;
    }
    .kb-quick-nav-btn {
        width: 100%;
        justify-content: center;
        text-align: center;
        box-sizing: border-box;
    }
}

/* =========================================================
   PRINT PRESERVATION (100% STRICT US LETTER)
   Zero scale distortion, full bleed margins, high-res vector output
========================================================= */
@media print {
    .web-nav,
    .btn-view-toggle,
    .btn-layout-toggle,
    .kb-sheet-navigator,
    .btn-print,
    .no-print {
        display: none !important;
    }

    body.mode-single-sheet .page-scaler-wrapper,
    .page-scaler-wrapper {
        display: block !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
    }

    .screen-container {
        padding: 0 !important;
        margin: 0 !important;
        display: block !important;
        width: 100% !important;
    }

    .page {
        width: 8.5in !important;
        height: 11in !important;
        min-height: 11in !important;
        max-height: 11in !important;
        margin: 0 !important;
        transform: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        page-break-after: always !important;
        break-after: page !important;
    }
}
