/* =============================================
   MOBILE-OPTIMIZED BELOTE CSS
   - Faster card animations
   - Centered lobby rooms
   - Better touch targets
   ============================================= */

/* ===== MOBILE PORTRAIT MODE ===== */
@media (max-width: 900px) {

    /* --- LOBBY SCREEN MOBILE FIXES --- */
    .lobby-menu-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 8px !important;
        width: 100% !important;
    }

    .menu-grid {
        height: 65vh !important;
        grid-template-columns: repeat(3, 1fr) !important;
        grid-auto-rows: 65vh !important;
    }

    .menu-grid .premium-tile {
        height: 100% !important;
        min-height: 0 !important;
    }

    .lobby-view-header {
        width: 100% !important;
        gap: 6px !important;
    }

    .lobby-view-title {
        font-size: 12px !important;
        letter-spacing: 0.5px !important;
    }

    .lobby-back {
        padding: 4px 8px !important;
        font-size: 10px !important;
    }

    .premium-tile {
        min-height: 0 !important;
        padding: 10px 8px !important;
    }

    .tile-art {
        flex: 1 1 auto !important;
    }

    .tile-card {
        width: min(95%, 140px) !important;
    }

    /* Центрируем карты на мобиле */
    .tile-card.card-1 {
        left: 50% !important;
        top: 15% !important;
        transform: translateX(-65%) rotate(-10deg) !important;
    }

    .tile-card.card-2 {
        left: 50% !important;
        top: -5% !important;
        transform: translateX(-35%) rotate(8deg) !important;
    }

    .tile-bottom {
        padding-top: 6px !important;
    }

    .tile-kicker {
        font-size: 8px !important;
        letter-spacing: 1px !important;
    }

    .tile-title {
        font-size: 11px !important;
    }

    .tile-sub {
        font-size: 9px !important;
    }

    .tile-action {
        font-size: 9px !important;
    }

    .quickplay-grid {
        height: 65vh !important;
        gap: 8px !important;
        padding: 0 !important;
        grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
        width: 100% !important;
    }

    .quickplay-grid .premium-tile {
        height: 100% !important;
        min-height: 0 !important;
    }

    .stake-amount {
        font-size: 14px !important;
    }

    .stake-chip {
        width: 14px !important;
        height: 14px !important;
    }

    .stake-top {
        gap: 4px !important;
        margin-bottom: 4px !important;
    }
    /* Center lobby title */
    .lobby-title {
        font-size: 24px !important;
        margin-bottom: 15px !important;
        text-align: center !important;
        letter-spacing: 2px !important;
    }

    .chip-row {
        font-size: 9px !important;
        gap: 4px !important;
    }

    .chip-icon {
        width: 14px !important;
        height: 14px !important;
    }

    /* Room cards - CENTERED and full width */
    .lobby-cards {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 12px !important;
        width: 100% !important;
        padding: 0 10px !important;
        box-sizing: border-box !important;
    }

    .lobby-card {
        width: 100% !important;
        max-width: 340px !important;
        padding: 14px 18px !important;
        margin: 0 auto !important;
        border-radius: 14px !important;
    }

    .lobby-card-title {
        font-size: 15px !important;
        margin-bottom: 6px !important;
    }

    .lobby-card-sub {
        font-size: 10px !important;
        margin-bottom: 10px !important;
    }

    .lobby-input {
        font-size: 14px !important;
        padding: 10px !important;
    }

    .lobby-btn {
        padding: 12px 16px !important;
        font-size: 13px !important;
        border-radius: 20px !important;
        margin-top: 6px !important;
    }

    /* Rooms list - centered */
    #rooms-list {
        max-height: 100px !important;
        font-size: 11px !important;
        text-align: center !important;
    }


    /* --- GAME SCREEN MOBILE FIXES --- */

    /* Faster card animations - reduced duration */
    .card-wrapper {
        transition: transform 0.15s cubic-bezier(0.34, 1.2, 0.64, 1) !important;
    }

    .card-vector {
        transition: all 0.1s ease-out !important;
    }

    .card-vector:hover,
    .card-vector:active {
        transform: translateY(-20px) scale(1.03) !important;
    }

    .card-vector.selected {
        transform: translateY(-35px) scale(1.08) !important;
    }

    /* Table center - responsive for mobile */
    #table-center {
        width: 45vmin !important;
        height: 55vmin !important;
        max-width: 220px !important;
        max-height: 280px !important;
    }
    
    /* Played cards - faster animation */
    .played-card {
        transition: all 0.2s cubic-bezier(0.34, 1.2, 0.64, 1) !important;
    }
    
    /* Player positions for mobile */
    #p1 {
        top: 2vmin !important;
    }
    
    #p2 {
        left: 1vmin !important;
    }
    
    #p3 {
        right: 1vmin !important;
    }

    @keyframes cardLand {
        0% {
            transform: scale(1.15) rotate(-3deg);
            opacity: 0.6;
        }

        60% {
            transform: scale(1.05) rotate(1deg);
        }

        100% {
            transform: scale(1) rotate(0deg);
            opacity: 1;
        }
    }

    .played-card img {
        animation: cardLand 0.2s ease-out !important;
    }

    /* Optimized card sizes for mobile */
    :root {
        --card-width: 16vmin !important;
        --avatar-size: 11vmin !important;
        --font-size-name: 2.5vmin !important;
    }

    /* Hand positioning */
    #my-hand {
        height: 160px !important;
        bottom: -10px !important;
    }

    /* Scoreboard compact */
    #scoreboard {
        transform: scale(0.75) !important;
        transform-origin: top right !important;
        top: 1vmin !important;
        right: 1vmin !important;
    }

    /* Hide game log on mobile */
    #game-log {
        display: none !important;
    }

    /* Compact last trick */
    #last-trick-container {
        top: 10px !important;
        left: 10px !important;
        width: 180px !important;
        height: 130px !important;
        transform: scale(0.8) !important;
        transform-origin: top left !important;
    }

    .last-trick-label {
        font-size: 12px !important;
    }

    .last-trick-card {
        width: 70px !important;
    }

    /* Contract indicator positioning */
    #contract-indicator {
        padding: 0.8vmin 1.5vmin !important;
        font-size: 2.5vmin !important;
    }

    /* Speech bubbles - faster */
    .speech-bubble {
        transition: all 0.15s ease-out !important;
        font-size: 2.5vmin !important;
        padding: 1vmin 2vmin !important;
    }
}

/* ===== EXTRA SMALL MOBILE (iPhone SE etc) ===== */
@media (max-width: 400px) {
    .lobby-title {
        font-size: 20px !important;
    }

    .lobby-card {
        max-width: 290px !important;
        padding: 12px !important;
    }

    .lobby-card-title {
        font-size: 14px !important;
    }

    .lobby-btn {
        padding: 10px 12px !important;
        font-size: 12px !important;
    }

    :root {
        --card-width: 14vmin !important;
        --avatar-size: 10vmin !important;
    }
    
    #table-center {
        width: 40vmin !important;
        height: 50vmin !important;
        max-width: 180px !important;
        max-height: 230px !important;
    }
    
    #p1 { top: 1vmin !important; }
    #p2 { left: 0.5vmin !important; }
    #p3 { right: 0.5vmin !important; }

    #my-hand {
        height: 130px !important;
        bottom: -15px !important;
    }
}

/* ===== MOBILE LANDSCAPE ===== */
@media (max-height: 500px) and (orientation: landscape) {

    /* Fast animations in landscape too */
    .card-wrapper {
        transition: transform 0.12s cubic-bezier(0.34, 1.2, 0.64, 1) !important;
    }

    .card-vector {
        transition: all 0.08s ease-out !important;
    }

    .played-card {
        transition: all 0.15s cubic-bezier(0.34, 1.2, 0.64, 1) !important;
    }

    :root {
        --avatar-size: 14vh !important;
        --card-width: 18vh !important;
        --font-size-name: 10px !important;
    }
    
    #table-center {
        width: 35vh !important;
        height: 45vh !important;
        max-width: 200px !important;
        max-height: 260px !important;
    }

    #my-hand {
        height: 140px !important;
        bottom: -10px !important;
    }

    #p1 {
        top: 2px !important;
    }
    
    #p2 {
        left: 1vmin !important;
    }
    
    #p3 {
        right: 1vmin !important;
    }

    #scoreboard {
        transform: scale(0.65) !important;
    }

    #last-trick-container {
        display: none !important;
    }
    
    /* Compact bidding panel in landscape */
    .premium-panel {
        transform: scale(0.7) !important;
        max-width: 300px !important;
    }
}

/* ===== QUICKPLAY MODAL MOBILE ===== */
@media (max-width: 900px) {
    .quickplay-content {
        padding: 18px 20px !important;
        border-radius: 16px !important;
        max-width: 320px !important;
    }

    .stake-grid {
        gap: 8px !important;
    }

    .stake-btn {
        padding: 12px 8px !important;
    }

    .stake-amount {
        font-size: 20px !important;
    }

    .stake-win {
        font-size: 12px !important;
    }
}

/* ===== BIDDING PANEL MOBILE ===== */
@media (max-width: 900px) {
    .premium-panel {
        transform: scale(0.75) !important;
        padding: 15px 20px !important;
        width: 90vw !important;
        max-width: 350px !important;
    }

    .suits-row {
        gap: 1.5vmin !important;
        padding: 1vmin !important;
    }

    .suit-bubble {
        width: 12vmin !important;
        height: 12vmin !important;
        min-width: 42px !important;
        min-height: 42px !important;
    }

    .btn-main {
        padding: 10px 0 !important;
        font-size: 12px !important;
    }

    .bid-val {
        font-size: 4vmin !important;
    }

    .btn-adjust {
        width: 4vmin !important;
        height: 4vmin !important;
        min-width: 28px !important;
        min-height: 28px !important;
    }
}

/* ===== TOUCH OPTIMIZATION ===== */
@media (pointer: coarse) {

    /* Bigger touch targets */
    .card-vector {
        min-width: 50px !important;
        cursor: pointer !important;
        -webkit-tap-highlight-color: transparent !important;
        touch-action: manipulation !important;
        user-select: none !important;
        -webkit-user-select: none !important;
    }

    .lobby-btn,
    .stake-btn,
    .btn-main,
    .suit-bubble,
    .premium-btn,
    .btn-adjust {
        min-height: 44px !important;
        min-width: 44px !important;
        -webkit-tap-highlight-color: transparent !important;
        touch-action: manipulation !important;
        cursor: pointer !important;
    }

    /* Disable hover effects on touch - use active instead */
    .card-vector:hover {
        transform: none !important;
    }

    .card-vector:active {
        transform: translateY(-25px) scale(1.05) !important;
        transition: transform 0.05s ease-out !important;
    }

    .card-vector.selected {
        transform: translateY(-40px) scale(1.1) !important;
    }
    
    /* Fix hover "sticking" on touch devices */
    @media (hover: none) {
        .card-vector:hover,
        .lobby-btn:hover,
        .stake-btn:hover,
        .btn-main:hover,
        .premium-tile:hover {
            transform: none !important;
            box-shadow: inherit !important;
        }
    }
    
    /* Prevent text selection on game elements */
    #game-container,
    #my-hand,
    .player-slot,
    .card-wrapper,
    #lobby-screen,
    .lobby-view {
        user-select: none !important;
        -webkit-user-select: none !important;
        -webkit-touch-callout: none !important;
    }
}

/* ===== iOS SPECIFIC FIXES ===== */
@supports (-webkit-touch-callout: none) {
    /* iOS only */
    body, #game-container, #lobby-screen, #welcome-screen {
        /* Use -webkit-fill-available as fallback */
        min-height: -webkit-fill-available;
    }
    
    /* Fix iOS bounce scrolling */
    html {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }
}

/* Shake animation for invalid move */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-6px); }
    80% { transform: translateX(6px); }
}