/* Capa responsive/táctil. Las ramas de mouse/fine pointer conservan el CSS previo. */

.zone-viewer-touch-action {
    display: none;
}

.zone-viewer-item {
    display: contents;
}

/* En touch, solo las cartas con una acción real de doble tap reservan el gesto
   para el juego. El resto del duelo conserva pan, scroll y pinch nativos. */
body.touch-layout-capable.duel-playing .attack-candidate,
body.touch-layout-capable.duel-playing .ability-doubleclick-candidate,
body.touch-layout-capable.duel-playing .revive-doubleclick-candidate,
body.touch-layout-capable.duel-playing [data-revive-candidate="true"] {
    touch-action: none;
}

@media (hover: none) and (pointer: coarse) {
    body:not(.duel-playing) .catalog-large-preview-source {
        cursor: pointer;
    }

    body:not(.duel-playing) #cardGrid.card-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: clamp(12px, 2vw, 20px);
    }

    body:not(.duel-playing) .deck-layout {
        grid-template-columns: 1fr;
    }

    body:not(.duel-playing) .deck-layout > .deck-current-panel {
        position: relative;
        top: auto;
        max-height: none;
    }

    body:not(.duel-playing) #deckAvailable {
        grid-template-columns: repeat(auto-fill, minmax(174px, 1fr));
    }

    body:not(.duel-playing) input,
    body:not(.duel-playing) select,
    body:not(.duel-playing) button,
    .initial-mulligan-actions button,
    .zone-viewer-modal button {
        min-height: 44px;
    }

    .initial-mulligan-modal {
        width: min(1180px, calc(100vw - 24px));
        max-width: min(1180px, calc(100vw - 24px));
        max-height: calc(100vh - 24px);
        max-height: calc(100dvh - 24px);
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .initial-mulligan-modal .choice-modal-head,
    .initial-mulligan-actions {
        flex: 0 0 auto;
    }

    .initial-mulligan-actions {
        top: 0;
    }

    .initial-mulligan-modal .initial-mulligan-grid {
        min-height: 0;
        max-height: none;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        overflow-y: auto;
        overscroll-behavior: contain;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .initial-mulligan-card .choice-target-card-detail .game-dialog-card-image {
        height: clamp(92px, 15dvh, 132px) !important;
    }

    .zone-viewer-item {
        min-width: 0;
        display: grid;
        justify-items: center;
        gap: 10px;
        padding: 8px;
        border: 1px solid transparent;
        border-radius: 16px;
    }

    .zone-viewer-item.is-touch-selected {
        border-color: rgba(244, 199, 106, .7);
        background: rgba(120, 53, 15, .16);
    }

    .zone-viewer-item .zone-viewer-touch-action {
        width: min(100%, 300px);
        min-height: 48px;
    }

    .zone-viewer-item.is-touch-selected .zone-viewer-touch-action {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .cost,
    .cg-cost-medallion,
    .cg-card-stat--fue,
    .cg-card-stat--cor,
    .resource-token,
    .counter-badge {
        aspect-ratio: 1 / 1;
    }

    .card-image img,
    .detail-visual img,
    .game-dialog-card-image img,
    .global-card-mini-art img {
        object-fit: contain;
    }
}

@media (hover: none) and (pointer: coarse) and (min-width: 981px) {
    body.duel-playing main {
        height: 100vh;
        height: 100dvh;
        padding-inline: 8px;
    }

    body.duel-playing .board-layout {
        grid-template-columns: minmax(0, 1fr) clamp(236px, 21.5vw, 286px) !important;
        gap: 8px;
    }

    body.duel-playing .board-layout .board-main.panel,
    body.duel-playing .board-layout .right-dock {
        gap: 7px;
    }

    body.duel-playing .right-dock {
        overscroll-behavior: contain;
    }

    body.duel-playing .right-dock .domain-dock {
        padding: 8px;
    }

    body.duel-playing .right-dock .domain-dock .jungle-area {
        grid-template-rows: auto clamp(108px, 15dvh, 158px) !important;
    }

    body.duel-playing .right-dock > .right-climate-slot,
    body.duel-playing .right-dock .right-climate-slot > button {
        min-height: 92px;
    }

    body.duel-playing .action-dock {
        padding: 8px 9px;
    }

    body.duel-playing .action-dock .action-row {
        gap: 6px;
    }

    body.duel-playing .action-dock button,
    body.duel-playing .stack-zone,
    body.duel-playing .jungle-card,
    body.duel-playing .global-climate-slot > button {
        min-height: 44px;
    }

    body.duel-playing .hand-zone > header.zone-header-stack.pillars-centered {
        min-height: 44px !important;
        gap: 5px !important;
    }

    body.duel-playing .hand-zone .mini-pillars {
        gap: 3px;
    }

    body.duel-playing .hand-zone .mini-pillars .pilar {
        min-width: 76px;
        min-height: 38px;
        padding: 5px 6px;
    }

    body.duel-playing .hand-zone .mini-pillars .pillar-icon {
        width: 24px;
        height: 24px;
        aspect-ratio: 1 / 1;
    }

    body.duel-playing .hand-zone .resource-strip {
        gap: 3px;
    }

    body.duel-playing .hand-zone .resource-chip {
        padding: 2px 5px;
    }

    body.duel-playing .hand-zone > header.zone-header-stack.pillars-centered > .hand-deck-zone {
        flex-basis: 58px;
    }

    body.duel-playing .board-main .field-zone .game-card.duel-card.has-field-template-card {
        --field-card-max-width: clamp(132px, 12.6vw, 174px);
    }
}

/* Tablet v2 horizontal: el tablero usa todo el ancho y los paneles auxiliares
   se reorganizan debajo. No se escala el board ni se alteran hitboxes. */
@media (orientation: landscape) and (min-width: 900px)
       and (max-width: 1400px) and (max-height: 900px) {
    body.touch-layout-capable.duel-playing main {
        height: 100vh;
        height: 100dvh;
        overflow-x: hidden;
        overflow-y: auto;
        padding: 8px;
        padding-bottom: max(18px, env(safe-area-inset-bottom));
    }

    body.touch-layout-capable.duel-playing .board-layout {
        height: auto !important;
        min-height: 0 !important;
        grid-template-columns: minmax(0, 1fr) !important;
        grid-template-rows: minmax(650px, calc(100vh - 16px)) auto;
        grid-template-rows: minmax(650px, calc(100dvh - 16px)) auto;
        gap: 10px !important;
        overflow: visible !important;
    }

    body.touch-layout-capable.duel-playing .board-layout .board-main.panel {
        box-sizing: border-box !important;
        width: 100%;
        height: calc(100vh - 16px) !important;
        height: calc(100dvh - 16px) !important;
        min-width: 0 !important;
        min-height: 650px !important;
    }

    body.touch-layout-capable.duel-playing .board-layout .right-dock {
        width: 100%;
        height: auto !important;
        min-width: 0 !important;
        min-height: 0 !important;
        display: grid !important;
        grid-template-columns: minmax(250px, 1.1fr) minmax(250px, 1fr) minmax(210px, .86fr) !important;
        grid-template-rows: auto auto !important;
        gap: 10px !important;
        overflow: visible !important;
    }

    body.touch-layout-capable.duel-playing .right-dock > .action-dock {
        grid-column: 1;
        grid-row: 1 / span 2;
        min-width: 0;
    }

    body.touch-layout-capable.duel-playing .right-dock > .domain-dock {
        grid-column: 2;
        grid-row: 1 / span 2;
        min-width: 0;
    }

    body.touch-layout-capable.duel-playing .right-dock > .right-climate-slot {
        grid-column: 3;
        grid-row: 1;
        min-width: 0;
        min-height: 112px;
    }

    body.touch-layout-capable.duel-playing .right-dock > .match-info-dock {
        grid-column: 3;
        grid-row: 2;
        min-width: 0;
    }

    body.touch-layout-capable.duel-playing .right-dock .domain-dock .jungle-area {
        grid-template-rows: auto clamp(118px, 18dvh, 166px) !important;
    }

    body.touch-layout-capable.duel-playing .board-main .field-zone .game-card.duel-card.has-field-template-card {
        --field-card-max-width: clamp(150px, 15vw, 210px);
    }
}

@media (max-width: 980px) {
    body.touch-layout-capable.duel-playing main {
        height: 100vh;
        height: 100dvh;
        overflow: auto;
        overscroll-behavior: contain;
        padding-inline: 8px;
        padding-bottom: max(18px, env(safe-area-inset-bottom));
    }

    body.touch-layout-capable.duel-playing .board-layout {
        height: auto;
        min-height: 100%;
        grid-template-columns: minmax(0, 1fr) !important;
        overflow: visible;
    }

    body.touch-layout-capable.duel-playing .board-layout .board-main.panel {
        box-sizing: border-box !important;
        width: 100%;
        min-width: 0 !important;
        min-height: 760px;
        min-height: max(760px, calc(100dvh - 16px));
        overflow: hidden;
    }

    body.touch-layout-capable.duel-playing .board-layout .right-dock {
        min-width: 0 !important;
        overflow: visible !important;
    }

    body.touch-layout-capable.duel-playing .right-dock > .right-climate-slot {
        flex: 0 0 auto;
        min-height: 130px;
    }

    body.touch-layout-capable.duel-playing .right-dock .domain-dock .jungle-area {
        grid-template-rows: auto clamp(132px, 22dvh, 190px) !important;
    }

    body.touch-layout-capable.duel-playing .hand-zone > header.zone-header-stack.pillars-centered {
        flex-wrap: wrap !important;
    }

    body.touch-layout-capable.duel-playing .hand-zone > header.zone-header-stack.pillars-centered > .mini-pillars {
        order: 3;
        flex-basis: 100%;
        justify-content: flex-start !important;
        overflow-x: auto;
    }

    body.touch-layout-capable.duel-playing .board-main .field-zone .game-card.duel-card.has-field-template-card {
        --field-card-max-width: clamp(132px, 29vw, 172px);
    }

    body.touch-layout-capable .zone-viewer-modal {
        width: calc(100vw - 20px);
        max-height: calc(100vh - 20px);
        max-height: calc(100dvh - 20px);
        padding: 12px;
    }

    body.touch-layout-capable .zone-viewer-list {
        grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
        max-height: none;
    }
}

@media (hover: none) and (pointer: coarse) and (max-width: 860px),
       (hover: none) and (pointer: coarse) and (max-height: 650px) {
    .initial-mulligan-modal .initial-mulligan-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .initial-mulligan-actions {
        grid-template-columns: 1fr;
        position: static;
    }
}

@media (hover: none) and (pointer: coarse) and (max-width: 760px) {
    body:not(.duel-playing) #cardGrid.card-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    body:not(.duel-playing) #deckAvailable {
        grid-template-columns: repeat(auto-fill, minmax(156px, 1fr));
    }

}

@media (hover: none) and (pointer: coarse) and (max-width: 479px) {
    body:not(.duel-playing) #cardGrid.card-grid,
    body:not(.duel-playing) #deckAvailable {
        grid-template-columns: 1fr;
    }

    .initial-mulligan-modal {
        width: calc(100vw - 12px);
        max-width: calc(100vw - 12px);
        padding: 10px;
    }

    .initial-mulligan-modal .initial-mulligan-grid {
        grid-template-columns: 1fr;
    }

}

@media (prefers-reduced-motion: reduce) {
    .zone-viewer-item {
        transition: none;
    }
}
