:root {
  --bg: #0f0f13;
  --surface: #1a1a24;
  --surface2: #22222f;
  --surface3: #2a2a3a;
  --accent: #7c5cfc;
  --accent2: #5b8def;
  --text: #e8e8f0;
  --text2: #9090a8;
  --success: #4caf84;
  --error: #e05555;
  --warning: #e0a040;
  --radius: 10px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; min-height: 100vh; }

/* ── Header ─────────────────────────────────────────────────────── */
.header {
  background: var(--surface);
  border-bottom: 1px solid #ffffff12;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-left { display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; }
.logo { font-size: 1.15rem; font-weight: 700; }
.subtitle { color: var(--text2); font-size: 0.78rem; }
.header-search { flex: 1; min-width: 180px; }
.header-search input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid #ffffff18;
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  padding: 9px 14px;
  outline: none;
  transition: border-color .2s;
}
.header-search input:focus { border-color: var(--accent); }
.disk-info { display: flex; flex-direction: column; gap: 5px; min-width: 180px; max-width: 240px; flex-shrink: 0; }
.disk-label { font-size: 0.78rem; color: var(--text2); white-space: nowrap; }
.disk-free { color: var(--success); font-weight: 600; }
.disk-bar-wrap { background: var(--surface2); border-radius: 4px; height: 5px; overflow: hidden; }
.disk-bar-fill { height: 100%; border-radius: 4px; transition: width .5s, background .5s; width: 0; }

/* ── Tabs bar ────────────────────────────────────────────────────── */
.tabs-bar {
  background: var(--surface);
  border-bottom: 1px solid #ffffff0e;
  display: flex;
  gap: 2px;
  padding: 0 16px;
  position: sticky;
  top: 65px;
  z-index: 40;
}
.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text2);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 500;
  margin-bottom: -1px;
  padding: 10px 16px;
  transition: color .2s, border-color .2s;
}
.tab:hover { color: var(--text); }
.tab.active { border-bottom-color: var(--accent); color: var(--text); }
.badge {
  background: var(--accent);
  border-radius: 10px;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  margin-left: 5px;
  padding: 1px 5px;
}

/* ── Main wrap ───────────────────────────────────────────────────── */
.main-wrap { max-width: 1200px; margin: 0 auto; padding: 20px 16px 40px; }
.tab-content.hidden { display: none; }
.hidden { display: none; }

/* ── Browse header ───────────────────────────────────────────────── */
.browse-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 16px;
}
.browse-header span { font-size: 1rem; font-weight: 600; }
.page-nav { display: flex; align-items: center; gap: 10px; }
.page-nav button {
  background: var(--surface);
  border: 1px solid #ffffff18;
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px 12px;
  transition: background .2s;
}
.page-nav button:hover:not(:disabled) { background: var(--surface2); }
.page-nav button:disabled { opacity: .3; cursor: default; }
.page-nav span { color: var(--text2); font-size: 0.85rem; }
.sg-page-nav {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 10px 0;
}
.sg-page-nav .btn-sm { font-size: 1.1rem; padding: 5px 14px; }
.sg-page-info { color: var(--text2); font-size: 0.9rem; min-width: 70px; text-align: center; }

/* ── Game grid ───────────────────────────────────────────────────── */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}
.game-tile {
  background: var(--surface);
  border: 1px solid #ffffff0e;
  border-radius: var(--radius);
  cursor: pointer;
  overflow: hidden;
  transition: border-color .2s, transform .15s;
}
.game-tile:hover { border-color: var(--accent); transform: translateY(-2px); }
.tile-img-wrap { aspect-ratio: 1; background: var(--surface2); overflow: hidden; }
.tile-img-wrap.no-img { background: var(--surface3); }
.tile-img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.game-tile:hover .tile-img { transform: scale(1.04); }
.tile-info { padding: 8px 10px 10px; }
.tile-name { font-size: 0.8rem; font-weight: 600; line-height: 1.3; margin-bottom: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile-meta { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--text2); }
.tile-size { color: var(--accent2); }

/* ── Game detail overlay ─────────────────────────────────────────── */
.detail-overlay {
  background: #000000cc;
  bottom: 0; left: 0; right: 0; top: 0;
  display: flex;
  justify-content: flex-end;
  overflow: hidden;
  position: fixed;
  z-index: 200;
}
.detail-overlay.hidden { display: none; }
.detail-panel {
  background: var(--bg);
  border-left: 1px solid #ffffff12;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 680px;
  overflow-y: auto;
  position: relative;
  width: 95%;
}
.detail-close {
  background: var(--surface2);
  border: none;
  border-radius: 50%;
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  height: 32px;
  position: absolute;
  right: 16px;
  top: 16px;
  width: 32px;
  z-index: 10;
  transition: background .2s;
}
.detail-close:hover { background: var(--error); }
.detail-loading { align-items: center; display: flex; flex-direction: column; gap: 16px; padding: 40px 24px; }
.detail-thumb-loading { border-radius: 8px; max-width: 120px; }

.detail-hero {
  display: flex;
  gap: 20px;
  padding: 24px 24px 16px;
  align-items: flex-start;
}
.detail-cover { border-radius: 10px; flex-shrink: 0; height: 130px; object-fit: cover; width: 130px; }
.detail-hero-info { flex: 1; min-width: 0; }
.detail-title { font-size: 1.1rem; font-weight: 700; line-height: 1.3; margin-bottom: 12px; }
.meta-table { border-collapse: collapse; font-size: 0.8rem; width: 100%; margin-bottom: 14px; }
.meta-table td { padding: 3px 0; vertical-align: top; }
.meta-table td:first-child { color: var(--text2); padding-right: 12px; white-space: nowrap; width: 1%; }
.detail-dl-btns { display: flex; flex-wrap: wrap; gap: 8px; }

/* Carousel */
.carousel { margin: 0 0 16px; position: relative; overflow: hidden; }
.carousel-track { display: flex; overflow: hidden; }
.carousel-slide { flex-shrink: 0; width: 100%; display: none; cursor: zoom-in; object-fit: cover; max-height: 320px; width: 100%; }
.carousel-slide.active { display: block; }
.car-btn {
  background: #000000aa;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 1.4rem;
  padding: 8px 12px;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  transition: background .2s;
  z-index: 5;
}
.car-prev { left: 0; border-radius: 0 6px 6px 0; }
.car-next { right: 0; border-radius: 6px 0 0 6px; }
.car-btn:hover { background: #000000dd; }
.car-dots { bottom: 8px; display: flex; gap: 6px; justify-content: center; left: 0; position: absolute; right: 0; }
.car-dot { background: #ffffff55; border-radius: 50%; cursor: pointer; height: 7px; transition: background .2s; width: 7px; }
.car-dot.active { background: #fff; }

.detail-desc { padding: 0 24px 24px; }
.detail-desc h3 { font-size: 0.9rem; font-weight: 600; margin-bottom: 8px; color: var(--text2); }
.detail-desc p { font-size: 0.85rem; line-height: 1.6; color: var(--text); white-space: pre-wrap; }

/* Fullscreen */
.fullscreen-overlay {
  align-items: center;
  background: #000000ee;
  bottom: 0; left: 0; right: 0; top: 0;
  display: flex;
  justify-content: center;
  position: fixed;
  z-index: 500;
}
.fullscreen-overlay img { max-height: 95vh; max-width: 95vw; border-radius: 6px; }
.fullscreen-overlay button {
  background: #ffffff22;
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  font-size: 1.1rem;
  height: 36px;
  position: absolute;
  right: 16px;
  top: 16px;
  width: 36px;
}

/* ── Download buttons ────────────────────────────────────────────── */
.btn-dl {
  border: none; border-radius: 8px; cursor: pointer;
  font-size: 0.82rem; font-weight: 600;
  padding: 9px 14px; transition: opacity .2s;
  display: flex; align-items: center; gap: 6px;
}
.btn-dl:hover { opacity: .82; }
.btn-full  { background: var(--accent);  color: #fff; }
.btn-base  { background: var(--accent2); color: #fff; }
.btn-update { background: var(--success); color: #fff; }
.btn-dlc   { background: var(--surface3); border: 1px solid #ffffff20; color: var(--text); }
.dl-size   { opacity: .75; font-weight: 400; font-size: 0.75rem; }

/* ── Queue ───────────────────────────────────────────────────────── */
.tab-toolbar { display: flex; gap: 8px; margin-bottom: 16px; align-items: center; }
.tab-toolbar input { flex: 1; background: var(--surface); border: 1px solid #ffffff18; border-radius: 8px; color: var(--text); font-size: 0.88rem; padding: 8px 12px; outline: none; }
.tab-toolbar input:focus { border-color: var(--accent); }
.btn-sm { background: var(--surface2); border: 1px solid #ffffff18; border-radius: 8px; color: var(--text2); cursor: pointer; font-size: 0.82rem; padding: 8px 14px; white-space: nowrap; transition: all .2s; }
.btn-sm:hover { border-color: var(--accent); color: var(--text); }

.queue-item { background: var(--surface); border: 1px solid #ffffff0e; border-radius: var(--radius); margin-bottom: 10px; padding: 12px 16px; }
.queue-item.completed { border-color: #4caf8440; }
.queue-item.error { border-color: #e0555540; }
.qi-top { align-items: center; display: flex; gap: 10px; flex-wrap: wrap; }
.qi-name { flex: 1; font-size: 0.9rem; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qi-kind { background: var(--surface2); border-radius: 4px; color: var(--text2); font-size: 0.72rem; padding: 2px 7px; }
.qi-status { border-radius: 4px; font-size: 0.72rem; font-weight: 600; padding: 2px 8px; }
.status-queued  { background: #3a3a50; color: var(--text2); }
.status-dl      { background: #2a3a6a; color: var(--accent2); }
.status-done    { background: #1a3a2a; color: var(--success); }
.status-err     { background: #3a1a1a; color: var(--error); }
.status-cancel  { background: #2a2a30; color: var(--text2); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }
.extracting-anim { animation: pulse 1.4s ease-in-out infinite; }
.progress-bar   { background: var(--surface2); border-radius: 4px; height: 6px; margin-top: 10px; overflow: hidden; }
.progress-fill  { background: var(--accent); height: 100%; transition: width .5s; }
.qi-stats { color: var(--text2); font-size: 0.78rem; margin-top: 5px; display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.qi-pct   { color: var(--text); font-weight: 700; font-size: 0.9rem; }
.qi-file  { color: var(--success); font-size: 0.8rem; margin-top: 6px; }
.qi-err   { color: var(--error); font-size: 0.8rem; margin-top: 6px; }
.btn-cancel { background: transparent; border: 1px solid #ffffff20; border-radius: 5px; color: var(--text2); cursor: pointer; font-size: 0.78rem; padding: 3px 8px; }
.btn-cancel:hover { border-color: var(--error); color: var(--error); }
.btn-retry { background: transparent; border: 1px solid #f0a50040; border-radius: 5px; color: #f0a500; cursor: pointer; font-size: 0.78rem; padding: 3px 8px; }
.btn-retry:hover { background: #f0a50015; border-color: #f0a500; }

/* ── Console badge ───────────────────────────────────────────────── */
.console-badge {
  align-items: center; cursor: pointer; display: flex; flex-shrink: 0;
  gap: 7px; background: var(--surface2); border: 1px solid #ffffff18;
  border-radius: 20px; padding: 5px 12px; transition: border-color .2s;
}
.console-badge:hover { border-color: var(--accent); }
.console-dot {
  border-radius: 50%; height: 8px; width: 8px; flex-shrink: 0;
  transition: background .4s;
}
.console-dot-lg {
  border-radius: 50%; height: 12px; width: 12px; flex-shrink: 0;
  transition: background .4s;
}
.dot-on  { background: var(--success); box-shadow: 0 0 6px var(--success); }
.dot-off { background: var(--text2); }
.console-name { font-size: 0.82rem; font-weight: 600; color: var(--text); }

/* ── Cyberfoil panel ─────────────────────────────────────────────── */
.cyberfoil-panel {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  border: 1px solid #7c5cfc44;
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}
.cyberfoil-header {
  align-items: center;
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  cursor: default;
}
.cyberfoil-icon { font-size: 1.4rem; flex-shrink: 0; }
.cyberfoil-title { font-size: 0.95rem; font-weight: 700; color: var(--text); }
.cyberfoil-sub { font-size: 0.78rem; color: var(--text2); margin-top: 2px; }
.cyberfoil-toggle {
  background: var(--surface2); border: none; border-radius: 6px;
  color: var(--text2); cursor: pointer; font-size: 0.8rem;
  margin-left: auto; padding: 4px 10px; transition: background .2s;
}
.cyberfoil-toggle:hover { background: var(--surface3); }
.cyberfoil-body { padding: 0 16px 16px; }
.install-apps { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .install-apps { grid-template-columns: 1fr; } }
.install-app { background: var(--surface2); border-radius: 8px; padding: 12px; }
.install-app-name { font-size: 0.88rem; font-weight: 700; color: var(--accent2); margin-bottom: 10px; }
.shop-url-wrap {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 8px;
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  padding: 10px 14px;
}
.shop-url {
  color: var(--accent2);
  flex: 1;
  font-size: 0.85rem;
  font-family: monospace;
  word-break: break-all;
}
.btn-copy {
  background: var(--accent); border: none; border-radius: 6px;
  color: #fff; cursor: pointer; font-size: 0.8rem; font-weight: 600;
  padding: 6px 14px; transition: background .2s; white-space: nowrap; flex-shrink: 0;
}
.btn-copy:hover { opacity: .85; }
.cyberfoil-steps {
  color: var(--text2);
  font-size: 0.82rem;
  line-height: 1.8;
  padding-left: 18px;
}
.cyberfoil-steps strong { color: var(--text); }

/* ── Library view toggle ─────────────────────────────────────────── */
.lib-view-toggle { display:flex; gap:6px; margin-bottom:16px; }
.lib-view-btn {
  background: var(--surface); border: 1px solid #ffffff18; border-radius: 8px;
  color: var(--text2); cursor: pointer; font-size: 0.85rem; font-weight: 500;
  padding: 8px 16px; transition: all .2s;
}
.lib-view-btn:hover { border-color: var(--accent); color: var(--text); }
.lib-view-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tile-cover-placeholder { width:100%; height:100%; background:var(--surface3); }

/* ── Library ─────────────────────────────────────────────────────── */
.lib-item { align-items: center; background: var(--surface); border: 1px solid #ffffff0e; border-radius: 8px; display: flex; gap: 12px; margin-bottom: 8px; padding: 10px 14px; }
.lib-item.lib-tmp { border-color: #2a3a6a; opacity: .8; }
.lib-icon { flex-shrink: 0; font-size: 1.1rem; }
.lib-name { flex: 1; font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-size { color: var(--text2); flex-shrink: 0; font-size: 0.78rem; font-variant-numeric: tabular-nums; }

/* ── Install button ──────────────────────────────────────────────── */
.btn-install {
  background: var(--success);
  border: none;
  border-radius: 6px;
  color: #0a1a10;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 5px 10px;
  transition: opacity .2s;
  white-space: nowrap;
}
.btn-install:hover { opacity: .82; }
.btn-install:disabled { background: var(--surface3); color: var(--text2); cursor: default; opacity: 1; }
.btn-delete {
  background: transparent;
  border: 1px solid #ffffff18;
  border-radius: 6px;
  color: var(--text2);
  cursor: pointer;
  flex-shrink: 0;
  font-size: 0.8rem;
  padding: 4px 8px;
  transition: all .2s;
}
.btn-delete:hover { border-color: var(--error); color: var(--error); }

/* ── Install queue items ─────────────────────────────────────────── */
.iq-item {
  align-items: center;
  background: var(--surface);
  border: 1px solid #4caf8428;
  border-radius: 8px;
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
  padding: 10px 14px;
}
.iq-name { color: var(--text); flex: 1; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-done {
  background: transparent;
  border: 1px solid var(--success);
  border-radius: 6px;
  color: var(--success);
  cursor: pointer;
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  transition: all .2s;
  white-space: nowrap;
}
.btn-done:hover { background: var(--success); color: #0a1a10; }

/* ── Misc ─────────────────────────────────────────────────────────── */
.loading { color: var(--text2); padding: 20px 0; text-align: center; }
.empty   { color: var(--text2); padding: 20px 0; text-align: center; }
.error   { color: var(--error); padding: 12px 0; }
.tid     { color: var(--accent); font-family: monospace; font-size: 0.78rem; }

@media (max-width: 500px) {
  .game-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
  .detail-hero { flex-direction: column; align-items: center; }
  .detail-cover { height: 100px; width: 100px; }
}
