:root {
  color-scheme: light;
  --paper: #f8f4eb;
  --sheet: #fffcf5;
  --ink: #29251f;
  --muted: #62594f;
  --rule: #d6cbbd;
  --control-rule: #9b8f80;
  --wash: #efe8dc;
  --seal: #9e3025;
  --measure: 70rem;
  --gutter: clamp(1rem, 4vw, 2rem);
  --radius: .25rem;
  --sans: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  --title: "Songti SC", "Noto Serif SC", "Source Han Serif SC", Georgia, serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #211e1b;
  --sheet: #292521;
  --ink: #f1e8da;
  --muted: #c3b7a7;
  --rule: #51483f;
  --control-rule: #8f8274;
  --wash: #342e28;
  --seal: #f08c7c;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --paper: #211e1b;
    --sheet: #292521;
    --ink: #f1e8da;
    --muted: #c3b7a7;
    --rule: #51483f;
    --control-rule: #8f8274;
    --wash: #342e28;
    --seal: #f08c7c;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-block-size: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font: 1rem/1.7 var(--sans);
}

main { flex: 1; }
h1, h2, h3, p, dl, dd { margin: 0; }
a { color: var(--seal); text-underline-offset: .2em; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible {
  outline: 2px solid var(--seal);
  outline-offset: 2px;
}

.wrap {
  width: calc(100% - var(--gutter) - var(--gutter));
  max-width: var(--measure);
  margin-inline: auto;
}

.sr-only {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.site-header { padding-block: clamp(1.5rem, 5vw, 3.75rem) 1.25rem; }

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: .5rem 1.25rem;
}

#site-title h1 {
  font: 700 clamp(1.75rem, 5vw, 3.25rem)/1.25 var(--title);
  letter-spacing: .04em;
}

.site-subtitle {
  margin-block-start: .5rem;
  color: var(--muted);
  font-size: .9375rem;
}

.site-tools {
  display: flex;
  align-items: center;
  gap: .625rem;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-inline-size: 44px;
  min-block-size: 44px;
  font-size: .6875rem;
  font-weight: 700;
  letter-spacing: .14em;
}

.site-stats {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem 1.5rem;
  margin-block-start: 1rem;
  font-size: .8125rem;
}

.site-stats > div { display: flex; gap: .5em; }
.site-stats dt { color: var(--muted); }
.site-stats dd, .result-count { font-variant-numeric: tabular-nums; }

button, input { font: inherit; color: inherit; }

button {
  min-block-size: 44px;
  padding: .375rem .75rem;
  border: 1px solid var(--control-rule);
  border-radius: var(--radius);
  background: var(--sheet);
  font-size: .875rem;
  line-height: 1.35;
  white-space: nowrap;
  cursor: pointer;
}

button:hover:not(:disabled) { background: var(--wash); }
button:disabled { color: var(--muted); cursor: default; }

button[aria-pressed="true"] {
  border-color: var(--seal);
  background: var(--wash);
  color: var(--seal);
  font-weight: 650;
}

.theme-toggle { background: transparent; font-size: .8125rem; }

.filter-bar {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  border-block: 1px solid var(--rule);
  background: var(--paper);
}

.filter-inner {
  display: grid;
  gap: .5rem;
  padding-block: .75rem .625rem;
}

.search-row, .filter-row, .filter-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.search-row input {
  flex: 1;
  min-inline-size: 0;
  min-block-size: 44px;
  padding: .4rem .75rem;
  border: 1px solid var(--control-rule);
  border-radius: var(--radius);
  background: var(--sheet);
}

.search-row input::placeholder { color: var(--muted); opacity: 1; }
.search-row input::-webkit-search-cancel-button { display: none; }
.filter-row { flex-wrap: wrap; gap: .25rem .75rem; }

.segments, .topic-chips {
  display: flex;
  max-inline-size: 100%;
  overflow-x: auto;
  padding: 4px;
  margin: -4px;
  scrollbar-width: thin;
}

.segments { max-inline-size: calc(100% + 8px); }
.segments > button { flex: none; border-radius: 0; padding-inline: .625rem; }
.segments > button + button { margin-inline-start: -1px; }
.segments > button:first-child { border-start-start-radius: var(--radius); border-end-start-radius: var(--radius); }
.segments > button:last-child { border-start-end-radius: var(--radius); border-end-end-radius: var(--radius); }
.segments > button[aria-pressed="true"], .segments > button:focus-visible { position: relative; }
.segments > button:focus-visible { z-index: 1; }
#filter-reset { border-color: transparent; background: transparent; text-decoration: underline; text-underline-offset: .2em; }

.topic-chips { gap: .375rem; max-inline-size: calc(100% + 8px); }
.topic-chips:empty, .result-count:empty { display: none; }
.topic-chips > button { flex: none; border-radius: 999px; }
.result-count { color: var(--muted); font-size: .8125rem; }

.catalog-results { padding-block: 1.5rem clamp(2.5rem, 7vw, 5rem); }

.project-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
}

.project-card {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  min-inline-size: 0;
  padding: 1.125rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--sheet);
  overflow-wrap: anywhere;
}

.card-header, .card-badges, .project-meta, .card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .375rem .75rem;
}

.project-title, .card-title, .project-card :is(h2, h3) {
  font-size: 1.0625rem;
  line-height: 1.45;
}

.status-pill, .featured-mark {
  display: inline-block;
  width: fit-content;
  border: 1px solid var(--rule);
  padding: .0625rem .5rem;
  color: var(--muted);
  font-size: .75rem;
}

.status-pill { border-radius: 999px; background: var(--wash); }
.featured-mark {
  border-color: var(--seal);
  border-radius: .125rem;
  color: var(--seal);
  font-weight: 700;
  letter-spacing: .08em;
}

.project-description, .card-description, .card-desc {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  color: var(--muted);
  font-size: .9375rem;
}

.project-meta, .card-meta {
  margin-block-start: auto;
  padding-block-start: .75rem;
  border-block-start: 1px solid var(--rule);
  color: var(--muted);
  font-size: .8125rem;
}

.project-link, .external-link {
  display: inline-flex;
  width: fit-content;
  min-block-size: 44px;
  align-items: center;
  gap: .4em;
  font-size: .875rem;
  font-weight: 650;
}

.project-link::after, .external-link::after {
  content: "";
  flex: none;
  inline-size: .58em;
  block-size: .58em;
  border-block-start: 1px solid currentColor;
  border-inline-end: 1px solid currentColor;
  background: linear-gradient(to top right, transparent 44%, currentColor 45%, currentColor 55%, transparent 56%);
}

.empty-state, .not-found {
  padding: clamp(1.5rem, 5vw, 3rem);
  border: 1px solid var(--rule);
  background: var(--sheet);
  text-align: center;
}

.empty-state h2, .not-found h1 { font-size: 1.25rem; }
.empty-state p, .not-found p { margin-block-start: .375rem; color: var(--muted); }

.site-footer {
  border-block-start: 1px solid var(--rule);
  padding-block: 1.5rem 2rem;
  color: var(--muted);
  font-size: .8125rem;
  overflow-wrap: anywhere;
}

.site-footer p + p { margin-block-start: .5rem; }

@media (min-width: 40rem) {
  .project-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-inner {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }
  .search-row { grid-column: 1 / -1; }
  .filter-row { grid-column: 1; }
  .topic-chips { grid-column: 1 / -1; }
  .result-count { grid-column: 2; grid-row: 2; justify-self: end; }
}

@media (min-width: 62rem) {
  .project-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-height: 32rem) {
  html { scroll-padding-block-start: 16rem; }
}

@media (max-height: 31.999rem) {
  .filter-bar { position: static; }
}

.project-card h2.project-name {
  margin: 0;
}

.project-card .featured-badge {
  display: inline-block;
  align-self: flex-start;
  width: fit-content;
  padding: .1em .4em;
  border: 1px solid currentColor;
  border-radius: 2px;
  color: var(--cinnabar, #a9362b);
  font-size: .75em;
  font-weight: 700;
  letter-spacing: .08em;
  white-space: nowrap;
}

.project-card .project-status {
  display: inline-block;
  padding: .15em .55em;
  border: 1px solid var(--rule, #d8cbb8);
  border-radius: 999px;
  background: var(--paper, #f5efe3);
  color: var(--ink-muted, #65594a);
  font-size: .75em;
  white-space: nowrap;
}

.project-meta .project-category,
.project-meta .project-developer {
  color: var(--ink-muted, #65594a);
  font-size: .875em;
}

.project-meta .project-category {
  font-weight: 600;
}
