:root {
  color-scheme: light;
  --bg: #f4f6fb;
  --card: #ffffff;
  --card-2: #f8fafc;
  --text: #172033;
  --muted: #64748b;
  --faint: #94a3b8;
  --line: #e2e8f0;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --ok: #15803d;
  --ok-soft: #ecfdf3;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --dead: #b91c1c;
  --dead-soft: #fef2f2;
  --unknown: #475569;
  --unknown-soft: #f1f5f9;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.86em;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  word-break: break-all;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 26px 18px 60px;
}

.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.hero h1 {
  margin: 0 0 4px;
  font-size: clamp(22px, 3vw, 30px);
  letter-spacing: -0.02em;
}

.hero p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.hero .hero-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.toolbar {
  position: sticky;
  top: 10px;
  z-index: 20;
  backdrop-filter: blur(12px);
  background: color-mix(in srgb, var(--card) 92%, transparent);
}

.toolbar-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) repeat(2, minmax(120px, 0.6fr)) auto;
  gap: 10px;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field label {
  font-size: 12px;
  color: var(--muted);
}

input[type="text"],
input[type="search"],
select,
input[type="url"] {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  outline: none;
}

input[type="text"]:focus,
input[type="search"]:focus,
select:focus,
input[type="url"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.switches {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 12px;
  align-items: center;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.switch input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 9px;
  height: 38px;
  padding: 0 13px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: 0.16s ease;
  white-space: nowrap;
}

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

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

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: #1d4ed8;
  color: #fff;
}

.btn.ghost { background: transparent; }

.btn.tiny {
  height: 28px;
  padding: 0 9px;
  font-size: 12px;
  border-radius: 7px;
}

.btn.danger { color: var(--dead); }
.btn.danger:hover:not(:disabled) { border-color: var(--dead); background: var(--dead-soft); }

.stats {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 9px 11px;
}

.stat b {
  display: block;
  font-size: 20px;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.stat span {
  color: var(--muted);
  font-size: 11px;
}

.stat.ok b { color: var(--ok); }
.stat.warn b { color: var(--warn); }
.stat.dead b { color: var(--dead); }
.stat.unknown b { color: var(--unknown); }

.source-meta {
  font-size: 12px;
  color: var(--muted);
  margin: 2px 2px 12px;
  overflow-wrap: anywhere;
}

.source-meta a { color: var(--muted); text-decoration: underline; }

.list-card { padding: 0; overflow: hidden; }

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--card-2);
}

.list-head h2 {
  margin: 0;
  font-size: 14px;
}

.list-head .hint {
  color: var(--muted);
  font-size: 12px;
}

.site-list { max-height: 62vh; overflow: auto; }

.site-row {
  display: grid;
  grid-template-columns: 30px minmax(180px, 1fr) auto auto auto;
  gap: 10px;
  align-items: center;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
}

.site-row:last-child { border-bottom: 0; }
.site-row:hover { background: var(--card-2); }
.site-row.official { background: linear-gradient(90deg, var(--accent-soft), transparent 55%); }

.check { display: flex; align-items: center; justify-content: center; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }

.site-main { min-width: 0; }
.site-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-sub { font-size: 11px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.star { color: #f59e0b; margin-right: 3px; }

.site-tags, .site-status { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }

.badge {
  display: inline-flex;
  align-items: center;
  height: 21px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--unknown-soft);
  color: var(--unknown);
  border: 1px solid var(--line);
  white-space: nowrap;
}

.badge.muted { color: var(--faint); }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: #bbf7d0; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: #fde68a; }
.badge.dead { background: var(--dead-soft); color: var(--dead); border-color: #fecaca; }
.badge.unknown { background: var(--unknown-soft); color: var(--unknown); }
.badge.untested { background: var(--card-2); color: var(--faint); }
.badge.type-api { background: #eef2ff; color: #4338ca; border-color: #c7d2fe; }
.badge.type-spider { background: #f5f3ff; color: #6d28d9; border-color: #ddd6fe; }
.badge.type-rule { background: #ecfeff; color: #0e7490; border-color: #a5f3fc; }

.ms { font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }
.note { font-size: 11px; color: var(--faint); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.progress-track {
  flex: 1;
  height: 7px;
  border-radius: 99px;
  background: var(--card-2);
  border: 1px solid var(--line);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}

.progress-text { font-size: 12px; color: var(--muted); white-space: nowrap; }

.result-card { border-color: #bfdbfe; }
.result-card h2 { margin: 0 0 4px; font-size: 15px; }
.result-card p { margin: 0 0 10px; color: var(--muted); font-size: 12px; }

.result-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.result-row input { flex: 1; }

.preview {
  margin: 12px 0 0;
  padding: 12px;
  max-height: 320px;
  overflow: auto;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 10px;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
}

.notes { color: var(--muted); font-size: 13px; }
.notes strong { color: var(--text); }
.notes ul { margin: 8px 0 0; padding-left: 20px; }
.notes li { margin: 4px 0; }

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

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: #111827;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 100;
  max-width: min(90vw, 560px);
  text-align: center;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.success { background: #166534; }
.toast.warn { background: #92400e; }
.toast.error { background: #991b1b; }

@media (max-width: 900px) {
  .toolbar-grid { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .site-row { grid-template-columns: 30px minmax(140px, 1fr) auto auto; }
  .site-row .site-tags { display: none; }
}

@media (max-width: 620px) {
  .wrap { padding: 16px 10px 40px; }
  .hero { flex-direction: column; }
  .hero .hero-links { justify-content: flex-start; }
  .toolbar { position: static; }
  .toolbar-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .site-row { grid-template-columns: 30px minmax(110px, 1fr) auto auto; padding: 9px 10px; }
  .site-status .note { display: none; }
  .result-row { flex-direction: column; align-items: stretch; }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0b1120;
    --card: #111827;
    --card-2: #0f172a;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --faint: #64748b;
    --line: #1f2937;
    --accent: #60a5fa;
    --accent-soft: #172554;
    --ok: #4ade80;
    --ok-soft: #052e16;
    --warn: #fbbf24;
    --warn-soft: #451a03;
    --dead: #f87171;
    --dead-soft: #450a0a;
    --unknown: #cbd5e1;
    --unknown-soft: #1e293b;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  }
  .toolbar { background: color-mix(in srgb, var(--card) 90%, transparent); }
  .site-row.official { background: linear-gradient(90deg, var(--accent-soft), transparent 55%); }
  .badge.type-api { background: #1e1b4b; color: #a5b4fc; border-color: #3730a3; }
  .badge.type-spider { background: #2e1065; color: #c4b5fd; border-color: #4c1d95; }
  .badge.type-rule { background: #083344; color: #67e8f9; border-color: #155e75; }
}
