/* =============================================================== */
/* === FILE CSS NÂNG CẤP - BẮT ĐẦU VỚI PHẦN HỘI THOẠI === */
/* =============================================================== */

/* --- ROOT VARIABLES & BASE STYLES --- */
:root {
    --bg-main: #f4f6fc;
    --card-bg: #ffffff;
    --primary-text: #2c3e50;
    --secondary-text: #7f8c8d;
    --border-color: #e_a_ecee;
    --soft-shadow: 0 10px 30px rgba(44, 62, 80, 0.08);

    --c-dialogue: linear-gradient(135deg, #48c9b0, #1abc9c);
    --c-vocab: linear-gradient(135deg, #af7ac5, #9b59b6);
    --c-grammar: linear-gradient(135deg, #f5b041, #e67e22);
    --c-reading: linear-gradient(135deg, #5dade2, #3498db);
    /* [CẬP NHẬT] Làm sáng màu nền tiêu đề Tools */
    --c-tools: linear-gradient(135deg, #8697a7, #5c6e7e);
    --accent-color: #3498db;
}

body {
    font-family: 'Segoe UI', 'Yu Gothic', 'Hiragino Sans', 'Meiryo', sans-serif;
    line-height: 1.7;
    color: var(--primary-text);
    background-color: var(--bg-main);
}
.main-container { display: flex; width: 100%; }
main { flex-grow: 1; padding: 20px; overflow-y: auto; height: 100vh; }
.main-header { text-align: center; margin-bottom: 30px; }
.section-container { background: var(--card-bg); border-radius: 15px; margin-bottom: 30px; box-shadow: var(--soft-shadow); overflow: hidden; }
.section-title { color: white; padding: 20px; }
.section-title h2 { font-size: 1.5rem; }
.section-body { padding: 20px; }

/* [CẬP NHẬT] Giảm padding tiêu đề Tools */
#section-tools .section-title {
    padding: 15px 20px;
}
.grammar-point { font-weight: bold; color: #d6336c; }
rt { font-size: 0.65em; color: #555; }
.highlight-word { background-color: #fcf8a2; border-radius: 3px; }

/* =============================================================== */
/* === [THÊM MỚI] PHẦN SLIDESHOW ẢNH === */
/* =============================================================== */
.slideshow-container {
    max-width: 600px;
    position: relative;
    margin: auto auto 25px auto;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--soft-shadow);
}
.slide-item {
    display: none; /* Ẩn tất cả các slide mặc định */
}
.slide-item img.responsive-image {
    width: 100%;
    vertical-align: middle;
}
.prev, .next {
    cursor: pointer;
    position: absolute;
    top: 50%;
    width: auto;
    padding: 16px;
    margin-top: -22px;
    color: white;
    font-weight: bold;
    font-size: 18px;
    transition: 0.6s ease;
    border-radius: 0 3px 3px 0;
    user-select: none;
    background-color: rgba(0,0,0,0.3);
}
.next {
    right: 0;
    border-radius: 3px 0 0 3px;
}
.prev:hover, .next:hover {
    background-color: rgba(0,0,0,0.8);
}
/* Hiệu ứng mờ dần */
.fade {
    animation-name: fade;
    animation-duration: 1.5s;
}
@keyframes fade {
    from {opacity: .4} 
    to {opacity: 1}
}


/* =============================================================== */
/* === [CẬP NHẬT] PHONG CÁCH HỘI THOẠI === */
/* =============================================================== */
.dialogue-wrapper { padding: 10px; }
.scene-tag { 
    display: inline-block; 
    padding: 8px 18px; 
    background-color: #e9ecef; 
    border: 1px solid #dee2e6; 
    border-radius: 25px; 
    font-weight: 600; 
    margin-bottom: 25px; 
    font-size: 1rem; 
    color: #495057; 
}
.dialogue-line { 
    margin-bottom: 20px; 
    padding: 15px; /* Giảm padding một chút */
    border-radius: 15px; 
    background-color: #F8F9FA; 
    border: 1px solid #e0e0e0; 
    border-left-width: 5px;
    border-left-style: solid;
    transition: background-color 0.3s ease; /* Thêm hiệu ứng chuyển màu */
}
/* [THÊM MỚI] Hiệu ứng hover cho thẻ hội thoại */
.dialogue-line:hover {
    background-color: #e9e4f5;
}

/* [THÊM MỚI] Layout header của hội thoại */
.dialogue-header {
    display: flex;
    align-items: center;
    gap: 15px; /* Khoảng cách giữa tên và lời thoại */
    margin-bottom: 5px; /* Khoảng cách với bản dịch */
}
.speaker { 
    font-weight: 700; 
    margin-bottom: 0; /* Bỏ margin cũ */
    font-size: 1.1rem; 
    flex-shrink: 0; /* Ngăn tên nhân vật bị co lại */
}
.speaker.tanaka { color: #0984e3; } .dialogue-line:has(.speaker.tanaka) { border-left-color: #0984e3; }
.speaker.an { color: #6c5ce7; } .dialogue-line:has(.speaker.an) { border-left-color: #6c5ce7; }

.dialogue-text-content { 
    display: flex; 
    align-items: center; 
    gap: 10px; 
}
.dialogue-play-btn {
    background: none; border: none; font-size: 1.5rem; cursor: pointer;
    color: var(--secondary-text); transition: color 0.3s ease;
    padding: 0; line-height: 1;
}
.dialogue-play-btn:hover { color: var(--accent-color); }
.japanese-text { 
    font-size: 1.2rem; 
    line-height: 1.8; 
    margin: 0; 
}
/* [CẬP NHẬT] Giảm khoảng cách cho phần dịch tiếng Việt */
.vietnamese-text { 
    font-style: italic;
    color: #27ae60;
    font-weight: 400;
    font-size: 0.95rem;
    margin-top: 4px; /* Giảm khoảng cách */
    padding: 0 0 0 5px; /* Thêm padding trái nhỏ cho thẳng hàng */
    background-color: transparent;
    border: none;
}

/* =============================================================== */
/* === THANH ĐIỀU HƯỚNG & LAYOUT CHUNG === */
/* =============================================================== */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    height: auto;
}
.top-nav-container {
    background: var(--card-bg);
    padding: 15px;
    border-radius: 12px;
    box-shadow: var(--soft-shadow);
    margin-bottom: 30px;
    border: 1px solid #e_a_ecee;
}
.sidebar-nav ul {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    padding: 0;
    margin: 0;
}
.sidebar-nav a {
    margin-bottom: 0; 
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--secondary-text);
    font-weight: 500;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}
.sidebar-nav a:hover {
    background: #f0f8ff;
    color: var(--accent-color);
}
.sidebar-nav a.active {
    color: var(--accent-color);
    font-weight: 600;
    background: transparent;
    border-bottom: 2px solid var(--accent-color);
    border-radius: 0;
}


/* =============================================================== */
/* === GIAO DIỆN BẢNG TỪ VỰNG === */
/* =============================================================== */
.vocabulary-table {
    width: 100%;
    border-collapse: collapse;
}
.vocabulary-table th, .vocabulary-table td {
    padding: 16px;
    text-align: left;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: middle;
}
.vocabulary-table thead th {
    background-color: #f8f9fa;
}
.example-sentence-cell {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}
.vocab-row {
    transition: background-color 0.3s ease;
}
.vocab-row:hover {
    background-color: #f3e5f5;
}
.vocabulary-table .grammar-point {
    color: #0d47a1;
    background-color: #e3f2fd;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
}
.play-btn-small {
    background-color: #e3f2fd;
    border: 1px solid #bbdefb;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    font-size: 1rem;
    color: #1976d2;
}
.play-btn-small:hover {
    background-color: #bbdefb;
    transform: scale(1.1);
}

/* =============================================================== */
/* === [CẬP NHẬT] PHẦN NGỮ PHÁP === */
/* =============================================================== */
#section-grammar .grammar-explanation h4 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.3rem;
    color: var(--primary-text);
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 10px;
    margin-top: 30px;
    margin-bottom: 20px;
}
#section-grammar .heading-icon {
    font-size: 1.5rem;
}
#section-grammar .explanation-list {
    list-style: none;
    padding-left: 0;
}
#section-grammar .explanation-list li {
    padding: 12px 15px;
    background-color: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 10px;
    border-left: 4px solid #f39c12;
    transition: background-color 0.3s ease; /* Thêm hiệu ứng chuyển màu */
}
/* [THÊM MỚI] Hiệu ứng hover cho thẻ giải thích */
#section-grammar .explanation-list li:hover {
    background-color:  #fcf8a2;
}
.grammar-rule-table {
    width: 100%;
    border-collapse: collapse;
    margin: 25px 0;
    font-size: 1rem;
    box-shadow: var(--soft-shadow);
    border-radius: 8px;
    overflow: hidden;
}
.grammar-rule-table caption {
    font-size: 1.2em;
    font-weight: bold;
    padding: 12px;
    background: var(--c-grammar); /* Dùng lại gradient cho đồng bộ */
    color: white; /* [SỬA LỖI] Đặt màu chữ là trắng */
    text-align: left;
}
.grammar-rule-table thead tr {
    background-color: #f8f9fa;
    color: #333;
    text-align: left;
    font-weight: bold;
}
.grammar-rule-table th, .grammar-rule-table td {
    padding: 12px 15px;
    border-bottom: 1px solid #dee2e6;
}
.grammar-rule-table tbody tr {
    transition: background-color 0.2s ease; /* Thêm hiệu ứng chuyển màu */
}

/* [SẮP XẾP LẠI] 1. Đặt màu nền xen kẽ LÊN TRÊN */
.grammar-rule-table tbody tr:nth-of-type(even) {
    background-color: #f9f9f9;
}



/* [THÊM MỚI] Màu nền xen kẽ cho các hàng */
.grammar-rule-table tbody tr:nth-of-type(even) {
    background-color: #f9f9f9;
}
.g-before {
    color: #c92c2c;
    background-color: #fff5f5;
    padding: 2px 4px;
    border-radius: 4px;
    font-weight: normal;
}
.g-after {
    color: #c92c2c;
    background-color: #fff5f5;
    padding: 2px 4px;
    border-radius: 4px;
    font-weight: bold;
}
.g-exception {
    color: #1864ab;
    background-color: #f1f7ff;
    padding: 2px 5px;
    border-radius: 4px;
    font-weight: bold;
}

/* [CẬP NHẬT] Hiệu ứng hover cho hàng trong bảng ngữ pháp */
.grammar-rule-table tbody tr:hover {
    background-color: #fcf8a2; /* Đổi thành màu vàng highlight */
}


/* =============================================================== */
/* === [CẬP NHẬT] GIAO DIỆN BÀI TẬP & ĐỌC HIỂU === */
/* =============================================================== */
.exercise-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 25px;
}
.exercise-item {
    background-color: #f7f9fc; /* [CẬP NHẬT] Thêm màu nền pastel rất nhẹ */
    border-radius: 12px;
    padding: 25px;
    border: 1px solid #e_a_ecee;
    margin-bottom: 25px;
}
.exercise-question {
    font-size: 1.1rem;
    margin-bottom: 20px;
    line-height: 1.8;
}
.exercise-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.exercise-option {
    padding: 15px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.exercise-item:not(.answered) .exercise-option:hover {
    border-color: #3498db;
    background-color: #f0f8ff;
}
.exercise-item.answered .exercise-option:not(.correct):not(.incorrect) {
     cursor: not-allowed;
     opacity: 0.7;
}
.exercise-option.correct {
    background-color: #e8f5e9;
    border-color: #4caf50;
    color: #2e7d32;
    font-weight: bold;
}
.exercise-option.incorrect {
    background-color: #ffebee;
    border-color: #f44336;
    color: #c62828;
    font-weight: bold;
}
.explanation.hidden {
    display: none;
}
.explanation {
    margin-top: 20px;
    padding: 15px;
    background-color: #e3f2fd;
    border-radius: 8px;
    border-left: 5px solid #2196f3;
}
.feedback-text {
    font-weight: normal;
    font-style: italic;
}

#reading-passage.email-content {
    background-color: #fefdf5;
    padding: 25px;
    border-radius: 8px;
    border: 1px solid #f0eada;
    line-height: 2.2;
    margin-bottom: 20px;
}
.reading-highlight {
    background-color: #ffe8e8;
    color: #c0392b;
    font-weight: 500;
    padding: 3px 6px;
    border-radius: 4px;
    margin: 0 2px;
}


/* =============================================================== */
/* === GIAO DIỆN ĐIỀU KHIỂN AUDIO & CÔNG CỤ === */
/* =============================================================== */
.audio-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    background-color: #f8f9fa;
    padding: 15px;
    border-radius: 12px;
}
.audio-controls .control-btn {
    border: none;
    border-radius: 8px;
    padding: 12px 20px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}
.audio-controls .play-pause {
    background-color: #28a745;
    color: white;
}
.audio-controls .play-pause:hover {
    background-color: #218838;
}
.audio-controls .stop {
    background-color: #dc3545;
    color: white;
}
.audio-controls .stop:hover {
    background-color: #c82333;
}
.speed-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}
.speed-controls span {
    font-weight: 500;
}
.speed-btn {
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 6px;
    padding: 6px 12px;
    cursor: pointer;
}
.speed-btn.active {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}
.reading-controls .speed-controls {
    margin-left: auto;
}
#text-to-read-input {
    width: 100%;
    font-size: 1.1rem;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #ccc;
    resize: vertical;
    min-height: 120px;
    margin-bottom: 20px;
}
.text-reader-app .app-controls {
    flex-direction: row;
}
.text-reader-app .app-main-buttons {
    display: flex;
    gap: 10px;
}
.text-reader-app .app-settings {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-left: auto;
}


/* =================================================================== */
/* === [THÊM MỚI] KHỐI MÃ TỐI ƯU TOÀN DIỆN CHO MOBILE === */
/* Áp dụng các style này khi chiều rộng màn hình từ 768px trở xuống */
/* =================================================================== */
@media (max-width: 768px) {

    /* --- 1. BỐ CỤC CHUNG & FONT CHỮ --- */
    body {
        font-size: 15px;
        -webkit-text-size-adjust: 100%;
    }
    main {
        padding: 10px;
        height: auto;
        overflow-y: visible;
    }
    .main-container {
        display: block;
    }
    .section-body {
        padding: 15px;
    }
    .main-header h1 {
        font-size: 1.6rem;
    }
    .section-title h2 {
        font-size: 1.3rem;
    }

    /* --- 2. THANH ĐIỀU HƯỚNG --- */
    .sidebar-nav ul {
        justify-content: flex-start;
    }
    .sidebar-nav a {
        padding: 8px 12px;
    }

    /* --- 3. BỐ CỤC PHẦN HỘI THOẠI (XẾP CHỒNG) --- */
    .dialogue-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .vietnamese-text {
        margin-top: 8px;
        padding-left: 0;
    }

    /* --- 4. TỐI ƯU BẢNG TỪ VỰNG (QUAN TRỌNG) --- */
    .vocabulary-table thead {
        display: none;
    }
    .vocabulary-table tr {
        display: block;
        border: 1px solid #ddd;
        border-radius: 8px;
        margin-bottom: 15px;
        padding: 10px;
        background-color: #fff;
    }
    .vocabulary-table td {
        display: flex;
        align-items: center;
        text-align: left !important;
        padding-left: 0;
        position: relative;
    }
    .vocabulary-table td:not(:last-child) {
        border-bottom: 1px dashed #eee;
        padding-bottom: 8px;
        margin-bottom: 8px;
    }
    .vocabulary-table td::before {
        content: attr(data-label);
        font-weight: bold;
        width: 120px;
        flex-shrink: 0;
        text-align: left;
        color: var(--primary-text);
    }
    .vocab-word-cell {
        justify-content: space-between;
    }
    .example-sentence-cell {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .example-sentence-cell::before {
        display: none;
    }
    .example-text-wrapper {
        width: 100%;
    }
    .play-example-btn {
        align-self: flex-end;
    }

    /* --- 5. TỐI ƯU TRÌNH ĐỌC VĂN BẢN --- */
    .text-reader-app .app-controls {
        flex-direction: column;
        gap: 20px;
    }
    .text-reader-app .app-main-buttons {
        flex-direction: column;
        width: 100%;
    }
    .text-reader-app .app-settings {
        flex-direction: column;
        align-items: flex-start;
        margin-left: 0;
        gap: 20px;
        width: 100%;
    }
    .voice-selector-wrapper {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
    }
    #voice-select {
        width: 100%;
    }
}
