/**
 * YouStory - Góc Viết Nhỏ Theme Styles
 * Tối ưu hóa màu sắc, tương phản, typography tiếng Việt và tương thích độc lập hoàn toàn.
 */

/* Import Google Fonts tiếng Việt chuẩn xác (Thống nhất 2 font: Lora & Be Vietnam Pro) */
@import url('https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:ital,wght@0,400;0,500;0,600;0,700;1,400&family=Lora:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500&display=swap');

/* Nền giấy kem và họa tiết chấm mực */
body {
    background-color: #FAF6F0;
    color: #2C221E;
    font-family: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-image: radial-gradient(rgba(107, 91, 83, 0.06) 1px, transparent 0);
    background-size: 24px 24px;
    margin: 0;
    padding: 0;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

::selection {
    background-color: #C85A32;
    color: #FFFFFF;
}

/* ==========================================================================
   HỆ THỐNG MÀU SẮC ĐỘC LẬP (ĐẢM BẢO TƯƠNG PHẢN TUYỆT ĐỐI)
   ========================================================================== */

/* Terracotta (Đất nung) */
.bg-terracotta-500 { background-color: #C85A32 !important; }
.bg-terracotta-600 { background-color: #B04A25 !important; }
.bg-terracotta-700 { background-color: #8C4327 !important; }
.bg-terracotta-100 { background-color: #F7E7E0 !important; }
.hover\:bg-terracotta-600:hover { background-color: #B04A25 !important; }
.hover\:bg-terracotta-500:hover { background-color: #C85A32 !important; }
.text-terracotta-500 { color: #C85A32 !important; }
.text-terracotta-600 { color: #B04A25 !important; }
.text-terracotta-700 { color: #8C4327 !important; }
.border-terracotta-500 { border-color: #C85A32 !important; }

/* Ink (Màu mực) */
.bg-ink-900 { background-color: #2C221E !important; }
.text-ink-900 { color: #2C221E !important; }
.text-ink-700 { color: #4A3B34 !important; }
.text-ink-600 { color: #5A4A42 !important; }
.text-ink-500 { color: #6B5B53 !important; }
.text-ink-400 { color: #8E7D74 !important; }
.hover\:text-ink-900:hover { color: #2C221E !important; }

/* Paper (Nền giấy kem) */
.bg-paper-50 { background-color: #FDFBF7 !important; }
.bg-paper-100 { background-color: #FAF6F0 !important; }
.bg-paper-200 { background-color: #F3ECE1 !important; }
.bg-paper-300 { background-color: #E6DCCD !important; }
.hover\:bg-paper-200:hover { background-color: #F3ECE1 !important; }
.hover\:bg-paper-300:hover { background-color: #E6DCCD !important; }
.border-paper-200 { border-color: #F3ECE1 !important; }
.border-paper-300 { border-color: #E6DCCD !important; }

/* Sage (Xanh xô thơm) */
.bg-sage-600 { background-color: #4E6E5D !important; }
.text-sage-600 { color: #4E6E5D !important; }
.bg-sage-100 { background-color: #E5EFE9 !important; }

/* White & Base */
.bg-white { background-color: #FFFFFF !important; }
.text-white { color: #FFFFFF !important; }
.text-paper-50 { color: #FDFBF7 !important; }
.text-paper-100 { color: #FAF6F0 !important; }
.text-paper-200 { color: #F3ECE1 !important; }

/* Tương phản nút bấm Terracotta chuẩn mực */
button.bg-terracotta-500,
a.bg-terracotta-500,
.bg-terracotta-500 {
    color: #FFFFFF !important;
}
button.bg-terracotta-500:hover,
a.bg-terracotta-500:hover {
    color: #FFFFFF !important;
}

/* Nút bộ lọc đang active */
.filter-btn.active,
button.bg-ink-900 {
    background-color: #2C221E !important;
    color: #FFFFFF !important;
}

/* ==========================================================================
   HIỆU ỨNG GÁY SÁCH 3D & CARD
   ========================================================================== */
.book-cover {
    position: relative;
    transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.35s ease;
}

.book-cover::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 12px;
    background: linear-gradient(90deg, rgba(255,255,255,0.28) 0%, rgba(0,0,0,0.18) 35%, rgba(255,255,255,0.12) 70%, transparent 100%);
    z-index: 10;
    pointer-events: none;
    border-top-left-radius: inherit;
    border-bottom-left-radius: inherit;
}

.book-card:hover .book-cover {
    transform: translateY(-6px) rotate(-1deg);
    box-shadow: 8px 16px 26px rgba(44, 34, 30, 0.22);
}

.shadow-book {
    box-shadow: 4px 8px 18px rgba(44, 34, 30, 0.16), -2px 0 4px rgba(255, 255, 255, 0.4) inset !important;
}

.shadow-soft {
    box-shadow: 0 10px 30px -10px rgba(44, 34, 30, 0.08) !important;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: #F3ECE1;
}
::-webkit-scrollbar-thumb {
    background: #D4C5B0;
    border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
    background: #B8A58D;
}

/* ==========================================================================
   THEMES TRÌNH ĐỌC TRUYỆN
   ========================================================================== */
.reader-theme-cream {
    background-color: #FAF6F0 !important;
    color: #2C221E !important;
}
.reader-theme-light {
    background-color: #FFFFFF !important;
    color: #1F2937 !important;
}
.reader-theme-dark {
    background-color: #1C1917 !important;
    color: #E7E5E4 !important;
}

/* Typography Classes Thống Nhất Tuyệt Đối */
.font-serif,
.font-reading {
    font-family: 'Lora', Georgia, serif !important;
}
.font-sans {
    font-family: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
}


/* ==========================================================================
   CUSTOM LOGO STYLES
   ========================================================================== */
.wp-block-site-logo {
    margin: 0 !important;
    display: flex !important;
    align-items: center !important;
}

/* Logo Styling & Dynamic Height */
:root {
    --youstory-logo-height: 45px;
}

.custom-logo-link,
.wp-block-site-logo a.custom-logo-link {
    display: inline-flex !important;
    align-items: center !important;
}

.custom-logo-link img,
.youstory-brand-area img.custom-logo,
.youstory-brand-area .custom-logo,
.wp-block-site-logo img.custom-logo,
img.custom-logo {
    height: var(--youstory-logo-height, 45px) !important;
    max-height: var(--youstory-logo-height, 45px) !important;
    width: auto !important;
    max-width: 100% !important;
    object-fit: contain !important;
    display: inline-block !important;
    transition: transform 0.2s ease;
}

.custom-logo-link:hover img.custom-logo,
.wp-block-site-logo a.custom-logo-link:hover img.custom-logo {
    transform: scale(1.03);
}

/* Tự động ẩn biểu tượng fallback khi đã có Logo tải lên */
.youstory-brand-area:has(.custom-logo) .youstory-fallback-brand,
.youstory-brand-area .custom-logo-link ~ .youstory-fallback-brand,
.youstory-brand-area .wp-block-site-logo:has(.custom-logo) ~ .youstory-fallback-brand {
    display: none !important;
}

/* ==========================================================================
   GIA CỐ HEADER RESPONSIVE & CHỐNG LỖI VỠ LAYOUT / KÉO DÃN (STRETCH)
   ========================================================================== */
header nav a {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
}

/* ==========================================================================
   CÂN BẰNG TUYỆT ĐỐI Ô TÌM KIẾM VÀ NÚT CHUÔNG
   ========================================================================== */
.header-actions {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
}

.search-box-wrapper {
    height: 40px !important;
    min-height: 40px !important;
    max-height: 40px !important;
    display: flex !important;
    align-items: center !important;
    box-sizing: border-box !important;
    background-color: rgba(243, 236, 225, 0.7) !important;
    border: 1px solid #E6DCCD !important;
    border-radius: 9999px !important;
    padding: 0 14px !important;
    position: relative !important;
}

.search-box-wrapper:focus-within {
    background-color: #FFFFFF !important;
    border-color: #C85A32 !important;
    box-shadow: 0 0 0 2px rgba(200, 90, 50, 0.15) !important;
}

.search-box-wrapper input {
    height: 100% !important;
    line-height: normal !important;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
    font-size: 13px !important;
    color: #2C221E !important;
}

.search-box-wrapper svg,
.search-box-wrapper i {
    width: 16px !important;
    height: 16px !important;
    flex-shrink: 0 !important;
    margin-right: 8px !important;
    display: block !important;
    color: #8E7D74 !important;
}

#notifBtn {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    max-width: 40px !important;
    min-height: 40px !important;
    max-height: 40px !important;
    border-radius: 9999px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    margin: 0 !important;
    flex-shrink: 0 !important;
    border: 1px solid #E6DCCD !important;
    background-color: rgba(243, 236, 225, 0.7) !important;
    cursor: pointer !important;
    position: relative !important;
}

#notifBtn:hover {
    background-color: #E6DCCD !important;
}

#notifBtn svg,
#notifBtn i {
    width: 18px !important;
    height: 18px !important;
    display: block !important;
    color: #4A3B34 !important;
}

#notifDot {
    width: 8px !important;
    height: 8px !important;
    position: absolute !important;
    top: 6px !important;
    right: 6px !important;
    border-radius: 9999px !important;
    background-color: #C85A32 !important;
    border: 1.5px solid #FAF6F0 !important;
}

/* ==========================================================================
   CONTAINER HEADER & TOÀN TRANG ĐỒNG BỘ 100% (THẲNG HÀNG TUYỆT ĐỐI)
   ========================================================================== */
.wp-site-blocks,
.wp-block-template-part,
.alignfull.wp-block-template-part,
.youstory-page-content,
.wp-block-post-content,
.entry-content {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

/* Khử triệt để mọi thẻ p và br tự sinh nếu có làm xô lệch flexbox trong Header */
header p,
header p:empty,
.header-actions p {
    display: contents !important;
    margin: 0 !important;
    padding: 0 !important;
}

header nav br {
    display: none !important;
}

/* Đồng bộ max-w-7xl trên toàn bộ Header, Hero, Books, Studio, Author, Footer */
.max-w-7xl {
    max-width: 80rem !important; /* 1280px */
    width: 100% !important;
    margin-left: auto !important;
    margin-right: auto !important;
    box-sizing: border-box !important;
}

/* ==========================================================================
   RESPONSIVE HEADER CHO MOBILE & TABLET
   ========================================================================== */
#mobileMenuDrawer {
    transition: all 0.3s ease;
}

#mobileMenuDrawer.hidden {
    display: none !important;
}

#mobileMenuBtn {
    border-radius: 9999px !important;
}

/* ==========================================================================
   BẢO VỆ LOGO & RESPONSIVE HEADER TRÊN MOBILE
   ========================================================================== */
.youstory-brand-area {
    flex-shrink: 0 !important;
}

.custom-logo-link {
    display: inline-flex !important;
    align-items: center !important;
    flex-shrink: 0 !important;
}

.custom-logo-link img,
img.custom-logo {
    max-height: 44px !important;
    width: auto !important;
    max-width: 160px !important;
    display: block !important;
    object-fit: contain !important;
    flex-shrink: 0 !important;
}

@media (max-width: 639px) {
    /* Ẩn hoàn toàn thanh input search to trên mobile */
    .search-box-wrapper {
        display: none !important;
    }
    /* Hiện nút icon tìm kiếm tròn trên mobile */
    #mobileSearchBtn {
        display: inline-flex !important;
    }
    /* Đảm bảo khoảng cách các nút bên phải */
    .header-actions {
        gap: 0.5rem !important;
        flex-shrink: 0 !important;
    }
    /* Đảm bảo logo hiển thị rõ ràng, không bị chèn ép */
    .youstory-brand-area {
        flex: 0 1 auto !important;
        min-width: 0 !important;
    }
}

@media (min-width: 640px) {
    #mobileSearchBtn {
        display: none !important;
    }
    .search-box-wrapper {
        display: flex !important;
    }
    #mobileSearchBar {
        display: none !important;
    }
}

/* ==========================================================================
   LƯỚI 5 CỘT CHO DANH SÁCH TÁC PHẨM TRÊN DESKTOP (LG >= 1024PX)
   ========================================================================== */
@media (min-width: 1024px) {
    #booksGrid,
    #booksGrid.lg\:grid-cols-5,
    .lg\:grid-cols-5 {
        grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    }
}
