@import url('./global.css');
@import url('./home-variants.css');

/* ------------------------------------------------------------------ */
/*  Page layout                                                       */
/* ------------------------------------------------------------------ */
.home-body {
  /* Thin aliases forwarding to the shared token layer (variables.css). Single
     source of truth — see docs/private/DESIGN_SYSTEM.md. */
  --home-bg: var(--surface-base);
  --home-bg-deep: var(--surface-deep);
  --home-panel: var(--surface-1);
  --home-panel-raised: var(--surface-2);
  --home-card: var(--card);
  --home-line: var(--line);
  --home-line-solid: var(--line-solid);
  --home-text: var(--ink);
  --home-muted: var(--ink-muted);
  --home-accent: var(--accent);
  --home-accent-strong: var(--accent-strong);

  gap: 0;
  max-width: none;
  padding-inline: clamp(0.75rem, 2vw, 1.5rem);
  color: var(--home-text);
  background: var(--portal-bg);
}

/* Full-width home: clear the fixed 64px sidebar rail on desktop so the flat
   grid never tucks under it (mobile keeps the rail off-canvas, no offset). */
@media (min-width: 768px) {
  .home-body {
    max-width: none;
    padding-left: calc(var(--rail-clearance) + clamp(0.75rem, 2vw, 1.5rem));
  }
}

.home-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: clamp(0.75rem, 1.6dvh, 1.1rem);
  width: 100%;
  max-width: none;
  padding: clamp(0.75rem, 2dvh, 1.25rem) 0 var(--spacing-md);
  animation: pageRise 0.4s ease both;
}

/* ------------------------------------------------------------------ */
/*  Category sections (only the Daily strip keeps a titled row now —   */
/*  the main catalogue is one flat, full-width grid, Poki-style)       */
/* ------------------------------------------------------------------ */
.game-category {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--spacing-sm);
  width: 100%;
}

.game-category-title {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  color: var(--home-muted);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bolder);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.game-category-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--home-line), transparent);
}

/* ------------------------------------------------------------------ */
/*  Compact icon grid                                                 */
/* ------------------------------------------------------------------ */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: clamp(0.5rem, 1vw, 0.8rem);
  width: 100%;
}

/* The main catalogue: a single dense grid that fills the whole width. */
.game-grid-all {
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
}

.game-tile {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  place-items: center;
  gap: 0.3rem;
  min-height: 6rem;
  padding: var(--spacing-sm) var(--spacing-xs);
  border: 1px solid color-mix(in srgb, var(--nav-accent, var(--home-accent)) 45%, transparent);
  border-radius: var(--border-radius-md);
  /* Accent-tinted fill so each tile reads as a themed thumbnail, not a flat
     icon on a card — the Poki-style coloured tile without needing 39 images. */
  background: linear-gradient(
    160deg,
    color-mix(in srgb, var(--nav-accent, var(--home-accent)) 62%, #0b1020),
    color-mix(in srgb, var(--nav-accent, var(--home-accent)) 30%, #0b1020)
  );
  color: #fff;
  text-decoration: none;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.22);
  transition:
    transform 0.16s ease,
    box-shadow 0.16s ease,
    border-color 0.16s ease;
}

.game-tile::before {
  content: attr(data-label);
  order: 2;
  max-width: 100%;
  color: #fff;
  font-size: 0.68rem;
  font-weight: var(--font-weight-bold);
  line-height: 1.1;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.game-tile:hover,
.game-tile:focus-visible {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--nav-accent, var(--home-accent)) 46%, var(--home-line));
  box-shadow: 0 10px 22px color-mix(in srgb, var(--nav-accent, var(--home-accent)) 26%, transparent);
}

/* Tap feedback: settle back down on press. */
.game-tile:active {
  transform: translateY(0) scale(0.97);
}

/* Touch: no real hover, so don't let the lift stick after a tap. */
@media (hover: none) {
  .game-tile:hover {
    transform: none;
    box-shadow: 0 5px 12px rgba(0, 0, 0, 0.16);
  }
}

/* Consistent keyboard focus ring (a11y). See docs/private/DESIGN_SYSTEM.md §5. */
.home-body :is(a, button):focus-visible {
  outline: 3px solid var(--line-strong);
  outline-offset: 2px;
}

.game-tile .game-icon {
  --game-icon-size: clamp(1.9rem, 2.6vw, 2.4rem);
}

.game-tile::after {
  content: attr(data-label);
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  z-index: 10;
  padding: 3px 10px;
  border: 1px solid var(--home-line);
  border-radius: var(--border-radius-sm);
  background: var(--home-bg);
  color: var(--home-text);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity 0.15s ease;
}

.game-tile:hover::after,
.game-tile:focus-visible::after {
  opacity: 1;
}

/* ------------------------------------------------------------------ */
/*  Footer                                                            */
/* ------------------------------------------------------------------ */
.home-footer {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  padding: var(--spacing-xs) 0 var(--spacing-sm);
  color: var(--home-muted);
  font-size: var(--font-size-xs);
}

.home-footer a {
  color: var(--home-muted);
  text-decoration: none;
}

.home-footer a:hover {
  color: var(--home-text);
  text-decoration: underline;
}

@media (max-width: 640px) {
  .game-grid {
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  }

  .game-grid-all {
    grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  }

  .game-tile {
    min-height: 5rem;
  }
}

@media (max-width: 767px) {
  .home-main {
    padding-top: var(--mobile-chrome-clearance);
  }

  /* The tile label is already visible on mobile. Keeping the hover tooltip in
     layout while transparent makes edge tiles widen the document. */
  .game-tile::after {
    display: none;
  }
}

@media (max-width: 480px) {
  .home-body {
    padding-inline: var(--spacing-sm);
  }

  .game-grid,
  .game-grid-all {
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  }

  .game-tile {
    min-height: 4.6rem;
  }

  .game-tile::before {
    font-size: 0.6rem;
  }

  .game-tile .game-icon {
    --game-icon-size: 1.6rem;
  }
}

/* Weekly-challenge flame: a small badge pinned to the featured game's tile
   (injected client-side, see weeklyFeature.ts; .game-tile is already relative)
   — no extra container, just a "hot this week" marker on the card itself. */
.weekly-flame {
  position: absolute;
  top: -6px;
  right: -6px;
  display: grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  background: var(--flame);
  color: #fff;
  font-size: 0.7rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  pointer-events: auto;
}

/* Daily-pick badge: same chip as the weekly flame but pinned top-LEFT and in the
   accent colour, so the "game of the day" reads distinctly from the weekly set. */
.daily-flame {
  position: absolute;
  top: -6px;
  left: -6px;
  display: grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  pointer-events: auto;
}
