/* ===================================
   AniFind - Mobile Styles
   =================================== */

/* ===================================
   Mobile Optimizations
   =================================== */

@media (max-width: 768px) {
  body {
    padding: 12px;
  }

  .app-shell {
    border-radius: 20px;
    padding: 20px 16px 16px;
  }

  /* Header */
  h1 {
    font-size: 1.3rem;
    /* Force solid color on mobile if gradient doesn't work */
    -webkit-text-fill-color: var(--text);
  }
  
  /* Support gradient where possible */
  @supports (-webkit-background-clip: text) {
    h1 {
      -webkit-text-fill-color: transparent;
    }
  }

  .logo-image {
    width: 40px;
    height: 40px;
  }

  .greeting {
    font-size: 1rem;
  }

  .subtitle {
    font-size: 0.88rem;
  }

  /* Show Hamburger Menu on Mobile */
  .hamburger-menu {
    display: flex;
  }

  /* Hide Desktop Navigation Tabs */
  .nav-tabs {
    display: none;
  }

  /* Search Bar */
  .search-bar {
    padding: 10px;
    gap: 8px;
  }

  .search-input-wrapper {
    flex: 1 1 100%;
  }

  .search-input {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 12px 14px 12px 44px; /* More padding for better touch */
  }

  .search-actions {
    flex: 1;
    width: 100%;
  }

  .btn {
    flex: 1;
    padding: 10px 14px;
    font-size: 0.85rem;
    justify-content: center;
  }

  /* Status Bar */
  .status-bar {
    font-size: 0.82rem;
    padding: 10px 12px;
  }

  /* Toast Notifications on Mobile */
  .toast-container {
    bottom: 16px;
    right: 16px;
    left: 16px;
    align-items: center;
  }

  .toast {
    min-width: unset;
    max-width: unset;
    width: 100%;
  }

  /* Results Grid */
  .results-container {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  /* Cards */
  .card {
    border-radius: 16px;
    position: relative;
    transition: transform 0.3s ease-out;
  }

  /* Swipe actions indicator */
  .card-swipe-actions {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 20px;
    background: linear-gradient(to left, var(--accent), transparent);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  .card.swiping .card-swipe-actions {
    opacity: 1;
  }

  /* Card being swiped */
  .card.swiping {
    transition: none;
  }

  .card-cover {
    height: 200px;
  }

  .card-body {
    padding: 14px;
    gap: 10px;
  }

  .card-title {
    font-size: 0.95rem;
  }

  .card-title span {
    font-size: 0.75rem;
  }

  .score-pill {
    padding: 5px 10px;
    font-size: 0.8rem;
  }

  .meta-badge {
    font-size: 0.7rem;
    padding: 3px 8px;
  }

  .description {
    font-size: 0.82rem;
    -webkit-line-clamp: 2;
  }

  .tag {
    font-size: 0.68rem;
    padding: 3px 8px;
  }

  .card-footer-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .tags-row {
    width: 100%;
  }

  .card-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .btn-watched,
  .btn-plan,
  .btn-move,
  .btn-rate,
  .btn-share,
  .btn-remove {
    flex: 1 1 calc(50% - 3px);
    min-width: 100px;
    min-height: 44px; /* Better touch target */
    padding: 10px 12px;
    font-size: 0.8rem;
    justify-content: center;
    font-weight: 600;
  }

  /* Collection Headers */
  .collection-header h2 {
    font-size: 1.15rem;
  }

  .collection-actions {
    flex-direction: column;
    width: 100%;
    align-items: stretch;
  }

  .sort-select {
    width: 100%;
    min-width: unset;
  }

  .collection-actions .btn {
    width: 100%;
  }

  /* Stats Page - CRITICAL FIX */
  .stats-container {
    padding: 0;
  }

  .stats-container h2 {
    font-size: 1.3rem;
    margin-bottom: 20px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .stat-card {
    padding: 16px;
  }

  .stat-card-large {
    flex-direction: row;
  }

  .stat-card-wide {
    grid-column: span 1;
  }

  .stat-icon {
    font-size: 2rem;
  }

  .stat-value {
    font-size: 1.8rem;
  }

  .stat-label {
    font-size: 0.85rem;
  }

  .genre-bar {
    flex-wrap: wrap;
  }

  .genre-name {
    min-width: 80px;
    font-size: 0.85rem;
  }

  .genre-count {
    font-size: 0.8rem;
  }

  .activity-item {
    padding: 10px;
  }

  .activity-icon {
    font-size: 1.3rem;
  }

  .activity-title {
    font-size: 0.9rem;
  }

  .activity-meta {
    font-size: 0.75rem;
  }

  /* Modal & Rating */
  .modal {
    padding: 16px;
  }

  .modal-content {
    max-width: 100%;
    margin: auto;
  }

  .modal-header {
    padding: 16px;
  }

  .modal-header h3 {
    font-size: 1.1rem;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-body p {
    font-size: 0.88rem;
  }

  /* Rating Stars - FIX OVERFLOW */
  .star-rating {
    gap: 4px;
    padding: 0 8px;
  }

  .star {
    font-size: 1.6rem;
  }

  .star:hover,
  .star.active {
    transform: scale(1.1);
  }

  .rating-value {
    font-size: 1.3rem;
  }

  /* JJK Banner */
  .jjk-banner {
    font-size: 0.8rem;
    padding: 10px 12px;
  }

  /* Footer */
  .app-footer {
    margin-top: 30px;
    padding-top: 20px;
  }

  .footer-content {
    flex-direction: column;
    text-align: center;
  }

  .footer-text {
    font-size: 0.85rem;
  }

  .footer-badge {
    font-size: 0.7rem;
  }

  /* Empty State */
  .empty-state,
  .error-state {
    padding: 60px 20px;
    text-align: center;
  }

  .empty-state-icon,
  .error-state-icon {
    font-size: 3.5rem;
    margin-bottom: 16px;
    animation: float 3s ease-in-out infinite;
  }

  @keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
  }

  .empty-state strong,
  .error-state strong {
    font-size: 1.1rem;
    display: block;
    margin-bottom: 8px;
  }

  .empty-state p {
    font-size: 0.9rem;
    color: var(--muted);
    margin-top: 8px;
  }

  /* Domain Expansion */
  .domain-circle {
    width: 300px;
    height: 300px;
  }

  .domain-circle::before {
    width: 200px;
    height: 200px;
  }

  .domain-circle::after {
    width: 100px;
    height: 100px;
  }

  .domain-symbols {
    width: 300px;
    height: 300px;
  }

  .domain-symbols span {
    font-size: 2rem;
  }

  .domain-text {
    font-size: 1.5rem;
  }

  /* Personal Rating Display */
  .personal-rating {
    font-size: 0.75rem;
    padding: 3px 8px;
  }
}

/* ===================================
   Small Mobile (< 400px)
   =================================== */

@media (max-width: 400px) {
  body {
    padding: 8px;
  }

  .app-shell {
    padding: 16px 12px 12px;
  }

  h1 {
    font-size: 1.15rem;
  }

  .logo-image {
    width: 36px;
    height: 36px;
  }

  .greeting {
    font-size: 0.9rem;
  }

  .subtitle {
    font-size: 0.82rem;
  }

  .search-bar {
    padding: 8px;
  }

  .btn {
    padding: 8px 12px;
    font-size: 0.8rem;
  }

  .card-cover {
    height: 180px;
  }

  .card-body {
    padding: 12px;
  }

  .modal-header h3 {
    font-size: 1rem;
  }

  /* Smaller stars for tiny screens */
  .star {
    font-size: 1.4rem;
  }

  /* Adjust domain expansion */
  .domain-circle {
    width: 250px;
    height: 250px;
  }

  .domain-symbols {
    width: 250px;
    height: 250px;
  }

  .domain-symbols span {
    font-size: 1.5rem;
  }

  .domain-text {
    font-size: 1.1rem;
  }

  /* Stats adjustments */
  .stat-icon {
    font-size: 1.8rem;
  }

  .stat-value {
    font-size: 1.6rem;
  }
}

/* ===================================
   Tablet (768px - 1024px)
   =================================== */

@media (min-width: 769px) and (max-width: 1024px) {
  .results-container {
    grid-template-columns: repeat(2, 1fr);
  }

  .card-cover {
    height: 220px;
  }
}

/* ===================================
   Large Desktop (> 1200px)
   =================================== */

@media (min-width: 1200px) {
  .results-container {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  }

  .card-cover {
    height: 240px;
  }
}

/* ===================================
   Touch Optimizations
   =================================== */

@media (hover: none) and (pointer: coarse) {
  /* Larger touch targets */
  .btn {
    min-height: 44px;
  }

  .nav-tab {
    min-height: 44px;
  }

  /* Remove hover effects on touch devices */
  .card:hover {
    transform: none;
  }

  .card:active {
    transform: scale(0.98);
  }

  .btn:hover {
    transform: none;
  }

  .btn:active {
    transform: scale(0.95);
    opacity: 0.9;
  }

  .card:active {
    transform: scale(0.98);
    opacity: 0.95;
  }

  /* Better tap highlighting */
  .btn,
  .nav-tab,
  .card {
    -webkit-tap-highlight-color: rgba(124, 58, 237, 0.2);
  }

  /* Visual feedback for interactive elements */
  .nav-drawer-item:active,
  .star:active {
    transform: scale(0.95);
    opacity: 0.8;
  }

  /* Improve button press feedback */
  .btn-watched:active,
  .btn-plan:active,
  .btn-rate:active,
  .btn-share:active {
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3);
  }
}

/* ===================================
   Landscape Mode (Mobile)
   =================================== */

@media (max-height: 500px) and (orientation: landscape) {
  .app-shell {
    padding: 16px;
  }

  .greeting {
    font-size: 0.9rem;
    margin-bottom: 4px;
  }

  .subtitle {
    font-size: 0.8rem;
  }

  .results-container {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
  }

  .card-cover {
    height: 140px;
  }

  .domain-circle {
    width: 200px;
    height: 200px;
  }

  .domain-symbols {
    width: 200px;
    height: 200px;
  }

  .domain-text {
    font-size: 1.2rem;
  }
}

/* ===================================
   Safe Area (for devices with notches)
   =================================== */

@supports (padding: max(0px)) {
  body {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .app-footer {
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }

  .toast-container {
    bottom: max(16px, env(safe-area-inset-bottom));
  }
}

/* ===================================
   Improve Scrolling Performance
   =================================== */

@media (max-width: 768px) {
  /* Enable momentum scrolling on iOS */
  .results-container,
  .tab-content {
    -webkit-overflow-scrolling: touch;
  }

  /* Reduce animation complexity on mobile */
  .card-enter {
    animation-duration: 0.3s;
  }

  /* Simplify shadows on mobile for better performance */
  .card {
    box-shadow: 0 4px 16px rgba(3, 6, 21, 0.4);
  }

  .card:hover {
    box-shadow: 0 6px 24px rgba(124, 58, 237, 0.25);
  }
}
