:root {
  color-scheme: dark;
  --bg: #111317;
  --surface: #181b20;
  --surface-2: #20242a;
  --line: #303640;
  --text: #f5f7fb;
  --muted: #a8b0bd;
  --red: #ef3d3d;
  --green: #7ad957;
  --cyan: #61d5e8;
  --amber: #f5bd45;
  --blue: #88a8ff;
  --shadow: 0 18px 60px rgb(0 0 0 / 0.24);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 12% 0%, rgb(239 61 61 / 0.08), transparent 28rem),
    linear-gradient(180deg, #111317 0%, #15181d 40%, #101215 100%);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1rem;
  align-items: center;
  min-height: 68px;
  padding: 0.75rem clamp(1rem, 3vw, 2.25rem);
  background: rgb(17 19 23 / 0.84);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.brand,
.account,
.nav,
.search-line,
.summary-row,
.meta,
.chips,
.actions,
.modal-head,
.modal-actions,
.filter-actions,
.checkline,
.docs-head {
  display: flex;
  align-items: center;
}

.brand {
  gap: 0.65rem;
  font-weight: 800;
  font-size: 1.05rem;
}

.brand img {
  width: 34px;
  height: 34px;
}

.nav {
  justify-content: center;
  gap: 0.35rem;
}

.nav a {
  color: var(--muted);
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
}

.nav a:hover {
  color: var(--text);
  background: var(--surface-2);
}

.account {
  gap: 0.55rem;
}

.status-dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 4px rgb(245 189 69 / 0.13);
}

.status-dot.ok {
  background: var(--green);
  box-shadow: 0 0 0 4px rgb(122 217 87 / 0.13);
}

.status-dot.bad {
  background: var(--red);
  box-shadow: 0 0 0 4px rgb(239 61 61 / 0.13);
}

.open-label {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 0.65rem;
  color: #dfffd4;
  background: rgb(122 217 87 / 0.12);
  border: 1px solid rgb(122 217 87 / 0.24);
  border-radius: 8px;
  font-size: 0.84rem;
  font-weight: 800;
}

main {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.25rem 0 4rem;
}

.status-panel {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(420px, 1.05fr);
  gap: 1rem;
  align-items: stretch;
  margin: 0.35rem 0 1rem;
  padding: 1rem;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgb(239 61 61 / 0.14), transparent 34%),
    linear-gradient(180deg, #1a1e24, #16191f);
  border: 1px solid #303743;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.status-copy {
  display: grid;
  align-content: center;
  gap: 0.45rem;
  min-width: 0;
}

.status-copy h1 {
  max-width: 720px;
  margin: 0;
  font-size: clamp(1.45rem, 2.8vw, 2.35rem);
  line-height: 1.08;
  letter-spacing: 0;
}

.status-copy p:not(.eyebrow) {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
}

.metric-card {
  display: grid;
  align-content: space-between;
  min-height: 118px;
  padding: 0.85rem;
  background: rgb(15 17 21 / 0.72);
  border: 1px solid #333b48;
  border-radius: 8px;
}

.metric-card span,
.metric-card small {
  color: var(--muted);
  font-size: 0.78rem;
}

.metric-card strong {
  margin: 0.35rem 0 0.1rem;
  color: #f9fbff;
  font-size: clamp(1.1rem, 2vw, 1.55rem);
  line-height: 1;
  word-break: break-word;
}

#metricUpdated {
  font-size: clamp(1.05rem, 1.45vw, 1.28rem);
  white-space: nowrap;
  word-break: normal;
}

#metricUptime {
  line-height: 1.35;
}

.search-workspace {
  padding-top: 0.75rem;
}

.search-form {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.search-line {
  gap: 0.75rem;
  padding: 0.8rem;
  border-bottom: 1px solid var(--line);
}

.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 48px;
  padding: 0 0.85rem;
  background: #0f1115;
  border: 1px solid #343a45;
  border-radius: 8px;
}

.search-box input {
  width: 100%;
  min-width: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: 0;
}

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.8rem;
  padding: 0.9rem;
}

label {
  display: grid;
  gap: 0.4rem;
}

label span {
  color: var(--muted);
  font-size: 0.86rem;
}

input,
select {
  width: 100%;
  min-height: 42px;
  padding: 0 0.75rem;
  color: var(--text);
  background: #242932;
  border: 1px solid #3a414d;
  border-radius: 8px;
  outline: 0;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgb(136 168 255 / 0.18);
}

.filter-actions {
  grid-column: span 2;
  gap: 0.65rem;
  align-self: end;
}

.checkline {
  grid-auto-flow: column;
  justify-content: start;
  gap: 0.5rem;
  min-height: 42px;
  padding: 0 0.7rem;
  background: #242932;
  border: 1px solid #3a414d;
  border-radius: 8px;
}

.checkline input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--red);
}

.button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 42px;
  color: var(--text);
  border: 1px solid #424955;
  border-radius: 8px;
  background: var(--surface-2);
}

.button {
  padding: 0 0.9rem;
  font-weight: 750;
}

.button.primary {
  background: var(--red);
  border-color: var(--red);
  color: white;
}

.button.primary:hover {
  background: #ff4b4b;
}

.button.ghost {
  background: transparent;
}

.button.compact {
  min-height: 38px;
}

.icon-button {
  width: 40px;
  padding: 0;
}

.button svg,
.icon-button svg,
.search-box svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.summary-row {
  justify-content: space-between;
  gap: 1rem;
  margin: 1rem 0;
  color: var(--muted);
}

.summary-row strong {
  display: block;
  color: var(--text);
}

.alert {
  margin: 1rem 0;
  padding: 0.9rem 1rem;
  background: rgb(239 61 61 / 0.12);
  border: 1px solid rgb(239 61 61 / 0.35);
  border-radius: 8px;
  color: #ffd5d5;
}

.results {
  display: grid;
  gap: 0.75rem;
}

.torrent-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem 1rem 1rem 1.1rem;
  background:
    linear-gradient(90deg, rgb(239 61 61 / 0.12), transparent 34%),
    #1c2026;
  border: 1px solid #2d343e;
  border-radius: 8px;
  box-shadow: 0 12px 36px rgb(0 0 0 / 0.18);
  transition: border-color 140ms ease, transform 140ms ease, background-color 140ms ease;
}

.torrent-card:hover {
  border-color: #46505e;
  transform: translateY(-1px);
  background:
    linear-gradient(90deg, rgb(239 61 61 / 0.16), transparent 36%),
    #20252c;
}

.title-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  min-width: 0;
}

.tracker-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 36px;
  height: 36px;
  background: #242a33;
  border: 1px solid #39424f;
  border-radius: 8px;
}

.tracker-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.title-block {
  min-width: 0;
}

.torrent-title {
  margin: 0;
  font-size: 1rem;
  line-height: 1.42;
}

.title-block p {
  margin: 0.25rem 0 0;
  color: #8f9aaa;
  font-size: 0.84rem;
  line-height: 1.35;
}

.meta,
.chips {
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.8rem;
}

.meta span,
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-height: 28px;
  padding: 0 0.55rem;
  color: var(--muted);
  background: #252a32;
  border: 1px solid #343b46;
  border-radius: 8px;
  font-size: 0.86rem;
}

.stat svg {
  width: 14px;
  height: 14px;
}

.seed {
  color: var(--green);
}

.peer {
  color: #ff8d8d;
}

.size {
  color: var(--cyan);
}

.quality {
  color: #cbf18b;
}

.availability {
  color: #d6e2ff;
}

.actions {
  gap: 0.5rem;
  align-self: start;
}

.magnet-button {
  color: #ffd8d8;
  background: rgb(239 61 61 / 0.16);
  border-color: rgb(239 61 61 / 0.36);
}

.send-tor {
  color: #d7fbff;
  background: rgb(97 213 232 / 0.13);
  border-color: rgb(97 213 232 / 0.32);
}

.send-tor .lucide-loader-2 {
  animation: spin 900ms linear infinite;
}

.actions .icon-button[disabled] {
  cursor: not-allowed;
  opacity: 0.45;
}

.has-tip {
  position: relative;
}

.has-tip:hover::after,
.has-tip:focus-visible::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  z-index: 50;
  width: max-content;
  max-width: min(260px, 70vw);
  transform: translateX(-50%);
  padding: 0.45rem 0.6rem;
  color: #f7f9fc;
  background: #0d0f13;
  border: 1px solid #3c4552;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.34);
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.25;
  pointer-events: none;
  white-space: normal;
}

.has-tip:hover::before,
.has-tip:focus-visible::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc(100% + 3px);
  z-index: 51;
  width: 10px;
  height: 10px;
  transform: translateX(-50%) rotate(45deg);
  background: #0d0f13;
  border-right: 1px solid #3c4552;
  border-bottom: 1px solid #3c4552;
  pointer-events: none;
}

.empty {
  padding: 2rem;
  color: var(--muted);
  text-align: center;
  border: 1px dashed #3a414d;
  border-radius: 8px;
}

.stats-section {
  margin-top: 2.5rem;
  padding-top: 1rem;
}

.chart-wrap {
  padding: 1rem;
  background:
    linear-gradient(180deg, rgb(97 213 232 / 0.08), transparent),
    #181b20;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tracker-chart {
  display: grid;
  gap: 0.55rem;
}

.tracker-row {
  display: grid;
  grid-template-columns: minmax(92px, 0.18fr) minmax(120px, 1fr) minmax(72px, auto);
  gap: 0.75rem;
  align-items: center;
  min-height: 28px;
}

.tracker-name {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tracker-bar {
  height: 12px;
  overflow: hidden;
  background: rgb(239 61 61 / 0.18);
  border-radius: 999px;
}

.tracker-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--red), var(--cyan));
  border-radius: inherit;
}

.tracker-row strong {
  color: #d8e2ff;
  font-size: 0.9rem;
  text-align: right;
  white-space: nowrap;
}

.tracker-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.tracker-stats .empty {
  grid-column: 1 / -1;
}

.tracker-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: center;
  min-height: 76px;
  padding: 0.85rem;
  background: #181b20;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tracker-card strong,
.tracker-card span {
  display: block;
}

.tracker-card strong {
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tracker-card div > span {
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.tracker-counts {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.35rem;
}

.tracker-counts span {
  min-height: 26px;
  padding: 0.25rem 0.45rem;
  color: #d8e2ff;
  background: #242932;
  border: 1px solid #343b46;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 750;
}

.docs {
  margin-top: 3rem;
  padding-top: 1rem;
}

.docs-head {
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--red);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 0.78rem;
}

.docs h1,
.docs h2 {
  margin: 0;
}

.docs-lead {
  max-width: 680px;
  margin: 0.45rem 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.doc-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.doc-card {
  padding: 1rem;
  background: #181b20;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.doc-card.wide {
  grid-column: 1 / -1;
}

.site-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 2rem;
  padding: 1rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.site-footer a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 34px;
  padding: 0 0.65rem;
  background: #181b20;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.site-footer a:hover {
  color: var(--text);
  border-color: #46505e;
}

.site-footer svg {
  width: 16px;
  height: 16px;
}

.site-footer span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #46505e;
}

.doc-grid p {
  color: var(--muted);
  line-height: 1.55;
}

.param-table {
  display: grid;
  grid-template-columns: minmax(110px, 0.28fr) minmax(0, 1fr);
  gap: 0;
  margin-top: 0.85rem;
  border: 1px solid #303640;
  border-radius: 8px;
  overflow: hidden;
}

.param-table span,
.param-table p {
  margin: 0;
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid #303640;
}

.param-table span:nth-last-child(2),
.param-table p:last-child {
  border-bottom: 0;
}

.param-table span {
  color: #d8e2ff;
  background: #11151b;
  font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  font-size: 0.86rem;
}

.param-table p {
  color: var(--muted);
  background: #171b21;
}

pre {
  overflow: auto;
  margin: 0.8rem 0 0;
  padding: 0.9rem;
  background: #0f1115;
  border: 1px solid #303640;
  border-radius: 8px;
}

code {
  color: #d8e2ff;
  font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  font-size: 0.88rem;
}

.modal {
  width: min(440px, calc(100% - 2rem));
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
}

.modal::backdrop {
  background: rgb(0 0 0 / 0.64);
  backdrop-filter: blur(8px);
}

.modal-body {
  display: grid;
  gap: 0.9rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.modal-head {
  justify-content: space-between;
}

.modal-head h2 {
  margin: 0;
}

.modal-actions {
  gap: 0.65rem;
  flex-wrap: wrap;
}

.tor-auth {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form-error {
  margin: 0;
  color: #ffb4b4;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 860px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .nav {
    display: none;
  }

  .filters,
  .doc-grid,
  .tracker-stats {
    grid-template-columns: 1fr 1fr;
  }

  .status-panel {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-actions {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  main {
    width: min(100% - 1rem, 1180px);
    padding-top: 0.75rem;
  }

  .status-panel,
  #stats,
  #api-docs {
    display: none;
  }

  .site-footer {
    margin-top: 1.25rem;
    padding-bottom: 1rem;
  }

  .search-line,
  .summary-row,
  .torrent-card,
  .docs-head {
    align-items: stretch;
    flex-direction: column;
  }

  .filters,
  .doc-grid,
  .tracker-stats,
  .tor-auth {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .metric-card {
    min-height: 92px;
  }

  .param-table {
    grid-template-columns: 1fr;
  }

  .param-table span {
    border-bottom: 0;
  }

  .param-table p {
    border-bottom: 1px solid #303640;
  }

  .param-table p:last-child {
    border-bottom: 0;
  }

  .filter-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .torrent-card {
    grid-template-columns: 1fr;
  }

  .actions {
    justify-content: flex-start;
  }

  .tracker-card {
    grid-template-columns: 1fr;
  }

  .tracker-row {
    grid-template-columns: 1fr;
    gap: 0.35rem;
    padding: 0.35rem 0;
  }

  .tracker-row strong {
    text-align: left;
  }

  .tracker-counts {
    justify-content: flex-start;
  }
}
