:root {
  --bg: #0f1216;
  --panel: #171c24;
  --panel-2: #1f2630;
  --border: #2a3340;
  --text: #e6eaf0;
  --muted: #8b96a5;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --green: #4ade80;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 70% -10%, #16202e 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.link {
  background: none; border: 0; color: var(--accent); cursor: pointer;
  padding: 0; font-size: inherit; text-decoration: underline;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; backdrop-filter: blur(8px);
  background: rgba(15, 18, 22, 0.7); z-index: 10;
}
.brand { font-weight: 700; font-size: 19px; display: flex; align-items: center; gap: 8px; }
.logo { font-size: 22px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.pill {
  font-size: 12px; padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel);
}
.pill-ok { color: var(--green); border-color: #1f5135; background: #0f2a1c; }
.pill-warn { color: var(--amber); border-color: #4d3d12; background: #2a2110; }

.icon-btn {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer; font-size: 17px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--panel-2); }
.icon-btn:disabled { opacity: 0.6; cursor: default; }
.icon-btn.spinning { animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Layout */
.container { max-width: 880px; margin: 0 auto; padding: 24px 18px 80px; }

.add-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 26px;
}
.add-row { display: flex; gap: 10px; }
.add-row input {
  flex: 1; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); padding: 12px 14px; border-radius: 10px; font-size: 15px;
}
.add-row input:focus { outline: none; border-color: var(--accent); }

button.primary {
  background: var(--accent); color: #fff; border: 0; padding: 12px 20px;
  border-radius: 10px; font-size: 15px; cursor: pointer; font-weight: 600;
}
button.primary:hover { background: var(--accent-2); }
button.ghost {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  padding: 10px 14px; border-radius: 10px; cursor: pointer;
}
button.ghost:hover { background: var(--panel-2); }

.drop-zone {
  margin-top: 14px; border: 1.5px dashed var(--border); border-radius: 10px;
  padding: 18px; text-align: center; color: var(--muted); transition: 0.15s;
}
.drop-zone.drag { border-color: var(--accent); background: #11203a; color: var(--text); }

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

.torrent-list { display: flex; flex-direction: column; gap: 12px; }
.empty {
  text-align: center; color: var(--muted); padding: 50px 20px;
  border: 1px dashed var(--border); border-radius: var(--radius);
}

/* Torrent card */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.card-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.card-name { font-weight: 600; word-break: break-word; line-height: 1.35; }
.card-actions { display: flex; gap: 6px; flex-shrink: 0; }
.mini-btn {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 6px 10px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.mini-btn:hover { background: #28323f; }
.mini-btn.danger:hover { background: #3a1f22; border-color: #5b2a2e; color: var(--red); }

.progress { height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; margin: 12px 0 8px; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #60a5fa); transition: width 0.5s; }
.progress.upload > span { background: linear-gradient(90deg, #16a34a, var(--green)); }

.meta { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); }
.meta b { color: var(--text); font-weight: 600; }

.status-tag { font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border); }
.s-downloading { color: #93c5fd; border-color: #1e3a5f; background: #0e1f33; }
.s-connecting { color: var(--amber); }
.s-done, .s-seeding { color: var(--green); border-color: #1f5135; background: #0f2a1c; }
.s-uploading { color: #c4b5fd; border-color: #3b2f63; background: #1c1733; }
.s-uploaded { color: var(--green); border-color: #1f5135; background: #0f2a1c; }
.s-error { color: var(--red); border-color: #5b2a2e; background: #2a1416; }

.drive-link { color: var(--accent); font-size: 13px; text-decoration: none; }
.drive-link:hover { text-decoration: underline; }
.err-text { color: var(--red); font-size: 13px; margin-top: 6px; }

/* Drawer */
.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); }
.drawer-panel {
  position: absolute; right: 0; top: 0; height: 100%; width: min(460px, 100%);
  background: var(--panel); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; animation: slidein 0.18s ease;
}
@keyframes slidein { from { transform: translateX(20px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-size: 17px; }
.drawer-body { padding: 18px 20px; overflow-y: auto; flex: 1; }
.drawer-body h3 { margin: 18px 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.drawer-body h3:first-child { margin-top: 0; }
.drawer-body label { display: block; margin: 12px 0 5px; font-size: 13px; }
.drawer-body input[type="text"], .drawer-body input[type="password"],
.drawer-body input[type="number"], .drawer-body select {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); padding: 10px 12px; border-radius: 9px; font-size: 14px;
}
.drawer-body input:focus, .drawer-body select:focus { outline: none; border-color: var(--accent); }
.drawer-body hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
label.check { display: flex; align-items: center; gap: 9px; margin: 12px 0; font-size: 14px; cursor: pointer; }
label.check input { width: auto; }
.btn-row, .folder-row { display: flex; gap: 8px; margin-top: 12px; }
.folder-row select { flex: 1; }
.redirect-box { background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; margin-top: 12px; }
.redirect-box code { display: block; color: #93c5fd; font-size: 12px; margin: 6px 0; word-break: break-all; }
.connected { color: var(--green); font-size: 13px; margin-top: 10px; }
.drawer-foot { padding: 14px 20px; border-top: 1px solid var(--border); }
.drawer-foot .primary { width: 100%; }
.msg { margin-top: 14px; font-size: 13px; }
.msg.ok { color: var(--green); }
.msg.err { color: var(--red); }

/* Login */
.login-overlay {
  position: fixed; inset: 0; background: var(--bg); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 34px 30px; width: 340px; display: flex; flex-direction: column; gap: 12px;
}
.login-card .brand { justify-content: center; font-size: 22px; margin-bottom: 4px; }
.login-card input {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 14px; border-radius: 10px; font-size: 15px;
}
.login-card button { background: var(--accent); color: #fff; border: 0; padding: 12px; border-radius: 10px; font-size: 15px; cursor: pointer; }
.error { color: var(--red); font-size: 13px; text-align: center; min-height: 16px; }

/* Toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 20px; border-radius: 10px; font-size: 14px; z-index: 200;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.toast.err { border-color: #5b2a2e; color: var(--red); }
.toast.ok { border-color: #1f5135; color: var(--green); }

@media (max-width: 520px) {
  .add-row { flex-direction: column; }
  .meta { gap: 10px; }
}
