/* --- Variables & Reset --- */
:root {
    --bg-color: #ffffff;
    --text-dark: #222222;
    --text-gray: #888888;
    --grid-gap: 8px; /* ช่องว่างระหว่างรูป บีบให้แคบลงแบบ Pixieset */
    --font-serif: 'Playfair Display', serif;
    --font-sans: 'Kanit', sans-serif;
}
/* ปิดกรอบฟ้าเวลากดในมือถือ (Tap Highlight) สำหรับทุกองค์ประกอบทั้งเว็บ */
* {
    -webkit-tap-highlight-color: transparent;
}

/* ปิดเส้นขอบโฟกัส (Outline) เวลากดปุ่ม เลือกลิงก์ หรือช่องกรอกข้อความ */
button:focus, 
a:focus, 
input:focus,
textarea:focus {
    outline: none;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    background-color: var(--bg-color);
    font-family: var(--font-sans);
    color: var(--text-dark);
    -webkit-font-smoothing: antialiased;
}

/* --- Header & Navigation (แถบเมนูด้านบนสุด) --- */
.site-header {
    display: flex; /* จัดให้อยู่บรรทัดเดียวกันซ้าย-ขวา */
    justify-content: space-between;
    align-items: center;
    padding: 30px 5%;
    background-color: var(--bg-color);
}

.logo {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 2px; /* เพิ่มระยะห่างตัวอักษรให้ดูแพง */
}

.site-nav a {
    text-decoration: none;
    color: var(--text-gray);
    margin-left: 30px;
    font-size: 0.9rem;
    font-weight: 400;
    transition: color 0.3s ease;
}

.site-nav a:hover, .site-nav a.active {
    color: var(--text-dark);
}

/* --- Hero Cover Section --- */
.hero-cover {
    width: 100%;
    height: 95vh; /* ความสูงเกือบเต็มจอ */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 40px 20px;
    color: white;
    text-align: center;
}

.hero-top-logo {
    font-size: 0.75rem;
    letter-spacing: 3px;
    font-weight: 500;
    text-transform: uppercase;
    opacity: 0.9;
}

.hero-content {
    margin-bottom: 5vh;
}

.hero-title {
    font-family: var(--font-main);
    font-size: 4.5rem;
    font-weight: 500; /* ใช้ตัวหนาปานกลางให้ดูโมเดิร์น */
    margin-bottom: 15px;
    letter-spacing: 1px;
}

.hero-subtitle {
    font-size: 0.8rem;
    letter-spacing: 4px;
    font-weight: 400;
    margin-bottom: 40px;
    opacity: 0.9;
}

.view-gallery-btn {
    color: white;
    text-decoration: none;
    font-size: 0.75rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    border-bottom: 1px solid rgba(255,255,255,0.5);
    padding-bottom: 5px;
    transition: all 0.3s ease;
}

.view-gallery-btn:hover {
    border-bottom: 1px solid white;
    opacity: 0.8;
}

/* --- Action Bar (Toolbar) --- */
.action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 25px 4%;
    background-color: var(--bg-color); /* เปลี่ยนจาก white ให้ดึงสีพื้นหลังปัจจุบันมาใช้แทน */
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid rgba(128, 128, 128, 0.2); /* ปรับสีเส้นขอบให้กลืนไปกับทั้งโหมดมืดและสว่าง */
    transition: background-color 0.3s ease; /* เพิ่มความสมูทตอนสลับสี */
}

.action-left h2 {
    font-family: var(--font-main);
    font-weight: 500;
    font-size: 1.5rem;
    margin-bottom: 2px;
}

.action-left p {
    font-size: 0.65rem;
    letter-spacing: 2px;
    color: var(--text-gray);
    text-transform: uppercase;
}

.action-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.text-link {
    font-size: 0.8rem;
    color: var(--text-gray);
    cursor: pointer;
    transition: color 0.3s;
}

.text-link:hover { color: var(--text-dark); }

.divider {
    height: 15px;
    width: 1px;
    background-color: #ddd;
    margin: 0 5px;
}

.icon {
    width: 20px;
    height: 20px;
    color: var(--text-gray);
    cursor: pointer;
    transition: color 0.3s, transform 0.2s;
}

.icon:hover {
    color: var(--text-dark);
    transform: scale(1.1);
}

/* --- Masonry Gallery Grid --- */
.gallery-container {
    padding: 20px 4% 60px; /* ลด Padding ด้านบนให้ต่อจาก Action bar เนียนๆ */
}

.gallery-grid {
    column-count: 3;
    column-gap: var(--grid-gap);
}

.gallery-item {
    break-inside: avoid;
    margin-bottom: var(--grid-gap);
    overflow: hidden;
    background-color: #f9f9f9;
    
    /* Animation ซ่อนไว้ก่อน */
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.gallery-item.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.gallery-item img {
    width: 100%;
    display: block;
    cursor: pointer;
    transition: opacity 0.3s ease;
}

.gallery-item img:hover {
    opacity: 0.85; /* Pixieset มักจะแค่ดรอปแสงลงเวลามีเมาส์ชี้ ไม่นิยมซูมภาพ */
}

/* --- Responsive --- */
@media (max-width: 1024px) {
    .gallery-grid { column-count: 2; }
    .hero-title { font-size: 3.5rem; }
}

@media (max-width: 768px) {
    .action-bar { flex-direction: column; gap: 15px; text-align: center; }
    .hero-title { font-size: 2.5rem; }
}

@media (max-width: 480px) {
    .gallery-grid { column-count: 1; }
}

/* --- Collection (Folder) Page Styles --- */
.collection-container {
    padding: 60px 5%;
    max-width: 1400px;
    margin: 0 auto;
}

.collection-header {
    text-align: center;
    margin-bottom: 60px;
}

.collection-header h1 {
    font-size: 2.5rem;
    font-weight: 500;
    margin-bottom: 10px;
}

.collection-header p {
    color: var(--text-gray);
    font-weight: 300;
}

/* Grid สำหรับเรียงโฟลเดอร์ */
.folder-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 40px;
}

.folder-item {
    text-decoration: none;
    color: var(--text-dark);
    display: block;
    transition: transform 0.3s ease;
}

.folder-item:hover {
    transform: translateY(-5px); /* เวลานำเมาส์ชี้ โฟลเดอร์จะลอยขึ้นนิดๆ */
}

.folder-image {
    width: 100%;
    aspect-ratio: 4 / 3; /* บังคับสัดส่วนหน้าปกให้เท่ากันทุกโฟลเดอร์ */
    background-size: cover;
    background-position: center;
    border-radius: 4px;
    margin-bottom: 15px;
    transition: opacity 0.3s ease;
}

.folder-item:hover .folder-image {
    opacity: 0.85;
}

.folder-info h3 {
    font-size: 1.2rem;
    font-weight: 500;
    margin-bottom: 5px;
}

.folder-info span {
    font-size: 0.8rem;
    color: var(--text-gray);
    letter-spacing: 1px;
}

/* --- Dark Mode Colors --- */
body.dark-mode {
    --bg-color: #111111;
    --text-dark: #ffffff;
    --text-gray: #888888;
}

/* ปุ่ม Dark Mode Toggle */
.theme-toggle {
    background: none;
    border: none;
    color: var(--text-gray);
    cursor: pointer;
    margin-left: 20px;
    vertical-align: middle;
    transition: color 0.3s;
}
.theme-toggle:hover { color: var(--text-dark); }
.theme-toggle svg { width: 18px; height: 18px; }

/* --- Filter Menu --- */
.filter-menu {
    margin-top: 30px;
    display: flex;
    justify-content: center;
    gap: 25px;
    flex-wrap: wrap;
}

.filter-btn {
    background: none;
    border: none;
    font-family: var(--font-main);
    font-size: 0.85rem;
    color: var(--text-gray);
    cursor: pointer;
    padding-bottom: 5px;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.filter-btn.active, .filter-btn:hover {
    color: var(--text-dark);
    border-bottom: 1px solid var(--text-dark);
}

/* --- Lock Icon --- */
.folder-image {
    position: relative; /* สำคัญมาก เพื่อให้ไอคอนล็อกอยู่ข้างในรูป */
}

.lock-icon {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px); /* ทำพื้นหลังเบลอนิดๆ ดูแพง */
    color: white;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lock-icon svg { width: 12px; height: 12px; }

/* ซ่อนโฟลเดอร์เวลาโดน Filter */
.folder-item.hidden {
    display: none;
}

/* =========================================
   Responsive Design (แท็บเล็ตและโทรศัพท์มือถือ)
   ========================================= */

/* สำหรับ iPad และหน้าจอที่เล็กกว่า 768px */
@media (max-width: 768px) {
    /* 1. จัด Header ใหม่ให้เรียงลงมาตรงกลาง */
    .site-header {
        flex-direction: column;
        gap: 15px;
        padding: 20px 5%;
        text-align: center;
    }
    
    /* 2. จัดเมนู Navigation ให้มีระยะห่างสมดุล */
    .site-nav {
        display: flex;
        justify-content: center;
        align-items: center;
        flex-wrap: wrap;
        gap: 20px;
    }

    .site-nav a {
        margin-left: 0; /* ลบ margin ซ้ายของเดิมทิ้ง */
        font-size: 0.85rem;
    }

    .theme-toggle {
        margin-left: 0;
    }

    /* 3. ลดขนาดหัวข้อลงนิดหน่อย */
    .collection-header h1 {
        font-size: 2rem;
    }

    /* 4. ปรับกริดโฟลเดอร์ให้รูปเล็กลงนิดนึงจะได้พอดีจอ iPad */
    .folder-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        gap: 25px;
    }
}

/* สำหรับสมาร์ทโฟน หน้าจอเล็กกว่า 480px */
@media (max-width: 480px) {
    /* ป้องกันโลโก้ตกบรรทัด */
    .logo {
        font-size: 1rem;
        white-space: nowrap; 
    }

    /* เพิ่มระยะห่างปุ่ม Filter เวลาถูกดันลงมาบรรทัดใหม่ */
    .filter-menu {
        gap: 15px;
    }

    .filter-btn {
        font-size: 0.75rem;
    }

    /* ปรับระยะห่างรวมของ Container ไม่ให้ชิดขอบจอเกินไป */
    .collection-container {
        padding: 40px 5%;
    }
}

/* =========================================
   Lightbox (ระบบขยายรูปภาพเต็มจอ)
   ========================================= */
.lightbox {
    position: fixed;
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%;
    background: rgba(0, 0, 0, 0.95); /* พื้นหลังดำสนิท 95% */
    display: flex; 
    justify-content: center; 
    align-items: center;
    z-index: 1000;
    
    /* ซ่อนไว้ก่อน */
    opacity: 0; 
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.lightbox.active {
    opacity: 1; 
    pointer-events: auto;
}

.lightbox-img {
    max-width: 90%; 
    max-height: 90vh;
    object-fit: contain; /* บังคับรูปไม่ให้ผิดสัดส่วน */
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    transition: transform 0.3s ease;
    transform: scale(0.95);
}

.lightbox.active .lightbox-img {
    transform: scale(1); /* เด้งขยายขึ้นมานิดนึงตอนเปิด */
}

/* ปุ่มกากบาทปิด */
.close-lightbox {
    position: absolute; 
    top: 20px; 
    right: 30px;
    color: white; 
    font-size: 40px; 
    font-family: var(--font-main);
    cursor: pointer;
    transition: transform 0.2s;
}

.close-lightbox:hover { 
    transform: scale(1.1); 
}

/* ปุ่มดาวน์โหลด */
.lightbox-download {
    position: absolute; 
    bottom: 30px; 
    right: 30px;
    color: white; 
    background: rgba(255,255,255,0.15);
    padding: 12px; 
    border-radius: 50%; 
    display: flex;
    transition: background 0.3s, transform 0.2s;
}

.lightbox-download svg {
    width: 20px;
    height: 20px;
}

.lightbox-download:hover { 
    background: rgba(255,255,255,0.3); 
    transform: translateY(-3px);
}

/* =========================================
   UI & Animations (ปุ่มย้อนกลับและโหลดหน้า)
   ========================================= */

/* แอนิเมชันเปิดหน้าเว็บให้ดูสมูท */
body {
    animation: fadeInPage 0.8s ease-out forwards;
}

@keyframes fadeInPage {
    from { 
        opacity: 0; 
        
    }
    to { 
        opacity: 1; 
        
    }
}

/* ปุ่มย้อนกลับ (Back Button) */
.back-btn {
    position: absolute;
    top: 30px;
    left: 4%;
    color: white;
    text-decoration: none;
    font-size: 0.75rem;
    letter-spacing: 2px;
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0.7;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 101; /* ให้อยู่บนสุดเสมอ */
}

.back-btn:hover {
    opacity: 1;
    transform: translateX(-5px); /* เลื่อนไปทางซ้ายนิดๆ เวลานำเมาส์ชี้ */
}

.back-btn svg { 
    width: 16px; 
    height: 16px; 
}

/* ปรับ responsive ให้ปุ่มย้อนกลับบนมือถือ */
@media (max-width: 768px) {
    .back-btn {
        top: 20px;
        left: 5%;
        font-size: 0.65rem;
    }
}

/* =========================================
   Responsive หน้า Album (Hero Cover)
   ========================================= */

/* สำหรับ iPad และแท็บเล็ต (หน้าจอเล็กกว่า 768px) */
@media (max-width: 768px) {
    .hero-cover {
        padding-top: 80px; /* เพิ่มพื้นที่ด้านบน ดันโลโก้ลงมาไม่ให้ชนขอบ */
    }
    
    .back-btn {
        top: 25px;
        left: 20px;
    }
    
    .hero-title {
        font-size: 3rem; /* ลดขนาดชื่ออัลบั้มลงจาก 4.5rem */
    }
}

/* สำหรับโทรศัพท์มือถือ (หน้าจอเล็กกว่า 480px) */
@media (max-width: 480px) {
    .hero-cover {
        height: 85vh; /* ลดความสูงหน้าปกลงนิดนึง ให้ลูกค้าเห็นขอบแกลเลอรีด้านล่าง จะได้รู้ว่าเลื่อนลงได้ */
        padding-top: 70px; 
        
        /* เลื่อนจุดโฟกัสรูปภาพจากตรงกลาง (center) ให้ขยับขึ้นมาด้านบนนิดนึง (30%) 
           ช่วยให้รูปหน้าปกแนวนอนแสดงผลบนมือถือแนวตั้งได้สวยขึ้น */
        background-position: center 30%; 
    }
    
    .back-btn {
        top: 20px;
        left: 15px;
        font-size: 0.6rem; /* ลดขนาดปุ่มย้อนกลับ */
    }

    .hero-top-logo {
        margin-top: 15px; /* ดันโลโก้ "PIXEL GALLERY PHOTOGRAPHY" หนีปุ่มย้อนกลับเพิ่มอีก */
        font-size: 0.65rem;
    }

    .hero-title {
        font-size: 2.2rem; /* ย่อชื่ออัลบั้มให้พอดีจอมือถือ */
        margin-bottom: 10px;
    }

    .hero-subtitle {
        font-size: 0.7rem;
        margin-bottom: 25px;
    }

    /* ปรับขนาดแถบ Action Bar ด้านล่างหน้าปกให้กะทัดรัดขึ้น */
    .action-bar {
        padding: 20px 5%;
    }
    
    .action-left h2 {
        font-size: 1.2rem;
    }
}

/* --- Lightbox Navigation Buttons --- */
.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.3s, transform 0.2s;
    z-index: 1001;
}

.lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-50%) scale(1.1);
}

.lightbox-nav svg {
    width: 24px;
    height: 24px;
}

.lightbox-nav.prev { left: 30px; }
.lightbox-nav.next { right: 30px; }

@media (max-width: 768px) {
    .lightbox-nav { width: 40px; height: 40px; }
    .lightbox-nav.prev { left: 10px; }
    .lightbox-nav.next { right: 10px; }
}

/* --- Search Bar --- */
.search-bar {
    display: flex;
    align-items: center;
    max-width: 350px; /* กำหนดความกว้างไม่ให้ยาวเกินไป */
    margin: 35px auto 0;
    padding: 8px 10px;
    border-bottom: 1px solid var(--text-gray);
    transition: border-color 0.3s ease;
}

/* ตอนคลิกพิมพ์ให้เส้นเข้มขึ้น */
.search-bar:focus-within {
    border-bottom-color: var(--text-dark);
}

.search-bar svg {
    width: 18px;
    height: 18px;
    color: var(--text-gray);
    margin-right: 12px;
}

.search-bar input {
    border: none;
    outline: none;
    background: transparent; /* โปร่งใสเพื่อให้เนียนไปกับโหมดมืด/สว่าง */
    width: 100%;
    font-family: var(--font-main);
    font-size: 0.95rem;
    color: var(--text-dark); /* สีตัวอักษรเปลี่ยนตามโหมด */
}

.search-bar input::placeholder {
    color: var(--text-gray);
    font-weight: 300;
}