/* CyberForge Arcade — Mobile header & search-popup styles
 *
 * Loaded after styles.css and searchBar.css so its rules win on small screens
 * without `!important` wars. Strategy:
 *
 *   - On wide screens (>640px), keep the existing inline `.filter-bar` and
 *     hide the mobile search trigger + modal.
 *   - On narrow screens (<=640px), hide the inline filter bar entirely and
 *     show a compact magnifier-icon button right next to the Menu button.
 *     Pressing it reveals a centered modal that hosts the `#searchInput`.
 *
 * The four top-level controls (Menu, Search trigger, 🎨 theme toggle, ☰ genres)
 * are anchored individually (existing fixed positions for theme/genres remain),
 * so spacing is enforced by horizontal offsets on each button rather than a
 * flex container — that keeps backward compatibility with the existing layout.
 */

/* -------------------- Mobile search trigger (icon) -------------------- */
.mobile-search-trigger {
    /* Hidden by default; only shown on small screens via the media query
       below. Positioned to sit immediately to the right of .app-menu-button,
       which itself is fixed at top:1rem, left:1rem (see styles.css). */
    display: none;
    position: fixed;
    top: 1rem;
    /* Sits to the right of the Menu button. The Menu button with its label
       runs ~7rem wide on a phone, so anchor the search icon well beyond it
       (with a comfortable gap) so it can't cover the "Menu" text. */
    left: 8.25rem;
    z-index: 60;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.85);
    border: 1px solid var(--primary);
    color: var(--text);
    font-size: 1rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 12px var(--glow-color-40);
    transition:
        background 0.18s ease,
        color 0.18s ease,
        border-color 0.18s ease,
        transform 0.18s ease,
        box-shadow 0.18s ease;
}

.mobile-search-trigger:hover,
.mobile-search-trigger:focus-visible {
    background: var(--primary);
    color: var(--background);
    transform: translateY(-1px);
    box-shadow: 0 0 18px var(--glow-color-60);
    outline: none;
}

.mobile-search-trigger:active {
    transform: translateY(0) scale(0.96);
}

.mobile-search-trigger[aria-expanded="true"] {
    background: var(--primary);
    color: var(--background);
    box-shadow: 0 0 16px var(--glow-color-60);
}

/* -------------------- Mobile search popup -------------------- */
.mobile-search-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.66);
    backdrop-filter: blur(6px);
    z-index: 11000;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: clamp(4rem, 12vh, 6rem) 1rem 1rem;
    opacity: 0;
    transition: opacity 0.22s ease;
}

.mobile-search-overlay.visible {
    display: flex;
    opacity: 1;
}

.mobile-search-modal {
    width: 100%;
    max-width: 520px;
    background: var(--background, #0a0a10);
    border: 1px solid var(--primary, #c0c0c0);
    border-radius: 14px;
    box-shadow:
        0 0 24px var(--glow-color-60, rgba(192, 192, 192, 0.6)),
        0 0 48px var(--glow-color-40, rgba(192, 192, 192, 0.4));
    color: var(--text, #fff);
    overflow: hidden;
    transform: translateY(-12px) scale(0.97);
    opacity: 0;
    transition:
        transform 0.24s cubic-bezier(0.2, 0.7, 0.3, 1.1),
        opacity 0.22s ease;
}

.mobile-search-overlay.visible .mobile-search-modal {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.mobile-search-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem 0.6rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.mobile-search-modal-title {
    font-size: 0.85rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--primary, #c0c0c0);
    text-shadow: 0 0 8px var(--glow-color-40);
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
}

.mobile-search-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--primary, #c0c0c0);
    background: transparent;
    color: var(--text, #fff);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.mobile-search-close:hover,
.mobile-search-close:focus-visible {
    background: var(--primary, #c0c0c0);
    color: var(--background, #000);
    outline: none;
    transform: scale(1.05);
}

.mobile-search-modal-body {
    padding: 0.9rem 1rem 1.1rem;
}

/* When the global #searchInput is re-parented inside the modal,
   give it a flat, full-width modal-friendly look. */
.mobile-search-modal-body .search-wrap {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--primary, #c0c0c0);
    border-radius: 999px;
    overflow: hidden;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.mobile-search-modal-body .search-wrap:focus-within {
    border-color: var(--secondary, #e8e8e8);
    box-shadow: 0 0 0 3px var(--glow-color-40), 0 0 16px var(--glow-color-60);
}

.mobile-search-modal-body .search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--primary, #c0c0c0);
    opacity: 0.85;
    pointer-events: none;
    font-size: 0.95rem;
}

.mobile-search-modal-body input#searchInput {
    flex: 1;
    width: 100%;
    max-width: none;
    border: 0;
    background: transparent;
    color: var(--text, #fff);
    font: inherit;
    font-size: 1rem;
    padding: 0.75rem 3rem 0.75rem 2.65rem;
    margin: 0;
    line-height: 1.2;
    box-shadow: none;
}

.mobile-search-modal-body input#searchInput::placeholder {
    color: var(--primary, #c0c0c0);
    opacity: 0.6;
}

.mobile-search-modal-body input#searchInput:focus {
    outline: none;
    box-shadow: none;
}

.mobile-search-modal-body .search-clear {
    position: absolute;
    right: 0.45rem;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 0;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text, #fff);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.mobile-search-modal-body .search-clear:hover,
.mobile-search-modal-body .search-clear:focus-visible {
    background: var(--primary, #c0c0c0);
    color: var(--background, #000);
    outline: none;
    transform: translateY(-50%) scale(1.05);
}

.mobile-search-modal-body .search-clear[hidden] {
    display: none;
}

.mobile-search-modal-body .search-count {
    display: block;
    margin: 0.55rem 0.4rem 0;
    font-size: 0.78rem;
    opacity: 0.65;
    text-align: right;
    letter-spacing: 0.02em;
}

.mobile-search-modal-body .search-count:empty {
    display: none;
}

/* -------------------- Spacing for the four header anchors -------------------- */
/* These rules apply on every viewport so spacing scales smoothly. The existing
   .menu-toggle (☰) and .theme-toggle (🎨) are absolutely fixed at top:1rem
   right:1rem and top:1rem right:5rem respectively (see styles.css), giving
   them ~4rem of horizontal separation. We keep that on wide screens. */

/* -------------------- Small-screen overrides (<= 640px) -------------------- */
@media (max-width: 640px) {
    /* Show the magnifier next to the Menu button. */
    .mobile-search-trigger {
        display: inline-flex;
    }

    /* Hide the always-visible inline filter bar so it stops eating space. */
    .filter-bar {
        display: none !important;
    }

    /* The grid no longer needs to clear a fixed filter bar; restore normal flow. */
    .games-grid.visible {
        padding-top: clamp(4.75rem, 9vh, 6.5rem) !important;
    }

    /* Tighten the Menu button so the search icon doesn't crowd the label. */
    .app-menu-button {
        padding: 0.5rem 0.75rem !important;
    }

    .app-menu-button-text {
        font-size: 0.78rem !important;
        letter-spacing: 0.08em !important;
    }
}

/* Very narrow screens: keep all four header controls inside 320–360px. */
@media (max-width: 380px) {
    /* Drop the Menu label on the smallest devices, keep just the icon stack. */
    .app-menu-button-text {
        display: none !important;
    }
    .app-menu-button {
        padding: 0.55rem 0.7rem !important;
    }
    /* Pull the search trigger closer to the now-icon-only Menu button. */
    .mobile-search-trigger {
        left: 4.25rem;
        width: 40px;
        height: 40px;
        font-size: 0.95rem;
    }
    /* Theme toggle and Genres toggle live at right:5rem and right:1rem.
       Slightly shrink them to guarantee no overlap on 320px viewports. */
    .theme-toggle,
    .menu-toggle {
        width: 40px !important;
        height: 40px !important;
        font-size: 1.05rem !important;
    }
}

/* Larger phones / small tablets: ensure the inline search bar is still nicely
   centered when it returns. */
@media (min-width: 641px) {
    .mobile-search-trigger,
    .mobile-search-overlay {
        display: none !important;
    }
}

/* Reduced motion: snap rather than animate. */
@media (prefers-reduced-motion: reduce) {
    .mobile-search-overlay,
    .mobile-search-modal {
        transition: none !important;
    }
}
