/* Mobile-optimized CSS for My Story Wish
   Follows mobile-first design principles and touch-friendly interactions */

/* ===== MOBILE BASE STYLES ===== */
@media (max-width: 768px) {
  /* Touch-friendly base styles */
  * {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
  }

  /* Improved text rendering on mobile */
  body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }

  /* Prevent zoom on input focus and ensure readable text */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  input[type="tel"],
  input[type="url"],
  textarea,
  select {
    font-size: 16px !important;
  }

  /* Ensure minimum text size for readability */
  body {
    font-size: 16px;
  }

  .mobile-button {
    font-size: 16px;
  }

  .mobile-input,
  .mobile-textarea,
  .mobile-select {
    font-size: 16px;
  }
}

/* ===== MOBILE COMPONENTS ===== */

/* Mobile Button Styles */
.mobile-button {
  position: relative;
  overflow: hidden;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.mobile-button:active {
  transform: scale(0.98);
  -webkit-transform: scale(0.98);
}

.mobile-button:disabled {
  transform: none;
  -webkit-transform: none;
}

/* Mobile Card Styles */
.mobile-card {
  transition: all 0.2s ease-out;
  -webkit-transition: all 0.2s ease-out;
}

.mobile-card.touch-feedback:active {
  transform: scale(0.98);
  -webkit-transform: scale(0.98);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Mobile Input Styles */
.mobile-input,
.mobile-textarea,
.mobile-select {
  transition: all 0.2s ease-out;
  -webkit-transition: all 0.2s ease-out;
}

.mobile-input:focus,
.mobile-textarea:focus,
.mobile-select:focus {
  transform: translateY(-1px);
  -webkit-transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.15);
}

/* Mobile Toggle Switch */
.mobile-toggle {
  transition: all 0.2s ease-out;
  -webkit-transition: all 0.2s ease-out;
}

.mobile-toggle:active {
  transform: scale(0.95);
  -webkit-transform: scale(0.95);
}

.mobile-toggle-thumb {
  transition: transform 0.2s ease-out;
  -webkit-transition: transform 0.2s ease-out;
}

/* Mobile Loading Spinner */
.loading-spinner {
  animation: spin 1s linear infinite;
  -webkit-animation: spin 1s linear infinite;
}

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

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

/* Mobile Toast Animations */
.mobile-slide-up {
  animation: slideUp 0.3s ease-out;
  -webkit-animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(100px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@-webkit-keyframes slideUp {
  from {
    -webkit-transform: translateY(100px);
    opacity: 0;
  }
  to {
    -webkit-transform: translateY(0);
    opacity: 1;
  }
}

/* Mobile Modal Animations */
.mobile-modal {
  animation: fadeIn 0.3s ease-out;
  -webkit-animation: fadeIn 0.3s ease-out;
}

.mobile-modal-panel {
  animation: slideUpModal 0.3s ease-out;
  -webkit-animation: slideUpModal 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@-webkit-keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

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

/* Mobile Tab Animations */
.mobile-tab {
  transition: all 0.2s ease-out;
  -webkit-transition: all 0.2s ease-out;
}

.mobile-tab:active {
  transform: scale(0.95);
  -webkit-transform: scale(0.95);
}

.mobile-tab-panel {
  animation: fadeInTab 0.3s ease-out;
  -webkit-animation: fadeInTab 0.3s ease-out;
}

@keyframes fadeInTab {
  from {
    opacity: 0;
    transform: translateY(10px);
    -webkit-transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
    -webkit-transform: translateY(0);
  }
}

@-webkit-keyframes fadeInTab {
  from {
    opacity: 0;
    -webkit-transform: translateY(10px);
  }
  to {
    opacity: 1;
    -webkit-transform: translateY(0);
  }
}

/* Mobile List Item Animations */
.mobile-list-item {
  transition: all 0.2s ease-out;
  -webkit-transition: all 0.2s ease-out;
}

.mobile-list-item:active {
  background-color: #f3f4f6;
  transform: scale(0.98);
  -webkit-transform: scale(0.98);
}

/* Mobile Search Animations */
.mobile-search-input:focus {
  transform: translateY(-1px);
  -webkit-transform: translateY(-1px);
}

/* Mobile Pull-to-Refresh */
.mobile-pull-refresh {
  transition: transform 0.3s ease-out;
  -webkit-transition: transform 0.3s ease-out;
}

.mobile-pull-refresh.active {
  transform: translateY(0);
  -webkit-transform: translateY(0);
}

/* Mobile Bottom Sheet (Legacy) */
.mobile-bottom-sheet {
  transition: transform 0.3s ease-out;
  -webkit-transition: transform 0.3s ease-out;
}

.mobile-bottom-sheet.active {
  transform: translateY(0);
  -webkit-transform: translateY(0);
}

/* ===== NATIVE BOTTOM SHEETS ===== */
/* iOS/Android style bottom sheets for confirmations and actions */

.bottom-sheet-container {
  /* Ensure it's above everything */
  z-index: 9999;
}

.bottom-sheet-backdrop {
  transition: opacity 0.3s ease-out;
  -webkit-transition: opacity 0.3s ease-out;
}

.bottom-sheet-panel {
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  -webkit-transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  will-change: transform;
  /* Safe area for iPhone notch/home indicator */
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Utility class for safe area padding */
.pb-safe {
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Smooth spring animation for native feel */
.bottom-sheet-panel.translate-y-0 {
  transform: translateY(0) !important;
  -webkit-transform: translateY(0) !important;
}

/* Touch feedback for sheet buttons */
.bottom-sheet-panel button:active,
.bottom-sheet-panel a:active {
  transform: scale(0.98);
  -webkit-transform: scale(0.98);
}

/* Drag handle styling */
.bottom-sheet-panel .cursor-grab {
  touch-action: pan-y;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Sheet content scrolling */
.bottom-sheet-panel .overflow-y-auto {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Prevent iOS rubber-banding on sheet */
.bottom-sheet-container {
  overscroll-behavior: none;
}

/* Action sheet specific styles (iOS style separated cards) */
.bottom-sheet-panel.action-sheet {
  background: transparent;
}

/* Mobile Floating Action Button */
.mobile-fab {
  transition: all 0.2s ease-out;
  -webkit-transition: all 0.2s ease-out;
}

.mobile-fab:active {
  transform: scale(0.9);
  -webkit-transform: scale(0.9);
}

/* ===== MOBILE NAVIGATION ===== */

/* Mobile Bottom Navigation */
.mobile-bottom-nav {
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.95);
}

.mobile-nav-item {
  transition: all 0.2s ease-out;
  -webkit-transition: all 0.2s ease-out;
}

.mobile-nav-item:active {
  transform: scale(0.9);
  -webkit-transform: scale(0.9);
}

/* Mobile Drawer - Uses pure Tailwind classes, no custom CSS needed */

.mobile-drawer-item {
  transition: all 0.2s ease-out;
  -webkit-transition: all 0.2s ease-out;
}

.mobile-drawer-item:active {
  transform: translateX(4px);
  -webkit-transform: translateX(4px);
}

/* Mobile Tab Bar */
.mobile-tab-bar {
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.95);
}

.mobile-tab-action {
  transition: all 0.2s ease-out;
  -webkit-transition: all 0.2s ease-out;
}

.mobile-tab-action:active {
  transform: scale(0.9);
  -webkit-transform: scale(0.9);
}

/* ===== MOBILE FORMS ===== */

/* Mobile Form Enhancements */
.mobile-form {
  animation: fadeInUp 0.4s ease-out;
  -webkit-animation: fadeInUp 0.4s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
    -webkit-transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
    -webkit-transform: translateY(0);
  }
}

@-webkit-keyframes fadeInUp {
  from {
    opacity: 0;
    -webkit-transform: translateY(20px);
  }
  to {
    opacity: 1;
    -webkit-transform: translateY(0);
  }
}

/* Mobile Form Field Groups */
.mobile-form-group {
  animation: fadeInUp 0.4s ease-out;
  -webkit-animation: fadeInUp 0.4s ease-out;
}

.mobile-form-group:nth-child(1) { animation-delay: 0.1s; }
.mobile-form-group:nth-child(2) { animation-delay: 0.2s; }
.mobile-form-group:nth-child(3) { animation-delay: 0.3s; }
.mobile-form-group:nth-child(4) { animation-delay: 0.4s; }
.mobile-form-group:nth-child(5) { animation-delay: 0.5s; }

/* Mobile Character/Story Forms */
.mobile-character-option,
.mobile-length-option,
.mobile-personality-tag {
  transition: all 0.2s ease-out;
  -webkit-transition: all 0.2s ease-out;
}

.mobile-character-option:active,
.mobile-length-option:active,
.mobile-personality-tag:active {
  transform: scale(0.95);
  -webkit-transform: scale(0.95);
}

.mobile-character-option input:checked + *,
.mobile-length-option input:checked + *,
.mobile-personality-tag input:checked + * {
  background-color: #9B8CFF;
  color: white;
}

/* ===== MOBILE UTILITIES ===== */

/* Touch Feedback */
.touch-feedback {
  transition: all 0.15s ease-out;
  -webkit-transition: all 0.15s ease-out;
}

.touch-feedback:active {
  transform: scale(0.95);
  -webkit-transform: scale(0.95);
  opacity: 0.8;
}

/* Touch Target */
.touch-target {
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Ensure all interactive elements meet touch target requirements */
.mobile-button,
.mobile-nav-item,
.mobile-tab-action,
.mobile-character-option,
.mobile-length-option,
.mobile-personality-tag {
  min-height: 44px;
  min-width: 44px;
}

/* Safe Area Support */
.safe-area-top {
  padding-top: env(safe-area-inset-top);
}

.safe-area-bottom {
  padding-bottom: env(safe-area-inset-bottom);
}

.safe-area-left {
  padding-left: env(safe-area-inset-left);
}

.safe-area-right {
  padding-right: env(safe-area-inset-right);
}

/* Mobile Loading Overlay */
.mobile-loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-loading-content {
  text-align: center;
}

/* Mobile Error States */
.mobile-error-text {
  animation: shake 0.5s ease-in-out;
  -webkit-animation: shake 0.5s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@-webkit-keyframes shake {
  0%, 100% { -webkit-transform: translateX(0); }
  25% { -webkit-transform: translateX(-5px); }
  75% { -webkit-transform: translateX(5px); }
}

/* Mobile Success States */
.mobile-success {
  animation: bounce 0.6s ease-in-out;
  -webkit-animation: bounce 0.6s ease-in-out;
}

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-10px); }
  60% { transform: translateY(-5px); }
}

@-webkit-keyframes bounce {
  0%, 20%, 50%, 80%, 100% { -webkit-transform: translateY(0); }
  40% { -webkit-transform: translateY(-10px); }
  60% { -webkit-transform: translateY(-5px); }
}

/* ===== MOBILE RESPONSIVE BREAKPOINTS ===== */

/* Small Mobile (320px - 480px) */
@media (max-width: 480px) {
  .mobile-card {
    margin: 0.5rem;
    border-radius: 1rem;
  }

  .mobile-button {
    padding: 0.75rem 1.5rem;
    font-size: 0.875rem;
  }

  .mobile-input,
  .mobile-textarea,
  .mobile-select {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
  }
}

/* Medium Mobile (481px - 768px) */
@media (min-width: 481px) and (max-width: 768px) {
  .mobile-card {
    margin: 1rem;
  }

  .mobile-button {
    padding: 1rem 2rem;
  }
}

/* Large Mobile / Small Tablet (769px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
  .mobile-card {
    margin: 1.5rem;
  }

  .mobile-bottom-nav {
    display: none;
  }
}

/* ===== MOBILE ACCESSIBILITY ===== */

/* Focus indicators for keyboard navigation */
.mobile-button:focus,
.mobile-input:focus,
.mobile-textarea:focus,
.mobile-select:focus {
  outline: 2px solid #9B8CFF;
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .mobile-button {
    border: 2px solid currentColor;
  }

  .mobile-input,
  .mobile-textarea,
  .mobile-select {
    border: 2px solid currentColor;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .mobile-card {
    background-color: #1f2937;
    border-color: #374151;
  }

  .mobile-input,
  .mobile-textarea,
  .mobile-select {
    background-color: #1f2937;
    border-color: #374151;
    color: #f9fafb;
  }

  .mobile-bottom-nav {
    background: rgba(31, 41, 55, 0.95);
    border-color: #374151;
  }
}
