:root {
  --bg: #0f1117;
  --card: #171a24;
  --card-hover: #1f2430;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #2a2f3d;
  --accent: #6366f1;
  --accent-quick: #22d3ee;
  --accent-arcade: #fb923c;
  --accent-puzzle: #c084fc;
  --accent-deep: #818cf8;
  --success: #34d399;
  --danger: #f87171;
  --radius: 16px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.logo span {
  background: linear-gradient(90deg, #6366f1, #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s ease;
}

.back-btn:hover {
  background: var(--card-hover);
  transform: translateY(-1px);
}

/* Search + Filters */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
  align-items: center;
}

.search-wrapper {
  flex: 1;
  min-width: 220px;
  position: relative;
}

.search-wrapper input {
  width: 100%;
  padding: 12px 16px 12px 44px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.search-wrapper input:focus {
  border-color: var(--accent);
}

.search-wrapper::before {
  content: "🔍";
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  opacity: 0.6;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-btn {
  padding: 8px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.filter-btn:hover {
  color: var(--text);
  border-color: #3f4759;
}

.filter-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Recently Played */
.section-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 28px 0 12px;
}

.recent-row {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: thin;
}

.recent-row::-webkit-scrollbar {
  height: 6px;
}

.recent-card {
  flex: 0 0 auto;
  width: 132px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
}

.recent-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.2);
}

.recent-card .emoji {
  font-size: 28px;
  display: block;
  margin-bottom: 4px;
}

.recent-card .title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Game Grid */
.game-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

@media (min-width: 640px) {
  .game-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 900px) {
  .game-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.game-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px 16px;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), 
              box-shadow 0.2s, 
              border-color 0.2s;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.game-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  border-color: #3f4759;
}

.game-card:active {
  transform: scale(0.985);
}

.game-card .emoji {
  font-size: 42px;
  line-height: 1;
  margin-bottom: 10px;
}

.game-card .title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 4px;
}

.game-card .desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.35;
  flex: 1;
  margin-bottom: 14px;
}

.game-card .meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
}

.tag {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tag-quick { background: rgba(34, 211, 238, 0.15); color: var(--accent-quick); }
.tag-arcade { background: rgba(251, 146, 60, 0.15); color: var(--accent-arcade); }
.tag-puzzle { background: rgba(192, 132, 252, 0.15); color: var(--accent-puzzle); }
.tag-deep { background: rgba(129, 140, 248, 0.15); color: var(--accent-deep); }

.highscore {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: #11141c;
  padding: 2px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

/* Game Page Layout */
.game-page {
  min-height: 100vh;
  padding-bottom: 40px;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.game-header .game-info {
  display: flex;
  align-items: center;
  gap: 14px;
}

.game-header .game-info .emoji {
  font-size: 32px;
}

.game-header .game-info .title {
  font-size: 22px;
  font-weight: 700;
}

.game-container {
  max-width: 720px;
  margin: 0 auto;
}

.instructions {
  font-size: 13px;
  color: var(--text-muted);
  background: var(--card);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

/* Common game UI elements */
.score-display {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
}

.score-item {
  text-align: center;
}

.score-item .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.score-item .value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

.game-area {
  background: #0a0c12;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.game-over {
  position: absolute;
  inset: 0;
  background: rgba(15, 17, 23, 0.96);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 20;
  padding: 24px;
  border-radius: var(--radius);
}

.game-over.show {
  display: flex;
}

.game-over h2 {
  margin: 0 0 8px;
  font-size: 26px;
}

.game-over .final-score {
  font-size: 42px;
  font-weight: 800;
  margin: 8px 0 4px;
}

.game-over .new-high {
  color: var(--success);
  font-weight: 700;
  margin-bottom: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}

.btn:hover {
  transform: translateY(-2px);
}

.btn:active {
  transform: scale(0.98);
}

.btn.secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 20px;
}

/* Responsive tweaks */
@media (max-width: 480px) {
  .game-header .game-info .title {
    font-size: 19px;
  }
  .score-item .value {
    font-size: 24px;
  }
}