/*
 * Todoist Playbook — Gallery Styles
 *
 * Contrast audit (WCAG 2.2 AA, ≥4.5:1 for normal text):
 *   --muted (#5a6472) on --bg (#fafbfc):           ~6.8:1  PASS
 *   --muted (#5a6472) on --card-bg (#ffffff):      ~6.8:1  PASS
 *   --muted (#5a6472) on --bg-secondary (#f3f5f7): ~6.5:1  PASS
 *   --muted-light (#a0aec0): DECORATIVE ONLY (aria-hidden separators).
 *   White on header gradient stops (#d34244 -> #ae3b3d): ~4.9:1 to ~5.7:1 PASS
 *
 * Dark mode audit (≥4.5:1):
 *   --muted (#8b949e) on --bg (#0f1117):           ~5.1:1  PASS
 *   --muted (#8b949e) on --card-bg (#1c2128):      ~4.6:1  PASS
 *
 * Typography: Inter Variable is self-hosted under docs/fonts/ and downloaded
 * at build time by generate_gallery.py. The system font stack below serves as
 * a progressive-enhancement fallback when the font file is unavailable (e.g.
 * on first load before the service worker caches it, or if the build-time
 * download failed). The wrap rules (text-wrap: balance / pretty) apply
 * regardless and are progressively enhanced.
 */

/* Inter Variable — self-hosted, verified by SHA-256 in font-manifest.json */
@font-face {
  font-family: 'Inter Variable';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('fonts/Inter-Variable.woff2') format('woff2');
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --red: #d34244;
  --red-dark: #a83436;
  --red-light: #fff0ef;
  --red-lighter: #fef8f7;
  --bg: #fafbfc;
  --bg-secondary: #f3f5f7;
  --card-bg: #ffffff;
  --text: #1a202c;
  --text-secondary: #2d3748;
  --muted: #5a6472;
  --muted-light: #a0aec0;
  --border: #e2e8f0;
  --tag-bg: #edf2f7;
  --tag-bg-active: #fed7d7;
  --tag-text: #2d3748;
  --section-color: #6d28d9;
  --section-bg: #f5f3ff;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);
  --shadow-hover: 0 20px 25px rgba(0,0,0,0.12), 0 10px 10px rgba(0,0,0,0.04);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --header-bg: linear-gradient(135deg, #d34244 0%, #ae3b3d 100%);
  --focus-ring: 2px solid var(--red);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117;
    --bg-secondary: #161b22;
    --card-bg: #1c2128;
    --text: #e6edf3;
    --text-secondary: #c9d1d9;
    --muted: #8b949e;
    --muted-light: #484f58;
    --border: #30363d;
    --tag-bg: #21262d;
    --tag-bg-active: #4a1f20;
    --tag-text: #c9d1d9;
    --red-light: #2d1b1c;
    --red-lighter: #1e1314;
    --section-bg: #1e1b2e;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
    --shadow-hover: 0 20px 25px rgba(0,0,0,0.5);
  }
}

[data-theme="dark"] {
  --bg: #0f1117;
  --bg-secondary: #161b22;
  --card-bg: #1c2128;
  --text: #e6edf3;
  --text-secondary: #c9d1d9;
  --muted: #8b949e;
  --muted-light: #484f58;
  --border: #30363d;
  --tag-bg: #21262d;
  --tag-bg-active: #4a1f20;
  --tag-text: #c9d1d9;
  --red-light: #2d1b1c;
  --red-lighter: #1e1314;
  --section-bg: #1e1b2e;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
  --shadow-hover: 0 20px 25px rgba(0,0,0,0.5);
}

.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  z-index: 9999;
  padding: 0.6rem 1.2rem;
  background: var(--card-bg);
  color: var(--red);
  font-weight: 700;
  border: 2px solid var(--red);
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 0.9rem;
}
.skip-link:focus {
  top: 1rem;
  outline: 3px solid var(--red);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body {
  font-family: 'Inter Variable', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
  min-height: 100vh;
  letter-spacing: -0.01em;
  font-feature-settings: 'cv11' 1, 'ss01' 1;
}

main:focus { outline: none; }

.site-header {
  background: var(--header-bg);
  color: #fff;
  padding: 1.5rem 1rem 1.25rem;
  text-align: center;
  box-shadow: 0 2px 8px rgba(211, 66, 68, 0.15);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.site-header h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.2;
  text-wrap: balance;
}
.site-header p {
  margin-top: 0.5rem;
  opacity: 0.95;
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.header-controls {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  gap: 0.5rem;
}
.theme-toggle {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.35);
  color: #fff;
  border-radius: 6px;
  width: 2.25rem;
  height: 2.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition);
}
.theme-toggle:hover { background: rgba(255,255,255,0.28); }
.theme-toggle:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(0,0,0,0.25);
}
.theme-toggle svg { width: 1.1rem; height: 1.1rem; stroke: currentColor; fill: none; stroke-width: 2; }

.header-github-link {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.35);
  color: #fff;
  border-radius: 6px;
  width: 2.25rem;
  height: 2.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: background var(--transition);
}
.header-github-link:hover { background: rgba(255,255,255,0.28); }
.header-github-link:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(0,0,0,0.25);
}
.header-github-link svg { width: 1.1rem; height: 1.1rem; fill: currentColor; }

.header-stat {
  margin-top: 0.35rem;
  font-size: 0.875rem;
  font-weight: 500;
  opacity: 0.8;
  letter-spacing: 0.01em;
  min-height: 1.25rem;
}

.search-bar {
  margin: 1rem auto 0;
  max-width: 520px;
  position: relative;
}
.search-bar input[type="search"] {
  width: 100%;
  padding: 0.75rem 3rem 0.75rem 1.25rem;
  border: none;
  border-radius: 999px;
  font-size: 0.95rem;
  background: rgba(255,255,255,0.22);
  color: #fff;
  transition: background var(--transition);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
input[type="search"]::-webkit-search-cancel-button { display: none; }
.search-bar input[type="search"]::placeholder {
  color: #ffffff;
  opacity: 0.95;
  font-weight: 500;
}
.search-bar input[type="search"]:focus {
  background: rgba(255,255,255,0.32);
  outline: 2px solid #ffffff;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(0,0,0,0.25);
}
.search-clear {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.85);
  line-height: 1;
  padding: 0.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.search-clear:hover { color: #fff; }
.search-clear:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
  border-radius: 4px;
}
.search-clear svg { width: 1rem; height: 1rem; stroke: currentColor; fill: none; stroke-width: 2.25; }

.search-summary {
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
  font-weight: 500;
}
.search-summary strong { color: var(--text-secondary); font-weight: 700; }

.no-results {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}
.no-results .no-results-icon { font-size: 2.8rem; margin-bottom: 1rem; }
.no-results p {
  font-size: 0.95rem;
  line-height: 1.6;
  max-width: 400px;
  margin: 0 auto 1.5rem;
}
.no-results-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  transition: background var(--transition);
}
.btn-secondary:hover { background: var(--tag-bg); }
.btn-secondary:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

.breadcrumb {
  display: none;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 0.9rem 1.5rem;
}
@media (prefers-reduced-motion: no-preference) {
  .breadcrumb { animation: slideDown 0.25s ease-out; }
}
@keyframes slideDown {
  from { transform: translateY(-8px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.breadcrumb button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--red);
  font-size: 0.9rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0;
  font-family: inherit;
}
.breadcrumb button:hover { color: var(--red-dark); text-decoration: underline; }
.breadcrumb button:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}
.breadcrumb .crumb-sep { color: var(--muted-light); margin: 0 0.5rem; }
.breadcrumb .crumb-current { color: var(--text-secondary); font-weight: 700; font-size: 0.9rem; }
.breadcrumb svg { width: 0.9rem; height: 0.9rem; stroke: currentColor; fill: none; stroke-width: 2.25; }

.container { max-width: 1100px; margin: 0 auto; padding: 2rem 1.25rem; }

.intro {
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
  font-weight: 500;
}
.intro strong { color: var(--text-secondary); font-weight: 600; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.sort-row { display: flex; align-items: center; gap: 0.5rem; }
.sort-row label { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.sort-row select {
  font-size: 0.85rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}
.sort-row select:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 1.5rem;
}
.filter-bar-label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  margin-right: 0.25rem;
}
.tag-filter {
  background: var(--tag-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  font-size: 0.78rem;
  color: var(--tag-text);
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition), border-color var(--transition);
}
.tag-filter:hover { background: var(--red-light); border-color: var(--red); }
.tag-filter[aria-pressed="true"] {
  background: var(--tag-bg-active);
  border-color: var(--red);
  color: var(--red-dark);
  font-weight: 700;
}
.tag-filter:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }

.recent-rail { margin-bottom: 2.5rem; }
/* Shared heading style used by both "Template Spotlight" and "Recently updated"
   so they always render with identical font, weight, size and colour. */
.section-heading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  letter-spacing: 0.01em;
}
.section-heading svg { width: 1.1rem; height: 1.1rem; stroke: var(--red); fill: none; stroke-width: 2; flex-shrink: 0; }
.recent-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}
@media (max-width: 900px) {
  .recent-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 540px) {
  .recent-grid { grid-template-columns: 1fr; }
}
.rail-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  cursor: pointer;
  transition: box-shadow var(--transition), border-color var(--transition), transform var(--transition);
  text-align: left;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
}
@media (prefers-reduced-motion: no-preference) {
  .rail-card:hover { transform: translateY(-2px); }
}
.rail-card:hover { box-shadow: var(--shadow-md); border-color: var(--red-light); }
.rail-card:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }
.rail-card-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--red);
  background: var(--red-light);
  border-radius: 4px;
  padding: 0.2rem 0.55rem;
  margin-bottom: 0.4rem;
  align-self: flex-start;
}
.rail-card-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-secondary);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.rail-card-desc {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
  margin-top: 0.3rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex-grow: 1;
}
.rail-card-meta { font-size: 0.72rem; color: var(--muted); margin-top: 0.5rem; }

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
}

.cat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
  transition: box-shadow var(--transition), border-color var(--transition), transform var(--transition);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  color: inherit;
  text-decoration: none;
}
@media (prefers-reduced-motion: no-preference) {
  .cat-card:hover { transform: translateY(-4px); }
}
.cat-card:hover { box-shadow: var(--shadow-md); border-color: var(--red-light); }
.cat-card:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 3px;
}
.cat-icon-wrap {
  width: 3rem;
  height: 3rem;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  margin-bottom: 0.25rem;
  /* Per-category accent set inline via --cat-accent; default is red */
  background: var(--cat-accent, var(--red-light));
  color: var(--text-secondary);
}
.cat-title {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-secondary);
  text-wrap: balance;
}
.cat-count { font-size: 0.85rem; color: var(--red); font-weight: 700; }
.cat-previews {
  list-style: none;
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-top: 0.25rem;
}
.cat-previews li::before { content: "◆ "; opacity: 0.4; color: var(--red); }
.cat-more { font-size: 0.8rem; color: var(--muted); font-style: italic; margin-top: 0.25rem; }
.cat-arrow {
  margin-top: auto;
  font-size: 0.85rem;
  color: var(--red);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  transition: transform var(--transition);
}
.cat-arrow svg { width: 0.9rem; height: 0.9rem; stroke: currentColor; fill: none; stroke-width: 2.25; }
@media (prefers-reduced-motion: no-preference) {
  .cat-card:hover .cat-arrow { transform: translateX(3px); }
}

.cat-detail-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 2px solid var(--border);
}
.cat-detail-icon-wrap {
  width: 3rem;
  height: 3rem;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  background: var(--cat-accent, var(--red-light));
}
.cat-detail-title {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--text-secondary);
  text-wrap: balance;
}
.cat-detail-count {
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: 0.2rem;
  font-weight: 500;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1.5rem;
}

.tpl-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: box-shadow var(--transition), border-color var(--transition), transform var(--transition);
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  padding: 0;
}
@media (prefers-reduced-motion: no-preference) {
  .tpl-card:hover { transform: translateY(-2px); }
}
.tpl-card:hover { box-shadow: var(--shadow-md); border-color: var(--red-light); }
.tpl-card:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 3px;
}
.tpl-card-main {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
}
.tpl-card-copy {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1.25rem;
  min-width: 0;
}
.tpl-card-header { display: flex; flex-direction: column; gap: 0.45rem; }
.tpl-type-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--red);
  background: var(--red-light);
  border-radius: 6px;
  padding: 0.25rem 0.65rem;
  margin-bottom: 0.5rem;
}
.tpl-title {
  font-size: 1.1rem;
  font-weight: 800;
  line-height: 1.3;
  color: var(--text-secondary);
  text-wrap: balance;
  margin: 0;
}
.tpl-desc {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.5;
  text-wrap: pretty;
}
.tpl-card-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
}
.tpl-section-label {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.tpl-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tag {
  padding: 0.2rem 0.65rem;
  background: var(--tag-bg);
  border-radius: 6px;
  font-size: 0.75rem;
  color: var(--tag-text);
  font-weight: 500;
  border: 1px solid transparent;
}
.tpl-fact-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}
.tpl-fact {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-secondary);
}
.tpl-fact-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.tpl-fact-value {
  font-size: 0.88rem;
  line-height: 1.35;
  color: var(--text-secondary);
}
.tpl-card-aside {
  border-left: 1px solid var(--border);
  background: var(--bg-secondary);
  padding: 1.25rem;
  display: flex;
}
.tpl-card-section-preview {
  padding-top: 0;
  border-top: none;
  width: 100%;
}
.tpl-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.tpl-preview-count {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  white-space: nowrap;
}
.tpl-preview {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  font-size: 0.8rem;
  background: var(--card-bg);
}
.preview-row {
  padding: 0.35rem 0.75rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.preview-row:last-child { border-bottom: none; }
.preview-row.section {
  font-weight: 700;
  background: var(--section-bg);
  color: var(--section-color);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.preview-row.task { padding-left: 1.5rem; font-weight: 500; }
.preview-row.task::before { content: "▪ "; opacity: 0.4; margin-right: 0.3rem; }
.preview-more {
  padding: 0.35rem 0.75rem;
  color: var(--muted);
  font-size: 0.75rem;
  background: var(--section-bg);
  font-weight: 500;
}
.tpl-inputs { font-size: 0.85rem; }
.input-chip {
  display: inline-block;
  background: var(--tag-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.65rem;
  margin: 0.15rem 0.2rem 0.15rem 0;
  font-size: 0.75rem;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  color: var(--text);
  font-weight: 500;
}
.tpl-card-footer {
  padding: 0.85rem 1.25rem;
  margin-top: auto;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--bg-secondary);
  flex-wrap: wrap;
}
.tpl-meta { font-size: 0.75rem; color: var(--muted); font-weight: 500; }
.download-caption {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 500;
}
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.5rem 1rem;
  background: var(--red);
  color: #fff;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  white-space: nowrap;
  user-select: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
@media (prefers-reduced-motion: no-preference) {
  .btn-primary:hover { transform: translateY(-1px); }
}
.btn-primary:hover { background: var(--red-dark); box-shadow: 0 4px 12px rgba(211, 66, 68, 0.2); }
.btn-primary:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }
.btn-primary svg { width: 0.9rem; height: 0.9rem; stroke: currentColor; fill: none; stroke-width: 2.25; }
.btn-secondary svg { width: 0.9rem; height: 0.9rem; }
.btn-action-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2rem;
}

.tag-toggle:hover { background: var(--red-light); border-color: var(--red); }
.tag-toggle[aria-pressed="true"] {
  background: var(--tag-bg-active);
  border-color: var(--red);
  color: var(--red-dark);
  font-weight: 700;
}
.tag-toggle:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }

.spotlight-section { margin-bottom: 2.5rem; }
/* .spotlight-heading typography comes from the shared .section-heading class */
.spotlight-card {
  background: linear-gradient(135deg, var(--red-lighter) 0%, var(--card-bg) 85%);
  border: 2px solid var(--red);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 20px rgba(211, 66, 68, 0.12);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0;
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  width: 100%;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  padding: 0;
  transition: box-shadow var(--transition);
}
.spotlight-card:hover { box-shadow: 0 12px 28px rgba(211, 66, 68, 0.18); }
.spotlight-card:focus-visible { outline: var(--focus-ring); outline-offset: 3px; }
.spotlight-body { padding: 1.5rem 1.75rem; }
.spotlight-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #ffffff;
  background: var(--red);
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  margin-bottom: 0.75rem;
}
.spotlight-name {
  font-size: 1.5rem;
  font-weight: 900;
  margin-bottom: 0.4rem;
  line-height: 1.2;
  color: var(--text-secondary);
  text-wrap: balance;
}
.spotlight-desc {
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 1rem;
  line-height: 1.6;
  text-wrap: pretty;
}
.spotlight-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }
.spotlight-tags .tag {
  background: var(--tag-bg);
  border-color: var(--border);
  border-radius: 9999px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.spotlight-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1rem;
  font-weight: 500;
}
.spotlight-stats > span:not(.sep) {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  line-height: 1;
}
.spotlight-stats > span:not(.sep) svg {
  width: 0.9rem;
  height: 0.9rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  flex-shrink: 0;
  display: block;
}
.spotlight-footer { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.spotlight-footer .btn-primary {
  padding: 0.625rem 1.125rem;
  font-size: 0.95rem;
  border-radius: 8px;
  min-height: 2.75rem;
}
.spotlight-footer .btn-primary svg { width: 1rem; height: 1rem; }
.spotlight-meta { font-size: 0.78rem; color: var(--muted); font-weight: 500; }
.spotlight-preview {
  border-left: 2px solid var(--border);
  min-width: 280px;
  max-width: 320px;
  font-size: 0.8rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: rgba(255,255,255,0.3);
}
[data-theme="dark"] .spotlight-preview { background: rgba(0,0,0,0.2); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .spotlight-preview { background: rgba(0,0,0,0.2); }
}
.spotlight-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.75rem;
  border-bottom: 2px solid var(--border);
  background: var(--section-bg);
  flex-shrink: 0;
}
.spotlight-preview-label {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--section-color);
}
.spotlight-preview-count {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--tag-bg);
  border-radius: 10px;
  padding: 0.1rem 0.5rem;
}
.spotlight-preview .preview-row { border-bottom: 1px solid var(--border); padding: 0.4rem 0.75rem; }
.spotlight-preview .preview-row:last-child { border-bottom: none; }
.spotlight-preview .preview-row.section { background: var(--section-bg); }
.spotlight-preview .preview-row.task {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  padding: 0.55rem 0.75rem;
}
.spotlight-preview .preview-row.task::before { content: none; }
.preview-task-icon {
  flex-shrink: 0;
  width: 1rem;
  height: 1rem;
  color: var(--muted-light);
  margin-top: 0.1rem;
}
.preview-task-icon svg {
  width: 1rem;
  height: 1rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  display: block;
}
.preview-task-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}
@media (max-width: 680px) {
  .spotlight-card { grid-template-columns: 1fr; }
  .spotlight-preview { border-left: none; border-top: 2px solid var(--border); max-width: 100%; min-width: 0; }
}

@media (max-width: 640px) {
  .site-header { padding: 1.5rem 1rem 1.25rem; padding-top: 4rem; }
  .site-header h1 { font-size: 1.5rem; }
  .site-header p { font-size: 0.95rem; }
  .container { padding: 1.5rem 1rem; }
  .category-grid { grid-template-columns: 1fr; gap: 1.25rem; }
  .template-grid { grid-template-columns: 1fr; gap: 1.25rem; }
  .cat-detail-header { flex-direction: column; align-items: flex-start; }
  .header-controls { top: 0.5rem; right: 0.5rem; }
  .tpl-card-main { grid-template-columns: 1fr; }
  .tpl-card-aside {
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .tpl-preview-head { align-items: flex-start; flex-direction: column; }
  .tpl-fact-grid { grid-template-columns: 1fr; }
}
@media (min-width: 641px) and (max-width: 960px) {
  .template-grid { grid-template-columns: repeat(2, 1fr); }
  .tpl-card-main { grid-template-columns: 1fr; }
  .tpl-card-aside {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  z-index: 1000;
  align-items: flex-start;
  justify-content: center;
  padding: 2.5rem 1rem;
  overflow-y: auto;
}
@media (prefers-reduced-motion: no-preference) {
  .modal-backdrop { animation: modalFade 0.18s ease-out; }
}
@keyframes modalFade { from { opacity: 0; } to { opacity: 1; } }
.modal-backdrop.open { display: flex; }
.modal-dialog {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-hover);
  max-width: 860px;
  width: 100%;
  max-height: calc(100vh - 5rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}
@media (prefers-reduced-motion: no-preference) {
  .modal-dialog { animation: modalRise 0.22s cubic-bezier(0.4,0,0.2,1); }
}
@keyframes modalRise {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.modal-header {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-wrap: wrap;
}
.modal-title-block { flex: 1 1 240px; min-width: 0; order: 1; }
.modal-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-secondary);
  line-height: 1.25;
  text-wrap: balance;
}
.modal-subtitle {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.2rem;
  font-weight: 500;
}
.modal-actions { display: flex; align-items: flex-start; gap: 0.75rem; flex-wrap: wrap; width: 100%; order: 3; }
.modal-action-group { display: flex; flex-direction: column; gap: 0.3rem; align-items: flex-start; }
.modal-action-buttons { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.modal-close {
  background: none;
  border: 1px solid var(--border);
  width: 2rem;
  height: 2rem;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  transition: background var(--transition), color var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  order: 2;
  flex-shrink: 0;
}
.modal-close svg { width: 0.95rem; height: 0.95rem; stroke: currentColor; fill: none; stroke-width: 2.25; }
.modal-close:hover { background: var(--bg-secondary); color: var(--text); }
.modal-close:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }
.modal-body {
  padding: 1.5rem 1.75rem 2rem;
  overflow-y: auto;
  flex: 1 1 auto;
  color: var(--text);
  line-height: 1.65;
}
.modal-body.empty {
  text-align: center;
  color: var(--muted);
  font-style: italic;
  padding: 3rem 1.5rem;
}
.modal-body h1, .modal-body h2, .modal-body h3,
.modal-body h4, .modal-body h5, .modal-body h6 {
  color: var(--text-secondary);
  font-weight: 800;
  line-height: 1.25;
  margin: 1.5rem 0 0.6rem;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
.modal-body h1 { font-size: 1.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.4rem; }
.modal-body h2 { font-size: 1.2rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3rem; }
.modal-body h3 { font-size: 1.05rem; }
.modal-body h4 { font-size: 0.95rem; }
.modal-body p, .modal-body ul, .modal-body ol,
.modal-body blockquote, .modal-body pre, .modal-body table { margin: 0.75rem 0; }
.modal-body p { text-wrap: pretty; }
.modal-body ul, .modal-body ol { padding-left: 1.4rem; }
.modal-body li { margin: 0.2rem 0; }
.modal-body a { color: var(--red); text-decoration: none; font-weight: 600; }
.modal-body a:hover { text-decoration: underline; color: var(--red-dark); }
.modal-body a:focus-visible { outline: var(--focus-ring); outline-offset: 2px; border-radius: 2px; }
.modal-body code {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 0.85em;
}
.modal-body pre {
  background: #1a202c;
  color: #f7fafc;
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.5;
}
.modal-body pre code { background: none; border: none; padding: 0; color: inherit; font-size: inherit; }
.modal-body blockquote {
  border-left: 3px solid var(--red);
  padding: 0.25rem 0 0.25rem 1rem;
  color: var(--muted);
  background: var(--red-lighter);
  border-radius: 0 6px 6px 0;
}
.modal-body table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
.modal-body th, .modal-body td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
}
.modal-body th { background: var(--bg-secondary); font-weight: 700; }
.modal-body img { max-width: 100%; border-radius: 6px; }
.modal-body hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
@media (max-width: 640px) {
  .modal-backdrop { padding: 0.75rem; }
  .modal-dialog { max-height: calc(100vh - 1.5rem); }
  .modal-header { padding: 1rem 1.1rem; }
  .modal-body { padding: 1.1rem 1.1rem 1.5rem; }
}

.site-footer {
  margin-top: 4rem;
  border-top: 1px solid var(--border);
  padding: 2rem 1rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--bg-secondary);
}
.site-footer .footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem 1.75rem;
  margin-bottom: 1rem;
}
.site-footer a {
  color: var(--red);
  text-decoration: none;
  font-weight: 700;
}
.site-footer a:hover { text-decoration: underline; color: var(--red-dark); }
.site-footer a:focus-visible { outline: var(--focus-ring); outline-offset: 2px; border-radius: 2px; }
.site-footer .build-stamp {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 0.5rem;
  font-variant-numeric: tabular-nums;
}

/* -- Faceted search controls --------------------------------------------- */

.search-controls {
  margin: 0.75rem auto 0;
  max-width: 520px;
  padding: 0 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}
.search-controls[hidden] { display: none; }

.segmented {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 999px;
  padding: 0.2rem 0.4rem 0.2rem 0.7rem;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.segmented-label {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.92);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-right: 0.25rem;
}
.seg-btn {
  background: transparent;
  border: none;
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.92);
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition), color var(--transition);
}
.seg-btn:hover { background: rgba(255,255,255,0.22); color: #fff; }
.seg-btn[aria-pressed="true"] {
  background: #fff;
  color: var(--red);
  font-weight: 700;
}
.seg-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* Match-tags segmented control sits inside filter-bar (light context) */
.filter-bar .segmented {
  background: var(--card-bg);
  border-color: var(--border);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  margin-left: auto;
}
.filter-bar .segmented-label { color: var(--muted); }
.filter-bar .seg-btn { color: var(--muted); }
.filter-bar .seg-btn:hover {
  background: var(--red-light);
  color: var(--red-dark);
}
.filter-bar .seg-btn[aria-pressed="true"] {
  background: var(--red);
  color: #fff;
}
.filter-bar .seg-btn:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}
.filter-bar-help {
  width: 100%;
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.25rem;
  font-style: italic;
}

/* -- Tag cloud on home --------------------------------------------------- */
.tag-cloud {
  margin: 0 0 2.5rem;
  padding: 1.25rem 1.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.tag-cloud-heading {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.85rem;
}
.tag-cloud-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.tag-cloud-chip {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.82rem;
  color: var(--tag-text);
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.tag-cloud-chip:hover {
  background: var(--red-light);
  border-color: var(--red);
  color: var(--red-dark);
}
.tag-cloud-chip:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }
.tag-cloud-count {
  background: var(--bg-secondary);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  transition: background var(--transition), color var(--transition);
}
.tag-cloud-chip:hover .tag-cloud-count {
  background: var(--red);
  color: #fff;
}

/* -- Card tag pills (interactive) ---------------------------------------- */
.tag-toggle {
  background: var(--tag-bg);
  border: 1px solid transparent;
  color: var(--tag-text);
  font-family: inherit;
  font-weight: 500;
  font-size: 0.75rem;
  padding: 0.2rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.tag-toggle:hover {
  background: var(--red-light);
  border-color: var(--red);
  color: var(--red-dark);
}
.tag-toggle[aria-pressed="true"] {
  background: var(--tag-bg-active);
  border-color: var(--red);
  color: var(--red-dark);
  font-weight: 700;
}
.tag-toggle:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }

/* -- Search summary mode-note -------------------------------------------- */
.search-summary-note {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  font-style: italic;
}

@media (max-width: 600px) {
  .search-controls { padding: 0 1rem; }
  .search-controls .segmented { width: 100%; justify-content: center; }
  .filter-bar .segmented { margin-left: 0; width: 100%; justify-content: center; }
}
