/* ============================================================
   RESPONSIVE STYLESHEET - Steam-like Game Platform
   Breakpoints:
     Desktop:  > 1200px  (full sidebar, multi-column grids)
     Tablet:   768px - 1200px  (collapsed sidebar, 2-col grid)
     Mobile:   < 768px  (sidebar hidden, single column)
   ============================================================ */

/* ------------------------------------------------------------
   Desktop (> 1200px)
   Default styles — no overrides needed here.
   Sidebar is visible at full 240px width.
   Grids use 3-4 columns for game cards.
   ------------------------------------------------------------ */

/* ------------------------------------------------------------
   Tablet (max-width: 1200px)
   - Sidebar collapses to icon-only (60px)
   - Content reflows to fill space
   - Game grids go to 2 columns
   - Typography slightly reduced
   ------------------------------------------------------------ */
@media (max-width: 1200px) {
  :root {
    --space-lg: 20px;
    --space-xl: 28px;
    --space-2xl: 40px;
  }

  /* Sidebar collapses automatically via .collapsed class,
     but we ensure layout adapts here */
  .main-content {
    margin-left: var(--sidebar-collapsed-width);
  }

  .topbar {
    left: var(--sidebar-collapsed-width);
  }

  /* Grid goes to 2 columns */
  .game-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-cols-4 {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Hero slightly shorter */
  .hero-section {
    height: 50vh;
    min-height: 350px;
    padding: 60px 30px;
  }

  .hero-section h1 {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
  }

  /* Footer grid stacks brand column */
  .footer-content {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-xl);
  }

  /* Admin panel responsive */
  .admin-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .admin-sidebar {
    width: var(--sidebar-collapsed-width);
  }

}

/* ------------------------------------------------------------
   Mobile (max-width: 768px)
   - Sidebar hidden, hamburger toggle appears
   - Single-column layout throughout
   - Touch-friendly sizing
   - Adjusted spacing and typography
   ------------------------------------------------------------ */
@media (max-width: 768px) {
  :root {
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;
    --space-2xl: 32px;
    --space-3xl: 48px;
    --topbar-height: 48px;
  }

  /* Show hamburger toggle */
  .sidebar-toggle {
    display: flex;
  }

  /* Sidebar moves off-screen */
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width);
    transition:
      transform var(--transition-base),
      width var(--transition-base);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  /* Collapsed state on mobile doesn't matter — it's hidden */
  .sidebar.collapsed {
    width: var(--sidebar-width);
    transform: translateX(-100%);
  }

  .sidebar.collapsed.mobile-open {
    transform: translateX(0);
  }

  /* Show close button on mobile */
  .sidebar-close {
    display: block;
  }

  /* Collapsed content styles reset for mobile open */
  .sidebar.mobile-open .sidebar-brand,
  .sidebar.mobile-open .nav-text,
  .sidebar.mobile-open .sidebar-social {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar.mobile-open .nav-item {
    justify-content: flex-start;
    padding: var(--space-sm) var(--space-md);
    margin: 2px var(--space-sm);
  }

  /* Overlay visible when sidebar is open */
  .sidebar-overlay {
    display: block;
  }

  /* Main content full width */
  .main-content {
    margin-left: 0;
  }

  .topbar {
    left: 0;
    padding: 0 var(--space-md);
  }

  /* Offset for hamburger button */
  .topbar-logo {
    margin-left: auto;
  }

  /* Hero section */
  .hero-section {
    height: 45vh;
    min-height: 300px;
    max-height: none;
    padding: 50px 20px;
  }

  .hero-section h1 {
    font-size: 1.5rem;
  }

  .hero-section p {
    font-size: var(--font-size-base);
  }

  /* Single-column game grid */
  .game-grid {
    grid-template-columns: 1fr;
    gap: var(--space-md);
  }

  .grid-cols-2,
  .grid-cols-3,
  .grid-cols-4 {
    grid-template-columns: 1fr;
  }

  /* Game cards: horizontal layout option for mobile */
  .game-card.search-result-card {
    flex-direction: row;
  }

  .game-card.search-result-card .game-card-image {
    width: 120px;
    min-width: 120px;
    aspect-ratio: 1;
  }

  .game-card.search-result-card .game-card-body {
    padding: var(--space-sm);
  }

  /* Section headers stack */
  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }

  /* Footer stacks completely */
  .footer-content {
    grid-template-columns: 1fr;
    gap: var(--space-xl);
  }

  .footer-bottom {
    flex-direction: column;
    gap: var(--space-md);
    text-align: center;
  }

  /* Buttons: touch-friendly minimum size (44px) */
  .btn {
    min-height: 44px;
    padding: 12px 20px;
  }

  .btn-sm {
    min-height: 36px;
    padding: 8px 14px;
  }

  .btn-lg {
    min-height: 52px;
    padding: 14px 28px;
  }

  .btn-icon {
    width: 44px;
    height: 44px;
  }

  /* Modals: nearly full screen on mobile */
  .modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }

  .modal {
    max-width: 100%;
    max-height: 90vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transform: translateY(100%);
  }

  .modal-backdrop.active .modal {
    transform: translateY(0);
  }

  .modal-body {
    padding: var(--space-md);
  }

  /* Forms */
  .form-input,
  .form-textarea,
  .form-select {
    padding: 12px 14px;
    font-size: 16px; /* Prevent zoom on iOS */
  }

  /* Breadcrumbs: truncate long paths */
  .breadcrumb {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .breadcrumb-separator:last-child {
    display: none;
  }

  /* Tags wrap naturally */
  .tag-list {
    flex-wrap: wrap;
  }

  /* Admin panel stacks */
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .admin-sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar-height);
    width: var(--sidebar-width);
    height: calc(100vh - var(--topbar-height));
    transform: translateX(-100%);
    z-index: var(--z-sidebar);
    transition: transform var(--transition-base);
  }

  .admin-sidebar.mobile-open {
    transform: translateX(0);
  }

  /* Game detail page stacks */

  /* Tables scroll horizontally */
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 calc(-1 * var(--space-md));
    padding: 0 var(--space-md);
  }

  table {
    min-width: 600px;
  }

  /* Pagination controls */
  .pagination {
    justify-content: center;
    flex-wrap: wrap;
    gap: var(--space-xs);
  }

  .pagination-item {
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Toast notifications: full width at bottom */
  .toast-container {
    left: var(--space-sm);
    right: var(--space-sm);
    bottom: var(--space-sm);
  }

  .toast {
    width: 100%;
  }
}

/* ------------------------------------------------------------
   Small Mobile (max-width: 480px)
   Extra-small screens: further reduce spacing and sizes
   ------------------------------------------------------------ */
@media (max-width: 480px) {
  :root {
    --font-size-base: 0.8125rem;
    --font-size-sm: 0.75rem;
    --space-md: 10px;
    --space-lg: 14px;
  }

  /* Reduce hero height further */
  .hero-section {
    height: 40vh;
    min-height: 260px;
  }

  .hero-section h1 {
    font-size: 1.3rem;
  }

  /* Even tighter game cards */
  .game-card-body {
    padding: var(--space-sm);
  }

  .game-card-meta {
    flex-wrap: wrap;
    gap: var(--space-sm);
  }

  /* Compact buttons */
  .btn {
    min-height: 40px;
    padding: 10px 16px;
    font-size: var(--font-size-sm);
  }

  /* Section titles smaller */
  .section-title {
    font-size: var(--font-size-xl);
  }

  .page-section {
    padding: var(--space-xl) 0;
  }
}

/* ------------------------------------------------------------
   Height-constrained viewports (short screens)
   ------------------------------------------------------------ */
@media (max-height: 600px) {
  .hero-section {
    height: 70vh;
  }

  .sidebar-nav {
    padding: var(--space-xs) 0;
  }

  .sidebar-nav .nav-item {
    padding: var(--space-xs) var(--space-md);
  }
}

/* ------------------------------------------------------------
   Hover-capable devices only
   Avoid sticky hover states on touch devices
   ------------------------------------------------------------ */
@media (hover: none) {
  .game-card:hover {
    transform: none;
    box-shadow: none;
  }

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

  .btn:hover {
    box-shadow: none;
  }

  .btn:active {
    transform: scale(0.96);
  }
}

/* ------------------------------------------------------------
   Print styles
   ------------------------------------------------------------ */
@media print {
  .sidebar,
  .topbar,
  .sidebar-toggle,
  .sidebar-overlay,
  .site-footer,
  .hero-section .btn,
  .game-card-footer {
    display: none !important;
  }

  .main-content {
    margin-left: 0;
    padding-top: 0;
  }

  body {
    background: white;
    color: black;
  }

  .game-card {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ccc;
  }
}

/* ------------------------------------------------------------
   Reduced motion preference
   Disables animations for users who prefer reduced motion
   ------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .game-card:hover {
    transform: none;
  }

  .modal {
    transform: none;
  }

  .sidebar {
    transition: none;
  }
}
