:root {
  --bg: #fff6e4;
  --bg-accent: #ffe8a3;
  --paper: #fffdf8;
  --ink: #3a2d18;
  --muted: #7a6848;
  --line: #f0d9a0;
  --yellow: #ffd34e;
  --yellow-deep: #f0b400;
  --orange: #f07a3a;
  --chip: #fff3cc;
  --chip-on: #3a2d18;
  --danger: #c0392b;
  --shadow: 0 10px 30px rgba(90, 60, 10, 0.08);
  --radius: 18px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #fff1b8 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #ffd9a8 0%, transparent 50%),
    var(--bg);
  min-height: 100vh;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--ink);
  color: #fff;
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 20;
}
.skip-link:focus { top: 12px; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.hero {
  padding: 20px 20px 0;
}
.hero-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  gap: 20px;
  align-items: center;
}
.hero-mascot {
  width: 84px;
  height: auto;
  background: var(--paper);
  border: 3px solid #fff;
  border-radius: 24px;
  box-shadow: var(--shadow);
}
.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  letter-spacing: 0.04em;
  font-size: 0.82rem;
}
h1 {
  margin: 0 0 8px;
  font-size: clamp(1.8rem, 3vw, 2.4rem);
  letter-spacing: 0.02em;
}
.lede {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
  max-width: 42em;
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 20px 64px;
}

.toolbar-sticky {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 6;
  background: #fff8ec;
  background: color-mix(in srgb, var(--bg) 88%, white);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  padding: 12px 0 8px;
}
.tag-panel {
  margin: 4px 0 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  padding: 0 10px;
}
.tag-panel summary {
  cursor: pointer;
  list-style: none;
  padding: 8px 0;
  font-weight: 600;
  color: var(--ink);
}
.tag-panel summary::-webkit-details-marker { display: none; }
.tag-panel summary::after {
  content: " ▾";
  color: var(--muted);
  font-weight: 400;
}
.tag-panel[open] summary::after { content: " ▴"; }
.tag-panel #tag-filters { padding-bottom: 6px; }
.search-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.search { flex: 1 1 280px; }
.search input {
  width: 100%;
  border: 2px solid var(--line);
  background: var(--paper);
  border-radius: 999px;
  padding: 12px 16px;
  font: inherit;
  color: var(--ink);
  box-shadow: var(--shadow);
}
.search input:focus {
  outline: 3px solid color-mix(in srgb, var(--yellow) 70%, white);
  border-color: var(--yellow-deep);
}
.btn {
  border: 2px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}
.btn:hover { border-color: var(--yellow-deep); }
.btn:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
.btn-primary {
  background: linear-gradient(#ffe56a, var(--yellow));
  border-color: #f0c422;
  font-weight: 650;
}
.btn-primary:hover { filter: brightness(1.03); }

.hint, .status, .empty, .error, .foot, .noscript {
  color: var(--muted);
  line-height: 1.5;
}
.hint { margin: 6px 0 0; font-size: 0.82rem; }
.status { margin: 8px 0 12px; font-weight: 600; color: var(--ink); }
.error {
  background: #fff1f0;
  color: var(--danger);
  border: 1px solid #f3c0bb;
  border-radius: 12px;
  padding: 12px 14px;
}
.empty {
  background: var(--paper);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
}

.filters { margin-top: 14px; }
.filter-group, .tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 6px;
}
.group-label {
  width: 100%;
  margin: 2px 0 0;
  font-size: 0.74rem;
  color: var(--muted);
  letter-spacing: 0.08em;
}
.chip {
  border: 1px solid var(--line);
  background: var(--chip);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 11px;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
}
.chip[aria-pressed="true"] {
  background: var(--chip-on);
  color: #fff8e5;
  border-color: var(--chip-on);
}
.chip:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
.chip .count {
  margin-left: 4px;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 12px;
}
.card {
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  padding: 0;
  background: var(--paper);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
}
.card::before {
  content: "";
  display: block;
  padding-top: 100%;
}
@supports (aspect-ratio: 1) {
  .card::before { content: none; display: none; padding-top: 0; }
}
.card:hover, .card:focus-visible {
  transform: translateY(-2px);
  outline: 3px solid var(--yellow);
  outline-offset: 2px;
}
.card-thumb {
  /* Absolute fill gives a definite containing block so max-height
     percentages work. Otherwise large PNG/JPG keep their intrinsic
     height, overflow the square card, and only a clipped corner shows. */
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background-image:
    linear-gradient(45deg, #f3efe4 25%, transparent 25%),
    linear-gradient(-45deg, #f3efe4 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f3efe4 75%),
    linear-gradient(-45deg, transparent 75%, #f3efe4 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.card-thumb.is-error::after {
  content: "加载失败";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.7rem;
  color: var(--muted);
  background: var(--paper);
  padding: 2px 6px;
  border-radius: 8px;
  pointer-events: none;
  z-index: 1;
}
.card-thumb img {
  display: block;
  width: auto;
  height: auto;
  max-width: 86%;
  max-height: 86%;
  object-fit: contain;
  min-width: 0;
  min-height: 0;
}
.badge, .tag-dot {
  position: absolute;
  font-size: 0.68rem;
  border-radius: 999px;
  padding: 2px 6px;
  background: rgba(58, 45, 24, 0.82);
  color: #fff;
  line-height: 1.3;
}
.badge { left: 6px; top: 6px; text-transform: uppercase; }
.tag-dot { right: 6px; top: 6px; background: var(--orange); }

.foot {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px 40px;
  font-size: 0.88rem;
}
.foot code, .noscript code { font-family: var(--mono); }
.noscript {
  margin: 16px 20px;
  padding: 12px;
  background: #fff;
  border-radius: 8px;
}

.lightbox[hidden], [hidden] { display: none !important; }
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 30;
}
.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(24, 16, 6, 0.78);
}
.lightbox-dialog {
  position: relative;
  height: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  justify-items: center;
  padding: 24px 12px;
  gap: 8px;
}
.lightbox-figure {
  margin: 0;
  max-width: min(920px, 90vw);
  max-height: 92vh;
  background: var(--paper);
  border-radius: 20px;
  overflow: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
  display: flex;
  flex-direction: column;
}
.lightbox-figure img {
  display: block;
  margin: 18px auto 0;
  max-width: min(86vw, 820px);
  max-height: min(64vh, 720px);
  object-fit: contain;
}
.lightbox-figure figcaption { padding: 14px 18px 18px; }
.lightbox-figure h2 { margin: 0 0 6px; font-size: 1.1rem; }
.lightbox-meta {
  margin: 0 0 8px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.82rem;
  word-break: break-all;
}
.lightbox-tags { margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.lightbox-tags span {
  background: var(--chip);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.82rem;
}
.lightbox-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 0; }
.lightbox-close, .lightbox-nav {
  border: 0;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.6rem;
  cursor: pointer;
  line-height: 1;
}
.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 2;
}
.lightbox-nav:disabled { opacity: 0.35; cursor: default; }

@media (max-width: 700px) {
  .hero { padding: 16px 16px 0; }
  .hero-mascot { width: 64px; }
  .hero-inner { align-items: flex-start; }
  .lede { display: none; }
  .hint { display: none; }
  .toolbar-sticky {
    padding-top: 10px;
    max-height: 38vh;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .search-row { gap: 8px; }
  .btn { padding: 8px 12px; }
  .status { margin: 8px 0 12px; }
  .lightbox-dialog { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .lightbox-nav.prev { justify-self: start; }
  .lightbox-nav.next { justify-self: end; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
}
