/* =========================
   MOBILE AUTO-SCALING & RESPONSIVE DESIGN
   ========================= */

/* Auto-scaling for mobile displays */
@media (max-width: 600px) {
  /* Root scaling variables for mobile */
  :root {
    --mobile-scale: 1;
    --mobile-scale-small: 0.9;
    --mobile-scale-tiny: 0.8;
  }
  
  /* Auto-scale game container */
  #game-container {
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    overflow: hidden;
    position: relative;
    transform-origin: top left;
  }
  
  /* Auto-scale game elements */
  .game-table,
  .table-container {
    width: 100%;
    height: auto;
    max-width: 100vw;
    transform-origin: center center;
  }
  
  /* Auto-scale cards */
  .card {
    transform-origin: center center;
    transition: transform 0.3s ease;
  }
  
  /* Auto-scale player areas */
  .player-area,
  .dealer-area {
    width: 100%;
    max-width: 100vw;
    padding: 0 10px;
  }
  
  /* Auto-scale HUD elements */
  .game-hud,
  .hud-container {
    width: 100%;
    max-width: 100vw;
    padding: 0 15px;
  }
  
  /* Auto-scale buttons */
  .game-button,
  .action-button {
    transform-origin: center center;
    min-height: 44px; /* Touch-friendly minimum */
  }
  
  /* Auto-scale text */
  .game-text,
  .player-name,
  .chip-count {
    font-size: clamp(0.8rem, 3vw, 1.2rem);
    line-height: 1.4;
  }
  
  /* Auto-scale modals */
  .modal,
  .modal-content {
    width: 95vw;
    max-width: 95vw;
    transform-origin: center center;
  }
  
  /* Dynamic scaling for different mobile sizes */
  @media (max-width: 480px) {
    :root {
      --mobile-scale: 0.95;
    }
    
    #game-container {
      transform: scale(0.95);
      transform-origin: top center;
    }
    
    .card {
      width: 52px;
      height: 78px;
      min-width: 52px;
      min-height: 78px;
    }
  }
  
  @media (max-width: 360px) {
    :root {
      --mobile-scale: 0.9;
    }
    
    #game-container {
      transform: scale(0.9);
      transform-origin: top center;
    }
    
    .card {
      width: 48px;
      height: 72px;
      min-width: 48px;
      min-height: 72px;
    }
  }
  
  @media (max-width: 320px) {
    :root {
      --mobile-scale: 0.85;
    }
    
    #game-container {
      transform: scale(0.85);
      transform-origin: top center;
    }
    
    .card {
      width: 44px;
      height: 66px;
      min-width: 44px;
      min-height: 66px;
    }
  }
  
  /* Safe area support for modern mobile devices */
  @supports (padding: max(0px)) {
    #game-container {
      padding-left: max(12px, env(safe-area-inset-left));
      padding-right: max(12px, env(safe-area-inset-right));
      padding-top: max(12px, env(safe-area-inset-top));
      padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
    
    #betting-controls,
    .betting-controls {
      bottom: max(120px, env(safe-area-inset-bottom) + 105px);
    }
    
    .action-bar {
      bottom: max(0px, env(safe-area-inset-bottom));
      padding-left: max(10px, env(safe-area-inset-left) + 5px);
      padding-right: max(10px, env(safe-area-inset-right) + 5px);
      padding-bottom: max(15px, env(safe-area-inset-bottom) + 5px);
    }
  }
}

/* =========================
   MOBILE-ONLY ENHANCEMENTS
   (desktop unaffected - these rules only apply on screens <= 600px)
   ========================= */
@media (max-width: 600px) {
  html, body { -webkit-text-size-adjust: 100%; }
  body { overscroll-behavior-y: contain; }
  * { -webkit-tap-highlight-color: transparent; }

  #game-container {
    padding: 12px;
    min-height: calc(var(--app-vh, 1vh) * 100);
  }

  /* Enhanced mobile card sizing */
  .card { 
    width: 56px; 
    height: 84px; 
    min-width: 56px;
    min-height: 84px;
  }
  
  /* Mobile card suit sizing - proportional to card size */
  .card .suit {
    font-size: 1.5rem !important;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
  }
  
  /* Mobile card corner numbers - proportional to card size */
  .card::before,
  .card::after {
    font-size: 0.9rem !important;
    line-height: 1;
  }
  
  .card::before {
    top: 3px;
    left: 3px;
  }
  
  .card::after {
    bottom: 3px;
    right: 3px;
  }
  
  .hand { 
    gap: 4px; 
    min-height: 90px; 
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .player-spot { 
    min-width: 160px; 
    min-height: 200px; 
    padding: 10px; 
    margin: 5px;
  }
  
  .player-spot.active-player { 
    transform: none; 
    border-width: 3px;
  }

  /* Enhanced mobile action bar */
  .action-bar {
    left: 0; 
    right: 0;
    bottom: 0;
    padding: 15px 10px;
    gap: 12px;
    background: rgba(15,15,15,0.98);
    border-top: 2px solid #333;
    flex-wrap: wrap;
    backdrop-filter: blur(15px);
    justify-content: center;
    align-items: center;
    z-index: 9999;
    min-height: 80px;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.8);
  }

  /* Larger touch targets for mobile */
  .action-bar button,
  .betting-controls button {
    min-height: 48px;
    min-width: 48px;
    touch-action: manipulation;
    font-size: 1rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
  }

  .action-bar > button:not(.hidden) {
    flex: 1 1 calc(50% - 10px);
    font-size: 1rem;
    padding: 12px 14px;
    border-radius: 8px;
    max-width: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
  }

  /* Enhanced betting controls for mobile - FORCE VISIBLE */
  .betting-controls {
    width: 100%;
    justify-content: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    background: rgba(0,0,0,0.9);
    backdrop-filter: blur(10px);
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
  }

  .betting-controls input {
    width: 120px;
    font-size: 1.1rem;
    padding: 12px;
    border-radius: 8px;
    border: 2px solid #333;
    background: #222;
    color: #fff;
    min-height: 48px;
  }

  #place-bet { 
    padding: 12px 18px; 
    font-size: 1.1rem; 
    border-radius: 8px;
    background: var(--gold);
    color: var(--black);
    font-weight: bold;
    min-height: 48px;
    min-width: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
  }

  /* Enhanced mobile chat */
  #chat-panel { 
    left: 10px; 
    right: 10px; 
    width: auto; 
    bottom: calc(100px + env(safe-area-inset-bottom));
    border-radius: 12px 12px 0 0;
  }

  /* Enhanced mobile leaderboard */
  .leaderboard {
    right: 10px;
    width: 180px;
    max-height: 200px;
    overflow-y: auto;
    border-radius: 12px;
    background: rgba(0,0,0,0.9);
    backdrop-filter: blur(10px);
  }

  /* Enhanced mobile modals */
  .modal-content {
    width: 94%;
    max-width: 520px;
    margin-bottom: env(safe-area-inset-bottom);
    border-radius: 16px;
    padding: 1.5rem;
  }

  /* Mobile-specific table header */
  .table-header {
    flex-direction: column;
    gap: 10px;
    padding: 15px;
  }

  .table-actions {
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
  }

  .table-actions button {
    min-height: 44px;
    min-width: 44px;
    font-size: 0.9rem;
    padding: 10px 12px;
  }

  /* Mobile-specific dealer area */
  .dealer-area {
    margin-bottom: 30px;
    padding: 10px;
  }

  /* Mobile-specific players area */
  .players-area {
    gap: 15px;
    padding: 10px;
  }

  /* Mobile-specific deck */
  .deck {
    width: 60px;
    height: 84px;
    margin: 0 auto;
  }

  /* Mobile-specific waiting list */
  .waiting-list {
    margin: 15px 0;
    padding: 15px;
    background: rgba(0,0,0,0.7);
    border-radius: 12px;
  }

  .waiting-list h2 {
    font-size: 1.1rem;
    margin-bottom: 10px;
  }

  /* Mobile-specific message element */
  #message {
    padding: 10px;
    margin: 10px 0;
    background: rgba(0,0,0,0.7);
    border-radius: 8px;
    text-align: center;
  }

  /* Mobile-specific round result */
  #round-result {
    padding: 10px;
    margin: 10px 0;
    background: rgba(0,0,0,0.7);
    border-radius: 8px;
    text-align: center;
  }

  /* Mobile-specific chips count */
  #chips-count {
    font-size: 1.1rem;
    font-weight: bold;
    text-align: center;
    padding: 8px;
    background: rgba(0,0,0,0.7);
    border-radius: 8px;
  }

  /* Mobile-specific season badge */
  #season-badge {
    bottom: 15px;
    right: 15px;
    font-size: 12px;
    padding: 6px 12px;
  }

  /* Keyboard open state */
  body.kb-open .action-bar { 
    transform: translateY(120%); 
    pointer-events: none; 
  }
}

/* Enhanced mobile shop experience */
@media (max-width: 600px) {
  .skins-modal-content {
    width: 95%;
    max-width: none;
    margin: 10px;
    border-radius: 16px;
  }

  .skins-grid {
    grid-template-columns: 1fr;
    gap: 15px;
    margin: 15px 0;
  }

  .skin-card.v2 {
    padding: 15px;
    border-radius: 16px;
  }

  .skin-card.v2 .skin-row {
    grid-template-columns: 1fr;
    gap: 15px;
    text-align: center;
  }

  .skin-preview3d {
    width: 100%;
    height: 160px;
    margin: 0 auto 15px auto;
  }

  .card3d {
    width: 100px;
    height: 140px;
  }

  .skin-actions {
    justify-content: center;
    gap: 10px;
  }

  .skin-actions button {
    min-height: 44px;
    min-width: 80px;
    font-size: 1rem;
    padding: 12px 16px;
    border-radius: 8px;
  }

  .cases-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }

  .case-card {
    padding: 15px;
    border-radius: 12px;
    flex-direction: column;
    text-align: center;
    gap: 15px;
  }

  .case-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto;
  }

  .case-actions {
    justify-content: center;
  }

  .case-open {
    min-height: 44px;
    min-width: 100px;
    font-size: 1rem;
    padding: 12px 18px;
    border-radius: 8px;
  }
}

/* Coarse pointers: relax hover effects */
@media (hover: none) and (pointer: coarse) {
  body[data-card-skin] #game-container .card:hover {
    transform: translateY(-1px) scale(1.015);
    transition: transform .15s ease;
  }
  
  /* Disable hover effects on mobile */
  .skin-card.v2:hover .card3d:not(.flipped) {
    transform: translate(-50%, -50%);
  }
  
  .skin-card.v2:hover .card3d.flipped {
    transform: translate(-50%, -50%) rotateY(180deg);
  }
}
