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

:root {
  --bg:           #0a0a0f;
  --surface:      #111118;
  --surface-2:    #18181f;
  --surface-3:    #1f1f2a;
  --border:       #252530;
  --border-light: #2e2e3d;
  --accent:       #7c3aed;
  --accent-dim:   #6d28d9;
  --accent-light: #a78bfa;
  --accent-glow:  rgba(124,58,237,.25);
  --text:         #e8e8f0;
  --text-dim:     #9090a8;
  --text-muted:   #52526a;
  --star:         #f59e0b;
  --radius:       10px;
  --radius-sm:    6px;
  --header-h:     58px;
  --shadow:       0 4px 24px rgba(0,0,0,.5);
}

html { font-size: 16px; scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: rgba(10,10,15,.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.site-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  text-decoration: none;
}
.site-logo {
  font-size: 1rem;
  color: var(--accent-light);
  line-height: 1;
}
.site-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.nav-wrap {
  display: none;
}
.nav-wrap::before,
.nav-wrap::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  width: 3rem;
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  transition: opacity .2s;
}
.nav-wrap::before {
  left: 0;
  background: linear-gradient(to right, var(--bg), transparent);
}
.nav-wrap::after {
  right: 0;
  background: linear-gradient(to left, var(--bg), transparent);
}
.nav-wrap.fade-left::before  { opacity: 1; }
.nav-wrap.fade-right::after  { opacity: 1; }

.nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 1.75rem;
  height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface-3);
  border: 1px solid var(--border-light);
  color: var(--text-dim);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, background .12s, color .12s;
  flex-shrink: 0;
}
.nav-arrow svg { width: 12px; height: 12px; }
.nav-arrow:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.nav-arrow-left  { left: 0; }
.nav-arrow-right { right: 0; }
.nav-wrap.fade-left  .nav-arrow-left  { opacity: 1; pointer-events: auto; }
.nav-wrap.fade-right .nav-arrow-right { opacity: 1; pointer-events: auto; }

.system-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.system-nav::-webkit-scrollbar { display: none; }

.nav-loading { font-size: .8rem; color: var(--text-muted); }

.system-tab {
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-dim);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  border: none;
  background: none;
  transition: color .12s, background .12s;
  line-height: 1.6;
}
.system-tab:hover  { color: var(--text); background: var(--surface-3); }
.system-tab.active { background: var(--accent); color: #fff; }

.header-controls {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Hamburger — hidden on desktop */
.hamburger {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  background: var(--surface-3);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  white-space: nowrap;
  font-size: 0.78rem;
  font-weight: 500;
  flex-shrink: 0;
  transition: background .12s, color .12s;
}
.hamburger svg { width: 15px; height: 12px; flex-shrink: 0; }
.hamburger:hover { background: var(--surface-2); color: var(--text); }

/* Nav drawer */
.nav-drawer {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border-light);
  z-index: 400;
  transform: translateX(-100%);
  transition: transform .25s ease;
  display: flex;
  flex-direction: column;
}
.nav-drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.drawer-close {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  border-radius: 4px;
  transition: color .12s, background .12s;
}
.drawer-close svg { width: 16px; height: 16px; }
.drawer-close:hover { background: var(--surface-3); color: var(--text); }

.drawer-list {
  overflow-y: auto;
  flex: 1;
  padding: 0.5rem 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}
.drawer-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.625rem 1.25rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background .1s, color .1s;
}
.drawer-item:hover  { background: var(--surface-2); color: var(--text); }
.drawer-item.active { color: var(--accent-light); font-weight: 600; background: var(--surface-2); }

/* Backdrop */
.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 399;
  backdrop-filter: blur(2px);
}
.nav-backdrop.open { display: block; }

/* All-systems search toggle — sliding switch */
.all-systems-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  opacity: 0.35;
  pointer-events: none;
  transition: opacity .15s, color .15s;
  user-select: none;
  position: relative;
}
.all-systems-toggle input { display: none; }

/* Track */
.all-systems-toggle::before {
  content: '';
  width: 28px;
  height: 16px;
  border-radius: 8px;
  background: var(--border-light);
  flex-shrink: 0;
  transition: background .15s;
}

/* Thumb */
.all-systems-toggle::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 50%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  transform: translateY(-50%) translateX(0);
  transition: transform .15s, background .15s;
}

.all-systems-toggle.available {
  opacity: 1;
  pointer-events: auto;
  color: var(--text-dim);
}
.all-systems-toggle.available:hover::before { background: var(--border); }

.all-systems-toggle.active {
  color: var(--accent-light);
  opacity: 1;
  pointer-events: auto;
}
.all-systems-toggle.active::before { background: var(--accent); }
.all-systems-toggle.active::after {
  background: #fff;
  transform: translateY(-50%) translateX(12px);
}

.search-wrap {
  position: relative;
}
.search-icon {
  position: absolute;
  left: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  pointer-events: none;
}
.search-wrap input {
  background: var(--surface-3);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  padding: 0.38rem 0.75rem 0.38rem 2rem;
  width: 200px;
  outline: none;
  transition: border-color .15s, width .2s;
}
.search-wrap input:focus {
  border-color: var(--accent-light);
  width: 240px;
}
.search-wrap input::placeholder { color: var(--text-muted); }

/* ── Main ────────────────────────────────────────────────────────────────── */
.main-content {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.25rem;
}

/* ── Toolbar ─────────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 0.75rem;
}
.toolbar-left  { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.toolbar-right { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }

.game-count { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; }

.toolbar-left select {
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.8rem;
  padding: 0.3rem 0.65rem;
  outline: none;
  cursor: pointer;
  max-width: 180px;
}
.toolbar-left select:focus { border-color: var(--accent-light); }

.view-toggle { display: flex; gap: 2px; }
.view-btn {
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 0.3rem 0.45rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: color .12s, background .12s;
}
.view-btn svg { width: 14px; height: 14px; }
.view-btn:hover  { color: var(--text); }
.view-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Grid view ───────────────────────────────────────────────────────────── */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.875rem;
}

.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, border-color .15s;
  display: flex;
  flex-direction: column;
}
.game-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 8px 28px var(--accent-glow);
}

.card-cover {
  aspect-ratio: 3 / 4;
  background: var(--surface-3);
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
}

.system-badge {
  position: absolute;
  bottom: 0.4rem;
  left: 0.4rem;
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(4px);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  letter-spacing: 0.02em;
  pointer-events: none;
  max-width: calc(100% - 0.8rem);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .2s;
}
.game-card:hover .card-cover img { transform: scale(1.04); }

.cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, var(--surface-3), var(--border));
}
.cover-placeholder span {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: -0.03em;
}

.card-info { padding: 0.6rem 0.7rem 0.7rem; flex: 1; }
.card-name {
  font-size: 0.775rem;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: 0.3rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-genre {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}
.card-stars { font-size: 0.6rem; letter-spacing: 1px; }
.star-on  { color: var(--star); }
.star-off { color: var(--border-light); }

/* ── List view ───────────────────────────────────────────────────────────── */
.game-grid.list-view {
  grid-template-columns: 1fr;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.game-grid.list-view .game-card {
  flex-direction: row;
  align-items: center;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  gap: 0.875rem;
  padding: 0.5rem 0.875rem 0.5rem 0.5rem;
}
.game-grid.list-view .game-card:last-child { border-bottom: none; }
.game-grid.list-view .game-card:hover { transform: none; box-shadow: none; background: var(--surface-2); }
.game-grid.list-view .card-cover {
  width: 36px;
  height: 48px;
  aspect-ratio: unset;
  border-radius: 4px;
  flex-shrink: 0;
}
.game-grid.list-view .card-info {
  flex: 1;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}
.game-grid.list-view .card-name {
  flex: 1;
  font-size: 0.85rem;
  -webkit-line-clamp: 1;
  min-width: 0;
}
.game-grid.list-view .card-genre { font-size: 0.78rem; width: 100px; flex-shrink: 0; }
.game-grid.list-view .card-stars { width: 60px; flex-shrink: 0; }

/* ── States ─────────────────────────────────────────────────────────────── */
.empty-state[hidden], .loading-state[hidden] { display: none; }
.empty-state, .loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5rem 2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  gap: 0.75rem;
}
.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border-light);
  border-top-color: var(--accent-light);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Setup notice ────────────────────────────────────────────────────────── */
.setup-notice {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
}
.setup-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 3rem;
  text-align: center;
  max-width: 380px;
}
.setup-box h2 { font-size: 1.25rem; margin-bottom: 0.75rem; }
.setup-box p  { color: var(--text-dim); font-size: 0.9rem; margin-bottom: 1.5rem; line-height: 1.6; }
.btn-primary {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 0.6rem 1.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  transition: background .15s;
}
.btn-primary:hover { background: var(--accent-dim); }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.modal-overlay[hidden] { display: none; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  max-width: 820px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow);
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}

.modal-close {
  position: sticky;
  top: 0.875rem;
  float: right;
  margin: 0.875rem 0.875rem 0 0;
  background: var(--surface-3);
  border: 1px solid var(--border-light);
  border-radius: 50%;
  color: var(--text-dim);
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1;
  flex-shrink: 0;
  transition: background .12s, color .12s;
}
.modal-close svg { width: 13px; height: 13px; }
.modal-close:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

.modal-body { padding: 1.5rem; }

.modal-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem;
}

/* ── Modal content ───────────────────────────────────────────────────────── */
.modal-top {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  align-items: start;
  clear: both;
}

.modal-cover { position: relative; }
.modal-cover img {
  width: 100%;
  border-radius: var(--radius-sm);
  display: block;
  box-shadow: var(--shadow);
}

.modal-meta h2 {
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.25;
  margin-bottom: 0.5rem;
}

.modal-stars { font-size: 1rem; letter-spacing: 2px; margin-bottom: 0.875rem; }

.meta-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-bottom: 1rem;
}
.meta-pill {
  background: var(--surface-3);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  font-size: 0.72rem;
  padding: 0.2rem 0.55rem;
  color: var(--text-dim);
  line-height: 1.5;
}
.meta-pill strong { color: var(--text); font-weight: 600; }

.modal-desc {
  font-size: 0.85rem;
  line-height: 1.75;
  color: var(--text-dim);
  white-space: pre-wrap;
}

/* ── Modal video ─────────────────────────────────────────────────────────── */
.modal-video {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.625rem;
  flex-wrap: wrap;
}
.video-preview-btn, .manual-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface-3);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
  text-decoration: none;
}
.video-preview-btn svg, .manual-link svg { width: 16px; height: 16px; flex-shrink: 0; }
.video-preview-btn:hover, .manual-link:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Modal media strip ───────────────────────────────────────────────────── */
.modal-media {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}
.modal-media-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.625rem;
}
.media-strip {
  display: flex;
  gap: 0.625rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}
.media-strip img {
  height: 144px;
  width: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color .12s, opacity .12s;
  object-fit: cover;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.media-strip img:hover { border-color: var(--accent-light); opacity: .9; }

/* ── Lightbox ────────────────────────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.92);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 95vw;
  max-height: 90vh;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 640px) {

  /* Header: single row — search | toggle | hamburger */
  .header-inner    { padding: 0 .875rem; gap: .5rem; }
  .site-brand      { display: none; }
  .header-controls { flex: 1; min-width: 0; gap: .375rem; }
  .search-wrap     { flex: 1; min-width: 0; }
  .search-wrap input,
  .search-wrap input:focus { width: 100%; transition: border-color .15s; }
  .all-systems-toggle span { display: none; }

  /* Toolbar */
  .view-toggle { display: none; }

  /* Game grid */
  .game-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .625rem; }

  /* Modal: full-screen */
  .modal-overlay { padding: 0; align-items: flex-start; }
  .modal-box {
    max-width: 100%;
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }
  .modal-close {
    width: 40px;
    height: 40px;
    top: .75rem;
    margin: .75rem .75rem 0 0;
  }
  .modal-close svg { width: 16px; height: 16px; }
  .modal-top     { grid-template-columns: 130px 1fr; gap: 1rem; }
  .modal-meta h2 { font-size: 1.05rem; }
}

@media (max-width: 420px) {
  .game-grid   { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .modal-top   { grid-template-columns: 1fr; }
  .modal-cover { max-width: 160px; }
}

@media (max-width: 640px) {
  .toolbar         { flex-direction: column; align-items: stretch; gap: 0.5rem; }
  .toolbar-left    { flex-direction: column; align-items: stretch; gap: 0.375rem; }
  .toolbar-left select { max-width: 100%; }
  .toolbar-right   { display: none; }
  .game-count      { font-size: 0.75rem; }
}
