/**
 * Responsive Styles - Mobile First Approach
 */

/* ==================== MOBILE (< 768px) ==================== */
@media (max-width: 767px) {
  /* Show mobile D-pad */
  .mobile-dpad {
    display: block;
  }

  /* Navigation - FIX: Title alignment */
  .nav {
    padding: 0 var(--spacing-md);
    flex-wrap: wrap; /* Allow wrapping if needed */
    justify-content: center; /* Center items */
    gap: var(--spacing-sm);
  }

  .nav__logo {
    font-size: 1rem; /* Smaller font */
    flex: 0 0 100%; /* Full width on its own row */
    text-align: center; /* Center text */
    order: -1; /* Put logo first */
  }

  .nav__controls {
    gap: var(--spacing-xs);
    flex-wrap: wrap;
    justify-content: center;
  }

  .nav__btn {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 0.7rem;
    white-space: nowrap;
  }

  /* Game Canvas - Touch optimized */
  .game {
    padding: var(--spacing-md);
    padding-bottom: 220px; /* Tăng space cho D-pad */
  }

  .game__canvas {
    width: 100%;
    height: auto;
    max-height: 50vh;
    touch-action: pan-y pinch-zoom; /* Better touch handling */
    cursor: pointer;
  }

  /* Progress */
  .progress {
    top: 90px; /* Adjust for wrapped nav */
    width: 95%;
    padding: var(--spacing-sm) var(--spacing-md);
  }

  /* Story Card - Better mobile experience */
  .story-card {
    width: 95vw;
    max-height: 90vh;
    padding: var(--spacing-md);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .story-card__header {
    position: sticky;
    top: 0;
    background: var(--color-bg-panel);
    z-index: 10;
    padding-bottom: var(--spacing-md);
    margin-bottom: var(--spacing-md);
  }

  .story-card__title {
    font-size: 1.125rem;
    line-height: 1.3;
  }

  .story-card__close {
    width: 44px; /* Larger touch target */
    height: 44px;
    font-size: 1.25rem;
    flex-shrink: 0;
  }

  .story-card__content {
    font-size: 0.9rem;
    line-height: 1.6;
  }

  /* ✅ FIX: Story images on mobile - Maintain aspect ratio */
  .story-card__images {
    grid-template-columns: 1fr;
    gap: var(--spacing-md);
  }

  .story-card__img {
    aspect-ratio: 16/9;
    max-height: 250px;
    object-fit: contain;
    background: var(--color-bg-darker);
  }

  /* Wishes Section - Mobile optimized */
  .wishes {
    padding: var(--spacing-md);
  }

  .wishes__grid {
    grid-template-columns: 1fr;
    gap: var(--spacing-md);
  }

  .wish-form {
    padding: var(--spacing-md);
  }

  .wish-form__input,
  .wish-form__textarea,
  .wish-form__select {
    font-size: 16px; /* Prevent zoom on iOS */
  }

  /* Divider */
  .wishes__divider-text {
    font-size: 1rem;
    padding: 0 var(--spacing-md);
  }

  /* Mobile D-pad - Centered at bottom */
  .mobile-dpad {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    bottom: 30px;
    display: block !important;
    opacity: 1;
    visibility: visible;
  }

  /* Đảm bảo D-pad không bị che */
  .game__canvas {
    margin-bottom: 220px;
  }

  /* Tutorial - Mobile optimized */
  .tutorial__content {
    padding: var(--spacing-lg);
    max-height: 95vh;
  }

  .tutorial__title {
    font-size: 1.5rem;
  }

  .tutorial__step {
    flex-direction: column;
    gap: var(--spacing-md);
    text-align: center;
  }

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

  .tutorial__step-content h3 {
    font-size: 1rem;
  }

  .tutorial__step-content p {
    font-size: 0.875rem;
  }

  .tutorial__footer {
    flex-direction: column;
    gap: var(--spacing-sm);
  }

  .tutorial__btn {
    width: 100%;
    padding: var(--spacing-md);
  }
}

/* ==================== TABLET (768px - 1023px) ==================== */
@media (min-width: 768px) and (max-width: 1023px) {
  /* Navigation */
  .nav {
    padding: 0 var(--spacing-lg);
  }

  /* Game */
  .game {
    padding: var(--spacing-lg);
  }

  /* Story Panel */
  .story {
    height: 45vh;
  }

  .story__images {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Wishes */
  .wishes__grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-lg);
  }

  /* Optional: Show D-pad for tablets */
  .mobile-dpad {
    display: block;
  }

  .game__canvas {
    max-width: 90%;
    max-height: 60vh;
  }

  .story-card {
    width: 85vw;
    max-height: 85vh;
  }

  .story-card__images {
    grid-template-columns: repeat(2, 1fr); /* 2 columns on tablet */
  }

  .story-card__img {
    aspect-ratio: 4/3;
    object-fit: contain;
  }
}

/* ==================== DESKTOP (1024px - 1439px) ==================== */
@media (min-width: 1024px) {
  /* Game */
  .game {
    padding: var(--spacing-2xl);
  }

  /* Story Panel - Side by side option */
  .story--side {
    left: auto;
    right: 0;
    width: 40vw;
    height: calc(100vh - 60px);
    border-top: none;
    border-left: 2px solid var(--color-accent);
    transform: translateX(100%);
  }

  .story--side.story--active {
    transform: translateX(0);
  }

  /* Wishes */
  .wishes__grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ==================== WIDE DESKTOP (>= 1440px) ==================== */
@media (min-width: 1440px) {
  /* Container max-width */
  .wishes {
    padding: var(--spacing-2xl) calc((100vw - 1400px) / 2);
  }

  /* Larger fonts */
  .wishes__title {
    font-size: 3rem;
  }

  .wishes__subtitle {
    font-size: 1.25rem;
  }
}

/* ==================== LANDSCAPE MODE ==================== */
@media (orientation: landscape) and (max-height: 600px) {
  /* Adjust story panel height */
  .story {
    height: 80vh;
  }

  /* Hide unnecessary spacing */
  .game {
    padding: var(--spacing-md);
    min-height: auto;
  }

  /* Adjust progress bar */
  .progress {
    top: 65px;
  }

  .story-card {
    max-height: 95vh;
    padding: var(--spacing-sm) var(--spacing-md);
  }

  .story-card__images {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .story-card__img {
    aspect-ratio: 16/9;
    max-height: 180px;
  }

  .game__canvas {
    max-height: 70vh;
  }
}

/* ==================== HIGH DPI SCREENS ==================== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  /* Adjust border widths for sharper appearance */
  .nav,
  .game__canvas,
  .story {
    border-width: 1px;
  }

  .nav__btn,
  .story__btn,
  .wish-form__submit {
    border-width: 1px;
  }
}

/* ==================== DARK MODE SUPPORT ==================== */
@media (prefers-color-scheme: dark) {
  /* Already dark by default, but can add adjustments here */
}

/* ==================== PRINT STYLES ==================== */
@media print {
  /* Hide interactive elements */
  .nav,
  .mobile-dpad,
  .replay-btn,
  .loading,
  .game {
    display: none !important;
  }

  /* Show content sections */
  .story,
  .wishes {
    display: block !important;
    position: static;
    height: auto;
    transform: none;
  }

  /* Adjust colors for print */
  body {
    background: white;
    color: black;
  }

  .wish-card {
    border: 1px solid #ccc;
    page-break-inside: avoid;
  }
}

/* ==================== TOUCH DEVICE OPTIMIZATIONS ==================== */
@media (hover: none) and (pointer: coarse) {
  /* Larger touch targets */
  .dpad-btn {
    min-width: 50px;
    min-height: 50px;
    -webkit-tap-highlight-color: rgba(83, 225, 255, 0.3);
  }

  /* Disable hover effects on touch */
  .dpad-btn:hover {
    transform: none;
  }

  /* Better active states for touch */
  .dpad-btn:active {
    transform: scale(0.9);
    background: var(--color-accent);
    color: var(--color-bg-dark);
  }

  /* Ensure D-pad is always visible on touch devices */
  .mobile-dpad {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
  }
}
@media (max-width: 767px) {
  .loading {
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    justify-content: center;
    align-items: center;
  }
  .loading__logo,
  .loading__text {
    text-align: center;
    width: 100%;
  }
  .loading__bar-container {
    width: 90vw; /* Cho thanh loading rộng hơn trên mobile */
    max-width: 300px;
  }
}
