/* ==========================================================================
   layout.css
   Structural layout: containers, page grid, header/footer scaffolding,
   section rhythm. Visual styling of components lives in components.css.
   ========================================================================== */

.container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--container-padding);
}

.section {
  padding-block: var(--space-7);
}

.section--tight {
  padding-block: var(--space-6);
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}

.section-head__title {
  font-size: var(--fs-xl);
}

.section-head__subtitle {
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}

main {
  flex: 1 0 auto;
}

/* ---------------------------------------------------------------------
   Site header
   --------------------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  height: var(--header-height);
  display: flex;
  align-items: center;
  border-bottom: var(--border-width) solid var(--color-border);
  transition: box-shadow var(--transition-base);
}

/*
 * The header's blurred-glass background lives on ::before rather than
 * directly on .site-header. This is a functional fix, not a visual one:
 * backdrop-filter (like transform/filter/perspective) makes an element
 * create a new containing block for any position:fixed descendants —
 * and .site-header__nav / .site-header__scrim (the mobile menu panel and
 * its backdrop) are both fixed-position descendants of .site-header.
 * With backdrop-filter directly on .site-header, they were being fixed
 * to the header's own ~64px-tall box instead of the viewport, which is
 * why the mobile menu rendered squished into the header bar instead of
 * sliding in as a full-height drawer. Moving the filter to a pseudo-
 * element keeps the exact same visual result (same blur, same color,
 * same everything) without .site-header itself creating that containing
 * block, so position:fixed on its descendants resolves against the
 * viewport again, as intended.
 */
.site-header::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: rgba(15, 20, 32, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

:root[data-theme="light"] .site-header::before {
  background: rgba(245, 246, 251, 0.85);
}

.site-header--scrolled {
  box-shadow: var(--shadow-md);
}

.site-header__inner {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  min-width: 0;
}

.site-header__search {
  flex: 1 1 420px;
  max-width: 460px;
  min-width: 120px;
  margin-left: auto;
}

.site-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.site-header__menu-toggle {
  display: inline-flex;
  border: var(--border-width) solid var(--color-border);
  background: var(--color-surface);
  transition: transform var(--transition-fast), background-color var(--transition-fast), border-color var(--transition-fast);
}

.site-header__menu-toggle:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-border-strong);
  transform: translateY(-1px);
}

.site-header__nav {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(390px, 92vw);
  margin: 0;
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-5);
  background: var(--color-bg-elevated);
  border-left: var(--border-width) solid var(--color-border);
  box-shadow: var(--shadow-lg);
  transform: translateX(105%);
  visibility: hidden;
  opacity: 0;
  transition: transform var(--transition-slow), opacity var(--transition-base), visibility var(--transition-slow);
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: var(--z-overlay);
}

.site-header__nav.is-open {
  transform: translateX(0);
  visibility: visible;
  opacity: 1;
}

.site-header__nav-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: var(--border-width) solid var(--color-border);
}

.site-header__nav-kicker {
  display: block;
  margin-bottom: 2px;
  color: var(--color-accent);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  letter-spacing: 0.12em;
}

.site-header__nav-title {
  display: block;
  color: var(--color-text);
  font-size: var(--fs-lg);
  line-height: var(--lh-tight);
}

.site-header__nav-close {
  flex: 0 0 auto;
}

.site-header__menu-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.site-header__menu-item,
.site-header__theme-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 64px;
  padding: var(--space-3);
  border: var(--border-width) solid transparent;
  border-radius: var(--radius-lg);
  color: var(--color-text);
  background: transparent;
  text-align: left;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}

.site-header__menu-item:hover,
.site-header__menu-item:focus-visible,
.site-header__theme-item:hover,
.site-header__theme-item:focus-visible {
  background: var(--color-surface);
  border-color: var(--color-border);
  transform: translateX(2px);
}

.site-header__menu-item > span:nth-child(2),
.site-header__theme-item > span:nth-child(2) {
  min-width: 0;
  flex: 1;
}

.site-header__menu-item strong,
.site-header__theme-item strong {
  display: block;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
}

.site-header__menu-item small,
.site-header__theme-item small {
  display: block;
  margin-top: 2px;
  color: var(--color-text-muted);
  font-size: var(--fs-xs);
  line-height: 1.35;
}

.site-header__menu-icon,
.site-header__theme-icon {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-accent);
  font-size: 1.25rem;
  border: var(--border-width) solid var(--color-border);
}

.site-header__menu-item--button {
  cursor: pointer;
  font: inherit;
}

.site-header__menu-item--button .nav-dropdown__chevron {
  flex: 0 0 auto;
  margin-left: auto;
}

/* Categories expand inside the same drawer on every screen size. */
.site-header__nav .nav-dropdown {
  position: static;
}

.site-header__nav .nav-dropdown__panel {
  position: static;
  min-width: 0;
  max-height: none;
  margin: 0 var(--space-2) var(--space-2) 54px;
  padding: var(--space-2);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: none;
  opacity: 1;
  transform: none;
}

.site-header__nav .nav-dropdown__panel[hidden] {
  display: none;
}

.site-header__nav-footer {
  margin-top: auto;
  padding-top: var(--space-4);
  border-top: var(--border-width) solid var(--color-border);
}

.site-header__theme-item {
  cursor: pointer;
  font: inherit;
}

.site-header__scrim:not([hidden]) {
  display: block;
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: calc(var(--z-overlay) - 1);
  animation: scrim-fade-in var(--transition-base) ease forwards;
}

@media (max-width: 768px) {
  .site-header {
    height: 64px;
  }

  .site-header__inner {
    gap: var(--space-2);
  }

  .site-header__search {
    max-width: none;
    margin-left: 0;
    flex: 1 1 auto;
  }

  .site-header__search .search-bar__input {
    min-width: 0;
  }

  .site-header__nav {
    width: min(380px, 94vw);
    padding: var(--space-4);
  }
}

@media (max-width: 420px) {
  .logo {
    gap: var(--space-1);
    font-size: var(--fs-sm);
  }

  .logo__mark {
    width: 28px;
    height: 28px;
    font-size: 0.65rem;
  }

  .site-header__search .search-bar__input {
    font-size: var(--fs-xs);
  }
}

@media (prefers-reduced-motion: reduce) {
  .site-header__nav,
  .site-header__menu-item,
  .site-header__theme-item,
  .site-header__menu-toggle {
    transition: none;
  }
}

@keyframes scrim-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------------------------------------------------------------------
   Site footer
   --------------------------------------------------------------------- */
.site-footer {
  border-top: var(--border-width) solid var(--color-border);
  background: var(--color-footer-bg);
  margin-top: var(--space-8);
}

.site-footer__grid {
  display: grid;
  grid-template-columns: 1.4fr repeat(3, 1fr);
  gap: var(--space-6);
  padding-block: var(--space-7);
}

.site-footer__bottom {
  border-top: var(--border-width) solid var(--color-border);
  padding-block: var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  font-size: var(--fs-xs);
  color: var(--color-text-faint);
}

@media (max-width: 768px) {
  .site-footer__grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  .site-footer__grid {
    grid-template-columns: 1fr;
  }

  :root {
    --container-padding: var(--space-4);
  }
}

/* ---------------------------------------------------------------------
   Grids
   --------------------------------------------------------------------- */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-5);
}

.game-grid--compact {
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: var(--space-4);
}

@media (max-width: 768px) {
  /* Strict requirement: game grids stay exactly two columns on mobile,
     never collapsing to one, regardless of card content length. */
  .game-grid,
  .game-grid--compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
  }
}

.category-rail {
  display: flex;
  gap: var(--space-3);
  overflow-x: auto;
  padding-bottom: var(--space-2);
  scrollbar-width: thin;
}

.category-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* ---------------------------------------------------------------------
   Two-column static page layout (about, privacy, terms, contact)
   --------------------------------------------------------------------- */
.static-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: var(--space-7);
  align-items: start;
}

@media (max-width: 900px) {
  .static-page {
    grid-template-columns: 1fr;
  }
}
