/* Blob Arcade — Poki-inspired dark theme */
:root {
  --bg-deep: #0a0e14;
  --bg-panel: #121820;
  --bg-card: #1a2230;
  --bg-card-hover: #243044;
  --accent: #00d4aa;
  --accent-dim: #00a884;
  --accent-glow: rgba(0, 212, 170, 0.35);
  --text: #e8edf5;
  --text-muted: #8b9bb8;
  --border: #2a3548;
  --hero-grad-1: #0d2840;
  --hero-grad-2: #1a1040;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --top-h: 64px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg-deep);
  color: var(--text);
  line-height: 1.5;
}

body.playing {
  overflow: hidden;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code {
  background: var(--bg-card);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.9em;
}

/* ─── Top bar ─── */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  padding: 12px 24px;
  background: rgba(10, 14, 20, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.logo {
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: 0.04em;
  color: var(--text);
  text-decoration: none;
  flex-shrink: 0;
}

.logo span {
  color: var(--accent);
}

#searchBox {
  flex: 1;
  min-width: 180px;
  max-width: 420px;
  padding: 10px 16px 10px 40px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='%238b9bb8' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242 1.156a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E") 14px center no-repeat;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#searchBox:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#searchBox::placeholder {
  color: var(--text-muted);
}

.cat-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
}

@media (min-width: 900px) {
  .cat-nav {
    width: auto;
    margin-left: auto;
  }
}

.cat-btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.cat-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text);
}

.cat-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg-deep);
}

/* ─── Hero ─── */
.hero {
  padding: 48px 24px 32px;
  text-align: center;
  background: linear-gradient(160deg, var(--hero-grad-1) 0%, var(--hero-grad-2) 50%, var(--bg-deep) 100%);
  border-bottom: 1px solid var(--border);
}

.hero h1 {
  margin: 0 0 12px;
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 800;
  background: linear-gradient(90deg, var(--text), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero p {
  margin: 0 auto 24px;
  max-width: 560px;
  color: var(--text-muted);
  font-size: 1.05rem;
}

.hero-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px 24px;
}

.hero-stats span {
  padding: 6px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.hero-stats span:first-child {
  color: var(--accent);
  border-color: var(--accent-dim);
}

/* ─── Catalog grid ─── */
.catalog {
  padding: 28px 24px 80px;
  max-width: 1400px;
  margin: 0 auto;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 18px;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 48px;
}

.game-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.2s, background 0.2s, border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.game-card:hover,
.game-card:focus-visible {
  background: var(--bg-card-hover);
  border-color: var(--accent-dim);
  transform: translateY(-4px);
  box-shadow: var(--shadow), 0 0 24px var(--accent-glow);
}

.card-icon {
  font-size: 2.5rem;
  line-height: 1;
}

.card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.card-desc {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--text-muted);
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-cat {
  align-self: flex-start;
  padding: 4px 10px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: rgba(0, 212, 170, 0.12);
  border-radius: var(--radius-sm);
}

/* ─── Game overlay ─── */
#gameOverlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-deep);
  padding: 16px;
  overflow-y: auto;
}

#gameOverlay[hidden] {
  display: none !important;
}

.game-top {
  width: 100%;
  max-width: 820px;
  margin-bottom: 12px;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  margin-bottom: 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: background 0.2s, border-color 0.2s;
}

.back-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

#gameTitle {
  margin: 0 0 4px;
  font-size: 1.4rem;
}

.game-hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

#gameCanvas {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  box-shadow: var(--shadow);
  background: #0d1117;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.game-embed {
  display: block;
  width: 100%;
  max-width: 1200px;
  height: min(78vh, 820px);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: #0a0e14;
}

.game-embed[hidden] {
  display: none !important;
}

body.playing-embed #gameCanvas {
  display: none;
}

.game-card.featured {
  border-color: rgba(255, 221, 0, 0.45);
  background: linear-gradient(145deg, #1a2230 0%, #1f2840 55%, #2a2040 100%);
  box-shadow: 0 0 24px rgba(255, 221, 0, 0.12);
}

.game-card.featured::after {
  content: "Featured";
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #ffdd00;
  background: rgba(0, 0, 0, 0.35);
  padding: 4px 8px;
  border-radius: 6px;
}

.game-controls {
  width: 100%;
  max-width: 820px;
  margin-top: 12px;
  padding: 12px 16px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: center;
}

/* ─── Footer ─── */
.footer {
  padding: 24px;
  text-align: center;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
}

.footer p {
  margin: 0;
}

/* ─── Responsive ─── */
@media (max-width: 600px) {
  .top-bar {
    padding: 10px 16px;
  }

  #searchBox {
    order: 3;
    width: 100%;
    max-width: none;
  }

  .hero {
    padding: 32px 16px 24px;
  }

  .catalog {
    padding: 20px 16px 60px;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
  }

  #gameCanvas {
    width: 100%;
  }
}

/* Card entrance animation */
@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.game-card {
  animation: card-in 0.35s ease backwards;
}

.grid .game-card:nth-child(1) { animation-delay: 0.02s; }
.grid .game-card:nth-child(2) { animation-delay: 0.04s; }
.grid .game-card:nth-child(3) { animation-delay: 0.06s; }
.grid .game-card:nth-child(4) { animation-delay: 0.08s; }
.grid .game-card:nth-child(5) { animation-delay: 0.1s; }
.grid .game-card:nth-child(6) { animation-delay: 0.12s; }
.grid .game-card:nth-child(n+7) { animation-delay: 0.14s; }

/* Playing state hides catalog scroll */
body.playing .catalog,
body.playing .hero,
body.playing .footer {
  visibility: hidden;
  pointer-events: none;
}

body.playing .top-bar {
  opacity: 0;
  pointer-events: none;
}

/* Focus ring for accessibility */
.cat-btn:focus-visible,
.back-btn:focus-visible,
#searchBox:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Category color accents on cards */
.game-card[data-cat="arcade"] .card-cat { color: #ff9f43; background: rgba(255, 159, 67, 0.15); }
.game-card[data-cat="puzzle"] .card-cat { color: #a29bfe; background: rgba(162, 155, 254, 0.15); }
.game-card[data-cat="action"] .card-cat { color: #ff6b6b; background: rgba(255, 107, 107, 0.15); }
.game-card[data-cat="sports"] .card-cat { color: #48dbfb; background: rgba(72, 219, 251, 0.15); }

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--bg-deep);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-dim);
}

/* Selection */
::selection {
  background: var(--accent);
  color: var(--bg-deep);
}

/* Large screens — wider hero */
@media (min-width: 1200px) {
  .hero h1 {
    font-size: 2.75rem;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 22px;
  }
}

/* Print — hide overlay */
@media print {
  #gameOverlay,
  .top-bar {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }

  .game-card {
    animation: none;
  }
}
