:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --line: #2a2f3a;
  --text: #e8eaef;
  --muted: #8b93a4;
  --accent: #4f8cff;
  --green: #3ccf7a;
  --amber: #f2b33d;
  --red: #ff5d5d;
  --purple: #a98bff;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }

/* lock */
.lock { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.lock-card { width: 100%; max-width: 340px; display: grid; gap: 14px; text-align: center; justify-items: center; }
.lock-card h1 { margin: 0 0 6px; font-size: 22px; }
.lock-card input, .lock-card button { width: 100%; }
.err { color: var(--red); min-height: 1.2em; margin: 0; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: rgba(15, 17, 21, .92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.title { font-weight: 700; font-size: 18px; }
.speeds { display: flex; gap: 12px; font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); }
.speeds .on-dl { color: var(--green); }
.speeds .on-up { color: var(--accent); }

.view { padding-bottom: calc(76px + var(--safe-b)); }
.sticky {
  position: sticky; top: calc(49px + var(--safe-t)); z-index: 4;
  background: var(--bg); padding: 10px 12px 6px; border-bottom: 1px solid var(--line);
}

/* inputs */
.search-input, select, textarea, .lock-card input {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 12px; width: 100%; outline: none;
}
.search-input:focus, textarea:focus, select:focus, .lock-card input:focus { border-color: var(--accent); }
.search-row { display: flex; gap: 8px; }
.search-row select { width: auto; flex: 0 0 auto; }
textarea { resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }

/* chips */
.chips { display: flex; gap: 8px; padding: 10px 0 4px; }
.chips.scroll { overflow-x: auto; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--panel);
  padding: 7px 13px; border-radius: 999px; font-size: 13px; white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .n { opacity: .7; margin-left: 4px; font-variant-numeric: tabular-nums; }
.chip-sep { flex: 0 0 1px; background: var(--line); margin: 4px 2px; }

/* sort */
.sortbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0 2px; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: none; padding: 7px 12px; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--panel-2); color: var(--text); font-weight: 600; }
.toggle { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.status { font-size: 12px; color: var(--muted); padding: 6px 0 2px; display: flex; align-items: center; gap: 8px; min-height: 26px; }
.status button { margin-left: auto; }

/* list + cards */
.list { padding: 10px 12px; display: grid; gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.card.pad { padding: 14px; display: grid; gap: 10px; margin: 12px; }
.tor { padding: 12px 14px; display: grid; gap: 7px; cursor: pointer; }
.tor:active { background: var(--panel-2); }
.name { font-weight: 600; word-break: break-word; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.meta b { color: var(--text); font-weight: 600; }
.bar { height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }
.st-down .bar > i { background: var(--accent); }
.st-seed .bar > i, .st-done .bar > i { background: var(--green); }
.st-paused .bar > i { background: var(--muted); }
.st-stalled .bar > i { background: var(--amber); }
.st-error .bar > i { background: var(--red); }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 6px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.badge.res { color: #fff; background: #2b3f6b; border-color: #34508a; }
.badge.uhd { background: #4a2f7a; border-color: #5e3d99; }
.badge.state { text-transform: capitalize; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; }

.result { padding: 12px 14px; display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; }
.result .info { display: grid; gap: 6px; min-width: 0; }
.seeds { color: var(--green); font-weight: 700; }
.seeds.low { color: var(--amber); }
.seeds.dead { color: var(--red); }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* buttons */
.btn {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 12px;
  padding: 11px 16px; font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: transparent; border-color: #5a2a2a; color: var(--red); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.small { padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.btn.wide { width: calc(100% - 24px); margin: 0 12px; }
.card .btn.wide { width: 100%; margin: 4px 0 0; }
.btn:disabled { opacity: .5; }
.btn.added { background: var(--green); border-color: var(--green); color: #08210f; }
.lbl { font-size: 13px; color: var(--muted); }

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: rgba(23, 26, 33, .96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
.tabbar button { border: 0; background: none; padding: 8px 0 10px; color: var(--muted); font-size: 11px; display: grid; justify-items: center; gap: 2px; }
.tabbar .ico { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.active { color: var(--accent); }

/* sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 10; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  background: var(--panel); border-top-left-radius: 18px; border-top-right-radius: 18px;
  border-top: 1px solid var(--line);
  padding: 10px 16px calc(16px + var(--safe-b)); display: grid; gap: 10px;
  max-height: 85dvh; overflow-y: auto; animation: up .18s ease-out;
}
.sheet .grab { width: 40px; height: 4px; background: var(--line); border-radius: 9px; margin: 0 auto 6px; }
.sheet h3 { margin: 0; font-size: 15px; word-break: break-word; }
.sheet .kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; color: var(--muted); }
.sheet .kv span:nth-child(even) { color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.sheet .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + var(--safe-b)); z-index: 20;
  background: #2a2f3a; color: var(--text); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.4); max-width: 90vw;
}
.toast.bad { background: #4a1f1f; }

.spin { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: s .8s linear infinite; }
@keyframes s { to { transform: rotate(360deg); } }
