/* Cài đặt chung */
:root {
    --bg-color: #141414;
    --card-bg-color: #232323;
    --text-color: #ffffff;
    --text-muted-color: #a0a0a0;
    --accent-color: #007bff;
    --rank-badge-color: #007bff; /* ĐÃ CẬP NHẬT: Màu đỏ cho rank badge */
    --star-color: #f5c518;

    /* Các màu cho viền gradient */
    --rainbow-color-1: #ff0000; /* Red */
    --rainbow-color-2: #ff7f00; /* Orange */
    --rainbow-color-3: #ffff00; /* Yellow */
    --rainbow-color-4: #00ff00; /* Green */
    --rainbow-color-5: #0000ff; /* Blue */
    --rainbow-color-6: #4b0082; /* Indigo */
    --rainbow-color-7: #9400d3; /* Violet */
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 2rem;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
}

.container {
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

header h1 {
    font-size: 1.75rem;
    font-weight: 600;
    margin: 0;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

header h1 span {
    font-size: 2rem;
    font-weight: 300;
    line-height: 1;
    color: var(--text-muted-color);
}

.header-links {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    font-size: 0.9rem;
    color: var(--text-muted-color);
}

.header-links a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 500;
}

.header-links a:hover {
    text-decoration: underline;
}

.see-all {
    background-color: var(--card-bg-color);
    padding: 0.5rem 1rem;
    border-radius: 999px;
    color: var(--text-color);
    font-weight: 600;
}

.see-all:hover {
    background-color: #3a3a3a;
    text-decoration: none;
}

/* Loader */
.loader {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 4rem auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Thông báo lỗi */
.error-message {
    color: #ff6b6b;
    background-color: #4d2a2a;
    border: 1px solid #ff6b6b;
    padding: 1rem;
    border-radius: 8px;
    text-align: center;
    font-size: 1rem;
}

/* Lưới phim Top 1-3 */
.top-movies-grid {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: repeat(3, 1fr);
    align-items: end; /* <-- Căn các item xuống dưới */
}

/* Lưới phim 4-10 */
.bottom-movies-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(7, 1fr);
    margin-top: 1.5rem;
}


/* --- Kiểu cho Phim #1, #2, #3 --- */
.movie-card-top {
    background-color: var(--card-bg-color);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    position: relative;
    height: 100%; /* #1 sẽ dùng 100%, #2 và #3 sẽ ghi đè */
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    flex-direction: row;
}

.movie-card-top:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.3);
}

/* ===== ĐÃ CẬP NHẬT: Style riêng cho #movie-1 ===== */
#movie-1 {
    background-color: #a00000; /* Màu đỏ đậm */
    border: 2px solid white; /* VIỀN TRẮNG */
    box-sizing: border-box; /* Đảm bảo padding/border không làm tăng kích thước */
    color: var(--text-color); /* ĐÃ THÊM: Chữ màu trắng */
    order: 2; /* <-- Chuyển vào giữa */
}

/* Đảm bảo nội dung bên trong movie-info-top cũng có nền đỏ khi cần */
#movie-1 .movie-info-top {
    background-color: #a00000;
}

/* ===== ĐÃ THÊM: Override màu chữ "mờ" cho #movie-1 ===== */
#movie-1 .movie-meta-top,
#movie-1 .movie-rating-top .rating-count,
#movie-1 .movie-rating-top .icon-user,
#movie-1 .movie-description-top {
    color: var(--text-color); /* Force white */
}

#movie-1 .movie-meta-top .movie-certification {
    border-color: var(--text-color); /* Make border white too */
}

/* ===== ĐÃ CẬP NHẬT: Style riêng cho #movie-2 (Nền vàng 50%, cao 90%) ===== */
#movie-2 {
    /* Màu vàng (#f5c518 là màu sao) với 50% trong suốt */
    background-color: rgba(245, 197, 24, 0.5);
    color: var(--text-color); /* Đảm bảo chữ vẫn màu trắng */
    order: 1; /* Chuyển sang trái */
    height: 90%; /* <-- CẬP NHẬT: Giảm chiều cao */
}

/* Đảm bảo nội dung bên trong movie-info-top cũng có nền vàng 50% */
#movie-2 .movie-info-top {
    background-color: rgba(245, 197, 24, 0.5);
}

/* Đảm bảo chữ "mờ" cũng là màu trắng cho #movie-2 */
#movie-2 .movie-meta-top,
#movie-2 .movie-rating-top .rating-count,
#movie-2 .movie-rating-top .icon-user,
#movie-2 .movie-description-top {
    color: var(--text-color);
}

#movie-2 .movie-meta-top .movie-certification {
    border-color: var(--text-color);
}


/* ===== ĐÃ CẬP NHẬT: Style cho #movie-3 (Copy từ #movie-2, đổi màu) ===== */
#movie-3 {
    background-color: rgba(0, 128, 0, 0.5); /* Màu xanh lá cây 50% trong suốt */
    color: var(--text-color); /* Đảm bảo chữ vẫn màu trắng */
    order: 3; /* Chuyển sang phải */
    height: 90%; /* <-- CẬP NHẬT: Giảm chiều cao */
}

#movie-3 .movie-info-top {
    background-color: rgba(0, 128, 0, 0.5); /* Đảm bảo nội dung có nền xanh lá 50% */
}

#movie-3 .movie-meta-top,
#movie-3 .movie-rating-top .rating-count,
#movie-3 .movie-rating-top .icon-user,
#movie-3 .movie-description-top {
    color: var(--text-color);
}

#movie-3 .movie-meta-top .movie-certification {
    border-color: var(--text-color);
}


/* Poster chung cho #1, #2, #3 */
/* ĐÃ CẬP NHẬT: .movie-poster-top giờ là thẻ <a> */
.movie-poster-top {
    position: relative;
    width: 40%;
    height: 100%;
    flex-shrink: 0;
    display: block; /* Thêm cho thẻ <a> */
}

.movie-poster-top img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    background-color: #1a1a1a;
    border-radius: 8px 0 0 8px; /* Bo góc cho ảnh poster */
}


.add-btn {
    position: absolute;
    top: 10px;
    left: 10px;
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s;
}

.add-btn:hover {
    background-color: rgba(0, 0, 0, 0.8);
}

/* Thông tin chung cho #1, #2, #3 */
.movie-info-top {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    position: relative;
    padding: 1.5rem;
    width: 60%;
    /* Đảm bảo nội dung không bị che bởi viền giả */
    z-index: 1; 
    background-color: inherit; /* Kế thừa màu nền từ cha để che phần viền */
    border-radius: 0 12px 12px 0; /* Bo góc phải cho phần nội dung */
}

/* Huy hiệu xếp hạng */
.rank-badge {
    position: absolute;
    top: 1.5rem;
    left: 1.5rem;
    background-color: var(--rank-badge-color); /* ĐÃ CẬP NHẬT: Sử dụng biến màu đỏ */
    color: white;
    padding: 0.25rem 0.75rem;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 4px;
}

/* Tiêu đề */
.movie-title-top {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    margin-top: 3rem;
    color: var(--text-color);
}

/* ===== ĐÃ THÊM: Style cho link trong tiêu đề ===== */
.movie-title-top a {
    color: inherit; /* Kế thừa màu chữ trắng */
    text-decoration: none; /* Bỏ gạch chân */
    transition: text-decoration 0.2s ease;
}

.movie-title-top a:hover {
    text-decoration: underline; /* Thêm gạch chân khi hover */
}


.movie-meta-top {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted-color);
    flex-wrap: wrap;
}

.movie-meta-top .dot {
    margin: 0 0.25rem;
}

/* Style cho chứng nhận (R, PG-13) */
.movie-meta-top .movie-certification {
    border: 1px solid var(--text-muted-color);
    padding: 0.1rem 0.35rem;
    font-size: 0.8rem;
    border-radius: 3px;
    /* line-height: 1; */ /* ĐÃ XÓA: Để canh giữa dọc tốt hơn */
}

/* Căn chỉnh phần rating */
.movie-rating-top {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
    font-weight: 600;
}

.movie-rating-top .icon-star {
    color: var(--star-color);
    font-size: 1rem;
}

.movie-rating-top span {
    color: var(--text-color);
}

.movie-rating-top .rating-count {
    color: var(--text-muted-color);
    font-weight: 400;
}

.movie-rating-top .icon-user {
    font-size: 0.85rem;
    margin: 0 0.2rem 0 0.1rem;
    color: var(--text-muted-color);
}

.movie-description-top {
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-muted-color);
    margin: 0.5rem 0;
    /* THÊM MỚI: Giới hạn số dòng cho phần mô tả */
    display: -webkit-box;
    -webkit-line-clamp: 4; /* Giới hạn 4 dòng */
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Style cho link "Mark as watched" */
.movie-watchlist-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    
    background-color: var(--accent-color);
    color: var(--text-color);
    
    width: 50%; /* <-- Kích thước chuẩn cho nút */
    padding: 0.75rem;
    border-radius: 8px;
    
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 600;
    margin-top: auto; /* <-- Áp dụng cho tất cả nút để đẩy xuống dưới */
    transition: background-color 0.2s ease;
}

.movie-watchlist-link:hover {
    color: var(--text-color);
    background-color: #0056b3;
}

.movie-watchlist-link i {
    font-size: 0.9rem;
}


/* --- Kiểu cho Phim #4 - #10 --- */

/* ===== ĐÃ THÊM: Wrapper link cho thẻ bottom ===== */
.movie-card-bottom-link {
    text-decoration: none; /* Bỏ gạch chân */
    color: inherit; /* Kế thừa màu chữ */
    display: block; /* Đảm bảo thẻ <a> chiếm toàn bộ không gian */
}

.movie-card-bottom {
    position: relative;
    transition: transform 0.2s ease;
}

.movie-card-bottom:hover {
    transform: translateY(-4px);
}

.movie-poster-bottom {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
}

.movie-poster-bottom img {
    width: 100%;
    height: auto;
    display: block;
    aspect-ratio: 2 / 3;
    object-fit: cover;
    background-color: var(--card-bg-color);
}

.rank-badge-bottom {
    position: absolute;
    top: 8px;
    left: 8px;
    background-color: var(--rank-badge-color); /* ĐÃ CẬP NHẬT: Sử dụng biến màu đỏ */
    color: white;
    padding: 0.2rem 0.6rem;
    font-size: 0.85rem;
    font-weight: 700;
    border-radius: 4px;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.3);
}

.movie-title-bottom {
    font-size: 1rem;
    font-weight: 600;
    margin: 0.75rem 0 0 0;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.movie-title-bottom .icon-play {
    color: var(--text-muted-color);
    font-size: 0.9rem;
    flex-shrink: 0;
}

.movie-title-bottom span {
    display: inline;
}

/* Nút See All ở cuối */
.bottom-see-all {
    display: block;
    width: max-content;
    margin: 2rem auto 0 auto;
    font-size: 1rem;
}

/* Responsive cho toàn bộ layout */
@media (max-width: 1400px) {
    .bottom-movies-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    }
}

@media (max-width: 1024px) {
    .top-movies-grid {
        grid-template-columns: 1fr;
        align-items: end; /* Tắt align-items: end ở mobile */
    }

    /* Đặt lại order và height cho mobile */
    #movie-1, #movie-2, #movie-3 {
        order: unset; /* Dùng thứ tự HTML gốc */
        height: auto; /* Dùng chiều cao tự động (đã sửa ở lần trước) */
    }
}


@media (max-width: 900px) {
    body {
        padding: 1rem;
    }
    
    header h1 {
        font-size: 1.5rem;
    }
    
     .bottom-movies-grid {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    }

    /* ĐÃ SỬA: Áp dụng cho tất cả thẻ .movie-card-top */
    .movie-card-top {
        flex-direction: column;
        height: auto; /* <<< SỬA LỖI: Cho phép thẻ co giãn theo nội dung */
    }
    .movie-card-top .movie-poster-top,
    .movie-card-top .movie-info-top {
        width: 100%;
    }
    
    /* <<< THÊM KHỐI NÀY ĐỂ SỬA LỖI */
    .movie-card-top .movie-poster-top {
        height: auto;
        aspect-ratio: 2 / 3;
        border-radius: 8px 8px 0 0; /* Bo góc ảnh poster khi ở dạng cột */
    }

    .movie-card-top .movie-info-top {
        border-radius: 0 0 8px 8px; /* Bo góc dưới cho phần nội dung */
    }

    #movie-1 .movie-info-top {
        background-color: #a00000; /* Đảm bảo vẫn có nền đỏ */
    }

    /* ===== ĐÃ THÊM: Đảm bảo nền vàng 50% cho #movie-2 trên di động ===== */
    #movie-2 .movie-info-top {
        background-color: rgba(245, 197, 24, 0.5);
    }
    /* ===== ĐÃ THÊM: Đảm bảo nền xanh 50% cho #movie-3 trên di động ===== */
    #movie-3 .movie-info-top {
        background-color: rgba(0, 128, 0, 0.5);
    }
}