:root {
  --bg: #0b0d12;
  --bg-elev: #141822;
  --bg-elev-2: #1c2130;
  --border: #262c3d;
  --text: #eef1f7;
  --text-dim: #9aa3b5;
  --text-faint: #6b7488;
  --accent: #c8a24a;
  --accent-2: #e4c777;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
  --header-h: 60px;
  --maxw: 1440px;
}

:root[data-theme="light"] {
  --bg: #f4f5f8;
  --bg-elev: #ffffff;
  --bg-elev-2: #eef0f5;
  --border: #dfe3ec;
  --text: #1a1f2b;
  --text-dim: #5b6478;
  --text-faint: #8b93a5;
  --accent: #9a7a22;
  --accent-2: #b8922f;
  --shadow: 0 10px 30px rgba(20,30,60,.12);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background .2s ease, color .2s ease;
}

img { display: block; max-width: 100%; }

a { color: inherit; text-decoration: none; }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  height: 100%;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .02em; }
.brand-mark { color: var(--accent); font-size: 18px; }
.brand-text { font-size: 16px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--bg-elev);
  color: var(--text-dim); font-size: 16px; cursor: pointer;
  display: grid; place-items: center; transition: .18s;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }

/* ---------- Layout ---------- */
.container { max-width: var(--maxw); margin: 0 auto; padding: 26px 20px 80px; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr auto;
  gap: 16px;
  align-items: center;
  margin-bottom: 22px;
}
.search-input, .sort-select {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: .18s;
}
.search-input:focus, .sort-select:focus { border-color: var(--accent); }
.sort-wrap { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.sort-label { color: var(--text-dim); font-size: 13px; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 116px;
  overflow-y: auto;
  padding: 2px;
  scrollbar-width: thin;
}
.chip {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-dim);
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: .16s;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { color: var(--text); border-color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #14110a; font-weight: 600; }
.chip .count { font-size: 11px; opacity: .75; }

/* ---------- Gallery grid ---------- */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 16px;
}
.card {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  cursor: pointer;
  aspect-ratio: 9 / 16;
  transition: transform .22s ease, box-shadow .22s ease, border-color .22s;
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: var(--accent); }
.card img { width: 100%; height: 100%; object-fit: cover; transition: transform .5s ease; }
.card:hover img { transform: scale(1.06); }
.card-overlay {
  position: absolute; inset: auto 0 0 0;
  padding: 34px 12px 11px;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,.82));
  color: #fff;
}
.card-name { font-size: 13.5px; font-weight: 600; line-height: 1.35; margin: 0; }
.card-dl {
  position: absolute; top: 10px; right: 10px;
  width: 34px; height: 34px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.55); color: #fff;
  font-size: 15px; cursor: pointer; opacity: 0;
  display: grid; place-items: center; transition: .18s;
  backdrop-filter: blur(6px);
}
.card:hover .card-dl { opacity: 1; }
.card-dl:hover { background: var(--accent); color: #14110a; }

/* ---------- States ---------- */
.gallery-state, .empty-state {
  text-align: center; padding: 70px 20px; color: var(--text-dim);
}
.empty-icon { font-size: 46px; margin-bottom: 12px; }
.empty-title { font-size: 18px; color: var(--text); margin: 0 0 8px; font-weight: 700; }
.empty-desc { font-size: 14px; line-height: 1.9; margin: 0; }
.empty-desc code {
  background: var(--bg-elev-2); padding: 2px 7px; border-radius: 6px;
  font-size: 12.5px; color: var(--accent-2); font-family: ui-monospace, Consolas, monospace;
}
.spinner {
  width: 30px; height: 30px; margin: 0 auto 14px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); background: var(--bg-elev); }
.footer-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 26px 20px;
  display: flex; align-items: center; justify-content: space-between;
  color: var(--text-faint); font-size: 13px; flex-wrap: wrap; gap: 10px;
}
.footer-links a:hover { color: var(--accent); }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4,6,10,.94);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 4vh 4vw;
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.lb-figure {
  margin: 0; max-width: min(1200px, 92vw); max-height: 92vh;
  display: flex; flex-direction: column; gap: 0;
  border-radius: var(--radius); overflow: hidden;
  background: #0d0f15; box-shadow: var(--shadow);
}
.lb-image { max-height: 74vh; width: auto; max-width: 100%; margin: 0 auto; object-fit: contain; }
.lb-caption {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 18px; background: #12151d; border-top: 1px solid #232838;
  flex-wrap: wrap;
}
.lb-meta { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.lb-name { font-size: 15px; font-weight: 700; color: #f2f4f9; }
.lb-actions { display: flex; gap: 10px; }
.btn {
  padding: 9px 16px; border-radius: 9px; font-size: 13.5px; font-weight: 600;
  border: 1px solid #2b3142; background: #1a1f2b; color: #dfe3ec; cursor: pointer;
  transition: .16s; display: inline-block;
}
.btn:hover { border-color: var(--accent); color: #fff; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #14110a; }
.btn-primary:hover { background: var(--accent-2); color: #14110a; }
.lb-close {
  position: absolute; top: 16px; right: 20px;
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid #2b3142; background: rgba(20,24,34,.8); color: #dfe3ec;
  font-size: 17px; cursor: pointer; display: grid; place-items: center;
}
.lb-close:hover { border-color: var(--accent); color: #fff; }
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 48px; height: 78px; border: 0; cursor: pointer;
  background: rgba(20,24,34,.6); color: #dfe3ec; font-size: 30px; line-height: 1;
  display: grid; place-items: center; border-radius: 10px;
}
.lb-nav:hover { background: rgba(200,162,74,.85); color: #14110a; }
.lb-prev { left: 1.5vw; }
.lb-next { right: 1.5vw; }
.lb-counter {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  color: #8b93a5; font-size: 13px; letter-spacing: .05em;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .toolbar { grid-template-columns: 1fr 1fr; }
  .chips { grid-column: 1 / -1; max-height: 104px; }
}
@media (max-width: 620px) {
  .toolbar { grid-template-columns: 1fr; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
  .lb-nav { width: 40px; height: 62px; }
  .lb-caption { flex-direction: column; align-items: flex-start; }
  .footer-inner { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}
