:root {
  --bg: #0b0e14;
  --bg-elev: #141924;
  --bg-elev2: #1c2230;
  --line: #262d3d;
  --text: #e8ecf4;
  --muted: #8a94a8;
  --accent: #4c8dff;
  --accent-2: #7b5cff;
  --good: #35c775;
  --warn: #ffb020;
  --bad: #ff5c5c;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  overscroll-behavior-y: none;
}

body { padding-bottom: calc(24px + var(--safe-bottom)); }

.hidden { display: none !important; }

/* ---------- логин ---------- */
.login {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(120% 80% at 50% 0%, #1b2440 0%, var(--bg) 60%);
  padding: 24px; z-index: 50;
}
.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-card h1 { font-size: 32px; margin: 0 0 4px; letter-spacing: -0.02em; }
.login-card p { color: var(--muted); margin: 0 0 24px; font-size: 15px; }
.login-card input, .login-card button {
  width: 100%; height: 50px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--bg-elev); color: var(--text); font-size: 16px; padding: 0 16px;
}
.login-card button {
  margin-top: 12px; border: none; font-weight: 600; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
}
.login-error { color: var(--bad); font-size: 14px; margin-top: 12px; min-height: 20px; }

/* ---------- шапка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(11, 14, 20, 0.86);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + var(--safe-top)) 16px 0;
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; }
.brand { font-size: 24px; margin: 0; letter-spacing: -0.02em; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-elev); color: var(--text); display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }
.icon-btn.spin svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.search-row { margin-top: 10px; display: flex; gap: 8px; }
.search-row input {
  flex: 1; min-width: 0; height: 42px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-elev); color: var(--text); padding: 0 14px; font-size: 15px;
}
.search-row .icon-btn { width: 42px; height: 42px; flex: 0 0 auto; position: relative; }
.dot {
  position: absolute; top: 6px; right: 6px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--accent);
}

.active-filters { display: flex; gap: 6px; overflow-x: auto; padding: 0 0 10px; }
.chip-btn {
  flex: 0 0 auto; padding: 7px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg-elev2); color: var(--muted);
  font-size: 13px; white-space: nowrap;
}
.chip-btn.on { background: rgba(76,141,255,.16); border-color: var(--accent); color: var(--text); }
.chip-btn i { font-style: normal; opacity: .55; margin-left: 5px; font-size: 11px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.filter-group { margin-bottom: 6px; }

.sheet-head {
  position: relative; padding: 18px 18px 4px; display: flex;
  align-items: center; justify-content: space-between;
}
.sheet-head h2 { font-size: 20px; margin: 0; }
.link-btn {
  background: none; border: none; color: var(--accent); font-size: 14px; cursor: pointer; padding: 0;
}

.tabs { display: flex; gap: 6px; margin-top: 12px; overflow-x: auto; padding-bottom: 10px; }
.tabs button {
  flex: 0 0 auto; height: 34px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.tabs button.active { background: var(--text); color: #0b0e14; border-color: var(--text); }
.badge {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; margin-left: 4px;
}

/* ---------- сетка ---------- */
.grid {
  display: grid; gap: 14px; padding: 16px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); } }

.card { cursor: pointer; position: relative; }
.poster {
  position: relative; aspect-ratio: 2/3; border-radius: var(--radius); overflow: hidden;
  background: var(--bg-elev2); box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.poster.no-img::after {
  content: attr(data-letter); position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 44px; font-weight: 700; color: var(--line);
}
.rating {
  position: absolute; left: 8px; top: 8px; padding: 3px 7px; border-radius: 8px;
  background: rgba(0,0,0,.72); font-size: 12px; font-weight: 700; backdrop-filter: blur(4px);
}
.rating.high { color: var(--good); }
.rating.mid { color: var(--warn); }
.rating.low { color: var(--bad); }
.chip {
  position: absolute; right: 8px; top: 8px; padding: 3px 7px; border-radius: 8px;
  background: rgba(0,0,0,.72); font-size: 11px; font-weight: 600; backdrop-filter: blur(4px);
}
.card-status {
  position: absolute; left: 8px; right: 8px; bottom: 8px; padding: 4px 8px; border-radius: 8px;
  background: rgba(76,141,255,.92); font-size: 11px; font-weight: 600; text-align: center;
}
.card-status.done { background: rgba(53,199,117,.92); }
.card h3 {
  font-size: 14px; font-weight: 600; margin: 8px 2px 2px; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .meta { font-size: 12px; color: var(--muted); margin: 0 2px; }
.card .meta.age { font-size: 11px; opacity: .7; margin-top: 1px; }

/* ---------- пусто / загрузка ---------- */
.empty { text-align: center; color: var(--muted); padding: 60px 24px; font-size: 15px; line-height: 1.5; }
.loader { display: grid; place-items: center; padding: 40px; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite;
}
.more {
  display: block; margin: 8px auto 32px; height: 44px; padding: 0 24px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg-elev); color: var(--text); font-size: 15px; cursor: pointer;
}

/* ---------- нижний лист ---------- */
.sheet { position: fixed; inset: 0; z-index: 40; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(2px); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto;
  background: var(--bg-elev); border-radius: 22px 22px 0 0; border-top: 1px solid var(--line);
  padding-bottom: calc(24px + var(--safe-bottom));
  animation: slideup .24s cubic-bezier(.2,.8,.2,1);
}
@keyframes slideup { from { transform: translateY(24px); opacity: 0; } }

.hero { position: relative; aspect-ratio: 16/9; background: var(--bg-elev2); }
.hero img { width: 100%; height: 100%; object-fit: cover; }
.hero::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 40%, var(--bg-elev) 100%);
}
.hero .grab {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  width: 40px; height: 4px; border-radius: 999px; background: rgba(255,255,255,.5); z-index: 2;
}
.sheet-content { padding: 0 18px; margin-top: -28px; position: relative; z-index: 1; }
.sheet-content h2 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.02em; line-height: 1.2; }
.sheet-sub { color: var(--muted); font-size: 14px; margin-bottom: 12px; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.pill {
  padding: 4px 10px; border-radius: 999px; background: var(--bg-elev2);
  font-size: 12px; color: var(--muted); border: 1px solid var(--line);
}
.overview { font-size: 14px; line-height: 1.55; color: #c3cbdb; margin-bottom: 18px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }

.folders { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.folder {
  padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg-elev2);
  font-size: 14px; cursor: pointer; text-align: left; color: var(--text); position: relative;
}
.folder.selected { border-color: var(--accent); background: rgba(76,141,255,.12); }
.folder small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }

.releases { display: flex; flex-direction: column; gap: 8px; }
.release {
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-elev2); cursor: pointer; font-size: 13px;
}
.release.selected { border-color: var(--accent); background: rgba(76,141,255,.12); }
.release .rel-title { word-break: break-word; line-height: 1.35; }
.release .rel-meta { color: var(--muted); font-size: 12px; margin-top: 4px; display: flex; gap: 10px; flex-wrap: wrap; }
.seed { color: var(--good); }

.target-path {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  color: var(--muted); background: var(--bg-elev2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; margin-top: 10px; word-break: break-all;
}

.download-btn {
  position: sticky; bottom: 0; width: 100%; height: 52px; margin-top: 20px;
  border-radius: 14px; border: none; cursor: pointer; font-size: 16px; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.download-btn:disabled { opacity: .5; cursor: default; }

/* ---------- загрузки ---------- */
.downloads { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.job {
  display: flex; gap: 12px; padding: 12px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--bg-elev);
}
.job img { width: 54px; height: 81px; object-fit: cover; border-radius: 8px; background: var(--bg-elev2); flex: 0 0 auto; }
.job-info { flex: 1; min-width: 0; }
.job-info h4 { margin: 0 0 4px; font-size: 15px; }
.job-info .sub { color: var(--muted); font-size: 12px; word-break: break-word; }
.bar { height: 6px; border-radius: 999px; background: var(--bg-elev2); margin-top: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; transition: width .4s; }
.job-status { font-size: 12px; margin-top: 6px; display: flex; justify-content: space-between; color: var(--muted); }
.job-status .completed { color: var(--good); }
.job-status .failed { color: var(--bad); }
.job-cancel {
  background: none; border: none; color: var(--muted); font-size: 12px; cursor: pointer;
  text-decoration: underline; padding: 0;
}

/* ---------- тост ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(24px + var(--safe-bottom)); z-index: 60;
  background: var(--bg-elev2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 18px; border-radius: 12px; font-size: 14px; max-width: 90vw;
  box-shadow: 0 12px 32px rgba(0,0,0,.5);
}
.toast.error { border-color: var(--bad); }

/* кнопка «назад» поверх обложки и в шапке фильтров */
.close-btn {
  position: absolute; top: calc(12px + var(--safe-top)); left: 12px; z-index: 3;
  width: 38px; height: 38px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(0,0,0,.55); backdrop-filter: blur(6px);
  color: #fff; display: grid; place-items: center;
}
.close-btn svg { width: 20px; height: 20px; fill: currentColor; }
.close-btn.inline {
  position: static; width: 34px; height: 34px; background: var(--bg-elev2);
  border: 1px solid var(--line); margin-right: 10px;
}
.sheet-head h2 { flex: 1; }
