/* Flip 7 - Mobile Container Layout */
/* Complete rewrite with controls panel and proper button placement */

@media (max-width: 1024px) {
    /* Reset body for mobile */
    body {
        overflow-x: hidden;
        overflow-y: auto;
        min-height: 100vh;
        margin: 0;
        padding: 0;
    }

    /* Main game container - vertical stack for mobile */
    .game-container {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        max-width: 100% !important;
        min-height: 100vh !important;
        padding: 0 !important;
        margin: 0 !important;
        gap: 0 !important;
        grid-template-columns: none !important;
        grid-template-rows: none !important;
    }

    /* Controls panel - compact horizontal strip at top */
    .controls-panel {
        display: grid !important;
        grid-template-columns: auto 1fr !important;
        grid-template-areas:
            "logo buttons"
            "speed speed" !important;
        align-items: center !important;
        width: 100% !important;
        padding: 4px 10px !important;
        background: rgba(0, 0, 0, 0.4) !important;
        border-bottom: 2px solid rgba(255, 255, 255, 0.2) !important;
        min-height: auto !important;
        max-height: none !important;
        order: 1 !important;
        column-gap: 10px !important;
        row-gap: 4px !important;
    }

    /* Logo - compact alignment next to controls */
    .controls-panel .logo-header {
        grid-area: logo !important;
        flex: 0 0 auto !important;
        order: 1 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
        width: 100% !important;
        margin: 0 !important;
        max-width: 120px !important;
    }

    .controls-panel .flip7-logo {
        height: auto !important;
        max-height: 44px !important;
        width: 100% !important;
        max-width: 96px !important;
        object-fit: contain !important;
    }

    /* Flatten inner container so buttons + slider can take grid areas */
    .controls-panel .control-section {
        display: contents !important;
    }

    .controls-panel .control-buttons {
        grid-area: buttons !important;
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 6px !important;
        width: 100% !important;
        flex-wrap: nowrap !important;
    }

    /* Control buttons styling - compact width */
    .controls-panel .control-buttons .btn {
        flex: 1 1 calc(33.333% - 4px) !important;
        padding: 5px 8px !important;
        font-size: 0.64rem !important;
        margin: 0 !important;
        line-height: 1.15 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        min-width: 0 !important;
        letter-spacing: 0.025em !important;
    }

    .controls-panel .speed-control {
        grid-area: speed !important;
        display: grid !important;
        grid-template-columns: auto 1fr !important;
        align-items: center !important;
        padding: 6px 0 2px !important;
        border-top: 1px solid rgba(255, 255, 255, 0.18) !important;
        margin-top: 0 !important;
        gap: 6px !important;
    }
    
    .controls-panel .speed-control label,
    .controls-panel .speed-control .speed-value {
        font-size: 0.7rem !important;
        margin: 0 !important;
    }

    .controls-panel .speed-control .speed-control-inputs {
        display: flex !important;
        flex: 1 1 auto !important;
        align-items: center !important;
        gap: 8px !important;
    }

    .controls-panel .speed-control #game-speed-slider {
        height: 4px !important;
        margin: 0 !important;
    }

    .controls-panel .speed-control .speed-helper-text {
        font-size: 0.65rem !important;
        line-height: 1.3 !important;
    }
    
    /* Position Rules button to the left */
    .controls-panel #rules-btn {
        order: 1 !important;
    }
    
    /* Position Scoreboard button to the right */
    .controls-panel #scoreboard-btn {
        order: 3 !important;
    }

    .controls-panel #restart-game-btn {
        order: 2 !important;
    }
    
    /* Show scoreboard button only on mobile */
    #scoreboard-btn {
        display: inline-block !important;
    }

    /* Hide desktop-only elements in controls */
    .controls-panel .desktop-info {
        display: none !important;
    }

    /* Draw pile - hide on mobile (less important than controls) */
    .draw-pile-column {
        display: none !important;
    }

    /* Game area - main content area */
    .game-area {
        display: flex !important;
        flex-direction: column !important;
        flex: 1 !important;
        width: 100% !important;
        padding: 10px !important;
        padding-bottom: 56px !important; /* Space for fixed buttons */
        overflow-y: auto !important;
        order: 2 !important;
    }

    /* Players grid - stack vertically on mobile */
    .players-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 6px !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Individual player areas */
    .player-area {
        width: 100% !important;
        padding: 6px !important;
        height: 120px !important;
        display: flex !important;
        flex-direction: column !important;
        background: rgba(255, 255, 255, 0.15) !important;
        border-radius: 8px !important;
        margin-bottom: 2px !important;
        position: relative !important;
        overflow-x: hidden !important;
        overflow-y: visible !important;
    }
    
    /* Player header section */
    .player-header {
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 6px !important;
        position: relative !important;
        margin-bottom: 3px !important;
        padding: 0 5px !important;
    }

    .player-header h3 {
        font-size: 0.95em !important;
        margin: 0 !important;
        color: var(--accent-gold) !important;
    }

    .player-name-group {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 6px !important;
        min-width: 0 !important;
    }

    .player-name-group .dealer-label {
        font-size: 0.6em !important;
        padding: 2px 6px !important;
        border: 1px solid rgba(255, 255, 255, 0.55) !important;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35) !important;
        position: static !important;
    }

    /* Hide player status - removed from HTML but keep for backwards compatibility */
    .player-stats,
    .player-status {
        display: none !important;
    }

    /* Score display */
    .round-score {
        position: absolute !important;
        right: 5px !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: flex-end !important;
        gap: 4px !important;
        line-height: 1 !important;
        font-size: 0.95em !important;
        color: var(--text-white) !important;
        font-weight: bold !important;
    }

    .round-score .round-value,
    .round-score .total-value {
        min-width: 24px !important;
        display: inline-block !important;
    }

    .round-score .total-value {
        color: var(--accent-gold) !important;
        text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8) !important;
    }

    .round-score .score-separator {
        opacity: 0.7 !important;
        font-size: 0.85em !important;
        letter-spacing: 0.04em !important;
    }

    /* Cards container */
    .player-cards {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 2px !important;
        flex: 1 !important;
        padding: 3px !important;
        align-items: flex-start !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        scrollbar-width: thin !important;
        scrollbar-color: rgba(255, 255, 255, 0.65) rgba(255, 255, 255, 0.15) !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .player-cards::-webkit-scrollbar {
        height: 6px !important;
    }

    .player-cards::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.1) !important;
        border-radius: 6px !important;
    }

    .player-cards::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.75) !important;
        border-radius: 6px !important;
    }

    /* Make cards fill available container height on mobile */
    .card {
        width: 65px !important;
        height: 82px !important;
        font-size: 0.9em !important;
    }

    /* Hit/Stay buttons - fixed at bottom of screen */
    .action-buttons-mobile {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        display: flex !important;
        justify-content: center !important;
        gap: 15px !important;
        padding: 8px 15px !important;
        background: linear-gradient(to top, rgba(0, 0, 0, 0.95), rgba(0, 0, 0, 0.8)) !important;
        border-top: 2px solid rgba(255, 215, 0, 0.3) !important;
        z-index: 1000 !important;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5) !important;
        max-height: 80px !important;
    }

    /* Control buttons styling - maximized */
    .action-buttons-mobile #mobile-hit-btn,
    .action-buttons-mobile #mobile-stay-btn {
        flex: 0 1 140px !important;
        padding: 12px 20px !important;
        font-size: 1.3em !important;
        height: calc(100% - 16px) !important;
        max-height: 56px !important;
        min-height: 48px !important;
        border-radius: 28px !important;
        font-weight: bold !important;
        text-transform: uppercase !important;
        letter-spacing: 1.5px !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
    }

    /* Winner celebration overlay */
    #winning-celebration {
        position: fixed !important;
        inset: 0 !important;
        z-index: 2000 !important;
    }

    /* Special card modal adjustments */
    .special-action-modal {
        padding: 10px !important;
    }

    .special-action-content {
        width: 90% !important;
        max-width: 350px !important;
    }

    /* Current turn indicator */
    .player-area.current-turn {
        border: 2px solid var(--accent-gold) !important;
        box-shadow: 0 0 15px rgba(255, 215, 0, 0.6) !important;
        animation: pulse 2s infinite !important;
    }

    @keyframes pulse {
        0%, 100% { box-shadow: 0 0 15px rgba(255, 215, 0, 0.6); }
        50% { box-shadow: 0 0 25px rgba(255, 215, 0, 0.9); }
    }

    /* Frozen player indicator */
    .player-area.frozen {
        background: linear-gradient(145deg, rgba(96, 165, 250, 0.3) 0%, rgba(255, 255, 255, 0.15) 100%) !important;
        border: 2px solid #60a5fa !important;
    }

    /* Hide desktop-only info panels */
    .desktop-info {
        display: none !important;
    }
}

/* Tablet adjustments (landscape mode) */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    /* Larger controls panel on tablets */
    .controls-panel {
        padding: 5px 14px !important;
        column-gap: 14px !important;
        row-gap: 6px !important;
        grid-template-columns: auto 1fr !important;
        max-height: none !important;
    }

    .controls-panel .flip7-logo {
        max-height: 50px !important;
        max-width: 110px !important;
    }

    /* Keep scoreboard button visible on tablet - use modal like mobile */
    #scoreboard-btn {
        display: inline-block !important;
    }

    /* Hide scoreboard panel on tablets - use modal instead */
    .controls-panel .scoreboard,
    .controls-panel .desktop-info {
        display: none !important;
    }

    /* Arrange players in 2x2 grid on tablets */
    .players-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        grid-template-rows: auto auto !important;
        gap: 10px !important;
        padding: 10px !important;
        padding-bottom: 58px !important;
    }

    .player-area {
        margin-bottom: 0 !important;
        height: 130px !important;
    }

    /* Control buttons for tablet */
    .controls-panel #rules-btn,
    .controls-panel #scoreboard-btn,
    .controls-panel #restart-game-btn {
        font-size: 0.9em !important;
        padding: 6px 10px !important;
    }

    /* Larger cards on tablets - fill container height */
    .card {
        width: 70px !important;
        height: 85px !important;
    }

    /* Slightly larger buttons on tablets */
    .action-buttons-mobile #mobile-hit-btn,
    .action-buttons-mobile #mobile-stay-btn {
        flex: 0 1 160px !important;
        max-height: 60px !important;
        min-height: 52px !important;
        font-size: 1.4em !important;
        padding: 14px 24px !important;
    }
}

/* Small mobile devices (phones in portrait) */
@media (max-width: 480px) {
    /* Smaller controls panel */
    .controls-panel { 
        padding: 3px 8px !important;
        column-gap: 6px !important;
        row-gap: 4px !important;
        grid-template-columns: auto 1fr !important;
        max-height: none !important;
    }

    .controls-panel .flip7-logo {
        height: auto !important;
        max-height: 38px !important;
        max-width: 88px !important;
    }

    .controls-panel .control-buttons {
        gap: 4px !important;
        justify-content: space-between !important;
    }

    .controls-panel #rules-btn,
    .controls-panel #scoreboard-btn,
    .controls-panel #restart-game-btn {
        font-size: 0.6rem !important;
        padding: 4px 6px !important;
        line-height: 1.2 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    .controls-panel .speed-control label,
    .controls-panel .speed-control .speed-value {
        font-size: 0.62rem !important;
    }

    .controls-panel .speed-control .speed-helper-text {
        font-size: 0.58rem !important;
    }

    /* Cards for small phones - fill available space */
    .card {
        width: 55px !important;
        height: 70px !important;
        font-size: 0.85em !important;
    }

    /* Smaller text */
    .player-header h3 {
        font-size: 0.8em !important;
    }

    .player-stats,
    .round-score {
        line-height: 1 !important;
        font-size: 0.8em !important;
        color: var(--text-white) !important;
    }

    /* Smaller control buttons */
    .action-buttons-mobile #mobile-hit-btn,
    .action-buttons-mobile #mobile-stay-btn {
        flex: 0 1 120px !important;
        max-height: 48px !important;
        min-height: 42px !important;
        font-size: 1.15em !important;
        padding: 10px 18px !important;
        letter-spacing: 1px !important;
    }

    /* Less padding on game area */
    .game-area {
        padding: 5px !important;
        padding-bottom: 50px !important;
    }
}
