/* Lenovo Tablet (Pilot Group) - 1463x834 inner (16:10) Optimizations */
/* Comprehensive responsive design for all pages */
/* Expanded range to capture heights from 730px to 920px */

@media (min-width: 1400px) and (max-width: 1500px) and (min-height: 730px) and (max-height: 920px) {
    
    /* Override body centering for homescreen only */
    html body.homescreen-page {
        justify-content: flex-start !important;
        align-items: flex-start !important;
    }
    
    /* ============================================
       NAVIGATION BUTTONS - Thumb-friendly size
       ============================================ */
    .sticky-home-button,
    .sticky-back-button,
    .sticky-profile-button {
        width: 100px !important;
        height: 100px !important;
        font-size: 2rem !important;
        top: 20px !important;
        left: 20px !important;
        border-radius: 25px !important;
    }
    
    .button-icon {
        width: 60px !important;
        height: 60px !important;
    }
    
    /* ============================================
       HOMESCREEN OPTIMIZATIONS
       ============================================ */
    /* Ultra-specific selectors for maximum priority */
    html body div.container {
        width: 100vw !important;
        max-width: 100vw !important;
        padding: 20px 0 20px 0 !important;
        align-items: stretch !important;
        margin: 0 !important;
        box-sizing: border-box !important;
    }
    
    html body div.container div.content-container {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
        padding: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        min-height: calc(100vh - 40px) !important;
        justify-content: flex-start !important;
        box-sizing: border-box !important;
    }
    
    /* Top Section - User Greeting */
    html body div.content-container div.top-section {
        display: flex !important;
        justify-content: flex-start !important;
        padding: 0 20px !important;
        margin-bottom: 20px !important;
        width: 100% !important;
    }
    
    html body div.top-section div.user-greeting-container {
        position: relative !important;
    }
    
    html body div.user-greeting-container div.user-greeting {
        font-size: 2rem !important;
        padding: 12px 24px !important;
    }
    
    /* Middle Section - Koala + Grid */
    html body div.content-container div.middle-section {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: end !important;
        gap: 10px !important;
        flex: 1 !important;
        width: 100% !important;
        margin: 10px 0 !important;
        padding: 0 20px !important;
    }
    
    html body div.middle-section div.koala-container {
        flex: 0 0 auto !important;
        justify-content: flex-start !important;
        display: flex !important;
    }
    
    html body div.middle-section div.grid-container {
        flex: 1 !important;
        justify-content: center !important;
        display: flex !important;
    }
    
    /* Kai sizing now consolidated in koala_assistant.css */
    
    html body div#kai-assistant.kai-assistant img.kai-image {
        width: 100% !important;
        height: 100% !important;
        object-fit: contain !important;
    }
    
    /* Categories Grid */
    html body div.grid-container div.categories-grid {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 5px !important;
        max-width: 760px !important;
        padding: 8px !important;
    }
    
    html body div.categories-grid div.category-card {
        min-height: 170px !important;
        padding: 6px !important;
    }
    
    html body div.category-card div.category-icon {
        width: 170px !important;
        height: 170px !important;
    }
    
    html body div.category-card h2.category-title {
        font-size: 1.6rem !important;
        margin-bottom: 0 !important;
    }
    
    html body div.category-card span.category-name {
        font-size: 1.6rem !important;
    }
    
    /* Bottom Section - Mic Button */
    html body div.content-container div.bottom-section {
        display: flex !important;
        justify-content: center !important;
        padding: 0 20px !important;
        margin-top: auto !important;
        width: 100% !important;
    }
    
    /* ============================================
       AUTH SCREENS - Better centering
       ============================================ */
    .auth-container {
        max-width: 600px !important;
    }
    
    .auth-header h1 {
        font-size: 56px !important;
    }
    
    .auth-header p {
        font-size: 20px !important;
    }
    
    .form-group input,
    .form-group select {
        font-size: 20px !important;
        padding: 20px 24px !important;
    }
    
    .btn {
        font-size: 20px !important;
        padding: 20px 24px !important;
        min-height: 64px !important;
    }
    
    .auth-footer p {
        font-size: 18px !important;
    }
    
    /* ============================================
       PROFILE CREATION
       ============================================ */
    .question-text {
        font-size: 3rem !important;
        text-align: center !important;
    }
    
    .name-input,
    .age-button {
        font-size: 1.8rem !important;
        padding: 25px 30px !important;
    }
    
    .koala-character {
        max-width: 350px !important;
    }
    
    /* ============================================
       GAME CATEGORY PAGES
       ============================================ */
    .content-container {
        padding: 30px !important;
    }
    
    .page-title {
        font-size: 4.5rem !important;
    }
    
    .game-card {
        min-height: 200px !important;
        padding: 25px !important;
    }
    
    .game-icon {
        width: 100px !important;
        height: 100px !important;
    }
    
    .game-title {
        font-size: 1.7rem !important;
    }
    
    /* ============================================
       INDIVIDUAL GAMES - Larger tap targets
       ============================================ */
    .answer-button,
    .option-button {
        min-width: 150px !important;
        min-height: 100px !important;
        font-size: 2rem !important;
    }
    
    .problem-text,
    .question-text {
        font-size: 3rem !important;
        text-align: center !important;
    }
    
    /* Microphone Button */
    html body button#mic-button.mic-button {
        width: 100px !important;
        height: 100px !important;
        position: relative !important;
    }
    
    html body button#mic-button.mic-button:hover {
        transform: scale(1.05) !important;
    }
    
    html body button#mic-button.mic-button:active {
        transform: scale(0.98) !important;
    }
    
    html body .mic-button .mic-icon {
        width: 40px !important;
        height: 40px !important;
    }
    
    /* ============================================
       SMARTSCAN / HOMEWORK HELP
       ============================================ */
    .analyzer-btn {
        padding: 20px 40px !important;
        font-size: 1.5em !important;
    }
    
    .analyzer-btn-row {
        bottom: 45px !important;
    }
    
    /* ============================================
       PROFILE CREATION CAROUSEL
       ============================================ */
    .carousel-container {
        max-width: 900px !important;
    }
    
    .carousel-slide h2 {
        font-size: 3rem !important;
    }
    
    .carousel-slide input[type="text"] {
        font-size: 2rem !important;
        padding: 25px 30px !important;
    }
    
    .age-buttons {
        gap: 15px !important;
    }
    
    .age-btn {
        font-size: 2rem !important;
        padding: 25px !important;
        min-width: 80px !important;
    }
    
    .avatar-grid {
        grid-template-columns: repeat(5, 1fr) !important;
        gap: 15px !important;
    }
    
    .avatar-btn {
        font-size: 4rem !important;
        padding: 20px !important;
    }
    
    .carousel-nav-btn {
        padding: 20px 50px !important;
        font-size: 1.8rem !important;
    }
    
    /* ============================================
       CHILD LOGIN PAGE
       ============================================ */
    #child-login-container {
        max-width: 1200px !important;
        gap: 60px !important;
    }
    
    .page-title {
        font-size: 4rem !important;
    }
    
    .user-cards-grid {
        gap: 35px !important;
    }
    
    .user-card {
        min-width: 220px !important;
        max-width: 240px !important;
        padding: 55px 45px !important;
    }
    
    .user-avatar {
        font-size: 5.5rem !important;
    }
    
    .user-name {
        font-size: 1.6rem !important;
    }
    
    .new-profile-icon {
        font-size: 5.5rem !important;
    }
    
    .new-profile-text {
        font-size: 1.6rem !important;
    }
    
    .manage-profiles-btn {
        font-size: 1.5rem !important;
        padding: 12px 25px !important;
    }
    
    /* ============================================
       PROFILE MANAGEMENT MODAL
       ============================================ */
    .modal-container {
        padding: 55px 65px !important;
        max-width: 1100px !important;
    }
    
    .modal-title {
        font-size: 3.5rem !important;
        margin-bottom: 45px !important;
    }
    
    .modal-close {
        width: 50px !important;
        height: 50px !important;
        font-size: 2rem !important;
        top: 22px !important;
        right: 22px !important;
    }
    
    .child-selection-grid {
        gap: 30px !important;
    }
    
    .modal-child-card {
        width: 220px !important;
        height: 220px !important;
        padding: 45px 35px !important;
    }
    
    .modal-child-avatar {
        font-size: 5.5rem !important;
    }
    
    .modal-child-name {
        font-size: 1.6rem !important;
    }
    
    .modal-form-label {
        font-size: 1.5rem !important;
    }
    
    .modal-name-input {
        font-size: 2.5rem !important;
        padding: 14px 18px !important;
    }
    
    .modal-age-buttons {
        gap: 10px !important;
    }
    
    .modal-age-btn {
        font-size: 2.5rem !important;
        padding: 12px !important;
    }
    
    .modal-avatar-grid {
        grid-template-columns: repeat(6, 1fr) !important;
        gap: 10px !important;
    }
    
    .modal-avatar-btn {
        font-size: 2.5rem !important;
        padding: 10px !important;
    }
    
    .modal-btn {
        padding: 14px 40px !important;
        font-size: 1.3rem !important;
        min-width: 120px !important;
    }
    
    .modal-actions {
        gap: 18px !important;
        margin-top: 30px !important;
    }
    
}

/* ============================================
   LENOVO TABLET 1507x765 (1920x1200 at 98% zoom) Optimizations
   Expanded range: 1500-1550px width, 750-800px height
   ============================================ */
@media (min-width: 1500px) and (max-width: 1550px) and (min-height: 750px) and (max-height: 800px) {
    
    /* Override body centering for homescreen only */
    html body.homescreen-page {
        justify-content: flex-start !important;
        align-items: flex-start !important;
        overflow-x: hidden !important;
    }
    
    /* ============================================
       HOMESCREEN OPTIMIZATIONS
       ============================================ */
    html body div.container {
        width: 100vw !important;
        max-width: 100vw !important;
        padding: 10px 0 10px 0 !important;
        align-items: stretch !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }
    
    html body div.container div.content-container {
        display: flex !important;
        flex-direction: column !important;
        gap: 5px !important;
        padding: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        min-height: calc(100vh - 20px) !important;
        justify-content: flex-start !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }
    
    /* Top Section - User Greeting */
    html body div.content-container div.top-section {
        display: flex !important;
        justify-content: flex-start !important;
        padding: 0 10px !important;
        margin-bottom: 5px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    
    html body div.user-greeting-container div.user-greeting {
        font-size: 1.5rem !important;
        padding: 8px 18px !important;
    }
    
    /* Middle Section - Koala + Grid - THIS IS CRITICAL */
    html body div.content-container div.middle-section {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: flex-end !important;
        gap: 20px !important;
        flex: 1 !important;
        width: 100% !important;
        max-width: 100vw !important;
        margin: 0 !important;
        padding: 0 10px !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }
    
    html body div.middle-section div.koala-container {
        flex: 0 0 auto !important;
        justify-content: flex-start !important;
        display: flex !important;
        width: 320px !important;
        min-width: 320px !important;
    }
    
    /* CRITICAL: Fix grid container to not push right */
    html body div.middle-section div.grid-container {
        flex: 1 !important;
        justify-content: center !important; /* Changed from flex-end */
        display: flex !important;
        max-width: calc(100vw - 360px) !important; /* Account for koala + padding + gap */
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }
    
    /* Kai sizing now consolidated in koala_assistant.css */
    
    html body div#kai-assistant.kai-assistant img.kai-image {
        width: 100% !important;
        height: 100% !important;
        object-fit: contain !important;
    }
    
    /* Categories Grid - FIT WITHIN VIEWPORT */
    html body div.grid-container div.categories-grid {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 6px !important;
        max-width: 850px !important; /* Reduced from 1200px */
        width: 100% !important;
        padding: 8px !important;
        box-sizing: border-box !important;
    }
    
    html body div.categories-grid div.category-card {
        min-height: 150px !important;
        padding: 6px !important;
        box-sizing: border-box !important;
    }
    
    html body div.category-card div.category-icon {
        width: 140px !important;
        height: 140px !important;
    }
    
    html body div.category-card h2.category-title {
        font-size: 1.3rem !important;
        margin-bottom: 0 !important;
        margin-top: 6px !important;
    }
    
    html body div.category-card span.category-name {
        font-size: 1.3rem !important;
    }
    
    /* Bottom Section - Mic Button */
    html body div.content-container div.bottom-section {
        display: flex !important;
        justify-content: center !important;
        padding: 0 10px 5px 10px !important;
        margin-top: auto !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Microphone Button */
    html body button#mic-button.mic-button {
        width: 85px !important;
        height: 85px !important;
        position: relative !important;
    }
    
    html body .mic-button .mic-icon {
        width: 36px !important;
        height: 36px !important;
    }
    
    /* ============================================
       NAVIGATION BUTTONS
       ============================================ */
    .sticky-home-button,
    .sticky-back-button,
    .sticky-profile-button {
        width: 85px !important;
        height: 85px !important;
        font-size: 1.7rem !important;
        top: 10px !important;
        left: 10px !important;
        border-radius: 20px !important;
    }
    
    .button-icon {
        width: 50px !important;
        height: 50px !important;
    }
    
    /* Kai sizing now consolidated in koala_assistant.css */
    
    /* ============================================
       AUTH SCREENS - Better centering
       ============================================ */
    .auth-container {
        max-width: 600px !important;
    }
    
    .auth-header h1 {
        font-size: 52px !important;
    }
    
    .auth-header p {
        font-size: 18px !important;
    }
    
    .form-group input,
    .form-group select {
        font-size: 18px !important;
        padding: 18px 22px !important;
    }
    
    .btn {
        font-size: 18px !important;
        padding: 18px 22px !important;
        min-height: 60px !important;
    }
    
    .auth-footer p {
        font-size: 16px !important;
    }
    
    /* ============================================
       PROFILE CREATION
       ============================================ */
    .question-text {
        font-size: 2.8rem !important;
        text-align: center !important;
    }
    
    .name-input,
    .age-button {
        font-size: 1.7rem !important;
        padding: 22px 28px !important;
    }
    
    .koala-character {
        max-width: 320px !important;
    }
    
    /* ============================================
       GAME CATEGORY PAGES
       ============================================ */
    .content-container {
        padding: 25px !important;
    }
    
    .page-title {
        font-size: 4rem !important;
    }
    
    .game-card {
        min-height: 180px !important;
        padding: 22px !important;
    }
    
    .game-icon {
        width: 90px !important;
        height: 90px !important;
    }
    
    .game-title {
        font-size: 1.6rem !important;
    }
    
    /* ============================================
       INDIVIDUAL GAMES - Larger tap targets
       ============================================ */
    .answer-button,
    .option-button {
        min-width: 140px !important;
        min-height: 90px !important;
        font-size: 1.9rem !important;
    }
    
    .problem-text,
    .question-text {
        font-size: 2.8rem !important;
        text-align: center !important;
    }
    
    /* ============================================
       SMARTSCAN / HOMEWORK HELP
       ============================================ */
    .analyzer-btn {
        padding: 18px 36px !important;
        font-size: 1.4em !important;
    }
    
    .analyzer-btn-row {
        bottom: 40px !important;
    }
    
    /* ============================================
       PROFILE CREATION CAROUSEL
       ============================================ */
    .carousel-container {
        max-width: 850px !important;
    }
    
    .carousel-slide h2 {
        font-size: 2.8rem !important;
    }
    
    .carousel-slide input[type="text"] {
        font-size: 1.9rem !important;
        padding: 22px 28px !important;
    }
    
    .age-buttons {
        gap: 14px !important;
    }
    
    .age-btn {
        font-size: 1.9rem !important;
        padding: 22px !important;
        min-width: 75px !important;
    }
    
    .avatar-grid {
        grid-template-columns: repeat(5, 1fr) !important;
        gap: 14px !important;
    }
    
    .avatar-btn {
        font-size: 3.8rem !important;
        padding: 18px !important;
    }
    
    .carousel-nav-btn {
        padding: 18px 45px !important;
        font-size: 1.7rem !important;
    }
    
    /* ============================================
       CHILD LOGIN PAGE
       ============================================ */
    #child-login-container {
        max-width: 1100px !important;
        gap: 55px !important;
    }
    
    .page-title {
        font-size: 3.8rem !important;
    }
    
    .user-cards-grid {
        gap: 32px !important;
    }
    
    .user-card {
        min-width: 200px !important;
        max-width: 220px !important;
        padding: 50px 40px !important;
    }
    
    .user-avatar {
        font-size: 5rem !important;
    }
    
    .user-name {
        font-size: 1.5rem !important;
    }
    
    .new-profile-icon {
        font-size: 5rem !important;
    }
    
    .new-profile-text {
        font-size: 1.5rem !important;
    }
    
    .manage-profiles-btn {
        font-size: 1.4rem !important;
        padding: 11px 22px !important;
    }
    
    /* ============================================
       PROFILE MANAGEMENT MODAL
       ============================================ */
    .modal-container {
        padding: 50px 60px !important;
        max-width: 1000px !important;
    }
    
    .modal-title {
        font-size: 3.2rem !important;
        margin-bottom: 40px !important;
    }
    
    .modal-close {
        width: 48px !important;
        height: 48px !important;
        font-size: 1.9rem !important;
        top: 20px !important;
        right: 20px !important;
    }
    
    .child-selection-grid {
        gap: 28px !important;
    }
    
    .modal-child-card {
        width: 200px !important;
        height: 200px !important;
        padding: 40px 32px !important;
    }
    
    .modal-child-avatar {
        font-size: 5rem !important;
    }
    
    .modal-child-name {
        font-size: 1.5rem !important;
    }
    
    .modal-form-label {
        font-size: 1.4rem !important;
    }
    
    .modal-name-input {
        font-size: 2.3rem !important;
        padding: 13px 17px !important;
    }
    
    .modal-age-buttons {
        gap: 9px !important;
    }
    
    .modal-age-btn {
        font-size: 2.3rem !important;
        padding: 11px !important;
    }
    
    .modal-avatar-grid {
        grid-template-columns: repeat(6, 1fr) !important;
        gap: 9px !important;
    }
    
    .modal-avatar-btn {
        font-size: 2.3rem !important;
        padding: 9px !important;
    }
    
    .modal-btn {
        padding: 13px 36px !important;
        font-size: 1.25rem !important;
        min-width: 110px !important;
    }
    
    .modal-actions {
        gap: 16px !important;
        margin-top: 28px !important;
    }
    
    /* ============================================
       WRITE IT RIGHT PAGE - 1507x765 Optimizations
       ============================================ */
    body.write-it-right-page .container {
        overflow: hidden !important;
    }
    
    body.write-it-right-page .content-container {
        overflow: hidden !important;
        max-height: 100vh !important;
    }
    
    body.write-it-right-page .main-content {
        overflow: hidden !important;
        padding: 20px !important;
    }
    
    body.write-it-right-page .game-area {
        overflow: hidden !important;
        gap: 20px !important;
    }
    
    body.write-it-right-page .main-letter-card {
        width: 200px !important;
        height: 200px !important;
        min-width: 200px !important;
        min-height: 200px !important;
        max-width: 200px !important;
        max-height: 200px !important;
        padding: 20px !important;
    }
    
    body.write-it-right-page .main-letter-text {
        font-size: 5rem !important;
    }
    
    body.write-it-right-page .question-text {
        font-size: 2rem !important;
        margin-top: 15px !important;
        margin-bottom: 10px !important;
    }
    
    body.write-it-right-page .instruction-text {
        display: none !important;
    }
    
    body.write-it-right-page .level-1-content {
        gap: 15px !important;
    }
}

/* Fix for peppa-pig page - override body/html overflow */
html body:not(.homescreen-page),
body:not(.homescreen-page),
#pwa-root:not(:has(.homescreen-page)) {
    height: 100vh !important;
    max-height: 100vh !important;
    overflow-y: hidden !important;
    overflow-x: hidden !important;
}

html:not(:has(body.homescreen-page)) {
    height: 100% !important;
    max-height: 100% !important;
    overflow: hidden !important;
}

#pwa-root:not(:has(.homescreen-page)) {
    height: 100vh !important;
    max-height: 100vh !important;
    overflow: hidden !important;
}

/* All Kai assistant sizing now consolidated in koala_assistant.css */

