/* Reset & Font */
* { box-sizing: border-box; }
body { font-family: 'Nunito', sans-serif; background: #f0fdfa; height: 100vh; margin: 0; overflow: hidden; }

/* Layout chính */
.main-container {
    display: flex; height: 100%; max-width: 1200px; margin: 0 auto; padding: 15px; gap: 15px;
}

/* Cột trái (Canvas) */
.canvas-card {
    flex: 2; background: white; border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
    border: 4px solid #fff; display: flex; flex-direction: column; overflow: hidden;
}

/* Tabs chọn chủ đề */
.tabs { display: flex; background: #f0f9ff; padding: 6px; gap: 6px; border-bottom: 2px solid #e0f2fe; }
.tab-btn {
    flex: 1; padding: 10px; border-radius: 12px; font-weight: 800; color: #64748b;
    border: 2px solid transparent; cursor: pointer; background: transparent; transition: 0.2s;
}
.tab-btn.active { background: white; color: #0f766e; border-color: #0d9488; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }

/* Canvas Area */
.canvas-wrap { flex: 1; position: relative; background: #fff; cursor: pointer; overflow: hidden; }
canvas { width: 100%; height: 100%; touch-action: none; }

/* Thanh điều hướng Level */
.level-bar {
    display: flex; justify-content: space-between; align-items: center; padding: 10px 20px;
    background: #f8fafc; border-top: 1px dashed #cbd5e1;
}
.level-info { text-align: center; }
.level-title { font-weight: 900; color: #334155; font-size: 1.1rem; }
.question-text { font-size: 0.8rem; font-weight: 800; color: #94a3b8; text-transform: uppercase; }

.btn-nav {
    background: #e2e8f0; width: 40px; height: 40px; border-radius: 50%; border: none;
    display: flex; align-items: center; justify-content: center; font-weight: 900; color: #475569; cursor: pointer;
}
.btn-nav:hover { background: #cbd5e1; }

/* Toolbar nút kiểm tra */
.toolbar {
    height: 80px; padding: 0 20px; background: #f1f5f9; border-top: 2px solid #e2e8f0;
    display: flex; align-items: center; justify-content: space-between;
}
.selection-info .label { font-size: 0.75rem; font-weight: 800; color: #94a3b8; text-transform: uppercase; }
.selection-info .value { font-size: 1.5rem; font-weight: 900; color: #0d9488; }

.btn-check {
    background: #0d9488; color: white; padding: 12px 35px; border: none;
    border-radius: 18px; font-size: 1.1rem; font-weight: 900; cursor: pointer;
    box-shadow: 0 4px 0 #115e59; transition: all 0.1s;
}
.btn-check:active { transform: translateY(4px); box-shadow: none; }

/* Cột phải (Kết quả) */
.sidebar {
    flex: 1; background: white; border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.05); padding: 15px; display: flex; flex-direction: column;
}
.sidebar-title { text-align: center; margin: 0 0 10px 0; color: #334155; font-weight: 900; }

.progress-container { margin-bottom: 15px; }
.prog-text { text-align: center; color: #94a3b8; font-weight: 800; margin-bottom: 5px; font-size: 0.9rem; }
.prog-bg { width: 100%; background: #f1f5f9; height: 10px; border-radius: 5px; overflow: hidden; }
.prog-fill { height: 100%; background: #14b8a6; width: 0%; transition: 0.5s; }

.res-box { flex: 1; overflow-y: auto; padding-right: 5px; }

/* Nhóm kết quả */
.res-group { margin-bottom: 15px; }
.res-group-title { font-size: 0.85rem; font-weight: 800; color: #64748b; margin-bottom: 5px; border-bottom: 1px solid #e2e8f0; padding-bottom: 3px; }
.chip {
    display: inline-block; background: #f1f5f9; border: 2px solid #e2e8f0;
    padding: 5px 10px; border-radius: 8px; margin: 3px;
    color: #475569; font-weight: 800; font-size: 0.9rem;
}
.chip.new { background: #ccfbf1; border-color: #2dd4bf; color: #115e59; animation: pop 0.4s; }

@keyframes pop { 0% { transform: scale(0.5); } 80% { transform: scale(1.1); } 100% { transform: scale(1); } }

.btn-reset {
    width: 100%; padding: 12px; background: #f8fafc; color: #94a3b8; font-weight: 800;
    border: none; border-radius: 12px; cursor: pointer; margin-top: 10px;
}
.btn-reset:hover { background: #e2e8f0; }

/* Thông báo (Toast) */
.toast {
    position: absolute; top: 20px; left: 50%; transform: translateX(-50%);
    padding: 10px 25px; border-radius: 30px; color: white; font-weight: 800;
    opacity: 0; pointer-events: none; transition: 0.3s; z-index: 100;
    box-shadow: 0 10px 20px rgba(0,0,0,0.15); white-space: nowrap;
}
.toast.success { background: #0d9488; }
.toast.err { background: #ef4444; }
.toast.warn { background: #f59e0b; }

/* --- MOBILE FIX: Giao diện điện thoại --- */
@media (max-width: 768px) {
    /* 1. Khóa cuộn trang chính, ép chiều cao 100% màn hình */
    body {
        position: fixed;
        width: 100%;
        height: 100%;
        overflow: hidden; /* Không cho cuộn cả trang */
    }

    .main-container {
        flex-direction: column;
        height: 100vh; /* Chiều cao bằng màn hình */
        padding: 10px;
        gap: 10px;
    }

    /* 2. Phần Hình Vẽ (Canvas Card) - Chiếm 60% màn hình */
    .canvas-card {
        flex: 0 0 60%; /* Cố định 60%, không co giãn */
        height: 60%; 
        margin-bottom: 0;
        display: flex;
        flex-direction: column;
        min-height: 0; /* Quan trọng để con cái co giãn được */
    }
    
    /* Ép Canvas co giãn để nhường chỗ cho Toolbar */
    .canvas-wrap {
        flex: 1;
        min-height: 0; 
    }

    /* 3. Phần Kết Quả (Sidebar) - Chiếm phần còn lại */
    .sidebar {
        flex: 1; /* Chiếm hết phần thừa còn lại */
        height: auto;
        min-height: 0; /* Quan trọng để bật cuộn bên trong */
        display: flex;
        flex-direction: column;
        padding: 10px;
        overflow: hidden; /* Ẩn phần thừa của chính nó */
    }

    .sidebar-title {
        font-size: 1rem;
        margin-bottom: 5px;
    }

    /* Khu vực chứa các chip kết quả: Cho phép cuộn riêng */
    .res-box {
        overflow-y: auto; /* Chỉ cuộn khu vực này */
        flex: 1;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
        border-radius: 8px;
        padding: 5px;
        margin-bottom: 5px;
    }

    /* 4. Fix lỗi dòng chữ "Đang chọn" quá dài làm vỡ khung */
    .selection-info {
        max-width: 50%; /* Giới hạn chiều rộng */
    }
    .selection-info .value {
        font-size: 1.2rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis; /* Hiện dấu ... nếu dài quá */
    }

    .toolbar {
        height: 60px; /* Thu nhỏ toolbar một chút trên mobile */
        padding: 0 10px;
    }
    
    .btn-check {
        padding: 8px 20px;
        font-size: 1rem;
    }
}