/* ── CSS Variables ── */
:root {
  --bg: #0a0a0f;
  --surface: #13131a;
  --border: #1e1e2e;
  --accent: #00e5a0;
  --accent2: #7c3aed;
  --warn: #f97316;
  --danger: #ef4444;
  --text: #e2e8f0;
  --muted: #64748b;
  --radius: 10px;
}

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

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

/* ── Play page body override ── */
.play-page { height: 100%; background: #000; }
html:has(.play-page) { height: 100%; }

/* ── Scanlines overlay ── */
body::before {
  content: '';
  position: fixed; inset: 0;
  background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,.08) 2px, rgba(0,0,0,.08) 4px);
  pointer-events: none; z-index: 9999;
}

/* ── Header ── */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,10,15,.95);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 100;
}
.logo { font-family: 'Press Start 2P', monospace; font-size: .95rem; letter-spacing: 0; line-height: 1.4; }
.logo span { color: var(--accent); }

/* ── Session timer (index.html uses #session-timer, play.html uses #timer-wrap) ── */
#session-timer {
  font-size: .8rem; color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}
#timer-wrap {
  display: flex; align-items: center; gap: 6px;
  font-size: .8rem; color: var(--muted);
}
#timer-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }
#timer-text { font-variant-numeric: tabular-nums; }

/* ── Expiry banner ── */
#expiry-banner {
  display: none;
  background: linear-gradient(90deg, #7c2d12, #9a3412);
  border-bottom: 1px solid #c2410c;
  padding: 10px 32px;
  font-size: .85rem;
  align-items: center; justify-content: space-between; gap: 12px;
}
#expiry-banner.show { display: flex; }
#extend-btn {
  background: var(--warn); color: #fff;
  border: none; border-radius: 6px;
  padding: 6px 14px; font-size: .8rem; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
#extend-note { color: #fed7aa; }

/* ── Spinner ── */
.spinner {
  width: 40px; height: 40px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 1s linear infinite; margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Buttons ── */
.btn {
  display: inline-block; margin-top: 8px;
  background: var(--accent); color: #000;
  border: none; border-radius: 8px;
  padding: 10px 24px; font-size: .9rem; font-weight: 700;
  cursor: pointer; text-decoration: none;
}
.btn-primary {
  background: var(--accent); color: #000;
  border: none; border-radius: 8px;
  padding: 10px 20px; font-size: .9rem; font-weight: 700;
  cursor: pointer; transition: opacity .2s;
  white-space: nowrap;
}
.btn-primary:hover { opacity: .85; }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }
.btn-ghost {
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); border-radius: 8px;
  padding: 9px 24px; font-size: .85rem; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

/* ── Error text ── */
.err { color: var(--danger); font-size: .82rem; margin-top: 8px; }

/* ════════════════════════════════════════════════
   INDEX.HTML — FREE GAMES SECTION
   ════════════════════════════════════════════════ */

#free-section {
  max-width: 1400px; margin: 0 auto;
  padding: 32px 32px 0;
}
.free-hero {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 20px; flex-wrap: wrap;
}
.free-hero-text h2 {
  font-family: 'Press Start 2P', monospace;
  font-size: .7rem; color: var(--accent); margin-bottom: 8px;
  letter-spacing: .04em;
}
.free-hero-text p {
  font-size: .85rem; color: var(--muted); line-height: 1.5;
}
.view-all-btn {
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); border-radius: 8px;
  padding: 7px 16px; font-size: .78rem; cursor: pointer;
  transition: border-color .15s, color .15s;
  white-space: nowrap; align-self: center;
  text-decoration: none; display: inline-block;
}
.view-all-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Premium teaser / gate view ── */
#premium-section {
  max-width: 1400px; margin: 0 auto;
  padding: 32px 32px 40px;
}
.premium-divider {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 28px;
}
.premium-divider::before, .premium-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.premium-divider span {
  font-size: .7rem; color: var(--muted); white-space: nowrap;
  font-weight: 600; text-transform: uppercase; letter-spacing: .08em;
}
.premium-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 40px;
  display: flex; gap: 40px; align-items: flex-start;
  flex-wrap: wrap;
}
.premium-card-text { flex: 1; min-width: 260px; }
.premium-card-text .lock-icon {
  font-size: 2.2rem; margin-bottom: 14px;
}
.premium-card-text h2 {
  font-size: 1.35rem; font-weight: 800; margin-bottom: 10px; line-height: 1.25;
}
.premium-card-text h2 span { color: var(--accent); }
.premium-card-text p {
  color: var(--muted); font-size: .9rem; line-height: 1.65; margin-bottom: 20px;
}
.premium-stats {
  display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: 24px;
}
.premium-stat {
  text-align: center;
  background: rgba(0,229,160,.05); border: 1px solid rgba(0,229,160,.12);
  border-radius: 10px; padding: 10px 18px;
}
.premium-stat .stat-num {
  font-size: 1.4rem; font-weight: 800; color: var(--accent); display: block;
}
.premium-stat .stat-label {
  font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em;
}
.premium-form { flex: 1; min-width: 260px; max-width: 380px; }
.premium-form label {
  font-size: .8rem; color: var(--muted); display: block;
  margin-bottom: 4px; margin-top: 14px;
}
.premium-form label:first-child { margin-top: 0; }
.premium-form input[type="text"] {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px;
  color: var(--text); font-size: .95rem;
  outline: none; transition: border-color .2s;
}
.premium-form input[type="text"]:focus { border-color: var(--accent); }
#submit-request-btn { width: 100%; margin-top: 16px; }

/* ── Pending state ── */
#pending-state { display: none; text-align: center; padding: 20px 0; }
.status-msg { font-size: .85rem; color: var(--muted); margin-top: 8px; }

/* ── Game preview blurred row ── */
.premium-preview {
  margin-top: 24px;
  display: flex; gap: 10px; overflow: hidden;
  pointer-events: none; user-select: none;
}
.preview-card {
  flex: 0 0 90px; aspect-ratio: 5/7;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
  filter: blur(3px) brightness(.5);
  position: relative;
}
.preview-card svg { width: 100%; height: 100%; }

/* ── Library view (premium users) ── */
#library-view { display: none; padding: 28px 32px; max-width: 1400px; margin: 0 auto; }

/* ── Search + filter bar ── */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; margin-bottom: 24px;
}
.search-wrap { position: relative; flex: 1; min-width: 200px; }
.search-wrap input {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 14px 9px 38px;
  color: var(--text); font-size: .9rem; outline: none;
  transition: border-color .2s;
}
.search-wrap input:focus { border-color: var(--accent); }
.search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: .9rem; pointer-events: none;
}
.sys-filters { display: flex; flex-wrap: wrap; gap: 6px; }
.sys-btn {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 5px 14px;
  font-size: .78rem; font-weight: 600; cursor: pointer;
  color: var(--muted); transition: all .15s;
}
.sys-btn:hover { border-color: var(--accent); color: var(--accent); }
.sys-btn.active { background: var(--accent); border-color: var(--accent); color: #000; }

/* ── Section header ── */
.section-title {
  font-size: 1rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
  margin-bottom: 16px;
}

/* ── Game grid ── */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s, border-color .15s, box-shadow .15s;
  text-decoration: none; color: inherit;
}
.game-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(0,229,160,.12);
}
.game-thumb {
  width: 100%; aspect-ratio: 5/7;
  position: relative; overflow: hidden;
}
.game-thumb img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; z-index: 2; }
.game-thumb .cart-art { position: absolute; inset: 0; width: 100%; height: 100%; }

/* ── Favorite button ── */
.fav-btn {
  position: absolute; top: 7px; right: 7px; z-index: 5;
  background: rgba(0,0,0,.55); border: none; border-radius: 50%;
  width: 30px; height: 30px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem; transition: background .15s, transform .15s;
  backdrop-filter: blur(4px);
}
.fav-btn:hover { background: rgba(0,0,0,.8); transform: scale(1.15); }
.fav-btn.active { background: rgba(229,57,53,.7); }

/* ── Curated section ── */
#curated-section { margin-bottom: 12px; }
.game-info { padding: 10px 12px 12px; }
.game-name {
  font-size: .82rem; font-weight: 600; line-height: 1.3;
  overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.sys-badge {
  display: inline-block; margin-top: 6px;
  font-size: .65rem; font-weight: 700;
  padding: 2px 7px; border-radius: 4px;
  text-transform: uppercase; letter-spacing: .04em;
}
.free-tag {
  display: inline-block; margin-top: 6px; margin-left: 4px;
  font-size: .6rem; font-weight: 700;
  padding: 2px 6px; border-radius: 4px;
  background: rgba(0,229,160,.15); color: var(--accent);
  text-transform: uppercase;
}

/* ── Load more ── */
.load-more-wrap { text-align: center; margin: 16px 0 32px; }

/* ── Empty state ── */
.empty { text-align: center; color: var(--muted); padding: 60px 0; font-size: .9rem; }

/* ── Free games mini-grid in free section ── */
#free-grid-mini {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
#free-all-panel { display: none; }
#free-all-panel.open { display: block; }
#free-grid-all {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

/* ── Free section divider from premium ── */
.section-sep {
  height: 1px; background: var(--border);
  max-width: 1400px; margin: 0 auto;
}

/* ════════════════════════════════════════════════
   PLAY.HTML — EMULATOR PAGE
   ════════════════════════════════════════════════ */

/* ── Top bar ── */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 44px; position: relative; z-index: 10;
}
#back-btn {
  display: flex; align-items: center; gap: 6px;
  color: var(--muted); text-decoration: none; font-size: .85rem;
  transition: color .15s;
}
#back-btn:hover { color: var(--accent); }
#game-title { font-size: .9rem; font-weight: 600; }

/* ── Emulator container ── */
#game-wrap {
  width: 100%;
  height: calc(100vh - 44px);
  display: flex; align-items: center; justify-content: center;
  background: #000;
}
#game-wrap.has-banner { height: calc(100vh - 44px - 36px); }

/* EmulatorJS overrides */
#game { width: 100%; height: 100%; }

/* ── Loading / error states ── */
#loading-screen {
  position: fixed; inset: 0; background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; z-index: 50;
}
#loading-screen p { color: var(--muted); font-size: .9rem; }

#error-screen {
  display: none; position: fixed; inset: 0; background: #000;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; text-align: center; padding: 32px;
}
#error-screen h2 { font-size: 1.2rem; }
#error-screen p { color: var(--muted); font-size: .9rem; max-width: 360px; line-height: 1.6; }

/* ════════════════════════════════════════════════
   MEDIA QUERIES
   ════════════════════════════════════════════════ */

@media(max-width: 600px) {
  header { padding: 14px 16px; }
  .logo { font-size: .65rem; }
  #library-view { padding: 20px 16px; }
  #free-section, #premium-section { padding-left: 16px; padding-right: 16px; }
  .game-grid, #free-grid-mini, #free-grid-all { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
  .premium-card { padding: 24px 20px; gap: 24px; }
  .premium-card-text h2 { font-size: 1.1rem; }
}
