/* ============================================================
   FONTS
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Figtree:wght@400;500;600;700;800&family=Lora:ital,wght@0,400;0,500;1,400&display=swap');

/* ============================================================
   THEME TOKENS
   ============================================================ */

/* =========================================
   Snyggare CSS-teman
   ========================================= */

:root {
  /* Gemensamma strukturella värden */
  --topbar-h:    52px;
  --r:           8px;  /* Något mjukare hörn */
  --r-lg:        12px;
  --ease:        cubic-bezier(0.23, 1, 0.32, 1); /* Modernare easing */
  
  /* Standard: Warm Dusk (Förfinad) */
  --bg-solid:    #1a1612;   /* Djupare bas */
  --surface:     #231f1b;   /* Bättre separation */
  --surface-2:   #2e2924;
  --surface-3:   #38312b;
  --border:      rgba(255,235,210,0.06);
  --border-hi:   rgba(255,235,210,0.12);
  --text:        #eee6dc;   /* Något ljusare för bättre kontrast */
  --text-dim:    #9c8c7c;
  --text-muted:  #5c5046;
  --accent:      #f0b085;   /* Varmare, klarare accent */
  --accent-dim:  rgba(240,176,133,0.1);
  --accent-glow: rgba(240,176,133,0.15);
  --danger:      #ff8585;   /* Tydligare röd */
  --danger-dim:  rgba(255,133,133,0.1);
  --topbar-bg:   rgba(26,22,18,0.95);
  --shadow:      0 4px 6px -1px rgba(0,0,0,0.4), 0 2px 4px -1px rgba(0,0,0,0.2);
}

/* --- Theme: Slate (Modern & Cool) --- */
[data-theme="slate"] {
  --bg-solid:    #10141c;
  --surface:     #171c26;
  --surface-2:   #1f2633;
  --surface-3:   #273040;
  --border:      rgba(180,200,240,0.05);
  --border-hi:   rgba(180,200,240,0.12);
  --text:        #e0e8f5;
  --text-dim:    #7a8ba8;
  --text-muted:  #455269;
  --accent:      #85b0f0;   /* Renare blå */
  --accent-dim:  rgba(133,176,240,0.1);
  --accent-glow: rgba(133,176,240,0.15);
  --topbar-bg:   rgba(16,20,28,0.95);
  --shadow:      0 4px 6px -1px rgba(0,0,0,0.5), 0 2px 4px -1px rgba(0,0,0,0.3);
}

/* --- Theme: Ember (Dark Charcoal + Red-Orange) --- */
[data-theme="ember"] {
  --bg-solid:    #151210;
  --surface:     #1e1916;
  --surface-2:   #28211d;
  --surface-3:   #332a25;
  --border:      rgba(255,160,80,0.06);
  --border-hi:   rgba(255,160,80,0.14);
  --text:        #f5ede6;
  --text-dim:    #a8897a;
  --text-muted:  #5f4438;
  --accent:      #ff6b35;
  --accent-dim:  rgba(255,107,53,0.10);
  --accent-glow: rgba(255,107,53,0.20);
  --danger:      #ff4d6d;
  --danger-dim:  rgba(255,77,109,0.10);
  --topbar-bg:   rgba(21,18,16,0.96);
  --shadow:      0 4px 12px rgba(0,0,0,0.5);
}

/* --- Theme: Arctic (Clean Light + Electric Blue) --- */
[data-theme="arctic"] {
  --bg-solid:    #f0f2f5;
  --surface:     #ffffff;
  --surface-2:   #e4e8ee;
  --surface-3:   #d5dbe5;
  --border:      rgba(30,60,120,0.10);
  --border-hi:   rgba(30,60,120,0.20);
  --text:        #0f1c2e;
  --text-dim:    #4a5e78;
  --text-muted:  #8a9bb0;
  --accent:      #1a6ff5;
  --accent-dim:  rgba(26,111,245,0.09);
  --accent-glow: rgba(26,111,245,0.18);
  --danger:      #e53935;
  --danger-dim:  rgba(229,57,53,0.09);
  --topbar-bg:   rgba(240,242,245,0.95);
  --shadow:      0 4px 16px -2px rgba(15,28,46,0.12), 0 2px 4px -1px rgba(15,28,46,0.06);
}
/* --- Theme: Noir (Pure Black + Champagne Gold) --- */
[data-theme="noir"] {
  --bg-solid:    #0a0a0a;
  --surface:     #111111;
  --surface-2:   #1c1c1c;
  --surface-3:   #262626;
  --border:      rgba(255,255,255,0.06);
  --border-hi:   rgba(255,255,255,0.12);
  --text:        #f7f7f7;
  --text-dim:    #888888;
  --text-muted:  #4a4a4a;
  --accent:      #d4a853;
  --accent-dim:  rgba(212,168,83,0.10);
  --accent-glow: rgba(212,168,83,0.22);
  --danger:      #e05050;
  --danger-dim:  rgba(224,80,80,0.10);
  --topbar-bg:   rgba(10,10,10,0.97);
  --shadow:      0 4px 20px rgba(0,0,0,0.7);
}
/* --- 2. OCEAN TRENCH (Mörkt & Oceaniskt) --- 
   Inspirerat av havets djup. En marinblå och teal-baserad palett 
   med en neonlysande cyan accent. */
[data-theme="ocean-trench"] {
  --bg-solid:    #0a1015;   /* Djuphavssvart */
  --surface:     #111921;   /* Mörk marinblå */
  --surface-2:   #192430;   /* För paneler */
  --surface-3:   #22303f;
  --border:      rgba(100,200,255,0.06);
  --border-hi:   rgba(100,200,255,0.14);
  --text:        #e6f1f5;   /* Isblå vit */
  --text-dim:    #7693a5;   /* Dämpad stormblå */
  --text-muted:  #405666;
  --accent:      #3fe3e3;   /* Elektrisk cyan / neon teal */
  --accent-dim:  rgba(63,227,227,0.08);
  --accent-glow: rgba(63,227,227,0.2);
  --danger:      #ff6b6b;
  --danger-dim:  rgba(255,107,107,0.08);
  --topbar-bg:   rgba(10,16,21,0.95);
  --shadow:      0 4px 12px rgba(0,5,15,0.6);
}

/* --- Theme: Crimson (Dark + Vivid Red) --- */
[data-theme="crimson"] {
  --bg-solid:    #0e0c0c;
  --surface:     #181313;
  --surface-2:   #221a1a;
  --surface-3:   #2c2020;
  --border:      rgba(220,60,60,0.07);
  --border-hi:   rgba(220,60,60,0.16);
  --text:        #f5f0f0;
  --text-dim:    #a08080;
  --text-muted:  #5a3a3a;
  --accent:      #e03030;
  --accent-dim:  rgba(224,48,48,0.10);
  --accent-glow: rgba(224,48,48,0.22);
  --danger:      #ff6b6b;
  --danger-dim:  rgba(255,107,107,0.10);
  --topbar-bg:   rgba(14,12,12,0.97);
  --shadow:      0 4px 16px rgba(0,0,0,0.6);
}
/* --- Theme: Forest (Deep Dark Green + Lime) --- */
[data-theme="forest"] {
  --bg-solid:    #080e08;
  --surface:     #0f1a0f;
  --surface-2:   #182618;
  --surface-3:   #203020;
  --border:      rgba(100,220,80,0.06);
  --border-hi:   rgba(100,220,80,0.14);
  --text:        #e8f5e8;
  --text-dim:    #7aaa7a;
  --text-muted:  #3d6040;
  --accent:      #5ddb3a;
  --accent-dim:  rgba(93,219,58,0.10);
  --accent-glow: rgba(93,219,58,0.20);
  --danger:      #ff5c5c;
  --danger-dim:  rgba(255,92,92,0.10);
  --topbar-bg:   rgba(8,14,8,0.97);
  --shadow:      0 4px 12px rgba(0,0,0,0.6);
}


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

html, body {
  height: 100%;
  background: var(--bg-solid);
  color: var(--text);
  font-family: 'Figtree', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font-family: 'Figtree', sans-serif; cursor: pointer; }
input  { font-family: 'Figtree', sans-serif; }

::-webkit-scrollbar             { width: 4px; height: 4px; }
::-webkit-scrollbar-track       { background: transparent; }
::-webkit-scrollbar-thumb       { background: var(--surface-3); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================================
   CONTAINER + TOPBAR
   ============================================================ */
.container { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--topbar-h); z-index: 900;
  display: flex; align-items: center;
  padding: 0 20px; gap: 2px;
  background: var(--topbar-bg);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-bottom: 1px solid var(--border);
  transform: translateY(0);
  transition: transform 0.32s var(--ease), box-shadow 0.28s;
  will-change: transform;
}

body.topbar-hidden  .topbar { transform: translateY(calc(-1 * var(--topbar-h) - 1px)); }
body.topbar-peeking .topbar {
  transform: translateY(0) !important;
  box-shadow: 0 4px 32px var(--shadow), 0 0 0 1px var(--accent-dim);
}

.topbar-hint {
  position: fixed; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent) 35%, var(--accent) 65%, transparent);
  opacity: 0; pointer-events: none; z-index: 901;
  box-shadow: 0 0 10px var(--accent-glow);
  transition: opacity 0.22s;
}
body.topbar-hidden  .topbar-hint { opacity: 0.8; }
body.topbar-peeking .topbar-hint { opacity: 0; }

.topbar-peek { position: fixed; top: 0; left: 0; right: 0; height: 10px; z-index: 902; }

.topbar-logo {
  display: flex; align-items: center; cursor: pointer;
  flex-shrink: 0; margin-right: 10px;
  opacity: 0.85; transition: opacity 0.18s;
}
.topbar-logo:hover { opacity: 1; }
.topbar-logo img { height: 26px; width: auto; display: block; }

/* ============================================================
   NAV BUTTONS + DROPDOWNS (hover, with safe close delay)
   ============================================================ */
.topbar-nav { display: flex; align-items: center; gap: 2px; flex: 1; }

.nav-button {
  display: flex; align-items: center; gap: 5px;
  height: 34px; padding: 0 13px;
  border: 1px solid transparent; border-radius: var(--r);
  background: transparent; color: var(--text-dim);
  font-size: 13px; font-weight: 600; letter-spacing: 0.01em;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  white-space: nowrap; user-select: none;
}
.nav-button .chevron {
  font-size: 9px; opacity: 0.5;
  display: inline-block; transition: transform 0.2s var(--ease), opacity 0.15s;
}
.nav-button:hover, .nav-button.dd-open {
  color: var(--text); background: var(--surface-2); border-color: var(--border);
}
.nav-button.dd-open .chevron { transform: rotate(180deg); opacity: 0.9; }
.nav-button.active {
  color: var(--accent); background: var(--accent-dim);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}

.nav-dropdown { position: relative; }

.dropdown-menu {
  position: absolute; top: calc(100% + 4px); left: 0;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: var(--r-lg);
  padding: 4px; z-index: 1000;
  box-shadow: 0 10px 36px var(--shadow);
  opacity: 0; pointer-events: none;
  transform: translateY(-5px) scale(0.98);
  transform-origin: top left;
  transition: opacity 0.15s var(--ease), transform 0.15s var(--ease);
}
/* Invisible bridge: covers the gap between button and menu */
.dropdown-menu::before {
  content: ''; position: absolute;
  bottom: 100%; left: 0; right: 0; height: 8px;
}
.dropdown-menu.dd-open {
  opacity: 1; pointer-events: auto;
  transform: translateY(0) scale(1);
}

.dropdown-item {
  display: block; width: 100%; padding: 8px 11px;
  border: none; border-radius: calc(var(--r-lg) - 3px);
  background: transparent; color: var(--text-dim);
  font-size: 13px; font-weight: 500; text-align: left;
  transition: color 0.12s, background 0.12s;
}
.dropdown-item:hover  { color: var(--text); background: var(--surface-2); }
.dropdown-item.active { color: var(--accent); background: var(--accent-dim); }

/* Divider inside dropdown */
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* Theme grid inside dropdown */
.theme-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 2px; }
.theme-btn {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 9px;
  border: 1px solid var(--border); border-radius: var(--r);
  background: transparent; color: var(--text-dim);
  font-size: 12px; font-weight: 600;
  transition: color 0.12s, background 0.12s, border-color 0.12s;
}
.theme-btn:hover { color: var(--text); background: var(--surface-2); border-color: var(--border-hi); }
.theme-btn.active {
  color: var(--accent); background: var(--accent-dim);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}
.theme-swatch {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.12);
}

/* Logout */
.logout-topbar {
  margin-left: auto; flex-shrink: 0;
  height: 32px; padding: 0 13px;
  border: 1px solid var(--border); border-radius: var(--r);
  background: transparent; color: var(--text-muted);
  font-size: 12px; font-weight: 600;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.logout-topbar:hover {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
  background: var(--danger-dim);
}

/* ============================================================
   MAIN + VIEWS
   ============================================================ */
.main {
  position: fixed; inset: 0; top: var(--topbar-h);
  transition: top 0.32s var(--ease); overflow: hidden;
}
body.topbar-hidden .main { top: 0; }

.view {
  display: none; position: absolute; inset: 0;
  overflow-y: auto; overflow-x: hidden;
  background: var(--bg-solid);
}
.view.active { display: block; }

/* ============================================================
   HUB
   ============================================================ */
#hub-view { padding: 28px 24px 48px; }

.system-grid-toggle {
  display: inline-flex; align-items: center; gap: 7px;
  height: 30px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 99px;
  background: transparent; color: var(--text-muted);
  font-size: 12px; font-weight: 600; letter-spacing: 0.02em;
  margin-bottom: 14px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.system-grid-toggle:hover { color: var(--text-dim); border-color: var(--border-hi); background: var(--surface-2); }
.system-grid-toggle.active {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  background: var(--accent-dim);
}
.grid-arrow { font-size: 9px; opacity: 0.6; display: inline-block; transition: transform 0.22s var(--ease); }
.system-grid-toggle.active .grid-arrow { transform: rotate(180deg); }

.sys-main { margin-bottom: 24px; }

/* ── Explore banner ─────────────────────────────────────────── */
.explore-banner {
  width: 100%;
  overflow: hidden;
  margin-bottom: 18px;
  position: relative;
  height: 160px;
  mask-image: linear-gradient(to right, transparent 0%, black 6%, black 94%, transparent 100%);
  -webkit-mask-image: linear-gradient(to right, transparent 0%, black 6%, black 94%, transparent 100%);
}

.explore-track {
  display: flex;
  gap: 10px;
  height: 100%;
  animation: explore-scroll 60s linear infinite;
  will-change: transform;
  width: max-content;
}

/* hover-pause is JS-controlled via mouseenter/mouseleave in _addExploreDrag */
.explore-banner.is-dragging { cursor: grabbing; }

@keyframes explore-scroll {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

.explore-card {
  flex-shrink: 0;
  width: 140px;
  height: 100%;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  border: 1px solid transparent;
  transition: border-color 0.15s, transform 0.15s;
}

.explore-card:hover {
  border-color: var(--accent, #6c63ff);
  transform: scale(1.04);
  z-index: 2;
}

.explore-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.explore-card-label {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.82));
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 14px 6px 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Hub grid (last-played + favourites side by side) ─────── */
.hub-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 700px) {
  .hub-grid { grid-template-columns: 1fr; }
  .explore-banner { height: 120px; }
  .explore-card { width: 110px; }
}

/* ── Favourite heart button ──────────────────────────────── */
.fav-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 32px;
  line-height: 1;
  padding: 2px 4px;
  color: var(--text-dim);
  transition: color 0.15s, transform 0.12s;
  flex-shrink: 0;
}

.fav-btn:hover { transform: scale(1.2); }


.fav-btn--emu {
  font-size: 26px;
  margin-left: 10px;
  align-self: center;
}

/* game card fav button */
.game-card-fav {
  position: absolute;
  top: 3px; left: 3px;
  font-size: 25px;
  padding: 1px 3px;
  background: rgba(0,0,0,0.5);
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.game-button:hover .game-card-fav,
.game-card-fav.is-fav { opacity: 1; }

.game-button { position: relative; }

/* favourites list in hub — horizontal card grid */
#favourites-list,
#last-played-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border, #333) transparent;
}

#favourites-list::-webkit-scrollbar,
#last-played-list::-webkit-scrollbar { height: 4px; }
#favourites-list::-webkit-scrollbar-track,
#last-played-list::-webkit-scrollbar-track { background: transparent; }
#favourites-list::-webkit-scrollbar-thumb,
#last-played-list::-webkit-scrollbar-thumb { background: var(--border, #333); border-radius: 2px; }

#favourites-list .fav-empty,
#last-played-list .fav-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 100px;
  gap: 8px;
  color: var(--text-dim);
  opacity: 0.55;
  font-size: 12px;
  text-align: center;
  user-select: none;
}

#favourites-list .fav-empty-icon,
#last-played-list .fav-empty-icon {
  font-size: 32px;
  line-height: 1;
  opacity: 0.4;
}

#favourites-list .fav-item,
#last-played-list .fav-item {
  flex-shrink: 0;
  width: 100px;
  cursor: pointer;
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid transparent;
  transition: border-color 0.15s, transform 0.12s;
  background: var(--surface-alt, #111);
  position: relative;
}

#favourites-list .fav-item:hover,
#last-played-list .fav-item:hover {
  border-color: var(--border);
  transform: translateY(-2px);
}

#favourites-list .fav-item img,
#last-played-list .fav-item img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block;
  background: var(--surface-alt, #111);
}

#favourites-list .fav-item-meta,
#last-played-list .fav-item-meta {
  padding: 4px 5px 5px;
}

#favourites-list .fav-item-name,
#last-played-list .fav-item-name {
  display: block;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.12s;
}

#favourites-list .fav-item:hover .fav-item-name,
#last-played-list .fav-item:hover .fav-item-name { color: var(--text); }

#favourites-list .fav-item-system,
#last-played-list .fav-item-system {
  display: block;
  font-size: 9px;
  color: var(--text-dim);
  opacity: 0.5;
  margin-top: 1px;
}

.emulator-card-header {
  display: flex;
  align-items: center;
}


.system-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px;
  max-height: 0; opacity: 0; pointer-events: none; overflow: hidden;
  transition: max-height 0.38s cubic-bezier(0,1,0.3,1), opacity 0.28s;
}
.system-grid.is-open { max-height: 500px; opacity: 1; pointer-events: auto; overflow: visible; }

.system-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 16px;
}

.sys-section { width: 100%; }
.sys-title { font-size: 11px; font-weight: 700; color: var(--text-muted); margin-bottom: 10px; letter-spacing: 0.04em; }
.sys-subtitle { font-size: 12px; color: var(--text-dim); margin-bottom: 3px; line-height: 1.5; }
.storage-stats { margin-bottom: 2px; }
.sys-progress-bg { height: 3px; background: var(--surface-3); border-radius: 99px; overflow: hidden; margin-top: 14px; }
.sys-progress-bar { height: 100%; background: var(--accent); border-radius: 99px; box-shadow: 0 0 6px var(--accent-glow); transition: width 0.7s var(--ease); min-width: 2px; }

.cpu-cores-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 5px; }
.cpu-core-item { display: flex; flex-direction: column; align-items: center; padding: 5px 3px;}
.core-num { font-size: 9px; color: var(--text-muted); margin-bottom: 1px; }
.core-val { font-size: 11px; font-weight: 600; color: var(--text); }

/* ============================================================
   CARDS
   ============================================================ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; }
.card h3 { font-size: 12px; font-weight: 700; letter-spacing: 0.04em; color: var(--text-muted); padding: 14px 16px; border-bottom: 1px solid var(--border); }
.grid { display: grid; grid-template-columns: 1fr; gap: 16px; }

/* ============================================================
   SAVES
   ============================================================ */
#saves { display: flex; flex-direction: column; }

.game-row { border-bottom: 1px solid var(--border); }
.game-row:last-of-type { border-bottom: none; }

.game-header { display: flex; align-items: center; justify-content: space-between; padding: 11px 16px; gap: 12px; }
.game-header .game-name { font-size: 14px; font-weight: 600; color: var(--text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.game-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.game-actions button,
.save-actions button {
  height: 27px; padding: 0 11px;
  border: 1px solid var(--border); border-radius: var(--r);
  background: transparent; color: var(--text-dim);
  font-size: 12px; font-weight: 600;
  transition: color 0.13s, background 0.13s, border-color 0.13s;
}
.game-actions button:hover,
.save-actions button:hover { color: var(--text); background: var(--surface-2); border-color: var(--border-hi); }

.game-actions button:last-child {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  background: var(--accent-dim);
}
.game-actions button:last-child:hover { background: color-mix(in srgb, var(--accent) 18%, transparent); }

.save-list { display: none; border-top: 1px solid var(--border); }

.save-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 16px; gap: 12px; border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.save-row:last-child { border-bottom: none; }
.save-row:hover { background: var(--surface-2); }
.save-row > span { font-size: 12px; color: var(--text-dim); flex: 1; }
.sram-section-title {
  padding-left: 24px;
  margin-top: 8px;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.sram-save-row > span {
  padding-left: 24px;
}
.save-actions { display: flex; align-items: center; gap: 6px; }
.save-actions button:last-child:hover {
  color: var(--danger) !important;
  border-color: color-mix(in srgb, var(--danger) 35%, transparent) !important;
  background: var(--danger-dim) !important;
}

.show-more-saves, .show-all-saves {
  display: block; width: 100%; padding: 9px;
  border: none; border-top: 1px solid var(--border); border-radius: 0;
  background: transparent; color: var(--text-muted);
  font-size: 11px; font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase; text-align: center;
  transition: color 0.13s, background 0.13s;
}
.show-more-saves:hover, .show-all-saves:hover { color: var(--text-dim); background: var(--surface-2); }

/* ============================================================
   GAMES VIEW
   ============================================================ */
#games-view {
  padding: 0;
  overflow: hidden; /* no scroll on this view — emulator must be exact */
}

/* Game selector scrolls independently */
.card#game-selector {
  margin: 0; border: none; border-radius: 0;
  height: 100%; display: flex; flex-direction: column;
  background: var(--bg-solid); overflow-y: auto;
}

.card-header {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 24px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 10; flex-shrink: 0;
}
#system-title { font-size: 17px; font-weight: 800; color: var(--text); flex-shrink: 0; }

#game-search {
  flex: 1; max-width: 260px; height: 32px; padding: 0 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r); color: var(--text); font-size: 13px; outline: none;
  transition: border-color 0.15s, background 0.15s;
}
#game-search::placeholder { color: var(--text-muted); }
#game-search:focus { border-color: var(--border-hi); background: var(--surface-3); }

.game-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  padding: 10px;
  overflow-y: auto;
  align-content: start;
}

/* Game card: thumbnail on top, name below */
.game-button {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--surface-alt, #1a1a2e);
  width: 100%;
  text-align: left;
  transition: border-color 0.15s, transform 0.12s, box-shadow 0.15s;
  overflow: hidden;
  cursor: pointer;
}
.game-button:hover {
  border-color: var(--border);
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}

/* Title screenshot image */
.game-title-img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block;
  background: var(--surface-alt, #111);
}

.game-button .game-name {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  transition: color 0.12s;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 5px 8px 6px;
}
.game-button:hover .game-name { color: var(--text); }

/* Floating screenshot tooltip */
.game-screenshot-tooltip {
  display: none;
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.7);
  border: 1px solid rgba(255,255,255,0.08);
  background: #0d0d1a;
}

/* ============================================================
   EMULATOR — fills the view exactly, no scroll needed
   Layout: [header bar] [iframe — flex:1] [back button bar]
   ============================================================ */
#emulator-container {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #000;
  overflow: hidden;
}

/* Header: title left, game-save status visually centered */
.emulator-card-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  height: 44px;
}

#playing-title {
  grid-column: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;

  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

#emulator-stage {
  flex: 1;
  min-height: 0;

  display: flex;
  align-items: center;
  justify-content: center;

  background: var(--surface);
  overflow: hidden;
}

#iframe-wrapper {
  width: min(100%, calc((100vh - var(--topbar-h) - 88px) * 16 / 9));
  height: min(100%, calc(100vw * 9 / 16));

  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
  flex: 0 0 auto;
}

#iframe-wrapper iframe {
  width: 100% !important;
  height: 100% !important;
  border: 0;
  display: block;
}

/* Back button — fixed-height footer strip */
.emulator-footer {
  flex-shrink: 0;
  height: 44px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

/* Style the back button when it's inside .emulator-footer */
.emulator-footer .game-button,
#emulator-container > .game-button {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  line-height: 1;
  width: auto;
  height: 30px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  transition: color 0.13s, background 0.13s, border-color 0.13s;
}

.emulator-footer .game-button:hover,
#emulator-container > .game-button:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border-hi);
}

.emulator-footer .game-button.back-to-hub-btn {
  display: inline-flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: center !important;
  flex-wrap: nowrap !important;

  width: auto !important;
  min-width: 104px;
  height: 30px !important;
  padding: 0 14px !important;

  border: 1px solid var(--border) !important;
  border-radius: var(--r) !important;
  background: transparent !important;
  color: var(--text-dim) !important;

  font-size: 12px !important;
  font-weight: 600 !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  text-align: center !important;
}

.emulator-footer .game-button.back-to-hub-btn:hover {
  color: var(--text) !important;
  background: var(--surface-2) !important;
  border-color: var(--border-hi) !important;
}

/* Game-save status pill */
.sram-status-box {
  grid-column: 2;
  justify-self: center;

  display: flex;
  align-items: center;
  gap: 8px;

  min-width: 0;
  max-width: min(620px, 46vw);
  height: 28px;

  padding: 3px 4px 3px 10px;
  border: 1px solid color-mix(in srgb, var(--border-hi) 75%, transparent);
  border-radius: 999px;

  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--surface-2) 92%, transparent),
      color-mix(in srgb, var(--surface) 96%, transparent)
    );

  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.035),
    0 4px 16px rgba(0,0,0,0.14);

  color: var(--text-dim);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.sram-status-box::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 999px;
  flex-shrink: 0;
  background: var(--text-muted);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.025);
}

.sram-status-box[data-state="ok"] {
  border-color: color-mix(in srgb, var(--accent) 32%, transparent);
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--accent-dim) 45%, var(--surface-2)),
      color-mix(in srgb, var(--surface) 94%, transparent)
    );
}

.sram-status-box[data-state="ok"]::before {
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}

.sram-status-box[data-state="warning"] {
  border-color: color-mix(in srgb, #f6c177 35%, transparent);
}

.sram-status-box[data-state="warning"]::before {
  background: #f6c177;
  box-shadow: 0 0 10px rgba(246,193,119,0.25);
}

.sram-status-box[data-state="error"] {
  border-color: color-mix(in srgb, var(--danger) 42%, transparent);
}

.sram-status-box[data-state="error"]::before {
  background: var(--danger);
  box-shadow: 0 0 10px var(--danger-dim);
}

.sram-status-box[data-state="busy"]::before {
  background: var(--accent);
  animation: sramPulse 1s infinite ease-in-out;
}

@keyframes sramPulse {
  0%, 100% {
    opacity: 0.35;
    transform: scale(0.9);
  }

  50% {
    opacity: 1;
    transform: scale(1.15);
  }
}

#sram-status-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;

  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
}

.sram-status-box[data-state="ok"] #sram-status-label {
  color: var(--text);
}

.sram-status-box[data-state="warning"] #sram-status-label {
  color: color-mix(in srgb, #f6c177 90%, var(--text));
}

.sram-status-box[data-state="error"] #sram-status-label {
  color: var(--danger);
}

#sram-sync-button {
  height: 22px;
  padding: 0 9px;

  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--border));
  border-radius: 999px;

  background: color-mix(in srgb, var(--accent-dim) 55%, transparent);
  color: var(--accent);

  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.01em;

  flex-shrink: 0;

  transition:
    color 0.14s,
    background 0.14s,
    border-color 0.14s,
    transform 0.14s;
}

#sram-sync-button:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border-color: color-mix(in srgb, var(--accent) 48%, transparent);
  transform: translateY(-1px);
}

#sram-sync-button:active {
  transform: translateY(0);
}

#sram-sync-button:disabled {
  opacity: 0.55;
  cursor: wait;
  transform: none;
}

/* ============================================================
   DOWNLOAD OVERLAY
   ============================================================ */
#global-download-overlay {
  font-family: 'Figtree', sans-serif !important;
  border-radius: var(--r-lg) !important;
  background: color-mix(in srgb, var(--surface) 97%, transparent) !important;
  border: 1px solid var(--border-hi) !important;
  box-shadow: 0 20px 60px var(--shadow) !important;
}

/* ============================================================
   RESPONSIVE / MOBILE
   ============================================================ */

/* ── Hamburger button (hidden on desktop) ── */
.topbar-hamburger {
  display: none;
  align-items: center; justify-content: center;
  width: 36px; height: 36px; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: var(--r);
  background: transparent; color: var(--text-dim);
  font-size: 16px; cursor: pointer; margin-left: auto;
  transition: color 0.15s, background 0.15s;
}
.topbar-hamburger:hover { color: var(--text); background: var(--surface-2); }

/* ── Mobile nav drawer ── */
.mobile-nav-drawer {
  display: none;
  position: fixed; top: var(--topbar-h); left: 0; right: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border-hi);
  padding: 10px 14px 16px;
  z-index: 850;
  box-shadow: 0 12px 32px rgba(0,0,0,0.35);
  flex-direction: column; gap: 4px;
  transform: translateY(-8px); opacity: 0;
  transition: transform 0.18s var(--ease), opacity 0.18s;
}
.mobile-nav-drawer.open {
  display: flex;
  transform: translateY(0); opacity: 1;
}

/* Mobile drawer backdrop */
.mobile-nav-backdrop {
  display: none; position: fixed; inset: 0; z-index: 840;
  background: rgba(0,0,0,0.4);
}
.mobile-nav-backdrop.open { display: block; }

.mobile-nav-btn {
  display: flex; align-items: center;
  width: 100%; padding: 11px 13px;
  border: none; border-radius: var(--r);
  background: transparent; color: var(--text-dim);
  font-size: 14px; font-weight: 600; text-align: left;
  cursor: pointer; transition: color 0.13s, background 0.13s;
}
.mobile-nav-btn:hover  { color: var(--text); background: var(--surface-2); }
.mobile-nav-btn.active { color: var(--accent); background: var(--accent-dim); }

.mobile-nav-divider {
  height: 1px; background: var(--border); margin: 6px 0;
}

/* Mobile sub-section label */
.mobile-nav-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-muted);
  padding: 8px 13px 4px;
}

/* ── Breakpoints ── */
@media (max-width: 1000px) { .system-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px)  {
  .system-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .emulator-card-header {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 48px;
    gap: 6px;
    padding: 8px 12px;
  }

  #playing-title {
    grid-column: 1;
    width: 100%;
    font-size: 13px;
  }

  .sram-status-box {
    grid-column: 1;
    justify-self: stretch;
    width: 100%;
    max-width: 100%;
  }

  #sram-status-label {
    font-size: 10.5px;
  }

/* Topbar: hide nav, show hamburger */
  .topbar-nav    { display: none; }
  .logout-topbar { display: none; }
  .topbar-hamburger { display: flex; }
  .topbar { padding: 0 14px; }
  .topbar-logo img { height: 22px; }

  /* Hub */
  #hub-view { padding: 16px 12px 48px; }
  .system-grid { grid-template-columns: 1fr; }
  .sys-main { margin-bottom: 16px; }
  .card h3 { font-size: 11px; }

  /* Save rows: stack actions below name */
  .game-header { flex-direction: column; align-items: flex-start; gap: 8px; padding: 10px 14px; }
  .game-actions { width: 100%; justify-content: flex-end; }
  .game-actions button, .save-actions button { height: 32px; }
  .save-row { flex-wrap: wrap; gap: 8px; padding: 8px 14px; }
  .save-row > span { min-width: 100%; font-size: 11px; }
  .save-actions { margin-left: auto; }

  /* Show-more buttons */
  .show-more-saves, .show-all-saves { padding: 11px; font-size: 11px; }

  /* Game selector */
  .card-header { flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px 14px; }
  #system-title { font-size: 15px; }
  #game-search { max-width: 100%; width: 100%; }
  .game-button { padding: 0; }
  .game-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 3px; padding: 6px; }

  /* Emulator footer touch target */
  .emulator-footer { height: 48px; }

  /* System grid toggle */
  .system-grid-toggle { font-size: 11px; height: 28px; padding: 0 11px; }
}

/* Extra-small phones */
@media (max-width: 380px) {
  #hub-view { padding: 12px 10px 48px; }
  .topbar { padding: 0 10px; }
  .game-actions { gap: 4px; }
  .game-actions button, .save-actions button { padding: 0 8px; font-size: 11px; }
}

/* Touch — remove hover transforms */
@media (hover: none) {
  .nav-button:hover, .dropdown-item:hover,
  .game-button:hover, .system-grid-toggle:hover,
  .theme-btn:hover { transform: none; }
}
/* ── Launch dialog ───────────────────────────────────────────── */
.launch-dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
  animation: fade-in 0.15s ease;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.launch-dialog {
  background: var(--surface, #1a1a2e);
  border: 1px solid var(--border, #333);
  border-radius: 14px;
  width: 100%;
  max-width: 380px;
  max-height: min(84vh, 760px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px rgba(0,0,0,0.8);
  animation: dialog-in 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes dialog-in {
  from { transform: scale(0.92) translateY(12px); opacity: 0; }
  to   { transform: scale(1)    translateY(0);    opacity: 1; }
}

.launch-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border, #2a2a3e);
  background: var(--surface-alt, #111);
}

.launch-dialog-header-main {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1 1 auto;
}

.launch-dialog-title-wrap {
  min-width: 0;
}

.launch-dialog-fav {
  position: static;
  top: auto;
  left: auto;
  opacity: 1;
  flex: 0 0 auto;
  align-self: flex-start;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--border, #2a2a3e);
  background: rgba(255,255,255,0.03);
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.launch-dialog-fav:hover {
  transform: translateY(-1px);
  border-color: var(--border-hover, #444);
  color: var(--text, #fff);
  background: rgba(255,255,255,0.05);
}

.launch-dialog-fav.is-fav {
  color: #ff5a76;
  border-color: rgba(255, 90, 118, 0.42);
  background: rgba(255, 90, 118, 0.08);
}

.launch-dialog-thumb {
  width: 72px;
  height: 54px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: var(--bg, #0d0d1a);
}

.launch-dialog-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.launch-dialog-system {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 3px;
  opacity: 0.7;
}

.launch-dialog-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.launch-dialog-footer {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  padding: 10px 16px 14px;
  border-top: 1px solid rgba(255,255,255,0.04);
  background: linear-gradient(180deg, rgba(14,14,20,0.2), rgba(14,14,20,0.92));
}


.launch-section--core {
  margin-top: 10px;
}

.launch-section--core .launch-section-title {
  margin-bottom: 0;
}

.launch-core-info {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1.5px solid currentColor;
  background: transparent;
  color: var(--text-dim);
  opacity: 0.8;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  padding: 0;
  cursor: help;
  transition: opacity 0.15s ease, color 0.15s ease, transform 0.12s ease;
}

.launch-core-info:hover,
.launch-core-info:focus-visible {
  color: var(--text, #fff);
  opacity: 1;
  transform: translateY(-1px);
  outline: none;
}

.launch-core-tooltip {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  width: min(260px, 70vw);
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--border, #2a2a3e);
  background: rgba(15, 15, 22, 0.96);
  color: var(--text, #fff);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.4;
  text-align: left;
  box-shadow: 0 12px 34px rgba(0,0,0,0.55);
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  pointer-events: none;
  z-index: 4;
  transition: opacity 0.12s ease, transform 0.12s ease, visibility 0s linear 0.12s;
}

.launch-core-info:hover .launch-core-tooltip,
.launch-core-info:focus-visible .launch-core-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition-delay: 0.25s;
}

.launch-core-select-wrap {
  position: relative;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0)) var(--surface-alt, #111);
  border: 1px solid var(--border, #222);
  border-radius: 10px;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}

.launch-core-select-wrap:hover {
  border-color: var(--border-hover, #444);
}

.launch-core-select-wrap:focus-within {
  border-color: var(--accent, #5c54d4);
  box-shadow: 0 0 0 2px rgba(92, 84, 212, 0.18);
}

.launch-core-select-wrap::after {
  content: '▾';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
  font-size: 12px;
}

.launch-core-select {
  width: 100%;
  min-height: 42px;
  padding: 10px 34px 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text, #fff);
  font-size: 13px;
  font-weight: 700;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

.launch-core-select:focus {
  box-shadow: none;
}

.launch-core-hint {
  margin-top: 7px;
  font-size: 11px;
  line-height: 1.45;
  color: var(--text-dim);
  opacity: 0.78;
  padding-left: 2px;
  max-width: 32ch;
}

.launch-btn {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.1s;
}

.launch-btn:hover { transform: translateX(2px); }

.launch-btn--primary {
  background: var(--accent, #5c54d4);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  padding: 12px 16px;
}
.launch-btn--primary:hover { background: var(--accent-hover, #6f67e0); }

.launch-btn--secondary {
  background: var(--surface-alt, #1e1e32);
  color: var(--text-dim);
  border-color: var(--border, #2a2a3e);
}
.launch-btn--secondary:hover { color: var(--text); border-color: var(--border-hover, #444); }

.launch-btn--cancel {
  background: transparent;
  color: var(--text-dim);
  opacity: 0.5;
  font-size: 12px;
  text-align: center;
  margin-top: 0;
}
.launch-btn--cancel:hover { opacity: 0.8; transform: none; }

.launch-section { margin-top: 8px; }

.launch-section-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  
  position: relative;
  z-index: 10; 
}

.launch-section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  opacity: 0.5;
  margin-bottom: 5px;
  padding-left: 2px;
}

.launch-btn--save {
  background: var(--surface-alt, #111);
  color: var(--text-dim);
  border-color: var(--border, #222);
  font-size: 12px;
  padding: 8px 12px;
}
.launch-btn--save:hover { color: var(--text); border-color: var(--border-hover, #444); }

.launch-btn--auto {
  opacity: 0.75;
  font-style: italic;
}

/* ── Save state rows with screenshot thumbnails ─────────────── */
.launch-btn--with-thumb {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
}

.launch-save-thumb {
  width: 64px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--bg, #0d0d1a);
  border: 1px solid var(--border, #222);
}

.launch-save-label {
  flex: 1;
  text-align: left;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#favourites-list,
#last-played-list,
#last-played-list {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding: 0 0 14px;
    scrollbar-width: thin;
    scrollbar-color: var(--border, #333) transparent;
}

/* ============================================================
   MANAGE VIEW — Save File Manager  v2
   ============================================================ */

/* ── Page layout ── */
#manage-view {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--topbar-h));
  overflow: hidden;
}

.mgr-page {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 28px 28px 0;
  box-sizing: border-box;
  gap: 0;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* ── Header ── */
.mgr-header {
  flex-shrink: 0;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}

.mgr-title-row {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 14px;
}

.mgr-title {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.025em;
}

.mgr-count {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* ── Toolbar ── */
.mgr-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.mgr-search-wrap {
  position: relative;
  flex: 1;
  min-width: 180px;
  max-width: 360px;
}

.mgr-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  pointer-events: none;
}

.mgr-search {
  width: 100%;
  box-sizing: border-box;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 8px 30px 8px 33px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}

.mgr-search:focus { border-color: var(--accent); }
.mgr-search::placeholder { color: var(--text-muted); }

.mgr-search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  opacity: 0;
  transition: opacity 0.15s;
  padding: 2px 4px;
  line-height: 1;
}

.mgr-sort-group {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 3px;
  gap: 2px;
  flex-shrink: 0;
}

.mgr-sort-btn {
  background: transparent;
  border: none;
  border-radius: calc(var(--r) - 2px);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 13px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  font-family: inherit;
  white-space: nowrap;
}

.mgr-sort-btn.active {
  background: var(--accent);
  color: var(--bg-solid);
  font-weight: 700;
}

/* ── Two-pane layout ── */
.mgr-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Left: game list ── */
.mgr-list-pane {
  overflow-y: auto;
  border-right: 1px solid var(--border);
  padding: 6px 0 24px;
}

/* Scrollbar */
.mgr-list-pane::-webkit-scrollbar { width: 4px; }
.mgr-list-pane::-webkit-scrollbar-track { background: transparent; }
.mgr-list-pane::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 2px; }

/* ── Game row button ── */
.mgr-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  box-sizing: border-box;
  padding: 11px 14px 11px 16px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  text-align: left;
  gap: 10px;
  transition: background 0.1s;
  font-family: inherit;
}

.mgr-row:last-child { border-bottom: none; }
.mgr-row:hover { background: var(--accent-dim); }

.mgr-row.is-selected {
  background: var(--accent-dim);
  border-left: 2px solid var(--accent);
  padding-left: 14px;
}

.mgr-row-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.mgr-sys-badge {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.07em;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid var(--accent-glow);
  border-radius: 4px;
  padding: 2px 6px;
  white-space: nowrap;
  flex-shrink: 0;
}

.mgr-row-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.mgr-row-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.mgr-row.is-selected .mgr-row-name { color: var(--accent); }

.mgr-row-ts {
  font-size: 11px;
  color: var(--text-muted);
}

.mgr-row-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.mgr-pill {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid var(--accent-glow);
  border-radius: 999px;
  padding: 1px 7px;
  min-width: 20px;
  text-align: center;
}

.mgr-row-arrow {
  width: 12px;
  height: 12px;
  color: var(--text-muted);
  transition: transform 0.12s, color 0.12s;
}

.mgr-row.is-selected .mgr-row-arrow {
  transform: rotate(0deg);
  color: var(--accent);
}

/* ── Right: detail pane ── */
.mgr-detail-pane {
  overflow-y: auto;
  padding: 24px 28px;
}

.mgr-detail-pane::-webkit-scrollbar { width: 4px; }
.mgr-detail-pane::-webkit-scrollbar-track { background: transparent; }
.mgr-detail-pane::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 2px; }

.mgr-detail-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  height: 100%;
  min-height: 240px;
  color: var(--text-muted);
}

.mgr-detail-placeholder svg {
  width: 52px;
  height: 52px;
  opacity: 0.25;
}

.mgr-detail-placeholder p {
  font-size: 13px;
  margin: 0;
  color: var(--text-muted);
}

/* ── Detail inner ── */
.mgr-detail-inner {
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: mgrFadeIn 0.18s ease;
}

@keyframes mgrFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Detail hero ── */
.mgr-detail-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.mgr-detail-hero-text { display: flex; flex-direction: column; gap: 7px; }

.mgr-detail-name {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.mgr-detail-sys {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid var(--accent-glow);
  border-radius: 5px;
  padding: 2px 8px;
  display: inline-block;
}

.mgr-continue-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: var(--bg-solid);
  border: none;
  border-radius: var(--r);
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.12s, transform 0.12s;
  font-family: inherit;
  white-space: nowrap;
}

.mgr-continue-btn svg { width: 13px; height: 13px; }
.mgr-continue-btn:hover { opacity: 0.88; transform: translateY(-1px); }
.mgr-continue-btn:active { transform: translateY(0); }

/* ── Section ── */
.mgr-section { display: flex; flex-direction: column; gap: 10px; }

.mgr-section-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mgr-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.mgr-section-pill {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: 999px;
  padding: 0 7px;
}

.mgr-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 4px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.mgr-tag--auto {
  background: rgba(100,130,210,0.13);
  color: #8ab4f8;
  border: 1px solid rgba(100,130,210,0.22);
}

.mgr-tag--sram {
  background: rgba(80,210,130,0.12);
  color: #6ee7a0;
  border: 1px solid rgba(80,210,130,0.2);
}

/* ── Saves list ── */
.mgr-saves { display: flex; flex-direction: column; gap: 6px; }

.mgr-save-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  gap: 12px;
  transition: border-color 0.12s;
}

.mgr-save-row:hover { border-color: var(--border-hi); }

.mgr-save-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.mgr-save-date {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
}

.mgr-save-btns {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Action buttons ── */
.mgr-action {
  padding: 6px 14px;
  border-radius: var(--r);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  font-family: inherit;
  white-space: nowrap;
}

.mgr-action--load {
  color: var(--accent);
  border-color: var(--accent-glow);
}

.mgr-action--load:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.mgr-action--del:hover {
  color: #e05555;
  border-color: rgba(220,80,80,0.4);
  background: rgba(220,80,80,0.07);
}

.mgr-action--confirm {
  color: #e05555 !important;
  border-color: rgba(220,80,80,0.5) !important;
  background: rgba(220,80,80,0.1) !important;
}

/* ── States ── */
.mgr-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 48px 20px;
  color: var(--text-muted);
  font-size: 13px;
}

.mgr-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-hi);
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  animation: mgrSpin 0.75s linear infinite;
}

@keyframes mgrSpin { to { transform: rotate(360deg); } }

/* Hub grid: single column */
.hub-grid--single {
  grid-template-columns: 1fr !important;
  max-width: 600px;
}

/* ── Mobile ── */
@media (max-width: 860px) {
  #manage-view { height: auto; overflow: visible; }

  .mgr-page {
    padding: 16px 14px 24px;
    height: auto;
    overflow: visible;
  }

  .mgr-layout {
    grid-template-columns: 1fr;
    overflow: visible;
    height: auto;
  }

  .mgr-list-pane {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 45vh;
    overflow-y: auto;
  }

  .mgr-detail-pane { padding: 16px 4px; }

  .mgr-toolbar { flex-direction: column; align-items: stretch; }
  .mgr-search-wrap { max-width: 100%; }
  .mgr-sort-group { align-self: flex-start; }

  .mgr-continue-btn { font-size: 12px; padding: 9px 14px; }
  .mgr-detail-hero { flex-wrap: wrap; }
}


/* ============================================================
   JMHD polish: Hub + Manage spacing/scroll fixes
   ============================================================ */

/* Hub: title above carousel and cleaner favourites section */
#hub-view {
  padding: 28px 24px 56px;
}

.hub-section {
  width: 100%;
}

.hub-page-title {
  margin: 0 0 18px;
  font-size: 23px;
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: -0.035em;
  color: var(--text);
}

.hub-section-title {
  margin: 0 0 14px;
  font-size: 14px;
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

.hub-section--explore .explore-banner {
  margin-bottom: 0;
}

.hub-favourites {
  margin-top: 28px;
}

/* Bigger favourite cards without wrapping them in a boxed container */
#favourites-list,
#last-played-list {
  gap: 12px;
  padding: 0 0 14px;
}

#favourites-list .fav-item,
#last-played-list .fav-item {
  width: 140px;
  border-radius: 10px;
  background: transparent;
  border-color: transparent;
}

#favourites-list .fav-item:hover,
#last-played-list .fav-item:hover {
  border-color: transparent;
  transform: translateY(-3px);
}

#favourites-list .fav-item img,
#last-played-list .fav-item img {
  aspect-ratio: 4 / 3;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

#favourites-list .fav-item:hover img,
#last-played-list .fav-item:hover img {
  border-color: var(--accent-glow);
}

#favourites-list .fav-item-meta,
#last-played-list .fav-item-meta {
  padding: 8px 2px 0;
}

#favourites-list .fav-item-name,
#last-played-list .fav-item-name {
  font-size: 12px;
  color: var(--text);
}

#favourites-list .fav-item-system,
#last-played-list .fav-item-system {
  font-size: 10px;
  margin-top: 3px;
}

/* Manage: align with the rest of the app and let the page scroll normally */
#manage-view {
  display: block;
  height: auto;
  min-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

#manage-root {
  min-height: 100%;
}

.mgr-page {
  max-width: none;
  width: 100%;
  height: auto;
  min-height: 100%;
  margin: 0;
  padding: 28px 24px 56px;
}

.mgr-header {
  border-bottom: none;
  padding-bottom: 18px;
  margin-bottom: 4px;
}

.mgr-layout {
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 24px;
  overflow: visible;
  align-items: start;
}

.mgr-list-pane {
  overflow: visible;
  border-right: none;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
}

.mgr-row:first-child {
  border-top-left-radius: var(--r-lg);
  border-top-right-radius: var(--r-lg);
}

.mgr-row:last-child {
  border-bottom-left-radius: var(--r-lg);
  border-bottom-right-radius: var(--r-lg);
}

.mgr-detail-pane {
  overflow: visible;
  padding: 0;
  min-width: 0;
}

.mgr-detail-hero {
  padding-top: 4px;
}

@media (max-width: 860px) {
  #hub-view {
    padding: 22px 14px 42px;
  }

  .hub-page-title {
    font-size: 21px;
    margin-bottom: 14px;
  }

  .hub-favourites {
    margin-top: 24px;
  }

  #favourites-list .fav-item,
  #last-played-list .fav-item {
    width: 122px;
  }

  #manage-view {
    display: block;
    height: auto;
    overflow-y: auto;
  }

  .mgr-page {
    padding: 18px 14px 42px;
  }

  .mgr-layout {
    grid-template-columns: 1fr;
    gap: 18px;
    overflow: visible;
  }

  .mgr-list-pane {
    max-height: none;
    overflow: visible;
  }

  .mgr-detail-pane {
    padding: 0;
  }
}

/* ============================================================
   MANAGE FIX: lock page height; scroll only inside panes
   ============================================================ */
#manage-view {
  display: block;
  height: 100%;
  overflow: hidden;
}

#manage-root {
  height: 100%;
  min-height: 0;
}

.mgr-page {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 28px 24px 24px;
}

.mgr-header {
  flex: 0 0 auto;
}

.mgr-layout {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  align-items: stretch;
}

.mgr-list-pane,
.mgr-detail-pane {
  min-height: 0;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

.mgr-list-pane {
  padding-bottom: 0;
}

.mgr-detail-pane {
  padding-right: 6px;
}

@media (max-width: 860px) {
  #manage-view {
    height: 100%;
    overflow: hidden;
  }

  #manage-root,
  .mgr-page {
    height: 100%;
    min-height: 0;
  }

  .mgr-page {
    padding: 18px 14px 18px;
  }

  .mgr-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(180px, 40%) minmax(0, 1fr);
    min-height: 0;
    overflow: hidden;
  }

  .mgr-list-pane,
  .mgr-detail-pane {
    min-height: 0;
    max-height: 100%;
    overflow-y: auto;
  }
}

/* ============================================================
   MANAGE POLISH: sort controls below search
   ============================================================ */
.mgr-toolbar {
  align-items: flex-start;
  flex-direction: column;
  gap: 9px;
}

.mgr-search-wrap {
  width: min(430px, 100%);
  max-width: 430px;
  flex: 0 0 auto;
}

.mgr-sort-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.mgr-sort-label {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.mgr-sort-group {
  width: auto;
}

@media (max-width: 520px) {
  .mgr-sort-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
    width: 100%;
  }

  .mgr-sort-group {
    width: 100%;
  }

  .mgr-sort-btn {
    flex: 1;
  }
}

/* ============================================================
   MANAGE POLISH: keep detail system badge compact
   ============================================================ */
.mgr-detail-hero-text {
  align-items: flex-start;
  min-width: 0;
}

.mgr-detail-sys {
  width: fit-content;
  max-width: max-content;
  align-self: flex-start;
}

/* ============================================================
   Hub favourites + launch-save preview polish
   ============================================================ */

.hub-favourites .hub-section-title {
  margin-bottom: 16px;
  font-size: 20px;
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--text);
}

#favourites-list,
#last-played-list {
  gap: 16px;
  padding-bottom: 18px;
}

#favourites-list .fav-item,
#last-played-list .fav-item {
  width: 168px;
}

#favourites-list .fav-item img,
#last-played-list .fav-item img {
  border-radius: 12px;
}

#favourites-list .fav-item-meta,
#last-played-list .fav-item-meta {
  padding-top: 10px;
}

#favourites-list .fav-item-name,
#last-played-list .fav-item-name {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.015em;
}

#favourites-list .fav-item-system,
#last-played-list .fav-item-system {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  opacity: 0.6;
}

.launch-save-preview {
  position: fixed;
  z-index: 10002;
  width: min(360px, calc(100vw - 24px));
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px) scale(0.97);
  transition: opacity 0.12s ease, transform 0.12s ease;
  padding: 10px;
  border-radius: 14px;
  border: 1px solid var(--border, #2a2a3e);
  background: rgba(13, 18, 30, 0.96);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(10px);
}

.launch-save-preview.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.launch-save-preview img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border, #2a2a3e);
  background: var(--surface-alt, #111827);
}

.launch-save-preview-label {
  margin-top: 8px;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 860px) {
  #favourites-list,
  #last-played-list {
    gap: 12px;
  }

  #favourites-list .fav-item,
  #last-played-list .fav-item {
    width: 138px;
  }

  .hub-favourites .hub-section-title {
    font-size: 18px;
  }

  .launch-save-preview {
    display: none !important;
  }
}
/* ── Save state toast ─────────────────────────────────────── */
#save-toast {
  position: fixed;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  z-index: 9999;

  display: flex;
  align-items: center;
  gap: 8px;

  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--accent-dim) 55%, var(--surface-2)),
    color-mix(in srgb, var(--surface) 90%, transparent)
  );
  box-shadow: 0 4px 24px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.04);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);

  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  pointer-events: none;

  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#save-toast.save-toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#save-toast::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  flex-shrink: 0;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}

/* ── Game download progress overlay (inside iframe) ───────── */
#game-load-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: #0a0a0f;
  pointer-events: none;
}

#game-load-overlay.hidden {
  display: none;
}

#game-load-title {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,0.55);
  letter-spacing: 0.03em;
  max-width: 280px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#game-load-bar-wrap {
  width: 240px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}

#game-load-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent, #7c6eff), color-mix(in srgb, var(--accent, #7c6eff) 60%, #a78bfa));
  box-shadow: 0 0 8px var(--accent-glow, rgba(124,110,255,0.4));
  transition: width 0.15s ease;
}

#game-load-pct {
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,0.3);
  letter-spacing: 0.04em;
}

/* ── SRAM source tabs: Website saves / App saves ───────────── */
.sram-source-tabs-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 6px 0 10px;
}

.sram-source-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 0 16px;
}

.launch-section .sram-source-tabs,
.mgr-sram-source-tabs-wrap .sram-source-tabs {
  padding: 0;
}

.sram-source-tab {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-alt, var(--surface));
  color: var(--text-dim);
  font: inherit;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 8px 10px;
  cursor: pointer;
  transition: background 0.13s, border-color 0.13s, color 0.13s, transform 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sram-source-tab:hover {
  color: var(--text);
  border-color: var(--border-hi, var(--border-hover));
}

.sram-source-tab.is-active {
  background: var(--accent-dim);
  border-color: var(--accent-glow, var(--accent));
  color: var(--accent);
}

.sram-source-panels {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sram-source-panel[hidden] {
  display: none !important;
}

.sram-source-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.save-list .sram-source-panel {
  gap: 0;
}

.sram-source-empty {
  padding: 12px 16px;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--r);
  background: rgba(255,255,255,0.015);
}

.save-list .sram-source-empty {
  margin: 0 16px 10px;
}

.launch-section--sram .sram-source-tabs-wrap {
  margin-top: 4px;
}

.launch-section--sram .sram-source-panel {
  gap: 5px;
}

.sram-launch-save-row {
  margin: 0;
}

.mgr-sram-source-tabs-wrap {
  margin-top: 0;
}

.mgr-sram-source-tabs-wrap .sram-source-panel {
  gap: 6px;
}

@media (max-width: 520px) {
  .sram-source-tab {
    font-size: 10px;
    padding: 7px 8px;
  }
}

/* ============================================================
   NETPLAY UI
   ============================================================ */

/* Room-count badge on the topbar netplay button */
.netplay-room-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    margin-left: 4px;
    border-radius: 9px;
    background: var(--accent, #1a6ff5);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    vertical-align: middle;
}

/* Footer layout: back button + host button side by side */
.emulator-footer {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.netplay-host-btn {
    border: 1px solid var(--border, #2a2a2a);
}
.netplay-host-btn.netplay-host-btn--active {
    background: var(--accent, #1a6ff5);
    color: #fff;
    border-color: var(--accent, #1a6ff5);
}

/* ── All-games console filter chips: a touch more breathing room ──
   (the `body` prefix raises specificity so this wins over the inline
   <style> block in index.html — tweak the values here from now on) */
body #all-games-filter { gap: 10px; padding: 6px 0 18px; }
body #all-games-filter .ag-chip {
    padding: 9px 18px;
    font-size: 13px;
    line-height: 1;
}

/* Dialog subtitle + close (reuses .launch-dialog modal pattern) */
.launch-dialog-subtitle {
    color: var(--text-dim, #9aa0a6);
    font-size: 13px;
    margin: -6px 0 14px;
}
.launch-dialog-close {
    position: absolute;
    top: 10px;
    right: 12px;
    background: transparent;
    border: none;
    color: var(--text-dim, #9aa0a6);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
}
.launch-dialog-close:hover { color: var(--text, #fff); }

/* Room list */
.netplay-dialog .launch-dialog { position: relative; }

.netplay-room-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 60vh;
    overflow-y: auto;
}

.netplay-room-card {
    border: 1px solid var(--border, #2a2a2a);
    border-radius: 10px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
    background: rgba(255,255,255,0.02);
}
.netplay-room-card:hover { border-color: var(--border-hi, #3a3a3a); }

.netplay-room-name {
    font-weight: 700;
    font-size: 15px;
    color: var(--text, #fff);
}
.netplay-room-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    color: var(--text-dim, #9aa0a6);
    font-size: 12px;
}
.netplay-room-system {
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--accent, #1a6ff5);
    font-weight: 600;
}
.netplay-room-sep { opacity: 0.5; }
.netplay-room-players { font-variant-numeric: tabular-nums; }

.netplay-join-btn {
    align-self: flex-start;
    margin-top: 4px;
    padding: 6px 16px;
    border-radius: 8px;
    border: none;
    background: var(--accent, #1a6ff5);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}
.netplay-join-btn:hover { background: var(--accent-dim, #1560d0); }

/* Empty state */
.netplay-empty {
    text-align: center;
    padding: 36px 16px;
    color: var(--text-dim, #9aa0a6);
}
.netplay-empty-icon { font-size: 40px; margin-bottom: 10px; }
.netplay-empty-title { font-size: 16px; font-weight: 700; color: var(--text, #fff); margin-bottom: 6px; }
.netplay-empty-text { font-size: 13px; }

@media (max-width: 600px) {
    .netplay-room-list { max-height: 70vh; }
    .emulator-footer { flex-direction: column; align-items: stretch; }
}

/* ============================================================
   MOBILE EMULATOR FULLSCREEN FIX
   Put this at the VERY END of the CSS file
   ============================================================ */

@media (max-width: 640px) {
  html.emulator-open,
  body.emulator-open {
    width: 100%;
    height: 100%;
    overflow: hidden !important;
    overscroll-behavior: none;
  }

  body.emulator-open .topbar,
  body.emulator-open .topbar-hint,
  body.emulator-open .topbar-peek,
  body.emulator-open .mobile-nav-drawer,
  body.emulator-open .mobile-nav-backdrop {
    display: none !important;
  }

  body.emulator-open .main {
    top: 0 !important;
    inset: 0 !important;
    height: 100dvh !important;
  }

  body.emulator-open #games-view {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    overflow: hidden !important;
    background: #000 !important;
    z-index: 99999 !important;
  }

  body.emulator-open #emulator-container {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    display: flex !important;
    flex-direction: column !important;
    background: #000 !important;
    overflow: hidden !important;
    z-index: 100000 !important;
  }

  body.emulator-open .emulator-card-header,
  body.emulator-open .emulator-footer,
  body.emulator-open #sram-status-box {
    display: none !important;
  }

  body.emulator-open #emulator-stage {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;

    /* Ändra dessa om det fortfarande klipper lite */
    top: max(8px, env(safe-area-inset-top)) !important;
    bottom: max(8px, env(safe-area-inset-bottom)) !important;

    width: 100vw !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;

    display: flex !important;
    align-items: center !important;
    justify-content: center !important;

    background: #000 !important;
    overflow: hidden !important;
  }

  body.emulator-open #iframe-wrapper {
    width: 100% !important;
    height: 100% !important;
    max-width: 100vw !important;
    max-height: 100% !important;

    aspect-ratio: auto !important;
    flex: 1 1 auto !important;

    margin: 0 !important;
    padding: 0 !important;
    background: #000 !important;
    overflow: hidden !important;
  }

  body.emulator-open #iframe-wrapper iframe,
  body.emulator-open #emulator {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    border: 0 !important;
    display: block !important;
  }
}

/* ============================================================
   PORTRAIT PHONE EMULATOR — keep app layout, fill stage
   ============================================================ */

@media (max-width: 640px) and (orientation: portrait) {
  html.emulator-open,
  body.emulator-open {
    position: static !important;
    width: 100%;
    height: 100%;
    overflow: hidden !important;
  }

  body.emulator-open .topbar {
    display: flex !important;
  }

  body.emulator-open .topbar-hint,
  body.emulator-open .topbar-peek {
    display: block !important;
  }

  body.emulator-open .main {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    top: var(--topbar-h) !important;
    bottom: 0 !important;
    height: auto !important;
    overflow: hidden !important;
  }

  body.emulator-open #games-view {
    position: absolute !important;
    inset: 0 !important;
    width: auto !important;
    height: auto !important;
    z-index: auto !important;
    overflow: hidden !important;
    background: var(--bg-solid) !important;
  }

  body.emulator-open #emulator-container {
    position: absolute !important;
    inset: 0 !important;
    width: auto !important;
    height: auto !important;
    display: flex !important;
    flex-direction: column !important;
    z-index: auto !important;
    overflow: hidden !important;
    background: #000 !important;
  }

  body.emulator-open .emulator-card-header {
    display: grid !important;
  }

  body.emulator-open .emulator-footer {
    display: flex !important;
  }

  body.emulator-open #sram-status-box {
    display: flex !important;
  }

  body.emulator-open #emulator-stage {
    position: relative !important;
    inset: auto !important;
    width: 100% !important;
    height: auto !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow: hidden !important;
    background: #000 !important;
  }

  body.emulator-open #iframe-wrapper {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    aspect-ratio: auto !important;
    flex: 1 1 auto !important;
    overflow: hidden !important;
    background: #000 !important;
  }

  body.emulator-open #emulator,
  body.emulator-open #iframe-wrapper iframe {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    border: 0 !important;
    display: block !important;
  }
}