:root {
  --bg: #0b0e17;
  --bg-elev: #131826;
  --bg-card: #181f32;
  --border: #26314d;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #6366f1;
  --accent-2: #22d3ee;
  --danger: #f43f5e;
  --success: #10b981;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --border: #cbd5e1;
  --text: #0f172a;
  --muted: #475569;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

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

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

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(11, 14, 23, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
[data-theme="light"] .topbar { background: rgba(255, 255, 255, 0.92); }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  color: var(--text);
}
.brand-badge {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
}
.btn:hover { border-color: var(--accent-2); transform: translateY(-1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  border-color: transparent;
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-accent {
  background: linear-gradient(135deg, #0ea5e9, var(--accent-2));
  border-color: transparent;
  color: #06131f;
}
.btn-sm { padding: 5px 10px; font-size: 0.8rem; border-radius: 8px; }

/* Container */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

/* Hero / Controls */
.hero {
  background: radial-gradient(circle at top right, rgba(99, 102, 241, 0.22), transparent 55%),
              radial-gradient(circle at bottom left, rgba(34, 211, 238, 0.14), transparent 55%),
              var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.hero h1 { font-size: 1.8rem; line-height: 1.2; margin-bottom: 6px; }
.hero p { color: var(--muted); max-width: 640px; font-size: 0.95rem; }

.controls-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
  align-items: center;
}
.search-input {
  flex: 1 1 260px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}
.search-input:focus { border-color: var(--accent-2); }

.select-input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 0.9rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}
.chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip:hover { color: var(--text); border-color: var(--accent); }
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.stats-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.88rem;
}

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

.game-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}
.game-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent-2);
  box-shadow: var(--shadow);
}

.game-thumb {
  height: 126px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.game-thumb-icon {
  font-size: 2.6rem;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.45));
  transition: transform 0.2s ease;
}
.game-card:hover .game-thumb-icon { transform: scale(1.14); }

.game-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.58);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
}
.game-diff {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.58);
  color: #e2e8f0;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
}

.game-info {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.game-title {
  font-weight: 700;
  font-size: 0.96rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.game-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--muted);
}
.game-card-actions {
  display: flex;
  gap: 6px;
  margin-top: auto;
  padding-top: 6px;
}
.game-card-actions .btn { flex: 1; }

/* Load More */
.load-more-wrap {
  text-align: center;
  margin: 28px 0;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 15, 0.84);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop.open { display: flex; }

.modal-box {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 960px;
  max-height: 94vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}
.modal-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

/* Game Player Stage */
.player-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background: #070a12;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.player-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px;
  background: #101626;
  border-bottom: 1px solid #1e293b;
  color: #f8fafc;
  font-size: 0.86rem;
}
.hud-scores {
  display: flex;
  gap: 14px;
  font-weight: 700;
}
.hud-scores span b { color: var(--accent-2); }
.hud-controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.player-stage {
  position: relative;
  width: 100%;
  height: 480px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #05070e;
  user-select: none;
  touch-action: none;
}
.player-stage canvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
}
.player-overlay {
  position: absolute;
  inset: 0;
  background: rgba(5, 7, 14, 0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  color: #fff;
  gap: 12px;
}
.player-overlay.hidden { display: none; }
.player-overlay h2 { font-size: 1.6rem; }
.player-overlay p { color: #cbd5e1; max-width: 420px; font-size: 0.92rem; }

.touch-pad {
  display: none;
  justify-content: center;
  gap: 8px;
  padding: 8px;
  background: #0d1321;
  border-top: 1px solid #1e293b;
}
@media (pointer: coarse), (max-width: 720px) {
  .touch-pad { display: flex; }
  .player-stage { height: 360px; }
}

/* Embed Studio */
.embed-section {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-top: 28px;
}
.embed-tabs {
  display: flex;
  gap: 8px;
  margin: 14px 0 18px;
  flex-wrap: wrap;
}
.code-block {
  position: relative;
  background: #060911;
  color: #e2e8f0;
  border: 1px solid #1e293b;
  border-radius: 10px;
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 8px 0 14px;
}
.embed-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.embed-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.embed-card h3 { font-size: 1.02rem; margin-bottom: 6px; }
.embed-card p { font-size: 0.86rem; color: var(--muted); margin-bottom: 10px; }

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.form-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--muted);
}
.form-row input, .form-row select {
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.86rem;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--success);
  color: #032217;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 200;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: all 0.2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
