/* ----- Reset & Base ----- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif; /* Hoặc font bạn chọn */
    line-height: 1.6;
    background-color: #f4f7f9; /* Màu nền xám nhạt, dịu mắt */
    color: #343a40; /* Màu chữ chính */
    display: flex;
    justify-content: center;
    padding: 20px;
    min-height: 100vh;
}

/* ----- Container ----- */
.container {
    background-color: #ffffff;
    padding: 30px 40px;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08);
    width: 100%;
    max-width: 900px; /* Giới hạn chiều rộng tối đa */
    display: flex;
    flex-direction: column;
    gap: 30px; /* Khoảng cách giữa các phần */
}

/* ----- Header ----- */
.header {
    text-align: center;
    border-bottom: 1px solid #e9ecef; /* Đường kẻ phân cách nhẹ */
    padding-bottom: 20px;
}

.header h1 {
    color: #0056b3; /* Màu xanh dương đậm cho tiêu đề */
    margin-bottom: 8px;
    font-size: 2em; /* Kích thước lớn hơn cho tiêu đề */
}

#progress {
    color: #6c757d; /* Màu xám cho text phụ */
    font-size: 0.95em;
}

/* ----- Main Content (Câu hỏi & Nhập liệu) ----- */
.main-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.sentence-display {
    font-size: 1.3em; /* Tăng kích thước font câu gốc */
    font-weight: 500;
    color: #495057;
    text-align: center;
    min-height: 30px; /* Đảm bảo có không gian dù câu bị ẩn */
    /* display: none; được quản lý bởi JS */
	display: none;
}

.input-area {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px; /* Tăng khoảng cách giữa các ô input */
    width: 100%;
}

.word-container {
    display: flex;
    flex-direction: column; /* Sắp xếp input trên, icon dưới */
    align-items: center;
    gap: 5px;
    position: relative; /* Để định vị span đáp án */
    background-color: #f8f9fa; /* Nền nhẹ cho từng ô */
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid #dee2e6;
}

.input-box {
    font-size: 1em;
    padding: 8px 10px;
    border: 1px solid #ced4da; /* Viền nhẹ hơn */
    border-radius: 4px;
    width: 100px; /* Điều chỉnh độ rộng */
    text-align: center;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    background-color: #fff;
}

.input-box:focus {
    border-color: #80bdff; /* Highlight viền khi focus */
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.input-box:disabled {
    background-color: #e9ecef; /* Màu nền khi bị vô hiệu hóa */
    cursor: not-allowed;
}

.speaker-icon {
    font-size: 1.1em;
    color: #6c757d;
    cursor: pointer;
    transition: color 0.3s ease;
}

.speaker-icon:hover {
    color: #007bff;
}

/* Định dạng span hiển thị đáp án đúng */
.word-container span[id^="answer-"] {
    font-size: 0.9em;
    color: #dc3545; /* Màu đỏ cho đáp án sai */
    margin-top: 2px;
    display: none; /* Được quản lý bởi JS */
    font-weight: 500;
}

/* ----- Controls ----- */
.controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 10px;
}

.controls button {
    background-color: #007bff; /* Màu nút chính */
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 500;
    transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
    display: inline-flex; /* Căn giữa icon và text */
    align-items: center;
    gap: 8px; /* Khoảng cách giữa icon và text */
}

.controls button:hover:not(:disabled) {
    background-color: #0056b3; /* Màu đậm hơn khi hover */
    transform: translateY(-2px); /* Hiệu ứng nhấc lên */
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.controls button:disabled {
    background-color: #adb5bd; /* Màu xám cho nút bị vô hiệu hóa */
    cursor: not-allowed;
    opacity: 0.7;
}

/* ----- Quick Stats ----- */
.quick-stats {
    text-align: center;
    margin-top: 15px;
    font-size: 1em;
    color: #495057;
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

.quick-stats span {
    font-weight: 500;
}

#correctCount, #totalCount {
    font-weight: 700;
    color: #343a40;
}

#correctPercentage {
    font-weight: 700;
    color: #28a745; /* Màu xanh lá cho tỷ lệ đúng */
}

#result {
    font-weight: bold;
}

/* ----- Statistics Section ----- */
.statistics-section {
    margin-top: 20px;
    border-top: 1px solid #e9ecef;
    padding-top: 30px;
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.statistics-section h2,
.statistics-section h3 {
    text-align: center;
    color: #0056b3;
    margin-bottom: 15px;
}

.statistics-section h3 {
    font-size: 1.2em;
    color: #495057;
}

.average-scores {
    display: flex;
    justify-content: space-around;
    background-color: #e9f5ff; /* Nền xanh nhạt */
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.average-scores span {
    font-weight: 600;
    color: #0056b3;
    font-size: 1em;
}

/* ----- Charts ----- */
.chart-container {
    background-color: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

#chart, #spiderChart {
    max-width: 100%; /* Đảm bảo biểu đồ không tràn */
    background-color: #fff;
    border-radius: 6px;
    padding: 10px;
}

/* ----- Tables ----- */
.table-wrapper {
    overflow-x: auto; /* Cho phép cuộn ngang nếu bảng quá rộng */
    background-color: #fff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95em;
}

th, td {
    padding: 12px 15px; /* Tăng padding */
    text-align: center;
    border-bottom: 1px solid #dee2e6; /* Đường kẻ ngang nhẹ */
    white-space: nowrap; /* Ngăn text xuống dòng trong ô */
}

thead th {
    background-color: #e9ecef; /* Màu nền header nhẹ */
    color: #495057;
    font-weight: 600;
    text-transform: uppercase; /* Viết hoa chữ header */
    letter-spacing: 0.5px; /* Tăng khoảng cách chữ */
}

tbody tr:nth-child(even) {
    background-color: #f8f9fa; /* Màu xen kẽ */
}

tbody tr:hover {
    background-color: #e9f5ff; /* Highlight nhẹ khi hover */
}

/* Style cho bảng lịch sử chi tiết */
#history-list table td:nth-child(2), /* Cột Bạn làm */
#history-list table td:nth-child(3) { /* Cột Đáp án */
    text-align: left;
    white-space: normal; /* Cho phép xuống dòng nếu cần */
    word-break: break-word; /* Ngắt từ nếu quá dài */
}

#history-list td span {
    padding: 2px 4px;
    border-radius: 3px;
    margin-right: 2px;
    display: inline-block;
}

#history-list td span[style*="color: red"] {
    background-color: #f8d7da;
    color: #721c24;
    text-decoration: line-through; /* Gạch ngang từ sai */
}

#history-list td span[style*="color: green"] {
    background-color: #d4edda;
    color: #155724;
}

/* ----- Responsive ----- */
@media (max-width: 768px) {
    .container {
        padding: 20px;
    }
    .header h1 {
        font-size: 1.8em;
    }
    .input-area {
        gap: 10px;
    }
    .input-box {
        width: 80px;
        font-size: 0.9em;
        padding: 6px 8px;
    }
    .controls button {
        padding: 8px 15px;
        font-size: 0.9em;
    }
    .average-scores span {
        font-size: 0.9em;
    }
    th, td {
        padding: 8px 10px;
        font-size: 0.9em;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    .container {
        padding: 15px;
    }
    .header h1 {
        font-size: 1.5em;
    }
    .input-box {
        width: 70px;
    }
    .controls {
        flex-direction: column; /* Nút xếp chồng lên nhau */
        gap: 10px;
    }
    .controls button {
       width: 100%;
    }
    .average-scores {
        flex-direction: column;
        gap: 5px;
        align-items: center;
    }
    .quick-stats {
        flex-direction: column;
        gap: 5px;
    }
}
/* --- Backup & Restore Section --- */
.backup-restore {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid #dee2e6;
}

.backup-restore h3 {
    margin-bottom: 1rem;
}

.backup-restore button,
.restore-label {
    display: inline-block; /* Align next to each other */
    margin-right: 1rem;
    margin-bottom: 0.5rem; /* Spacing for wrapping */
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid #007bff;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
    background-color: #fff;
    color: #007bff;
    text-align: center;
}

.backup-restore button:hover,
.restore-label:hover {
    background-color: #e7f3ff;
}

.backup-restore .restore-label {
    background-color: #28a745; /* Green for restore */
    border-color: #28a745;
    color: white;
}
.backup-restore .restore-label:hover {
     background-color: #218838;
     border-color: #1e7e34;
}

.backup-restore .note {
    font-size: 0.85rem;
    color: #6c757d;
    margin-top: 0.5rem;
}