:root {
  color-scheme: dark;
  --page: #0b0d0e;
  --surface: #121516;
  --surface-raised: #181c1d;
  --surface-soft: #202526;
  --ink: #f5f7f2;
  --muted: #aeb5ae;
  --quiet: #7d8781;
  --line: #313738;
  --line-strong: #4a5351;
  --acid: #d8ff3e;
  --acid-ink: #101309;
  --cyan: #27d9bf;
  --coral: #ff705d;
  --focus: #ffffff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background: var(--page);
}
body:not([data-role="internal"]) .internal-only { display: none !important; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.library-header {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: 68px;
  padding: 10px max(20px, calc((100vw - 1500px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(11, 13, 14, 0.96);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 24px;
}

.library-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
}
.library-brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 7px;
  overflow: hidden;
  background: #f6f5ed;
  display: grid;
  place-items: center;
}
.library-brand-logo img { width: 100%; height: 100%; object-fit: contain; }
.library-brand strong, .library-brand small { display: block; }
.library-brand strong { font-size: 15px; line-height: 1.2; }
.library-brand small { margin-top: 2px; color: var(--quiet); font-size: 11px; }

.library-nav { display: flex; justify-content: center; gap: 4px; }
.library-nav a {
  min-height: 38px;
  padding: 9px 13px;
  border-radius: 7px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
}
.library-nav a:hover { color: var(--ink); background: var(--surface-raised); }
.library-nav a.active { color: var(--acid-ink); background: var(--acid); }

.library-user-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; }
.viewer-badge {
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
}

.library-main {
  width: min(1500px, calc(100% - 40px));
  margin: 0 auto;
  padding: 34px 0 64px;
}
.library-intro {
  padding: 0 0 26px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}
.brand-line { margin: 0 0 8px; color: var(--acid); font-size: 13px; font-weight: 800; }
.library-intro h1 { margin: 0; font-size: 38px; line-height: 1.1; letter-spacing: 0; text-wrap: balance; }
.intro-copy { max-width: 68ch; margin: 10px 0 0; color: var(--muted); font-size: 15px; line-height: 1.7; text-wrap: pretty; }
.internal-actions { display: flex; gap: 9px; flex-wrap: wrap; }

.button {
  min-height: 40px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-weight: 760;
  transition: background 180ms ease, color 180ms ease, border-color 180ms ease, opacity 180ms ease;
}
.button:disabled { cursor: wait; opacity: 0.55; }
.button-primary { color: var(--acid-ink); background: var(--acid); }
.button-primary:hover:not(:disabled) { background: #e3ff72; }
.button-secondary { color: var(--ink); border-color: var(--line-strong); background: transparent; }
.button-secondary:hover:not(:disabled) { border-color: var(--muted); background: var(--surface-raised); }

.library-summary {
  min-height: 100px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(3, minmax(130px, 190px)) 1fr;
  align-items: center;
  gap: 24px;
}
.library-summary > div { min-width: 0; display: grid; grid-template-columns: auto 1fr; align-items: baseline; column-gap: 8px; }
.library-summary span { grid-column: 1 / -1; color: var(--quiet); font-size: 12px; }
.library-summary strong { margin-top: 4px; font-size: 24px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.library-summary small { color: var(--muted); font-size: 12px; }
.library-summary > p { justify-self: end; max-width: 52ch; margin: 0; color: var(--muted); line-height: 1.6; text-align: right; }

.source-console {
  margin-top: 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.source-console strong { font-size: 14px; }
.source-console p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.status-label { padding: 6px 9px; border-radius: 999px; color: var(--acid-ink); background: var(--acid); font-size: 12px; font-weight: 800; white-space: nowrap; }
.status-label.warning { color: #2a1d02; background: #ffc95c; }

.library-controls { padding: 22px 0 18px; }
.industry-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 13px;
  overflow-x: auto;
  scrollbar-width: none;
}
.industry-tabs::-webkit-scrollbar { display: none; }
.industry-tab {
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 720;
}
.industry-tab:hover { color: var(--ink); border-color: var(--line-strong); }
.industry-tab.active { color: var(--acid-ink); border-color: var(--acid); background: var(--acid); }
.industry-tab small { margin-left: 5px; color: inherit; opacity: 0.7; }

.control-row { display: grid; grid-template-columns: minmax(260px, 1fr) auto auto; align-items: center; gap: 10px; }
.search-field input, .sort-field select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  color: var(--ink);
  background: var(--surface);
}
.search-field input { padding: 10px 13px; }
.search-field input::placeholder { color: #929a94; }
.sort-field { min-width: 190px; min-height: 44px; display: flex; align-items: center; gap: 9px; padding-left: 12px; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--surface); }
.sort-field span { color: var(--quiet); font-size: 12px; }
.sort-field select { min-height: 40px; padding: 0 30px 0 0; border: 0; background: transparent; }
.result-count { min-width: 88px; color: var(--muted); font-size: 13px; text-align: right; }

.material-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.material-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  transition: border-color 180ms ease, transform 180ms ease;
}
.material-card:hover { border-color: #626d69; transform: translateY(-2px); }
.material-preview {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: #1b1f20;
}
.material-preview img { position: absolute; z-index: 1; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.douyin-embed { width: 100%; height: 100%; border: 0; display: block; background: #050606; }
.material-preview[data-image-state="error"] img { display: none; }
.preview-fallback { position: absolute; z-index: 2; inset: 0; padding: 18px; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.material-preview:has(img:not([src=""])) .preview-fallback { background: linear-gradient(180deg, transparent 45%, rgba(0, 0, 0, 0.78)); }
.material-preview:has(.douyin-embed) .preview-fallback { right: auto; bottom: auto; }
.preview-rank { align-self: flex-start; min-width: 34px; min-height: 30px; padding: 6px 8px; border-radius: 6px; color: var(--acid-ink); background: var(--acid); font-size: 13px; font-weight: 850; }
.preview-copy { max-width: 20ch; margin: 0; color: var(--ink); font-size: 13px; font-weight: 700; line-height: 1.45; }
.material-preview img + .preview-fallback .preview-copy { text-shadow: 0 1px 5px #000; }

.material-card-body { flex: 1; padding: 15px; display: flex; flex-direction: column; }
.material-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--quiet); font-size: 12px; }
.industry-chip { color: var(--cyan); font-weight: 780; }
.material-card h2 {
  min-height: 46px;
  margin: 11px 0 8px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 16px;
  line-height: 1.45;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}
.material-author { min-height: 20px; margin: 0 0 12px; color: var(--muted); font-size: 12px; }
.tag-list { min-height: 28px; margin-bottom: 13px; display: flex; flex-wrap: wrap; gap: 5px; }
.tag { max-width: 100%; padding: 5px 8px; border-radius: 999px; overflow: hidden; color: #dfe5df; background: var(--surface-soft); text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.card-actions { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.card-actions a, .card-actions button {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  color: var(--ink);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 12px;
  font-weight: 760;
}
.card-actions a:hover, .card-actions button:hover { border-color: var(--muted); background: var(--surface-raised); }
.card-actions .replicate-link { color: var(--acid-ink); border-color: var(--acid); background: var(--acid); }
.card-actions .replicate-link:hover { color: var(--acid-ink); border-color: #e3ff72; background: #e3ff72; }

.material-skeleton { min-height: 430px; border-radius: 8px; background: var(--surface); position: relative; overflow: hidden; }
.material-skeleton::after { content: ""; position: absolute; inset: 0; background: linear-gradient(100deg, transparent 20%, rgba(255,255,255,0.06) 45%, transparent 70%); transform: translateX(-100%); animation: skeleton 1.4s infinite; }
@keyframes skeleton { to { transform: translateX(100%); } }

.empty-state { padding: 70px 20px; border-top: 1px solid var(--line); text-align: center; }
.empty-state strong { font-size: 18px; }
.empty-state p { margin: 8px 0 18px; color: var(--muted); }

.detail-dialog {
  width: min(920px, calc(100vw - 32px));
  max-height: min(86vh, 900px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--ink);
  background: var(--surface);
}
.detail-dialog::backdrop { background: rgba(0, 0, 0, 0.72); }
.detail-shell { max-height: inherit; display: flex; flex-direction: column; }
.detail-header { min-height: 74px; padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.detail-header h2 { margin: 4px 0 0; font-size: 20px; }
.detail-industry { color: var(--cyan); font-size: 12px; font-weight: 760; }
.icon-button { width: 40px; height: 40px; border: 1px solid var(--line-strong); border-radius: 50%; color: var(--ink); background: transparent; font-size: 26px; line-height: 1; }
.icon-button:hover { background: var(--surface-soft); }
.detail-content { overflow-y: auto; padding: 22px; }
.detail-lead { display: grid; grid-template-columns: 230px 1fr; gap: 22px; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.detail-cover { aspect-ratio: 4 / 3; overflow: hidden; border-radius: 7px; background: var(--surface-soft); display: grid; place-items: center; }
.detail-cover img { width: 100%; height: 100%; object-fit: cover; }
.detail-cover span { padding: 20px; color: var(--quiet); text-align: center; }
.detail-summary h3 { margin: 0 0 8px; font-size: 20px; line-height: 1.45; overflow-wrap: anywhere; }
.detail-summary p { margin: 7px 0; color: var(--muted); line-height: 1.6; }
.detail-link { margin-top: 16px; display: inline-flex; }
.analysis-list { margin: 0; padding: 0; list-style: none; }
.analysis-row { padding: 19px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 150px 1fr; gap: 24px; }
.analysis-row:last-child { border-bottom: 0; }
.analysis-row strong { font-size: 14px; }
.analysis-row p { margin: 0; color: var(--muted); line-height: 1.75; }
.analysis-values { display: flex; flex-wrap: wrap; gap: 7px; }
.analysis-value { padding: 7px 9px; border-radius: 6px; color: var(--ink); background: var(--surface-soft); font-size: 13px; }
.analysis-empty { padding: 28px 0 8px; color: var(--muted); line-height: 1.8; }
.technical-note { margin-top: 18px; padding: 13px 14px; border: 1px solid #5d4b2a; border-radius: 7px; color: #f2d99a; background: #201b13; font-size: 12px; line-height: 1.6; }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: 60; max-width: min(420px, calc(100vw - 40px)); padding: 12px 15px; border: 1px solid var(--line-strong); border-radius: 8px; color: var(--ink); background: #202425; box-shadow: 0 8px 14px rgba(0,0,0,0.32); font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1100px) {
  .material-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .library-summary { grid-template-columns: repeat(3, 1fr); }
  .library-summary > p { grid-column: 1 / -1; justify-self: start; text-align: left; }
}

@media (max-width: 820px) {
  .library-header { grid-template-columns: auto 1fr; gap: 14px; }
  .library-nav { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; overflow-x: auto; }
  .library-user-actions { justify-self: end; }
  .library-main { width: min(100% - 28px, 1500px); padding-top: 26px; }
  .library-intro { align-items: flex-start; }
  .library-intro h1 { font-size: 32px; }
  .material-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-lead { grid-template-columns: 180px 1fr; }
}

@media (max-width: 580px) {
  .library-header { position: relative; padding: 10px 14px; }
  .library-brand small, .viewer-badge { display: none; }
  .library-user-actions .button { min-height: 36px; padding: 7px 10px; }
  .library-main { width: min(100% - 22px, 1500px); padding: 22px 0 42px; }
  .library-intro { display: block; }
  .library-intro h1 { font-size: 29px; }
  .intro-copy { font-size: 14px; }
  .internal-actions { margin-top: 18px; }
  .library-summary { grid-template-columns: 1fr 1fr; gap: 18px 12px; }
  .library-summary > div:nth-child(3) { grid-column: 1 / -1; }
  .control-row { grid-template-columns: 1fr; }
  .sort-field { min-width: 0; }
  .result-count { text-align: left; }
  .material-grid { grid-template-columns: 1fr; }
  .material-preview { aspect-ratio: 16 / 10; }
  .material-card h2 { min-height: 0; }
  .detail-dialog { width: 100vw; max-width: none; max-height: 92vh; margin: auto 0 0; border-radius: 10px 10px 0 0; }
  .detail-content { padding: 18px; }
  .detail-lead { grid-template-columns: 1fr; }
  .detail-cover { aspect-ratio: 16 / 10; }
  .analysis-row { grid-template-columns: 1fr; gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
