/*
 * PsyGuild Mobile CSS
 * Tối ưu hoàn toàn cho iOS / Android — mobile-first responsive.
 * Breakpoints: 480 | 640 | 768 | 991
 * ─────────────────────────────────────────────────────────────────────
 */

/* ══════════════════════════════════════════════════════════════════════
   1. GLOBAL MOBILE RESETS & SAFE AREA
   ══════════════════════════════════════════════════════════════════════ */

/* iOS tap highlight xóa — tránh flash xanh khi tap link */
* {
    -webkit-tap-highlight-color: transparent;
}

/* Tránh font inflate trên landscape iOS */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Toàn bộ body: dùng 100dvh thay 100vh để tránh lỗi Safari mobile toolbar */
body {
    min-height: 100dvh;
}

/* ══════════════════════════════════════════════════════════════════════
   2. HEADER — Safe Area + Layout
   ══════════════════════════════════════════════════════════════════════ */

/* Safe area top cho iPhone X / Dynamic Island */
.site-header {
    padding-top: env(safe-area-inset-top, 0px);
}

/* Header inner: co lại padding trên mobile nhỏ */
@media (max-width: 640px) {
    .site-header .header-inner {
        padding: 12px 0 !important;
    }

    .site-logo-text {
        font-size: 1.3rem !important;
        margin: 0;
    }

    /* CTA button trong header: rút ngắn text, đủ touch target */
    .header-cta .psyguild-btn {
        padding: 8px 16px;
        font-size: 0.85rem;
    }
}

/* ══════════════════════════════════════════════════════════════════════
   3. MOBILE NAV V2 (Tailwind + được quản lý qua header.php inline CSS)
   V2 mobile nav = #v2-mobile-drawer + #v2-mobile-drawer-panel
   Breakpoint chuẩn: <1024px (lg:) hiện hamburger, ẩn desktop nav
   ══════════════════════════════════════════════════════════════════════ */

/* Ẩn desktop nav dưới 1024px */
@media (max-width: 1023px) {
    #main-header nav { display: none !important; }
    #main-header .hidden.lg\:flex { display: none !important; }
    #v2-mobile-menu-btn { display: flex !important; }

    /* V2 Drawer safe-area cho iPhone notch */
    #v2-mobile-drawer-panel {
        padding-bottom: env(safe-area-inset-bottom, 16px);
    }
}

/* psy-mobile-menu-list: WP menu trong mobile drawer */
.psy-mobile-menu-list {
    list-style: none !important;
    margin: 0 !important;
    padding: 0.5rem 1.25rem !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    width: 100% !important;
    gap: 0 !important;
}
.psy-mobile-menu-list li {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    list-style: none !important;
    border-bottom: 1px solid rgba(255,255,255,0.06) !important;
}
.psy-mobile-menu-list li:last-child {
    border-bottom: none !important;
}
.psy-mobile-menu-list li a {
    display: flex !important;
    align-items: center !important;
    padding: 0.9rem 0 !important;
    font-size: 1.05rem !important;
    font-weight: 700 !important;
    color: #f1f5f9 !important;
    text-decoration: none !important;
    min-height: 48px !important;
    line-height: 1.4 !important;
    background: transparent !important;
    transition: color 0.2s ease !important;
}
.psy-mobile-menu-list li a:hover,
.psy-mobile-menu-list li.current-menu-item > a {
    color: #00f2fe !important;
}

/* ══════════════════════════════════════════════════════════════════════
   4. HERO BLOCK — Responsive Stack
   ══════════════════════════════════════════════════════════════════════ */

/* Tablet: 2 cột vẫn giữ nhưng thu hẹp padding */
@media (max-width: 991px) {
    .psyguild-hero-layout {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    /* Cột trái hero: giảm padding */
    .psyguild-hero .psyguild-card-dark[style*="padding:48px"],
    .psyguild-hero .psyguild-card-dark[style*="padding: 48px"] {
        padding: clamp(24px, 5vw, 40px) !important;
    }

    /* H1 hero: fluid size */
    .psyguild-hero h1 {
        font-size: clamp(1.8rem, 5vw, 2.8rem) !important;
    }
}

/* Mobile: ẩn cột phải (expert + featured cards) — không đủ chỗ */
@media (max-width: 640px) {
    /* Cột phải của hero grid ẩn trên mobile nhỏ */
    .psyguild-hero .psyguild-hero-layout > div:last-child {
        display: none;
    }

    /* Hero container: 1 cột full width */
    .psyguild-hero-layout {
        grid-template-columns: 1fr;
    }

    /* Hero H1: nhỏ hơn */
    .psyguild-hero h1 {
        font-size: clamp(1.6rem, 6vw, 2.2rem) !important;
        margin-bottom: 16px !important;
    }

    /* Hero desc: cỡ chữ vừa phải */
    .psyguild-hero p {
        font-size: 1rem !important;
        margin-bottom: 24px !important;
    }

    /* Hero actions: stack vertical nếu 2 nút quá chật */
    .hero-actions {
        flex-direction: column;
        gap: 12px !important;
    }
    .hero-actions .psyguild-btn {
        width: 100%;
        justify-content: center;
        padding: 14px 20px;
        font-size: 1rem;
    }
}

/* ══════════════════════════════════════════════════════════════════════
   5. SECTION PADDING — Giảm khoảng cách trên mobile
   ══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* Section padding: gọn hơn trên mobile */
    .section-padding {
        padding-top:    clamp(32px, 6vw, 52px) !important;
        padding-bottom: clamp(32px, 6vw, 52px) !important;
    }

    /* Container padding co lại nhẹ nhàng */
    .psyguild-container {
        padding-left:  clamp(16px, 4.5vw, 24px);
        padding-right: clamp(16px, 4.5vw, 24px);
    }

    /* Hero trên mobile: không cần min-height lớn */
    .psyguild-hero.section-padding {
        min-height: auto !important;
        padding-top:    clamp(36px, 6vw, 56px) !important;
        padding-bottom: clamp(36px, 6vw, 56px) !important;
    }
}

/* ══════════════════════════════════════════════════════════════════════
   6. SERVICES BLOCK — Mobile Layout
   ══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* Services inner card: giảm padding lớn */
    .psyguild-services .psyguild-card-dark {
        padding: clamp(24px, 6vw, 40px) !important;
    }

    /* Services flex: đã wrap, giảm gap */
    .psyguild-services .psyguild-card-dark > div {
        gap: 24px !important;
    }

    /* Services H2: nhỏ hơn */
    .psyguild-services h2 {
        font-size: clamp(1.4rem, 5vw, 1.9rem) !important;
    }

    /* Services bullet grid: 1 cột thay 2 cột */
    .psyguild-services ul {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
}

/* ══════════════════════════════════════════════════════════════════════
   7. COMMUNITY BLOCK — Mobile Layout
   ══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* Community card: giảm padding */
    .psyguild-community .psyguild-card-dark {
        padding: clamp(24px, 6vw, 40px) !important;
    }

    /* Community H2: nhỏ lại */
    .psyguild-community h2 {
        font-size: clamp(1.5rem, 5vw, 2rem) !important;
        margin-bottom: 12px !important;
    }

    /* Community features: wrap thành 1 cột */
    .psyguild-community .psyguild-card-dark > div > div[style*="flex"] {
        flex-direction: column !important;
        gap: 12px !important;
    }

    /* Feature badges: full width */
    .psyguild-community .psyguild-card-dark [style*="padding: 8px 16px"] {
        width: 100%;
        justify-content: center;
    }

    /* CTA button: full width mobile */
    .psyguild-community .psyguild-btn {
        width: 100%;
        justify-content: center;
        padding: 14px 20px !important;
        font-size: 1rem !important;
    }
}

/* ══════════════════════════════════════════════════════════════════════
   8. NEWS HIGHLIGHT & SECTION HEADERS — Mobile
   ══════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
    /* Section header (badge + title + CTA button): stack vertical */
    .psyguild-news-highlight [style*="justify-content: space-between"],
    .psyguild-news-highlight [style*="justify-content:space-between"] {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
    }

    /* Section H2 */
    .psyguild-news-highlight h2 {
        font-size: clamp(1.3rem, 5vw, 1.8rem) !important;
        margin-top: 4px !important;
    }

    /* Grid cards: 1 cột trên mobile nhỏ */
    .psyguild-grid-cards {
        grid-template-columns: 1fr !important;
    }
}

/* ══════════════════════════════════════════════════════════════════════
   9. CATEGORIES TICKER — Mobile Performance
   ══════════════════════════════════════════════════════════════════════ */

/* Grid cards ticker: 1 cột trên mobile nhỏ */
@media (max-width: 640px) {
    .psyguild-categories-ticker .psyguild-grid-cards {
        grid-template-columns: 1fr;
    }
}

/* Tắt ticker animation trên màn rất nhỏ để tiết kiệm pin/GPU */
@media (max-width: 480px) {
    .psy-post-strip-track {
        animation-play-state: paused !important;
        flex-wrap: wrap !important;
        width: 100% !important;
        gap: 12px !important;
    }
    .psy-post-mini {
        width: 100% !important;
    }
    /* Hiện chỉ 3 item đầu tiên */
    .psy-post-mini:nth-child(n+4) {
        display: none !important;
    }
    /* Tắt mask gradient */
    .psy-post-strip {
        -webkit-mask-image: none !important;
        mask-image: none !important;
    }
}

/* ══════════════════════════════════════════════════════════════════════
   10. POST CARDS — Responsive Grid
   ══════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
    /* Post card thumbnail: giảm height */
    .psyguild-post-card .post-thumbnail,
    .psyguild-paper-card .post-thumbnail {
        height: 180px;
    }

    /* Card padding */
    .psyguild-post-card .post-content,
    .psyguild-paper-card .post-content {
        padding: 18px;
    }

    /* Tắt stagger transform (Paper Cards) — tránh layout shift */
    .psyguild-container .psyguild-paper-card:nth-child(even) {
        transform: none !important;
    }
    .psyguild-container .psyguild-paper-card:nth-child(even):hover {
        transform: translateY(-4px) !important;
    }
}

/* ══════════════════════════════════════════════════════════════════════
   11. BUTTONS — Touch Targets (WCAG: min 44×44px)
   ══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .psyguild-btn {
        min-height: 44px;
        padding: 12px 22px;
    }

    /* Pagination: tăng touch target */
    .psyguild-pagination .page-numbers a,
    .psyguild-pagination .page-numbers span {
        width: 44px;
        height: 44px;
    }
}

/* ══════════════════════════════════════════════════════════════════════
   12. SCROLL REVEAL — Mobile Performance
   ══════════════════════════════════════════════════════════════════════ */

/* Trên mobile, giảm blur trong reveal animation (tốn GPU) */
@media (max-width: 768px) {
    .reveal {
        filter: none; /* Tắt blur — dùng opacity + translateY thôi */
        transform: translateY(20px) scale(0.98);
        transition: opacity 0.7s ease, transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
    }
    .reveal.active {
        filter: none;
        transform: translateY(0) scale(1);
    }
}

/* Người dùng chọn "Reduce motion": tắt hoàn toàn animation */
@media (prefers-reduced-motion: reduce) {
    .reveal,
    .reveal.active {
        opacity: 1 !important;
        transform: none !important;
        filter: none !important;
        transition: none !important;
    }

    .psy-post-strip-track {
        animation: none !important;
    }

    .psyguild-ambient-orb {
        animation: none !important;
    }

    .threshold-crack {
        animation: none !important;
    }

    .threshold-mist {
        animation: none !important;
    }
}

/* ══════════════════════════════════════════════════════════════════════
   13. SINGLE POST — Mobile Reading Experience
   ══════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
    /* Reading zone: padding compact hơn */
    .psyguild-reading-zone {
        padding: clamp(24px, 5vw, 40px) clamp(16px, 4vw, 24px) !important;
        border-radius: 24px 24px 0 0 !important;
    }

    /* Entry content: font size đọc được */
    .psyguild-reading-zone .entry-content {
        font-size: 1.05rem !important;
        line-height: 1.85 !important;
    }

    /* Pre/code: scroll ngang tốt */
    .psyguild-reading-zone .entry-content pre {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 16px;
    }

    /* Table: scroll ngang */
    .psyguild-reading-zone .entry-content table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Blockquote: compact hơn */
    .psyguild-reading-zone .entry-content blockquote {
        padding: 20px 18px !important;
        font-size: 1.05rem !important;
        margin: 32px 0 !important;
    }

    /* Cover zone: giảm padding trên nhỏ */
    .psyguild-cover-inner {
        padding: 0 16px 24px !important;
    }

    /* Single CTA section: compact */
    .psyguild-cta-section {
        padding: 32px 20px !important;
    }
    .psyguild-cta-section .psyguild-btn-primary {
        width: 100% !important;
    }
}

/* ══════════════════════════════════════════════════════════════════════
   14. ARCHIVE PAGE — Mobile
   ══════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
    .psyguild-archive-shell {
        padding: 32px 0 !important;
    }

    .psyguild-archive-shell .archive-title {
        font-size: clamp(1.6rem, 6vw, 2.2rem);
    }
}

/* ══════════════════════════════════════════════════════════════════════
   15. FOOTER — Safe Area Bottom
   ══════════════════════════════════════════════════════════════════════ */

footer,
.site-footer {
    /* Safe area handled by animations.css .psyguild-footer */
}

/* ══════════════════════════════════════════════════════════════════════
   16. SOCIAL FLOAT — Mobile Position
   ══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* Social float bar: ẩn mặc định trên mobile (theo setting theme) */
    .psyguild-social-float:not(.show-mobile) {
        display: none !important;
    }

    /* Nếu show: di chuyển xuống bottom, thành horizontal bar */
    .psyguild-social-float.show-mobile {
        position: fixed;
        bottom: env(safe-area-inset-bottom, 0px);
        left: 0;
        right: 0;
        top: auto;
        width: 100%;
        flex-direction: row;
        justify-content: center;
        padding: 8px 16px;
        background: rgba(10, 18, 34, 0.95);
        backdrop-filter: blur(16px);
        border-top: 1px solid var(--psyguild-border-dark);
        border-radius: 0;
        gap: 24px;
        z-index: 900;
    }
}

/* ══════════════════════════════════════════════════════════════════════
   17. AMBIENT ORBS — Hiệu năng Mobile
   ══════════════════════════════════════════════════════════════════════ */

/* Thu nhỏ orb trên mobile để giảm tải GPU */
@media (max-width: 768px) {
    .psyguild-orb-1 {
        width: 80vw;
        height: 40vh;
        filter: blur(50px);
        opacity: 0.2;
    }
    .psyguild-orb-2 {
        width: 90vw;
        height: 50vh;
        filter: blur(50px);
        opacity: 0.15;
    }
}

/* Tắt orbs hoàn toàn trên thiết bị rất nhỏ */
@media (max-width: 480px) {
    .psyguild-ambient-orb {
        display: none;
    }
}

/* ══════════════════════════════════════════════════════════════════════
   18. SEARCH PAGE — Mobile
   ══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* Search form: input dễ dùng hơn */
    .psy-search-input,
    .search-field {
        font-size: 16px !important; /* Tránh iOS auto-zoom khi focus input */
        min-height: 44px;
        flex: 1; /* Input takes up available space */
    }
    
    /* Align Search Form with Flexbox */
    .search-form {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 8px;
        width: 100%;
    }
    
    .search-submit {
        min-height: 44px;
        padding: 0 16px;
        flex-shrink: 0; /* Prevent button from shrinking */
    }
}

/* ══════════════════════════════════════════════════════════════════════
   19. IMAGE HANDLING — Mobile
   ══════════════════════════════════════════════════════════════════════ */

/* Đảm bảo ảnh không tràn container trên mobile */
img {
    max-width: 100%;
    height: auto;
}

/* Tránh ảnh bị kéo giãn */
img[width][height] {
    aspect-ratio: attr(width) / attr(height);
}

/* ══════════════════════════════════════════════════════════════════════
   20. UTILITY — Mobile Visibility
   ══════════════════════════════════════════════════════════════════════ */

.hide-mobile { display: none !important; }
.show-mobile { display: block !important; }
.show-mobile-flex { display: flex !important; }

@media (min-width: 769px) {
    .hide-mobile { display: revert !important; }
    .show-mobile { display: none !important; }
    .show-mobile-flex { display: none !important; }
    .hide-desktop { display: none !important; }
}

/* ══════════════════════════════════════════════════════════════════════
   21. GLOBAL — Ngăn horizontal scroll trên mọi breakpoint
   ══════════════════════════════════════════════════════════════════════ */

html, body {
    overflow-x: hidden !important;
    max-width: 100vw;
}

/* Đảm bảo container không tràn */
.container, .psyguild-container, [class*="max-w-"] {
    max-width: 100%;
    box-sizing: border-box;
}

/* ══════════════════════════════════════════════════════════════════════
   22. ARCHIVE — Sidebar và Main Content order trên mobile
   ══════════════════════════════════════════════════════════════════════ */

/* Trên mobile: sidebar ẩn hoặc collapse xuống dưới content */
@media (max-width: 1023px) {
    /* Archive 2-cột: stack vertical, content trước - sidebar sau */
    .flex.flex-col.lg\\:flex-row.gap-8.items-start > aside {
        order: 2; /* sidebar xuống dưới */
        width: 100% !important;
        position: static !important; /* bỏ sticky */
    }
    .flex.flex-col.lg\\:flex-row.gap-8.items-start > div {
        order: 1; /* content lên trên */
        width: 100% !important;
    }

    /* Archive sidebar: ẩn mặc định, chỉ mở khi có filter button */
    aside.w-full.lg\\:w-1\\/4 {
        display: none;
    }
}

/* Archive grid: 2 cột tablet, 1 cột mobile nhỏ */
@media (max-width: 1023px) and (min-width: 641px) {
    #archive-grid { grid-template-columns: repeat(2, 1fr) !important; }
}
@media (max-width: 640px) {
    #archive-grid { grid-template-columns: 1fr !important; }
}

/* ══════════════════════════════════════════════════════════════════════
   23. SEARCH FORM — Flex layout đúng chuẩn, không vỡ trên mobile
   ══════════════════════════════════════════════════════════════════════ */

/* WP default search form */
.search-form,
form[role="search"] {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    width: 100% !important;
    flex-wrap: nowrap !important;
}
.search-form .search-field,
form[role="search"] input[type="search"],
form[role="search"] input[name="s"] {
    flex: 1 1 auto !important;
    min-width: 0 !important; /* tránh overflow */
    font-size: 16px; /* tránh iOS zoom */
    min-height: 44px;
    box-sizing: border-box;
}
.search-form .search-submit,
form[role="search"] button[type="submit"] {
    flex-shrink: 0 !important;
    min-height: 44px !important;
    min-width: 44px !important;
}

/* ══════════════════════════════════════════════════════════════════════
   24. SINGLE POST V2 — Mobile Container & Typography
   ══════════════════════════════════════════════════════════════════════ */

@media (max-width: 1023px) {
    /* Single post article: padding top giảm (header fixed 64px/80px) */
    .psyguild-v2-single article { padding-top: 5rem !important; }

    /* Hero banner: height nhỏ hơn trên mobile */
    .psyguild-v2-single header.relative.w-full {
        min-height: 35vh !important;
        border-radius: 1.5rem !important;
    }

    /* Sidebar sticky TOC: ẩn trên mobile, chỉ hiện desktop */
    .psyguild-v2-single .lg\\:sticky.lg\\:top-28 {
        display: none !important;
    }

    /* Main content: full width */
    .psyguild-v2-single .lg\\:w-2\\/3,
    .psyguild-v2-single .lg\\:w-3\\/4 {
        width: 100% !important;
    }
}

@media (max-width: 640px) {
    /* Hero h1: kích thước phù hợp mobile */
    .psyguild-v2-single h1 {
        font-size: clamp(1.6rem, 5.5vw, 2.2rem) !important;
        line-height: 1.3 !important;
    }

    /* Container single: padding nhỏ hơn */
    .psyguild-v2-single .container { padding-left: 1rem !important; padding-right: 1rem !important; }

    /* Reading area content: đủ dễ đọc */
    .psyguild-v2-single .entry-content p,
    .psyguild-v2-single .entry-content li {
        font-size: 1.0625rem !important;
        line-height: 1.85 !important;
    }
}

/* ══════════════════════════════════════════════════════════════════════
   25. IMAGES — Tránh tràn container trên mọi thiết bị
   ══════════════════════════════════════════════════════════════════════ */

.entry-content img,
.post-thumbnail img,
article img {
    max-width: 100% !important;
    height: auto !important;
}

