:root {
  color-scheme: light;
  --bg: #f7f3ee;
  --paper: #fffdf9;
  --ink: #171717;
  --muted: #6f6a62;
  --line: rgba(23, 23, 23, 0.11);
  --accent: #d9435f;
  --accent-dark: #a72b42;
  --shadow: 0 10px 28px rgba(35, 27, 18, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px clamp(14px, 3vw, 36px);
  background: rgba(247, 243, 238, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.eyebrow,
h1 {
  margin: 0;
}

.eyebrow {
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin-top: 2px;
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1.05;
}

.tools {
  display: grid;
  grid-template-columns: minmax(180px, 320px) 150px;
  gap: 10px;
  width: min(100%, 500px);
}

.filter-toggle {
  display: none;
}

input,
select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  outline: none;
}

input {
  padding: 0 14px;
}

select {
  padding: 0 10px;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217, 67, 95, 0.16);
}

main {
  padding: 18px clamp(10px, 2vw, 28px) 40px;
}

.status {
  margin: 12px auto 20px;
  max-width: 720px;
  color: var(--muted);
  text-align: center;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(var(--columns, 5), minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.masonry-column {
  display: grid;
  gap: 16px;
  align-content: start;
}

.card {
  display: block;
  width: 100%;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.card:hover {
  transform: translateY(-2px);
  border-color: rgba(217, 67, 95, 0.35);
  box-shadow: var(--shadow);
}

.image-wrap {
  position: relative;
  display: block;
  min-height: 0;
  overflow: hidden;
  background: #eee7de;
}

.card > .image-wrap {
  aspect-ratio: var(--preview-ratio, 4 / 5);
}

.image-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, #eee7de 8%, #f8f2ea 18%, #eee7de 33%);
  background-size: 220% 100%;
  animation: shimmer 1.3s linear infinite;
}

.image-wrap.loaded::before,
.image-wrap.failed::before {
  content: none;
}

.image-wrap.failed {
  display: grid;
  min-height: 220px;
  place-items: center;
  padding: 18px;
  background: #eee7de;
}

.image-wrap.failed::after {
  content: "图片暂不可用\a" attr(data-title);
  white-space: pre-wrap;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
}

.image-wrap.failed img {
  display: none;
}

.card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #eee7de;
}

.card-body {
  padding: 10px 11px 11px;
}

.card-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  min-height: 24px;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.28;
}

.title-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

.badge {
  flex: 0 0 auto;
  padding-top: 1px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.detail {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  overflow: auto;
  padding: 22px;
  background: rgba(23, 23, 23, 0.58);
}

.detail.open {
  display: block;
}

.detail-content {
  width: min(1120px, 100%);
  margin: 0 auto;
  overflow: hidden;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

.close {
  position: fixed;
  top: 16px;
  right: 18px;
  z-index: 60;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
  gap: 0;
}

.detail-media {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 16px;
  background: #111;
}

.detail-media img {
  width: 100%;
  height: auto;
  border-radius: 6px;
  object-fit: contain;
  background: #2a2a2a;
}

.detail-media .image-wrap {
  min-height: 260px;
  border-radius: 6px;
  background: #2a2a2a;
}

@keyframes shimmer {
  to {
    background-position-x: -220%;
  }
}

.detail-copy {
  padding: clamp(20px, 4vw, 38px);
}

.detail-copy h2 {
  margin: 0 0 8px;
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1.08;
}

.source-link {
  display: inline-flex;
  margin-bottom: 22px;
  color: var(--accent-dark);
  font-weight: 800;
  text-decoration: none;
}

.prompt-box {
  max-height: 62vh;
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbf6ef;
  white-space: pre-wrap;
  color: #25201b;
  font: 14px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (max-width: 1200px) {
  .gallery {
    gap: 14px;
  }

  .masonry-column {
    gap: 14px;
  }
}

@media (max-width: 900px) {
  .topbar,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
    display: grid;
  }

  .tools {
    grid-template-columns: 1fr;
    width: 100%;
  }

}

@media (max-width: 640px) {
  .topbar {
    gap: 12px;
    padding: 14px 16px 12px;
  }

  h1 {
    font-size: 30px;
  }

  .filter-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    height: 42px;
    padding: 0 13px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--paper);
    color: var(--ink);
    font: inherit;
    font-weight: 800;
    text-align: left;
  }

  .filter-toggle::after {
    content: "⌄";
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 18px;
    line-height: 1;
  }

  .filter-toggle[aria-expanded="true"]::after {
    content: "×";
    font-size: 22px;
  }

  #filterSummary {
    min-width: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tools {
    display: none;
    gap: 8px;
  }

  .topbar.filters-open .tools {
    display: grid;
  }

  main {
    padding-top: 12px;
  }

  .status {
    margin-top: 6px;
    margin-bottom: 14px;
    font-size: 14px;
  }

  .gallery {
    gap: 10px;
  }

  .masonry-column {
    gap: 10px;
  }

  .detail {
    padding: 10px;
  }
}
