/* ============================================================
   MOBILE — responsive fixes layer
   Loads after styles.css + retro-fx.css + redesign.css and only
   adapts layout for small screens. Desktop is untouched.

   The big one: the header. styles.css forces .site-header__inner
   into a single nowrap flex row with overflow:hidden on the nav,
   which clips the nav links off-screen on phones. Below 760px we
   collapse nav + account cluster into a hamburger-toggled panel.
   ============================================================ */

/* ---------- Hamburger toggle (hidden on desktop) ---------- */

.nav-toggle {
    display: none;
    position: relative;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    cursor: pointer;
    color: var(--pixel-ink, var(--text));
    background: var(--pixel-panel, rgba(255, 255, 255, 0.04));
    border: 2px solid var(--pixel-line-strong, var(--line-strong));
    box-shadow:
        inset 1px 1px 0 var(--rd-edge-light, rgba(255, 255, 255, 0.14)),
        3px 3px 0 var(--rd-shadow, #000);
}

.nav-toggle__bars::before {
    content: "☰";
    font-size: 1.25rem;
    line-height: 1;
}

.site-header.is-menu-open .nav-toggle__bars::before {
    content: "✕";
}

.nav-toggle__dot {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 12px;
    height: 12px;
    border-radius: 999px;
    background: var(--pixel-accent, var(--accent));
    border: 2px solid var(--rd-shadow, #000);
}

@media (max-width: 760px) {

    /* ---------- Header: brand + hamburger row ---------- */

    .site-header__inner {
        flex-wrap: wrap !important;
        gap: 10px !important;
        min-height: 0;
        padding: 10px 0;
    }

    .brand {
        margin-right: auto;
        gap: 10px;
    }

    .brand__mark,
    .brand__logo,
    .brand__logo img {
        width: 42px;
        height: 42px;
    }

    .brand__copy span {
        display: none;
    }

    .nav-toggle {
        display: inline-flex;
    }

    /* Nav + account cluster collapse into the menu panel */
    .site-header .site-nav,
    .site-header .account-cluster {
        display: none !important;
    }

    .site-header.is-menu-open .site-nav {
        display: flex !important;
        flex: 0 0 100%;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        overflow: visible;
        white-space: normal;
        padding: 12px 0 4px;
        border-top: 2px dashed var(--pixel-line-strong, var(--line-strong));
    }

    .site-header.is-menu-open .site-nav a {
        font-size: 0.78rem;
        padding: 13px 14px;
        text-align: center;
    }

    .site-header.is-menu-open .account-cluster {
        display: flex !important;
        flex: 0 0 100%;
        width: 100%;
        flex-wrap: wrap !important;
        justify-content: flex-start;
        gap: 8px;
        margin-left: 0;
        padding: 4px 0 12px;
    }

    /* Inside the open menu there is room — restore the labels that the
       desktop header strips down to icons. */
    .site-header.is-menu-open .account-cluster .account-link--label-hide-md {
        font-size: 0.9rem !important;
        padding: 6px 14px !important;
    }

    .site-header.is-menu-open .account-cluster .account-link--label-hide-md::before {
        margin-right: 8px;
    }

    .site-header.is-menu-open .account-chip__body {
        display: grid !important;
    }

    .site-header.is-menu-open .account-chip {
        padding: 4px 14px 4px 4px !important;
    }
}

/* ---------- Home page: cube + tiles ---------- */

@media (max-width: 760px) {

    /* Stack the mascot above the tiles instead of floating it over their
       center (where it ends up clipped and overlapping the header). */
    .home-cube {
        flex-direction: column;
        align-items: center;
    }

    .home-mascot {
        position: relative;
        top: auto;
        left: auto;
        transform: none;
        width: 150px;
        max-width: 150px;
        min-width: 0;
        margin: 0 auto 16px;
        /* The bob keyframes animate the desktop translate(-50%, -50%)
           centering transform, which drags the mascot 75px up-left out of
           its flow slot here. Animations beat normal declarations, so the
           transform:none above can't win — stop the animation entirely. */
        animation: none;
    }

    /* One tile per row; drop the square aspect that desktop needs. */
    .home-grid {
        width: 100%;
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        aspect-ratio: auto;
    }

    /* Desktop pushes tile content into outer corners with 200px paddings to
       clear the centered mascot — on mobile that leaves no room. Reset. */
    .home-grid .home-tile,
    .home-grid .home-tile:nth-child(1),
    .home-grid .home-tile:nth-child(2),
    .home-grid .home-tile:nth-child(3),
    .home-grid .home-tile:nth-child(4) {
        padding: 20px 18px;
        min-height: 200px;
        align-items: flex-start;
        justify-content: flex-start;
        text-align: left;
    }

    /* The Wiki/Forum buttons sit absolutely in the top corner and overlap
       the tile label — clear space for them and keep them on the right
       (desktop flips them left on even tiles, which collides here). */
    .home-grid .home-tile:has(.home-tile__actions) {
        padding-top: 54px;
    }

    /* :nth-child(n) matches everything — it only raises specificity above
       the desktop :nth-child(odd/even) left-right flip rules. */
    .home-grid > .home-tile:nth-child(n) .home-tile__actions {
        right: 12px;
        left: auto;
        top: 12px;
    }

    /* Same for the download button: always bottom-right. */
    .home-grid > .home-tile:nth-child(n) .home-tile__download {
        right: 12px;
        left: auto;
    }

    /* The "Coming soon" badge loses its absolute corner position to the
       generic .home-tile__link > * rule and stretches full width — keep it
       in flow but shrink it back to a pill. */
    .home-grid .home-tile .home-tile__badge {
        justify-self: start;
        width: fit-content;
    }
}

/* ---------- Small-screen layout fixes ---------- */

@media (max-width: 520px) {

    /* Card grids whose minmax() floors (240–320px) overflow narrow
       phones — force a single column. */
    .settings-grid,
    .profile-activity,
    .admin-grid,
    .admin-ban-grid,
    .member-grid,
    .maps-grid,
    .home-downloads__list {
        grid-template-columns: 1fr;
    }

    .install-stage {
        padding: 32px 0;
    }

    .install-card {
        padding: 24px 18px;
    }

    .rich-editor__emoji-grid {
        grid-template-columns: repeat(6, 1fr);
    }

    .app-modal__card {
        padding: 18px 16px;
    }

    /* Meta rows (views/replies/author chips) must be allowed to wrap. */
    .topic-card__meta,
    .forum-card__stats,
    .community-toolbar {
        flex-wrap: wrap;
    }

    /* Long URLs / unbroken strings in user content must not force
       horizontal scroll. */
    .post-body,
    .blog-body,
    .reply-card__body,
    .topic-body,
    .page-intro,
    .community-hero,
    .message-list__body,
    .profile-bio {
        overflow-wrap: anywhere;
    }
}
