/* Nền trang và thanh tiêu đề (màu lấy từ css/theme.css) */
html,
body {
    background-color: rgb(var(--app-bg));
}

body {
    accent-color: rgb(var(--c-blue-600));
    transition: background-color 0.2s ease, color 0.2s ease;
}

.app-header {
    background-color: rgb(var(--header-bg) / 0.85);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    backdrop-filter: saturate(180%) blur(12px);
}

.modal-backdrop {
    background-color: rgb(2 6 23 / 0.55);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

/* ---------------------------------------------------------------- Thành phần dùng chung
 * Viết bằng CSS thường (không dùng @apply) để trình soạn thảo kiểm tra được.
 * Tailwind CDN chèn CSS của nó sau file này, nên class tiện ích (text-xs, !py-2, hidden…) vẫn ghi đè được.
 */
.card {
    background-color: rgb(var(--surface));
    border: 1px solid rgb(var(--c-slate-200) / 0.8);
    border-radius: 1rem;
    box-shadow: 0 1px 2px rgb(15 23 42 / 0.04), 0 1px 3px rgb(15 23 42 / 0.06);
}

.eyebrow {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgb(var(--c-slate-500));
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 2.25rem;
    min-width: 2.25rem;
    padding: 0 0.625rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 500;
    color: rgb(var(--c-slate-600));
    transition: color 0.15s ease, background-color 0.15s ease;
}
.icon-btn:hover {
    color: rgb(var(--c-slate-900));
    background-color: rgb(var(--c-slate-100));
}

.field {
    width: 100%;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: rgb(var(--c-slate-700));
    background-color: rgb(var(--c-slate-50));
    border: 1px solid rgb(var(--c-slate-200));
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field::placeholder {
    color: rgb(var(--c-slate-400));
}
.field:focus {
    outline: none;
    border-color: rgb(var(--c-blue-500));
    box-shadow: 0 0 0 2px rgb(var(--c-blue-500) / 0.3);
}

.btn,
.btn-primary,
.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 600;
    transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.btn:disabled,
.btn-primary:disabled,
.btn-secondary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.btn-primary {
    background-color: rgb(var(--c-blue-600));
    color: #fff;
    box-shadow: 0 1px 2px 0 rgb(var(--c-blue-600) / 0.25);
}
.btn-primary:not(:disabled):hover {
    background-color: rgb(var(--c-blue-700));
}
html.dark .btn-primary:not(:disabled):hover {
    background-color: rgb(var(--c-blue-500));
}
.btn-secondary {
    background-color: rgb(var(--c-slate-100));
    color: rgb(var(--c-slate-700));
}
.btn-secondary:not(:disabled):hover {
    background-color: rgb(var(--c-slate-200));
}

/* Tab chọn chế độ (class active do js/app.js gán) */
.mode-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.4rem 0.9rem;
    border-radius: 0.5rem;
    color: rgb(var(--c-slate-600));
    transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.mode-btn:hover {
    color: rgb(var(--c-slate-900));
}
.mode-btn.is-active {
    background-color: rgb(var(--surface));
    color: rgb(var(--c-blue-700));
    box-shadow: 0 1px 2px rgb(15 23 42 / 0.08), 0 0 0 1px rgb(var(--c-slate-200) / 0.7);
}

/* Thanh chế độ dưới đáy màn hình (điện thoại) */
@media (max-width: 767.98px) {
    html { scroll-padding-bottom: 4.5rem; }
}
.bottom-nav {
    background-color: rgb(var(--header-bg) / 0.95);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    backdrop-filter: saturate(180%) blur(12px);
    padding-bottom: env(safe-area-inset-bottom);
}
.bottom-tab {
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.55rem 0.1rem 0.5rem;
    border-radius: 0;
    font-size: 10.5px;
    font-weight: 500;
    white-space: nowrap;
}
.bottom-tab i {
    font-size: 1.05rem;
}
.bottom-tab.is-active {
    background: transparent;
    box-shadow: inset 0 2px 0 rgb(var(--c-blue-600));
    color: rgb(var(--c-blue-600));
    font-weight: 600;
}

/* Trang chủ */
.home-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    padding: 1.1rem 1.25rem;
    text-align: left;
    background-color: rgb(var(--surface));
    border: 1px solid rgb(var(--c-slate-200) / 0.8);
    border-radius: 1rem;
    box-shadow: 0 1px 2px rgb(15 23 42 / 0.04), 0 1px 3px rgb(15 23 42 / 0.06);
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.home-card:hover {
    border-color: rgb(var(--c-blue-300));
    box-shadow: 0 4px 14px rgb(15 23 42 / 0.08);
    transform: translateY(-1px);
}
.home-icon {
    flex-shrink: 0;
    width: 3rem;
    height: 3rem;
    border-radius: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}
.home-title {
    display: block;
    font-size: 1.05rem;
    font-weight: 700;
    color: rgb(var(--c-slate-900));
}
.home-desc {
    display: block;
    margin-top: 0.1rem;
    font-size: 0.85rem;
    color: rgb(var(--c-slate-500));
}
.home-arrow {
    margin-left: auto;
    font-size: 0.8rem;
    color: rgb(var(--c-slate-300));
    transition: color 0.15s ease, transform 0.15s ease;
}
.home-card:hover .home-arrow {
    color: rgb(var(--c-blue-600));
    transform: translateX(2px);
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    background-color: rgb(var(--c-slate-100));
    color: rgb(var(--c-slate-600));
}

/* Luyện tập / Thi thử trên điện thoại: bộ lọc và danh sách câu chỉ hiện khi bấm nút tương ứng */
@media (max-width: 1023.98px) {
    #quiz-sidebar:not([data-open]),
    #quiz-sidebar #progress-card,
    #quiz-sidebar > [data-panel-body] {
        display: none;
    }
    #quiz-sidebar[data-open="filters"] > [data-panel-body="filters"]:not(.hidden),
    #quiz-sidebar[data-open="map"] > [data-panel-body="map"]:not(.hidden) {
        display: flex;
    }
    #quiz-sidebar[data-open="map"] > [data-panel-body="map"]:not(.hidden) {
        display: block;
    }
    #quiz-sidebar[data-open] {
        grid-template-columns: minmax(0, 1fr);
    }
}
@media (max-width: 1023.98px) {
    .mobile-hide {
        display: none !important;
    }
}
[data-panel].is-open {
    background-color: rgb(var(--c-blue-50));
    color: rgb(var(--c-blue-700));
}

/* Menu chọn giao diện */
.theme-option {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    color: rgb(var(--c-slate-700));
}
.theme-option:hover {
    background-color: rgb(var(--c-slate-100));
}
.theme-option .fa-check {
    visibility: hidden;
}
.theme-option[aria-checked="true"] {
    color: rgb(var(--c-blue-700));
    font-weight: 600;
}
.theme-option[aria-checked="true"] .fa-check {
    visibility: visible;
}

/* Thanh cuộn */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgb(var(--c-slate-300));
    border-radius: 4px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: rgb(var(--c-slate-400));
}
.sidebar::-webkit-scrollbar-thumb {
    background: transparent;
}
.sidebar:hover::-webkit-scrollbar-thumb {
    background: rgb(var(--c-slate-300));
}

html.theme-switching *,
html.theme-switching *::before,
html.theme-switching *::after {
    transition: none !important;
}

/* Phần gạch chân trong câu "Find the incorrect part" */
.question-html u {
    text-decoration: underline;
    text-decoration-color: rgb(var(--c-rose-500));
    text-underline-offset: 4px;
    font-weight: 600;
}
.question-html i {
    font-style: normal;
    font-weight: 500;
    color: rgb(var(--c-blue-700));
}

.passage-text {
    white-space: pre-line;
}

/* Căn cứ cho đáp án trong bài đọc (chỉ hiện sau khi có phản hồi) */
mark.evidence {
    background: rgb(var(--c-amber-200));
    color: inherit;
    border-radius: 3px;
    padding: 0 2px;
    box-shadow: 0 0 0 1px rgb(var(--c-amber-500)) inset;
}

/* Writing: phần sai được đánh dấu trong bài viết */
mark.w-err {
    background: rgb(var(--c-rose-100));
    color: inherit;
    border-radius: 3px;
    padding: 1px 2px;
    cursor: pointer;
    text-decoration: underline wavy rgb(var(--c-rose-500));
    text-decoration-thickness: 1px;
    text-underline-offset: 4px;
    transition: background-color 0.15s ease, box-shadow 0.15s ease;
}
mark.w-err.w-v {
    background: rgb(var(--c-indigo-100));
    text-decoration-color: rgb(var(--c-indigo-500));
}
mark.w-err:hover,
mark.w-err.is-focus,
.w-fix:hover,
.w-fix.is-focus {
    background: rgb(var(--c-amber-200));
    box-shadow: 0 0 0 1px rgb(var(--c-amber-500)) inset;
}
mark.w-err sup,
.w-fix sup {
    font-size: 0.6rem;
    font-weight: 700;
    color: rgb(var(--c-rose-600));
    margin-left: 1px;
}
mark.w-err.w-v sup,
.w-fix.w-v sup {
    color: rgb(var(--c-indigo-600));
}

/* Writing – chế độ "bài đã sửa": phần sai gạch bỏ, phần sửa chèn ngay sau */
.w-fix {
    border-radius: 3px;
    padding: 1px 2px;
    cursor: pointer;
    transition: background-color 0.15s ease, box-shadow 0.15s ease;
}
.w-fix del {
    color: rgb(var(--c-rose-600));
    text-decoration-thickness: 1.5px;
    opacity: 0.85;
}
.w-fix ins {
    text-decoration: none;
    font-weight: 600;
    color: rgb(var(--c-emerald-700));
    background: rgb(var(--c-emerald-100));
    border-radius: 3px;
    padding: 0 2px;
    margin-left: 2px;
}

/* Writing – mục lỗi ở cột nhận xét */
.w-item.is-focus {
    border-color: rgb(var(--c-blue-300));
    background: rgb(var(--c-blue-50));
}

summary::-webkit-details-marker {
    display: none;
}

kbd {
    display: inline-block;
    min-width: 1.4em;
    padding: 0 0.3em;
    border: 1px solid rgb(var(--c-slate-300));
    border-bottom-width: 2px;
    border-radius: 4px;
    background: rgb(var(--surface));
    font-family: inherit;
    font-size: 0.7rem;
    line-height: 1.4;
    text-align: center;
    color: rgb(var(--c-slate-600));
}

.hidden-important {
    display: none !important;
}

/* ---------------------------------------------------------------- Chế độ tối
 * Phần lớn màu tự đổi qua biến trong css/theme.css. Riêng `white` giữ nguyên (chữ trắng trên nút),
 * nên các nền trắng do JS sinh ra được đổi sang màu bề mặt ở đây.
 */
html.dark .bg-white,
html.dark .hover\:bg-white:hover {
    background-color: rgb(var(--surface));
}
/* Nút nền đậm chữ trắng: sắc độ 700 ở chế độ tối là màu sáng, nên dùng 500 khi rê chuột. */
html.dark .hover\:bg-blue-700:hover { background-color: rgb(var(--c-blue-500)); }
html.dark .hover\:bg-emerald-700:hover { background-color: rgb(var(--c-emerald-500)); }
html.dark .hover\:bg-rose-700:hover { background-color: rgb(var(--c-rose-500)); }
html.dark .hover\:bg-indigo-700:hover { background-color: rgb(var(--c-indigo-500)); }
html.dark .bg-slate-100 > .bg-white {
    background-color: rgb(var(--c-slate-300));
}
html.dark *,
html.dark ::before,
html.dark ::after {
    --tw-ring-offset-color: rgb(var(--surface));
}
html.dark .card,
html.dark .shadow-sm,
html.dark .shadow-card {
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.3);
}
html.dark ::selection {
    background-color: rgb(var(--c-blue-300));
    color: rgb(var(--c-blue-950));
}

/* Speaking: gợi ý câu trả lời */
.spk-hints > summary::-webkit-details-marker { display: none; }
.spk-hints > summary { list-style: none; }
.spk-hints[open] .spk-chevron { transform: rotate(180deg); }
.spk-hints .spk-chevron { transition: transform 0.15s ease; }
