/* --- Reset & Base --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background-color: #f4f7f9; /* Màu nền xám rất nhạt */
    color: #333;
    line-height: 1.6;
    display: flex;
    justify-content: center;
    padding: 20px;
    min-height: 100vh;
}

/* --- Container & Layout --- */
.main-container {
    width: 100%;
    max-width: 900px; /* Giới hạn chiều rộng tối đa */
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
    overflow: hidden; /* Đảm bảo border-radius hoạt động với header */
    display: flex;
    flex-direction: column;
}

.app-header {
    background-color: #0056b3; /* Màu xanh dương đậm hơn */
    color: #fff;
    padding: 20px 30px;
    text-align: center;
}

.app-header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin: 0;
}

.game-area {
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 30px; /* Khoảng cách giữa các section */
}

.stats-area {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); /* Responsive grid */
    gap: 30px;
}

/* --- Card Style --- */
.card {
    background-color: #fff;
    /* Cards bây giờ nằm trong container trắng, nên không cần background riêng trừ khi muốn khác biệt */
    /* padding: 25px; */ /* Padding được xử lý bởi .game-area */
    border: 1px solid #e0e0e0; /* Thêm viền nhẹ */
    border-radius: 8px;
    /* box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05); */ /* Giảm shadow nếu không cần */
}

.card h2, .card h3 {
    margin-bottom: 20px;
    color: #0056b3; /* Màu tiêu đề */
    font-weight: 600;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}

.card h2 { font-size: 1.4rem; }
.card h3 { font-size: 1.2rem; }

/* --- Word Display & Input --- */
.word-section {
     padding: 25px; /* Thêm padding riêng cho card này */
}

.word-display {
    text-align: center;
    margin-bottom: 25px;
}

.word-container {
    display: flex;
    justify-content: center;
    flex-wrap: wrap; /* Cho phép xuống dòng nếu từ quá dài */
    gap: 8px;
    margin-bottom: 20px;
    min-height: 50px; /* Chiều cao tối thiểu để không bị giật layout */
}

.word-container .letter { /* Giữ nguyên class 'letter' cho JS */
    background-color: #e0e0e0; /* Màu nền chữ cái */
    color: #333;
    font-size: 1.5rem; /* Kích thước chữ cái */
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 6px;
    min-width: 40px;
    text-align: center;
    cursor: pointer; /* Giữ cursor nếu chức năng swap vẫn còn */
    transition: background-color 0.2s ease, transform 0.2s ease;
    user-select: none; /* Không cho chọn text */
}

.word-container .letter:hover {
    background-color: #c7c7c7;
    transform: translateY(-2px);
}

.hint {
    font-size: 1.1rem;
    color: #555;
    margin-top: 15px;
}

.hint strong {
    color: #007bff;
}

.input-area {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
    align-items: center; /* Căn giữa input và button */
}

#userInput {
    flex-grow: 1; /* Input chiếm phần lớn không gian */
    padding: 12px 15px;
    font-size: 1rem;
    border: 1px solid #ccc;
    border-radius: 6px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#userInput:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.15);
    outline: none;
}

/* --- Buttons --- */
.button {
    padding: 12px 25px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    text-align: center;
    white-space: nowrap; /* Không xuống dòng chữ trên button */
}

.primary-button {
    background-color: #007bff;
    color: white;
}

.primary-button:hover {
    background-color: #0056b3;
}

.primary-button:active {
    transform: scale(0.98);
}

/* --- Result Message --- */
.result-message { /* Đổi tên class nếu muốn, nhưng ID 'result' phải giữ */
    text-align: center;
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: 20px;
    padding: 10px;
    border-radius: 6px;
    min-height: 40px; /* Chiều cao tối thiểu */
}

.result.correct { /* Giữ class 'correct' và 'incorrect' cho JS */
    color: #155724;
    background-color: #d4edda;
    border: 1px solid #c3e6cb;
}

.result.incorrect {
    color: #721c24;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
}

/* --- Stats Section --- */
.stats-card {
     padding: 25px; /* Thêm padding riêng cho card này */
}
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 15px;
    text-align: center;
}

.stats-grid p {
    font-size: 1rem;
    color: #555;
}

.stats-grid span {
    display: block; /* Cho số nhảy xuống dòng mới */
    font-size: 1.5rem;
    font-weight: 700;
    color: #007bff;
}

#memorizationStats {
    font-size: 1rem;
    color: #555;
    text-align: center;
    margin-bottom: 15px;
}

/* --- Progress Bar --- */
.progress-bar-container {
    padding-top: 5px; /* Khoảng cách với text phía trên */
}

.progress-bar {
    width: 100%;
    height: 12px; /* Giảm chiều cao thanh progress */
    background-color: #e9ecef;
    border-radius: 6px;
    overflow: hidden; /* Quan trọng để bo góc phần fill */
}

.progress-bar-fill { /* Giữ class cho JS */
    height: 100%;
    background-color: #28a745; /* Màu xanh lá cho tiến độ */
    width: 0%; /* Bắt đầu từ 0 */
    border-radius: 6px;
    transition: width 0.5s ease-out; /* Hiệu ứng chuyển động mượt */
    text-align: center;
    color: white;
    font-size: 0.7rem; /* Có thể thêm % vào đây nếu muốn */
    line-height: 12px;
}

/* --- History Section --- */
.history-section {
     padding: 25px; /* Thêm padding riêng cho card này */
}
.table-container {
    overflow-y: auto; /* Thêm thanh cuộn dọc khi nội dung dài */
    border: 1px solid #e0e0e0;
    border-radius: 6px; /* Bo góc cho vùng chứa bảng */
}

#historyTable {
    width: 100%;
    border-collapse: collapse; /* Gộp đường viền */
}

#historyTable th, #historyTable td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
    vertical-align: middle; /* Căn giữa theo chiều dọc */
}
#historyTable td:first-child, #historyTable th:first-child {
    width: 5%; /* STT nhỏ hơn */
    text-align: center;
}
#historyTable td:nth-child(2), #historyTable th:nth-child(2) {
    width: 25%; /* Từ vựng */
    font-weight: 600;
}
#historyTable td:nth-child(3), #historyTable th:nth-child(3) {
    width: 40%; /* Kết quả */
}
#historyTable td:last-child, #historyTable th:last-child {
    width: 30%; /* Bạn trả lời */
    font-style: italic;
     color: #555;
}

#historyTable th {
    background-color: #f8f9fa; /* Màu nền header bảng */
    color: #333;
    font-weight: 700;
    position: sticky; /* Giữ header khi cuộn */
    top: 0;
    z-index: 1;
}

#historyTable tbody tr:last-child td {
    border-bottom: none; /* Bỏ border dòng cuối */
}

#historyTable tbody tr:hover {
    background-color: #f1f1f1; /* Hiệu ứng hover */
}

/* --- Footer --- */
.app-footer {
    background-color: #f8f9fa; /* Màu nền footer */
    padding: 15px 30px;
    text-align: center;
    font-size: 0.9rem;
    color: #666;
    border-top: 1px solid #e0e0e0;
}
.app-footer a {
    color: #007bff;
    text-decoration: none;
}
.app-footer a:hover {
    text-decoration: underline;
}


/* --- Responsive Adjustments --- */
@media (max-width: 768px) {
    .game-area {
        padding: 20px;
        gap: 20px;
    }
    .stats-area {
        gap: 20px;
    }
    .input-area {
        flex-direction: column; /* Xếp input và button dọc */
        align-items: stretch; /* Kéo dài theo chiều ngang */
    }
    #checkInputButton {
        width: 100%; /* Button chiếm toàn bộ chiều rộng */
    }
    .app-header h1 {
        font-size: 1.5rem;
    }
    .card h2 { font-size: 1.2rem; }
    .card h3 { font-size: 1.1rem; }
    #historyTable th, #historyTable td {
        padding: 10px 8px;
        font-size: 0.9rem;
    }

}

@media (max-width: 480px) {
    body { padding: 10px; }
    .main-container { border-radius: 8px; }
    .game-area { padding: 15px; }
    .app-header { padding: 15px 20px;}
    .app-header h1 { font-size: 1.3rem; }
    .word-container .letter { font-size: 1.2rem; padding: 6px 10px; min-width: 35px; }
    .hint { font-size: 1rem; }
    #userInput, .button { font-size: 0.9rem; padding: 10px 15px; }
     .stats-grid span { font-size: 1.3rem; }
    .app-footer { padding: 10px 20px; font-size: 0.8rem; }
}
/* --- Reset & Base --- */
/* ... (Giữ nguyên phần đầu) ... */

/* --- Container & Layout --- */
/* ... (Giữ nguyên) ... */

.app-header {
    background-color: #0056b3; /* Màu xanh dương đậm hơn */
    color: #fff;
    padding: 20px 30px;
    text-align: center;
    position: relative; /* Thêm để định vị nút help */
}

/* --- Nút Help --- */
.help-button {
    position: absolute;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    background-color: rgba(255, 255, 255, 0.2);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%; /* Bo tròn */
    width: 35px;
    height: 35px;
    font-size: 1.2rem;
    font-weight: bold;
    line-height: 33px; /* Căn giữa dấu ? */
    text-align: center;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    padding: 0; /* Reset padding */
}

.help-button:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

.help-button:active {
    transform: translateY(-50%) scale(0.95);
}


.game-area {
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 30px; /* Khoảng cách giữa các section */
}

/* ... (Giữ nguyên các phần CSS khác) ... */

/* --- Modal Styles --- */
.modal {
    display: none; /* Ẩn mặc định */
    position: fixed; /* Che phủ toàn màn hình */
    z-index: 1000; /* Nằm trên cùng */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto; /* Cho phép cuộn nếu nội dung modal dài */
    background-color: rgba(0, 0, 0, 0.6); /* Lớp nền mờ */
    justify-content: center;
    align-items: center;
    padding: 20px; /* Tạo khoảng cách với mép màn hình */
}

.modal-content {
    background-color: #fff;
    border-radius: 8px;
    padding: 30px 40px;
    position: relative;
    max-width: 700px; /* Giới hạn chiều rộng modal */
    width: 90%; /* Chiếm 90% chiều rộng viewport */
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    max-height: 85vh; /* Giới hạn chiều cao */
    overflow-y: auto; /* Thêm cuộn nếu nội dung vượt quá chiều cao */
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    background: none;
    border: none;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

.modal-close:hover,
.modal-close:focus {
    color: #333;
    text-decoration: none;
}

.modal-content h2 {
    margin-top: 0;
    margin-bottom: 25px;
    color: #0056b3;
    text-align: center;
    border-bottom: 1px solid #eee;
    padding-bottom: 15px;
}

.modal-content ul {
    list-style: none; /* Bỏ dấu chấm đầu dòng mặc định */
    padding-left: 0;
}

.modal-content ul li {
    margin-bottom: 15px;
}

.modal-content ul li strong {
    color: #007bff; /* Làm nổi bật tiêu đề nhỏ */
    display: block; /* Cho tiêu đề nhỏ xuống dòng riêng */
    margin-bottom: 5px;
}

.modal-content ol {
    padding-left: 20px; /* Thụt lề cho danh sách có thứ tự */
    margin-top: 5px;
}
.modal-content ol li {
    margin-bottom: 8px;
}


/* --- Footer --- */
/* ... (Giữ nguyên) ... */

/* --- Responsive Adjustments --- */
/* ... (Giữ nguyên hoặc điều chỉnh thêm nếu cần cho modal) ... */

@media (max-width: 768px) {
     /* ... */
     .modal-content {
         padding: 25px 30px;
         max-width: 90%;
     }
     .modal-content h2 {
         font-size: 1.3rem;
     }
     .help-button {
         right: 15px;
         width: 32px;
         height: 32px;
         font-size: 1.1rem;
         line-height: 30px;
     }
     /* ... */
}

@media (max-width: 480px) {
    /* ... */
    .modal-content {
        padding: 20px;
        max-height: 90vh; /* Cho phép cao hơn trên mobile */
        width: 95%;
    }
     .modal-content h2 {
        font-size: 1.2rem;
        margin-bottom: 20px;
        padding-bottom: 10px;
     }
     .modal-content ul li, .modal-content p, .modal-content ol li {
         font-size: 0.9rem; /* Chữ nhỏ hơn trong modal trên mobile */
     }
     .help-button {
         right: 10px;
         width: 30px;
         height: 30px;
         font-size: 1rem;
         line-height: 28px;
     }
    /* ... */
}
/* --- Backup & Restore Section --- */
.backup-restore {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid #dee2e6;
	    padding: 30px;
}

.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;
}
.logo-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding-top: 20px;
}

.logo {
    max-width: 150px; /* Kích thước gốc */
    height: auto;
    display: block;
}