
:root {
    --bg-main: #eff4f8;
    --bg-card: rgba(255, 255, 255, 0.88);
    --bg-accent: #f8fbff;
    --border-soft: rgba(22, 69, 102, 0.14);
    --text-main: #16344b;
    --text-soft: #597286;
    --blue: #0d6efd;
    --blue-deep: #0a4fb5;
    --green: #1e8f62;
    --amber: #d48a12;
    --red: #d94a43;
    --shadow-lg: 0 18px 50px rgba(22, 52, 75, 0.14);
    --shadow-sm: 0 8px 18px rgba(22, 52, 75, 0.08);
    --radius-lg: 24px;
    --radius-md: 18px;
    --radius-sm: 12px;
    --font-ui: 'Be Vietnam Pro', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--font-ui); /* Áp dụng font cho toàn web */
}

body {
    min-height: 100vh;
    padding: 24px;
    color: var(--text-main);
    background:
        radial-gradient(circle at top left, rgba(13, 110, 253, 0.18), transparent 32%),
        radial-gradient(circle at bottom right, rgba(30, 143, 98, 0.12), transparent 28%),
        linear-gradient(160deg, #edf5fb 0%, #f8fbfd 45%, #eef4f6 100%);
}

button,
input,
select {
    font: inherit;
}

button {
    border: none;
    border-radius: 999px;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
    /* FIX NÚT BẤM BỊ ÉP CHỮ */
    white-space: nowrap; 
    flex-shrink: 0;      
    padding: 14px 24px;  
}

button:hover:not(:disabled) {
    transform: translateY(-1px);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

input,
select {
    width: 100%;
    border: 1px solid var(--border-soft);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.9);
    color: var(--text-main);
    padding: 14px 16px;
    outline: none;
}

input:focus,
select:focus {
    border-color: rgba(13, 110, 253, 0.45);
    box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.12);
}

.hidden {
    display: none !important;
}

.app-shell {
    max-width: 1240px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.navbar {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    padding: 28px 30px;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.94), rgba(247, 251, 255, 0.9));
    border: 1px solid rgba(13, 110, 253, 0.12);
    box-shadow: var(--shadow-lg);
}

.brand-block {
    max-width: 760px;
}

.brand-kicker {
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--blue);
}

.logo {
    font-size: clamp(34px, 4vw, 48px);
    line-height: 1;
    font-weight: 900;
    letter-spacing: -0.04em;
    color: #103451;
}

.brand-copy {
    max-width: 640px;
    margin-top: 14px;
    color: var(--text-soft);
    line-height: 1.6;
}

.status-banner {
    min-width: 280px;
    align-self: flex-start;
    padding: 14px 16px;
    border-radius: 18px;
    background: rgba(13, 110, 253, 0.1);
    border: 1px solid rgba(13, 110, 253, 0.16);
    color: var(--blue-deep);
    font-weight: 700;
    line-height: 1.5;
}

.status-banner.warning {
    background: rgba(212, 138, 18, 0.14);
    border-color: rgba(212, 138, 18, 0.2);
    color: #8e5d09;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(13, 110, 253, 0.1);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-sm);
}

.tab-btn {
    padding: 12px 18px;
    background: transparent;
    color: var(--text-soft);
    font-weight: 700;
}

.tab-btn.active {
    background: linear-gradient(135deg, var(--blue), #2a8cff);
    color: #fff;
    box-shadow: 0 10px 20px rgba(13, 110, 253, 0.22);
}

.app-container {
    display: flex;
    flex-direction: column;
    min-height: 720px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.72);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(12px);
}

.view-section {
    display: flex;
    min-height: 720px;
}

.flex-col {
    flex-direction: column;
    padding: 32px;
    gap: 18px;
}

.sidebar {
    width: 320px;
    flex-shrink: 0;
    padding: 30px 24px;
    background:
        linear-gradient(180deg, rgba(13, 110, 253, 0.05), rgba(255, 255, 255, 0.78)),
        rgba(255, 255, 255, 0.78);
    border-right: 1px solid rgba(13, 110, 253, 0.12);
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.panel-heading p,
.section-head p,
.saved-header p,
.chat-header p {
    margin-top: 8px;
    line-height: 1.6;
    color: var(--text-soft);
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.topic-list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.topic-item {
    width: 100%;
    padding: 14px 16px;
    border-radius: 16px;
    text-align: left;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(13, 110, 253, 0.08);
    color: var(--text-main);
    font-weight: 700;
}

.topic-item.active {
    background: linear-gradient(135deg, rgba(13, 110, 253, 0.12), rgba(42, 140, 255, 0.16));
    border-color: rgba(13, 110, 253, 0.3);
    color: var(--blue-deep);
}

.main-content {
    flex: 1;
    padding: 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
}

.content-heading {
    text-align: center;
}

.content-heading p {
    margin-top: 8px;
    color: var(--text-soft);
}

/* ==================================================================== */
/* FLASHCARD BẤT TỬ (ĐÃ FIX CHỈ LẬT KHI CLICK & CHỐNG XUYÊN THẤU) */
/* ==================================================================== */
.flashcard-container {
    width: min(100%, 460px);
    height: 290px;
    perspective: 1100px;
}

/* --- FLASHCARD: FIX TRÀN CHỮ & LỘ ĐÁP ÁN --- */
.flashcard {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

/* Class bổ trợ để tắt hiệu ứng khi reset (Dùng trong JS) */
.no-transition {
    transition: none !important;
}

.flashcard.is-flipped {
    transform: rotateY(180deg) !important;
}

.card-face {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 25px;
    border-radius: 28px;
    backface-visibility: hidden !important;
    -webkit-backface-visibility: hidden !important;
    text-align: center;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    /* Ép trình duyệt render phẳng để chống lỗi hiển thị */
    transform: translateZ(0); 
}

/* FIX: Tràn chữ mặt trước và mất chữ mặt sau */
.word-main {
    font-size: clamp(20px, 4vw, 38px); 
    font-weight: 800;
    line-height: 1.2;
    width: 100%;
    text-align: center;
    word-wrap: break-word;
    
    /* FIX CẢNH BÁO VS CODE & TRÀN CHỮ */
    display: -webkit-box;
    -webkit-line-clamp: 4; /* Cho Webkit (Chrome, Cốc Cốc, Safari) */
    line-clamp: 4;         /* Thuộc tính tiêu chuẩn (Xóa lỗi xanh) */
    -webkit-box-orient: vertical;
    
    overflow: hidden;
    color: inherit;
}

.card-front {
    background: #ffffff;
    border: 2px solid rgba(13, 110, 253, 0.25); /* Viền xanh nhạt chuyên nghiệp */
    z-index: 2;
    transform: rotateY(0deg);
}
.card-back {
    background: linear-gradient(135deg, var(--blue), var(--blue-deep));
    border: 2px solid rgba(255, 255, 255, 0.2); /* Viền trắng mờ tinh tế */
    color: #fff !important;
    transform: rotateY(180deg);
}

.word-main {
    font-size: clamp(32px, 4vw, 44px);
    font-weight: 900;
    letter-spacing: -0.04em;
}

.word-main-vi {
    font-size: clamp(28px, 3vw, 36px);
}

.word-pro,
.hint,
.example {
    line-height: 1.6;
}

.word-pro,
.hint {
    color: var(--text-soft);
}

.card-back .hint,
.card-back .example {
    color: rgba(255, 255, 255, 0.9);
}

.action-buttons,
.controls {
    display: flex;
    gap: 12px;
    width: min(100%, 460px);
}

.action-buttons button,
.controls button,
.section-actions button,
.audio-controls button,
.listen-actions button,
.saved-header button {
    flex: 1;
}

.panel-note,
.content-box {
    width: 100%;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 24px;
    border: 1px solid rgba(13, 110, 253, 0.1);
    box-shadow: var(--shadow-sm);
}

.panel-note {
    max-width: 560px;
    padding: 18px 20px;
}

.panel-note strong {
    display: block;
    margin-bottom: 8px;
}

.panel-note p {
    line-height: 1.65;
}

.section-head,
.saved-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

/* NỚI RỘNG CHO NÚT BẤM VÀ SELECT ĐỠ BỊ ÉP */
.section-actions {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 500px; 
}

.content-box {
    padding: 28px;
}

.status-note {
    padding: 10px 14px;
    border-radius: 14px;
    background: rgba(13, 110, 253, 0.08);
    color: var(--blue-deep);
    font-weight: 700;
}

.reading-text {
    font-size: 20px;
    line-height: 1.9;
    color: var(--text-main);
}

.reading-text span {
    display: inline-block;
    margin: 2px 1px;
    padding: 2px 4px;
    border-bottom: 1px dashed rgba(13, 110, 253, 0.35);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease;
}

.reading-text span:hover {
    background: rgba(13, 110, 253, 0.12);
    color: var(--blue-deep);
}

.reading-hint {
    margin-top: 18px;
    color: var(--text-soft);
}

.full-translation-box {
    margin-top: 18px;
    padding: 18px;
    border-radius: 18px;
    background: rgba(13, 110, 253, 0.08);
    border: 1px solid rgba(13, 110, 253, 0.12);
    line-height: 1.7;
    color: var(--blue-deep);
}

.grammar-title {
    margin-bottom: 20px;
    font-size: 28px;
    line-height: 1.2;
    color: #0f3052;
}

.grammar-card {
    padding: 18px 20px;
    border-radius: 18px;
    background: var(--bg-accent);
    border: 1px solid rgba(13, 110, 253, 0.08);
}

.grammar-card + .grammar-card {
    margin-top: 14px;
}

.grammar-card h4 {
    margin-bottom: 10px;
}

.grammar-formula {
    display: inline-block;
    padding: 10px 14px;
    border-radius: 12px;
    background: rgba(217, 74, 67, 0.12);
    color: #9b2d29;
    font-family: "Consolas", "Courier New", monospace;
    font-weight: 700;
}

.grammar-examples {
    padding-left: 20px;
    line-height: 1.7;
}

/* ==================================================================== */
/* CHAT GIA SƯ AI PREMIUM ĐÃ NÂNG CẤP */
/* ==================================================================== */
.chat-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    gap: 16px;
}

.chat-header {
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(13, 110, 253, 0.12);
    text-align: center;
}

.chat-box {
    flex: 1;
    min-height: 420px;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(13, 110, 253, 0.08);
}

.message { display: flex; max-width: 85%; }
.ai-message { align-self: flex-start; }
.user-message { align-self: flex-end; }

.msg-bubble {
    padding: 16px 20px;
    border-radius: 20px;
    line-height: 1.6;
    font-size: 15.5px;
    box-shadow: var(--shadow-sm);
    white-space: pre-wrap;
}

.ai-message .msg-bubble { background: #fff; border: 1px solid var(--border-soft); border-bottom-left-radius: 6px; }
.user-message .msg-bubble { background: linear-gradient(135deg, var(--blue), #2a8cff); color: #fff; border-bottom-right-radius: 6px; }

.chat-input-area {
    display: flex;
    gap: 12px;
    background: #fff;
    padding: 12px;
    border-radius: 999px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-soft);
}

.chat-input-area input { border: none; background: transparent; box-shadow: none; }
.chat-input-area input:focus { box-shadow: none; border: none; }
/* ==================================================================== */

.typing-indicator {
    display: inline-flex;
    gap: 6px;
    padding: 14px 16px;
    border-radius: 18px;
    background: #fff;
    box-shadow: var(--shadow-sm);
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(89, 114, 134, 0.7);
    animation: typing 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.12s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.24s;
}

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.4);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.audio-controls,
.listen-actions,
.matching-summary {
    display: flex;
    gap: 12px;
}

.quiz-container {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.quiz-card {
    padding: 20px;
    border-radius: 18px;
    background: var(--bg-accent);
    border: 1px solid rgba(13, 110, 253, 0.08);
}

.quiz-card h4 {
    margin-bottom: 14px;
}

.quiz-option-label {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 12px 14px;
    margin-top: 10px;
    border-radius: 14px;
    border: 1px solid rgba(13, 110, 253, 0.12);
    background: rgba(255, 255, 255, 0.95);
    cursor: pointer;
}

.quiz-option-label.option-correct {
    background: rgba(30, 143, 98, 0.14);
    border-color: rgba(30, 143, 98, 0.35);
}

.quiz-option-label.option-wrong {
    background: rgba(217, 74, 67, 0.14);
    border-color: rgba(217, 74, 67, 0.3);
}

.quiz-result,
.transcript-box,
.matching-feedback {
    margin-top: 18px;
    padding: 16px 18px;
    border-radius: 18px;
    line-height: 1.65;
}

.quiz-result {
    font-weight: 800;
    text-align: center;
}

.transcript-box {
    background: rgba(13, 110, 253, 0.08);
    color: var(--blue-deep);
    border: 1px solid rgba(13, 110, 253, 0.12);
}

.matching-board {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    margin-top: 20px;
}

.matching-column h3 {
    margin-bottom: 12px;
}

.matching-list {
    display: grid;
    gap: 12px;
}

.matching-option {
    width: 100%;
    padding: 14px 16px;
    border-radius: 16px;
    text-align: left;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(13, 110, 253, 0.1);
    color: var(--text-main);
    font-weight: 700;
}

.matching-option.is-selected {
    border-color: rgba(13, 110, 253, 0.4);
    box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.12);
}

.matching-option.is-matched {
    background: rgba(30, 143, 98, 0.14);
    border-color: rgba(30, 143, 98, 0.3);
    color: #116241;
}

.matching-feedback {
    background: rgba(13, 110, 253, 0.08);
    border: 1px solid rgba(13, 110, 253, 0.12);
    color: var(--blue-deep);
}

.matching-feedback.success {
    background: rgba(30, 143, 98, 0.12);
    border-color: rgba(30, 143, 98, 0.28);
    color: #116241;
}

.matching-feedback.error {
    background: rgba(217, 74, 67, 0.12);
    border-color: rgba(217, 74, 67, 0.26);
    color: #8a2d29;
}

.saved-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}

.saved-card {
    padding: 18px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(13, 110, 253, 0.08);
    box-shadow: var(--shadow-sm);
}

.saved-card h3 {
    margin-bottom: 10px;
}

.saved-card p {
    color: var(--text-soft);
    line-height: 1.6;
}

.saved-card .remove-btn {
    margin-top: 14px;
    width: 100%;
}

.tooltip {
    position: absolute;
    z-index: 1000;
    padding: 8px 12px;
    border-radius: 12px;
    background: rgba(16, 37, 55, 0.92);
    color: #fff;
    font-size: 14px;
    line-height: 1.4;
    pointer-events: none;
    box-shadow: var(--shadow-sm);
}

.btn-primary {
    background: linear-gradient(135deg, var(--blue), #2a8cff);
    color: #fff;
}

.btn-secondary {
    background: rgba(22, 52, 75, 0.08);
    color: var(--text-main);
}

.btn-warning {
    background: linear-gradient(135deg, var(--amber), #f5ab2f);
    color: #fff;
}

.btn-success {
    background: linear-gradient(135deg, var(--green), #29ad79);
    color: #fff;
}

.btn-danger {
    background: linear-gradient(135deg, var(--red), #f16861);
    color: #fff;
}

/* ==================================================================== */
/* EMPTY STATE - TRẠNG THÁI RỖNG ĐỂ TRÁNH TRỐNG WEB */
/* ==================================================================== */
.empty-state-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 20px;
    background: rgba(13, 110, 253, 0.03);
    border: 2px dashed rgba(13, 110, 253, 0.15);
    border-radius: 24px;
    margin-top: 20px;
    color: var(--text-soft);
    animation: fadeIn 0.5s ease;
}

.empty-state-box h3 {
    color: var(--blue-deep);
    font-size: 20px;
    margin-bottom: 10px;
}

.empty-state-box p {
    max-width: 400px;
    line-height: 1.6;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 960px) {
    body {
        padding: 14px;
    }

    .navbar,
    .view-section,
    .section-head,
    .saved-header {
        flex-direction: column;
    }

    .sidebar,
    .main-content {
        width: 100%;
    }

    .sidebar {
        border-right: none;
        border-bottom: 1px solid rgba(13, 110, 253, 0.12);
    }

    .section-actions,
    .chat-input-area,
    .audio-controls,
    .listen-actions,
    .matching-summary,
    .action-buttons,
    .controls {
        flex-direction: column;
    }

    .matching-board {
        grid-template-columns: 1fr;
    }

    .message {
        max-width: 100%;
    }
}

@media (max-width: 720px) {
    .tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
    }

    .flex-col,
    .main-content,
    .sidebar {
        padding: 20px 18px;
    }

    .content-box {
        padding: 20px;
    }

    .flashcard-container {
        height: 250px;
    }

    .reading-text {
        font-size: 18px;
    }
}
.flashcard:hover .card-front {
    border-color: var(--blue);
}
/* --- TRẠNG THÁI RỖNG (EMPTY STATE) --- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 20px;
    background: rgba(13, 110, 253, 0.02);
    border: 2px dashed rgba(13, 110, 253, 0.12);
    border-radius: 24px;
    margin-top: 20px;
    color: var(--text-soft);
    animation: fadeIn 0.4s ease-out;
}

.empty-state h3 {
    color: var(--blue-deep);
    font-size: 22px;
    margin-bottom: 12px;
}

.empty-state p {
    max-width: 480px;
    line-height: 1.6;
    margin-bottom: 20px;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 15px;
    opacity: 0.8;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Tinh chỉnh nút bấm trong phần Chat để không bị ép chữ */
button {
    white-space: nowrap;
    flex-shrink: 0;
}