:root {
  --bg: #eef1f4;
  --panel: #fbfaf8;
  --card: #ffffff;
  --text: #1f252e;
  --muted: #7c8490;
  --line: #dfe4e9;
  --accent: #c4473b;
  --accent-soft: #f8e8e5;
  --tag: #f2f4f6;
  --shadow: 0 1px 2px rgba(31, 37, 46, .06), 0 12px 34px rgba(31, 37, 46, .08);
}

body.dark {
  --bg: #111418;
  --panel: #191d23;
  --card: #20252d;
  --text: #f2f4f7;
  --muted: #9aa2ad;
  --line: #303742;
  --accent: #ff7a66;
  --accent-soft: #3a211f;
  --tag: #171b21;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 14px 38px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  font-size: 14px;
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 58px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  flex: none;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
  white-space: nowrap;
}
.brand span { color: var(--accent); }
.nsfw-badge {
  flex: none;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--line));
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
}
.icon-btn:hover {
  background: var(--tag);
  border-color: var(--line);
}
#menuBtn { gap: 4px; }
#menuBtn span {
  display: block;
  width: 17px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}
.theme-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.codex-select {
  max-width: 260px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--card);
  color: var(--text);
}

.search-box {
  position: relative;
  flex: 1;
  max-width: 560px;
  min-width: 180px;
}
.search-box svg {
  position: absolute;
  left: 11px;
  top: 50%;
  width: 17px;
  height: 17px;
  transform: translateY(-50%);
  stroke: var(--muted);
  stroke-width: 2;
  fill: none;
}
.search-box input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px 0 36px;
  outline: none;
  background: var(--card);
  color: var(--text);
}
.search-box input:focus { border-color: var(--accent); }

.check-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  color: var(--muted);
  white-space: nowrap;
}
.check-pill input { accent-color: var(--accent); }

.layout { display: flex; align-items: flex-start; }
.sidebar {
  position: sticky;
  top: 58px;
  flex: 0 0 256px;
  width: 256px;
  height: calc(100vh - 58px);
  padding: 14px 10px 18px;
  overflow: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.sidebar.hidden { display: none; }
.library-meta {
  padding: 6px 10px 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 10px;
}
.library-meta strong {
  display: block;
  font-size: 15px;
}
.library-meta span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}
.tree-row:hover { background: var(--tag); }
.tree-row.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}
.tree-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tree-count {
  color: var(--muted);
  font-size: 11px;
}
.tree-arrow {
  width: 14px;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
}
.tree-item.collapsed > .tree-row .tree-arrow { transform: rotate(-90deg); }
.tree-children {
  margin-left: 13px;
  padding-left: 5px;
  border-left: 1px solid var(--line);
}
.tree-item.collapsed > .tree-children { display: none; }

.main {
  flex: 1;
  min-width: 0;
  padding: 18px 22px 80px;
}
.result-bar {
  min-height: 20px;
  margin-bottom: 14px;
  color: var(--muted);
}
.result-bar b { color: var(--accent); }
.loading {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
}

.masonry {
  position: relative;
  min-height: 1px;
  contain: layout paint;
}
.card {
  position: absolute;
  left: 0;
  top: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  box-shadow: var(--shadow);
  cursor: pointer;
  contain: layout paint style;
  transition: box-shadow .14s, border-color .14s, opacity .14s;
}
.card:hover {
  border-color: color-mix(in srgb, var(--accent) 38%, var(--line));
  box-shadow: 0 16px 42px rgba(31, 37, 46, .16);
}
.card.copied { outline: 2px solid var(--accent); }
.image-wrap {
  position: relative;
  overflow: hidden;
  background: var(--tag);
}
.image-wrap::after {
  content: "图片加载中";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
}
.image-wrap.loaded::after { content: ""; }
.image-wrap.error::after { content: "图片加载失败"; }
.card-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .18s;
}
.card-img.ready { opacity: 1; }
.zoom-btn {
  position: absolute;
  right: 8px;
  top: 8px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: rgba(0, 0, 0, .52);
  color: #fff;
  opacity: 0;
  transition: opacity .12s;
}
.zoom-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}
.image-wrap:hover .zoom-btn { opacity: 1; }

.card-body { padding: 12px 13px 11px; }
.title-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}
.card-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
  letter-spacing: 0;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.fav-btn {
  flex: none;
  border: 0;
  border-radius: 6px;
  padding: 0 3px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.2;
}
.fav-btn.on { color: #df9b24; }
.prompt-text {
  height: 78px;
  overflow: hidden;
  padding: 9px 10px;
  border-radius: 8px;
  background: var(--tag);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  mask-image: linear-gradient(180deg, #000 68%, transparent);
}
.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 9px;
  font-size: 11px;
}
.path-text {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.copy-text {
  flex: none;
  color: var(--accent);
  font-weight: 700;
  opacity: 0;
}
.card:hover .copy-text { opacity: 1; }
.detail-btn {
  flex: none;
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 8px;
  background: var(--card);
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
}
.detail-btn:hover {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  z-index: 60;
  transform: translate(-50%, 14px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s, transform .16s;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: none;
  place-items: center;
  padding: 28px;
  background: rgba(0, 0, 0, .84);
  cursor: zoom-out;
}
.lightbox:not([hidden]) { display: grid; }
.lightbox img {
  max-width: 94vw;
  max-height: 92vh;
  border-radius: 8px;
  box-shadow: 0 16px 60px rgba(0, 0, 0, .45);
}
.detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 75;
  background: rgba(0, 0, 0, .34);
  opacity: 0;
  transition: opacity .18s;
}
.detail-overlay[hidden] { display: none; }
body.detail-open .detail-overlay { opacity: 1; }
.detail-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
  width: min(560px, 100vw);
  height: 100vh;
  border-left: 1px solid var(--line);
  background: var(--card);
  box-shadow: -18px 0 50px rgba(0, 0, 0, .18);
  transform: translateX(100%);
  transition: transform .2s ease;
}
.detail-drawer[hidden] { display: none; }
body.detail-open .detail-drawer { transform: translateX(0); }
.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}
.detail-path {
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  word-break: break-word;
}
.detail-head h2 {
  margin: 4px 0 0;
  font-size: 18px;
  line-height: 1.35;
  letter-spacing: 0;
  word-break: break-word;
}
.detail-scroll {
  flex: 1;
  overflow: auto;
  padding: 16px;
}
.detail-gallery {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 8px;
  background: var(--tag);
}
.detail-gallery[hidden] { display: none; }
.detail-gallery img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.detail-nav {
  position: absolute;
  top: 50%;
  display: grid;
  place-items: center;
  width: 34px;
  height: 42px;
  border: 0;
  border-radius: 8px;
  background: rgba(0, 0, 0, .48);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  transform: translateY(-50%);
}
.detail-nav:disabled { opacity: .35; cursor: default; }
.detail-prev { left: 8px; }
.detail-next { right: 8px; }
.detail-zoom,
.detail-count {
  position: absolute;
  bottom: 8px;
  min-height: 28px;
  border-radius: 999px;
  padding: 5px 10px;
  background: rgba(0, 0, 0, .54);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}
.detail-zoom {
  right: 8px;
  border: 0;
}
.detail-count { left: 8px; }
.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
}
.detail-meta span {
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--tag);
}
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}
.detail-actions button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--card);
  color: var(--text);
  font-weight: 800;
}
.detail-actions button:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--accent) 48%, var(--line));
  background: var(--accent-soft);
  color: var(--accent);
}
.detail-actions button:disabled {
  opacity: .45;
  cursor: not-allowed;
}
.detail-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.detail-section h3 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0;
}
.detail-note,
.detail-section pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}
.detail-section pre {
  max-height: 260px;
  overflow: auto;
  border-radius: 8px;
  padding: 10px;
  background: var(--tag);
  color: var(--text);
  font-size: 12px;
}
.age-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(17, 20, 24, .94), rgba(48, 24, 22, .92)),
    var(--bg);
}
.age-gate[hidden] { display: none; }
.age-panel {
  width: min(460px, 100%);
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 8px;
  padding: 26px;
  background: #fbfaf8;
  color: #1f252e;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .38);
}
.age-mark {
  display: inline-flex;
  align-items: center;
  height: 30px;
  border-radius: 999px;
  padding: 0 10px;
  background: #c4473b;
  color: #fff;
  font-size: 13px;
  font-weight: 900;
}
.age-panel h1 {
  margin: 14px 0 10px;
  font-size: 24px;
  letter-spacing: 0;
}
.age-panel p {
  margin: 0;
  color: #5f6874;
  line-height: 1.75;
}
.age-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}
.age-actions button {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 800;
}
.age-primary {
  border: 0;
  background: #c4473b;
  color: #fff;
}
.age-secondary {
  border: 1px solid #d6dbe2;
  background: #fff;
  color: #39414d;
}
.empty {
  padding: 60px 0;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 720px) {
  .topbar {
    height: auto;
    min-height: 58px;
    flex-wrap: wrap;
    padding: 8px 10px;
  }
  .search-box {
    order: 2;
    flex-basis: 100%;
    max-width: none;
  }
  .check-pill span { display: none; }
  .sidebar {
    position: fixed;
    top: 58px;
    left: 0;
    z-index: 18;
    box-shadow: var(--shadow);
  }
  .main { padding: 14px 12px 72px; }
  .detail-drawer { width: 100vw; }
  .detail-head { padding: 12px; }
  .detail-scroll { padding: 12px; }
  .detail-actions button { flex: 1 1 132px; }
}
