/* Reset & Base */
* { box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; -webkit-tap-highlight-color: transparent; }
body { 
    background-color: #f0f2f5; 
    height: 100vh; /* Fallback */
    height: 100dvh; /* Fix Safari iPhone */
    display: flex; flex-direction: column; overflow: hidden; 
}

/* HEADER */
.header {
    background-color: #2c3e50; color: white; height: 60px;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 10px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); z-index: 50;
    flex-shrink: 0;
}

/* [SỬA QUAN TRỌNG] Cấu hình co giãn cho Header */
.header-left { 
    display: flex; align-items: center; gap: 8px; 
    flex: 1; /* Chiếm phần không gian còn lại */
    min-width: 0; /* Cho phép co nhỏ hơn nội dung để hiện dấu ... */
    margin-right: 5px; /* Tạo khoảng cách với cụm nút bên phải */
}

.header-right { 
    display: flex; align-items: center; gap: 8px; 
    flex-shrink: 0; /* Không cho phép cụm nút này bị co lại */
}

.logo { 
    font-size: 1.1rem; font-weight: bold; 
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; /* Hiện dấu ... nếu dài quá */
}

.timer { 
    font-family: monospace; font-size: 1.1rem; 
    background: rgba(0,0,0,0.2); padding: 5px 8px; 
    border-radius: 5px; min-width: 60px; text-align: center;
}

.menu-btn { background: none; border: none; color: white; font-size: 1.4rem; cursor: pointer; padding: 5px; }

/* Nút Nộp trên Header */
.btn-submit-header {
    background-color: #27ae60; color: white; border: none;
    padding: 6px 12px; border-radius: 4px; font-weight: bold; cursor: pointer;
    display: flex; align-items: center; gap: 5px; font-size: 0.9rem;
    white-space: nowrap; /* Không cho xuống dòng chữ Nộp */
}
.btn-submit-header:hover { background-color: #2ecc71; }

/* Nút làm lại trên Header */
.btn-reset-header {
    background-color: rgba(255, 255, 255, 0.15); 
    color: white; border: 1px solid rgba(255,255,255,0.2);
    padding: 6px 12px; border-radius: 4px; font-weight: bold; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem;
}
.btn-reset-header:hover { background-color: rgba(255, 255, 255, 0.3); }

/* LAYOUT */
.container { display: flex; flex: 1; position: relative; overflow: hidden; }

/* SIDEBAR */
.sidebar {
    width: 260px; background: white; border-right: 1px solid #ddd;
    display: flex; flex-direction: column; 
    z-index: 2000; 
    transition: transform 0.3s ease;
}
.sidebar-header {
    padding: 15px; background: #f8f9fa; border-bottom: 1px solid #ddd;
    font-weight: bold; color: #555; display: flex; justify-content: space-between; align-items: center;
}
.close-sidebar { background: none; border: none; font-size: 1.2rem; color: #888; cursor: pointer; display: none; }
.question-list { 
    padding: 10px; overflow-y: auto; flex: 1; 
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; align-content: start; 
    padding-bottom: 100px;
}
.q-btn {
    aspect-ratio: 1; background: #eee; border: none; border-radius: 8px;
    font-size: 0.9rem; font-weight: 500; cursor: pointer; color: #555;
    display: flex; justify-content: center; align-items: center;
}
.q-btn.active { background-color: #3498db; color: white; border: 2px solid #2980b9; }
.q-btn.answered { background-color: #27ae60; color: white; }
.q-btn.answered.active { background-color: #2ecc71; border: 2px solid #27ae60; }
.q-btn.wrong-mark { background-color: #e74c3c !important; color: white; }

.sidebar-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 1500; display: none;
}

/* MAIN CONTENT */
.main-content { 
    flex: 1; padding: 15px; overflow-y: auto; background: #eef2f5; 
    display: flex; flex-direction: column; align-items: center; 
    padding-bottom: 120px;
}
.question-card {
    background: white; width: 100%; max-width: 800px; border-radius: 12px;
    padding: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); margin-bottom: 20px;
}
.question-header h3 { color: #2c3e50; margin-bottom: 20px; line-height: 1.6; font-size: 1.1rem; }

.answers { display: flex; flex-direction: column; gap: 12px; }
.answer-option {
    padding: 15px; border: 1px solid #e0e0e0; border-radius: 8px;
    cursor: pointer; background: #fff; transition: all 0.2s; line-height: 1.4;
    -webkit-tap-highlight-color: rgba(0,0,0,0.05);
}
.answer-option:active { background-color: #f0f0f0; }
.answer-option.correct { background-color: #d1e7dd; border-color: #badbcc; color: #0f5132; }
.answer-option.wrong { background-color: #f8d7da; border-color: #f5c2c7; color: #842029; }
.answer-option.selected-neutral { background-color: #cfe2ff; border-color: #b6d4fe; color: #084298; font-weight: bold; }

/* BOTTOM NAV */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; width: 100%; 
    background: white; box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    display: flex; justify-content: space-around; align-items: center;
    padding: 10px; z-index: 45;
    padding-bottom: calc(10px + env(safe-area-inset-bottom)); /* Fix iPhone Home Bar */
    height: auto;
}
.bottom-nav button {
    padding: 12px 25px; border: none; border-radius: 25px;
    font-size: 1rem; font-weight: bold; cursor: pointer;
    display: flex; align-items: center; gap: 8px; width: 45%; justify-content: center;
}
#btn-prev { background: #f1f2f6; color: #555; }
#btn-next { background: #3498db; color: white; transition: background 0.3s;}
#btn-next:active { background: #2980b9; transform: scale(0.98); }
#btn-next.finish-mode { background: #27ae60; } 

/* MODAL CHUNG */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); display: flex; justify-content: center; align-items: center; z-index: 3000;
}
.modal-content {
    background: white; width: 90%; max-width: 400px; border-radius: 15px;
    overflow: hidden; animation: popup 0.3s ease-out; display: flex; flex-direction: column; max-height: 90vh;
}
@keyframes popup { from {transform: scale(0.8); opacity: 0;} to {transform: scale(1); opacity: 1;} }

/* --- CSS CÀI ĐẶT --- */
.modal-header { padding: 15px; background: #f8f9fa; border-bottom: 1px solid #eee; font-weight: bold; text-align: center; font-size: 1.1rem; }
.modal-body { padding: 15px; overflow-y: auto; }
.setting-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid #f0f0f0; }
.input-toggle-group { display: flex; align-items: center; gap: 10px; }
.input-number { width: 50px; padding: 5px; text-align: center; border: 1px solid #ccc; border-radius: 5px; }

/* CSS cho dropdown chọn phần */
.input-select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.95rem;
    color: #2c3e50;
    background-color: #f9f9f9;
    outline: none;
    cursor: pointer;
    max-width: 180px;
}
.input-select:focus { border-color: #3498db; background-color: #fff; }

/* --- CSS KẾT QUẢ --- */
.result-content { background: white; padding: 25px 20px; text-align: center; align-items: center; }
.trophy-container { margin-bottom: 10px; display: flex; justify-content: center; }
.trophy-circle { width: 80px; height: 80px; background: #fef9e7; border-radius: 50%; display: flex; justify-content: center; align-items: center; }
.trophy-circle i { font-size: 2.5rem; color: #f1c40f; text-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.result-message { font-size: 1.5rem; color: #2c3e50; margin: 5px 0 15px; }
.big-score-container { margin-bottom: 20px; }
.score-value { font-size: 3.5rem; font-weight: 800; color: #2c3e50; line-height: 1; }
.score-subtitle { color: #7f8c8d; font-size: 0.9rem; margin-top: 5px; text-transform: uppercase; }
.stats-grid { display: flex; gap: 15px; width: 100%; margin-bottom: 25px; }
.stat-box { flex: 1; background: #f8f9fa; padding: 15px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; gap: 5px; border: 1px solid #eee; }
.stat-box i { font-size: 1.2rem; color: #3498db; }
.stat-box span { font-size: 1.2rem; font-weight: bold; color: #2c3e50; }
.stat-box small { font-size: 0.8rem; color: #95a5a6; }
.result-actions { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.result-actions button { width: 100%; padding: 14px; border: none; border-radius: 30px; font-size: 1rem; font-weight: bold; cursor: pointer; display: flex; justify-content: center; align-items: center; gap: 8px; }
.btn-review { background: #ecf0f1; color: #2c3e50; }
.btn-restart { background: #3498db; color: white; box-shadow: 0 4px 10px rgba(52, 152, 219, 0.3); }

/* FOOTER MODAL SETUP */
.modal-footer { display: flex; border-top: 1px solid #eee; margin-top: auto; width: 100%; }
.modal-footer button { flex: 1; padding: 15px; border: none; font-weight: bold; font-size: 1rem; cursor: pointer; }
.btn-skip { background: #fff; color: #777; }
.btn-start { background: #3498db; color: white; }

/* SWITCH */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; border-radius: 34px; transition: .4s; }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 3px; bottom: 3px; background-color: white; border-radius: 50%; transition: .4s; }
input:checked + .slider { background-color: #2ecc71; }
input:checked + .slider:before { transform: translateX(20px); }

/* RESPONSIVE: Tinh chỉnh cho điện thoại */
@media (max-width: 768px) {
    .menu-btn { display: block; }
    .close-sidebar { display: block; }
    .sidebar {
        position: fixed; top: 0; left: 0; height: 100dvh; 
        transform: translateX(-100%);
        box-shadow: 2px 0 10px rgba(0,0,0,0.2);
    }
    .sidebar.active { transform: translateX(0); }
    .sidebar-overlay.active { display: block; }
    .bottom-nav { display: flex; }
    .container { margin-bottom: 0; }
    .question-list { grid-template-columns: repeat(6, 1fr); }

    /* [MỚI] Tinh chỉnh Header trên mobile nhỏ */
    .logo { 
        font-size: 0.95rem; /* Giảm cỡ chữ logo */
    }
    .header {
        padding: 0 8px; /* Giảm padding header */
    }
    .header-left { gap: 5px; } /* Giảm khoảng cách icon menu và logo */
    .header-right { gap: 6px; } /* Giảm khoảng cách các nút bên phải */
    
    .timer {
        font-size: 0.9rem;
        min-width: 50px;
        padding: 4px 5px;
    }
    .btn-submit-header {
        padding: 5px 10px;
        font-size: 0.85rem;
    }
    .btn-reset-header {
        padding: 5px 8px;
    }
}
