/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #0b57d0;
  --primary-dark: #0842a0;
  --bg: #f8f9ff;
  --surface: #ffffff;
  --surface2: #f1f3f9;
  --text: #1a1c1e;
  --text2: #44474f;
  --text3: #74777f;
  --border: #c7c8d0;
  --shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-hover: 0 4px 12px rgba(0,0,0,.15);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: .2s ease;
}

html { font-size: 16px; }
body {
  font-family: 'DM Sans', 'Google Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

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

/* ===== Header ===== */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #000251;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 700;
  font-size: 1.2rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.logo img { width: 32px; height: 32px; border-radius: 6px; }

.logo-text { font-size: 1.1rem; letter-spacing: -.3px; }

.search-wrap {
  flex: 1;
  max-width: 500px;
  position: relative;
}

.search-wrap input {
  width: 100%;
  padding: 8px 16px 8px 42px;
  border: none;
  border-radius: 24px;
  background: rgba(255,255,255,.15);
  color: #fff;
  font-size: .95rem;
  outline: none;
  transition: background var(--transition);
}

.search-wrap input::placeholder { color: rgba(255,255,255,.6); }
.search-wrap input:focus { background: rgba(255,255,255,.25); }

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255,255,255,.7);
  width: 18px;
  height: 18px;
  pointer-events: none;
}

/* ===== Main Layout ===== */
.main-wrap {
  display: flex;
  min-height: calc(100vh - 60px);
}

/* ===== Sidebar (categories) ===== */
.sidebar {
  width: 200px;
  flex-shrink: 0;
  padding: 16px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
}

.sidebar h3 {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text3);
  padding: 4px 12px 8px;
}

.cat-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text2);
  font-size: .9rem;
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  font-family: inherit;
}

.cat-btn:hover { background: var(--surface2); color: var(--text); }
.cat-btn.active { background: #e8f0fe; color: var(--primary); font-weight: 600; }

.cat-btn .cat-count {
  margin-left: auto;
  font-size: .75rem;
  color: var(--text3);
  background: var(--surface2);
  border-radius: 20px;
  padding: 1px 7px;
}

.cat-btn.active .cat-count { background: #c2d7ff; color: var(--primary); }

/* ===== Content Area ===== */
.content {
  flex: 1;
  min-width: 0;
  padding: 24px;
}

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.content-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

.game-count {
  font-size: .9rem;
  color: var(--text3);
}

/* ===== Game Grid ===== */
.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.game-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  border: 1px solid transparent;
}

.game-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
  border-color: var(--primary);
}

.game-thumb-wrap {
  position: relative;
  width: 100%;
  padding-top: 56.25%; /* 16:9 */
  background: var(--surface2);
  overflow: hidden;
}

.game-thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .3s ease;
}

.game-card:hover .game-thumb { transform: scale(1.04); }

.play-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,40,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition);
}

.game-card:hover .play-overlay { opacity: 1; }

.play-btn {
  width: 52px;
  height: 52px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}

.play-btn svg { width: 24px; height: 24px; margin-left: 3px; }

.game-info {
  padding: 10px 12px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.game-title {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.game-cat {
  font-size: .75rem;
  color: var(--text3);
}

/* ===== No Results ===== */
.no-results {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text3);
}

.no-results svg { width: 60px; height: 60px; opacity: .3; margin-bottom: 16px; }
.no-results h3 { font-size: 1.2rem; margin-bottom: 8px; color: var(--text2); }

/* ===== Game Page ===== */
.game-page { padding: 0; display: flex; flex-direction: column; height: calc(100vh - 60px); }

.game-topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text2);
  font-size: .9rem;
  cursor: pointer;
  background: var(--surface);
  font-family: inherit;
  transition: all var(--transition);
}

.back-btn:hover { background: var(--surface2); color: var(--text); }
.back-btn svg { width: 16px; height: 16px; }

.game-page-title { font-size: 1.1rem; font-weight: 600; flex: 1; }

.fullscreen-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 20px;
  font-size: .9rem;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition);
}

.fullscreen-btn:hover { background: var(--primary-dark); }
.fullscreen-btn svg { width: 16px; height: 16px; }

.game-frame-wrap {
  flex: 1;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.game-frame-wrap iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.game-details {
  padding: 16px 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  max-height: 100px;
  overflow: hidden;
}

.game-details p {
  font-size: .85rem;
  color: var(--text2);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ===== Loading Spinner ===== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  grid-column: 1 / -1;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--surface2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Image loading placeholder ===== */
.game-thumb.loading-img { filter: blur(0); background: var(--surface2); }
.game-thumb:not([src]) { opacity: 0; }
.thumb-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea33 0%, #764ba233 100%);
  color: var(--primary);
  font-size: 2rem;
  font-weight: 700;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .games-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .content { padding: 16px; }
  .cat-tabs { display: flex; overflow-x: auto; gap: 8px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
  .cat-tab { white-space: nowrap; padding: 6px 14px; border-radius: 20px; background: var(--surface2); border: none; font-family: inherit; font-size: .85rem; cursor: pointer; transition: all var(--transition); }
  .cat-tab.active { background: var(--primary); color: #fff; }
}

@media (min-width: 901px) {
  .cat-tabs { display: none; }
}

@media (max-width: 600px) {
  header { padding: 0 16px; gap: 12px; }
  .logo-text { display: none; }
  .games-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .game-topbar { padding: 10px 16px; }
  .game-details { display: none; }
}
