:root {
  --bg: #0b0d12;
  --bg-2: #12151d;
  --bg-3: #1a1f2b;
  --card: #161a24;
  --line: #262c3a;
  --text: #eef1f7;
  --muted: #9aa3b5;
  --muted-2: #6b7488;
  --accent: #f5c518;
  --accent-ink: #171200;
  --good: #4cd08a;
  --radius: 14px;
  --radius-sm: 10px;
  --search-btn-w: 92px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select { font-family: inherit; }
h1, h2, h3 { margin: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 11px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #ffd23f; }
.btn-ghost { background: var(--bg-3); color: var(--text); border: 1px solid var(--line); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: rgba(255, 92, 122, .1); color: #e8a4b2; border: 1px solid rgba(255, 92, 122, .3); }
.btn-danger:hover { background: rgba(255, 92, 122, .18); color: #ffc0cc; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.input,
select.input {
  width: 100%;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 14px;
  outline: none;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--muted-2); }
select.input { appearance: none; -webkit-appearance: none; }

.muted { color: var(--muted); }
.hidden { display: none !important; }

/* 标题字体：马善政（Ma Shan Zheng），SIL OFL 免费字体，见 static/fonts/ma-shan-zheng-LICENSE.txt */
@font-face {
  font-family: "Ma Shan Zheng";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/ma-shan-zheng-400.woff2") format("woff2");
}

/* ------------------------------------------------------------------ 首页 */
.home {
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
  padding: 76px 20px 96px;
}
.home-top {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}
.settings-link {
  position: fixed;
  top: 16px;
  right: 18px;
  z-index: 30;
  padding: 8px 14px;
  font-size: 13.5px;
  color: var(--muted);
  background: rgba(22, 26, 36, .72);
  border: 1px solid var(--line);
  border-radius: 999px;
  backdrop-filter: blur(10px) saturate(130%);
  -webkit-backdrop-filter: blur(10px) saturate(130%);
  transition: color .15s ease, border-color .15s ease;
}
.settings-link:hover { color: var(--accent); border-color: rgba(245, 197, 24, .5); }

.hero { text-align: center; margin-bottom: 32px; }
.hero h1 {
  margin: 0;
  font-family: "Ma Shan Zheng", "PingFang SC", "Source Han Sans SC",
    "Noto Sans CJK SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 60px;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-indent: 0.08em;
  line-height: 1.2;
  color: #f2ece1;
  text-shadow: none;
}
.hero p {
  margin: 14px 0 0;
  color: #8c8779;
  font-size: 11.5px;
  font-weight: 400;
  letter-spacing: 0.1em;
  text-indent: 0;
  line-height: 1.7;
}

.searchbar { display: flex; gap: 10px; }
/* 左侧留出与搜索按钮等宽的空位，使「搜索框」相对上方标题居中（按钮仍在右边） */
.searchbar::before {
  content: "";
  flex: 0 0 auto;
  width: var(--search-btn-w);
}
.searchbar input {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  font-size: 16px;
  color: var(--text);
  outline: none;
  box-shadow: var(--shadow);
  transition: border-color .15s ease;
}
.searchbar input:focus { border-color: var(--accent); }
.searchbar input::placeholder { color: var(--muted-2); }
.searchbar .btn {
  width: var(--search-btn-w);
  padding: 0;
  font-size: 15px;
  border-radius: var(--radius);
  flex: 0 0 auto;
}

.home-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  padding-left: 4px;
  font-size: 13px;
  color: var(--muted-2);
}
.home-meta b { color: var(--accent); font-weight: 700; }

.recent { margin-top: 28px; }
.recent-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 12.5px;
  color: var(--muted-2);
}
.link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--muted-2);
  font-size: 12.5px;
  cursor: pointer;
}
.link-btn:hover { color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--muted);
  font-size: 13px;
  padding: 6px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease;
}
.chip:hover { color: var(--text); border-color: var(--muted-2); }

.status { margin-top: 32px; text-align: center; color: var(--muted); font-size: 14px; }
.error {
  margin-top: 24px;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  background: rgba(255, 92, 122, .08);
  border: 1px solid rgba(255, 92, 122, .28);
  color: #f0b4c0;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

#results { margin-top: 36px; }
.results-head {
  padding-bottom: 14px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  color: var(--muted);
}
.results-head b { color: var(--text); }
.results-head .gold { color: var(--accent); font-weight: 700; }
.cards {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  align-items: stretch;
  gap: 14px;
}
@media (min-width: 560px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 860px) {
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1140px) {
  .cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.card {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 16px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card .card-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 44px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.45;
  word-break: break-word;
}
.card .card-title.has-detail { cursor: pointer; }
.card .badges { display: flex; flex-wrap: wrap; gap: 6px; }
.source-line {
  color: var(--muted-2);
  font-size: 12.5px;
  line-height: 1.5;
  min-height: 19px;
}
.source-line b { color: var(--muted); font-weight: 600; }
.badge {
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--muted);
}
.badge.quark { color: #8fb0ff; border-color: rgba(90, 140, 255, .35); background: rgba(90, 140, 255, .1); }
.badge.baidu { color: var(--accent); border-color: rgba(245, 197, 24, .35); background: rgba(245, 197, 24, .1); }
.card .desc {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .actions { position: relative; margin-top: auto; display: flex; gap: 10px; padding-top: 2px; }
.card .actions .btn { flex: 1; }
.drive-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  min-width: 132px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 10;
}
.drive-menu[hidden] { display: none; }
.drive-menu button {
  border: 0;
  background: none;
  color: var(--text);
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  cursor: pointer;
}
.drive-menu button:hover { background: var(--bg-3); color: var(--accent); }
.drive-menu button:disabled { opacity: .5; cursor: not-allowed; color: var(--muted-2); }
.btn.is-done { background: rgba(76, 208, 138, .14); color: #9fe3bd; border: 1px solid rgba(76, 208, 138, .35); }
.transfer-msg { margin-top: 6px; font-size: 12px; line-height: 1.5; word-break: break-word; }
.transfer-msg.ok { color: #9fe3bd; }
.transfer-msg.err { color: #f0b4c0; }
.empty { padding: 22px 0; text-align: center; color: var(--muted-2); font-size: 14px; }

.filters { display: flex; flex-wrap: wrap; gap: 12px 22px; margin-bottom: 18px; }
.filter-row { display: flex; gap: 8px; }
.chip.active { background: var(--text); color: #0b0d12; border-color: var(--text); font-weight: 700; }

.tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  align-content: flex-start;
  gap: 6px;
  height: 26px;
  overflow: hidden;
}
.tag {
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.tag.hl { color: var(--accent); border-color: rgba(245, 197, 24, .35); background: rgba(245, 197, 24, .1); }
.tag-sep { color: var(--muted-2); font-size: 12px; }
.tag-drive { color: var(--muted); font-weight: 600; font-size: 12.5px; white-space: nowrap; }
.raw-toggle { align-self: flex-start; }
.raw-title {
  margin-top: 6px;
  color: var(--muted-2);
  font-size: 12px;
  line-height: 1.55;
  word-break: break-word;
}

.low-wrap { margin-top: 26px; text-align: center; }
.low-toggle {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted-2);
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease;
}
.low-toggle b { color: var(--muted); font-weight: 700; }
.low-toggle:hover { color: var(--muted); border-color: var(--muted-2); }
.cards.low { margin-top: 18px; }
.cards.low .card { opacity: .68; }

.raw { margin-top: 30px; }
.raw summary {
  list-style: none;
  cursor: pointer;
  padding: 8px 0;
  color: var(--muted-2);
  font-size: 13px;
}
.raw summary::-webkit-details-marker { display: none; }
.raw summary:hover { color: var(--muted); }
.raw .reply {
  padding: 14px;
  margin-top: 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: #c6cdda;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}
.debug-summary {
  padding: 12px 14px;
  margin-top: 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.8;
  white-space: pre-wrap;
}
.debug-bot {
  margin-top: 12px;
  padding: 14px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.debug-bot-head { font-size: 13.5px; font-weight: 700; color: var(--text); }
.debug-line { color: var(--muted); font-size: 12.5px; line-height: 1.7; white-space: pre-wrap; margin-top: 4px; }

/* ------------------------------------------------------------ 资源源管理 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  background: rgba(11, 13, 18, .86);
  border-bottom: 1px solid rgba(255, 255, 255, .06);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
}
.topbar .back { color: var(--muted); font-size: 13.5px; }
.topbar .back:hover { color: var(--accent); }
.topbar h1 { font-size: 17px; font-weight: 750; }
.topbar .spacer { margin-left: auto; }

.manage { max-width: 820px; margin: 0 auto; padding: 28px 20px 96px; }
.sources { display: flex; flex-direction: column; gap: 12px; }
.source {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.source-info { flex: 1; min-width: 0; }
.source-name { font-size: 15.5px; font-weight: 700; }
.source-fields { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 7px; }
.field-kv { font-size: 12.5px; color: var(--muted-2); }
.field-kv span { color: var(--muted); }
.source code {
  padding: 1px 6px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 12.5px;
  color: #cdd4e0;
}
.source-side { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.status-pill {
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted-2);
}
.status-pill.on { color: var(--good); border-color: rgba(76, 208, 138, .35); background: rgba(76, 208, 138, .1); }
.row-actions { display: flex; gap: 8px; }

.form-card {
  padding: 20px;
  margin-bottom: 24px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.form-card h2 { font-size: 16px; margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; color: var(--muted-2); }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--muted); }
.checkbox input { width: auto; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.form-actions .btn { padding: 10px 20px; }

.notice {
  padding: 11px 14px;
  margin-bottom: 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  white-space: pre-wrap;
}
.notice.ok { background: rgba(76, 208, 138, .1); border: 1px solid rgba(76, 208, 138, .3); color: #9fe3bd; }
.notice.err { background: rgba(255, 92, 122, .08); border: 1px solid rgba(255, 92, 122, .28); color: #f0b4c0; }
.empty-tip { padding: 20px 0; color: var(--muted-2); font-size: 14px; }

.card-status { font-size: 12px; font-weight: 600; min-height: 17px; }
.card-status.pending { color: var(--muted-2); }
.card-status.ok { color: var(--good); }
.card-status.err { color: #f0b4c0; }
.card-status.warn { color: var(--accent); }

.detect-status { margin: 0 0 14px; font-size: 13px; color: var(--muted); }
.detect-status.done { color: var(--muted-2); }
.head-note { margin-left: 6px; font-size: 13px; color: var(--muted-2); }

/* ---------- 预览弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(4, 6, 10, .72); backdrop-filter: blur(2px); }
.modal-panel {
  position: relative;
  width: min(720px, 100%);
  max-height: min(80vh, 760px);
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head-text { min-width: 0; }
.modal-title { font-size: 16px; font-weight: 700; line-height: 1.4; word-break: break-word; }
.modal-sub { margin-top: 4px; font-size: 12.5px; color: var(--muted); }
.modal-close { flex: none; border: 1px solid var(--line); background: var(--bg-3); color: var(--text); border-radius: 9px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.modal-close:hover { border-color: var(--accent); color: var(--accent); }
.modal-body { padding: 14px 18px 20px; overflow-y: auto; }

.preview-badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.preview-badge.ok { background: rgba(76, 208, 138, .14); color: var(--good); }
.preview-badge.err { background: rgba(255, 92, 122, .14); color: #f0b4c0; }
.preview-stats { margin: 4px 0 12px; font-size: 13px; color: var(--muted); }
.preview-loading, .preview-empty { padding: 28px 0; text-align: center; color: var(--muted); font-size: 14px; }
.preview-more { margin-top: 10px; font-size: 12.5px; color: var(--muted-2); }
.preview-tree { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-2); }
.preview-node { border-bottom: 1px solid rgba(38, 44, 58, .55); }
.preview-node:last-child { border-bottom: 0; }
.preview-row { display: flex; align-items: center; gap: 8px; padding: 8px 12px; font-size: 13.5px; }
.preview-row:hover { background: rgba(255, 255, 255, .03); }
.preview-icon { flex: none; width: 18px; text-align: center; font-size: 13px; opacity: .9; }
.preview-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-row.collapsible .preview-name { cursor: pointer; }
.preview-row.kind-folder .preview-name { font-weight: 600; }
.preview-row.kind-video .preview-name { color: #ffd23f; }
.preview-size { flex: none; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.preview-row.kind-video .preview-size { color: var(--accent); font-weight: 700; }
.preview-row.collapsed .preview-icon { opacity: .5; }
.preview-children { background: rgba(0, 0, 0, .12); }

/* ---------- 登录页 ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 32px 26px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}
.login-title {
  margin: 0;
  font-family: "Ma Shan Zheng", "PingFang SC", "Source Han Sans SC", "Noto Sans CJK SC", sans-serif;
  font-size: 40px;
  font-weight: 400;
  color: #f2ece1;
}
.login-sub {
  margin: 0 0 10px;
  color: #8c8779;
  font-size: 11px;
  letter-spacing: 0.06em;
  line-height: 1.6;
}
.login-card .input { text-align: left; }
.login-btn { width: 100%; height: 46px; margin-top: 4px; }
.login-error { color: #f0b4c0; font-size: 13px; }
.login-tip { margin-top: 4px; color: var(--muted-2); font-size: 12px; }

@media (max-width: 620px) {
  .home { padding: 58px 16px 80px; }
  .settings-link { display: none; }
  .hero h1 { font-size: 42px; letter-spacing: 0.06em; text-indent: 0.06em; }
  .hero p {
    font-size: 11px;
    letter-spacing: 0.06em;
    text-indent: 0;
    line-height: 1.65;
  }

  .searchbar { flex-direction: column; gap: 8px; }
  .searchbar::before { display: none; }
  .searchbar input {
    flex: 0 0 auto;
    height: 42px;
    padding: 0 15px;
    font-size: 16px;
    border-radius: 12px;
    box-shadow: none;
  }
  .searchbar .btn {
    width: 100%;
    height: 38px;
    padding: 0 14px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 12px;
    background: #dfb42c;
    color: var(--accent-ink);
  }
  .searchbar .btn:active { background: #efc84a; }

  .source { flex-direction: column; align-items: stretch; }
  .source-side { flex-direction: row; align-items: center; justify-content: space-between; }
  .grid { grid-template-columns: 1fr; }
  .topbar { padding: 12px 16px; }
  .manage { padding: 20px 16px 80px; }
}
