/* ===== Mobile layout (phones & small tablets) ===== */

@media (max-width: 900px) {
    .container {
        padding-left: 14px;
        padding-right: 14px;
    }

    header {
        padding: 12px 0;
        padding-top: calc(12px + env(safe-area-inset-top, 0px));
    }

    nav {
        flex-wrap: nowrap;
        gap: 8px;
    }

    .logo-img {
        height: 32px;
        max-width: 110px;
    }

    .nav-links {
        display: none !important;
    }

    .header-user-bar {
        display: flex !important;
        align-items: center;
        gap: 8px;
        margin-left: auto;
        flex-shrink: 0;
    }

    .header-player-stats {
        display: none;
    }

    .header-notif-panel {
        position: fixed;
        top: auto;
        bottom: calc(76px + env(safe-area-inset-bottom, 0px));
        left: 12px;
        right: 12px;
        width: auto;
        max-height: min(55vh, 420px);
        z-index: 10080;
        box-shadow: 0 -12px 48px rgba(0, 0, 0, 0.55);
    }

    .header-notif-panel-mobile {
        animation: headerNotifSheetIn 0.28s ease;
    }

    .header-notif-backdrop:not([hidden]) {
        display: block;
    }

    body.header-notif-mobile-open {
        overflow: hidden;
    }

    .gq-toast {
        top: calc(12px + env(safe-area-inset-top, 0px));
        left: 12px;
        right: 12px;
        max-width: none;
        text-align: center;
    }

    .coop-invite-toast {
        top: auto;
        bottom: calc(76px + env(safe-area-inset-bottom, 0px));
        left: 12px;
        right: 12px;
        max-width: none;
        z-index: 10075;
    }

    body {
        padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    }

    body.settings-page-open,
    body.modal-scroll-lock,
    body.friend-page-open {
        padding-bottom: 0;
    }

    .hero-row {
        padding: 24px 0 20px;
        gap: 20px;
    }

    .hero h1 {
        font-size: 28px;
    }

    .hero p {
        font-size: 14px;
        margin-bottom: 20px;
    }

    .hero-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .hero-cta,
    .hero-login-btn {
        width: 100%;
        justify-content: center;
    }

    .profile-layout,
    .quests-layout,
    .leaderboard-container {
        flex-direction: column;
        gap: 16px;
    }

    .friends-sidebar,
    .profile-main,
    .challenges-sidebar,
    .quests-filters,
    .filters-sidebar {
        width: 100%;
        height: auto;
        max-height: none;
        min-height: 0;
    }

    .profile-main {
        order: 1;
    }

    .friends-sidebar {
        order: 2;
        max-height: none;
    }

    .challenges-sidebar {
        order: 3;
    }

    .profile-header {
        max-height: none;
        overflow: visible;
    }

    .profile-hero-banner {
        min-height: auto;
    }

    .profile-hero-content {
        padding: 16px 16px 18px;
    }

    .profile-header-top {
        gap: 14px;
    }

    .profile-bio-block {
        margin-top: 12px;
    }

    .profile-avatar {
        width: 72px;
        height: 72px;
        font-size: 36px;
    }

    .profile-name {
        font-size: 24px !important;
        word-break: break-word;
    }

    .profile-level,
    .profile-xp {
        font-size: 12px;
    }

    .quests-filters {
        position: static;
        top: auto;
    }

    .quests-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
    }

    .quest-card {
        min-width: 0;
    }

    .challenges-sidebar-compact {
        height: auto;
        max-height: none;
    }

    .quest-modal {
        padding: 0;
        align-items: stretch;
    }

    .quest-modal-content {
        max-width: none;
        width: 100%;
        max-height: 100dvh;
        height: 100dvh;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .quest-modal-header {
        padding: 16px;
    }

    .quest-modal-body {
        padding: 16px;
    }

    .auth-modal-content,
    .achievements-modal-content {
        width: calc(100vw - 20px) !important;
        max-height: calc(100dvh - 24px) !important;
    }

    .friends-page .friends-panel {
        min-height: 0;
    }

    .friends-page .friends-panel-body {
        min-height: 0;
    }

    .fm-list {
        max-height: none;
    }

    .add-friend-btn {
        padding: 10px 12px;
        font-size: 12px;
    }

    .friend-search-results {
        max-height: min(240px, 40vh);
    }

    .guestbook-section,
    .profile-section {
        min-width: 0;
    }

    .profile-social-list {
        flex-wrap: wrap;
    }

    .quests-stats-list {
        min-width: 0;
    }
}

@media (max-width: 520px) {
    .quests-grid {
        grid-template-columns: 1fr;
    }

    .player-row,
    .table-header {
        grid-template-columns: 40px 1fr 72px;
        gap: 8px;
        padding: 10px 8px;
    }

    /* На телефоне показываем только #, игрока и XP */
    .player-row > :nth-child(n+4),
    .table-header > :nth-child(n+4) {
        display: none;
    }

    .settings-social-row {
        grid-template-columns: 1fr;
    }

    .save-buttons {
        flex-direction: column;
    }

    .save-buttons .save-btn,
    .save-buttons .cancel-btn {
        width: 100%;
    }

    #settings-page .settings-avatar-actions {
        grid-template-columns: 1fr;
    }

    .coop-friend-row,
    .coop-lobby-roster {
        flex-wrap: wrap;
    }
}

/* Bottom navigation */
.mobile-bottom-nav {
    display: none;
}

@media (max-width: 900px) {
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        z-index: 10050;
        align-items: stretch;
        justify-content: space-around;
        gap: 4px;
        padding: 8px 6px;
        background: rgba(0, 0, 0, 0.3);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.15);
        border-radius: 14px;
        box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
    }

    body.settings-page-open .mobile-bottom-nav,
    body.modal-scroll-lock .mobile-bottom-nav {
        display: none;
    }

    .mobile-nav-link {
        flex: 1;
        min-width: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        padding: 10px 4px 12px;
        border: none;
        background: transparent;
        color: rgba(255, 255, 255, 0.5);
        text-decoration: none;
        font-size: 11px;
        font-weight: 500;
        line-height: 1.2;
        border-radius: 10px;
        cursor: pointer;
        font-family: inherit;
        -webkit-tap-highlight-color: transparent;
        white-space: nowrap;
        transition: color 0.25s;
    }

    .mobile-nav-link.active {
        color: #fff;
        font-weight: 700;
        background: transparent;
    }

    .mobile-nav-link.active::after {
        content: '';
        position: absolute;
        left: 18%;
        right: 18%;
        bottom: 5px;
        height: 2px;
        background: #fff;
        border-radius: 2px;
        box-shadow: 0 0 10px rgba(255, 255, 255, 0.4);
    }

    .mobile-nav-link.nav-auth-only {
        display: none;
    }

    body.is-authenticated .mobile-nav-link.nav-auth-only {
        display: flex;
    }

    .mobile-nav-login {
        display: flex;
    }

    body.is-authenticated .mobile-nav-login {
        display: none !important;
    }

    .quest-play-page,
    .community-quest-page {
        padding: 20px 0 calc(88px + env(safe-area-inset-bottom, 0px));
    }

    .cq-page-title {
        font-size: 22px;
    }

    .cq-play-card,
    .cq-editor-card {
        padding: 18px 16px;
        border-radius: 12px;
    }

    .cq-page-foot,
    .quest-results-actions {
        flex-direction: column;
    }

    .cq-page-foot .quest-results-btn,
    .quest-results-actions .quest-results-btn {
        width: 100%;
    }
}
