/* =========================================
   1. CORE VARIABLES & RESET
   ========================================= */
:root {
    --primary-color: #4ecdc4;       /* Xanh ngọc */
    --secondary-color: #ff6b6b;     /* Đỏ hồng */
    --accent-color: #ff9ff3;        /* Hồng phấn */
    --success-color: #2ecc71;       /* Xanh lá */
    --bg-color: #e0f2fe;            /* Nền game */
    --panel-bg: #ffffff;            /* Nền khung */
    --text-font: 'Comic Sans MS', 'Chalkboard SE', 'Fredoka One', sans-serif;
}

#kac-game-wrapper * { box-sizing: border-box; }
#kac-game-wrapper { display: none; font-family: var(--text-font); }
body.kac-locked { overflow: hidden !important; touch-action: none; }

/* =========================================
   2. NÚT BẮT ĐẦU GAME
   ========================================= */
.kac-btn-start {
    display: inline-block; padding: 20px 45px; font-size: 22px; font-weight: 900;
    color: white; background: linear-gradient(135deg, #ff9ff3 0%, #ff6b6b 100%);
    border: 5px solid #fff; border-radius: 60px; cursor: pointer;
    text-transform: uppercase; letter-spacing: 1px; font-family: var(--text-font);
    box-shadow: 0 10px 25px rgba(255, 107, 107, 0.5);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    animation: floatPulse 3s infinite ease-in-out;
}
.kac-btn-start:hover { transform: translateY(-5px) scale(1.05); box-shadow: 0 15px 35px rgba(255, 107, 107, 0.7); }
.kac-btn-start:active { transform: scale(0.95); box-shadow: 0 5px 15px rgba(255, 107, 107, 0.4); }
.kac-btn-start .dashicons { font-size: 32px; width: 32px; height: 32px; vertical-align: middle; margin-right: 10px; margin-bottom: 5px; }
@keyframes floatPulse { 0% { transform: scale(1); } 50% { transform: scale(1.05); } 100% { transform: scale(1); } }

/* =========================================
   3. FULLSCREEN CONTAINER
   ========================================= */
#kac-game-wrapper.active {
    display: flex !important; flex-direction: column;
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    width: 100vw; height: 100dvh; background: var(--bg-color); z-index: 999999;
    padding-top: env(safe-area-inset-top); padding-left: 0; padding-right: 0; padding-bottom: 0;
}

/* =========================================
   4. HEADER
   ========================================= */
.kac-header {
    flex: 0 0 auto; text-align: center; margin-bottom: 5px; position: relative; padding-top: 5px; padding-left: 10px; padding-right: 10px;
}
.kac-header h2 { color: var(--secondary-color); margin: 0; font-size: 1.4em; text-shadow: 2px 2px 0 #fff; line-height: 1.2; }
#kac-exit-fullscreen {
    position: absolute; right: 10px; top: 5px; background: #ff4757; color: white; border: none; width: 35px; height: 35px; border-radius: 50%; cursor: pointer; box-shadow: 0 2px 5px rgba(0,0,0,0.2); display: flex; align-items: center; justify-content: center;
}
#kac-topic-box {
    background: #fff; padding: 5px 15px; border-radius: 20px; display: inline-block; border: 2px dashed var(--primary-color); margin-top: 5px; font-size: 1em; box-shadow: 0 2px 5px rgba(0,0,0,0.05); max-width: 95%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kac-topic-box .label { color: #888; font-size: 0.9em; }
#btn-new-topic {
    background: var(--primary-color); color: white; border: none; padding: 4px 10px; border-radius: 10px; margin-left: 8px; cursor: pointer; font-size: 0.85em; font-family: var(--text-font);
}

/* =========================================
   5. MAIN LAYOUT
   ========================================= */
.kac-main-area {
    flex: 1 1 auto; display: flex; gap: 15px; overflow: hidden; position: relative; padding: 0 10px 10px 10px;
}

/* =========================================
   6. SIDEBAR / TOOLBAR (DESKTOP)
   ========================================= */
.kac-sidebar {
    background: var(--panel-bg); padding: 10px; border-radius: 15px; display: flex; box-shadow: 0 4px 15px rgba(0,0,0,0.05); z-index: 50; flex-direction: column; width: 80px; overflow-y: auto; gap: 12px; border: 2px solid #fff;
}
.tool-group { display: flex; justify-content: center; }
input[type=color] { width: 45px; height: 45px; padding: 0; border: 3px solid #eee; border-radius: 50%; cursor: pointer; background: none; overflow: hidden; }
input[type=range] { width: 100%; cursor: pointer; accent-color: var(--primary-color); }
.kac-tool-btn {
    width: 100%; height: 50px; border: none; border-radius: 12px; background: #f1f2f6; color: #57606f; cursor: pointer; transition: 0.2s; display: flex; align-items: center; justify-content: center;
}
.kac-tool-btn .dashicons { font-size: 24px; }
.kac-tool-btn.active { background: var(--primary-color); color: white; box-shadow: 0 4px 0 #3cb0a8; transform: translateY(-2px); }
.kac-tool-btn.active:active { transform: translateY(2px); box-shadow: none; }
.kac-tool-btn.danger { background: var(--secondary-color); color: white; margin-top: auto; }
.kac-btn-submit {
    background: var(--success-color); color: white; border: none; border-radius: 12px; width: 100%; padding: 10px 0; font-weight: bold; cursor: pointer; box-shadow: 0 4px 0 #27ae60; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 12px; animation: pulse 2s infinite;
}
.kac-btn-submit:active { transform: translateY(3px); box-shadow: none; animation: none;}
@keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.05); } 100% { transform: scale(1); } }

/* =========================================
   7. CANVAS AREA
   ========================================= */
.kac-canvas-outer {
    flex: 1 1 auto; background: #cbd5e1; border-radius: 15px; padding: 8px; position: relative; display: flex; justify-content: center; align-items: center; box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
}
.kac-canvas-container {
    width: 100%; height: 100%; background: #fff; border-radius: 10px; cursor: crosshair; box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
canvas#drawing-canvas { display: block; touch-action: none; }

/* =========================================
   8. CHAT PANEL
   ========================================= */
.kac-chat-panel {
    position: absolute; bottom: 20px; right: 20px; width: 300px;
    background: #fff; border: 3px solid var(--accent-color); border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25); z-index: 100;
    display: flex; flex-direction: column; 
    /* Thêm transition cho bottom để hiệu ứng trượt mượt mà */
    transition: bottom 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), opacity 0.3s;
    max-height: 60vh;
}
.kac-chat-header {
    background: var(--accent-color); padding: 12px 15px; color: white; font-weight: bold; display: flex; justify-content: space-between; align-items: center; border-radius: 12px 12px 0 0; cursor: pointer; user-select: none; font-size: 1.1em;
}
.kac-chat-header:hover { background: #ff88ec; }
.kac-chat-header #toggle-chat { background: none; border: none; color: white; font-size: 1.4em; cursor: pointer; pointer-events: none; }
.kac-chat-content {
    padding: 15px; overflow-y: auto; background: #fdfdfd; border-radius: 0 0 15px 15px; flex-grow: 1; min-height: 120px;
}
.kac-chat-panel.collapsed .kac-chat-content { display: none !important; }
.kac-chat-panel.collapsed .kac-chat-header { border-radius: 15px; }
.kac-chat-panel.collapsed { width: auto; min-width: 200px; }

.message { display: flex; margin-bottom: 12px; align-items: flex-start; }
.message .avatar { width: 40px; height: 40px; border-radius: 50%; margin-right: 10px; border: 2px solid var(--accent-color); background: #fff; flex-shrink: 0;}
.message .bubble { background: #f1f2f6; padding: 10px 14px; border-radius: 18px; border-top-left-radius: 2px; font-size: 15px; line-height: 1.5; color: #2d3436; box-shadow: 0 1px 2px rgba(0,0,0,0.1); }

/* =========================================
   9. MODAL & LOADING
   ========================================= */
#kac-modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.6); z-index: 9999999; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(2px); }
.kac-modal { background: #fff; width: 90%; max-width: 380px; border-radius: 25px; padding: 25px; text-align: center; border: 5px solid var(--primary-color); box-shadow: 0 20px 50px rgba(0,0,0,0.3); animation: popIn 0.3s; }
.kac-modal h3 { color: var(--secondary-color); margin-top: 0; font-size: 1.5em; }
.kac-modal-actions { display: flex; justify-content: center; gap: 15px; margin-top: 20px;}
.kac-modal button { padding: 10px 25px; border: none; border-radius: 50px; font-weight: bold; cursor: pointer; transition: 0.2s; }
.kac-btn-primary { background: var(--primary-color); color: white; box-shadow: 0 4px 0 #3cb0a8; }
.kac-btn-secondary { background: #dfe6e9; color: #636e72; box-shadow: 0 4px 0 #b2bec3; }
@keyframes popIn { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#kac-loading { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255,255,255,0.95); z-index: 9999998; display: flex; flex-direction: column; justify-content: center; align-items: center; color: var(--secondary-color); font-weight: bold; font-size: 1.2em; }
.loader { width: 50px; height: 50px; border: 6px solid #f3f3f3; border-top: 6px solid var(--secondary-color); border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 20px; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* =========================================
   10. MOBILE RESPONSIVE (FIXED POSITIONS)
   ========================================= */
@media (max-width: 768px) {
    .kac-main-area { flex-direction: column; padding: 0; gap: 0; margin-bottom: 120px; }
    .kac-header h2 { font-size: 1.1em; }
    #kac-topic-box { font-size: 0.9em; max-width: 85%; }
    .kac-canvas-outer { border-radius: 0; background: #cbd5e1; margin: 0; }

    /* TOOLBAR NỔI: Cách đáy 30px */
    .kac-sidebar {
        position: fixed; bottom: 30px; left: 15px; right: 15px;
        width: auto; height: auto; padding: 10px;
        flex-direction: row; justify-content: space-around; align-items: center;
        border-radius: 20px; border: 2px solid #fff; background: #fff;
        box-shadow: 0 5px 25px rgba(0,0,0,0.2);
    }
    .tool-group { margin: 0; }
    input[type=color] { width: 40px; height: 40px; } input[type=range] { width: 50px; margin: 0 5px; } 
    .kac-tool-btn, .kac-btn-submit { width: 45px; height: 45px; border-radius: 12px; margin: 0; padding: 0; }
    .kac-tool-btn .dashicons { font-size: 22px; }
    .kac-btn-submit { background: var(--success-color); width: 60px; font-size: 11px; animation: none;}
    .kac-tool-btn.danger { margin-top: 0; }

    /* CHAT PANEL: MỞ RỘNG (Cao để xem tin nhắn) */
    .kac-chat-panel {
        width: 92%; left: 4%; right: 4%;
        bottom: 115px; /* Cách đáy 115px để nằm trên toolbar */
        max-height: 45vh; border-width: 2px;
    }
    
    /* CHAT PANEL: ĐÓNG (QUAN TRỌNG: ĐẨY XUỐNG SÁT TOOLBAR) */
    .kac-chat-panel.collapsed {
        /* Toolbar đáy 30px + cao ~65px = đỉnh toolbar ở 95px */
        /* Đặt chat ở 98px để vừa khít phía trên */
        bottom: 98px !important; 
        
        width: auto; min-width: 180px;
        right: 15px; left: auto;
    }
}