/* * Filename: assets/css/style.css
 * Description: Stylesheet for Khang's Learning Quest (V5.3 - Shop Fix)
 * Theme: Colorful Gradient, Transparent 3D, Mobile Touch Fixed
 */

/* =========================================
   1. VARIABLES & RESET
   ========================================= */
:root {
    --primary: #FF9800;    
    --primary-dark: #F57C00;
    --secondary: #2196F3;  
    --accent: #4CAF50;     
    --accent-dark: #388E3C;
    --danger: #FF5252;     
    --gold: #FFC107;       
    --text: #5D4037;       
    
    --font-main: 'Patrick Hand', 'Comic Sans MS', cursive, sans-serif;
    --radius-lg: 25px;
    --radius-md: 15px;
}

html { margin-top: 0 !important; }
#wpadminbar { display: none !important; }

body {
    margin: 0; padding: 0;
    overflow: hidden;
    font-family: var(--font-main);
}

/* =========================================
   2. GAME WRAPPER (NỀN CHUYỂN ĐỘNG)
   ========================================= */
#klq-game-wrapper {
    position: fixed; 
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100vw; height: 100vh;
    
    /* Gradient nền */
    background: linear-gradient(-45deg, #FF9A9E, #FECFEF, #A18CD1, #84FAB0);
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    
    z-index: 999999; 
    overflow: hidden;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

#klq-game-container { width: 100%; height: 100%; display: block; }
#klq-game-container canvas { display: block; width: 100%; height: 100%; outline: none; }

/* =========================================
   3. UI LAYER (LỚP GIAO DIỆN)
   ========================================= */
#klq-ui-layer {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; /* Mặc định không chặn click để xuyên xuống 3D */
    z-index: 10;
}

/* BẬT LẠI TƯƠNG TÁC CHO CÁC PHẦN TỬ CON */
.klq-top-bar, 
#klq-dialog-box, 
#klq-shop-modal, 
#klq-alert-modal,
.modal-content, 
.game-btn, 
#essay-input {
    pointer-events: auto !important; /* Bắt buộc nhận click */
}

/* =========================================
   4. TOP BAR
   ========================================= */
.klq-top-bar {
    position: absolute; top: 15px; left: 15px; right: 15px;
    display: flex; justify-content: space-between; align-items: center;
    z-index: 20;
}

.coin-display {
    background: rgba(255, 255, 255, 0.9);
    padding: 8px 15px; border-radius: 30px;
    border: 3px solid #FFF; box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    display: flex; align-items: center; gap: 6px;
    font-size: 1.3rem; font-weight: bold; color: var(--gold);
}
.coin-icon { font-size: 1.5rem; }

.action-buttons button {
    background: rgba(255, 255, 255, 0.9); border: none;
    border-radius: var(--radius-md); padding: 8px 12px;
    font-family: var(--font-main); font-size: 1.1rem; font-weight: bold;
    color: var(--secondary); cursor: pointer; margin-left: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.action-buttons button:active { transform: translateY(3px); }

/* =========================================
   5. DIALOG BOX
   ========================================= */
#klq-dialog-box {
    position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
    width: 90%; max-width: 600px;
    background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(5px);
    border-radius: var(--radius-lg); padding: 20px;
    border-bottom: 8px solid rgba(0,0,0,0.1);
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    display: flex; flex-direction: column;
    animation: slideUp 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.avatar-circle {
    position: absolute; top: -30px; left: 20px; width: 60px; height: 60px;
    background: #FFEB3B; border-radius: 50%; border: 4px solid #FFF;
    display: flex; align-items: center; justify-content: center;
    font-size: 30px; box-shadow: 0 5px 15px rgba(0,0,0,0.15);
    transform: rotate(-10deg); z-index: 25;
}

#klq-speaker { margin: 0 0 5px 60px; color: var(--primary); font-size: 1.3rem; font-weight: 900; text-transform: uppercase; }
#klq-text { margin: 0; color: var(--text); font-size: 1.25rem; line-height: 1.4; min-height: 50px; }
#klq-options { display: grid; grid-template-columns: 1fr; gap: 10px; }

/* Tự luận */
#klq-essay-area { margin-top: 15px; display: flex; flex-direction: column; gap: 10px; animation: fadeIn 0.3s ease; }
#essay-input {
    width: 100%; height: 90px; padding: 12px;
    border: 2px solid #CFD8DC; border-radius: var(--radius-md);
    font-family: var(--font-main); font-size: 1.2rem; color: #333;
    resize: none; outline: none; background: #F9FAFB;
    /* Fix nhập liệu trên mobile */
    user-select: text !important; -webkit-user-select: text !important;
}
#essay-input:focus { border-color: var(--primary); background: #FFF; }

/* Buttons */
.game-btn {
    background: var(--accent); color: white; border: none;
    padding: 14px 20px; border-radius: var(--radius-md);
    font-family: var(--font-main); font-size: 1.2rem; font-weight: bold;
    cursor: pointer; box-shadow: 0 5px 0 var(--accent-dark);
    text-align: left; transition: all 0.1s; width: 100%;
}
.game-btn:active { transform: translateY(5px); box-shadow: 0 0 0 var(--accent-dark); }
.start-btn { background: var(--primary); box-shadow: 0 5px 0 var(--primary-dark); text-align: center; animation: pulse 2s infinite; }

/* =========================================
   6. MODALS (FIX LỖI SCROLL & CLICK)
   ========================================= */
#klq-shop-modal, #klq-alert-modal {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(4px);
    z-index: 10000; /* Cao hơn tất cả */
    display: flex; align-items: center; justify-content: center;
    opacity: 1; transition: opacity 0.3s;
}

.hidden { display: none !important; opacity: 0; }

.shop-content, .alert-content {
    background: #FFF; width: 90%; max-width: 420px;
    border-radius: var(--radius-lg); padding: 25px; text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    border: 5px solid var(--secondary);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    
    /* FIX QUAN TRỌNG: Đảm bảo nội dung bên trong nhận sự kiện chuột */
    pointer-events: auto !important;
    position: relative;
}

.modal-header { color: var(--primary); font-size: 1.8rem; font-weight: bold; margin-bottom: 10px; }

/* SHOP ITEMS - FIX CUỘN TRÊN MOBILE */
.shop-items {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
    margin: 15px 0; padding: 5px;
    
    /* Kích thước vùng cuộn */
    max-height: 55vh; 
    overflow-y: auto; /* Cho phép cuộn dọc */
    
    /* FIX IOS & ANDROID SCROLL */
    -webkit-overflow-scrolling: touch; /* Mượt mà trên iPhone */
    touch-action: pan-y; /* Cho phép trượt dọc trên Android */
    overscroll-behavior: contain; /* Không cuộn lan ra body */
    
    /* Đảm bảo nhận click */
    pointer-events: auto !important;
}

.shop-item {
    background: #F1F8E9; border: 2px solid #DCEDC8;
    border-radius: var(--radius-md); padding: 10px;
    cursor: pointer; transition: transform 0.1s;
    
    /* Fix chọn item */
    user-select: none; 
    pointer-events: auto; /* Bắt buộc */
}

.shop-item:active { transform: scale(0.95); background: #DCEDC8; }
.shop-item:hover { border-color: var(--primary); }
.shop-item.owned { opacity: 0.6; background: #EEEEEE; border-color: #E0E0E0; cursor: default; }

.item-icon { font-size: 2.2rem; display: block; margin-bottom: 5px; }
.item-name { font-weight: bold; margin-bottom: 3px; display: block; }
.item-price {
    color: var(--danger); font-weight: bold;
    background: rgba(255, 82, 82, 0.1); padding: 2px 8px;
    border-radius: 8px; font-size: 0.9rem;
}

.close-btn {
    background: var(--danger); color: white; border: none;
    padding: 10px 20px; border-radius: var(--radius-md);
    font-family: var(--font-main); font-size: 1.1rem; font-weight: bold;
    cursor: pointer; box-shadow: 0 4px 0 #C62828; margin-top: 10px;
}
.close-btn:active { transform: translateY(4px); box-shadow: none; }

/* =========================================
   7. OTHER ELEMENTS
   ========================================= */
#loading-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255,255,255,0.85); display: none;
    flex-direction: column; align-items: center; justify-content: center; z-index: 200;
}
.loader {
    border: 6px solid #f3f3f3; border-top: 6px solid var(--primary);
    border-radius: 50%; width: 50px; height: 50px;
    animation: spin 1s linear infinite; margin-bottom: 15px;
}
@keyframes spin { 100% { transform: rotate(360deg); } }
@keyframes popIn { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes slideUp { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
@keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.05); } 100% { transform: scale(1); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

@media screen and (max-width: 600px) {
    #klq-dialog-box { width: 95%; bottom: 10px; padding: 15px; }
    .avatar-circle { width: 50px; height: 50px; font-size: 25px; top: -25px; }
    #klq-speaker { margin-left: 50px; font-size: 1.1rem; }
    .game-btn { padding: 12px 15px; font-size: 1.1rem; }
    .coin-display { font-size: 1.1rem; padding: 6px 10px; }
}