:root {
  --bg: #0d1117;
  --bg-soft: #161b22;
  --bg-card: #12181f;
  --line: #263040;
  --fg: #e6edf3;
  --fg-dim: #8b98a9;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: radial-gradient(1200px 600px at 15% -10%, #1b2130 0%, var(--bg) 55%) fixed;
  color: var(--fg);
  font: 14px/1.55 -apple-system, "SF Pro Text", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--fg-dim); font-size: 12px; }
.grow { flex: 1; }

/* ---------------- topbar ---------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
  background: rgba(13, 17, 23, .82); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.logo {
  font-weight: 800; letter-spacing: .5px; font-size: 18px;
  background: linear-gradient(92deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.sub { color: var(--fg-dim); font-size: 13px; }
.ver { color: var(--fg-dim); font-size: 11px; }
.topactions { display: flex; align-items: center; gap: 8px; }

main { max-width: 1240px; margin: 0 auto; padding: 18px 20px 64px; }

/* ---------------- panels ---------------- */
.panel {
  background: linear-gradient(180deg, rgba(255,255,255,.02), transparent), var(--bg-soft);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 14px;
}
textarea, input[type=text], input[type=number], select {
  width: 100%; background: #0b1017; color: var(--fg);
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px;
  font: inherit; outline: none;
}
textarea { resize: vertical; min-height: 54px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
textarea:focus, input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,92,255,.15); }

.row { display: flex; align-items: center; gap: 10px; }
.search-row { margin-top: 10px; flex-wrap: wrap; }

button {
  font: inherit; cursor: pointer; border-radius: 9px; padding: 8px 14px;
  border: 1px solid var(--line); background: #1b2230; color: var(--fg);
  transition: transform .08s ease, filter .15s ease, background .15s ease;
}
button:hover:not(:disabled) { filter: brightness(1.15); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: linear-gradient(92deg, var(--accent), #5b7cfa); border-color: transparent; font-weight: 600; }
button.danger { background: #2a1518; border-color: #59232a; color: #ffb4ae; }
button.ghost { background: transparent; }
button.tiny { padding: 4px 8px; font-size: 12px; border-radius: 7px; }

.inline { display: inline-flex; align-items: center; gap: 6px; color: var(--fg-dim); font-size: 13px; white-space: nowrap; }
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; }

/* ---------------- options ---------------- */
.options summary { cursor: pointer; font-weight: 600; }
.options[open] summary { margin-bottom: 12px; }
.opt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.opt label { display: block; color: var(--fg-dim); font-size: 12px; margin-bottom: 5px; }
.checks { display: flex; flex-wrap: wrap; gap: 10px; }
.checks-only { display: flex; flex-direction: column; gap: 8px; justify-content: center; }

/* ---------------- cards ---------------- */
.card {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 14px; animation: fade .25s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.code-title { font-size: 17px; font-weight: 700; letter-spacing: .3px; }
.code-title .raw { color: var(--fg-dim); font-weight: 400; font-size: 12px; margin-left: 6px; }
.card-meta { margin-left: auto; display: flex; gap: 10px; }
.stat { font-size: 12px; color: var(--fg-dim); }
.stat b { color: var(--fg); }

.badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; border: 1px solid var(--line); background: #1a2130; color: var(--fg-dim);
}
.badge.kind { color: #cdb8ff; border-color: #3b2f66; background: #221a3a; }
.badge.src.knaben { color: #ffd479; border-color: #4a3a17; background: #2a2210; }
.badge.src.sukebei { color: #ff9ec4; border-color: #4b2436; background: #2a1520; }
.badge.src.nyaa { color: #9fd6ff; border-color: #1e3d55; background: #10202b; }
.badge.src.apibay { color: #a8e6a3; border-color: #21452a; background: #102213; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }

/* 过滤诊断条 */
.filterbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin-top: 8px; padding-top: 8px; border-top: 1px dashed #1f2937;
  font-size: 11px;
}
.filterbar:empty { display: none; }
.fstat { color: var(--fg-dim); }
.fstat b { color: var(--fg); }
.dchip {
  padding: 1px 7px; border-radius: 999px;
  border: 1px solid #3a2f18; background: #241d0e; color: #e3b341;
}
.dchip.warn { border-color: #5c2c2c; background: #2a1414; color: #ff9d95; }
.chip {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  border: 1px dashed var(--line); color: var(--fg-dim);
}
.chip.done { border-style: solid; color: var(--fg); background: #171f2b; }
.chip.bad { border-color: #5b2a2a; color: #ff9d95; }
.chip .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--yellow); margin-right: 5px; animation: pulse 1s infinite; }
.chip.done .dot { background: var(--green); animation: none; }
.chip.bad .dot { background: var(--red); animation: none; }
@keyframes pulse { 50% { opacity: .25; } }

table.results { width: 100%; border-collapse: collapse; margin-top: 12px; }
table.results th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--fg-dim); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line);
}
table.results td { padding: 8px; border-bottom: 1px solid #1b2431; vertical-align: middle; }
table.results tr.row-item { cursor: pointer; }
table.results tr.row-item:hover { background: #161f2b; }
table.results tr.row-item:last-child td { border-bottom: none; }
td.rank { color: var(--fg-dim); width: 34px; }
td.rank .n { font-weight: 700; color: var(--fg); }
td.title-cell { max-width: 520px; }
td.title-cell .ttl { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subline { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 3px; }
td.title-cell .reasons { color: #6f7c8c; font-size: 11px; }

/* 质量列 */
td.qc { white-space: nowrap; width: 96px; }
.qbadge {
  display: inline-block; min-width: 20px; text-align: center;
  padding: 2px 6px; border-radius: 7px; font-weight: 700; font-size: 12px;
  border: 1px solid var(--line);
}
.q-s { color: #ffd76a; border-color: #6b5416; background: #2b2210; }
.q-a { color: #7ee787; border-color: #23562f; background: #102515; }
.q-b { color: #79c0ff; border-color: #204466; background: #0f1f2e; }
.q-c { color: #e3b341; border-color: #5a4715; background: #26200c; }
.q-d { color: #ff9d95; border-color: #5c2c2c; background: #2a1414; }
.qmeta { font-size: 11px; color: var(--fg-dim); margin-top: 2px; }

/* 速度列 */
td.seedcell { width: 76px; }
.seednum { font-variant-numeric: tabular-nums; }
.spd {
  display: inline-block; min-width: 16px; text-align: center;
  font-weight: 700; font-size: 10px; border-radius: 5px; padding: 0 3px;
  border: 1px solid var(--line);
}
.spd-s { color: #7ee787; border-color: #23562f; background: #102515; }
.spd-a { color: #7ee787; border-color: #23562f; background: #102515; }
.spd-b { color: #79c0ff; border-color: #204466; background: #0f1f2e; }
.spd-c { color: #e3b341; border-color: #5a4715; background: #26200c; }
.spd-d { color: #ff9d95; border-color: #5c2c2c; background: #2a1414; }

.tags { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.tag {
  font-size: 10px; padding: 0 6px; border-radius: 999px;
  border: 1px solid #2b3a4d; background: #16202c; color: #9db2c9;
}
.tag-bad { border-color: #5c2c2c; background: #2a1414; color: #ff9d95; }
td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.seed-high { color: var(--green); font-weight: 600; }
.seed-mid { color: var(--yellow); }
.seed-zero { color: var(--red); }
td.acts { white-space: nowrap; text-align: right; }
td.acts .btn { display: inline-block; }

.card-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.empty { padding: 14px; color: var(--fg-dim); border: 1px dashed var(--line); border-radius: 10px; margin-top: 12px; }
.empty b { color: var(--fg); }

/* ---------------- dialogs / toast ---------------- */
dialog {
  background: var(--bg-soft); color: var(--fg); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; min-width: min(420px, 92vw); max-height: 80vh;
}
dialog::backdrop { background: rgba(0,0,0,.55); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
#dlgSourcesBody table { width: 100%; border-collapse: collapse; font-size: 13px; }
#dlgSourcesBody td { padding: 6px 4px; border-bottom: 1px solid #1b2431; }
#dlgCacheBody pre { background: #0b1017; padding: 10px; border-radius: 8px; overflow: auto; font-size: 12px; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  background: #1f2735; border: 1px solid var(--line); color: var(--fg);
  padding: 9px 16px; border-radius: 999px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: .2s ease; z-index: 50;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { border-color: #2c5c39; }
.toast.err { border-color: #5c2c2c; }

@media (max-width: 720px) {
  td.title-cell { max-width: 200px; }
  .card-meta { width: 100%; margin-left: 0; }
}
