:root {
  --bg: #0a0c11;
  --surface: #12151c;
  --surface-2: #181c25;
  --border: #232836;
  --text: #e9ebf1;
  --muted: #8b91a3;
  --accent: #8b6cff;
  --accent-strong: #a48bff;
  --success: #3ddc97;
  --radius: 14px;
  --sidebar-w: 248px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html { color-scheme: dark; height: 100%; }

body {
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body:has(dialog[open]) { overflow: hidden; }

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
img { display: block; max-width: 100%; }
svg { width: 20px; height: 20px; flex-shrink: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

img.is-missing { visibility: hidden; }

.noscript {
  padding: 14px 20px;
  background: #3a1f24;
  color: #ffd9de;
  text-align: center;
  font-size: 14px;
}

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 20px 16px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: #0a0c11;
}

.brand-mark svg { width: 18px; height: 18px; }

.nav-group { display: flex; flex-direction: column; gap: 2px; }

.nav-label {
  padding: 0 10px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover { background: var(--surface-2); color: var(--text); }

.nav-item[aria-current="true"] {
  background: rgba(139, 108, 255, 0.12);
  color: var(--text);
}

.nav-item[aria-current="true"] svg { color: var(--accent-strong); }

.nav-badge {
  margin-left: auto;
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent);
  color: #0a0c11;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.nav-badge[hidden] { display: none; }

.sidebar-card {
  margin-top: auto;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}

.sidebar-card strong { display: block; color: var(--text); font-size: 14px; margin-bottom: 4px; }

.storage-bar {
  height: 6px;
  margin-top: 12px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.storage-bar span { display: block; height: 100%; width: 42%; background: var(--accent); border-radius: inherit; transition: width 0.4s; }

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

/* ---------- Main ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 28px;
  background: rgba(10, 12, 17, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.menu-btn {
  display: none;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.search {
  position: relative;
  flex: 1;
  max-width: 520px;
}

.search svg {
  position: absolute;
  left: 14px; top: 50%;
  transform: translateY(-50%);
  width: 18px; height: 18px;
  color: var(--muted);
  pointer-events: none;
}

.search input {
  width: 100%;
  height: 42px;
  padding: 0 14px 0 42px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  transition: border-color 0.15s;
}

.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139, 108, 255, 0.2); }

.avatar {
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
}

.content { flex: 1; padding: 28px; display: flex; flex-direction: column; gap: 28px; }

.footer {
  padding: 22px 28px 28px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

/* ---------- Hero ---------- */
.hero {
  position: relative;
  display: flex;
  align-items: flex-end;
  min-height: 260px;
  padding: 32px;
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: linear-gradient(135deg, #1b2030, #0a0c11);
  isolation: isolate;
}

.hero img {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  z-index: -2;
}

.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(10, 12, 17, 0.95) 0%, rgba(10, 12, 17, 0.6) 50%, rgba(10, 12, 17, 0.1) 100%);
  z-index: -1;
}

.hero-body { max-width: 460px; display: flex; flex-direction: column; gap: 12px; }

.eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.hero h1 { font-size: clamp(26px, 4vw, 38px); line-height: 1.1; letter-spacing: -0.02em; text-wrap: balance; }
.hero p { color: #c3c7d3; font-size: 15px; text-wrap: pretty; }
.hero-actions { display: flex; gap: 10px; margin-top: 6px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
}

.btn:active { transform: scale(0.98); }
.btn svg { width: 17px; height: 17px; }

.btn-primary { background: var(--accent); color: #0a0c11; }
.btn-primary:hover { background: var(--accent-strong); }

.btn-ghost { background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.12); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.1); }

.btn-download { width: 100%; }
.btn-download.hero-dl { width: auto; min-width: 160px; }

.btn-download .btn-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: var(--accent-strong);
  transition: width 0.2s linear;
}

.btn-download .btn-label { position: relative; display: inline-flex; align-items: center; gap: 8px; }

.btn-download.is-downloading { background: rgba(139, 108, 255, 0.35); color: var(--text); cursor: progress; }
.btn-download.is-downloading .btn-fill { background: var(--accent); opacity: 0.85; }

.btn-download.is-done { background: rgba(61, 220, 151, 0.14); color: var(--success); border: 1px solid rgba(61, 220, 151, 0.35); cursor: default; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.toolbar h2 { font-size: 20px; letter-spacing: -0.01em; scroll-margin-top: 90px; }
.toolbar .result-count { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 8px; }

.segmented {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.segmented button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}

.segmented button svg { width: 16px; height: 16px; }
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }

/* ---------- Grid ---------- */
.toolbar + .grid { margin-top: 18px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
}

.card {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.card:hover {
  transform: translateY(-3px);
  border-color: #343a4d;
  box-shadow: 0 18px 40px -20px rgba(0, 0, 0, 0.8);
}

.card-media {
  position: relative;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: linear-gradient(135deg, #1b2030, #12151c);
}

.card-media img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.4s; }
.card:hover .card-media img { transform: scale(1.05); }

.card-open {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.platform-tags {
  position: absolute;
  top: 10px; left: 10px;
  display: flex;
  gap: 6px;
  z-index: 2;
  pointer-events: none;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(10, 12, 17, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.tag svg { width: 12px; height: 12px; }

.card-body { display: flex; flex-direction: column; gap: 12px; padding: 14px 16px 16px; flex: 1; }

.card-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card-title { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.card-genre { font-size: 13px; color: var(--muted); }

.rating {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.rating svg { width: 14px; height: 14px; color: #ffc857; }

.card-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-top: auto;
}

.empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 60px 20px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty strong { color: var(--text); font-size: 16px; }

/* ---------- Modal ---------- */
.modal {
  margin: auto;
  width: min(760px, calc(100% - 32px));
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  overflow: hidden auto;
  overscroll-behavior: contain;
}

.modal::backdrop { background: rgba(4, 5, 8, 0.75); backdrop-filter: blur(4px); }

.modal[open] { animation: modal-in 0.22s ease-out; }

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

.modal-media { position: relative; aspect-ratio: 16 / 7; background: linear-gradient(135deg, #1b2030, #12151c); }
.modal-media img { width: 100%; height: 100%; object-fit: cover; }
.modal-media::after { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, var(--surface) 0%, transparent 60%); pointer-events: none; }

.modal-close {
  position: absolute;
  top: 14px; right: 14px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(10, 12, 17, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.modal-body { display: flex; flex-direction: column; gap: 18px; padding: 0 28px 28px; margin-top: -32px; position: relative; }

.modal-head { display: flex; flex-direction: column; gap: 6px; }
.modal-head h2 { font-size: 26px; letter-spacing: -0.02em; line-height: 1.15; }
.modal-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.modal-desc { color: #c3c7d3; font-size: 15px; text-wrap: pretty; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.stat {
  padding: 12px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.stat dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stat dd { font-size: 15px; font-weight: 600; margin-top: 2px; }

.features { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; }
.features li { padding: 5px 11px; border-radius: 999px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); color: #c3c7d3; }

.download-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border-radius: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.download-panel[hidden] { display: none; }

.progress-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted); }
.progress-row strong { color: var(--text); font-variant-numeric: tabular-nums; }

.progress {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  transition: width 0.2s linear;
}

.progress.is-done span { background: var(--success); }

.modal-actions { display: flex; gap: 10px; }
.modal-download-slot { flex: 1; display: flex; }
.modal-actions .btn-download { flex: 1; height: 46px; font-size: 15px; }
.modal-actions .btn-ghost { height: 46px; }

/* ---------- Toast ---------- */
.toasts {
  position: fixed;
  right: 20px; bottom: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: calc(100vw - 40px);
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  box-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.8);
  font-size: 14px;
  animation: toast-in 0.25s ease-out;
}

.toast svg { color: var(--success); }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: fixed;
    left: 0; top: 0;
    z-index: 50;
    width: min(var(--sidebar-w), 82vw);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .scrim { opacity: 1; pointer-events: auto; }

  .menu-btn { display: grid; }
  .topbar { padding: 12px 16px; }
  .content { padding: 20px 16px; gap: 22px; }
  .footer { padding: 18px 16px 24px; }
}

@media (max-width: 600px) {
  .hero { min-height: 300px; padding: 22px; }
  .hero::after { background: linear-gradient(0deg, rgba(10, 12, 17, 0.97) 10%, rgba(10, 12, 17, 0.4) 100%); }
  .toolbar { flex-direction: column; align-items: stretch; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; justify-content: center; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
  .card-body { padding: 12px; gap: 10px; }
  .card-title { font-size: 15px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .modal-body { padding: 0 18px 20px; }
  .modal-head h2 { font-size: 22px; }
  .modal-actions { flex-direction: column; }
  .avatar { display: none; }
  .toasts { left: 16px; right: 16px; bottom: 16px; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
