/* Shared tile grid (home page and category pages): logo box, game tiles, category tiles */
/* Home page: one grid of square cells (fixed size, column count follows the window width).
   The logo box is the first item in the grid; games come in three sizes: 1x1, 2x2 and 3x3. */
:root { --cell: 94px; --tile-gap: 16px; }

main {
  flex: 1;
  padding: 16px 16px var(--tile-gap);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, var(--cell));
  grid-auto-rows: var(--cell);
  grid-auto-columns: var(--cell);
  grid-auto-flow: dense;
  gap: var(--tile-gap);
  justify-content: center;
  /* only ever an even number of columns: the grid's width snaps down to a whole number of column pairs */
  width: calc(round(down, 100% + var(--tile-gap) + 1px, 2 * (var(--cell) + var(--tile-gap))) - var(--tile-gap));
  margin: 0 auto;
}

/* ---------- logo box: 2 cells wide, 1 tall ---------- */
.nav-tile {
  grid-column: 1 / span 2;
  grid-row: 1;
  position: relative;
  z-index: 5;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 6px 14px rgba(70, 100, 150, 0.18);
}

.nav-logo {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  border-radius: 10px 10px 0 0;
}
.nav-logo picture { display: contents; }
.nav-logo .logo-img { display: block; width: 100%; height: auto; }

.nav-buttons {
  flex: none;
  height: 52%;
  display: flex;
  border-top: 1px solid #e8edf4;
}

.nav-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: none;
  color: #3a3a3a;
  font: 600 14px "Montserrat", system-ui, sans-serif;
  letter-spacing: -0.01em;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-btn + .nav-btn { border-left: 1px solid #e8edf4; }
.nav-btn:first-child { border-bottom-left-radius: 10px; }
.nav-btn:last-child { border-bottom-right-radius: 10px; }
.nav-btn:hover, .nav-btn[aria-expanded="true"] { background: #eef3fa; color: #111; }
.nav-btn svg { width: 20px; height: 20px; }

/* search pops out below the logo box */
.search-pop {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: min(360px, calc(100vw - 32px));
}
.search-pop[hidden] { display: none; }
.search-pop .search-island {
  height: 52px;
  border-radius: 10px;
  box-shadow: 0 14px 34px rgba(50, 70, 120, 0.22);
  padding: 0 16px;
  gap: 10px;
}
.search-pop .search-island > svg { width: 20px; height: 20px; }
.search-pop .search-island input { font-size: 16px; }

/* ---------- game tiles ---------- */
.tile {
  position: relative;
  overflow: hidden;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #4338ca;
  text-decoration: none;
  box-shadow: 0 6px 14px rgba(70, 100, 150, 0.18);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.tile:hover {
  transform: scale(1.04);
  box-shadow: 0 16px 32px rgba(50, 70, 120, 0.35);
  z-index: 1;
}
.tile.md { grid-column: span 2; grid-row: span 2; border-radius: 14px; }
.tile.lg { grid-column: span 3; grid-row: span 3; border-radius: 18px; }

/* Home page: grid.js picks a column count (--cols on <main>) and a hand-drawn layout map for it,
   then sets each tile's order and size. Without JS the plain auto-fill grid above is used. */
.home-grid.mapped {
  grid-template-columns: repeat(var(--cols), var(--cell));
  width: calc(var(--cols) * var(--cell) + (var(--cols) - 1) * var(--tile-gap));
}
/* the category boxes below match the game grid's width: one box per two columns, stretched to fit */
.home-grid.mapped ~ .cat-grid {
  grid-template-columns: repeat(round(down, var(--cols) / 2, 1), 1fr);
  width: calc(var(--cols) * var(--cell) + (var(--cols) - 1) * var(--tile-gap));
}
.home-grid.mapped ~ .cat-grid .cat-tile { grid-column: auto; }

.tile img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  transition: transform 0.35s ease;
}
.tile:hover img { transform: scale(1.05); }


/* icon art with its own frame: show it whole, inset inside the tile */
.tile.fit { background: #fff; }
.tile.fit img { inset: 12%; width: 76%; height: 76%; }

/* game name: white text along the bottom, fades in on hover */
.game-tile-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  padding: 18px 6px 7px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.45));
  color: #fff;
  font-family: "Montserrat", system-ui, sans-serif;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.md .game-tile-name, .lg .game-tile-name { font-size: 14px; padding-bottom: 10px; }
.tile:hover .game-tile-name,
.tile:focus-visible .game-tile-name { opacity: 1; transform: translateY(0); }

/* phones: four columns that fill the screen width */
@media (max-width: 560px) {
  :root { --tile-gap: 8px; --cell: calc((100vw - 16px - 3 * var(--tile-gap)) / 4); }
  /* phones: always exactly four square columns edge to edge, no column-pair snapping */
  .grid { width: 100%; grid-template-columns: repeat(4, var(--cell)); }
  .cat-intro { width: 100%; }
  main { padding: 8px 8px var(--tile-gap); }
  .nav-btn { font-size: 13px; }
}

/* periodic diagonal glint on random tiles */
.tile::after {
  content: ""; position: absolute; inset: -50%; pointer-events: none;
  background: linear-gradient(45deg, transparent 42%, rgba(255,255,255,0.55) 50%, transparent 58%);
  transform: translate(-60%, 60%); opacity: 0;
}
.tile.glint::after { animation: glint 0.9s ease-in-out; }
@keyframes glint {
  0%   { transform: translate(-60%, 60%); opacity: 1; }
  100% { transform: translate(60%, -60%); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .tile.glint::after { animation: none; } }

/* ---------- category tiles: 2 cells wide, 1 tall, icon chip + name + game count ---------- */
.cat-grid { margin-top: calc(var(--tile-gap) * 3); }
.cat-tile {
  grid-column: span 2;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px 0 8px;
  min-width: 0;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(30, 45, 80, 0.06), 0 6px 14px rgba(70, 100, 150, 0.12);
  color: #18213a;
  text-decoration: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.cat-tile:hover { transform: translateY(-3px); box-shadow: 0 2px 4px rgba(30, 45, 80, 0.06), 0 14px 28px rgba(50, 70, 120, 0.2); z-index: 1; }
.cat-tile:focus-visible { outline: 2px solid #2f6fdf; outline-offset: 3px; }
.cat-tile img { flex: none; width: 72px; height: 72px; margin: -6px 0; display: block; object-fit: contain; filter: drop-shadow(0 3px 4px rgba(30, 45, 80, 0.12)); transition: transform 0.25s ease; }
.cat-tile:hover img { transform: scale(1.08); }
.cat-name {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
  text-align: center;
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

/* ---------- page title box on category pages: sits next to the logo box ---------- */
.title-tile {
  grid-column: span 4;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 24px;
  text-align: center;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(30, 45, 80, 0.06), 0 6px 14px rgba(70, 100, 150, 0.12);
}
.title-tile h1 {
  font-size: clamp(19px, 1.9vw, 24px);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.025em;
  color: #18213a;
}
.cat-intro {
  width: calc(round(down, 100% + var(--tile-gap) + 1px, 2 * (var(--cell) + var(--tile-gap))) - var(--tile-gap));
  margin: calc(var(--tile-gap) * 3) auto 0;
  padding: 26px 32px;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 6px 14px rgba(70, 100, 150, 0.18);
  color: #1e2a44;
  font-size: 15px;
  line-height: 1.65;
}
.cat-intro h2 { font-size: 16px; font-weight: 800; color: #12204a; margin-bottom: 8px; }
.cat-intro p + p { margin-top: 12px; }
.cat-intro p + h2 { margin-top: 22px; }

@media (max-width: 560px) {
  .cat-tile { gap: 6px; padding: 0 8px 0 4px; }
  .cat-tile img { width: 54px; height: 54px; margin: -4px 0; }
  .cat-name { font-size: 14.5px; }
  .title-tile { grid-column: span 2; padding: 0 12px; }
  .title-tile h1 { font-size: 16px; }
  .cat-intro { padding: 20px 18px; font-size: 14px; }
}
