/* --- Mobile App Layout --- */
.mobile-menu-btn,
.mobile-sidebar-overlay {
    display: none;
}

@media (max-width: 768px) {
    body.app-active {
        overflow: hidden;
        height: 100vh;
    }

    #app-view {
        position: relative;
        flex-direction: row;
        overflow: hidden;
    }

    .sidebar {
        position: fixed;
        z-index: 2600;
        inset: 0;
        width: 100vw;
        max-width: none;
        height: 100dvh;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        border-right: none;
        border-radius: 0;
        box-shadow: none;
        overflow-y: auto;
    }

    #app-view.mobile-sidebar-open .sidebar {
        transform: translateX(0);
    }

    .main-content {
        width: 100%;
        min-width: 0;
        padding-top: 58px;
    }

    .set-header {
        padding: 1rem;
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .set-header > div:first-child {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }

    #set-logo {
        max-height: 42px;
        max-width: 180px;
    }

    #set-title {
        font-size: 1.45rem;
        line-height: 1.15;
    }

    #set-stats {
        font-size: 0.88rem;
    }

    .set-header-control-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .set-progress-container {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .set-card-controls {
        min-width: 0;
        width: 100%;
        flex: none;
        justify-items: stretch;
    }

    .card-sort-controls,
    .card-view-controls {
        width: 100%;
        justify-content: stretch;
    }

    .card-sort-btn,
    .binder-view-toggle,
    .binder-size-btn {
        flex: 1 1 30%;
        min-width: 0;
        padding: 0 0.55rem;
    }

    .binder-size-controls {
        width: 100%;
    }

    .cards-grid.binder-mode {
        padding: 0.55rem;
    }

    .binder-spread {
        grid-template-columns: 1fr;
        min-height: min(68vh, 620px);
        gap: 0.25rem;
        padding: 0.25rem;
    }

    .binder-spread-mobile .binder-page-left {
        display: none;
    }

    .binder-spread-mobile .binder-page-right::before {
        display: none;
    }

    .binder-pockets {
        inset: 0.8rem;
        gap: 0.35rem;
    }

    .binder-nav {
        grid-template-columns: 1fr;
        gap: 0.55rem;
    }

    .binder-nav button,
    .binder-nav button:first-child,
    .binder-nav button:last-child {
        justify-self: stretch;
    }

    .progress-box {
        width: 100%;
    }

    #filter-container {
        width: 100%;
        flex: none;
        align-items: stretch !important;
    }


    .cards-grid {
        padding: 1rem;
        gap: 0.8rem;
        grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
    }

    .card-item {
        padding: 8px;
        border-radius: 10px;
    }

    .card-image {
        margin-bottom: 8px;
        border-radius: 7px;
    }

    .card-meta {
        font-size: 0.72rem;
        gap: 4px;
    }

    .card-name {
        font-size: 0.82rem;
    }

    .card-variant {
        font-size: 0.72rem;
    }

    .cards-grid.browse-mode {
        padding: 1rem;
    }

    .browse-heading {
        font-size: 1.25rem;
        margin-bottom: 1rem;
    }

    .series-grid {
        grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
        gap: 0.8rem;
    }

    .series-card {
        min-height: 90px;
        padding: 1rem;
        border-radius: 10px;
    }

    .series-card-logo {
        max-height: 34px;
        max-width: 90%;
    }

    .series-card-logo.large-logo {
        max-height: 54px;
    }

    .series-card-count {
        font-size: 0.74rem;
        padding: 2px 8px;
    }

    .sets-grid {
        grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
        gap: 0.8rem;
    }

    .set-card {
        min-height: 105px;
        padding: 0.9rem;
    }

    .set-card-logo {
        max-height: 38px;
    }

    .set-card-name {
        font-size: 0.82rem;
    }

    .set-card-meta {
        font-size: 0.72rem;
    }

    .series-sets-header {
        flex-wrap: wrap;
        gap: 0.6rem;
        padding: 0.85rem 1rem;
    }

    .series-sets-logo {
        max-height: 34px;
        max-width: 160px;
    }

    .series-owned-count,
    .series-sets-count {
        font-size: 0.78rem;
    }

    .friend-view-banner {
        flex-direction: column;
        align-items: stretch;
        padding: 12px 14px;
    }

    .friend-view-banner button {
        width: 100%;
    }

    .donation-strip {
        margin: 0 0 14px;
    }
}

/* --- Mobile Modals --- */
@media (max-width: 768px) {
    .modal {
        align-items: stretch;
        justify-content: stretch;
        padding: 0;
    }

    .modal-content {
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        overflow-y: auto;
    }

    .modal-body {
        flex-direction: column;
        padding: 1rem;
        gap: 1rem;
        overflow-y: auto;
    }

    .modal-image-container {
        max-width: 100%;
        flex: none;
        max-height: 42vh;
    }

    .modal-image-container img {
        max-height: 40vh;
    }

    .modal-info {
        max-height: none;
        overflow: visible;
    }

    .modal-info h2 {
        font-size: 1.5rem;
    }

    .variant-controls {
        align-items: stretch;
    }

    .qty-btn {
        width: 34px;
        height: 34px;
    }

    .qty-input {
        width: 55px;
    }

    .cond-select,
    .notes-input {
        flex: 1 1 100%;
        min-width: 100%;
    }

    .price-actions {
        flex-direction: column;
    }

    .price-actions .action-btn {
        width: 100%;
    }
}

/* --- Mobile Friends / Chat: list-only then chat-only --- */
.mobile-chat-back-btn {
    display: none;
}

@media (max-width: 768px) {
    #friends-chat-view.active {
        display: block;
        width: 100vw;
        height: 100dvh;
        overflow: hidden;
    }

    .friends-chat-page {
        display: block;
        width: 100vw;
        height: 100dvh;
        min-height: 100dvh;
        overflow: hidden;
        background: linear-gradient(180deg, #1b2a3d, #101722);
    }

    .friends-chat-sidebar {
        width: 100vw;
        height: 100dvh;
        min-height: 100dvh;
        border-right: none;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }

    .friends-chat-main {
        display: none;
        width: 100vw;
        height: 100dvh;
        min-height: 100dvh;
    }

    .friends-chat-page.mobile-chat-open .friends-chat-sidebar {
        display: none;
    }

    .friends-chat-page.mobile-chat-open .friends-chat-main {
        display: flex;
        width: 100vw;
        height: 100dvh;
        min-height: 100dvh;
    }

    .friends-chat-page.mobile-chat-open .chat-empty-state {
        display: none !important;
    }

    .friends-chat-page.mobile-chat-open .web-chat-panel {
        display: flex !important;
        height: 100dvh;
        min-height: 100dvh;
        width: 100vw;
    }

    .web-chat-header {
        min-height: 64px;
        padding: 10px 12px;
        gap: 10px;
        align-items: center;
    }

    .mobile-chat-back-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
        height: 38px;
        padding: 0 12px;
        border-radius: 8px;
        border: 1px solid rgba(148, 163, 184, 0.35);
        background: rgba(255, 255, 255, 0.06);
        color: #dbe8f5;
        font-weight: 800;
        cursor: pointer;
    }

    .web-chat-header > div {
        min-width: 0;
    }

    .web-chat-header h2 {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .web-chat-messages {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        padding: 16px;
    }

    .web-chat-input-row {
        flex: 0 0 auto;
        height: auto;
        padding: 10px;
        gap: 6px;
    }

    .web-chat-input-row input {
        min-width: 0;
        height: 42px;
    }

    .web-chat-input-row button {
        height: 42px;
        padding: 0 12px;
    }

    .web-sound-menu {
        right: 64px;
        bottom: 58px;
    }

    .friends-section {
        padding-bottom: 14px;
    }

    .web-friend-list {
        padding-bottom: 6px;
    }
}

/* --- Mobile set page space saver --- */
.donation-strip {
    position: relative;
}

.donation-strip-dismiss-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    font-size: 22px;
    line-height: 1;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}

.donation-strip-dismiss-btn:hover {
    background: rgba(255, 255, 255, 0.16);
}

.progress-mobile-label {
    display: none;
}

@media (max-width: 768px) {
    .set-header {
        padding: 14px 18px;
        gap: 10px;
        align-items: flex-start;
    }

    #set-logo {
        max-height: 46px;
        max-width: 190px;
        margin-bottom: 4px;
    }

    #set-title {
        display: none;
    }

    #set-stats {
        font-size: 0.9rem;
        line-height: 1.25;
        margin-top: 2px;
        color: rgba(240, 248, 255, 0.92);
    }

    .set-progress-container {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        align-items: start;
        width: 100%;
        margin-top: 8px;
    }

    .progress-box {
        width: 100%;
        min-width: 0;
    }

    .progress-labels {
        font-size: 0.78rem;
        line-height: 1.15;
        margin-bottom: 3px;
        gap: 4px;
    }

    .bold-label {
        font-weight: 800;
        white-space: nowrap;
    }

    .progress-full-label {
        display: none;
    }

    .progress-mobile-label {
        display: inline;
    }

    .progress-bar-bg {
        height: 5px;
        border-radius: 999px;
    }

    .donation-strip {
        margin: 10px 12px 12px;
        padding: 12px 42px 12px 14px;
        border-radius: 14px;
        gap: 10px;
    }

    .donation-strip-copy strong {
        font-size: 0.95rem;
        line-height: 1.15;
    }

    .donation-strip-copy span {
        font-size: 0.8rem;
        line-height: 1.2;
    }

    .donation-strip-btn {
        padding: 8px 12px;
        min-height: 38px;
        border-radius: 10px;
        font-size: 0.9rem;
    }

    .donation-strip-dismiss-btn {
        top: 8px;
        right: 8px;
        width: 26px;
        height: 26px;
        font-size: 20px;
    }

    .cards-grid {
        padding-top: 14px;
    }
}

@media (max-width: 480px) {
    .set-progress-container {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .progress-labels {
        font-size: 0.72rem;
    }

    .donation-strip {
        flex-direction: column;
        align-items: stretch;
    }

    .donation-strip-btn {
        width: 100%;
    }
}

/* --- Mobile: put set search + filter on same row --- */
@media (max-width: 768px) {
    #filter-container {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) 118px;
        gap: 8px;
        width: 100%;
        align-items: stretch !important;
    }

    #set-card-search {
        display: block !important;
        width: 100% !important;
        min-width: 0;
        height: 46px;
        margin: 0 !important;
        padding: 0 14px;
        font-size: 1rem;
        border-radius: 12px;
    }

    #card-filter {
        width: 100% !important;
        min-width: 0;
        height: 46px;
        margin: 0 !important;
        padding: 0 10px;
        font-size: 0.95rem;
        border-radius: 12px;
    }
}

@media (max-width: 420px) {
    #filter-container {
        grid-template-columns: minmax(0, 1fr) 96px;
        gap: 7px;
    }

    #set-card-search {
        font-size: 0.95rem;
        padding: 0 12px;
    }

    #card-filter {
        font-size: 0.9rem;
        padding: 0 8px;
    }
}




/* --- Mobile: move the real set logo into the top bar --- */
.mobile-top-bar {
    display: none;
}

.desktop-set-logo-slot {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .mobile-top-bar {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 66px;
        z-index: 3000;
        align-items: center;
        gap: 12px;
        padding: 8px 16px;
        background: rgba(10, 45, 70, 0.96);
        border-bottom: 1px solid var(--glass-border);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
    }

    .mobile-top-bar .mobile-menu-btn {
        position: static !important;
        display: flex !important;
        width: 50px;
        height: 50px;
        flex: 0 0 50px;
        border-radius: 14px;
        border: 1px solid var(--glass-border);
        background: rgba(16, 55, 78, 0.92);
        color: var(--text-main);
        align-items: center;
        justify-content: center;
        font-size: 1.45rem;
        font-weight: 900;
        cursor: pointer;
        box-shadow: none;
    }

    .mobile-set-logo-slot {
        flex: 1;
        min-width: 0;
        height: 50px;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        overflow: hidden;
    }

    .mobile-set-logo-slot #set-logo {
        display: block;
        max-height: 40px !important;
        max-width: 190px !important;
        width: auto;
        object-fit: contain;
        margin: 0 !important;
    }

    .desktop-set-logo-slot {
        display: none !important;
    }

    #app-view.mobile-sidebar-open .mobile-set-logo-slot {
        display: none;
    }

    #app-view.mobile-sidebar-open .mobile-top-bar .mobile-menu-btn {
        margin-left: 0;
    }

    .main-content {
        padding-top: 66px !important;
    }

    .set-header {
        padding-top: 12px !important;
    }

    #set-title {
        display: none !important;
    }
}

@media (max-width: 420px) {
    .mobile-top-bar {
        height: 62px;
        padding: 7px 14px;
    }

    .mobile-top-bar .mobile-menu-btn {
        width: 48px;
        height: 48px;
        flex-basis: 48px;
    }

    .mobile-set-logo-slot {
        height: 48px;
    }

    .mobile-set-logo-slot #set-logo {
        max-height: 36px !important;
        max-width: 165px !important;
    }

    .main-content {
        padding-top: 62px !important;
    }
}

/* --- Mobile top bar: site logo + set logo behavior --- */
.mobile-site-logo {
    display: none;
}

@media (max-width: 768px) {
    .mobile-site-logo {
        display: block;
        height: 34px;
        width: auto;
        max-width: 190px;
        object-fit: contain;
        flex: 1;
        min-width: 0;
    }

    .mobile-set-logo-slot {
        display: none;
    }

    #app-view.mobile-set-logo-active .mobile-site-logo {
        display: none;
    }

    #app-view.mobile-set-logo-active .mobile-set-logo-slot {
        display: flex;
    }

    #app-view.mobile-sidebar-open .mobile-site-logo {
        display: block;
    }

    #app-view.mobile-sidebar-open .mobile-set-logo-slot {
        display: none !important;
    }
}

@media (max-width: 420px) {
    .mobile-site-logo {
        height: 30px;
        max-width: 160px;
    }
}

/* --- Mobile menu open: keep hamburger + logo on left --- */
@media (max-width: 768px) {
    #app-view.mobile-sidebar-open .mobile-top-bar {
        justify-content: flex-start;
    }

    #app-view.mobile-sidebar-open .mobile-top-bar .mobile-menu-btn {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    #app-view.mobile-sidebar-open .mobile-site-logo {
        flex: 0 1 auto;
        margin-left: 0;
    }
}

@media (max-width: 768px) {
    .mobile-site-logo,
    .mobile-set-logo-slot,
    .mobile-set-logo-slot #set-logo {
        cursor: pointer;
    }
}

/* =========================================================
   Mobile responsive layout for logged-out landing/auth pages
   Desktop stays unchanged
========================================================= */

@media (max-width: 768px) {
    body:not(.app-active) {
        overflow-x: hidden;
    }

    #landing-view.active {
        display: block;
        width: 100%;
        min-height: 100dvh;
        overflow-y: auto;
    }

    .container {
        width: 100%;
        max-width: 100%;
        padding: 0 18px;
    }

    /* Landing top nav */
    .landing-header {
        position: sticky;
        top: 0;
        padding: 12px 0;
        z-index: 1000;
    }

    .landing-header .container {
        gap: 12px;
    }

    .site-logo {
        height: 34px;
        max-width: 170px;
    }

    .landing-header nav {
        gap: 10px;
        flex-shrink: 0;
    }

    .landing-header nav a {
        display: none;
    }

    .nav-auth-btn {
        padding: 9px 12px;
        border-radius: 9px;
        font-size: 0.85rem;
        white-space: nowrap;
    }

    /* Hero section */
    .hero {
        min-height: auto;
        padding: 42px 0 38px;
        display: block;
    }

    .hero-content {
        display: flex;
        flex-direction: column;
        gap: 24px;
        padding: 0 18px;
    }

    .hero-content h1 {
        font-size: clamp(2rem, 9vw, 3rem);
        line-height: 1.08;
        margin-bottom: 16px;
        text-align: left;
    }

    .hero-content p {
        font-size: 1rem;
        line-height: 1.55;
        margin-bottom: 22px;
        max-width: 100%;
    }

    .hero-btns {
        display: grid;
        grid-template-columns: 1fr;
        gap: 12px;
        margin-bottom: 0;
    }

    .primary-btn.large,
    .secondary-btn.large {
        width: 100%;
        padding: 14px 18px;
        font-size: 1rem;
        border-radius: 12px;
    }

    .hero-visual {
        width: 100%;
    }

    .hero-img {
        width: 100%;
        border-radius: 14px;
        transform: none;
        box-shadow: 0 16px 34px rgba(0, 0, 0, 0.45);
    }

    .hero-img:hover {
        transform: none;
    }

    /* Feature section */
    .features {
        padding: 48px 0;
    }

    .section-title {
        font-size: 1.8rem;
        line-height: 1.15;
        margin-bottom: 24px;
    }

    .feature-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .feature-card {
        padding: 24px 18px;
        border-radius: 18px;
    }

    .feature-card:hover {
        transform: none;
    }

    .feature-icon {
        font-size: 2.4rem;
        margin-bottom: 12px;
    }

    .feature-card h3 {
        font-size: 1.25rem;
    }

    .feature-card p {
        font-size: 0.95rem;
    }

    .social-preview-section {
        padding: 48px 0;
    }

    .social-preview-layout {
        grid-template-columns: 1fr;
        gap: 22px;
    }

    .section-kicker {
        font-size: 0.72rem;
    }

    .social-preview-copy h2 {
        font-size: 1.8rem;
        line-height: 1.15;
    }

    .social-preview-copy p {
        font-size: 0.98rem;
        line-height: 1.55;
    }

    .social-feature-list {
        gap: 10px;
    }

    .social-feature-list span {
        padding: 12px 14px;
        font-size: 0.92rem;
    }

    .social-preview-visual {
        padding: 6px;
        border-radius: 12px;
    }

    .social-preview-visual img {
        border-radius: 8px;
    }

    /* Preview section */
    .previews {
        padding: 48px 0;
    }

    .preview-gallery {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .preview-img {
        border-radius: 12px;
    }

    .preview-img:hover {
        transform: none;
    }

    /* Legal notice */
    .legal-notice-section {
        padding: 36px 0 24px;
    }

    .legal-notice-card {
        padding: 18px;
        border-radius: 16px;
        font-size: 0.88rem;
        line-height: 1.55;
    }

    .legal-notice-card h2 {
        font-size: 1.2rem;
    }

    .landing-footer {
        padding: 18px 0;
        text-align: center;
        font-size: 0.85rem;
    }

    /* Auth login/register page */
    #auth-view.active {
        display: flex;
        min-height: 100dvh;
        height: auto;
        overflow-y: auto;
        padding: 24px 18px;
        justify-content: flex-start;
    }

    .auth-page {
        min-height: calc(100dvh - 48px);
        justify-content: center;
        gap: 18px;
    }

    .auth-page-header {
        width: 100%;
        display: flex;
        justify-content: center;
    }

    .auth-site-logo {
        height: 54px;
        max-width: 240px;
    }

    .auth-box {
        width: 100%;
        max-width: 430px;
        padding: 22px 18px;
        border-radius: 18px;
    }

    .auth-header {
        margin-bottom: 18px;
    }

    .auth-header h2 {
        font-size: 1.35rem;
        line-height: 1.2;
    }

    .auth-tabs {
        margin-top: 14px;
    }

    .auth-tabs button {
        padding: 10px 8px;
        font-size: 0.95rem;
    }

    .auth-form {
        gap: 12px;
    }

    .auth-form input,
    .auth-form select {
        min-height: 46px;
        font-size: 1rem;
        padding: 11px 12px;
        border-radius: 10px;
    }

    .auth-form .primary-btn {
        min-height: 46px;
        font-size: 1rem;
        border-radius: 10px;
    }

    .auth-page > .back-btn {
        margin-bottom: 0;
        font-size: 0.95rem;
    }
}

@media (max-width: 430px) {
    .container {
        padding: 0 14px;
    }

    .landing-header .container {
        padding: 0 12px;
    }

    .site-logo {
        height: 30px;
        max-width: 150px;
    }

    .nav-auth-btn {
        padding: 8px 10px;
        font-size: 0.8rem;
    }

    .hero-content {
        padding: 0 14px;
    }

    .hero-content h1 {
        font-size: 2.15rem;
    }

    .hero-content p {
        font-size: 0.95rem;
    }

    .auth-box {
        padding: 20px 16px;
    }

    .auth-site-logo {
        height: 48px;
        max-width: 220px;
    }
}

/* --- Mobile logout button --- */
.mobile-logout-btn {
    display: none;
}

@media (max-width: 768px) {
    .mobile-logout-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        flex: 0 0 44px;
        margin-left: auto;
        border-radius: 12px;
        border: 1px solid var(--glass-border);
        background: rgba(16, 55, 78, 0.92);
        color: var(--text-main);
        font-size: 1.15rem;
        cursor: pointer;
    }

    .mobile-logout-btn:hover {
        background: var(--bg-panel-hover);
    }

    .mobile-site-logo {
        min-width: 0;
    }

    .mobile-set-logo-slot {
        min-width: 0;
    }
}

@media (max-width: 420px) {
    .mobile-logout-btn {
        width: 40px;
        height: 40px;
        flex-basis: 40px;
        font-size: 1rem;
    }
}

/* --- Fix desktop donation close button overlap --- */
@media (min-width: 701px) {
    .donation-strip {
        padding-right: 58px;
    }

    .donation-strip-dismiss-btn {
        top: 50%;
        right: 14px;
        transform: translateY(-50%);
    }

    .donation-strip-btn {
        margin-right: 0;
    }
}

/* --- Mobile: make expanded donation page scrollable --- */
@media (max-width: 768px) {
    .main-content {
        overflow-y: auto !important;
        overflow-x: hidden !important;
        height: 100dvh;
        -webkit-overflow-scrolling: touch;
    }

    .donation-page {
        max-height: none;
        overflow: visible;
        margin: 12px;
        padding: 18px;
        padding-bottom: 120px;
    }

    .donation-body {
        overflow: visible;
    }

    .donation-body p {
        font-size: 0.98rem;
        line-height: 1.55;
    }

    .donation-actions {
        padding-bottom: 40px;
    }
}

@media (max-width: 768px) {
    #app-view.active {
        overflow: hidden;
    }

    .cards-grid {
        min-height: 0;
    }
}

/* =========================================================
   Mobile fix: card detail modal should fit under top bar
   and scroll normally on phones.
   Desktop is unchanged.
========================================================= */
@media (max-width: 768px) {
    /* Keep the mobile top bar visible, but do not let it cover the modal */
    #card-modal.modal {
        top: 66px;
        left: 0;
        right: 0;
        bottom: 0;
        height: calc(100dvh - 66px);
        max-height: calc(100dvh - 66px);
        align-items: stretch;
        justify-content: stretch;
        padding: 0;
        overflow: hidden;
        z-index: 2500;
    }

    /* Use the real mobile viewport instead of old 100vh */
    #card-modal .modal-content {
        width: 100%;
        height: calc(100dvh - 66px);
        max-height: calc(100dvh - 66px);
        min-height: 0;
        border-radius: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    /* Do not create a second trapped scroll area */
    #card-modal .modal-body {
        display: flex;
        flex-direction: column;
        width: 100%;
        min-height: auto;
        padding: 14px 16px calc(34px + env(safe-area-inset-bottom));
        gap: 16px;
        overflow: visible;
    }

    /* Keep image visible but not so tall that it steals the whole screen */
    #card-modal .modal-image-container {
        width: 100%;
        max-width: 100%;
        max-height: none;
        flex: 0 0 auto;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    #card-modal .modal-image-container img {
        width: auto;
        max-width: min(82vw, 300px);
        max-height: 44dvh;
        object-fit: contain;
        border-radius: 12px;
    }

    /* Let all card text and variants be part of the main modal scroll */
    #card-modal .modal-info {
        width: 100%;
        max-height: none;
        min-height: 0;
        overflow: visible;
        display: flex;
        flex-direction: column;
    }

    #card-modal .modal-info h2 {
        font-size: 1.55rem;
        line-height: 1.15;
        margin-bottom: 12px;
    }

    #card-modal .badges {
        margin-bottom: 18px;
        flex-wrap: wrap;
    }

    #card-modal .flavor-text {
        font-size: 1rem;
        line-height: 1.55;
        margin-bottom: 20px;
    }

    #card-modal .variants-title {
        margin-top: 18px;
        margin-bottom: 10px;
    }

    /* Remove the small internal variant scroll limit on mobile */
    #card-modal .variants-list {
        max-height: none;
        overflow: visible;
        padding-bottom: 14px;
    }

    #card-modal .variant-row {
        width: 100%;
    }

    #card-modal .variant-controls {
        display: grid;
        grid-template-columns: 42px minmax(0, 1fr) 42px;
        gap: 8px;
        align-items: stretch;
    }

    #card-modal .qty-btn {
        width: 42px;
        height: 42px;
    }

    #card-modal .qty-input {
        width: 100%;
        height: 42px;
    }

    #card-modal .cond-select,
    #card-modal .notes-input {
        grid-column: 1 / -1;
        width: 100%;
        min-width: 100%;
        height: 42px;
    }

    #card-modal .close-btn {
        top: 10px;
        right: 10px;
        z-index: 5;
    }
}
    
/* =========================================================
   Mobile donation strip scroll/cutoff fix
========================================================= */
@media (max-width: 768px) {
    .donation-strip {
        scroll-margin-top: 88px;
        margin-top: 12px;
    }

    .donation-page {
        scroll-margin-top: 88px;
    }

    .main-content {
        scroll-padding-top: 88px;
    }
}

/* =========================================================
   Mobile donation layout fix
   Makes main content scroll on mobile so the donation strip
   and expanded donation page cannot get clipped.
========================================================= */
@media (max-width: 768px) {
    body.app-active {
        overflow: hidden !important;
        height: 100dvh !important;
    }

    #app-view {
        height: 100dvh !important;
        max-height: 100dvh !important;
        overflow: hidden !important;
    }

    #app-view .main-content {
        height: 100dvh !important;
        max-height: 100dvh !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch;
        padding-top: 72px !important;
        scroll-padding-top: 88px;
    }

    #app-view .cards-grid {
        flex: 0 0 auto !important;
        overflow: visible !important;
        min-height: auto !important;
        padding-bottom: calc(90px + env(safe-area-inset-bottom)) !important;
    }

    #app-view .donation-strip {
        flex: 0 0 auto !important;
        margin: 12px 12px 14px !important;
        scroll-margin-top: 88px;
    }

    #app-view .donation-page {
        flex: 0 0 auto !important;
        margin: 12px 12px 14px !important;
        scroll-margin-top: 88px;
    }
}
