/* =============================================================
   MOBILE LAYOUT — Boutine Guessing Game
   Critical overrides for phones and small screens.
   The game board wraps inside a horizontal-scroll zone so players
   can swipe to see all clue columns without the whole page scrolling.
   ============================================================= */

@media (max-width: 768px) {

    /* --- Body --- */
    body {
        padding: max(12px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    }

    /* --- Main titles --- */
    .main-title { font-size: 34px; padding-top: 20px; }
    h1.title-md { font-size: 22px; }

    /* --- Ensure 44px touch targets on interactive elements --- */
    .menu-btn,
    .difficulty-btn,
    .daily-btn,
    .accordion-toggle,
    .profile-tab,
    .stat-sub-btn,
    .filter-btn,
    .sidebar-btn,
    .icon-btn,
    .cal-nav-btn { min-height: 44px; }

    /* Setting-nav arrows are 32 × 32 by default; promote to 44 × 44 on mobile */
    .setting-nav-btn { min-width: 44px; min-height: 44px; }

    /* --- Game screen ---
         overflow-x: auto here lets the board scroll without the whole
         page scrolling when the grid is wider than the viewport.       */
    #game-screen { padding: 10px 6px; overflow-x: hidden; }

    .game-board {
        min-width: unset;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Fix min-width so the grid never wraps but scrolls instead */
    .header-row,
    .guess-row { min-width: 530px; }

    /* Reduce box text slightly for tight columns */
    .box { font-size: 11px; padding: 6px 4px; }
    .guess-row .box:first-child img { width: 50px; height: 50px; }
    .guess-row .box:first-child { min-width: 54px; }

    /* --- Search input: full width --- */
    .search-container {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* --- Game HUD: allow wrapping --- */
    .game-hud { flex-wrap: wrap; gap: 6px; }

    /* --- Game over card: fill almost full width, scrollable if too tall --- */
    .game-over-card {
        width: 96vw !important;
        max-width: 96vw !important;
        max-height: 90dvh;
        overflow-y: auto;
        padding: 20px 14px;
        border-radius: var(--radius-md);
    }

    /* --- Modals: center properly and scroll internally on small screens/iOS --- */
    .modal { padding: max(20px, env(safe-area-inset-top)) 0 max(12px, env(safe-area-inset-bottom)); align-items: flex-start; overflow-y: auto; -webkit-overflow-scrolling: touch; }
    .modal > div, .modal > .report-modal-content, .modal > .game-over-card { margin: auto; }

    /* --- Daily missions panel: stretch to full width --- */
    .daily-missions-panel { max-width: 100%; }

    /* --- Calendar: constrain width on phone --- */
    .calendar-container { width: 100% !important; }

    /* --- Challenge / H2H URL input row: stack on very small screens --- */
    .challenge-url-row { flex-wrap: wrap; gap: 6px; }
    .challenge-url-input { min-width: 0; flex: 1 1 100%; }

    /* --- Suggestion dropdown: cap height when keyboard is open --- */
    .suggestions { max-height: 160px; }
}

@media (max-width: 480px) {
    .main-title { font-size: 28px; }

    /* Stats sub-tab buttons: scrollable row */
    .stats-navigation {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
        padding-bottom: 4px;
    }

    .stat-sub-btn { white-space: nowrap; flex-shrink: 0; }
}

/* =============================================================
   OFFLINE DATA INDICATOR
   Shown when game data is served from localStorage cache.
   ============================================================= */
#offlineIndicator {
    position: fixed;
    bottom: max(32px, calc(env(safe-area-inset-bottom) + 8px));
    right: max(12px, env(safe-area-inset-right));
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 6px 12px;
    font-size: 11px;
    color: var(--text-muted);
    z-index: 900;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    transition: opacity 0.3s;
}

#offlineIndicator.d-none { display: none; }
#offlineIndicator.offline-warn {
    border-color: rgba(224,59,59,0.4);
    color: #f97070;
}

#offlineIndicator .offline-refresh-btn {
    background: none;
    border: none;
    color: var(--purple);
    font-size: 11px;
    cursor: pointer;
    padding: 0;
    font-family: inherit;
    font-weight: 600;
    text-decoration: underline;
}

/* =============================================================
   APP UPDATE BANNER
   Slides in from the top when a new service worker is installed.
   ============================================================= */
#updateBanner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding-top: max(10px, env(safe-area-inset-top));
    background: var(--purple);
    color: var(--white);
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    padding: 10px 16px;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.4);
    transform: translateY(-100%);
    transition: transform 0.35s ease;
}

#updateBanner.banner-show { transform: translateY(0); }
#updateBanner.d-none { display: none; }

#updateBanner button {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.5);
    color: var(--white);
    border-radius: var(--radius-sm);
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: background var(--transition);
}

#updateBanner button:hover { background: rgba(255,255,255,0.35); }

/* =============================================================
   TOAST STACK — shared container for all floating notifications
   ============================================================= */
#toast-stack {
    position: fixed;
    bottom: max(28px, calc(env(safe-area-inset-bottom) + 8px));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    z-index: 9999;
    pointer-events: none;
    max-width: 90vw;
}
#toast-stack > * { pointer-events: auto; }

/* =============================================================
   SYNC STATUS TOAST
   ============================================================= */
.sync-toast {
    background: var(--surface-2);
    border: 1px solid var(--border-hi);
    border-radius: var(--radius-md);
    padding: 10px 18px;
    font-size: 12px;
    color: var(--text-muted);
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    opacity: 0;
    transform: translateY(12px);
    transition: transform 0.35s ease, opacity 0.35s ease;
    white-space: nowrap;
}

.sync-toast.sync-toast-show {
    transform: translateY(0);
    opacity: 1;
}

.sync-toast--error {
    border-color: #e03b3b;
    color: #f97070;
}

/* =============================================================
   NOTIFICATION PANEL — mobile overrides
   ============================================================= */
@media (max-width: 768px) {
    .notif-bell {
        top: calc(max(20px, env(safe-area-inset-top)) + 80px);
        right: max(12px, env(safe-area-inset-right));
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    .notif-panel {
        top: calc(max(20px, env(safe-area-inset-top)) + 132px);
        right: max(8px, env(safe-area-inset-right));
        left: max(8px, env(safe-area-inset-left));
        width: auto;
        max-height: 60vh;
    }
}
