/**
 * 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;
}

/* =============================================
   FEATURED GAMES — DISTINCT SPOTLIGHT MOSAIC
   One large 2×2 "spotlight" tile with square tiles flowing around it.
   Borderless and shadow-free — set apart from the plain game rows /
   all-games grid below it by a soft brand-tinted wash and an
   accented header rather than a hard panel.
   ============================================= */
.cg-hero {
  position: relative;
  margin-bottom: 2.25rem;
}

/* Section header with a gradient accent rule extending to the right */
.cg-hero-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 1.15rem;
}

.cg-hero-head::after {
  content: "";
  flex: 1;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(
    to right,
    color-mix(in srgb, var(--primary-color, #667eea) 45%, transparent),
    transparent
  );
}

.cg-hero-head-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  color: #422006;
  flex-shrink: 0;
}

.cg-hero-head-icon svg {
  width: 18px;
  height: 18px;
}

.cg-hero-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text-color, #fff);
  flex-shrink: 0;
}

/* Square mosaic grid — scales to any number of featured games.
   grid-auto-flow: dense lets the smaller tiles backfill the row the
   2×2 spotlight leaves open. */
.cg-hero-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  grid-auto-flow: dense;
  gap: 0.85rem;
}

.cg-hero-card {
  position: relative;
  display: block;
  aspect-ratio: 1 / 1; /* square tiles */
  border-radius: 16px;
  overflow: hidden;
  text-decoration: none;
  color: #fff;
  background: #1a1a1a;
  isolation: isolate; /* contain z-index for play button + badge */
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1),
              box-shadow 0.35s ease;
  will-change: transform;
}

.cg-hero-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 36px color-mix(in srgb, var(--primary-color, #667eea) 30%, rgba(0, 0, 0, 0.4));
}

.cg-hero-card:focus-visible {
  outline: 3px solid var(--primary-color, #667eea);
  outline-offset: 2px;
}

/* Diagonal light-sweep sheen that glides across the card on hover */
.cg-hero-card::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(
    105deg,
    transparent 30%,
    rgba(255, 255, 255, 0.18) 48%,
    rgba(255, 255, 255, 0.05) 56%,
    transparent 70%
  );
  transform: translateX(-120%);
  transition: transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.cg-hero-card:hover::after {
  transform: translateX(120%);
}

.cg-hero-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1),
              filter 0.4s ease;
}

.cg-hero-card:hover .cg-hero-img {
  transform: scale(1.08);
  filter: brightness(0.7);
}

/* The first featured game is a large 2×2 spotlight tile */
.cg-hero-spotlight {
  grid-column: span 2;
  grid-row: span 2;
}

/* "Featured" badge — gold gradient pill, shown only on the spotlight tile */
.cg-hero-badge {
  position: absolute;
  top: 0.9rem;
  left: 0.9rem;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.32rem 0.7rem;
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  color: #422006;
  font-size: 0.6875rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(251, 191, 36, 0.45),
              inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

/* Spotlight gets more generous text + padding to match its size */
.cg-hero-spotlight .cg-hero-gradient {
  padding: 1.4rem;
}

.cg-hero-spotlight .cg-hero-name {
  font-size: 1.6rem;
}

.cg-hero-spotlight .cg-hero-play {
  width: 62px;
  height: 62px;
}

.cg-hero-spotlight .cg-hero-play svg {
  width: 24px;
  height: 24px;
}

/* Gradient overlay holding title + meta */
.cg-hero-gradient {
  position: absolute;
  inset: 0;
  z-index: 1;
  /* Fallback: dark readability gradient only (browsers without color-mix) */
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.94) 0%,
    rgba(0, 0, 0, 0.6) 32%,
    rgba(0, 0, 0, 0.12) 62%,
    transparent 100%
  );
  /* Enhanced: same dark gradient + a subtle brand-color tint at the base */
  background:
    linear-gradient(
      to top,
      rgba(0, 0, 0, 0.94) 0%,
      rgba(0, 0, 0, 0.6) 32%,
      rgba(0, 0, 0, 0.12) 62%,
      transparent 100%
    ),
    linear-gradient(
      to top,
      color-mix(in srgb, var(--primary-color, #667eea) 38%, transparent) 0%,
      transparent 45%
    );
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0.85rem;
  pointer-events: none; /* let clicks fall through to the <a> wrapper */
}

.cg-hero-info {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  transform: translateY(0);
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.cg-hero-card:hover .cg-hero-info {
  transform: translateY(-2px);
}

.cg-hero-name {
  font-size: 1.0625rem;
  font-weight: 800;
  color: #ffffff;
  margin: 0;
  line-height: 1.2;
  letter-spacing: -0.01em;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.6);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cg-hero-rating {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  width: fit-content;
  font-size: 0.75rem;
  color: #ffd76a;
  font-weight: 800;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 215, 106, 0.3);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

/* Circular play button. Touch devices (no hover) show it pinned to the
   top-right corner; pointer devices reveal it centered on hover. */
.cg-hero-play {
  position: absolute;
  top: 0.7rem;
  right: 0.7rem;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: var(--primary-color, #667eea);
  color: #fff;
  border-radius: 50%;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--primary-color, #667eea) 45%, rgba(0, 0, 0, 0.45));
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1),
              box-shadow 0.3s ease,
              opacity 0.3s ease;
}

.cg-hero-play svg {
  width: 18px;
  height: 18px;
  margin-left: 2px; /* visual centering of triangle inside circle */
}

/* On pointer devices, the play button sits centered and scales in on hover */
@media (hover: hover) {
  .cg-hero-play {
    top: 50%;
    left: 50%;
    right: auto;
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.55);
  }
  .cg-hero-card:hover .cg-hero-play,
  .cg-hero-card:focus-visible .cg-hero-play {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* Grid density tuning at breakpoints */
@media (min-width: 1600px) {
  .cg-hero-grid {
    grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .cg-hero-card,
  .cg-hero-img,
  .cg-hero-info,
  .cg-hero-play {
    transition: none !important;
  }
  .cg-hero-card:hover {
    transform: none;
  }
  .cg-hero-card:hover .cg-hero-img {
    transform: none;
  }
  /* Disable the light-sweep sheen entirely */
  .cg-hero-card::after {
    display: none;
  }
  /* Keep the centered play button visible (no fade/scale) when motion is reduced */
  @media (hover: hover) {
    .cg-hero-play {
      opacity: 1;
      transform: translate(-50%, -50%);
    }
  }
}

/* =============================================
   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-all-grid.games-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }
}

@media (min-width: 1600px) {
  .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;
  }
}

@media (max-width: 1024px) {
  .cg-mobile-cats {
    display: block;
  }

  .cg-main {
    padding: 1rem 1.25rem 5rem; /* extra bottom for sticky bar */
  }

  /* Tablet: denser square grid */
  .cg-hero-grid {
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
    gap: 0.85rem;
  }

  .cg-row-scroll {
    margin: 0 -1.25rem;
    padding: 0 1.25rem;
  }
}

/* =============================================
   RESPONSIVE — MOBILE
   ============================================= */
@media (max-width: 768px) {
  .cg-main {
    padding: 0.75rem 1rem 5rem;
  }

  /* Mobile: two tiles per row with the spotlight spanning the full width
     (2 cols) at the top. */
  .cg-hero-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
  }

  .cg-hero-title {
    font-size: 1.125rem;
  }

  .cg-hero-name {
    font-size: 0.9375rem;
  }

  .cg-hero-spotlight .cg-hero-name {
    font-size: 1.2rem;
  }

  .cg-hero-spotlight .cg-hero-gradient {
    padding: 1rem;
  }

  .cg-hero-spotlight .cg-hero-play {
    width: 50px;
    height: 50px;
  }

  .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-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;
  }
}
