/* Phong cách tổng thể */
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap'); /* Import Google Font */

:root {
    --primary-color: #007bff; /* Màu xanh dương chính */
    --secondary-color: #6c757d; /* Màu xám phụ */
    --success-color: #28a745; /* Màu xanh lá thành công */
    --danger-color: #dc3545; /* Màu đỏ nguy hiểm */
    --warning-color: #ffc107; /* Màu vàng cảnh báo */
    --info-color: #17a2b8; /* Màu xanh mòng két */
    --light-color: #f8f9fa; /* Màu nền sáng */
    --dark-color: #343a40; /* Màu chữ/nền tối */
    --white-color: #ffffff;
    --border-color: #dee2e6; /* Màu viền nhạt */
    --text-color: #333;
    --text-muted: #6c757d;
}


html {
  box-sizing: border-box;
}
*, *:before, *:after {
  box-sizing: inherit;
}

body {
  font-family: 'Roboto', sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start; /* Align items to the top */
  min-height: 100vh;
  background: linear-gradient(to bottom right, #e0eafc, #cfdef3); /* Nền gradient nhạt hơn */
  color: var(--text-color);
  padding: 30px 15px; /* Thêm padding ngang */
  margin: 0;
}

.container {
  background: var(--white-color);
  padding: 30px 40px;
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1); /* Bóng đổ rõ hơn */
  width: 95%; /* Rộng hơn trên màn hình lớn */
  max-width: 950px; /* Tăng max-width */
  text-align: center;
  margin: auto;
}

h2, h3 {
  color: #333;
  margin-top: 0;
  margin-bottom: 20px;
  font-weight: 500;
}

/* Thẻ hiển thị từ vựng */
.word-card {
  font-size: 22px;
  margin-bottom: 15px;
  padding: 25px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  min-height: 280px; /* Tăng chiều cao tối thiểu */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background-color: var(--light-color); /* Nền nhạt */
  transition: box-shadow 0.3s ease;
  position: relative; /* Cho các thành phần con nếu cần */
}

.word-card:hover {
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.word-card b {
  display: block;
  font-size: 36px; /* Tăng cỡ chữ từ */
  margin-bottom: 10px;
  color: var(--primary-color);
  font-weight: 700;
}

.word-card img {
  max-width: 70%; /* Điều chỉnh lại nếu cần */
  max-height: 160px; /* Tăng chiều cao tối đa */
  height: auto;
  margin-bottom: 15px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border-color); /* Thêm viền nhẹ cho ảnh */
}
#wordImage { /* ID cho ảnh để dễ target */
    min-height: 50px; /* Chiều cao tối thiểu phòng khi ảnh lỗi */
}


.word-card p { /* Nghĩa của từ */
    margin-top: 5px;
    margin-bottom: 10px;
    font-size: 1.15em; /* To hơn chút */
    color: #444;
}

/* Câu ví dụ */
#exampleSentence {
    font-size: 1em; /* Cỡ chữ chuẩn hơn */
    color: #555; /* Màu chữ đậm hơn */
    font-style: normal; /* Bỏ italic mặc định */
    margin-top: 15px;
    line-height: 1.5;
    width: 90%; /* Giới hạn chiều rộng */
    max-width: 600px; /* Giới hạn tối đa */
    margin-left: auto;
    margin-right: auto;
}
#exampleSentence b { /* Nhãn "Ví dụ:" */
    font-size: 0.9em;
    color: var(--text-color);
    font-weight: bold;
    margin-right: 5px;
    display: inline;
}
#exampleSentence span { /* Từ được highlight */
    color: var(--danger-color);
    font-weight: bold;
}


/* Nút chức năng */
.button-container {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
    margin-top: 15px;
    margin-bottom: 15px;
}

.btn {
  background-color: var(--primary-color);
  color: var(--white-color);
  padding: 12px 25px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.1s ease, box-shadow 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  text-decoration: none; /* Cho trường hợp dùng thẻ <a> */
  vertical-align: middle;
}
/* Style cho button nhỏ hơn (dùng trong modal hướng dẫn) */
.btn-sm {
    padding: 5px 10px;
    font-size: 13px;
    border-radius: 4px;
}

.btn:hover {
  background-color: #0056b3; /* Đậm hơn primary */
  transform: translateY(-1px);
  box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}

.btn:active {
    transform: translateY(0px);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.2);
}
.btn:disabled {
    background-color: #adb5bd; /* Màu xám khi bị vô hiệu hóa */
    cursor: not-allowed;
    opacity: 0.7;
}


.btn i { /* Icon trong nút */
  margin-right: 8px;
  font-size: 0.95em; /* Kích thước icon tương đối */
}

/* Nút loại trừ đặc biệt */
#excludeCurrentWordButton,
#excludeWordButton {
    background-color: var(--warning-color);
    color: var(--text-color); /* Chữ đen trên nền vàng */
}
#excludeCurrentWordButton:hover,
#excludeWordButton:hover {
    background-color: #e0a800; /* Vàng đậm hơn */
}

#excludeCurrentWordButton { /* Nút dưới thẻ từ */
    padding: 8px 15px;
    font-size: 14px;
    margin-top: 5px;
}

/* ===== CSS CHO TABS ===== */
.tabs-container {
    width: 100%;
    margin-top: 30px;
    background-color: var(--light-color);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    overflow: hidden;
    border: 1px solid var(--border-color); /* Thêm viền nhẹ */
}

.tab-buttons {
    display: flex;
    background-color: #e9ecef;
}

.tab-button {
    padding: 12px 15px;
    cursor: pointer;
    border: none;
    background-color: transparent;
    font-size: 15px;
    font-weight: 500;
    color: var(--text-muted); /* Màu chữ mờ hơn */
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
    flex-grow: 1;
    text-align: center;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
    outline: none; /* Bỏ outline mặc định */
}

.tab-button:hover {
    background-color: #dee2e6;
    color: var(--dark-color);
}

.tab-button.active {
    background-color: var(--white-color);
    color: var(--primary-color);
    border-bottom: 3px solid var(--primary-color);
}
.tab-button:focus-visible { /* Style khi focus bằng bàn phím */
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
    z-index: 1; /* Nổi lên trên border */
}


.tab-content {
    padding: 25px;
    background-color: var(--white-color);
}

.tab-panel {
    display: none;
    animation: fadeIn 0.4s ease-in-out; /* Animation nhẹ nhàng */
}

.tab-panel.active {
    display: block;
}

/* Style chung cho các bảng trong tab */
.tab-panel h2, .tab-panel h3 {
    text-align: center;
    margin-top: 0;
    margin-bottom: 20px;
    color: #333;
}

.table-responsive { /* Container cho bảng để cuộn ngang */
    overflow-x: auto;
    margin-bottom: 15px; /* Khoảng cách dưới bảng */
    -webkit-overflow-scrolling: touch; /* Cuộn mượt trên iOS */
}

.tab-panel table {
    width: 100%;
    min-width: 500px; /* Chiều rộng tối thiểu để đảm bảo cột không quá hẹp */
    margin: 15px auto;
    border-collapse: collapse;
    font-size: 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.tab-panel th,
.tab-panel td {
    border: 1px solid var(--border-color);
    padding: 10px 12px;
    text-align: left;
    vertical-align: middle; /* Căn giữa theo chiều dọc */
}

.tab-panel th {
    color: var(--white-color);
    font-weight: 500;
    white-space: nowrap; /* Không xuống dòng tiêu đề */
}

/* Màu nền tiêu đề riêng cho từng bảng */
#historyTable th { background-color: var(--info-color); }
#customWordsTable th { background-color: var(--primary-color); }
#excludedWordsTable th { background-color: var(--secondary-color); }

.tab-panel tbody tr:nth-child(even) {
  background-color: var(--light-color);
}

.tab-panel tbody tr:hover {
  background-color: #e9ecef;
}

/* Input group styling */
.tab-panel .input-group {
  display: flex;
  justify-content: center;
  align-items: stretch; /* Làm các item cao bằng nhau */
  gap: 10px;
  margin-bottom: 25px;
  flex-wrap: wrap;
}

.tab-panel input[type="text"] {
  padding: 10px 15px;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 15px;
  flex-grow: 1;
  min-width: 180px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.tab-panel input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

/* Nút trong các tab */
#addWordButton { padding: 10px 20px; font-size: 15px; background-color: var(--success-color); }
#addWordButton:hover { background-color: #1f7a38; } /* Darker green */

#excludeWordButton { /* Nút loại trừ trong tab */
    padding: 10px 20px;
    font-size: 15px;
}


/* Nút xóa/học lại */
.delete-btn, .remove-exclusion-btn {
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: background-color 0.2s ease, opacity 0.2s ease;
  vertical-align: middle; /* Căn giữa tốt hơn */
}
.delete-btn:hover, .remove-exclusion-btn:hover {
    opacity: 0.85;
}

.delete-btn { background-color: var(--danger-color); }
.remove-exclusion-btn { background-color: var(--success-color); }

/* Căn giữa nút trong ô cuối bảng */
.tab-panel td:last-child { text-align: center; }

/* Animation cho tab panel */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}
/* ===== KẾT THÚC CSS CHO TABS ===== */


/* ===== CSS CHO CUSTOM VOICE SELECT DROPDOWN ===== */
#voiceSelectionContainer { /* Container bao ngoài */
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
  text-align: center;
}

#voiceSelectionContainer label { /* Nhãn */
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: var(--text-muted);
}

.custom-select-container { /* Div chứa nút và list */
  position: relative;
  display: inline-block;
  width: 90%;
  max-width: 400px; /* Tăng chiều rộng tối đa */
  text-align: left;
}

/* Nút bấm chính */
.custom-select-trigger {
  width: 100%;
  padding: 10px 15px;
  font-size: 15px;
  background-color: var(--white-color); /* Nền trắng */
  color: var(--text-color);
  border: 1px solid #ced4da; /* Viền xám chuẩn */
  border-radius: 8px;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.075);
  transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}
.custom-select-trigger:hover {
    border-color: #adb5bd; /* Viền đậm hơn khi hover */
}
.custom-select-trigger:focus { /* Style khi focus */
    outline: 0;
    border-color: #86b7fe; /* Viền xanh khi focus */
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25), inset 0 1px 2px rgba(0,0,0,0.075);
}
.custom-select-trigger[disabled] { /* Style khi bị disable */
    background-color: var(--light-color);
    opacity: 0.7;
    cursor: not-allowed;
}

/* Phần hiển thị giá trị đang chọn */
#customVoiceSelectValue {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  margin-right: 10px;
  flex-grow: 1; /* Cho phép co giãn */
}

/* Mũi tên dropdown */
.custom-select-arrow {
  transition: transform 0.2s ease;
  color: var(--text-muted); /* Màu xám cho mũi tên */
  flex-shrink: 0; /* Không co lại */
}

/* Xoay mũi tên khi dropdown mở */
.custom-select-trigger[aria-expanded="true"] .custom-select-arrow {
  transform: rotate(180deg);
}

/* Danh sách options */
.custom-select-options {
  position: absolute;
  top: calc(100% + 2px); /* Khoảng cách nhỏ dưới nút */
  left: 0;
  width: 100%;
  background-color: var(--white-color);
  border: 1px solid #ced4da;
  border-radius: 8px;
  max-height: 250px;
  overflow-y: auto;
  z-index: 1050;
  list-style: none;
  padding: 5px 0;
  margin: 0;
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15); /* Bóng đổ rõ hơn */
  display: none; /* Ẩn ban đầu */
}
/* Style khi list mở (thêm class khi mở bằng JS nếu cần animation phức tạp) */
.custom-select-options.open {
    display: block;
    animation: fadeInDropdown 0.2s ease-out;
}


/* Từng option trong danh sách */
.custom-select-options li[role="option"] {
  padding: 10px 15px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background-color 0.2s ease, color 0.2s ease;
}
.custom-select-options li[role="option"]:hover,
.custom-select-options li[role="option"]:focus { /* Style khi hover hoặc focus bằng bàn phím */
  background-color: var(--light-color);
  color: var(--dark-color);
  outline: none; /* Bỏ outline mặc định khi focus */
}

.custom-select-options li[role="option"].selected {
  background-color: var(--primary-color);
  color: var(--white-color);
  font-weight: 500;
}

/* Thông báo khi không có giọng đọc */
.custom-select-options .no-voices-message {
    cursor: default;
    padding: 10px; color: var(--text-muted); text-align: center;
}
.custom-select-options .no-voices-message:hover {
    background-color: transparent;
}

@keyframes fadeInDropdown {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}
/* ===== KẾT THÚC CSS CUSTOM SELECT ===== */


/* ===== CSS CHO MODAL HƯỚNG DẪN ===== */
.modal {
  display: none;
  position: fixed;
  z-index: 1001;
  left: 0; top: 0;
  width: 100%; height: 100%;
  overflow: auto;
  background-color: rgba(0,0,0,0.5);
  animation: fadeInModal 0.3s ease-out;
}

.modal-content {
  background-color: #fefefe;
  margin: 8% auto; /* Điều chỉnh margin top */
  padding: 30px 40px;
  border: 1px solid #888;
  width: 90%;
  max-width: 750px; /* Tăng max-width */
  border-radius: 10px;
  position: relative;
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);
  animation: slideInModal 0.3s ease-out;
}

.modal-content h2 { text-align: center; color: var(--primary-color); margin-top: 0; margin-bottom: 25px; }
.modal-content h2 i { margin-right: 10px; }
.modal-content h3 { color: #333; border-bottom: 1px solid #eee; padding-bottom: 8px; margin-top: 25px; margin-bottom: 15px; font-size: 1.1em; }
.modal-content ul { list-style-type: none; /* Bỏ dấu chấm đầu dòng */ padding-left: 0; margin-bottom: 15px; }
.modal-content ul ul { list-style-type: none; margin-top: 5px; margin-bottom: 10px; padding-left: 15px; /* Thụt lề danh sách con */ }
.modal-content li { margin-bottom: 12px; line-height: 1.6; color: #444; padding-left: 20px; position: relative; } /* Thụt lề và dùng pseudo-element */
.modal-content li::before { /* Dấu chấm đầu dòng tùy chỉnh */
    content: '•';
    position: absolute;
    left: 0;
    color: var(--primary-color);
    font-weight: bold;
    display: inline-block;
    width: 1em;
}
.modal-content li ul li::before { content: '◦'; color: var(--secondary-color); } /* Dấu tròn rỗng cho list con */

.modal-content li strong { color: #111; }
.modal-content .btn { margin: 0 3px; vertical-align: baseline; } /* Điều chỉnh nút trong hướng dẫn */


.close-button {
  color: #aaa; position: absolute; top: 10px; right: 20px; font-size: 32px; font-weight: bold; cursor: pointer; transition: color 0.2s ease; line-height: 1; background: none; border: none; padding: 0;
}
.close-button:hover, .close-button:focus { color: #333; text-decoration: none; outline: none; }

/* Nút hướng dẫn cố định */
#helpButton { position: fixed; top: 15px; right: 15px; z-index: 1000; background-color: var(--secondary-color); color: white; border: none; border-radius: 50%; width: 40px; height: 40px; font-size: 18px; cursor: pointer; box-shadow: 0 2px 5px rgba(0,0,0,0.2); display: flex; justify-content: center; align-items: center; transition: background-color 0.3s ease, transform 0.2s ease; }
#helpButton:hover { background-color: #5a6268; transform: scale(1.1); }

@keyframes fadeInModal { from { background-color: rgba(0,0,0,0); } to { background-color: rgba(0,0,0,0.5); } }
@keyframes slideInModal { from { transform: translateY(-30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
/* ===== KẾT THÚC CSS MODAL ===== */


/* Responsive adjustments */
@media (max-width: 768px) {
    body { padding: 20px 10px; }
    .container { width: 98%; padding: 20px; }
    .word-card { padding: 20px; font-size: 20px; min-height: 250px; }
    .word-card b { font-size: 28px; }
    .word-card img { max-width: 80%; max-height: 120px; }
    .btn { padding: 10px 20px; font-size: 15px; }
    #excludeCurrentWordButton { padding: 7px 12px; font-size: 13px; }
    .tab-button { font-size: 14px; padding: 10px 10px; /* Giảm padding ngang */ }
    .tab-content { padding: 15px; }
    .tab-panel .input-group { flex-direction: column; align-items: stretch; }
    .tab-panel input[type="text"], .tab-panel .input-group .btn { width: 100%; box-sizing: border-box; }
    .custom-select-container { max-width: 90%; }
    .modal-content { width: 95%; margin: 5% auto; padding: 20px; }
    .modal-content h2 { font-size: 1.3em; }
    .modal-content h3 { font-size: 1.05em; }
    .modal-content li { font-size: 0.95em; }
}

@media (max-width: 480px) {
    body { padding: 15px 5px; }
    .container { padding: 15px; }
    .word-card b { font-size: 24px; }
    .word-card p { font-size: 1em; }
    #exampleSentence { font-size: 0.9em; }
    .button-container { gap: 10px; }
    .btn { padding: 9px 15px; font-size: 14px; }
    .tab-button { font-size: 13px; padding: 9px 5px; }
    .tab-panel th, .tab-panel td { padding: 8px; font-size: 13px; }
    .delete-btn, .remove-exclusion-btn { padding: 5px 8px; font-size: 12px; }
    .custom-select-trigger { padding: 9px 12px; font-size: 14px; }
    .custom-select-options li[role="option"] { padding: 9px 12px; font-size: 13px; }
    #helpButton { width: 35px; height: 35px; font-size: 16px; top: 10px; right: 10px; }
    .modal-content { padding: 15px 20px; }
}
/* --- 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;
}
/* ... (Toàn bộ CSS cũ giữ nguyên) ... */

/* --- Gemini Explanation Container --- */
.explanation-container {
    margin-top: 25px;
    padding: 20px 25px;
    border: 1px solid #d1d9e6;
    border-radius: 10px;
    background-color: #fdfdff;
    text-align: left;
    min-height: 50px;
    line-height: 1.7;
    animation: fadeIn 0.5s ease-in-out;
    color: #444;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.explanation-container.loading {
    color: #888;
    font-style: italic;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 30px;
}

/* Main title styling */
.explanation-container h4 {
    font-size: 1.3em;
    color: var(--primary-color);
    margin-top: 0;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary-color);
    font-weight: 700;
}

.explanation-container h4 i {
    margin-right: 12px;
}

/* Style for each section */
.explanation-section {
    margin-bottom: 20px;
}
.explanation-section:last-child {
    margin-bottom: 0;
}


/* Subsection titles */
.explanation-section .section-title {
    font-weight: 700;
    color: #333;
    display: block;
    margin-bottom: 6px;
    font-size: 1.1em;
}

/* Content within sections */
.explanation-section .section-content {
    padding-left: 5px;
    color: #555;
}

/* Example styling */
.explanation-section .example-text {
    padding-left: 15px;
    border-left: 3px solid #b0c4de;
    margin-top: 8px;
    font-size: 0.95em;
}

.explanation-section .example-text em {
    font-style: italic;
    color: #1a1a1a;
}

/* List styling for Vietnamese Equivalents */
.explanation-container ul {
    list-style-type: none; /* Remove default bullets */
    padding-left: 5px;
    margin: 8px 0 0 0;
}

.explanation-container li {
    padding-left: 20px;
    position: relative;
    margin-bottom: 6px;
}

.explanation-container li::before {
    content: '•';
    color: var(--primary-color);
    font-weight: bold;
    position: absolute;
    left: 0;
    top: -1px;
}
/* Thêm vào cuối file style.css */

.explanation-section .meaning-block {
    margin-bottom: 15px; /* Khoảng cách giữa các nghĩa khác nhau */
    padding-left: 10px;
    border-left: 3px solid #e0e0e0;
}

.explanation-section .part-of-speech {
    font-style: italic;
    color: #555;
    margin-bottom: 5px;
    font-size: 0.95em;
}

.explanation-section .example-text {
    background-color: #f8f9fa;
    padding: 10px;
    border-radius: 5px;
    margin-top: 8px;
}
/* ... (Các CSS còn lại giữ nguyên) ... */