/* === Phones and small tablets (loaded last, so these override the desktop layout) ===
 * Battle screen: compact headers, the board full width, one action row under the board
 * (Log · settings · End Turn · Attack), the log and settings behind buttons, long-press
 * to read a card (UI.addLongPress), and only the music button in the corner.
 */

.mobile-only { display: none; }

@media (max-width: 900px) {
    :root {
        --hand-card-w: clamp(80px, 25vw, 120px);
        --board-card-h: clamp(88px, min(calc((100dvh - 280px - var(--hand-card-h)) / 2), 40vw), 180px);
    }
    #game-container { height: 100dvh; }

    /* Headers: name, essence and numbers only */
    .player-info { padding: 4px 8px; gap: 6px; }
    #opponent-area .player-info { padding-right: 48px; } /* room for the music button */
    .player-name { font-size: 0.75rem; letter-spacing: 0.5px; white-space: nowrap; }
    .player-stats { gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
    .stat { font-size: 0.85rem; gap: 2px; }
    #opponent-area .stat.essence-count { display: none; } /* its essence pool beside the name shows the same */
    .essence-pool.compact { font-size: 0.65rem; padding: 1px 6px; gap: 4px; }
    .stat-icon { font-size: 0.95rem; }
    .stat-bar { display: none; }
    .mind-state { font-size: 0.6rem; padding: 1px 4px; }
    .portrait { width: 26px; height: 26px; font-size: 0.8rem; }
    .essence-pool { padding: 3px 8px; gap: 6px; min-height: 0; }

    #opponent-hand { padding: 3px 8px; min-height: 0; gap: 3px; }
    #opponent-hand .card-back { width: 26px; height: 36px; }
    #opponent-hand .card-back .card-back-symbol { font-size: 0.6rem; }

    /* The board takes the full width */
    #battlefield { padding: 4px 6px; justify-content: center; }
    .board-row { padding: 6px; gap: 6px; }
    #phase-indicator { padding: 3px 6px; gap: 10px; }
    #phase-hint { display: none; }
    #current-phase { font-size: 0.75rem; letter-spacing: 1px; }

    /* The log: a button opens the whole log (UI.showLog) */
    #game-log { display: none; }

    /* Side panel becomes one row of buttons under the board */
    #side-panel { position: static; width: auto; flex-direction: row; margin-top: 6px; }
    #cast-queue { display: none; }
    #action-bar { flex-direction: row; flex: 1; gap: 6px; }
    #action-bar .action-btn { flex: 1; padding: 9px 6px; font-size: 0.72rem; letter-spacing: 0.5px; }
    #action-bar .mobile-only { display: block; flex: 0 0 auto; padding: 9px 12px; }
    #btn-deck { display: none; }

    /* Battle settings: a small popover over the action row */
    #settings-box { display: none; }
    body.settings-open #settings-box {
        display: flex;
        position: fixed; left: 8px; right: 8px; bottom: calc(var(--hand-card-h) + 90px);
        z-index: 200; padding: 10px 12px; font-size: 0.85rem; gap: 10px;
    }

    #player-hand { padding: 6px 8px 8px; min-height: calc(var(--hand-card-h) + 12px); }

    /* Corner tools: just the music button, small, top right */
    .corner-tools { top: 4px; right: 6px; bottom: auto; }
    .corner-tools .corner-btn, .corner-tools .music-volume { display: none; }
    .music-toggle { width: 32px; height: 32px; font-size: 15px; }

    /* Cards: no browser menu or callout on long-press */
    .card { -webkit-touch-callout: none; }
    #card-preview .card { --card-w: min(260px, 70vw); }

    /* Deck builder: the card pool on top, your deck below; each scrolls, Save stays in view */
    .db-header { flex-wrap: wrap; gap: 6px 10px; padding: 8px 12px; padding-right: 48px; align-items: center; }
    .db-title { font-size: 1rem; letter-spacing: 1px; }
    .db-name { width: 100%; max-width: 260px; }
    .db-rules, .db-owner { font-size: 0.75rem; }
    .db-body { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) minmax(0, 44%); }
    .db-body > *, .db-pool-section { min-width: 0; }
    .db-pool { overflow-x: hidden; }
    .db-filters { padding: 6px 10px; gap: 4px; }
    .db-chip { font-size: 0.65rem; padding: 3px 8px; }
    .db-pool { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 14px 8px; padding: 8px 10px 16px; }
    .db-pool .card { --card-w: 100px; }
    .db-sidebar { border-left: none; border-top: 1px solid var(--border-subtle); padding: 8px 10px; gap: 6px; }
    .db-curve, .db-needs { display: none; }
    .db-total { font-size: 1rem; }
    .db-actions { flex-wrap: wrap; gap: 6px; }

    /* Campaign map: small stone labels so they fit a phone-width map */
    .campaign-map-screen { padding: 10px; }
    .campaign-header { flex-wrap: wrap; gap: 4px 10px; padding-right: 40px; }
    .campaign-stone { padding: 2px 4px; gap: 1px; }
    .campaign-stone-mark { width: 12px; height: 19px; }
    .campaign-stone-name { font-size: 0.6rem; line-height: 1.1; max-width: 80px; text-align: center; }
    .campaign-stone-sub { font-size: 0.52rem; }
    .stone-next::before { width: 28px; height: 28px; top: 2px; }

    /* Campaign story screens taller than the phone: scroll from the top instead of clipping it */
    .campaign-overlay:not(.campaign-map-screen) { justify-content: safe center; padding: 12px; }
    .campaign-overlay > * { flex-shrink: 0; }
}
