:root {
  --bg: #f7f9f8;
  --panel: #ffffff;
  --panel-soft: #edf3f0;
  --text: #1d2d2b;
  --muted: #566966;
  --line: #d3e1dc;
  --primary: #136f63;
  --primary-dark: #0e594f;
  --accent: #a05132;
  --code-bg: #182321;
  --code-text: #e5e7eb;
  --shadow: 0 12px 30px rgba(29, 65, 60, 0.08);
  --header-bg: rgba(255, 255, 255, 0.96);
  --primary-soft: #e6f1ed;
  --panel-subtle: #fbfdfc;
  --radius: 5px;
  --mono: Consolas, Menlo, Monaco, "Ubuntu Mono", "Courier New", monospace;
  --sans: "Noto Sans SC", "Microsoft YaHei", Arial, sans-serif;
}

:root[data-color-theme='dark'] {
  --bg: #192120;
  --panel: #222d2b;
  --panel-soft: #2b3936;
  --text: #eaf3ef;
  --muted: #a7b9b3;
  --line: #40534f;
  --primary: #6fd3ba;
  --primary-dark: #4ca88f;
  --accent: #e7a27d;
  --code-bg: #111917;
  --shadow: 0 16px 45px rgba(0, 0, 0, 0.28);
  --header-bg: rgba(25, 33, 32, 0.96);
  --primary-soft: #26463e;
  --panel-subtle: #202a28;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: var(--sans);
  line-height: 1.55;
}

a { color: inherit; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: clamp(1rem, 4vw, 3rem);
  width: min(100% - 3rem, 80rem);
  min-height: 4rem;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 4px;
  background: var(--primary);
  color: var(--panel);
  font-size: 0.88rem;
}

.top-nav {
  display: flex;
  align-items: center;
  gap: 1.4rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.top-nav a { text-decoration: none; }
.top-nav a:hover, .top-nav a[aria-current='page'] { color: var(--text); }
.top-nav a[aria-current='page'] { text-decoration: underline; text-decoration-color: var(--primary); text-decoration-thickness: 2px; text-underline-offset: 0.35em; }

.header-actions { display: flex; align-items: center; gap: 0.8rem; margin-left: auto; }
.main-site-link { color: var(--primary); font-size: 0.82rem; font-weight: 700; text-decoration: none; white-space: nowrap; }
.main-site-link:hover { text-decoration: underline; text-underline-offset: 0.3em; }
.theme-toggle {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.theme-toggle:hover { border-color: var(--primary); color: var(--primary); }

.page-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2rem);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 520px);
  gap: clamp(1rem, 4vw, 3rem);
  align-items: end;
  padding: clamp(1.25rem, 4vw, 3rem) 0 clamp(1rem, 3vw, 2rem);
}

.template-page {
  display: grid;
  gap: 1rem;
  max-width: 1100px;
  margin: 0 auto;
}

.eyebrow {
  margin: 0 0 0.45rem;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1.08;
  letter-spacing: 0;
}

.hero-copy, .template-summary {
  max-width: 720px;
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.hero-actions { display: grid; gap: 0.75rem; }
.hero-commands, .template-commands { display: flex; flex-wrap: wrap; align-items: center; gap: 0.65rem; }
.template-commands { justify-content: space-between; }
.template-commands > a:first-child { color: var(--primary); font-weight: 700; text-decoration: none; }
.template-commands > a:first-child:hover { text-decoration: underline; text-underline-offset: 0.25em; }

.search-box {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.search-box input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 0.9rem;
  color: var(--text);
  background: var(--panel);
  font: inherit;
  outline: none;
}

.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.ghost-button, .download-button, .open-link, .copy-button {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.55rem 0.85rem;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.download-button,
.download-button:visited,
.download-button:focus,
.open-link,
.open-link:visited,
.open-link:focus {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  outline: none;
}

.download-button:hover,
.download-button:focus-visible,
.open-link:hover,
.open-link:focus-visible {
  border-color: var(--primary-dark);
  background: var(--primary-dark);
  color: #fff;
}

.top-nav .download-button,
.top-nav .download-button:hover,
.top-nav .download-button:focus,
.top-nav .download-button:focus-visible,
.top-nav .download-button:visited {
  color: #fff;
}
.download-button[aria-disabled="true"],
.download-button[aria-disabled="true"]:hover {
  border-color: var(--primary-dark);
  background: var(--primary-dark);
  color: #fff;
  cursor: wait;
  opacity: 1;
}
.ghost-button:hover, .copy-button:hover { border-color: var(--primary); color: var(--primary); }

.layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 78px;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.sidebar-title {
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.category-list { display: grid; gap: 0.45rem; }

.category-button {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0.55rem 0.65rem;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.category-button:hover, .category-button.active {
  border-color: rgba(37, 99, 235, 0.25);
  background: var(--primary-soft);
  color: var(--primary);
}

.category-count { color: var(--muted); font-size: 0.85rem; }
.content-area {
  min-width: 0;
  height: auto;
  max-height: none;
  overflow: visible;
}

.result-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  color: var(--muted);
}

.active-filter {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  background: var(--panel);
  color: var(--text);
  font-size: 0.9rem;
}

.template-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 310px), 1fr));
  gap: 1rem;
  height: auto;
  max-height: none;
  overflow: visible;
}

.template-card, .template-panel {
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-header { display: grid; gap: 0.65rem; padding: 1rem 1rem 0.85rem; border-bottom: 1px solid var(--line); }
.template-card h2 { margin: 0; font-size: 1.2rem; line-height: 1.25; letter-spacing: 0; }
.card-body { display: grid; gap: 0.8rem; padding: 1rem; }

.tag-row { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}
.tag.category { background: var(--primary-soft); color: var(--primary); }

.meta-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.meta-grid.compact { grid-template-columns: 1fr; }
.meta-block { min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); padding: 0.65rem; background: var(--panel-subtle); }
.meta-label { margin-bottom: 0.25rem; color: var(--muted); font-size: 0.78rem; font-weight: 800; }
.meta-value { color: var(--text); font-size: 0.92rem; }

.code-shell {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--code-bg);
  box-shadow: var(--shadow);
}

.copy-button {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  z-index: 2;
  min-height: 32px;
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(17, 24, 39, 0.86);
  color: #fff;
  font-size: 0.82rem;
}

pre {
  margin: 0;
  overflow-x: auto;
  overflow-y: visible;
  padding: 1rem;
  padding-top: 3rem;
  color: var(--code-text);
  font-family: var(--mono);
  font-size: 0.9rem;
  line-height: 1.55;
  tab-size: 4;
}

code { font-family: inherit; }
.template-source {
  display: block;
  width: 100%;
  min-height: 420px;
  border: 0;
  outline: none;
  resize: none;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 3rem 1rem 1rem;
  background: transparent;
  color: var(--code-text);
  font-family: var(--mono);
  font-size: 0.9rem;
  line-height: 1.55;
  tab-size: 4;
  white-space: pre;
}

.usage-note {
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.usage-note h2,
.usage-note h3,
.usage-note p,
.usage-note ul {
  margin: 0;
}

.usage-note h2 { font-size: 1.25rem; }
.usage-note h3 { font-size: 1rem; }
.usage-note ul { padding-left: 1.25rem; }
.usage-note li + li { margin-top: 0.35rem; }
.usage-note code { font-family: var(--mono); }
.usage-note pre {
  margin: 0;
  padding: 1rem;
  border-radius: var(--radius);
  background: var(--code-bg);
  color: var(--code-text);
  overflow-x: auto;
}
.source-note { color: var(--muted); font-size: 0.92rem; }
.empty-state { border: 1px dashed var(--line); border-radius: var(--radius); padding: 2rem; background: var(--panel); color: var(--muted); text-align: center; }

@media (max-width: 980px) {
  .hero, .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .category-list { display: grid; overflow: visible; padding-bottom: 0; }
  .category-button { flex: initial; width: 100%; white-space: normal; }
  .meta-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .header-inner { width: min(100% - 2rem, 80rem); flex-wrap: wrap; gap: 0.2rem 1rem; padding: 0.6rem 0; }
  .top-nav { order: 3; width: 100%; gap: 1.2rem; }
  .header-actions { gap: 0.65rem; }
  .main-site-link { font-size: 0.76rem; }
  .result-bar { align-items: stretch; flex-direction: column; }
  .page-shell { padding: 1rem; }
  pre { font-size: 0.82rem; }
}

@media (max-width: 480px) {
  .header-actions { order: 2; width: 100%; justify-content: flex-end; }
}
