* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0f0f1a;
  --surface: #16162b;
  --surface2: #1f1f3a;
  --surface3: #2a2a4a;
  --primary: #7c73ff;
  --primary-glow: #9d94ff;
  --primary-dim: rgba(124, 115, 255, 0.12);
  --accent: #ff6b6b;
  --accent-glow: rgba(255, 107, 107, 0.25);
  --green: #51cf66;
  --yellow: #ffd43b;
  --text: #e8e8f0;
  --text-dim: #8888aa;
  --text-muted: #555577;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 8px 32px rgba(124, 115, 255, 0.15);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }

header {
  background: rgba(22, 22, 43, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  position: sticky;
  top: 0;
  z-index: 100;
}

header .logo {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 10px;
}

header .logo::before {
  content: '';
  width: 28px;
  height: 28px;
  background: url('../logo.png') center/contain no-repeat;
  display: block;
}

header .logo span { color: var(--accent); }
header nav { display: flex; gap: 4px; }
header nav a {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  transition: all 0.2s;
}
header nav a:hover, header nav a.active {
  background: var(--primary-dim);
  color: var(--primary);
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 24px;
}

.page-title {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 24px;
  letter-spacing: -0.3px;
}
.page-title .sub {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-dim);
  display: block;
  margin-top: 4px;
}

.search-section {
  margin-bottom: 28px;
}

.search-bar {
  width: 100%;
  margin-bottom: 14px;
}

.search-bar input {
  width: 100%;
  padding: 13px 18px;
  border: 1.5px solid var(--surface2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: all 0.25s;
}
.search-bar input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-dim);
}
.search-bar input::placeholder { color: var(--text-muted); }

.layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

.sidebar {
  width: 210px;
  flex-shrink: 0;
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  padding: 4px 0 24px 0;
  scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }

.sidebar .sidebar-close { display: none; }

.sidebar .cat-btn {
  display: block;
  width: 100%;
  padding: 6px 12px;
  text-align: left;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar .cat-btn:hover {
  background: var(--primary-dim);
  color: var(--primary);
}
.sidebar .cat-btn.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.main-content {
  flex: 1;
  min-width: 0;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.game-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.25s, box-shadow 0.25s;
  cursor: pointer;
  border: 1px solid var(--surface2);
  text-decoration: none;
  display: block;
  position: relative;
}
.game-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-glow);
  border-color: rgba(124, 115, 255, 0.25);
}

.game-card .thumb {
  width: 100%;
  aspect-ratio: 1;
  position: relative;
  overflow: hidden;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
}
.game-card .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.35s;
}
.game-card:hover .thumb img {
  transform: scale(1.08);
}

.game-card .thumb .hover-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(124, 115, 255, 0.15), rgba(255, 107, 107, 0.08));
  opacity: 0;
  transition: opacity 0.25s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.game-card:hover .hover-overlay { opacity: 1; }

.game-card .thumb .play-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(124, 115, 255, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: #fff;
  transform: scale(0.7);
  transition: transform 0.25s;
  backdrop-filter: blur(4px);
}
.game-card:hover .play-icon { transform: scale(1); }

.game-card .fav-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.45);
  border: none;
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  z-index: 2;
  opacity: 0;
  backdrop-filter: blur(4px);
}
.game-card:hover .fav-btn { opacity: 1; }
.game-card .fav-btn:hover { transform: scale(1.12); background: rgba(0, 0, 0, 0.7); }
.game-card .fav-btn.favorited { color: var(--accent); background: var(--accent-glow); opacity: 1; }

.game-card .info {
  padding: 10px 12px;
}
.game-card .info h3 {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Game page */
.game-page-wrapper {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px;
}

.game-game {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.game-canvas-wrapper {
  position: relative;
  background: #000;
}

.game-canvas-wrapper iframe {
  width: 100%;
  height: 65vh;
  border: none;
  display: block;
}

.game-meta {
  padding: 20px;
}

.game-meta-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.game-meta-header .category-badge {
  font-size: 0.7rem;
  background: var(--primary-dim);
  color: var(--primary);
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.game-meta h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

.game-desc {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.6;
}

.fullscreen-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  backdrop-filter: blur(4px);
}
.fullscreen-btn:hover { opacity: 1; background: rgba(124, 115, 255, 0.7); }

.game-fav-row {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  align-items: center;
}
.game-fav-row button, .game-fav-row a {
  padding: 10px 20px;
  border: 1.5px solid var(--surface2);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.game-fav-row button:hover { border-color: var(--accent); color: var(--accent); }
.game-fav-row button.favorited { border-color: var(--accent); color: var(--accent); background: var(--accent-glow); }

.btn-secondary {
  background: var(--surface2) !important;
  color: var(--text) !important;
  border: none !important;
}
.btn-secondary:hover { background: var(--surface3) !important; }

.game-about-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 16px;
  box-shadow: var(--shadow);
}
.game-about-section h3 {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  color: var(--text);
}
.game-about-section .edit-btn {
  background: var(--surface2);
  border: none;
  color: var(--text-dim);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.game-about-section .edit-btn:hover { background: var(--primary); color: #fff; }
.game-about-section .instructions {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.6;
  min-height: 40px;
  outline: none;
  border-radius: 6px;
  padding: 8px;
  transition: background 0.2s;
}
.game-about-section .instructions:focus {
  background: var(--primary-dim);
  box-shadow: inset 0 0 0 1px var(--primary);
}
.game-about-section .instructions:empty:before {
  content: 'Click edit to add instructions, tips, or how to play...';
  color: #555;
}
.game-about-section .save-hint {
  font-size: 0.7rem;
  color: #555;
  margin-top: 8px;
  text-align: right;
  display: none;
}
.game-about-section .save-hint.show { display: block; }

.ad-space {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  margin-top: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  border: 1px dashed var(--surface2);
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ad-space.has-ad {
  border-style: solid;
  padding: 0;
  background: transparent;
  min-height: 0;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state p { font-size: 1rem; }

footer {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  margin-top: 48px;
}

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

@media (max-width: 860px) {
  .game-grid { grid-template-columns: repeat(3, 1fr); gap: 12px; }
  .game-canvas-wrapper iframe { height: 50vh; }
  .container { padding: 24px 16px; }
  header { padding: 12px 18px; }
  header .logo { font-size: 1.25rem; }
  header .logo::before { width: 24px; height: 24px; }
}

@media (max-width: 580px) {
  .game-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .game-canvas-wrapper iframe { height: 40vh; }
  .game-card .info h3 { font-size: 0.75rem; }
  .game-card .info { padding: 8px 10px; }
  .game-page-wrapper { padding: 16px; }
  .page-title { font-size: 1.3rem; margin-bottom: 18px; }
  header { flex-direction: column; gap: 10px; }
  header nav a { font-size: 0.8rem; padding: 6px 12px; }

  .sidebar {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%;
    max-height: none;
    z-index: 200;
    background: rgba(0,0,0,0.6);
    padding: 0;
    overflow-y: auto;
  }
  .sidebar.open { display: block; }

  .sidebar .sidebar-close {
    display: block;
    position: sticky;
    top: 0;
    width: 100%;
    padding: 14px 16px;
    background: var(--surface);
    border: none;
    color: var(--text);
    font-size: 1.1rem;
    font-weight: 700;
    text-align: right;
    cursor: pointer;
    z-index: 1;
  }

  .sidebar .cat-btn {
    padding: 12px 16px;
    font-size: 0.9rem;
    background: var(--surface);
    border-bottom: 1px solid var(--surface2);
    border-radius: 0;
  }
  .sidebar .cat-btn:first-of-type { margin-top: 0; }
  .sidebar .cat-btn.active { border-radius: 0; }

  .layout { gap: 0; }
}
