    /*
============================================
  Custom Stylesheet (Final Version)
============================================
*/

/* === 1. General & Layout === */
html { 
    scroll-behavior: smooth; 
}
body { 
    background-color: #212529; 
}

.main-layout {
    display: flex;
    flex-direction: column; /* ค่าเริ่มต้นสำหรับจอเล็ก: เรียงแนวตั้ง */
    gap: 2rem;
}

.content-area {
    flex: 1;
    min-width: 0;
}

.sidebar {
    width: 100%; /* ค่าเริ่มต้นสำหรับจอเล็ก */
}

/* --- Layout สำหรับ Tablet (md = 768px ขึ้นไป) --- */
@media (min-width: 768px) {
    .main-layout {
        flex-direction: row; /* เปลี่ยนเป็นแนวนอน */
        gap: 1.5rem;
    }

    .sidebar {
        width: 240px; /* กำหนดความกว้าง Sidebar เป็น 200px */
        flex-shrink: 0;
    }
}

/* --- Layout สำหรับ Desktop (lg = 992px ขึ้นไป) --- */
@media (min-width: 992px) {
    .sidebar {
        width: 310px; /* ขยายความกว้าง Sidebar เป็น 310px */
    }
}

/* === Responsive Iframe in Sidebar === */
.iframe-responsive-wrapper {
    position: relative;
    width: 100%;
    overflow: hidden;
    padding-top: 500px; /* 166.66% **สำคัญ** คำนวณสัดส่วน (500 / 300 * 100) */
}
.iframe-responsive-wrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    width: 100%;
    height: 100%;
}
.iframe-max-width-wrapper {
    max-width: 300px; /* กว้างสุดไม่เกิน 300px */
    width: 100%;      /* แต่ถ้าพื้นที่น้อยกว่า 300px ให้กว้างเต็ม 100% */
}

/* === 2. Navbar === */
.navbar .search-expand {
    width: 150px;
    transition: width 0.4s ease-in-out;
}
.navbar .search-expand:focus {
    width: 250px;
}


/* === 3. Article Cards (Gallery & Sidebar) === */
.doujin-item {
    transition: transform 0.2s ease-in-out;
    border-radius: 0.375rem;
    overflow: hidden;
    display: block;
    height: 100%;
    background-color: #343a40;
}
.doujin-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.4);
}
.doujin-cover {
    position: relative;
    aspect-ratio: 3 / 4;
    overflow: hidden;
    background-color: #343a40;
}
.doujin-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.doujin-title-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 2.5rem 0.75rem 0.75rem;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0));
}
.doujin-title {
    font-size: 0.9rem;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar .doujin-title {
    font-size: 0.8rem;
    -webkit-line-clamp: 2;
}


/* === 4. Read Page: Specific Styles === */

/* --- Breadcrumb --- */
.breadcrumb-custom {
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 0.375rem;
    padding: 0.75rem 1rem;
}
.breadcrumb-custom .breadcrumb-item a {
    color: #adb5bd;
    text-decoration: none;
}
.breadcrumb-custom .breadcrumb-item.active {
    color: #fff;
    font-weight: bold;
}
.breadcrumb-custom .breadcrumb-item+.breadcrumb-item::before {
    color: #6c757d;
}

/* --- Image Reader --- */
.image-reader figure.manga-page {
    position: relative;
    margin: 0 0 0.5rem 0;
    padding: 0;
}
.image-reader img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

/* --- Image Click Navigation --- */
.page-nav-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    z-index: 10;
}
.page-nav-overlay a {
    flex: 1;
    height: 100%;
}
.page-nav-overlay .prev-link { cursor: n-resize; }
.page-nav-overlay .next-link { cursor: s-resize; }

/* --- Translator Comment --- */
.translator-comment {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}
.translator-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 3px solid #495057;
}
.translator-bubble {
    flex: 1;
    background-color: #343a40;
    border-radius: 0.5rem;
    padding: 1.5rem;
    color: #fff;
    position: relative;
}
.translator-bubble::before {
    content: '';
    position: absolute;
    left: -10px;
    top: 20px;
    width: 0;
    height: 0;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 10px solid #343a40;
}

/* --- Tag Badge Enhancements --- */
#doujin-details .badge {
    white-space: normal;
    text-align: left;
    overflow-wrap: break-word;
    word-break: break-word;
    position: relative; 
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}
#doujin-details .badge:hover {
    transform: scale(1.1);
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.5);
    z-index: 10; 
}


/* === 5. Sidebar: Sticky Banner & Mobile Carousel === */

/* แก้ไข: เปลี่ยน Breakpoint เป็น 1400px */
@media (min-width: 768px) {
    .sidebar-banner-sticky {
        position: -webkit-sticky;
        position: sticky;
        top: 1.5rem;
    }
}

.recommended-mobile .carousel-control-prev-icon,
.recommended-mobile .carousel-control-next-icon {
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    padding: 1rem;
}


/* === 6. Final Banner (900x300) === */
.banner-viewport {
    max-width: 900px;
    width: 100%;
    height: 300px;
    margin: 0 auto;
    overflow: hidden;
    position: relative;
    border-radius: 0.375rem;
    background-color: #343a40;
}
.banner-content {
    width: 900px;
    height: 300px;
    position: absolute;
    top: 0;
    left: 0;
}
@keyframes pan-banner {
    0% { left: 0; }
    50% { left: calc(100% - 900px); }
    100% { left: 0; }
}
@media (max-width: 899.98px) {
    .banner-viewport .banner-content {
        animation: pan-banner 10s ease-in-out infinite alternate;
    }
}


/* 1. ซ่อน Banner เป็นค่าเริ่มต้น */
.side-banner {
    display: none;
}
/* 2. ใช้ Media Query เพื่อกำหนดสไตล์เมื่อหน้าจอกว้าง 2000px ขึ้นไปเท่านั้น */
@media (min-width: 2000px) {
    .side-banner {
        display: block;
        position: fixed; /* ทำให้เลื่อนตามหน้าจอ */
        top: 50px;      /* เว้นระยะจากด้านบน 300px */
        width: 300px;
        height: 1000px;
        z-index: 99;     /* ให้อยู่เหนือเนื้อหาบางส่วน แต่ต่ำกว่า Modal */
    }

    #left-banner {
        /* * คำนวณตำแหน่ง:
        * 50% = กึ่งกลางหน้าจอ
        * 700px = ครึ่งหนึ่งของ container (1400px / 2)
        * 30px = ระยะห่างจากขอบ container
        * 300px = ความกว้างของ iframe
        * right: calc(50% + 700px + 30px) คือการยึดขอบขวาของ iframe ไว้ที่ตำแหน่งนี้
        */
        right: calc(50% + 700px + 30px);
    }

    #right-banner {
        /*
        * คำนวณตำแหน่ง:
        * left: calc(50% + 700px + 30px) คือการยึดขอบซ้ายของ iframe ไว้ที่ตำแหน่งนี้
        */
        left: calc(50% + 700px + 30px);
    }
}

.download-card {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    background-color: #343a40;
    border-radius: 0.5rem;
    color: #fff;
    transition: background-color 0.2s ease, transform 0.2s ease;
}
.download-card:hover {
    background-color: #495057;
    transform: translateY(-3px);
}
.download-card-icon {
    font-size: 2.5rem;
    margin-right: 1.5rem;
    color: #0dcaf0; /* สี info */
}
.download-card-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* ป้องกันชื่อไฟล์ยาวเกิน */
}
.download-card-info .info-title {
    font-weight: bold;
    font-size: 1.1rem;
    white-space: nowrap; /* ป้องกันการขึ้นบรรทัดใหม่ */
    overflow: hidden;
    text-overflow: ellipsis; /* แสดง ... เมื่อชื่อยาว */
}
.download-card-info .info-details {
    font-size: 0.85rem;
    opacity: 0.7;
}
.download-card-arrow {
    font-size: 1.5rem;
    transition: transform 0.2s ease;
}
.download-card:hover .download-card-arrow {
    transform: translateX(5px);
}

/* === Navbar Menu Hover Effect === */
.navbar-nav .nav-link {
    transition: background-color 0.2s ease-in-out;
    border-radius: 0.375rem; /* ทำให้ขอบมน */
}

.navbar-nav .nav-link:hover,
.navbar-nav .nav-link:focus {
    background-color: rgba(255, 255, 255, 0.1); /* สีพื้นหลังโปร่งแสง */
}

.image-link-hover {
    transition: opacity 0.2s ease-in-out;
}

.image-link-hover:hover {
    opacity: 0.8; /* ทำให้รูปจางลงเล็กน้อยเมื่อชี้ */
}