:root {
  --bg: var(--tg-theme-bg-color, #0f0f14);
  --bg2: var(--tg-theme-secondary-bg-color, #1b1b23);
  --text: var(--tg-theme-text-color, #f2f2f5);
  --hint: var(--tg-theme-hint-color, #8b8b99);
  --accent: var(--tg-theme-button-color, #7c5cff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --safe-top: var(--tg-content-safe-area-inset-top, 0px);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

.top {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: calc(10px + var(--safe-top)) 12px 8px;
  background: var(--bg);
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--bg2);
}
.search svg { width: 18px; height: 18px; fill: var(--hint); flex: none; }
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px; /* below 16px iOS zooms the page on focus */
}
.search input::placeholder { color: var(--hint); }
.search input::-webkit-search-cancel-button { display: none; }

.chips {
  display: flex;
  gap: 6px;
  margin: 10px -12px 0;
  padding: 0 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  height: 32px;
  padding: 0 13px;
  border: 0;
  border-radius: 16px;
  background: var(--bg2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: transform 120ms ease-out;
}
.chip:active { transform: scale(0.95); }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

/* Fullscreen on a computer: Telegram reserves a tall top band, but only its
   close button sits there, so keep the header up and clear of that button. */
.tg-desktop { --safe-top: 0px; }
.tg-desktop .top { padding-right: 64px; }
/* Telegram's back and close buttons float over the top corners; a game or an
   ad's own Close button there would sit under them. Give them a band. */
.tg-desktop .player { padding-top: 64px; }

main { padding: 4px 12px calc(16px + env(safe-area-inset-bottom)); }

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px 8px;
  align-items: start;
}
@media (min-width: 600px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}

.card {
  display: block;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 140ms ease-out;
}
.card:active { transform: scale(0.97); }
.card img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--bg2);
}
.card span {
  display: -webkit-box;
  margin-top: 6px;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-size: 12px;
}

.empty { margin: 40px 0; text-align: center; color: var(--hint); }
.more { height: 1px; }

.player {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: #000;
}
.player iframe { width: 100%; height: 100%; border: 0; display: block; }
.close {
  position: absolute;
  top: calc(8px + var(--safe-top));
  left: 8px;
  z-index: 1;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 18px;
  background: rgb(0 0 0 / 0.5);
  cursor: pointer;
}
.close svg { width: 20px; height: 20px; fill: #fff; }
/* Inside Telegram the native Back button closes the game. */
.in-tg .close { display: none; }
