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

:root {
  --bg: #0d0d0f;
  --surface: #18181c;
  --surface2: #222228;
  --border: #2e2e38;
  --accent: #ff6b35;
  --accent2: #ff9a00;
  --text: #e8e8f0;
  --text2: #8888a8;
  --radius: 10px;
  --flash: #ff4444;
  --html5: #3b82f6;
  --shockwave: #8b5cf6;
  --java: #f59e0b;
  --unity: #22c55e;
}

html { scroll-behavior: smooth; }

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

/* ── Header ── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(13,13,15,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
}
.logo svg { flex-shrink: 0; }
.stats {
  font-size: 0.82rem;
  color: var(--text2);
  white-space: nowrap;
}

/* ── Main ── */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

/* ── Search ── */
.search-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 240px;
}
.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text2);
  pointer-events: none;
}
#searchInput {
  width: 100%;
  padding: 12px 42px 12px 42px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}
#searchInput:focus { border-color: var(--accent); }
#searchInput::placeholder { color: var(--text2); }
.clear-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 14px;
  padding: 4px;
  line-height: 1;
}
.clear-btn:hover { color: var(--text); }
.filters { display: flex; gap: 10px; }
.filters select {
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}
.filters select:focus { border-color: var(--accent); }

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

.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
  position: relative;
}
.game-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 8px 28px rgba(255,107,53,0.18);
}
.game-thumb {
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--surface2);
  position: relative;
  overflow: hidden;
}
.game-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 0.3s;
}
.game-thumb img.loading { opacity: 0; }
.game-thumb img.loaded { opacity: 1; }
.thumb-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--border);
}
.thumb-placeholder svg { width: 40px; height: 40px; }

.game-info {
  padding: 10px 12px 12px;
}
.game-title {
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 6px;
}
.game-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.game-dev {
  font-size: 0.75rem;
  color: var(--text2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

/* ── Platform Badges ── */
.badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}
.badge-Flash    { background: rgba(255,68,68,0.2);  color: var(--flash); }
.badge-HTML5    { background: rgba(59,130,246,0.2); color: var(--html5); }
.badge-Shockwave{ background: rgba(139,92,246,0.2); color: var(--shockwave); }
.badge-Java     { background: rgba(245,158,11,0.2); color: var(--java); }
.badge-Unity    { background: rgba(34,197,94,0.2);  color: var(--unity); }
.badge-other    { background: rgba(136,136,168,0.2);color: var(--text2); }

.play-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.18s;
}
.game-card:hover .play-overlay { opacity: 1; }
.play-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Empty / Loading ── */
.empty-state, .loading-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 80px 24px;
  color: var(--text2);
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 32px;
  flex-wrap: wrap;
}
.pagination button {
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.88rem;
  transition: all 0.15s;
}
.pagination button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.pagination button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}
.pagination button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.pagination .page-info {
  font-size: 0.85rem;
  color: var(--text2);
  padding: 0 8px;
}

/* ── Modal ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.82);
  backdrop-filter: blur(4px);
}
.modal-content {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 900px;
  margin: auto;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
  animation: modalIn 0.2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-title-wrap { flex: 1; min-width: 0; }
.modal-title-wrap h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 6px;
  line-height: 1.2;
}
.modal-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.meta-item {
  font-size: 0.82rem;
  color: var(--text2);
}
.close-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text2);
  width: 32px; height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.close-btn:hover { color: var(--text); border-color: var(--text2); }

.modal-body { padding: 0; }

#ruffle-container {
  width: 100%;
  aspect-ratio: 4/3;
  background: #000;
  border-radius: 0;
  overflow: hidden;
  position: relative;
}
#ruffle-container ruffle-object,
#ruffle-container ruffle-embed {
  width: 100% !important;
  height: 100% !important;
}

.modal-info {
  padding: 16px 24px 20px;
}
#modalDesc {
  font-size: 0.88rem;
  color: var(--text2);
  line-height: 1.6;
  margin-bottom: 12px;
}
#modalDesc:empty { display: none; }
.tags-list {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.tag {
  font-size: 0.76rem;
  padding: 3px 9px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text2);
}

/* ── Responsive ── */
@media (max-width: 600px) {
  main { padding: 16px; }
  .header-inner { padding: 12px 16px; }
  .search-bar { flex-direction: column; }
  .filters { flex-wrap: wrap; }
  .game-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .modal { padding: 0; }
  .modal-content { border-radius: 0; min-height: 100vh; }
}
