/* ==================== MOBILE RESPONSIVE FIX ==================== */
/* File này fix các vấn đề responsive chung cho toàn bộ website */

/* Đảm bảo viewport không bị zoom trên mobile */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    touch-action: manipulation;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Fix overflow trên mobile */
body, html {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Fix cho các container */
.container, .app-container {
    max-width: 100%;
    overflow-x: hidden;
}

/* ==================== MOBILE SPECIFIC (< 768px) ==================== */
@media (max-width: 768px) {
    /* Padding cho body khi có bottom nav */
    body.has-bottom-nav {
        padding-bottom: 70px !important;
    }
    
    /* Ẩn nút Home/Back trên mobile nhưng giữ lại nút Menu */
    .nav-home-btn,
    .nav-back-btn {
        display: none !important;
    }
    
    /* Giữ lại nav-container để hiển thị nút Menu */
    .nav-container {
        display: flex !important;
    }
    
    /* Fix cho các game container - Giảm padding-top vì đã ẩn nav */
    .container {
        padding: 15px 15px 20px 15px !important;
        margin: 10px !important;
        border-radius: 20px !important;
    }
    
    /* Fix cho app container (Tiếng Việt) */
    .app-container {
        height: 100vh !important;
        max-height: none !important;
        border-radius: 0 !important;
        margin: 0 !important;
        padding-top: 15px !important;
    }
    
    /* Fix cho header - Giảm padding-top vì đã ẩn nav */
    header, .game-header {
        padding: 15px 10px !important;
        margin-top: 0 !important;
    }
    
    header h1, .game-header h1 {
        font-size: 1.5rem !important;
        margin-bottom: 10px !important;
    }
    
    /* Fix cho stats */
    .stats, .player-info {
        flex-wrap: wrap !important;
        gap: 10px !important;
        padding: 10px !important;
    }
    
    .stat-item {
        font-size: 0.85rem !important;
    }
    
    /* Fix cho buttons */
    button, .btn, .action-btn {
        font-size: 0.9rem !important;
        padding: 12px 20px !important;
        min-height: 44px !important; /* iOS touch target */
    }
    
    /* Fix cho game area */
    .game-area {
        padding: 15px 10px !important;
    }
    
    /* Fix cho question display */
    .question, .question-text {
        font-size: 1.2rem !important;
        padding: 15px !important;
        line-height: 1.5 !important;
    }
    
    /* Fix cho answers grid */
    .answers, .answer-grid {
        gap: 10px !important;
        padding: 10px !important;
    }
    
    .answer-btn, .answer-option {
        font-size: 1rem !important;
        padding: 15px !important;
        min-height: 50px !important;
    }
    
    /* Fix cho modals */
    .modal-content {
        width: 95% !important;
        max-width: 95% !important;
        margin: 10px !important;
        padding: 20px 15px !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
    }
    
    /* Fix cho pet home */
    .pet-home-scene {
        min-height: 450px !important;
        padding: 15px !important;
    }
    
    .pet-home-display {
        padding: 15px !important;
    }
    
    .pet-home-emoji {
        font-size: 4rem !important;
    }
    
    /* Fix cho navigation */
    .nav-container {
        top: 10px !important;
        left: 10px !important;
        right: 10px !important;
    }
    
    /* Ẩn các element không cần thiết trên mobile */
    .breadcrumb {
        display: none !important;
    }
    
    /* Fix cho grid layouts - Luôn hiển thị 2 cột trên mobile */
    .game-grid, .grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px !important;
        padding: 10px !important;
    }
    
    /* Fix cho cards */
    .card, .game-box {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 auto 15px !important;
    }
}

/* ==================== SMALL MOBILE (< 480px) ==================== */
@media (max-width: 480px) {
    /* Tăng font size cho dễ đọc trên màn hình nhỏ */
    html {
        font-size: 15px;
    }
    
    header h1, .game-header h1, .app-title {
        font-size: 1.4rem !important;
    }
    
    .question, .question-text {
        font-size: 1.2rem !important;
    }
    
    .answer-btn, .answer-option {
        font-size: 1rem !important;
        padding: 14px !important;
    }
    
    button, .btn, .action-btn {
        font-size: 0.95rem !important;
        padding: 12px 18px !important;
    }
    
    /* Fix cho pet home trên màn hình rất nhỏ */
    .pet-home-scene {
        min-height: 400px !important;
    }
    
    .pet-home-emoji {
        font-size: 3rem !important;
    }
    
    /* Fix cho stats bars */
    .stat-bar-home, .stat-bar {
        height: 20px !important;
    }
    
    .stat-label-home, .stat-label {
        font-size: 0.8rem !important;
    }
    
    /* Fix cho action buttons */
    .home-actions-container {
        gap: 8px !important;
    }
    
    .home-action-btn {
        padding: 10px !important;
    }
    
    .home-action-icon {
        font-size: 1.5rem !important;
    }
    
    .home-action-name {
        font-size: 0.8rem !important;
    }
    
    .home-action-cost {
        font-size: 0.75rem !important;
    }
}

/* ==================== LANDSCAPE MODE FIX ==================== */
@media (max-width: 768px) and (orientation: landscape) {
    /* Fix cho landscape mode trên mobile */
    .container, .app-container {
        height: auto !important;
        min-height: 100vh !important;
    }
    
    .pet-home-scene {
        min-height: 350px !important;
    }
    
    /* Giảm padding để tận dụng không gian - Đã ẩn nav nên không cần padding-top lớn */
    .container {
        padding: 15px 15px 15px 15px !important;
    }
    
    body.has-bottom-nav {
        padding-bottom: 60px !important;
    }
}

/* ==================== SAFE AREA INSETS (iOS) ==================== */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    
    .nav-container {
        top: max(10px, env(safe-area-inset-top));
        left: max(10px, env(safe-area-inset-left));
        right: max(10px, env(safe-area-inset-right));
    }
    
    .bottom-nav {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
}

/* ==================== TOUCH IMPROVEMENTS ==================== */
/* Tăng kích thước touch target cho mobile */
@media (max-width: 768px) {
    a, button, input, select, textarea, .clickable {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Remove tap highlight */
    * {
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Smooth scrolling */
    * {
        -webkit-overflow-scrolling: touch;
    }
}

/* ==================== FIX SPECIFIC PAGES ==================== */

/* Fix cho trang Dashboard */
@media (max-width: 768px) {
    .dashboard-container {
        padding: 70px 10px 70px 10px !important;
    }
    
    .overview-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .leaderboard-table {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
}

/* Fix cho trang 1 Vạn Câu Hỏi */
/* Đã được xử lý trong 1vancauhoivisao/style.css - không override để tránh conflict */

/* Fix cho Result Pages */
@media (max-width: 768px) {
    .result-container {
        padding: 20px 15px !important;
        width: 95% !important;
    }
    
    .score-value {
        font-size: 2rem !important;
    }
    
    .result-message {
        font-size: 1.2rem !important;
    }
}


/* ==================== FIX HOMEPAGE ==================== */
@media (max-width: 768px) {
    /* Fix homepage content - Giảm padding-top vì đã ẩn nav */
    .content {
        padding: 15px 15px 80px 15px !important;
    }
    
    h1 {
        font-size: 1.8rem !important;
        margin-bottom: 30px !important;
    }
    
    .game-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 20px !important;
        padding: 0 !important;
        justify-content: unset !important;
    }
    
    .game-box {
        width: 100% !important;
        max-width: none !important;
        padding: 25px !important;
    }
    
    .icon-wrap {
        width: 100px !important;
        height: 100px !important;
    }
    
    .icon-wrap img {
        width: 60px !important;
        height: 60px !important;
    }
    
    .game-title {
        font-size: 1.3rem !important;
    }
    
    .game-desc {
        font-size: 0.9rem !important;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.5rem !important;
    }
    
    .game-grid {
        gap: 10px !important;
    }
    
    .game-box {
        padding: 15px !important;
    }
    
    .icon-wrap {
        width: 70px !important;
        height: 70px !important;
        margin-bottom: 10px !important;
    }
    
    .icon-wrap img {
        width: 45px !important;
        height: 45px !important;
    }
    
    .game-title {
        font-size: 1rem !important;
        margin-bottom: 5px !important;
    }
    
    .game-desc {
        font-size: 0.85rem !important;
    }
}

/* ==================== FIX TOAN GAME ==================== */
@media (max-width: 768px) {
    /* Fix container */
    .container {
        max-width: 100% !important;
        width: calc(100% - 20px) !important;
        margin: 10px !important;
    }
    
    /* Fix game header */
    .game-header h1 {
        font-size: 1.8rem !important;
    }
    
    /* Fix stats */
    .stats {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        justify-content: space-between !important;
    }
    
    .stat-item {
        flex: 0 0 48% !important;
        margin-bottom: 10px !important;
    }
    
    /* Fix question display */
    .question-display {
        font-size: 2rem !important;
        padding: 20px !important;
    }
    
    /* Fix answer buttons */
    .answer-btn {
        font-size: 1.3rem !important;
        padding: 18px !important;
    }
    
    /* Fix Top 3 Display - End Game */
    .top3-container {
        padding: 15px !important;
        margin: 15px 0 !important;
    }
    
    .top3-title {
        font-size: 16px !important;
        margin-bottom: 12px !important;
    }
    
    .top3-list {
        gap: 8px !important;
    }
    
    .top3-item {
        padding: 10px 8px !important;
        gap: 8px !important;
    }
    
    .top3-rank {
        font-size: 24px !important;
        width: 30px !important;
    }
    
    .top3-avatar {
        width: 40px !important;
        height: 40px !important;
        font-size: 24px !important;
    }
    
    .top3-info {
        flex: 1 !important;
        min-width: 0 !important;
        overflow: hidden !important;
    }
    
    .top3-name {
        font-size: 13px !important;
        margin-bottom: 2px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    
    .top3-score {
        font-size: 12px !important;
    }
}

/* ==================== FIX TIENG VIET GAME ==================== */
@media (max-width: 768px) {
    /* Fix app container */
    .app-container {
        border-radius: 0 !important;
        height: 100vh !important;
        max-height: 100vh !important;
    }
    
    /* Fix home content - Giảm padding-top vì đã ẩn nav */
    .home-content {
        padding: 15px 20px 80px !important;
    }
    
    .app-title {
        font-size: 2rem !important;
    }
    
    /* Fix game modes */
    .game-modes {
        gap: 15px !important;
    }
    
    .mode-card {
        padding: 20px !important;
    }
    
    /* Fix game page - Giảm padding-top vì đã ẩn nav */
    .game-content {
        padding: 15px 15px 80px !important;
    }
    
    /* Fix word display */
    .word-display {
        font-size: 2.5rem !important;
        padding: 20px !important;
    }
    
    /* Fix letter buttons */
    .letter-btn {
        width: 45px !important;
        height: 45px !important;
        font-size: 1.2rem !important;
    }
}

/* ==================== FIX TIENG ANH GAME ==================== */
@media (max-width: 768px) {
    /* Fix container - Giảm padding-top vì đã ẩn nav */
    .container {
        padding: 15px 15px 80px 15px !important;
    }
    
    /* Fix header */
    .header-content h1 {
        font-size: 1.5rem !important;
    }
    
    /* Fix score board */
    .score-board {
        flex-wrap: wrap !important;
        gap: 10px !important;
    }
    
    .score-item {
        flex: 0 0 48% !important;
    }
    
    /* Fix game selection - Luôn hiển thị 2 cột trên mobile */
    .game-selection {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px !important;
    }
    
    /* Fix matching game - Luôn hiển thị 2 cột trên mobile */
    .matching-game {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
    }
    
    .column {
        padding: 10px !important;
    }
    
    .column h3 {
        font-size: 0.9rem !important;
        margin-bottom: 10px !important;
    }
    
    .match-item {
        padding: 12px 8px !important;
        font-size: 0.95rem !important;
        margin: 8px 0 !important;
    }
    
    .match-item > div:first-child {
        font-size: 2em !important;
    }
    
    .word-text {
        font-size: 1.1em !important;
    }
    
    .translation-text {
        font-size: 0.8em !important;
    }
    
    .word-card {
        padding: 15px !important;
        font-size: 1rem !important;
    }
    
    /* Fix quiz */
    .quiz-question {
        font-size: 1.3rem !important;
        padding: 20px !important;
    }
    
    .quiz-option {
        font-size: 1rem !important;
        padding: 15px !important;
    }
}

/* ==================== FIX NUOI THU AO ==================== */
@media (max-width: 768px) {
    /* Fix pet home section */
    .pet-home-section {
        padding: 0 !important;
    }
    
    /* Fix stats header */
    .pet-home-stats-header {
        padding: 8px 10px !important;
        gap: 6px !important;
        flex-wrap: wrap !important;
        justify-content: space-between !important;
    }
    
    .pet-home-stats-header .stat-item {
        font-size: 0.85rem !important;
        flex: 0 1 auto !important;
        min-width: 0 !important;
        white-space: nowrap !important;
    }
    
    /* Fix pet home scene */
    .pet-home-scene {
        min-height: 450px !important;
        padding: 15px !important;
    }
    
    /* Fix house */
    .house {
        padding: 15px !important;
    }
    
    /* Fix pet display */
    .pet-home-display {
        padding: 15px !important;
    }
    
    .pet-home-emoji {
        font-size: 4rem !important;
    }
    
    .pet-home-name {
        font-size: 1.2rem !important;
    }
    
    /* Fix stats bars */
    .stats-container {
        gap: 10px !important;
        padding: 10px !important;
    }
    
    .stat-bar-home {
        margin-bottom: 10px !important;
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
    }
    
    .stat-label-home {
        display: flex !important;
        align-items: center !important;
        gap: 5px !important;
        line-height: 1.2 !important;
        min-width: 90px !important;
        white-space: nowrap !important;
    }
    
    .stat-bar-bg-home {
        flex: 1 !important;
    }
    
    /* Fix action buttons */
    .home-actions-container {
        gap: 10px !important;
        padding: 10px !important;
    }
    
    .home-action-btn {
        padding: 12px 8px !important;
    }
    
    .home-action-icon {
        font-size: 1.8rem !important;
    }
    
    .home-action-name {
        font-size: 0.85rem !important;
    }
    
    .home-action-cost {
        font-size: 0.75rem !important;
    }
    
    /* Fix bottom actions - Now inside house */
    .bottom-actions {
        padding: 0 !important;
        gap: 6px !important;
        margin-top: 10px !important;
    }
    
    .bottom-actions.extra-actions {
        margin-top: -50px !important;
    }
    
    .action-btn {
        font-size: 0.9rem !important;
        padding: 10px 15px !important;
    }
    
    .bottom-actions .action-btn {
        padding: 8px 10px !important;
        margin-bottom: 0 !important;
    }
    
    /* Fix quests button - Góc trái trong house */
    .quests-button {
        top: 8px !important;
        bottom: auto !important;
        left: 8px !important;
        right: auto !important;
        width: 40px !important;
        height: 40px !important;
        font-size: 1.2rem !important;
    }
    
    /* Fix modals */
    .modal-content {
        width: 95% !important;
        max-width: 95% !important;
        padding: 20px 15px !important;
    }
    
    /* Fix quiz modal */
    .quiz-container {
        padding: 15px !important;
    }
    
    .question {
        font-size: 1.2rem !important;
        padding: 15px !important;
    }
    
    .answers {
        gap: 10px !important;
    }
    
    .answer-btn {
        font-size: 1rem !important;
        padding: 15px !important;
    }
}

@media (max-width: 480px) {
    .pet-home-scene {
        min-height: 400px !important;
    }
    
    .pet-home-emoji {
        font-size: 3rem !important;
    }
    
    .home-action-btn {
        padding: 10px 6px !important;
    }
    
    .home-action-icon {
        font-size: 1.5rem !important;
    }
    
    .home-action-name {
        font-size: 0.75rem !important;
    }
}

/* ==================== FIX DASHBOARD ==================== */
@media (max-width: 1024px) {
    /* Fix dashboard container - Giảm padding-top vì đã ẩn nav */
    .dashboard-container {
        padding: 15px 10px 80px 10px !important;
    }
    
    /* Fix sidebar - Đã được xử lý trong dashboard.css */
    /* Không override để tránh conflict */
    
    /* Fix main content */
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 15px !important;
    }
    
    /* Fix overview grid - Luôn hiển thị 2 cột trên mobile */
    .overview-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px !important;
    }
    
    /* Fix overview card */
    .overview-card {
        padding: 15px !important;
    }
    
    /* Fix leaderboard */
    .leaderboard-section {
        padding: 15px !important;
    }
    
    .leaderboard-table {
        overflow-x: auto !important;
    }
    
    /* Fix table for mobile */
    .table-header, .table-row {
        font-size: 0.85rem !important;
        padding: 10px 5px !important;
    }
}

/* ==================== FIX 1 VAN CAU HOI ==================== */
/* Không áp dụng CSS cho sidebar ở đây nữa - để tránh conflict với Dashboard */
/* Mỗi trang sẽ tự quản lý sidebar của mình */
@media (max-width: 1024px) {
    /* Fix question card */
    .question-card {
        padding: 20px 15px !important;
    }
    
    .question-title {
        font-size: 1.3rem !important;
    }
    
    .question-content {
        font-size: 1rem !important;
        line-height: 1.6 !important;
    }
    
    /* Fix category buttons */
    .category-btn {
        font-size: 0.9rem !important;
        padding: 10px 15px !important;
    }
}
