/* ==========================================================================
   Responsive Breakpoints & Layout Adaptations
   Strictly Ordered Descending: 1024px -> 900px -> 880px -> 768px -> 640px -> 480px
   ========================================================================== */

/* Large Tablets and Medium Screens (<= 1024px) */
@media (max-width: 1024px) {
    .footer-top {
        grid-template-columns: 1fr 1fr;
        gap: 2.5rem;
    }

    .showcase-container {
        padding: 0 1.25rem;
    }

    .genhub-app-window {
        max-width: 100%;
    }

    .gh-catalog-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    }

    .gh-profiles-row {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }

    .gh-detail-grid {
        grid-template-columns: 1fr 280px;
        gap: 16px;
    }
}

/* Medium Tablets & Below (<= 900px) */
@media (max-width: 900px) {
    .showcase-container {
        padding: 0 1rem;
        margin: 1.5rem auto 3rem;
    }

    .genhub-app-window {
        height: 700px;
        max-height: 88vh;
        border-radius: 10px;
    }

    /* Hide desktop-only window minimize/maximize/close buttons */
    .genhub-window-controls {
        display: none !important;
    }

    .genhub-titlebar-left {
        width: auto;
    }

    .genhub-titlebar-right {
        width: auto;
        gap: 6px;
    }

    .genhub-titlebar-center {
        flex: 1;
        justify-content: center;
    }

    .genhub-pill-btn {
        padding: 4px 12px;
        font-size: 11.5px;
    }

    .gh-detail-grid {
        grid-template-columns: 1fr;
    }

    .gh-profile-settings-window {
        width: 96% !important;
        max-width: 96% !important;
        height: 92% !important;
        max-height: 92% !important;
    }
}

/* Navigation Collapse (<= 880px) */
@media (max-width: 880px) {
    header {
        padding: 0.75rem 1rem;
    }

    nav {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .mobile-menu-btn {
        display: flex;
    }

    .nav-links {
        display: none; /* Toggled via .mobile-open */
    }

    .nav-links.mobile-open {
        display: flex;
        flex-direction: column;
        width: 100%;
        padding: 1rem 0;
        background: #110924;
        border-top: 1px solid var(--glass-border);
    }
}

/* Tablets and Mobile Landscape (<= 768px) */
@media (max-width: 768px) {
    main {
        padding: 5.5rem 0 3rem;
    }

    .hero-section {
        padding: 2rem 1rem 3rem;
    }

    .hero-title {
        font-size: 2.35rem;
    }

    .hero-subtitle {
        font-size: 1.1rem;
    }

    .cta-group {
        flex-direction: column;
        width: 100%;
    }

    .btn {
        width: 100%;
        justify-content: center;
        padding: 0.95rem 1.25rem;
        min-height: 48px; /* Accessible touch target */
    }

    .btn-primary-content {
        align-items: center;
        text-align: center;
    }

    .hero-logo-backdrop {
        width: 96vw;
        top: -10px;
        opacity: 0.2;
    }

    .ecosystem-logos {
        gap: 1.5rem;
    }

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

    .footer-bottom {
        flex-direction: column;
        text-align: center;
    }

    .genhub-app-window {
        height: 660px;
        max-height: 90vh;
        border-radius: 10px;
    }

    .gh-table-container,
    .gh-map-datagrid-wrap {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Downloads: horizontal chip carousel for publishers on tablet/mobile */
    .gh-downloads-view {
        flex-direction: column !important;
        height: 100% !important;
        overflow: hidden !important;
    }

    .gh-publishers-sidebar {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        flex: 0 0 auto !important;
        height: auto !important;
        border-right: none !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
        padding: 8px 12px !important;
    }

    .gh-publishers-header {
        display: none !important;
    }

    .gh-publishers-list {
        display: flex !important;
        flex-direction: row !important;
        gap: 6px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
        padding-bottom: 2px !important;
    }

    .gh-publishers-list::-webkit-scrollbar {
        display: none !important;
    }

    .gh-pub-btn {
        flex: 0 0 auto !important;
        width: auto !important;
        padding: 5px 12px !important;
        border-radius: 20px !important;
        background: #181826 !important;
        border: 1px solid rgba(255, 255, 255, 0.08) !important;
    }

    .gh-pub-btn img {
        width: 18px !important;
        height: 18px !important;
        min-width: 18px !important;
        max-width: 18px !important;
    }

    .gh-pub-btn span {
        font-size: 11.5px !important;
    }

    .gh-manifest-folder-btn {
        display: none !important;
    }

    .gh-downloads-main {
        flex: 1 !important;
        min-height: 0 !important;
        overflow: hidden !important;
    }

    .gh-downloads-topbar {
        padding: 10px 14px !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
    }

    .gh-downloads-pub-info h3 {
        font-size: 14px !important;
    }

    .gh-downloads-pub-info p {
        font-size: 11px !important;
    }

    .gh-downloads-controls {
        width: 100% !important;
        display: flex !important;
        gap: 6px !important;
    }

    .gh-downloads-search-wrap {
        flex: 1 !important;
    }

    .gh-downloads-search-wrap .gh-downloads-search {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .gh-catalog-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)) !important;
        padding: 12px 14px 60px !important;
        gap: 12px !important;
    }

    /* Tools: horizontal carousel on tablet/mobile */
    .gh-tools-view {
        flex-direction: column !important;
        height: 100% !important;
        overflow: hidden !important;
    }

    .gh-tools-sidebar {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        flex: 0 0 auto !important;
        height: auto !important;
        border-right: none !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
        padding: 8px 12px !important;
    }

    .gh-tools-sidebar-top,
    .gh-tools-sidebar-bottom {
        display: none !important;
    }

    .gh-tools-list {
        display: flex !important;
        flex-direction: row !important;
        gap: 6px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
        padding-bottom: 2px !important;
    }

    .gh-tools-list::-webkit-scrollbar {
        display: none !important;
    }

    .gh-tool-item {
        flex: 0 0 auto !important;
        width: auto !important;
        padding: 5px 12px !important;
        border-radius: 20px !important;
        background: #181826 !important;
        border: 1px solid rgba(255, 255, 255, 0.08) !important;
        font-size: 11.5px !important;
    }

    .gh-tools-main {
        flex: 1 !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        padding: 12px !important;
    }

    .gh-replay-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
    }

    .gh-replay-import-bar {
        width: 100% !important;
        min-width: 0 !important;
    }

    .gh-replay-actions {
        width: 100% !important;
        justify-content: space-between !important;
    }

    .gh-replay-action-bar {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
    }

    .gh-replay-action-left,
    .gh-replay-action-right {
        flex-wrap: wrap !important;
        justify-content: space-between !important;
    }

    /* Content Detail View */
    .gh-detail-view {
        padding: 12px !important;
        gap: 12px !important;
    }

    .gh-detail-banner-card {
        flex-direction: column !important;
        align-items: flex-start !important;
    }

    /* Settings & Info Views */
    .gh-settings-view,
    .gh-info-view {
        flex-direction: column !important;
        height: 100% !important;
        min-height: 0 !important;
        flex: 1 1 auto !important;
        overflow: hidden !important;
    }

    .gh-settings-sidebar {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        flex: 0 0 auto !important;
        border-right: none !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
        padding: 8px 12px !important;
        flex-direction: row !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
    }

    .gh-settings-sidebar::-webkit-scrollbar {
        display: none !important;
    }

    .gh-settings-title {
        display: none !important;
    }

    .gh-settings-nav-list {
        display: flex !important;
        flex-direction: row !important;
        gap: 6px !important;
    }

    .gh-setting-nav-btn {
        flex: 0 0 auto !important;
        width: auto !important;
        padding: 5px 12px !important;
        border-radius: 20px !important;
        font-size: 11.5px !important;
    }

    /* Info Tab Responsive: Dedicated Mobile Header Controls & Fluid Touch Scroll */
    .gh-info-sidebar {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        flex: 0 0 auto !important;
        align-self: auto !important;
        border-right: none !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
        padding: 8px 12px 6px !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 6px !important;
        overflow: visible !important;
        background: #12121c !important;
        box-sizing: border-box !important;
    }

    .gh-info-module-select-wrap {
        width: 100% !important;
        margin-bottom: 0 !important;
        flex: 0 0 auto !important;
    }

    #ghInfoModuleSelect {
        width: 100% !important;
        min-height: 34px !important;
        padding: 6px 30px 6px 10px !important;
        font-size: 12px !important;
    }

    .gh-info-nav-list {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x !important;
        scrollbar-width: none !important;
        gap: 6px !important;
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 auto !important;
        height: auto !important;
        min-height: 34px !important;
        padding-bottom: 2px !important;
        box-sizing: border-box !important;
    }

    .gh-info-nav-list::-webkit-scrollbar {
        display: none !important;
    }

    .gh-info-nav-btn {
        flex: 0 0 auto !important;
        width: auto !important;
        height: auto !important;
        min-height: 28px !important;
        max-height: 34px !important;
        white-space: nowrap !important;
        padding: 5px 12px !important;
        border-radius: 20px !important;
        font-size: 11.5px !important;
        line-height: 1.2 !important;
        box-sizing: border-box !important;
        align-self: center !important;
    }

    .gh-settings-content,
    .gh-info-content {
        padding: 12px 14px 60px !important;
        flex: 1 1 auto !important;
        min-height: 0 !important;
        height: auto !important;
        max-height: none !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior-y: contain !important;
        touch-action: pan-y !important;
        box-sizing: border-box !important;
    }

    .gh-info-card {
        padding: 14px 14px !important;
    }

    .gh-info-card-header {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }

    .gh-info-card-header h4 {
        font-size: 13.5px !important;
        line-height: 1.4 !important;
    }

    .gh-info-expand-btn {
        min-height: 30px !important;
        padding: 5px 0 !important;
        display: inline-flex !important;
        align-items: center !important;
    }

    .gh-info-detailed-content {
        padding: 10px 12px !important;
        font-size: 12px !important;
        line-height: 1.55 !important;
        overflow-wrap: break-word !important;
        overflow-wrap: anywhere !important;
    }

    .gh-info-detailed-content ul {
        padding-left: 18px !important;
        margin: 6px 0 !important;
    }

    .gh-workspace-demo-grid {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }

    .gh-demo-wrapper {
        padding: 14px 12px !important;
        margin-bottom: 14px !important;
    }
}

/* Mobile Phones (<= 640px) */
@media (max-width: 640px) {
    .showcase-container {
        padding: 0 0.5rem;
    }

    .genhub-app-window {
        height: 640px;
        max-height: 92vh;
        border-radius: 8px;
    }

    .genhub-titlebar {
        height: auto;
        min-height: 42px;
        flex-wrap: wrap;
        padding: 8px 10px;
        row-gap: 8px;
    }

    .genhub-titlebar-left {
        order: 1;
        flex: 1;
    }

    .genhub-titlebar-right {
        order: 2;
    }

    .genhub-titlebar-center {
        order: 3;
        width: 100%;
        display: flex;
    }

    .genhub-pill-nav {
        width: 100%;
        display: flex;
        justify-content: space-between;
    }

    .genhub-pill-btn {
        flex: 1;
        text-align: center;
        padding: 6px 4px;
        font-size: 11px;
    }

    .genhub-statusbar {
        padding: 0 10px;
        font-size: 10px;
    }

    .genhub-sb-right {
        font-size: 9.5px;
    }

    /* Game Profiles */
    .gh-profiles-view {
        padding: 12px 10px;
    }

    .gh-profiles-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        margin-bottom: 12px;
    }

    .gh-profiles-titles h2 {
        font-size: 16px;
    }

    .gh-profiles-titles p {
        font-size: 11px;
    }

    .gh-scan-btn {
        width: 100%;
        justify-content: center;
        padding: 8px;
    }

    .gh-profiles-row {
        grid-template-columns: 1fr !important;
        gap: 12px;
        padding: 0 0 40px;
    }

    .gh-profile-card {
        height: 200px;
    }

    /* On touch screens, show action buttons directly without requiring hover */
    .gh-card-actions-bar {
        opacity: 1 !important;
        transform: translateY(0) !important;
        pointer-events: auto !important;
    }

    /* Downloads catalog 1 column on phone */
    .gh-catalog-grid {
        grid-template-columns: 1fr !important;
        padding: 10px 10px 60px !important;
    }

    /* Modals */
    .gh-modal-backdrop {
        padding: 8px;
    }

    .gh-modal-window {
        max-height: 96%;
        border-radius: 8px;
    }

    .gh-sel-header,
    .gh-wizard-header,
    .gh-edit-header {
        padding: 12px 14px;
    }

    .gh-sel-body,
    .gh-wizard-body,
    .gh-edit-body {
        padding: 12px 14px;
    }

    .gh-sel-grid {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }

    .gh-sel-card {
        height: 170px;
    }

    .gh-profile-settings-window {
        width: 100% !important;
        height: 98% !important;
        max-width: 100% !important;
        max-height: 98% !important;
        border-radius: 8px;
    }

    .gh-win-nav-bar {
        height: auto;
        padding: 8px;
        gap: 6px;
        overflow-x: auto;
        justify-content: flex-start;
        -webkit-overflow-scrolling: touch;
    }

    .gh-win-nav-btn {
        width: 50px;
        height: 46px;
        flex-shrink: 0;
    }

    .gh-win-header {
        padding: 0 12px;
    }

    .gh-notification-flyout {
        top: 48px;
        left: 8px;
        right: 8px;
        width: auto;
        max-width: none;
    }

    .gh-general-settings-grid {
        flex-direction: column !important;
    }

    .gh-sub-sidebar {
        width: 100% !important;
        flex-direction: row !important;
        overflow-x: auto !important;
        padding-bottom: 8px !important;
    }

    .gh-card-hover {
        opacity: 1 !important;
        pointer-events: auto !important;
    }

    /* Info Tab Responsive: Mobile 640px */
    .gh-info-content {
        padding: 10px 12px 50px !important;
        gap: 12px !important;
    }

    .gh-info-page-header h2 {
        font-size: 17px !important;
    }

    .gh-info-page-header p {
        font-size: 11.5px !important;
    }
}

/* Small Mobile Phones (<= 480px) */
@media (max-width: 480px) {
    .hero-title {
        font-size: 1.95rem;
    }

    .hero-subtitle {
        font-size: 1rem;
    }

    .version-badge {
        font-size: 0.75rem;
        padding: 0.35rem 0.8rem;
    }

    .platform-info {
        gap: 0.75rem;
    }

    .platform-badge {
        font-size: 0.775rem;
        padding: 0.25rem 0.6rem;
    }

    .stats-tooltip {
        width: min(340px, calc(100vw - 32px)) !important;
    }

    .genhub-app-window {
        height: 600px;
        max-height: 94vh;
    }

    .gh-content-card {
        min-height: 290px;
    }

    .gh-content-banner {
        height: 80px;
    }

    .gh-action-btn,
    .gh-btn-secondary {
        font-size: 11.5px;
    }

    .gh-content-title {
        font-size: 13px;
    }

    .gh-content-desc {
        font-size: 11px;
    }

    .gh-content-editor-toolbar {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    /* Info Tab Responsive: Small Mobile 480px */
    .gh-info-sidebar {
        padding: 6px 10px 4px !important;
        gap: 5px !important;
    }

    .gh-info-content {
        padding: 8px 10px 45px !important;
        gap: 10px !important;
    }

    .gh-info-card {
        padding: 12px 10px !important;
    }

    .gh-info-card-header h4 {
        font-size: 13px !important;
    }

    .gh-info-card p {
        font-size: 12px !important;
    }

    .gh-demo-wrapper {
        padding: 12px 10px !important;
    }

    .gh-demo-wrapper .gh-profile-card {
        width: 100% !important;
        max-width: 260px !important;
        height: 320px !important;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    :root {
        --glass-bg: rgba(15, 20, 45, 0.95);
        --glass-border: rgba(99, 102, 241, 0.6);
        --text-muted: #cbd5e1;
    }
}
