/**
 * Phone layout: keep the map visible and only the essentials on top of it.
 * Loaded last so it wins over the per-component mobile rules.
 */

/* Any screen size: the Live Activity card would cover the bottom of an open spot panel */
body:has(#territory-panel:not(.hidden)) #timeline-widget {
    display: none !important;
}
@media (max-width: 768px) {
    /* Discover card, floating feedback and ranking buttons live in the side menu on phones */
    .recommendation-panel,
    #feedback-button,
    .feedback-button,
    .ranking-mobile-btn {
        display: none !important;
    }

    /* Pinch to zoom instead of the +/- / compass buttons */
    .mapboxgl-ctrl-bottom-right .mapboxgl-ctrl-group,
    .mapboxgl-ctrl-top-right .mapboxgl-ctrl-group {
        display: none !important;
    }

    /* World button + country picker in one slim row at the bottom */
    .map-controls {
        top: auto !important;
        left: 10px !important;
        right: 10px !important;
        bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important;
        flex-direction: row !important;
        align-items: stretch !important;
        gap: 8px !important;
        padding: 0 !important;
        background: none !important;
        border: none !important;
        box-shadow: none !important;
    }

    .map-controls .view-toggle-btn {
        width: auto !important;
        flex: 0 0 auto;
        height: 44px;
        padding: 0 14px;
        white-space: nowrap;
    }

    .map-controls .map-mode-toggle {
        flex: 1 1 auto;
        width: auto !important;
        min-width: 0;
    }

    .map-controls #country-selector {
        width: 100% !important;
        height: 44px;
        min-width: 0 !important;
    }

    /* Leave room above the bottom row for the Mapbox logo/attribution */
    .mapboxgl-ctrl-bottom-left,
    .mapboxgl-ctrl-bottom-right {
        bottom: calc(84px + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* Header: one slim bar beside the menu button, wallet on the right */
    .header {
        top: 20px !important;
        left: 82px !important;
        right: 12px !important;
        transform: none !important;
        max-width: none !important;
        min-width: 0 !important;
        height: 50px;
        padding: 0 6px 0 14px !important;
        flex-wrap: nowrap !important;
        justify-content: space-between !important;
        gap: 8px !important;
    }

    .header-content {
        flex: 1 1 auto;
        min-width: 0;
        text-align: left;
    }

    .header-content h1 {
        flex-wrap: nowrap !important;
        justify-content: flex-start !important;
        font-size: 17px !important;
        overflow: hidden;
    }

    .header-content p {
        display: none;
    }

    .header-wallet {
        flex: 0 0 auto;
        margin: 0 !important;
        position: static !important;
    }

    .wallet-btn {
        height: 38px;
        padding: 0 12px !important;
        font-size: 14px !important;
        white-space: nowrap;
    }

    /* While a spot is open, nothing else floats over it */
    body:has(#territory-panel:not(.hidden)) .map-controls {
        display: none !important;
    }

    /* Scroll area sized to the sheet so the sticky button below lands on screen */
    #territory-panel:not(.hidden) {
        display: flex !important;
        flex-direction: column;
    }

    #territory-panel:not(.hidden) > .panel-header {
        flex: 0 0 auto;
    }

    #territory-panel:not(.hidden) > .panel-content {
        flex: 1 1 auto;
        min-height: 0;
        max-height: none !important;
        overflow-y: auto;
    }

    /* Keep the main buy/sign-in/edit button reachable without scrolling */
    #territory-panel .territory-actions:not(:has(.action-option-card, .protected-info-notice, .auction-active-notice)) {
        position: sticky;
        bottom: 0;
        z-index: 2;
        margin: 0 -4px;
        padding: 10px 4px calc(10px + env(safe-area-inset-bottom, 0px));
        background: rgb(14, 22, 26);
        box-shadow: 0 -10px 16px rgba(14, 22, 26, 0.9);
    }

    /* Charge points: 2x2 packages so the PayPal button is close by */
    .payment-modal-content {
        width: calc(100vw - 16px) !important;
        max-width: none !important;
        max-height: calc(100dvh - 16px) !important;
        overflow-y: auto !important;
    }

    .payment-screen {
        padding: 18px 14px calc(18px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .payment-screen .modal-header {
        padding: 0 40px 10px !important;
    }

    .payment-screen .modal-header h2 {
        font-size: 20px !important;
    }

    .current-balance {
        padding: 8px 12px !important;
        margin-bottom: 12px !important;
    }

    .point-packages {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
        margin-bottom: 12px !important;
    }

    .package-card {
        padding: 18px 8px 10px !important;
    }

    .package-card .badge {
        font-size: 10px !important;
        padding: 2px 8px !important;
        top: -9px !important;
    }

    .package-card .package-points {
        font-size: 15px !important;
    }

    .package-card .package-price {
        font-size: 18px !important;
    }

    .package-card .package-bonus {
        font-size: 11px !important;
    }

    .custom-amount-section {
        margin-bottom: 12px !important;
    }

    .custom-amount-info {
        flex-direction: row !important;
        align-items: center !important;
    }

    /* First-visit guide: slide height follows its content and scrolls instead of being cut off */
    .onboarding-container {
        display: flex;
        flex-direction: column;
        max-height: calc(100dvh - 24px) !important;
    }

    .onboarding-slides {
        flex: 1 1 auto;
        min-height: 0 !important;
        overflow-y: auto !important;
    }

    .onboarding-slide {
        position: relative !important;
        inset: auto !important;
        display: none !important;
        padding: 52px 20px 16px !important;
        transform: none !important;
    }

    .onboarding-slide.active {
        display: flex !important;
    }

    .onboarding-nav {
        flex: 0 0 auto;
        padding: 12px 16px calc(14px + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* Toasts: one line at the top, out of the way of the panel */
    #notification-container {
        top: 76px !important;
        bottom: auto !important;
    }
}
