/* ==========================================================================
   Responsive overrides
   Breakpoints: 900px (tablet — sidebar becomes a collapsible drawer)
                600px (small phones — tighter spacing, stacked navbar)
   ========================================================================== */

/* Hidden by default — only shown inside the ≤900px block below.
   Without this, the button becomes a stray flex child of .layout on desktop. */
.filters-toggle {
    display: none;
}

.nav-toggle {
    display: none;
}

@media (max-width: 900px) {
    body {
        font-size: 14px;
    }

    /* ---- Layout / sidebar drawer ---- */
    .layout {
        flex-direction: column;
        padding: 10px;
    }

    .filters-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        background: #333;
        color: #fff;
        border: none;
        border-radius: 8px;
        padding: 12px 14px;
        font-family: inherit;
        font-size: 14px;
        font-weight: bold;
        cursor: pointer;
        box-sizing: border-box;
    }

    .filters-toggle::after {
        content: "▾";
        transition: transform 0.2s ease;
    }

    .filters-toggle[aria-expanded="true"]::after {
        transform: rotate(180deg);
    }

    .sidebar {
        width: 100%;
        padding: 0 4px;
        margin-bottom: 0;
        max-height: 0;
        overflow: hidden;
        box-sizing: border-box;
        transition: max-height 0.3s ease, padding 0.3s ease, margin-bottom 0.3s ease;
    }

    .sidebar.open {
        max-height: 2500px;
        padding: 16px 4px;
        margin-bottom: 20px;
    }

    #sortContainer {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 6px;
    }

    .filter-btn {
        padding: 7px 12px;
        font-size: 13px;
    }

    /* ---- Project cards: same layout as desktop, just scaled down ---- */
    .project-grid {
        gap: 16px;
        margin: 20px 0;
    }

    .project-card {
        max-width: 100%;
    }

    .project-header {
        gap: 10px;
        padding: 10px;
    }

    .project-info {
        padding-right: 84px;
    }

    .project-icon {
        width: 44px;
        height: 44px;
    }

    .project-info h3 {
        font-size: 15px;
        gap: 4px;
        flex-wrap: wrap;
    }

    .project-info h3 span {
        font-size: 12px;
    }

    .project-info p {
        font-size: 12px;
    }

    .project-tags span {
        font-size: 10px;
        padding: 2px 6px;
    }

    .tags-overflow-popup {
        left: 50%;
        top: 50%;
        bottom: auto;
        transform: translate(-50%, -50%);
        max-width: calc(100vw - 60px);
    }

    .tags-overflow-btn:hover .tags-overflow-popup {
        transform: translate(-50%, -50%);
    }

    .card-controls {
        width: 84px;
        padding: 8px;
        gap: 6px;
    }

    .header-buttons {
        gap: 2px;
    }

    .header-button {
        width: 26px;
        height: 26px;
    }

    .chevron-container {
        margin-right: 2px;
    }

    .chevron {
        font-size: 20px;
    }

    /* ---- Version / variant tables: collapse the fixed-width grids into stacked cards ---- */
    .version-row {
        grid-template-columns: 32px 1fr;
        gap: 8px 10px;
        padding: 12px;
    }

    .version-row>span:nth-child(2) {
        margin-top: 0;
    }

    .version-variants {
        grid-column: 1 / -1;
    }

    .variant-row,
    .variant-row.no-loader {
        grid-template-columns: 1fr;
        gap: 4px;
        text-align: left;
        padding: 10px;
        background: #202020;
        border-radius: 8px;
    }

    .download-btn {
        width: 100%;
        box-sizing: border-box;
        text-align: center;
        padding: 8px 0;
    }

    .changelog-box {
        font-size: 13px;
        grid-column: 1 / -1;
    }

    /* ---- Navbar: links collapse behind a hamburger toggle (see nav_toggle.js) ---- */
    .navbar {
        align-items: flex-start;
        height: auto;
        min-height: 64px;
        padding-top: calc(18px + env(safe-area-inset-top, 0px));
        padding-bottom: 10px;
    }

    .nav-slider {
        display: none;
    }

    .nav-left {
        flex-wrap: wrap;
        gap: 0;
    }

    .nav-right {
        gap: 10px;
    }

    .nav-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 34px;
        height: 34px;
        background: transparent;
        border: 2px solid #444;
        border-radius: 8px;
        color: #fff;
        font-size: 18px;
        line-height: 1;
        cursor: pointer;
    }

    .nav-links {
        flex-basis: 100%;
        flex-direction: column;
        gap: 2px;
        max-height: 0;
        overflow: hidden;
        font-size: 14px;
        transition: max-height 0.3s ease;
    }

    .nav-links.open {
        max-height: 400px;
        padding-top: 8px;
    }

    .nav-links a {
        padding: 8px 6px;
        border-radius: 6px;
    }

    .nav-links a:hover {
        background: #2a2a2a;
        transform: none;
    }

    .nav-logo {
        height: 40px;
    }

    .discord-btn {
        width: 34px;
        height: 34px;
        padding: 0;
        justify-content: center;
        gap: 0;
    }

    .discord-btn span {
        display: none;
    }

    .discord-btn img {
        width: 20px;
        height: 20px;
    }

    /* ---- Screenshot modal ---- */
    #modalIframe {
        width: min(90vw, 640px);
        height: auto;
        aspect-ratio: 16 / 9;
    }

    .screenshot-modal img {
        max-width: 92%;
        max-height: 70%;
    }

    .screenshot-modal .close-btn {
        top: 10px;
        right: 10px;
        font-size: 22px;
        padding: 10px 14px;
    }

    .screenshot-modal .nav-btn {
        font-size: 26px;
        padding: 12px 14px;
    }
}

@media (max-width: 600px) {
    /* ---- Navbar ---- */
    .nav-logo {
        height: 34px;
    }

    /* ---- Sidebar fields ---- */
    #searchBox {
        margin-bottom: 12px;
        font-size: 14px;
        width: 100%;
        box-sizing: border-box;
    }

    /* ---- Project cards ---- */
    .project-card {
        font-size: 13px;
    }

    .project-header {
        padding: 8px;
        flex-wrap: wrap;
        align-items: center;
    }

    .project-icon-container {
        order: 1;
    }

    .card-controls {
        order: 2;
        position: static;
        width: auto;
        flex-basis: auto;
        margin-left: auto;
        flex-direction: row;
        justify-content: flex-end;
        align-items: center;
        gap: 10px;
        padding: 0;
    }

    .project-info {
        order: 3;
        flex-basis: 100%;
        width: 100%;
        padding-right: 0;
        margin-top: 8px;
    }

    .project-icon-container {
        flex-direction: row;
        align-items: center;
        gap: 8px;
    }

    .project-date {
        font-size: 9px;
    }

    /* Always show the dates on mobile, not just when the card is expanded.
       margin-top matches .project-card.open .project-dates exactly so nothing
       shifts when the card is toggled open/closed. */
    .project-dates {
        max-height: 60px;
        opacity: 1;
        transform: translateY(0);
        margin-top: 4px;
    }

    .project-icon {
        width: 36px;
        height: 36px;
    }

    .project-info h3 {
        font-size: 14px;
    }

    .header-button {
        width: 26px;
        height: 26px;
    }

    .chevron {
        font-size: 20px;
    }

    /* Center the author popup on the viewport instead of the (often edge-hugging) author name,
       so it can never get cut off on a narrow screen. */
    .author-popup {
        left: 50%;
        top: 50%;
        bottom: auto;
        transform: translate(-50%, -50%) scale(0.95);
        max-width: calc(100vw - 60px);
        padding: 8px;
        gap: 8px;
    }

    .author-popup.visible {
        transform: translate(-50%, -50%) scale(1);
    }

    .author-popup .avatar-container img {
        width: 30px;
        height: 30px;
    }

    .author-popup .discord-btn-small {
        width: 16px;
        height: 16px;
    }

    .author-popup .author-name {
        font-size: 12px;
    }

    .author-popup .role {
        font-size: 10px;
    }

    /* ---- Server status / join popup ---- */
    .server-status {
        font-size: 0.8em;
        flex-wrap: wrap;
    }

    .join-popup {
        min-width: 140px;
        max-width: calc(100vw - 32px);
    }

    /* ---- Creator list (main page) ---- */
    .creator-card {
        min-width: 0;
        width: 100%;
        box-sizing: border-box;
        padding: 12px 16px;
    }
}