/**
 * CrazyGames-Style Layout
 * Applied site-wide: left sidebar navigation + content area.
 * On the homepage: hero banner + horizontal scroll rows.
 * On other pages: sidebar wraps category/tag/single content.
 *
 * @package GameHub
 */

/* =============================================
   USE THEME'S GLOBAL LEFT SIDEBAR ON ALL LAYOUTS
   Hide the CrazyGames-specific sidebar; the global
   .left-sidebar from sidebar-nav.css handles navigation.
   ============================================= */

/* Hide the CG-specific sidebar — theme sidebar is used instead */
.cg-sidebar {
  display: none !important;
}

/* Hide the header category bar — left sidebar handles categories */
body.homepage-crazygames .category-bar {
  display: none;
}

/* =============================================
   LAYOUT STRUCTURE
   ============================================= */
.cg-layout {
  display: flex;
  min-height: calc(100vh - 80px);
  background: var(--background-color);
}

/* =============================================
   LEFT SIDEBAR — Collapsed icons-only, expands on hover
   ============================================= */
.cg-sidebar {
  position: sticky;
  top: 64px;
  left: 0;
  width: 60px;
  min-width: 60px;
  height: calc(100vh - 64px);
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--card-background);
  border-right: 1px solid var(--border-color);
  padding: 0.75rem 0;
  z-index: 20;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              min-width 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.25s ease;
}

.cg-sidebar:hover {
  width: 220px;
  min-width: 220px;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
}

.cg-sidebar::-webkit-scrollbar {
  width: 0;
}

.cg-sidebar:hover::-webkit-scrollbar {
  width: 4px;
}

.cg-sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.cg-sidebar::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.cg-sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 0.375rem;
}

.cg-sidebar:hover .cg-sidebar-nav {
  padding: 0 0.5rem;
}

.cg-sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text-color);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  justify-content: center;
}

.cg-sidebar:hover .cg-sidebar-item {
  padding: 0.625rem 0.875rem;
  justify-content: flex-start;
}

.cg-sidebar-item:hover {
  background: var(--primary-15, rgba(99, 102, 241, 0.1));
  color: var(--primary-color);
}

.cg-sidebar-item.active {
  background: var(--primary-15, rgba(99, 102, 241, 0.1));
  color: var(--primary-color);
  font-weight: 600;
}

.cg-sidebar-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.cg-sidebar-label {
  opacity: 0;
  width: 0;
  overflow: hidden;
  transition: opacity 0.2s ease 0s, width 0.25s ease;
}

.cg-sidebar:hover .cg-sidebar-label {
  opacity: 1;
  width: auto;
  transition: opacity 0.2s ease 0.1s, width 0.25s ease;
}

.cg-sidebar-divider {
  height: 1px;
  background: var(--border-color);
  margin: 0.5rem 0.625rem;
}

.cg-sidebar:hover .cg-sidebar-divider {
  margin: 0.5rem 0.875rem;
}

/* Tooltip on collapsed sidebar items */
.cg-sidebar-item {
  position: relative;
}

.cg-sidebar-item::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--card-background);
  color: var(--text-color);
  padding: 0.375rem 0.75rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color);
  z-index: 100;
}

.cg-sidebar-item:hover::after {
  opacity: 1;
}

/* Hide tooltip when sidebar is expanded */
.cg-sidebar:hover .cg-sidebar-item::after {
  opacity: 0 !important;
  display: none;
}

/* =============================================
   MAIN CONTENT AREA
   ============================================= */
.cg-main {
  flex: 1;
  min-width: 0;
  padding: 1.25rem 1.75rem 3rem;
  overflow-x: clip; /* clip instead of hidden — preserves sticky positioning */
}

/* Full Width layout override — let cg-main span the full available area */
.layout-fullwidth .cg-main {
  max-width: 100%;
}

/* Browse pages (.browse-page) inside CrazyGames layout:
   Remove extra container padding since .cg-main handles it. */
.cg-main .browse-page .browse-hero {
  margin: -1.25rem -1.75rem 0;
  border-radius: 0;
}

.cg-main .browse-container {
  max-width: 100%;
  padding: 1.5rem 0 0;
}

/* Single game layout inside CrazyGames */
.cg-main .single-game-layout {
  max-width: 100%;
  padding: 0;
}

/* Fix game-sidebar sticky & height inside CrazyGames layout */
.cg-main .game-sidebar {
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  align-self: start;
}

/* Page wrapper inside CrazyGames */
.cg-main .page-wrapper .page-hero {
  margin: -1.25rem -1.75rem 0;
}

.cg-main .page-wrapper .page-container-full {
  max-width: 100%;
  padding: 2rem 0;
}

/* =============================================
   HERO BANNER GRID
   ============================================= */
.cg-hero {
  margin-bottom: 1.75rem;
}

.cg-hero-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 0.75rem;
  min-height: 340px;
  max-height: 420px;
}

.cg-hero-card {
  position: relative;
  display: block;
  border-radius: 16px;
  overflow: hidden;
  text-decoration: none;
  color: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.cg-hero-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.4s ease;
}

.cg-hero-card:hover img {
  transform: scale(1.04);
}

.cg-hero-card:hover {
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
}

.cg-hero-primary {
  grid-column: 1;
  grid-row: 1 / 3;
  min-height: 340px;
}

.cg-hero-secondary {
  min-height: 160px;
}

.cg-hero-secondary:nth-child(2) { grid-column: 2; grid-row: 1; }
.cg-hero-secondary:nth-child(3) { grid-column: 3; grid-row: 1; }
.cg-hero-secondary:nth-child(4) { grid-column: 2; grid-row: 2; }
.cg-hero-secondary:nth-child(5) { grid-column: 3; grid-row: 2; }

/* Hero gradient overlay */
.cg-hero-gradient {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.3) 40%, transparent 65%);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 1.25rem;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.cg-hero-card:hover .cg-hero-gradient {
  opacity: 1;
}

.cg-hero-primary .cg-hero-gradient {
  padding: 1.75rem;
  opacity: 1; /* always show title on the large primary card */
}

.cg-hero-info {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.cg-tag {
  display: inline-block;
  background: var(--primary-color);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  width: fit-content;
}

.cg-hero-name {
  font-size: 0.9375rem;
  font-weight: 700;
  color: #ffffff;
  margin: 0;
  line-height: 1.3;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7);
}

.cg-hero-primary .cg-hero-name {
  font-size: 1.5rem;
}

.cg-hero-rating {
  font-size: 0.75rem;
  color: #fbbf24;
  font-weight: 600;
}

.cg-hero-primary .cg-hero-rating {
  font-size: 0.875rem;
}

.cg-hero-play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--primary-color);
  color: #fff;
  padding: 0.625rem 1.25rem;
  border-radius: 50px;
  font-size: 0.875rem;
  font-weight: 700;
  opacity: 0;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.cg-hero-card:hover .cg-hero-play {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.cg-hero-secondary .cg-hero-play {
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
}

.cg-hero-secondary .cg-hero-play svg {
  width: 14px;
  height: 14px;
}

/* =============================================
   ROW SECTIONS (Game Rows)
   ============================================= */
.cg-row-section {
  margin-bottom: 1.75rem;
}

.cg-row-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.875rem;
}

.cg-row-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-color);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-left: 13px;
  position: relative;
}

.cg-row-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 1em;
  border-radius: 3px;
  background: var(--primary-gradient, linear-gradient(180deg, #6366f1, #8b5cf6));
}

.cg-row-icon {
  font-size: 1.1rem;
}

.cg-show-more {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 13px 5px 11px;
  border: 1.5px solid var(--border-color, rgba(255,255,255,0.12));
  border-radius: 999px;
  color: var(--text-color, #fff);
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.cg-show-more:hover {
  border-color: var(--primary-color, #6366f1);
  background: rgba(99, 102, 241, 0.1);
  color: var(--primary-color, #8b8cf8);
}

/* Horizontal scroll wrapper */
.cg-row-scroll {
  position: relative;
  margin: 0 -1.75rem;
  padding: 0 1.75rem;
}

.cg-row {
  display: flex;
  gap: 0.875rem;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: smooth;
  padding-bottom: 0.75rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

.cg-row::-webkit-scrollbar {
  height: 6px;
}

.cg-row::-webkit-scrollbar-track {
  background: transparent;
}

.cg-row::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

.cg-row::-webkit-scrollbar-thumb:hover {
  background: var(--text-60);
}

/* Card sizing within CG rows */
.cg-row .game-card.in-row {
  width: 185px;
  border-radius: 12px;
}

.cg-row .game-card.in-row .game-card-image {
  border-radius: 12px;
}

/* Always show title on row cards */
.cg-row .game-card.in-row .game-card-gradient-overlay {
  opacity: 1;
}

/* Recently played row – slightly smaller */
#cg-recent-row .game-card.in-row {
  width: 155px;
}

/* =============================================
   ALL GAMES GRID
   ============================================= */
.cg-all-section {
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-color);
}

.cg-all-grid.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 0.875rem;
}

/* Infinite scroll loader */
.cg-loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 2rem;
  color: var(--text-60);
  font-size: 0.875rem;
}

.cg-spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: cgSpin 0.8s linear infinite;
}

@keyframes cgSpin {
  to { transform: rotate(360deg); }
}

.cg-end {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--text-40, var(--text-60));
  font-size: 0.875rem;
}

/* =============================================
   SEO CONTENT SECTION
   ============================================= */
.cg-seo-section {
  border-top: 1px solid var(--border-color);
  padding-top: 1.5rem;
}

.cg-seo-card {
  background: var(--card-background);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 2rem 2.5rem;
}

.cg-seo-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-color);
  margin: 0 0 1.25rem;
  padding-bottom: 0.875rem;
  border-bottom: 2px solid var(--border-color);
}

/* =============================================
   MOBILE CATEGORY BAR
   ============================================= */
.cg-mobile-cats {
  display: none;
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card-background);
  border-top: 1px solid var(--border-color);
  z-index: 50;
  padding: 0.5rem 0;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
}

.cg-mobile-cats-scroll {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding: 0.25rem 1rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.cg-mobile-cats-scroll::-webkit-scrollbar {
  display: none;
}

.cg-mob-cat {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.875rem;
  border-radius: 50px;
  background: var(--background-color);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.cg-mob-cat:hover,
.cg-mob-cat.active {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: #fff;
}

/* =============================================
   RESPONSIVE — LARGE SCREENS (1440px+)
   ============================================= */
@media (min-width: 1440px) {
  .cg-main {
    max-width: 1380px; /* prevent unbounded stretch on ultra-wide monitors */
  }

  .cg-hero-grid {
    max-height: 500px;
    grid-template-columns: 1.3fr 1fr 1fr;
  }

  .cg-hero-primary {
    min-height: 400px;
  }

  .cg-hero-secondary {
    min-height: 200px;
  }
}

@media (min-width: 1600px) {
  .cg-hero-grid {
    max-height: 560px;
  }

  .cg-hero-primary {
    min-height: 440px;
  }

  .cg-hero-secondary {
    min-height: 225px;
  }

  .cg-all-grid.games-grid {
    grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  }
}

/* =============================================
   RESPONSIVE — TABLET
   ============================================= */
@media (max-width: 1200px) {
  .cg-sidebar {
    width: 56px;
    min-width: 56px;
  }

  .cg-sidebar:hover {
    width: 200px;
    min-width: 200px;
  }

  .cg-hero-grid {
    max-height: 360px;
  }

  .cg-hero-primary {
    min-height: 280px;
  }

  .cg-hero-secondary {
    min-height: 130px;
  }
}

@media (max-width: 1024px) {
  .cg-mobile-cats {
    display: block;
  }

  .cg-main {
    padding: 1rem 1.25rem 5rem; /* extra bottom for sticky bar */
  }

  .cg-hero-grid {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    max-height: none;
  }

  .cg-hero-primary {
    grid-column: 1 / -1;
    grid-row: 1;
    min-height: 220px;
    max-height: 280px;
  }

  .cg-hero-secondary:nth-child(2) { grid-column: 1; grid-row: 2; }
  .cg-hero-secondary:nth-child(3) { grid-column: 2; grid-row: 2; }
  .cg-hero-secondary:nth-child(4) { display: none; }
  .cg-hero-secondary:nth-child(5) { display: none; }

  .cg-row-scroll {
    margin: 0 -1.25rem;
    padding: 0 1.25rem;
  }
}

/* =============================================
   RESPONSIVE — MOBILE
   ============================================= */
@media (max-width: 768px) {
  .cg-main {
    padding: 0.75rem 1rem 5rem;
  }

  .cg-hero-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    gap: 0.5rem;
  }

  .cg-hero-primary {
    grid-column: 1;
    grid-row: 1;
    min-height: 200px;
    max-height: 240px;
  }

  .cg-hero-secondary:nth-child(2),
  .cg-hero-secondary:nth-child(3) {
    display: none;
  }

  .cg-hero-gradient {
    opacity: 1; /* Always show on mobile */
  }

  .cg-hero-play {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.85);
  }

  .cg-hero-primary .cg-hero-name {
    font-size: 1.125rem;
  }

  .cg-row-title {
    font-size: 1.0625rem;
  }

  .cg-row-scroll {
    margin: 0 -1rem;
    padding: 0 1rem;
  }

  .cg-row {
    gap: 0.625rem;
  }

  .cg-row .game-card.in-row {
    width: 140px;
  }

  #cg-recent-row .game-card.in-row {
    width: 120px;
  }

  .cg-all-grid.games-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.625rem;
  }

  .cg-seo-card {
    padding: 1.5rem 1.25rem;
    border-radius: 12px;
  }

  .cg-seo-title {
    font-size: 1.375rem;
  }
}

@media (max-width: 480px) {
  .cg-hero-primary {
    min-height: 170px;
    max-height: 200px;
  }

  .cg-row .game-card.in-row {
    width: 120px;
  }

  .cg-all-grid.games-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }

  .cg-mob-cat {
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
  }
}
