/**
 * OriginRealm — Mobile layout fixes
 * Loaded last so it wins over grid-fix / spinning-border / style.css
 */

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    overflow-x: hidden;
    max-width: 100vw;
}

img {
    max-width: 100%;
    height: auto;
}

/* ---------- Header ---------- */
@media (max-width: 900px) {
    .header-container {
        gap: 0.5rem 0.65rem;
        padding: 0 0.85rem;
        flex-wrap: wrap;
        align-items: center;
    }

    .logo {
        font-size: 1.05rem;
        gap: 0.45rem;
    }

    .logo img {
        height: 40px !important;
        width: 40px !important;
    }

    .header-actions,
    .auth-buttons {
        gap: 0.4rem;
        position: relative;
        z-index: 2;
    }

    .hamburger {
        display: flex !important;
        order: 4;
        z-index: 1100 !important;
        pointer-events: auto !important;
    }

    .btn-donate,
    .btn-login,
    .auth-buttons .btn {
        padding: 0.4rem 0.7rem !important;
        font-size: 0.8rem !important;
        white-space: nowrap;
    }

    .search-bar {
        order: 6 !important;
        width: 100%;
        max-width: none !important;
        flex: 1 1 100%;
        margin: 0.25rem 0 0;
        position: relative;
        z-index: 1;
    }

    .search-form,
    .search-input {
        width: 100%;
    }

    .profile-avatar {
        width: 36px !important;
        height: 36px !important;
    }

    header nav,
    header .site-nav {
        order: 5;
        z-index: 1050;
    }
}

@media (max-width: 480px) {
    header {
        padding: 0.75rem 0;
        min-height: auto;
    }

    .btn-donate {
        display: none; /* keep header clean; Donate still in footer */
    }

    .hamburger {
        margin-left: 0.15rem;
    }
}

/* ---------- Homepage / browse grids ---------- */
@media (max-width: 768px) {
    .featured-slider {
        padding: 0 0.75rem !important;
        margin: 1rem auto !important;
        overflow: hidden !important;
        max-width: 100% !important;
        width: 100% !important;
        box-sizing: border-box;
    }

    .slide {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 1rem !important;
        padding: 1rem !important;
        text-align: left !important;
        min-width: 0 !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }

    .slide-cover {
        width: 120px !important;
        height: 170px !important;
        max-width: 40vw;
        margin: 0 auto;
        flex-shrink: 0;
    }

    .slide-info {
        min-width: 0 !important;
        width: 100% !important;
        text-align: left !important;
    }

    .slide-info h2 {
        font-size: 1.25rem !important;
        line-height: 1.3;
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    .slider-controls {
        display: none !important;
    }

    .section {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .section-header {
        padding: 0 0.25rem;
        gap: 0.5rem;
    }

    .site-footer-inner {
        grid-template-columns: 1fr !important;
        gap: 2rem !important;
        padding: 0 1rem 2.5rem !important;
    }

    .site-footer-brand {
        grid-column: auto !important;
        max-width: none !important;
    }

    .grid,
    .series-grid,
    .promo-grid,
    .groups-grid,
    .promoted-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.75rem !important;
        padding: 0 0.75rem !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        margin: 1rem auto !important;
    }

    .card,
    .series-card,
    .promo-card,
    .group-card,
    .promoted-card {
        min-width: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        overflow: hidden !important;
        box-sizing: border-box;
    }

    /* Spinning border was forcing overflow:visible and blowing card width */
    .grid .card,
    .grid .series-card,
    .series-grid .card,
    .series-grid .series-card {
        overflow: hidden !important;
    }

    .grid .card::before,
    .grid .series-card::before,
    .series-grid .card::before,
    .series-grid .series-card::before {
        inset: 0 !important;
        border-radius: 8px;
        pointer-events: none;
    }

    .card-cover,
    .card-image,
    .series-card img,
    .promo-card-image,
    .promoted-card .card-cover,
    .cover-crop-wrapper,
    .cover-crop-wrapper-profile {
        height: auto !important;
        aspect-ratio: 2 / 3;
        width: 100% !important;
        object-fit: cover !important;
        object-position: center top !important;
        max-height: none;
    }

    .cover-crop-wrapper,
    .cover-crop-wrapper-profile {
        overflow: hidden !important;
    }

    .cover-crop-wrapper img,
    .cover-crop-wrapper-profile img {
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        height: 100% !important;
        width: 100% !important;
        object-fit: cover !important;
    }

    .card-body,
    .series-info {
        padding: 0.65rem !important;
        min-width: 0;
    }

    .card-title,
    .series-card .series-title,
    .card .series-title,
    .promo-card-title,
    .group-card-title,
    .promoted-card .card-title {
        font-size: 0.82rem !important;
        line-height: 1.25 !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden !important;
        white-space: normal !important;
        word-break: break-word;
        margin-bottom: 0.35rem !important;
    }

    .card-meta {
        font-size: 0.72rem !important;
        gap: 0.25rem;
        flex-wrap: wrap;
    }

    .type-badge {
        font-size: 0.65rem !important;
        padding: 0.15rem 0.45rem !important;
    }

    .channels-grid {
        grid-template-columns: 1fr !important;
        padding: 0 0.75rem !important;
    }
}

@media (max-width: 380px) {
    .grid,
    .series-grid,
    .promo-grid,
    .groups-grid,
    .promoted-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.55rem !important;
        padding: 0 0.5rem !important;
    }

    .grid .card-title,
    .series-card .series-title,
    .card .series-title,
    .promo-card-title,
    .group-card-title {
        font-size: 0.75rem !important;
    }
}

/* ---------- Series detail page ---------- */
.series-detail-shell,
.series-detail-layout {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.series-detail-cover-col {
    min-width: 0;
}

.series-detail-meta-col {
    min-width: 0;
}

@media (max-width: 900px) {
    .series-detail-outer {
        padding: 0 0.75rem !important;
        margin: 1rem auto !important;
    }

    .series-detail-shell.series-detail-layout,
    .series-detail-layout {
        flex-direction: column !important;
        gap: 1.25rem !important;
        padding: 1rem !important;
        align-items: stretch !important;
    }

    .series-detail-cover-col {
        width: 100% !important;
        max-width: 240px;
        margin: 0 auto;
    }

    .series-detail-meta-col {
        width: 100% !important;
        gap: 1rem !important;
    }

    .series-detail-page .series-title,
    h1.series-title {
        font-size: 1.35rem !important;
        line-height: 1.3 !important;
        word-break: break-word;
        overflow-wrap: anywhere;
        max-width: 100%;
    }

    #alt-title-bar {
        max-width: 100% !important;
        flex-wrap: wrap;
    }

    #alt-title-primary {
        white-space: normal !important;
        max-width: 100% !important;
    }

    .series-info-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.75rem !important;
        padding-right: 2rem !important;
    }

    .series-info-grid > div {
        min-width: 0;
        overflow-wrap: anywhere;
    }

    /* Tags must wrap, not clip */
    .series-tags,
    .tag-list,
    [class*="tags"] {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 0.4rem !important;
        max-width: 100%;
    }

    .series-tags a,
    .series-tags span,
    .tag-pill,
    .tag {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Prev/next arrows: don't cover content on phones */
    .nav-btn,
    .nav-btn-disabled {
        display: none !important;
    }

    .series-actions-row,
    .action-buttons {
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
    }

    .series-actions-row .action-btn,
    .action-buttons a,
    .action-buttons button {
        flex: 1 1 auto;
        text-align: center;
        padding: 0.65rem 0.85rem !important;
        font-size: 0.8rem !important;
    }

    .close-btn {
        top: 0.5rem !important;
        right: 0.5rem !important;
        width: 36px !important;
        height: 36px !important;
        font-size: 20px !important;
    }
}

@media (max-width: 480px) {
    .series-detail-cover-col {
        max-width: 200px;
    }

    .series-detail-page .series-title,
    h1.series-title {
        font-size: 1.15rem !important;
    }

    .series-info-grid {
        grid-template-columns: 1fr 1fr !important;
        font-size: 0.9rem;
    }
}

/* ---------- Profile (mobile) ---------- */
@media (max-width: 768px) {
    .profile-wrapper {
        padding: 0 0.85rem !important;
        margin: 1rem auto !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }

    .profile-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 1.25rem !important;
        padding: 1.25rem !important;
    }

    .profile-stats {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        gap: 0.5rem !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        padding: 0.75rem 0.5rem !important;
    }

    .stat-item {
        min-width: 0 !important;
    }

    .stat-label {
        font-size: 0.65rem !important;
        letter-spacing: 0.04em !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Keep tab panels from pulling the viewport toward the footer on iOS */
    .profile-wrapper .tabs {
        position: sticky;
        top: 4.5rem; /* sit below sticky site header, not over it */
        z-index: 40;
        scroll-margin-top: 0;
    }

    .profile-wrapper .tab-content {
        scroll-margin-top: 4.5rem;
        min-height: 40vh; /* avoids empty panels sitting above a huge footer void */
    }

    .profile-wrapper .tab-content.active {
        min-height: 50vh;
    }
}
