:root {
  --bg: #0a0c10;
  --panel: #141820;
  --line: #2a3140;
  --text: #eef1f6;
  --muted: #8b93a7;
  --accent: #3dd68c;
  --radius: 12px;
  font-family: "Segoe UI", system-ui, sans-serif;
}

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

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: rgba(10, 12, 16, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.logo { color: var(--accent); }
.brand h1 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.04em;
}

.search-box { flex: 1; max-width: 420px; }
.search-box input {
  width: 100%;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #1a1f2a;
  color: var(--text);
  font-size: 0.9rem;
}
.search-box input:focus {
  outline: 2px solid #1f8f5a;
  border-color: var(--accent);
}

.lib-status {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}
.lib-status.warn { color: #f0c040; }

code {
  font-size: 0.85em;
  color: #f0c040;
}

.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 3rem;
}

.hero { margin-bottom: 1.5rem; }
.hero h2 { margin: 0 0 0.35rem; font-size: 1.5rem; }
.hero p { margin: 0; color: var(--muted); font-size: 0.9rem; }

.platform {
  margin-bottom: 2rem;
  overflow: visible;
}
.platform h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  overflow: visible;
}

.game-card {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  text-align: left;
  color: inherit;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  position: relative;
}
.game-card:hover {
  transform: translateY(-3px);
  border-color: #1f8f5a;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
}
.game-card.previewing {
  overflow: visible;
  z-index: 8;
}
.game-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cover {
  background: linear-gradient(145deg, #1e2430, #0d1016);
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
}
/* Sin imagen: caja de respaldo; con imagen: proporción original */
.cover.no-img,
.cover:not(:has(img)) {
  aspect-ratio: 3 / 4;
}
.cover img {
  width: 100%;
  height: auto;
  display: block;
  position: relative;
  z-index: 1;
}
/* Preview con proporción nativa del vídeo (no recortado a 3:4) */
.cover-video {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  width: auto;
  height: auto;
  max-width: min(320px, 70vw);
  max-height: min(220px, 40vh);
  object-fit: contain;
  opacity: 0;
  pointer-events: none;
  z-index: 6;
  background: #000;
  border: 1px solid rgba(61, 214, 140, 0.45);
  border-radius: 6px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.65);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.cover.previewing {
  overflow: visible;
}
.cover.previewing .cover-video {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
.cover.previewing img {
  opacity: 0.35;
}
.cover-fallback {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  opacity: 0.7;
  z-index: 0;
  pointer-events: none;
}
.cover.no-img .cover-fallback,
.cover:not(:has(img)) .cover-fallback {
  display: flex;
}
.cover.previewing.no-img .cover-fallback {
  display: none;
}

.game-info {
  padding: 0.65rem 0.75rem 0.8rem;
}
.game-info h4 {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.game-info span {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.no-results {
  text-align: center;
  color: var(--muted);
  padding: 2rem;
}

/* Overlay emulador */
.emulator-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.emulator-overlay[hidden] { display: none !important; }

.emulator-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
}

.emulator-panel {
  position: relative;
  z-index: 1;
  width: min(1100px, 100%);
  max-height: 96vh;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.emulator-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.emulator-head h2 {
  margin: 0;
  font-size: 1.05rem;
}
.meta {
  margin: 0.2rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.btn-close {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #1a1f2a;
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
}
.btn-close:hover { border-color: var(--accent); }

.game-screen {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  min-height: 420px;
  height: min(78vh, 640px);
  background: #000;
  overflow: hidden;
}

.ejs-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; }
  .search-box { max-width: none; width: 100%; order: 3; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}
