/* ============================================================
   NEONBET · Games view (dedicated lobby)  (redesign-v2 · FIX-4)
   ------------------------------------------------------------
   Mobile-first dedicated games page: header + count, category
   poster cards, search + sort + filters, 2-col game grid.
   Driven by the LIVE data layer — rails/filters use the admin
   CATEGORIES and GAMES; providers derived from GAMES. Game launch
   reuses openGameIframe. No backend/API/category changes.
   Injected as #nb-games (sibling of #nb-home, view-switched by nav).
   ============================================================ */

#nb-games { position: relative; z-index: 1; display: none; }
#nb-games.is-active { display: block; }
#nb-games .container { width: 100%; max-width: var(--container-max); margin: 0 auto; padding: 0 var(--space-5); }
@media (min-width: 768px) { #nb-games .container { padding: 0 var(--space-8); } }

/* Hero */
#nb-games .lobby-hero { padding: var(--space-6) 0 var(--space-2); }
#nb-games .lobby-hero h1 { margin: 0; font-family: var(--font-display); font-size: var(--text-3xl); font-weight: 400; letter-spacing: 0.02em; text-transform: uppercase; color: var(--text-primary); }
#nb-games .lobby-hero p { color: var(--text-secondary); margin: var(--space-2) 0 0; font-size: var(--text-base); }

/* Category poster strip — designer poster cards (reference games.css).
   Desktop/tablet: responsive grid (5 → 4 columns). Phones: single
   swipeable row, next tile peeking. All cards share the 256:143 poster
   aspect so poster and gradient-fallback tiles line up in one row. */
#nb-games .cat-strip {
  display: grid;
  /* Desktop: fixed 4 across — the designed 12-card nav reads as a 4×3 wall. */
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-4);
  padding: var(--space-5) 0 var(--space-2);
}
@media (max-width: 900px) {
  #nb-games .cat-strip { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-3); }
}
@media (max-width: 600px) {
  /* Same iOS pan fix as the homepage .rail: proximity snap (mandatory can
     lock WebKit touch scrolling) + explicit pan permissions + momentum. */
  #nb-games .cat-strip { display: flex; grid-template-columns: none; gap: var(--space-3); overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y; overscroll-behavior-x: contain; }
  #nb-games .cat-strip::-webkit-scrollbar { display: none; }
  #nb-games .cat-strip > .cat-card { flex: 0 0 62%; scroll-snap-align: start; }
}
/* Plan B — touch devices: free scrolling, no snap (see .rail in home.css). */
@media (pointer: coarse) {
  #nb-games .cat-strip { scroll-snap-type: none !important; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y; }
  #nb-games .cat-strip > * { scroll-snap-align: none !important; }
}
#nb-games .cat-card {
  position: relative; min-width: 0;
  aspect-ratio: 256 / 143;   /* match the poster art — full-bleed, no letterbox */
  border-radius: var(--radius-md); overflow: hidden;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle); cursor: pointer; isolation: isolate;
  display: flex; align-items: flex-end; padding: var(--space-4);
  transition: transform var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
/* Gradient text look — live categories WITHOUT a poster (and the onerror
   degradation path). Hidden entirely on poster cards below. */
#nb-games .cat-card::before { content: ""; position: absolute; inset: 0; z-index: -1; opacity: 0.9; }
#nb-games .cat-card.g0::before { background: linear-gradient(135deg, rgba(255,46,147,0.55), rgba(139,92,255,0.35)); }
#nb-games .cat-card.g1::before { background: linear-gradient(135deg, rgba(0,229,255,0.45), rgba(139,92,255,0.40)); }
#nb-games .cat-card.g2::before { background: linear-gradient(135deg, rgba(139,92,255,0.50), rgba(0,229,255,0.30)); }
#nb-games .cat-card.g3::before { background: linear-gradient(135deg, rgba(232,194,106,0.50), rgba(255,46,147,0.30)); }
#nb-games .cat-card::after { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(0deg, rgba(7,7,12,0.65), transparent 70%); }
#nb-games .cat-card:hover { transform: translateY(-3px); border-color: var(--neon-cyan); box-shadow: 0 8px 24px rgba(0, 229, 255, 0.15); }
#nb-games .cat-card.is-active { border-color: var(--neon-cyan); box-shadow: 0 0 0 1px var(--neon-cyan), 0 8px 24px rgba(0, 229, 255, 0.25); }
#nb-games .cat-card .cat-card-name { font-family: var(--font-display); font-size: var(--text-lg); color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,0.6); letter-spacing: 0.02em; text-transform: uppercase; }
#nb-games .cat-card .cat-card-sub { position: absolute; top: var(--space-3); left: var(--space-4); font-family: var(--font-mono); font-size: 0.6rem; letter-spacing: 0.08em; text-transform: uppercase; color: rgba(255,255,255,0.85); }
/* Poster variant — the PNG fills the card edge-to-edge; the name/count
   stay in the DOM for accessibility but are visually hidden (the label
   is baked into the artwork). onerror strips .has-poster, restoring the
   gradient text look above. */
#nb-games .cat-card.has-poster { padding: 0; }
#nb-games .cat-card.has-poster::before,
#nb-games .cat-card.has-poster::after { display: none; }
#nb-games .cat-card.has-poster .cat-glyph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
#nb-games .cat-card.has-poster .cat-img { width: 100%; height: 100%; object-fit: contain; object-position: center; display: block; }
#nb-games .cat-card.has-poster .cat-card-name,
#nb-games .cat-card.has-poster .cat-card-sub {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
/* Card that LOST its poster (onerror removed .has-poster): the glyph/img
   must not cover the gradient text fallback. */
#nb-games .cat-card:not(.has-poster) .cat-glyph { display: none; }

/* "Show all games" — teaser-limit reveal button under the grid */
#nb-games .load-more { display: flex; justify-content: center; margin-top: var(--space-8); }
/* Expanded-mode sentinel: parks under the grid and auto-loads the next
   +15 batch when it nears the viewport; removed once the list is done. */
#nb-games .gv-sentinel { display: flex; justify-content: center; padding: var(--space-6) 0 var(--space-4); }
#nb-games .gv-loader { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border-subtle); border-top-color: var(--neon-cyan); animation: gv-spin 0.9s linear infinite; }
@keyframes gv-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { #nb-games .gv-loader { animation: none; } }

/* Toolbar */
#nb-games .lobby-toolbar { position: sticky; top: calc(var(--nav-height-mobile) + env(safe-area-inset-top)); z-index: 10; background: var(--bg-base); padding: var(--space-3) 0; margin-top: var(--space-2); }
@media (min-width: 1200px) { #nb-games .lobby-toolbar { top: calc(var(--nav-height) + env(safe-area-inset-top)); } }
#nb-games .lobby-toolbar-inner { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
#nb-games .lobby-search { position: relative; flex: 1 1 100%; }
@media (min-width: 560px) { #nb-games .lobby-search { flex: 1 1 240px; } }
#nb-games .lobby-search input { height: 44px; width: 100%; padding: 0 var(--space-4) 0 44px; background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); color: var(--text-primary); font-family: var(--font-sans); font-size: var(--text-base); }
#nb-games .lobby-search input:focus { outline: none; border-color: var(--neon-cyan); box-shadow: 0 0 0 3px rgba(0,229,255,0.14); }
#nb-games .lobby-search svg { position: absolute; top: 50%; left: 14px; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-muted); pointer-events: none; }
#nb-games .sort-select { height: 44px; padding: 0 var(--space-3); background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); color: var(--text-primary); font-family: var(--font-sans); font-size: var(--text-sm); }
#nb-games .filter-toggle { height: 44px; padding: 0 var(--space-4); display: inline-flex; align-items: center; gap: 8px; background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); color: var(--text-primary); font-family: var(--font-display); font-size: var(--text-xs); letter-spacing: 0.04em; text-transform: uppercase; cursor: pointer; }
#nb-games .filter-toggle:hover { border-color: var(--neon-cyan); }
#nb-games .filter-toggle svg { width: 16px; height: 16px; }
#nb-games .filter-toggle .fcount { background: var(--neon-magenta); color: #fff; border-radius: var(--radius-pill); font-family: var(--font-mono); font-size: 0.6rem; padding: 1px 6px; }

/* Count */
#nb-games .lobby-count { font-size: var(--text-sm); color: var(--text-secondary); margin: var(--space-2) 0 var(--space-4); }
#nb-games .lobby-count strong { color: var(--text-primary); font-family: var(--font-mono); }

/* Grid */
#nb-games .games-grid { display: grid; gap: var(--space-3); grid-template-columns: repeat(2, 1fr); padding-bottom: var(--space-20); }
@media (min-width: 600px)  { #nb-games .games-grid { grid-template-columns: repeat(3, 1fr); gap: var(--space-4); } }
@media (min-width: 900px)  { #nb-games .games-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1280px) { #nb-games .games-grid { grid-template-columns: repeat(5, 1fr); } }
#nb-games .games-empty { grid-column: 1 / -1; padding: var(--space-12) var(--space-5); text-align: center; color: var(--text-muted); }

/* Filter drawer */
.gv-filter-scrim { position: fixed; inset: 0; background: var(--bg-overlay); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); opacity: 0; pointer-events: none; z-index: calc(var(--z-drawer)); transition: opacity 200ms var(--ease-out); }
.gv-filter-scrim.is-open { opacity: 1; pointer-events: auto; }
.gv-filter { position: fixed; top: 0; left: 0; bottom: 0; width: min(340px, 86vw); z-index: calc(var(--z-drawer) + 1); background: var(--bg-base); border-right: 1px solid var(--border-subtle); box-shadow: 16px 0 60px rgba(0,0,0,0.55); transform: translateX(-100%); transition: transform 260ms var(--ease-out); display: flex; flex-direction: column; }
.gv-filter.is-open { transform: translateX(0); }
.gv-filter[hidden] { display: none; }
.gv-filter-head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-5); border-bottom: 1px solid var(--border-subtle); }
.gv-filter-head h3 { margin: 0; font-family: var(--font-display); font-size: var(--text-lg); font-weight: 400; }
.gv-filter-close { width: 36px; height: 36px; border-radius: var(--radius-md); display: inline-flex; align-items: center; justify-content: center; background: var(--bg-surface); border: 1px solid var(--border-subtle); color: var(--text-secondary); cursor: pointer; }
.gv-filter-body { flex: 1; overflow-y: auto; padding: var(--space-5); }
.gv-filter-section { margin-bottom: var(--space-6); }
.gv-filter-section h4 { font-family: var(--font-mono); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin: 0 0 var(--space-3); }
.gv-opt { display: flex; align-items: center; gap: var(--space-2); width: 100%; padding: 8px 10px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--text-primary); font-family: var(--font-sans); font-size: var(--text-sm); text-align: left; cursor: pointer; min-height: 38px; transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out); }
.gv-opt:hover { background: rgba(255,255,255,0.04); }
.gv-opt.is-active { background: rgba(0,229,255,0.12); color: var(--neon-cyan); font-weight: 600; }
.gv-opt input { accent-color: var(--neon-cyan); width: 16px; height: 16px; }
.gv-opt .gv-c { margin-left: auto; font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-muted); }
.gv-filter-foot { padding: var(--space-4) var(--space-5) calc(var(--space-5) + env(safe-area-inset-bottom)); border-top: 1px solid var(--border-subtle); display: flex; gap: var(--space-3); }
.gv-filter-foot .btn { flex: 1; }
@media (min-width: 1024px) { .gv-filter, .gv-filter-scrim { /* sidebar handled inline; keep drawer for simplicity on all sizes */ } }
