/* =====================================================================
   Recipe Map on phones: map first, with count bubbles
   (scripts/map-phone.js). Title and Map | List on one row, Recipes /
   Chefs with a Filters button under it, the map as a card with + / − /
   reset and the bubbles, then the chosen country's recipes as compact
   rows. Desktop and the profile page's map are untouched.
   ===================================================================== */
.mph-zoom,
.mph-hint,
.mph-filters-btn,
.mph-sheet,
.mph-sheet-dim { display: none; }

@media (max-width: 768px) {
    #map-section {
        --mph-green: var(--primary-color, #1f4836);
        --mph-gold: #bf9b30;
        --mph-sage-soft: #e8eee0;
        --mph-paper: #fffdf7;
        --mph-ink: #24302a;
        --mph-muted: #6b7263;
        --mph-line: #e2dccb;
        --mph-sea: #eef1ea;
        --mph-serif: var(--heading-font, 'Cormorant Garamond', Georgia, serif);
        --mph-sans: var(--body-font, 'Inter', -apple-system, 'Segoe UI', sans-serif);
    }
    /* Only while the tab is open: .main-tab-content hides the others with display: none. */
    #map-section.active {
        display: grid;
        align-content: start;
        background: var(--cream-bg, #f5efe1) !important;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        column-gap: 10px;
        row-gap: 10px;
    }
    #map-section > * { grid-column: 1 / -1; min-width: 0; }

    /* Title and Map | List share the top row; the long intro goes. */
    #map-section > h2 {
        grid-column: 1;
        margin: 0 !important;
        text-align: left !important;
        font: 600 1.4rem/1.1 var(--mph-serif) !important;
        color: var(--mph-green);
    }
    #map-section > h2 + p { display: none; }
    #map-section > .map-view-toggle {
        grid-column: 2;
        grid-row: 1;
        margin: 0 !important;
        display: inline-grid !important;
        grid-template-columns: 1fr 1fr;
        padding: 3px;
        border: 0;
        border-radius: 999px;
        background: var(--mph-sage-soft);
        box-shadow: none;
    }
    #map-section .map-view-btn {
        padding: 5px 12px !important;
        border: 0 !important;
        border-radius: 999px !important;
        background: none !important;
        color: var(--mph-muted) !important;
        font: 700 0.74rem var(--mph-sans) !important;
        box-shadow: none !important;
    }
    #map-section .map-view-btn i { display: none; }
    /* "Map View" / "List View" read as just Map / List here, so the title fits. */
    #map-section .map-view-btn { font-size: 0 !important; }
    #map-section .map-view-btn::after { font: 700 0.74rem var(--mph-sans); }
    #map-section .map-view-btn[data-view="map"]::after { content: "Map"; }
    #map-section .map-view-btn[data-view="list"]::after { content: "List"; }
    #map-section .map-view-btn.active { background: var(--mph-green) !important; color: #fff !important; }

    /* Recipes / Chefs, with Filters beside it. */
    #map-section > .map-result-toggle {
        grid-column: 1;
        margin: 0 !important;
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        padding: 3px;
        border: 0;
        border-radius: 999px;
        background: var(--mph-sage-soft);
    }
    #map-section .mrt-btn {
        padding: 6px !important;
        border: 0 !important;
        border-radius: 999px !important;
        background: none !important;
        color: var(--mph-muted) !important;
        font: 600 0.78rem var(--mph-sans) !important;
        box-shadow: none !important;
    }
    #map-section .mrt-btn i { display: none; }
    #map-section .mrt-btn.active { background: var(--mph-paper) !important; color: var(--mph-green) !important; box-shadow: 0 1px 3px rgba(31, 72, 54, 0.12) !important; }
    #map-section > .mph-filters-btn {
        grid-column: 2;
        display: inline-flex;
        align-items: center;
        gap: 6px;
        height: 36px;
        padding: 0 12px;
        border: 1px solid var(--mph-line);
        border-radius: 999px;
        background: var(--mph-paper);
        color: var(--mph-green);
        font: 700 0.76rem var(--mph-sans);
        cursor: pointer;
    }
    .mph-filters-n {
        display: inline-grid;
        place-items: center;
        min-width: 18px;
        height: 18px;
        padding: 0 5px;
        border-radius: 999px;
        background: var(--mph-green);
        color: #fff;
        font: 700 0.62rem var(--mph-sans);
        font-style: normal;
    }
    .mph-filters-n[hidden] { display: none; }

    /* ---- The map card ---- */
    #map-section .map-wrapper {
        overflow: hidden;
        border-radius: 14px;
        background: var(--mph-sea);
        box-shadow: 0 2px 10px rgba(31, 72, 54, 0.08);
    }
    #world-map-container svg {
        display: block;
        width: 100% !important;
        height: auto !important;
        touch-action: pan-y;        /* one finger scrolls the page; two move the map */
        -webkit-user-select: none;
        user-select: none;
    }
    #map-tooltip { display: none !important; }   /* hover tooltips do not suit touch */
    .mph-zoom { position: absolute; right: 8px; top: 8px; z-index: 2; display: grid; gap: 4px; }
    .mph-zoom button {
        width: 32px;
        height: 32px;
        display: grid;
        place-items: center;
        padding: 0;
        border: 0;
        border-radius: 9px;
        background: rgba(255, 253, 247, 0.96);
        color: var(--mph-green);
        font: 700 1rem var(--mph-sans);
        box-shadow: 0 1px 4px rgba(31, 72, 54, 0.22);
        cursor: pointer;
    }
    .mph-zoom button[hidden] { display: none; }
    .mph-hint {
        position: absolute;
        left: 8px;
        bottom: 8px;
        z-index: 2;
        display: block;
        padding: 3px 9px;
        border-radius: 999px;
        background: rgba(255, 253, 247, 0.94);
        color: var(--mph-muted);
        font: 600 0.64rem var(--mph-sans);
        pointer-events: none;
        transition: opacity 0.3s ease, background 0.2s ease, color 0.2s ease;
    }
    .mph-hint.nudge { background: var(--mph-green); color: #fff; }
    .mph-hint.gone { opacity: 0; }

    .mph-bub { cursor: pointer; }
    .mph-bub circle { fill: var(--mph-gold); stroke: #fffdf7; stroke-width: 1.5px; vector-effect: non-scaling-stroke; }
    .mph-bub.group circle { fill: #8a6d1d; }
    .mph-bub.sel circle { fill: var(--mph-green); }
    .mph-bub text {
        fill: #fff;
        font-family: var(--mph-sans);
        font-weight: 700;
        text-anchor: middle;
        dominant-baseline: central;
        pointer-events: none;
    }
    .mph-bub:focus { outline: none; }
    .mph-bub:focus-visible circle { stroke: var(--mph-ink); stroke-width: 2.5px; }

    /* ---- List view ---- */
    #map-section .map-view-list { margin: 0; }

    /* ---- The chosen country's recipes ---- */
    #map-results-container {
        margin: 0 !important;
        padding: 12px;
        border-radius: 14px;
        background: var(--mph-paper);
        box-shadow: 0 2px 10px rgba(31, 72, 54, 0.08);
    }
    #selected-country-title {
        margin: 0 0 10px !important;
        text-align: left !important;
        font: 600 1.2rem var(--mph-serif) !important;
        color: var(--mph-green) !important;
    }
    #map-recipes-list.map-country-grid { display: grid !important; grid-template-columns: minmax(0, 1fr) !important; gap: 8px !important; }
    #map-recipes-list .map-country-card {
        display: grid !important;
        grid-template-columns: 54px minmax(0, 1fr);
        gap: 10px;
        align-items: center;
        padding: 0 !important;
        border: 0 !important;
        background: none !important;
        box-shadow: none !important;
        text-decoration: none;
    }
    #map-recipes-list .mcc-image { width: 54px !important; height: 54px !important; border-radius: 9px; overflow: hidden; flex: none; }
    #map-recipes-list .mcc-image img { width: 100%; height: 100%; object-fit: cover; }
    #map-recipes-list .mcc-body { padding: 0 !important; min-width: 0; }
    #map-recipes-list .mcc-title { margin: 0 0 2px !important; font: 600 0.98rem/1.15 var(--mph-serif) !important; color: var(--mph-green) !important; }
    #map-recipes-list .mcc-meta { display: flex; flex-wrap: wrap; gap: 0 10px; font-size: 0.7rem !important; color: var(--mph-muted) !important; }
    #map-recipes-list .mcc-meta + .mcc-meta span:last-child { display: none; }   /* the date */
    #map-recipes-list .mcc-country { display: none; }                            /* already in the title */

    /* ---- Filters sheet ---- */
    .mph-sheet-dim:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 2000; background: rgba(20, 36, 28, 0.4); }
    .mph-sheet:not([hidden]) {
        display: grid;
        gap: 12px;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 2001;
        max-height: 85vh;
        overflow-y: auto;
        padding: 8px 16px calc(16px + env(safe-area-inset-bottom, 0px));
        border-radius: 18px 18px 0 0;
        background: #fffdf7;
        box-shadow: 0 -10px 30px rgba(31, 72, 54, 0.25);
        font-family: var(--body-font, sans-serif);
        transform: translateY(100%);
        transition: transform 0.22s ease;
    }
    .mph-sheet.in { transform: none; }
    html.mph-sheet-open { overflow: hidden; }
    .mph-grab { justify-self: center; width: 40px; height: 4px; border-radius: 999px; background: #e2dccb; }
    .mph-sheet-head h3 { margin: 0; font: 600 1.25rem var(--heading-font, Georgia, serif); color: var(--primary-color, #1f4836); }
    .mph-sheet-body { display: grid; gap: 14px; }
    .mph-sheet .map-mode-filters,
    .mph-sheet .map-cooktime-filter,
    .mph-sheet .map-filters-bar { display: flex !important; flex-wrap: wrap; gap: 6px !important; justify-content: flex-start !important; margin: 0 !important; }
    .mph-sheet .mmf-label,
    .mph-sheet .mct-label { flex: 1 0 100%; font-size: 0.64rem !important; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: #6b7263; }
    .mph-sheet .mct-label i { display: none; }
    .mph-sheet .map-mode-explainer { margin: -6px 0 0 !important; text-align: left !important; font-size: 0.76rem !important; color: #6b7263; }
    .mph-sheet .map-filters-bar::before { content: "Narrow the results"; flex: 1 0 100%; font-size: 0.64rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: #6b7263; }
    .mph-sheet .map-filters-bar .filter-select { flex: 1 1 140px; min-width: 0; }
    .mph-sheet-done { padding: 12px; border: 0; border-radius: 999px; background: var(--primary-color, #1f4836); color: #fff; font: 700 0.86rem var(--body-font, sans-serif); cursor: pointer; }
}
