:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c232c;
  --line: #262d36;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* The browser's own `[hidden] { display: none }` has the same specificity as a
   class, so `.centered { display: grid }` quietly beat it and the "hidden"
   login screen stayed on top of the app. Make hidden actually mean hidden. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.view { min-height: 100vh; }
.centered { display: grid; place-items: center; padding: 24px; }
.wrap { max-width: 860px; margin: 0 auto; padding: 20px 16px 64px; }

.logo { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.error { color: var(--err); margin: 8px 0 0; font-size: 14px; }
.warn { color: var(--warn); margin: 10px 0 0; font-size: 14px; }
.empty { text-align: center; padding: 32px 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

/* ---------- login ---------- */
.login-card { width: min(380px, 100%); display: grid; gap: 12px; }
.login-card h1 { margin-bottom: 0; }
.login-card p { margin: 0; font-size: 14px; }
.field { display: grid; gap: 6px; font-size: 14px; margin-top: 6px; }
.field span { color: var(--muted); }

input[type="text"], input[type="password"] {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 9px 14px;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); }
.btn.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.btn.ghost:hover { color: var(--text); border-color: var(--muted); }
.btn.danger { background: transparent; color: var(--err); border-color: #4a2226; }
.btn.danger:hover { background: #2a1417; }
.btn.small { padding: 6px 10px; font-size: 13px; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.online { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.offline { background: var(--muted); }

/* ---------- storage ---------- */
.storage { margin-bottom: 14px; }
.storage-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 10px; font-size: 14px; }
.bar { height: 8px; border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s ease, background .3s; }
.bar-fill.warn { background: var(--warn); }
.bar-fill.full { background: var(--err); }

/* ---------- add form ---------- */
.add-form { display: flex; gap: 10px; align-items: center; }
.add-form input { flex: 1; }

/* ---------- list ---------- */
.list-head { display: flex; align-items: baseline; justify-content: space-between; margin: 24px 0 12px; }
.list-head h2 { font-size: 16px; margin: 0; }

.torrent { margin-bottom: 12px; }
.t-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.t-name { font-weight: 600; word-break: break-word; margin: 0 0 4px; }
.t-actions { display: flex; gap: 8px; flex-shrink: 0; }

.badge {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line);
  color: var(--muted);
}
.badge.downloading { color: var(--accent); border-color: #1e3a63; }
.badge.done { color: var(--ok); border-color: #14532d; }
.badge.error { color: var(--err); border-color: #4a2226; }
.badge.queued { color: var(--warn); border-color: #4a3a12; }

.t-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.t-bar { margin-top: 10px; }
.t-error { color: var(--err); font-size: 13px; margin: 10px 0 0; word-break: break-word; }
.t-stalled { color: var(--warn); font-size: 13px; margin: 8px 0 0; }

.files { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 6px; }
.file-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.file-name { word-break: break-all; }
.file-size { color: var(--muted); font-size: 13px; flex-shrink: 0; }
.file-dl { color: var(--accent); text-decoration: none; font-size: 13px; flex-shrink: 0; }
.file-dl:hover { text-decoration: underline; }
.files-toggle { background: none; border: 0; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; padding: 0; margin-top: 10px; }
.files-toggle:hover { color: var(--text); }

@media (max-width: 560px) {
  .add-form { flex-direction: column; align-items: stretch; }
  .t-head { flex-direction: column; }
}
