/* ==========================================================================
   PHẦN 1: CODE GỐC CỦA BẠN (KHÔNG SỬA ĐỔI)
   ========================================================================== */

/* 1. KHAI BÁO BIẾN MÀU */
/* --- A. MẶC ĐỊNH LÀ LIGHT MODE --- */
:root {
    --tr-primary: #31c493;
    --tr-primary-hover: #0ebc82;
    
    --tr-bg-body: #ffffff;
    --tr-bg-main: transparent;
    
    --tr-text-title: #000000;
    --tr-text-body: #000000;
    --tr-text-sub: #000000;
    --tr-text-link: #000000;
    
    --tr-border: #e2e8f0;
    --tr-shadow: 0 4px 14px rgba(2,6,23,0.06);
    
    --tr-btn-bg: #e2e8f0;
    --tr-btn-text: #000000;
    
    --tr-tag-bg: #f1f5f9;
    --tr-tag-text: #000000;
    
    --tr-chap-link: #0ea5e9;
}

/* Theme Ashe thường thêm class "ashe-dark-mode" vào body */
body.ashe-dark-mode, 
body.dark-mode, 
html.dark-mode { 
    --tr-bg-body: #333941;
    --tr-bg-main: #111827;
    
    --tr-text-title: #ffffff;
    --tr-text-body: #ffffff;
    --tr-text-sub: #d1d5db;
    --tr-text-link: #ffffff;
    
    --tr-border: #374151;
    --tr-shadow: 0 4px 14px rgba(0,0,0,0.5);
    
    --tr-btn-bg: #374151;
    --tr-btn-text: #ffffff;
    
    --tr-tag-bg: #374151;
    --tr-tag-text: #e5e7eb;
    
    --tr-chap-link: #ff4d4d;
}

/* 2. CẤU TRÚC CHUNG (GLOBAL) */
.tr-section { margin: 24px 0; }
.tr-section-title, 
.tr-title-page {
    font-size: 1.6rem;
    margin-bottom: 16px;
    color: #1f2937;
    font-weight: 700;
    border-left: 4px solid #10b981;
    padding-left: 12px;
}

/* 3. GRID & ITEM */
.tr-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 18px;
}

.tr-manga-item { 
    background: var(--tr-bg-body);
    border-radius: 8px; 
    overflow: hidden; 
    box-shadow: var(--tr-shadow);
    display: flex; 
    flex-direction: column;
    position: relative;
    cursor: pointer;
    border: 1px solid var(--tr-border);
}

.tr-manga-item .tr-thumb { 
    display: block; width: 100%; height: 0; padding-bottom: 140%; position: relative; overflow: hidden; 
}
.tr-manga-item .tr-thumb img { 
    position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; 
}

.tr-manga-item .tr-info { 
    padding: 10px; flex: 1; display: flex; flex-direction: column; justify-content: space-between; 
}

.tr-title {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tr-title a { 
    color: var(--tr-text-link);
    text-decoration: none;
    display: flex; max-width: 100%; font-weight: 600; font-size: 16px;
}
.tr-title a:hover { color: var(--tr-primary); }

.tr-latest { 
    font-size: 12px; 
    color: var(--tr-text-sub);
    display: flex; justify-content: space-between; gap: 8px; align-items: center; 
}
.tr-chap-link { 
    color: var(--tr-chap-link);
    text-decoration: none; font-weight: 600; 
}

/* 4. DETAIL PAGE */
.tr-detail { display: block; }

.tr-detail-header { 
    display: flex; gap: 20px; align-items: flex-start; margin-bottom: 18px; 
}

.tr-detail-thumb { 
    width: 180px; border-radius: 8px; object-fit: cover; 
}

.tr-detail-meta h1 { 
    font-size: 1.5rem; margin: 0 0 8px 0; color: var(--tr-text-title);
}
.tr-detail-meta p { color: var(--tr-text-body); }
.tr-detail-meta strong { color: var(--tr-text-title); }

.tr-desc {
    border: 1px solid var(--tr-border);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    color: var(--tr-text-body);
}

.tr-buttons .tr-btn {
    display: inline-block; 
    margin-right: 10px; 
    padding: 8px 16px; 
    border-radius: 8px; 
    background: var(--tr-btn-bg);
    color: var(--tr-btn-text);
    text-decoration: none; 
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.tr-buttons .tr-btn-primary {
    background: var(--tr-primary); 
    color: #fff; 
}

.tr-buttons .tr-btn:hover {
    background-color: var(--tr-text-link);
    color: #10b981;
}

.tr-buttons .tr-btn-primary:hover {
    background-color: var(--tr-primary-hover);
    color: #fff;
}

.tr-chapter-list {
    max-height: 400px; overflow-y: auto; padding: 0 10px; 
    border: 1px solid var(--tr-border); 
    border-radius: 8px; list-style: none;
}
.tr-chapter-list li {
    padding: 6px 0; border-bottom: 1px solid var(--tr-border);
}
.tr-chapter-list li:last-child { border-bottom: none; }
.tr-chapter-list a { text-decoration: none; color: var(--tr-primary); }
.tr-chapter-list a:hover { color: var(--tr-primary); }

/* 5. READER & NAV */
.tr-chapter-nav { display: flex; gap: 15px; margin: 15px 0; justify-content: center; }

.tr-chapter-nav .tr-btn {
    padding: 8px 16px; 
    background: var(--tr-primary); 
    color: #fff; 
    border-radius: 6px; text-decoration: none;
}
.tr-chapter-nav .tr-btn:hover { background: var(--tr-primary-hover); }

.tr-chapter-nav select {
    padding: 8px; border-radius: 6px; border: 1px solid var(--tr-border);
    background: var(--tr-bg-body); color: var(--tr-text-body);
}

.tr-chapter-popup { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.tr-chapter-popup-content { background: var(--tr-bg-body); padding: 20px; border-radius: 10px; max-height: 80%; overflow-y: auto; width: 300px; position: relative; }
.tr-chapter-close { position: absolute; top: 10px; right: 15px; font-size: 20px; cursor: pointer; color: var(--tr-text-body); }
.tr-chapter-popup a { text-decoration: none; color: var(--tr-primary); }

.tr-chapter-img { text-align: center; background: #222; padding: 20px 0; }
.tr-chapter-img img { width: 100%; height: auto; display: block; max-width: 800px; margin: 0 auto; }

/* 6. WIDGET THỂ LOẠI */
.tr-widget-cat {
    background: var(--tr-bg-body);
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    margin-bottom: 20px;
    border: 1px solid var(--tr-border);
}

.tr-widget-title {
    font-size: 18px; font-weight: 700; margin-top: 0; margin-bottom: 15px;
    border-bottom: 2px solid var(--tr-primary); padding-bottom: 8px;
    display: inline-block; color: var(--tr-text-title);
}

.tr-cat-cloud { display: flex; flex-wrap: wrap; gap: 8px; }

.tr-cat-tag {
    display: inline-block; padding: 6px 12px; font-size: 13px;
    border-radius: 20px; text-decoration: none; transition: all 0.2s ease;
    border: 1px solid transparent;
    background: var(--tr-tag-bg); 
    color: var(--tr-tag-text);
}

.tr-cat-tag:hover {
    background: var(--tr-btn-bg); color: var(--tr-text-link); transform: translateY(-2px);
}

.tr-cat-tag.active {
    background: var(--tr-primary); color: #ffffff;
}

/* 7. PAGINATION & SEARCH */
.tr-pagination { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin: 30px 0; }

.tr-pagination a,
.tr-pagination span.current {
    display: inline-block; padding: 3px 0px; min-width: 42px; text-align: center;
    font-size: 15px; line-height: 1.4; border-radius: 8px;
    border: 1px solid #ccc;
    background: var(--tr-bg-body); color: var(--tr-text-body);
    text-decoration: none; box-sizing: border-box; transition: 0.2s; white-space: nowrap;
}

.tr-pagination a:hover { border-color: var(--tr-primary-hover); color: var(--tr-primary-hover); }

.tr-pagination span.current {
    background: var(--tr-primary); border-color: var(--tr-primary); color: #fff; font-weight: bold;
}

.tr-search-form { display: flex; gap: 8px; margin-bottom: 12px; }
.tr-search-form input[type="search"] { 
    padding: 8px; border-radius: 6px; border: 1px solid var(--tr-border); flex: 1; 
    background: var(--tr-bg-body); color: var(--tr-text-body);
}
.tr-search-form button { padding: 8px 12px; border-radius: 6px; background: #111827; color: #fff; border: 0; }

.tr-more { text-align: center; margin-top: 40px; }
.tr-more .tr-btn {
    display: inline-block; font-size: 18px; padding: 12px 30px; border-radius: 8px;
    background-color: var(--tr-primary); color: #fff; text-decoration: none; transition: transform 0.2s, background-color 0.2s;
}
.tr-more .tr-btn:hover { transform: scale(1.05); background-color: var(--tr-primary-hover); }


/* ==========================================================================
   PHẦN 2: BỔ SUNG TÍNH NĂNG MỚI (AJAX LOADING & MOBILE)
   ========================================================================== */

/* 8. LOADING SPINNER (CẦN THIẾT CHO AJAX READER) */
.tr-loader {
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--tr-primary);
    border-radius: 50%;
    width: 35px;
    height: 35px;
    animation: spin 0.8s linear infinite;
    margin: 40px auto 15px auto;
}
@keyframes spin { 
    0% { transform: rotate(0deg); } 
    100% { transform: rotate(360deg); } 
}

/* 9. MOBILE OPTIMIZATION (ĐIỀU CHỈNH 2 CỘT & NÚT BẤM) */
@media (max-width: 768px) {
    .tr-section-title, .tr-title-page {
        font-size: 1.3rem; margin-bottom: 15px; padding-left: 10px;
    }
}

@media (max-width: 480px) {
    /* 1. Lưới truyện 2 cột */
    .tr-grid {
        grid-template-columns: repeat(2, 1fr); 
        gap: 10px;
    }
    
    /* Chữ nhỏ lại trên mobile */
    .tr-title a { font-size: 14px; }
    
    /* Ẩn ngày cập nhật cho gọn */
    .tr-updated { display: none; }

    /* 2. Trang chi tiết gọn hơn */
    .tr-detail-header { flex-direction: column; padding: 15px; }
    .tr-detail-thumb { width: 140px; align-self: center; margin-bottom: 15px; }
    .tr-detail-meta h1 { font-size: 1.4rem; text-align: center; }
    .tr-detail-meta p { font-size: 14px; text-align: center; }
    
    /* Nút bấm full width */
    .tr-buttons { flex-direction: column; width: 100%; }
    .tr-buttons .tr-btn { margin-top: 10px; margin-right: 0; text-align: center; width: 100%; padding: 12px; }

    /* 3. Trang đọc: Nút điều hướng to, dễ bấm */
    .tr-chapter-nav { gap: 8px; padding: 0 10px; flex-wrap: wrap; }
    
    /* Nút Prev/Next chia đôi màn hình */
    .tr-chapter-nav .tr-btn { width: 35%; padding: 12px 5px; font-size: 14px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    
    /* Select box xuống dòng, full width */
    .tr-chapter-nav select { width: 100%; max-width: none; padding: 10px; margin-top: 5px; font-size: 16px; order: 3; }
    
    /* Ảnh full màn hình */
    .tr-chapter-img { padding: 0; }
    .tr-chapter-img img { width: 100% !important; }

    /* 4. Pagination & Search */
    .tr-pagination a, .tr-pagination span.current { padding: 8px 12px; font-size: 14px; min-width: 38px; height: 38px; }
    .tr-search-form { flex-direction: column; }
    .tr-search-form button { width: 100%; padding: 12px; }
    
    /* Widget */
    .tr-widget-cat { padding: 15px; }
}