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

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

/* === General & Layout (Flexbox Version) === */

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

.content-area {
    flex: 1; /* ทำให้ content ขยายเต็มพื้นที่ที่เหลือ */
    min-width: 0; /* ป้องกัน item ล้น container */
}

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

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

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

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


/* === 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;
}


/* === 4. Tags (on Article Cards) === */
.doujin-tags-container {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
}
.doujin-tag {
    color: white;
    padding: 0.15rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 0.25rem;
    font-weight: bold;
    display: inline-block;
}
.doujin-tag--new { background-color: #dc3545; }
.doujin-tag--popular { background-color: #0d6efd; }
.doujin-tag--thai-artist { background-color: #198754; }
.doujin-tag--color { background-color: #ffc107; color: #000; }


/* 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);
    }
}

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

/* === 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% */
}

/* === 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;
    }
}

/* === 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); /* สีพื้นหลังโปร่งแสง */
}

/* === Panning Iframe Banner === */

/* 1. กรอบนอกสุด */
.panning-banner-wrapper {
    width: 100%;       /* กว้างเต็มพื้นที่ที่ทำได้ */
    max-width: 300px;  /* แต่กว้างสุดไม่เกิน 300px */
}

/* 2. กรอบแสดงผล */
.panning-banner-viewport {
    height: 250px;       /* ความสูงคงที่ */
    overflow: hidden;    /* ซ่อนเนื้อหาที่ล้นกรอบ */
    position: relative;  /* เป็นจุดอ้างอิงให้ content */
}

/* 3. เนื้อหา iframe ข้างใน */
.panning-banner-content {
    width: 300px;        /* ความกว้างของเนื้อหาคงที่ */
    height: 250px;
    position: absolute;
    top: 0;
    left: 0;
}

/* 4. Animation สำหรับเลื่อนไปมา */
@keyframes pan-iframe-content {
    0% {
        left: 0;
    }
    50% {
        /* คำนวณตำแหน่งซ้ายสุดที่จะเลื่อนไปได้ */
        left: calc(100% - 300px);
    }
    100% {
        left: 0;
    }
}

/* 5. สั่งให้ Animation ทำงานเฉพาะเมื่อหน้าจอแคบกว่า 300px */
@media (max-width: 299.98px) {
    .panning-banner-viewport .panning-banner-content {
        animation: pan-iframe-content 8s ease-in-out infinite alternate;
    }
}