:root {
  --bg: #0b0e14;
  --bg-alt: #10141d;
  --fg: #e8eaf0;
  --fg-dim: #9aa3b2;
  --accent: #4fd1c5;
  --accent-dim: rgba(79, 209, 197, 0.35);
  --header-h: 64px;
  --border: rgba(255, 255, 255, 0.08);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
}

#network-bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  display: block;
}

/* Header / toolbar */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  background: rgba(11, 14, 20, 0.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.header-inner {
  max-width: 1100px;
  height: 100%;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--fg);
  text-decoration: none;
  letter-spacing: 0.02em;
}

.logo span {
  color: var(--accent);
}

.site-nav {
  display: flex;
  gap: 28px;
}

.nav-link {
  color: var(--fg-dim);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  transition: color 0.15s ease;
}

.nav-link:hover,
.nav-link.active {
  color: var(--fg);
}

.nav-link.active {
  color: var(--accent);
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 34px;
  height: 34px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
}

.nav-toggle span {
  display: block;
  height: 2px;
  width: 100%;
  background: var(--fg);
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.nav-toggle.open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.nav-toggle.open span:nth-child(2) {
  opacity: 0;
}

.nav-toggle.open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Hero */
.hero {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--header-h) + 20px) 24px 40px;
  text-align: center;
}

.hero-content {
  max-width: 620px;
}

.hero-content h1 {
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  margin: 0 0 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.hero-content p {
  font-size: clamp(1rem, 2vw, 1.15rem);
  line-height: 1.6;
  color: var(--fg-dim);
  margin: 0;
}

/* Tool pages */
.page {
  position: relative;
  z-index: 1;
  padding: calc(var(--header-h) + 40px) 24px 60px;
}

.page-content {
  max-width: 860px;
  margin: 0 auto;
}

.page-content h1 {
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  margin: 0 0 12px;
  letter-spacing: -0.02em;
}

.page-intro {
  color: var(--fg-dim);
  line-height: 1.6;
  margin: 0 0 28px;
}

.card {
  background: rgba(16, 20, 29, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}

.prose p {
  color: var(--fg-dim);
  line-height: 1.7;
  font-size: 0.95rem;
  margin: 0 0 16px;
}

.prose p:last-child {
  margin-bottom: 0;
}

.prose strong {
  color: var(--fg);
}

.field-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--fg-dim);
  margin: 14px 0 6px;
}

.field-label:first-child {
  margin-top: 0;
}

.muted {
  color: var(--fg-dim);
  font-weight: 400;
}

.text-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s ease;
}

.text-input:focus {
  border-color: var(--accent-dim);
}

.option-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 24px;
}

.option {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  display: flex;
  flex-direction: column;
}

.option h2 {
  font-size: 1rem;
  margin: 0 0 10px;
}

.option p {
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--fg-dim);
  margin: 0 0 16px;
  flex: 1;
}

.btn {
  display: inline-block;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px 16px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn + .btn {
  margin-top: 8px;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent-dim);
}

.btn-primary {
  background: rgba(79, 209, 197, 0.12);
  border-color: var(--accent-dim);
  color: var(--accent);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-small {
  padding: 5px 12px;
  font-size: 0.8rem;
}

.run-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
  font-size: 0.9rem;
  color: var(--fg-dim);
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--accent-dim);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.progress-wrap {
  margin-top: 14px;
}

.progress-bar {
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.2s ease;
}

.progress-fill.indeterminate {
  animation: indeterminate 1.4s ease-in-out infinite;
}

@keyframes indeterminate {
  0% { margin-left: -40%; width: 40%; }
  100% { margin-left: 100%; width: 40%; }
}

.progress-text {
  display: block;
  font-size: 0.8rem;
  color: var(--fg-dim);
  margin-top: 6px;
}

.gateway-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 18px;
  font-size: 0.85rem;
}

.gateway-table th,
.gateway-table td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
}

.gateway-table th {
  color: var(--fg-dim);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.gw-ok { color: var(--accent); }
.gw-bad { color: #e07a7a; }

.log {
  margin-top: 18px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  max-height: 260px;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--fg-dim);
}

.log-ok { color: var(--accent); }
.log-warn { color: #d9b45f; }
.log-error { color: #e07a7a; }

.result {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 18px;
}

.hidden {
  display: none !important;
}

.text-link {
  color: var(--accent);
  text-decoration: none;
}

.text-link:hover {
  text-decoration: underline;
}

.torrent-meta {
  margin-top: 20px;
}

.torrent-meta h2 {
  font-size: 1rem;
  margin: 0 0 4px;
  word-break: break-all;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.action-row .btn + .btn {
  margin-top: 0;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
  width: 100%;
  max-width: 440px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h2 {
  font-size: 1.1rem;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  color: var(--fg-dim);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
}

.modal-close:hover {
  color: var(--fg);
}

.modal-hint {
  font-size: 0.82rem;
  line-height: 1.5;
  margin: 8px 0 12px;
}

.server-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  flex: 1;
  min-height: 60px;
}

.server-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: 0.85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.server-item + .server-item {
  border-top: 1px solid var(--border);
}

.server-remove {
  background: none;
  border: none;
  color: #e07a7a;
  font-size: 0.78rem;
  cursor: pointer;
  padding: 2px 4px;
}

.server-remove:hover {
  text-decoration: underline;
}

.modal-add-row {
  display: flex;
  gap: 8px;
}

.modal-add-row .text-input {
  flex: 1;
}

.modal-add-row .btn {
  margin: 0;
}

.modal-foot {
  margin-top: 12px;
  text-align: right;
}

/* Mobile */
@media (max-width: 720px) {
  .option-grid {
    grid-template-columns: 1fr;
  }

  .nav-toggle {
    display: flex;
  }

  .site-nav {
    position: absolute;
    top: var(--header-h);
    left: 0;
    right: 0;
    background: rgba(11, 14, 20, 0.97);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    gap: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.2s ease;
  }

  .site-nav.open {
    max-height: 320px;
  }

  .nav-link {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
  }
}
