/* ============================================================
   CWTB Mobile Responsive — Main Site
   Covers: index, servers, events, gallery, staff, partners
   Device targets:
     • xs  : ≤ 390px  — iPhone SE, older Androids, Pixel 4a
     • sm  : ≤ 430px  — iPhone 14/15/16 Pro Max, Pixel 8 Pro, Galaxy S24
     • md  : ≤ 768px  — tablets / large phones landscape
     • safe-area insets for iPhone notch / Dynamic Island
     • Android Chrome bottom bar compensation
   ============================================================ */

/* ── Safe-area env() support (iPhone notch / Dynamic Island) ── */
:root {
    --safe-top:    env(safe-area-inset-top,    0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left:   env(safe-area-inset-left,   0px);
    --safe-right:  env(safe-area-inset-right,  0px);
}

/* ── Global mobile base ── */
@media (max-width: 768px) {
    html {
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }

    body {
        overflow-x: hidden;
        /* compensate Android Chrome bottom nav bar */
        padding-bottom: var(--safe-bottom);
    }

    /* Prevent horizontal overflow from any child */
    .container,
    main,
    section {
        max-width: 100%;
        overflow-x: hidden;
    }

    /* ── Header / Navigation ── */
    .header {
        padding-top: var(--safe-top);
    }

    .nav-container {
        padding: 0 16px;
        position: relative;
    }

    .navbar {
        padding: 1.1rem 0;
    }

    /* Hide logo on mobile */
    .nav-logo {
        display: none !important;
    }

    /* Show centered title on mobile */
    .nav-mobile-title {
        display: block !important;
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        font-size: 1rem;
        font-weight: 700;
        color: var(--text-primary);
        white-space: nowrap;
        letter-spacing: -0.3px;
        pointer-events: none;
    }

    /* Theme toggle moves to left */
    .theme-toggle {
        position: absolute;
        left: 16px;
        top: 50%;
        transform: translateY(-50%);
        width: 42px;
        height: 42px;
        min-width: 42px;
        font-size: 1.1rem;
        z-index: 2;
    }

    /* Nav actions: only hamburger stays on the right */
    .nav-actions {
        margin-left: auto;
        gap: 0.6rem;
    }

    /* Hide Discord icon on mobile */
    .nav-discord-btn {
        display: none !important;
    }

    /* Show hamburger on mobile, hide inline nav links */
    .menu-toggle {
        display: flex !important;
        width: 42px;
        height: 42px;
        padding: 0;
        font-size: 1.15rem;
    }

    .nav-links-inline {
        display: none !important;
    }

    /* Hero island adjustments */
    .hero-island {
        padding: 32px 20px 28px;
        border-radius: 14px;
    }

    .hero-islands-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .hero-island-card {
        padding: 18px 16px;
    }

    /* Stats bar stacks on mobile */
    .stats-bar-inner {
        gap: 0;
        flex-wrap: wrap;
        justify-content: center;
    }

    .stats-bar-item {
        padding: 12px 24px;
        flex: 1 1 40%;
    }

    .stats-bar-divider {
        display: none;
    }

    .stats-bar-number {
        font-size: 1.6rem;
    }

    /* Full-screen mobile nav overlay */
    .dropdown-nav {
        padding-top: calc(var(--safe-top) + 1rem);
        padding-bottom: calc(var(--safe-bottom) + 1rem);
    }

    .dropdown-link {
        font-size: 1.6rem;
        padding: 0.85rem 1.5rem;
        min-height: 56px;
        display: flex;
        align-items: center;
        justify-content: center;
        -webkit-tap-highlight-color: transparent;
        border-radius: 10px;
        width: 80%;
    }

    .menu-close {
        top: calc(var(--safe-top) + 1rem);
        right: 1.25rem;
        font-size: 1.75rem;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* ── Hero Section ── */
    .hero {
        padding: calc(80px + var(--safe-top)) 16px 60px;
        min-height: 100svh; /* small viewport height — excludes browser UI */
    }

    .hero-container {
        max-width: 100%;
    }

    .hero-badge {
        font-size: 0.8rem;
        padding: 0.4rem 0.85rem;
    }

    .hero h1 {
        font-size: 2.4rem;
        line-height: 1.15;
        margin-bottom: 1rem;
    }

    .hero p {
        font-size: 1.05rem;
        line-height: 1.65;
        margin-bottom: 2rem;
    }

    .hero-buttons {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }

    .hero-buttons .btn {
        width: 100%;
        justify-content: center;
        padding: 0.9rem 1.25rem;
        font-size: 1rem;
        min-height: 48px;
    }

    .hero-stats {
        gap: 1.5rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    .hero-stat-number {
        font-size: 1.6rem;
    }

    .hero-stat-label {
        font-size: 0.8rem;
    }

    /* ── Features Section ── */
    .features-section {
        padding: 60px 0;
    }

    .features-grid {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }

    .feature-card {
        padding: 1.75rem 1.25rem;
    }

    .feature-icon {
        width: 58px;
        height: 58px;
    }

    .feature-icon i {
        font-size: 1.5rem;
    }

    .feature-card h3 {
        font-size: 1.2rem;
    }

    /* ── About Section ── */
    .about-section {
        padding: 60px 0;
    }

    .about-grid {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .about-content-left h2 {
        font-size: 2rem;
    }

    .about-features {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .about-feature {
        font-size: 0.95rem;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }

    .stat-card {
        padding: 1.25rem 1rem;
    }

    .stat-number {
        font-size: 1.75rem;
    }

    .cta-buttons {
        flex-direction: column;
        gap: 0.75rem;
    }

    .cta-buttons .btn {
        width: 100%;
        justify-content: center;
        min-height: 48px;
    }

    /* ── Servers Page ── */
    .servers-section {
        padding: 80px 0 40px;
    }

    .servers-grid {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }

    .server-card {
        padding: 1.5rem 1.25rem;
    }

    .server-card:hover {
        transform: none; /* disable hover lift on touch */
    }

    .server-header {
        gap: 0.85rem;
        margin-bottom: 1.25rem;
    }

    .server-icon {
        width: 52px;
        height: 52px;
    }

    .server-title h3 {
        font-size: 1.25rem;
    }

    .server-actions {
        flex-direction: column;
        gap: 0.6rem;
    }

    .server-actions .btn {
        width: 100%;
        justify-content: center;
        min-height: 46px;
        font-size: 0.95rem;
    }

    .rules-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Patreon banner mobile */
    .patreon-banner {
        padding: 1.5rem 1.25rem;
        margin-top: 2.5rem;
    }

    .patreon-banner-top {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 1.25rem;
        margin-bottom: 1.25rem;
    }

    .patreon-left {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .patreon-text h3 {
        font-size: 1.1rem;
    }

    .patreon-text p {
        font-size: 0.85rem;
    }

    .patreon-btn {
        width: 100%;
        justify-content: center;
        padding: 0.85rem 1.5rem;
    }

    .patreon-perks {
        justify-content: center;
        gap: 0.5rem;
    }

    .patreon-perk {
        font-size: 0.8rem;
        padding: 0.4rem 0.75rem;
    }

    /* ── Events Page ── */
    .events-container {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .event-item {
        padding: 1.25rem;
        gap: 1rem;
        min-height: auto;
    }

    .event-item:hover {
        transform: none;
    }

    .event-date {
        min-width: 52px;
        padding: 8px;
    }

    .event-day {
        font-size: 1.35rem;
    }

    .event-details h4 {
        font-size: 1rem;
    }

    /* Event register button — move below content on mobile */
    .event-item .event-register-btn {
        position: static;
        width: 100%;
        justify-content: center;
        margin-top: 0.75rem;
        min-height: 44px;
    }

    .past-events-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Calendar */
    .calendar-widget {
        padding: 1rem;
    }

    .calendar-grid {
        gap: 3px;
    }

    .calendar-day {
        font-size: 0.8rem;
        border-radius: 4px;
    }

    .calendar-day-header {
        font-size: 0.75rem;
        padding: 6px 0;
    }

    /* Event modal */
    .event-modal-content {
        width: 100%;
        max-width: 100%;
        border-radius: 20px 20px 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 92svh;
        animation: slideUpModal 0.3s ease;
        margin: 0;
        padding-bottom: var(--safe-bottom);
    }

    @keyframes slideUpModal {
        from { transform: translateY(100%); }
        to   { transform: translateY(0); }
    }

    .event-modal {
        align-items: flex-end;
    }

    .event-modal-header {
        padding: 1.5rem 1.25rem 1rem;
        gap: 1rem;
    }

    .event-modal-body {
        padding: 1rem 1.25rem;
    }

    .event-modal-footer {
        padding: 1rem 1.25rem;
        padding-bottom: calc(1rem + var(--safe-bottom));
    }

    /* ── Gallery Page ── */
    .gallery-section {
        padding: 80px 0 40px;
    }

    .gallery-filters {
        gap: 0.6rem;
        margin-bottom: 2rem;
    }

    .filter-btn {
        padding: 7px 14px;
        font-size: 0.875rem;
        min-height: 40px;
    }

    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .gallery-item img {
        max-height: 180px;
        max-width: 100%;
    }

    /* Gallery overlay — always visible on touch (no hover) */
    .gallery-item .gallery-overlay {
        transform: translateY(0);
        background: linear-gradient(to top, rgba(0,0,0,0.75), transparent);
        padding: 1.25rem 1rem 0.75rem;
    }

    .gallery-overlay h3 {
        font-size: 0.85rem;
    }

    /* Upload section */
    .upload-section {
        padding: 1.75rem 1.25rem;
        border-radius: 14px;
    }

    .upload-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .upload-header h3 {
        font-size: 1.4rem;
    }

    .upload-dropzone {
        padding: 1.75rem 1rem;
    }

    /* Lightbox */
    .lightbox-content {
        max-width: 100%;
        padding: 0 8px;
    }

    .lightbox-img {
        max-height: 65svh;
        border-radius: 8px;
    }

    .close-lightbox {
        top: calc(var(--safe-top) + 12px);
        right: 16px;
        font-size: 2rem;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

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

    /* ── Staff Page ── */
    .staff-section {
        padding: 80px 0 40px;
    }

    .staff-grid,
    .staff-grid.owners {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .staff-card {
        padding: 1.25rem;
        gap: 1rem;
    }

    .staff-card:hover {
        transform: none;
    }

    .staff-avatar img {
        width: 68px;
        height: 68px;
    }

    .staff-card.owner .staff-avatar img {
        width: 80px;
        height: 80px;
    }

    .staff-info h3 {
        font-size: 1.1rem;
    }

    .join-staff,
    .become-partner {
        padding: 1.5rem 1rem;
    }

    /* ── Mod Creators ── */
    .mod-creators-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .mod-creator-card {
        padding: 0.75rem 1rem;
    }

    .mod-creator-links {
        display: none;
    }

    /* ── Partners Page ── */
    .partners-section {
        padding: 80px 0 40px;
    }

    .partners-grid {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }

    .partner-card:hover {
        transform: none;
    }

    .partner-logo {
        height: 120px;
    }

    .partner-info h3 {
        font-size: 1.3rem;
    }

    .partner-actions {
        flex-direction: column;
        gap: 0.6rem;
    }

    .partner-actions .btn {
        width: 100%;
        justify-content: center;
        min-height: 46px;
    }

    /* ── Leaderboard ── */
    .leaderboard-section {
        padding: 1.25rem;
        margin-top: 2.5rem;
    }

    .leaderboard-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .leaderboard-header h2 {
        font-size: 1.4rem;
    }

    .leaderboard-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
    }

    .leaderboard-table {
        min-width: 380px;
        font-size: 0.9rem;
    }

    .leaderboard-table th,
    .leaderboard-table td {
        padding: 0.75rem 0.6rem;
    }

    /* ── Footer ── */
    .footer-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 10px 16px;
        padding-bottom: calc(10px + var(--safe-bottom));
    }

    .footer-right {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .footer-copy {
        font-size: 0.75rem;
    }

    /* ── Buttons — global touch improvements ── */
    .btn,
    button {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    .btn:active {
        transform: scale(0.97);
        transition: transform 0.1s ease;
    }

    /* ── Forms — prevent iOS zoom on focus ── */
    input,
    select,
    textarea {
        font-size: 16px !important;
        -webkit-appearance: none;
        appearance: none;
    }

    /* ── Section spacing ── */
    section {
        padding: 60px 0;
    }

    .section-header {
        margin-bottom: 2.5rem;
    }

    .section-title {
        font-size: 2rem;
    }

    .section-tag {
        font-size: 0.8rem;
    }
}

/* ── Extra small — iPhone SE / compact Androids (≤ 390px) ── */
@media (max-width: 390px) {
    .nav-logo span {
        font-size: 0.95rem;
    }

    .hero h1 {
        font-size: 2rem;
    }

    .hero p {
        font-size: 0.95rem;
    }

    .hero-buttons .btn {
        padding: 0.85rem 1rem;
        font-size: 0.95rem;
    }

    .hero-stats {
        gap: 1rem;
    }

    .hero-stat-number {
        font-size: 1.4rem;
    }

    .gallery-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .dropdown-link {
        font-size: 1.4rem;
        width: 90%;
    }

    .feature-card {
        padding: 1.5rem 1rem;
    }

    .server-card {
        padding: 1.25rem 1rem;
    }

    .staff-card {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .staff-socials {
        justify-content: center;
    }

    .partner-stats {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* ── Pixel-specific (Pixel 7/8/9 — 412px wide) ── */
@media (min-width: 391px) and (max-width: 430px) {
    .hero h1 {
        font-size: 2.3rem;
    }

    .features-grid {
        /* Two column on Pixel 7/8/9 if they fit */
        grid-template-columns: 1fr;
    }

    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* ── iPhone 14 Pro / 15 / 16 Dynamic Island (393px, notch 59px) ── */
@media (min-width: 391px) and (max-width: 430px) and (-webkit-device-pixel-ratio: 3) {
    .header {
        /* Dynamic Island adds ~59px at top */
        padding-top: max(var(--safe-top), 0px);
    }

    .hero {
        /* Extra breathing room below Dynamic Island */
        padding-top: max(calc(80px + var(--safe-top)), 105px);
    }

    .dropdown-nav {
        padding-top: max(calc(var(--safe-top) + 1rem), 70px);
    }
}

/* ── Galaxy S series / large Android (≥ 390px, ≤ 430px, pixel ratio 2-3) ── */
@media (min-width: 360px) and (max-width: 430px) and (-webkit-min-device-pixel-ratio: 2) {
    /* Android Chrome gesture nav bar bottom — extra padding */
    body {
        padding-bottom: max(var(--safe-bottom), 16px);
    }

    .footer {
        padding-bottom: max(calc(1rem + var(--safe-bottom)), 1.75rem);
    }
}

/* ── Tablet / landscape phone (431px – 768px) ── */
@media (min-width: 431px) and (max-width: 768px) {
    .hero h1 {
        font-size: 3rem;
    }

    .hero-buttons {
        flex-direction: row;
        justify-content: center;
    }

    .hero-buttons .btn {
        width: auto;
        min-width: 160px;
    }

    .features-grid {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    }

    .about-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .servers-grid {
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    }

    .gallery-grid {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    }

    .staff-grid {
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    }

    .partners-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .events-container {
        grid-template-columns: 1fr;
    }

    .footer-content {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ── Landscape orientation (phones rotated) ── */
@media (max-width: 932px) and (orientation: landscape) and (max-height: 500px) {
    .hero {
        min-height: auto;
        padding: calc(70px + var(--safe-top)) 16px 40px;
    }

    .hero h1 {
        font-size: 2rem;
        margin-bottom: 0.75rem;
    }

    .hero p {
        display: none; /* too cramped in landscape */
    }

    .hero-buttons {
        flex-direction: row;
        margin-bottom: 1.5rem;
    }

    .hero-buttons .btn {
        width: auto;
        min-width: 140px;
    }

    .hero-stats {
        gap: 2rem;
    }

    .dropdown-nav {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.25rem;
        padding: calc(var(--safe-top) + 0.5rem) 1.5rem;
        justify-content: center;
        align-content: center;
    }

    .dropdown-link {
        font-size: 1.1rem;
        width: auto;
        padding: 0.6rem 1.25rem;
    }

    .event-modal-content {
        border-radius: 12px;
        position: relative;
        bottom: auto;
        max-height: 90svh;
    }

    .event-modal {
        align-items: center;
    }
}

/* ── Reduced motion (accessibility) ── */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ── High contrast / forced colors ── */
@media (forced-colors: active) {
    .btn,
    .feature-card,
    .server-card,
    .staff-card {
        forced-color-adjust: auto;
    }
}
