/**
 * Mobile-Specific Enhancements
 * Touch targets, gestures, and mobile UX improvements
 */

/* ==================== TOUCH TARGETS ==================== */
/* Apple recommends 44x44px minimum for touch targets */

/* Increase zone button touch targets on mobile */
@media (max-width: 768px) {
  .zone-btn {
    min-width: 48px;
    min-height: 48px;
    padding: 12px;
  }
  
  .float-btn {
    min-width: 48px;
    min-height: 48px;
  }
  
  .action-btn,
  .tool-btn,
  .filter-chip {
    min-height: 44px;
    padding: 12px 16px;
  }
  
  /* Player controls */
  .player-btn {
    min-width: 44px;
    min-height: 44px;
  }
  
  .player-btn.main {
    min-width: 52px;
    min-height: 52px;
  }
  
  /* Transport buttons in Lab */
  .transport-btn {
    min-width: 52px;
    min-height: 52px;
  }
  
  #lab-play-btn {
    min-width: 60px;
    min-height: 60px;
  }
  
  /* Region controls */
  .region-play,
  .region-delete {
    min-width: 44px;
    min-height: 44px;
  }
  
  /* Modal close buttons */
  .modal-close,
  .expanded-close {
    min-width: 44px;
    min-height: 44px;
    font-size: 20px;
  }
}

/* ==================== HOVER STATE FALLBACKS ==================== */
/* Mobile doesn't have hover, so ensure active states work */

@media (hover: none) {
  .sample-card:active {
    transform: scale(0.98);
    border-color: var(--zone-primary);
  }
  
  .zone-btn:active {
    background: rgba(168, 85, 247, 0.3);
  }
  
  .action-btn:active {
    background: rgba(168, 85, 247, 0.2);
    transform: scale(0.98);
  }
  
  .filter-chip:active {
    background: var(--cyan);
    color: var(--void);
  }
  
  /* Remove hover-only effects */
  .sample-card::before,
  .sample-card::after {
    display: none;
  }
}

/* ==================== MODAL IMPROVEMENTS ==================== */
/* Ensure modals fit on small screens */

@media (max-width: 480px) {
  .modal-content,
  .pack-content {
    max-height: 90vh;
    overflow-y: auto;
    margin: 16px;
    width: calc(100% - 32px);
  }
  
  .export-slices-modal .modal-content {
    padding: 24px 20px;
    max-width: calc(100% - 32px);
  }
  
  .pack-card {
    width: 160px;
    height: 240px;
  }
  
  .reveal-cards {
    gap: 8px;
  }
  
  .reveal-card {
    width: 90px;
    height: 130px;
  }
  
  /* Expanded card view */
  .expanded-content {
    padding: 16px;
    max-height: 90vh;
    overflow-y: auto;
  }
  
  .expanded-card {
    max-width: 100%;
  }
  
  .expanded-actions {
    flex-direction: column;
    gap: 10px;
  }
  
  .expanded-actions .action-btn {
    width: 100%;
    justify-content: center;
  }
}

/* ==================== LAB MOBILE IMPROVEMENTS ==================== */

@media (max-width: 768px) {
  .lab-editor {
    padding: 12px;
    gap: 12px;
  }
  
  .lab-editor-header {
    padding: 12px 16px;
  }
  
  .lab-file-name {
    max-width: 180px;
    font-size: 12px;
  }
  
  .lab-transport {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 12px;
  }
  
  .lab-waveform-container {
    padding: 12px;
  }
  
  .lab-waveform {
    height: 100px;
  }
  
  /* Make drop zone more touch-friendly */
  .lab-dropzone {
    min-height: 150px;
    padding: 32px;
  }
}

/* ==================== FILTER PANEL MOBILE ==================== */

@media (max-width: 600px) {
  .filter-panel {
    position: fixed;
    bottom: 80px;
    left: 0;
    right: 0;
    top: auto;
    max-height: 60vh;
    overflow-y: auto;
    border-radius: 16px 16px 0 0;
    padding: 20px;
    padding-bottom: 32px;
  }
  
  .filter-chips {
    flex-wrap: wrap;
  }
  
  .filter-chip {
    flex: 0 0 auto;
  }
  
  .filter-actions {
    position: sticky;
    bottom: 0;
    background: var(--surface);
    padding-top: 16px;
    margin-top: 16px;
  }
}

/* ==================== LIBRARY MOBILE IMPROVEMENTS ==================== */

@media (max-width: 600px) {
  .lib-song-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  
  .lib-song-info {
    width: 100%;
  }
  
  .lib-song-actions {
    width: 100%;
    justify-content: flex-end;
  }
  
  /* Mini player adjustments */
  .unified-player {
    width: 100%;
    max-width: 100%;
    left: 0;
    transform: none;
    border-radius: 16px 16px 0 0;
  }
  
  .player-track-info {
    min-width: unset;
    flex: 1;
  }
}

/* ==================== SAFE AREA INSETS ==================== */
/* For devices with notches (iPhone X+) */

@supports (padding: env(safe-area-inset-bottom)) {
  .float-zones {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
  
  .unified-player {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
  
  .install-banner {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}

/* ==================== INSTALL BANNER ==================== */

.install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.95), rgba(124, 58, 237, 0.95));
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  z-index: 1000;
  backdrop-filter: blur(10px);
  animation: slide-up 0.3s ease;
}

.install-banner.hidden {
  display: none;
}

@keyframes slide-up {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.install-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.install-icon {
  font-size: 28px;
}

.install-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.install-text strong {
  font-size: 14px;
  color: white;
}

.install-text span {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
}

.install-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.install-btn {
  background: white;
  color: #7c3aed;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: transform 0.2s;
}

.install-btn:active {
  transform: scale(0.95);
}

.install-dismiss {
  background: transparent;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  opacity: 0.8;
}

/* Hide on desktop */
@media (min-width: 769px) {
  .install-banner {
    max-width: 400px;
    left: auto;
    right: 20px;
    bottom: 20px;
    border-radius: 12px;
  }
}

/* ==================== REDUCED MOTION ==================== */

@media (prefers-reduced-motion: reduce) {
  .install-banner {
    animation: none;
  }
  
  * {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  /* Allow essential layout transitions */
  .modal-content,
  .item-modal,
  .vault-inventory-panel {
    transition: opacity 0.1s ease !important;
  }
}

/* ==================== VAULT GAME MOBILE ==================== */

@media (max-width: 768px) {
  /* Touch-friendly tap targets (44px minimum) */
  .vault-game .hero-nav-btn,
  .vault-game .hero-dot,
  .vault-game .carousel-arrow,
  .vault-game .view-toggle-btn,
  .vault-game .inventory-action-btn,
  .vault-game .marketplace-tab,
  .vault-game .filter-btn,
  .vault-game .item-modal-close,
  .vault-game .modal-action-btn {
    min-width: 44px;
    min-height: 44px;
  }
  
  /* Hero carousel swipe hint */
  .hero-carousel::after {
    content: '';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    pointer-events: none;
    animation: swipe-hint 2s ease-in-out infinite;
  }
  
  @keyframes swipe-hint {
    0%, 100% { opacity: 0; transform: translateY(-50%) translateX(0); }
    50% { opacity: 0.6; transform: translateY(-50%) translateX(-8px); }
  }
  
  /* Hide swipe hint after first interaction */
  .hero-carousel.touched::after {
    display: none;
  }
  
  /* Scrollable marketplace tabs */
  .marketplace-tabs {
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
  }
  
  .marketplace-tab {
    scroll-snap-align: start;
  }
}

/* ==================== SWIPE TO DISMISS MODAL ==================== */

@media (max-width: 768px) {
  .item-modal-backdrop {
    touch-action: none;
  }
  
  .item-modal {
    touch-action: pan-y;
  }
  
  /* Drag handle for sheet-style modal */
  .item-modal::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: var(--game-border);
    border-radius: 2px;
    z-index: 10;
  }
  
  .item-modal.dragging {
    transition: none !important;
  }
}

/* ==================== PULL TO REFRESH INDICATOR ==================== */

.vault-pull-indicator {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%) translateY(-100%);
  background: var(--game-bg-panel);
  border: 1px solid var(--game-gold);
  border-radius: 24px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--game-gold);
  z-index: 200;
  opacity: 0;
  transition: transform 0.2s, opacity 0.2s;
  pointer-events: none;
}

.vault-pull-indicator.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(8px);
}

.vault-pull-indicator.refreshing .pull-icon {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ==================== MOBILE PERFORMANCE OPTIMIZATIONS ==================== */

@media (max-width: 768px) {
  /* GPU acceleration for smooth scrolling */
  .marketplace-grid,
  .carousel-track,
  .inventory-grid {
    will-change: scroll-position;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Reduce paint complexity */
  .inventory-slot.rarity-legendary,
  .inventory-slot.rarity-mythic,
  .carousel-item.rarity-legendary,
  .carousel-item.rarity-mythic,
  .item-card.rarity-legendary,
  .item-card.rarity-mythic {
    box-shadow: 0 0 10px var(--glow-legendary);
  }
  
  /* Simpler gradients */
  .hero-artwork-overlay {
    background: linear-gradient(90deg, rgba(12, 12, 18, 0.9) 0%, transparent 60%);
  }
  
  /* Contain layout shifts */
  .item-card,
  .carousel-item,
  .inventory-slot {
    contain: layout style;
  }
  
  /* Lazy load off-screen content */
  .carousel-item:not(:nth-child(-n+4)) {
    content-visibility: auto;
    contain-intrinsic-size: 160px 220px;
  }
  
  .item-card:not(:nth-child(-n+6)) {
    content-visibility: auto;
    contain-intrinsic-size: 150px 200px;
  }
}

/* ==================== LANDSCAPE PHONE ==================== */

@media (max-height: 500px) and (orientation: landscape) {
  .float-top {
    padding: 8px 16px;
  }
  
  .float-zones {
    padding: 8px 12px;
  }
  
  .zone-btn {
    padding: 8px;
  }
  
  .expanded-content {
    flex-direction: row;
    max-height: 90vh;
  }
  
  .lab-waveform {
    height: 80px;
  }
}
