/* =========================================
   HTML Anything · Template Explorer
   ========================================= */

/* ---------- Design Tokens ---------- */
:root {
  /* Paper / Ink */
  --paper: #f5f4ed;
  --paper-alt: #efeee5;
  --ink: #1f1d18;
  --ink-soft: #4a4740;
  --ink-muted: #6b665b;
  --ink-subtle: #9a968b;
  --ink-border: #d4d1c5;
  --ink-border-soft: #e8e6dc;

  /* Accent: Ink Blue */
  --accent: #1B365D;
  --accent-soft: #3a5a8e;
  --accent-bg: #e8ecf4;
  --accent-hover: #14284a;

  /* Signal colors */
  --success: #3d6b3d;
  --warn: #8a5a00;
  --danger: #8a2a2a;
  --gold: #b8860b;

  /* Typography */
  --font-serif: "Source Serif Pro", "Noto Serif SC", Georgia, "Times New Roman", serif;
  --font-sans: "Inter", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --font-display: "Playfair Display", "Source Serif Pro", "Noto Serif SC", Georgia, serif;

  /* Spacing: 8px baseline grid */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;
  --s-9: 96px;

  /* Radii */
  --r-sm: 2px;
  --r-md: 4px;
  --r-lg: 6px;

  /* Shadows (subtle hairline only) */
  --sh-1: 0 1px 0 rgba(31, 29, 24, 0.04);
  --sh-2: 0 2px 8px rgba(31, 29, 24, 0.06);
  --sh-3: 0 8px 32px rgba(31, 29, 24, 0.12);

  /* Layout */
  --container-w: 1280px;
  --sidebar-w: 260px;
  --sidebar-w-lg: 300px;

  /* Motion */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur-fast: 120ms;
  --dur: 200ms;
  --dur-slow: 400ms;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-serif);
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.01em;
  margin: 0;
  line-height: 1.2;
}
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
a { color: var(--accent); text-decoration: none; transition: color var(--dur-fast) var(--ease); }
a:hover { color: var(--accent-hover); text-decoration: underline; }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }
img, svg { display: block; max-width: 100%; }
::selection { background: var(--accent-bg); color: var(--ink); }

/* ---------- Utility ---------- */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}
.container { max-width: var(--container-w); margin: 0 auto; padding: 0 var(--s-5); }
kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 6px;
  background: var(--paper-alt);
  border: 1px solid var(--ink-border);
  border-radius: var(--r-md);
  color: var(--ink-soft);
}

/* ============================================
   HEADER
   ============================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(245, 244, 237, 0.88);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--ink-border);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  gap: var(--s-5);
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  color: var(--ink);
  text-decoration: none;
}
.brand:hover { text-decoration: none; color: var(--ink); }
.brand-mark {
  font-size: 28px;
  line-height: 1;
  color: var(--accent);
  font-family: var(--font-serif);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-family: var(--font-serif); font-size: 17px; font-weight: 600; }
.brand-text small { font-size: 11px; color: var(--ink-muted); letter-spacing: 0.02em; }

.primary-nav {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13.5px;
  color: var(--ink-soft);
  border-radius: var(--r-md);
  transition: all var(--dur-fast) var(--ease);
}
.nav-link:hover { background: var(--paper-alt); color: var(--ink); text-decoration: none; }
.nav-link.is-active { background: var(--accent); color: var(--paper); }
.nav-link.is-active:hover { background: var(--accent-hover); }
.nav-fav .fav-count {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  background: var(--accent-bg);
  color: var(--accent);
  border-radius: 999px;
}
.nav-link.is-active .fav-count {
  background: rgba(255, 255, 255, 0.2);
  color: var(--paper);
}

/* ============================================
   HERO
   ============================================ */
.hero {
  padding: var(--s-8) 0 var(--s-7);
  border-bottom: 1px solid var(--ink-border);
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at top left, rgba(27, 54, 93, 0.04), transparent 50%),
    radial-gradient(ellipse at bottom right, rgba(27, 54, 93, 0.03), transparent 50%);
  pointer-events: none;
}
.hero-inner { position: relative; max-width: 860px; }

.hero-meta {
  display: inline-flex;
  align-items: center;
  gap: var(--s-3);
  font-size: 12.5px;
  font-family: var(--font-mono);
  color: var(--ink-muted);
  margin-bottom: var(--s-5);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.hero-dot { opacity: 0.5; }
.badge {
  display: inline-block;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 999px;
}

.hero-title {
  font-family: var(--font-serif);
  font-size: clamp(32px, 5vw, 54px);
  font-weight: 500;
  line-height: 1.15;
  margin-bottom: var(--s-4);
}
.hero-accent {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  color: var(--accent);
  border-bottom: 3px solid var(--accent);
  padding-bottom: 2px;
}
.hero-subtitle {
  font-family: var(--font-serif);
  font-size: clamp(15px, 1.3vw, 18px);
  color: var(--ink-soft);
  line-height: 1.6;
  margin-bottom: var(--s-6);
  max-width: 640px;
}

/* Search */
.hero-search { margin-bottom: var(--s-6); }
.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: #fff;
  border: 1px solid var(--ink-border);
  border-radius: var(--r-lg);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  box-shadow: var(--sh-1);
}
.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(27, 54, 93, 0.08), var(--sh-1);
}
.search-icon {
  padding: 0 var(--s-4);
  font-size: 18px;
  color: var(--ink-muted);
  line-height: 1;
}
.search-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  padding: var(--s-4) 0;
  font-size: 15px;
  font-family: var(--font-sans);
}
.search-input::placeholder { color: var(--ink-subtle); }
.search-clear {
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font-size: 22px;
  padding: 0 var(--s-4);
  line-height: 1;
  transition: color var(--dur-fast) var(--ease);
}
.search-clear:hover { color: var(--ink); }
.search-kbd {
  margin-right: var(--s-3);
  font-size: 12px;
}

/* Stats */
.hero-stats {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: var(--s-2);
  max-width: 620px;
  padding-top: var(--s-5);
  border-top: 1px solid var(--ink-border-soft);
}
.stat { text-align: left; }
.stat strong {
  display: block;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 400;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 4px;
}
.stat span { font-size: 11.5px; color: var(--ink-muted); letter-spacing: 0.02em; }

/* ============================================
   MAIN LAYOUT
   ============================================ */
.main {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: var(--s-7);
  padding-top: var(--s-7);
  padding-bottom: var(--s-8);
  align-items: start;
}

/* ============================================
   FILTERS SIDEBAR
   ============================================ */
.filters {
  position: sticky;
  top: 88px;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  padding-right: var(--s-2);
  scrollbar-width: thin;
}
.filters::-webkit-scrollbar { width: 6px; }
.filters::-webkit-scrollbar-thumb {
  background: var(--ink-border);
  border-radius: 3px;
}

.filters-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--s-4);
  padding-bottom: var(--s-3);
  border-bottom: 1px solid var(--ink-border);
}
.filters-title {
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 600;
  margin: 0;
}
.filters-reset {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 12.5px;
  padding: 0;
  transition: color var(--dur-fast) var(--ease);
}
.filters-reset:hover { color: var(--accent-hover); text-decoration: underline; }

.filter-group {
  margin-bottom: var(--s-5);
}
.filter-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s-3);
}
.filter-group h3 {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  margin: 0;
}
.filter-count {
  font-size: 11px;
  color: var(--accent);
  font-weight: 500;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tag-grid { max-height: 260px; overflow-y: auto; padding-right: 4px; }
.tag-grid::-webkit-scrollbar { width: 4px; }
.tag-grid::-webkit-scrollbar-thumb { background: var(--ink-border); border-radius: 2px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 11px;
  font-size: 12.5px;
  color: var(--ink-soft);
  background: var(--paper-alt);
  border: 1px solid var(--ink-border);
  border-radius: 999px;
  transition: all var(--dur-fast) var(--ease);
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover {
  color: var(--ink);
  border-color: var(--accent);
  background: #fff;
}
.chip.is-active {
  background: var(--accent);
  color: var(--paper);
  border-color: var(--accent);
}
.chip-count {
  font-size: 10.5px;
  opacity: 0.7;
  margin-left: 2px;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
  user-select: none;
}
.checkbox input { position: absolute; opacity: 0; pointer-events: none; }
.checkbox-box {
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--ink-border);
  border-radius: var(--r-sm);
  background: #fff;
  transition: all var(--dur-fast) var(--ease);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.checkbox input:checked ~ .checkbox-box {
  background: var(--accent);
  border-color: var(--accent);
}
.checkbox input:checked ~ .checkbox-box::after {
  content: "";
  width: 4px;
  height: 8px;
  border: solid var(--paper);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
  margin-top: -2px;
}
.checkbox input:focus-visible ~ .checkbox-box {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============================================
   CONTENT — RESULT HEADER
   ============================================ */
.result-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-5);
  margin-bottom: var(--s-5);
  padding-bottom: var(--s-4);
  border-bottom: 1px solid var(--ink-border);
}
.result-info { flex: 1; min-width: 0; }
.result-count {
  font-family: var(--font-serif);
  font-size: 16px;
  color: var(--ink);
}
.result-count strong { font-size: 20px; color: var(--accent); font-weight: 600; }
.result-subcount { color: var(--ink-muted); font-size: 13px; margin-left: 6px; }

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: var(--s-3);
}
.active-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 3px 10px;
  font-size: 11.5px;
  background: var(--accent-bg);
  color: var(--accent);
  border-radius: var(--r-md);
}
.active-filter-chip button {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity var(--dur-fast) var(--ease);
}
.active-filter-chip button:hover { opacity: 1; }

.result-tools {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  flex-shrink: 0;
}
.sort-label {
  font-size: 12.5px;
  color: var(--ink-muted);
}
.sort-select {
  padding: 6px 28px 6px 10px;
  font-size: 13px;
  background: #fff;
  border: 1px solid var(--ink-border);
  border-radius: var(--r-md);
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%234a4740' d='M5 6L0 0h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 8px;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color var(--dur-fast) var(--ease);
}
.sort-select:hover { border-color: var(--accent); }
.sort-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(27, 54, 93, 0.08); }

.view-toggle {
  display: inline-flex;
  background: var(--paper-alt);
  border: 1px solid var(--ink-border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.view-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--ink-muted);
  transition: all var(--dur-fast) var(--ease);
}
.view-btn svg { fill: currentColor; pointer-events: none; }
.view-btn:hover { color: var(--ink-soft); }
.view-btn.is-active {
  background: #fff;
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

/* ============================================
   CONTENT — TEMPLATE GRID
   ============================================ */
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--s-4);
}

/* List view */
.template-grid.is-list {
  grid-template-columns: 1fr;
  gap: var(--s-3);
}
.template-grid.is-list .template-card {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: var(--s-4);
  padding: var(--s-4);
}
.template-grid.is-list .card-preview { min-height: 56px; height: 56px; margin-bottom: 0; }
.template-grid.is-list .card-title-row { margin-bottom: var(--s-2); }
.template-grid.is-list .card-body { padding: 0; }
.template-grid.is-list .card-tags { margin-bottom: 0; }
.template-grid.is-list .card-description { display: none; }

/* Card */
.template-card {
  background: #fff;
  border: 1px solid var(--ink-border);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  cursor: pointer;
  position: relative;
  display: flex;
  flex-direction: column;
}
.template-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--sh-3);
}
.template-card.is-favorite::after {
  content: "★";
  position: absolute;
  top: 10px; right: 10px;
  width: 28px; height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  border: 1px solid var(--ink-border);
  border-radius: 50%;
  color: var(--gold);
  font-size: 13px;
  z-index: 2;
}

.card-preview {
  min-height: 140px;
  background: var(--preview-bg, linear-gradient(135deg, var(--paper-alt), #fff));
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--ink-border-soft);
  overflow: hidden;
}
.card-preview-emoji {
  font-size: 54px;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(31, 29, 24, 0.08));
}
.card-preview-emoji.is-dark {
  color: #fff;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.35));
}
.card-preview.is-dark .card-preview-pattern {
  background-image:
    repeating-linear-gradient(0deg, transparent 0 19px, rgba(255,255,255,0.04) 19px 20px),
    repeating-linear-gradient(90deg, transparent 0 27px, rgba(255,255,255,0.03) 27px 28px);
}
.card-preview-pattern {
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(0deg, transparent 0 19px, rgba(27, 54, 93, 0.04) 19px 20px),
    repeating-linear-gradient(90deg, transparent 0 27px, rgba(27, 54, 93, 0.03) 27px 28px);
  pointer-events: none;
}
.card-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 3px 8px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(255, 255, 255, 0.92);
  color: var(--accent);
  border: 1px solid var(--ink-border);
  border-radius: 999px;
  z-index: 1;
}
.card-badge-brown {
  background: var(--accent);
  color: var(--paper);
  border-color: var(--accent);
}

.card-body {
  padding: var(--s-4);
  display: flex;
  flex-direction: column;
  flex: 1;
}
.card-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: 4px;
}
.card-title {
  font-family: var(--font-serif);
  font-size: 16.5px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.3;
  flex: 1;
  min-width: 0;
}
.card-meta {
  font-size: 11.5px;
  color: var(--ink-muted);
  font-family: var(--font-mono);
  margin-bottom: var(--s-3);
}
.card-meta .sep { opacity: 0.4; margin: 0 4px; }
.card-description {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.55;
  margin-bottom: var(--s-4);
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: var(--s-3);
}
.card-tag {
  display: inline-block;
  padding: 2px 8px;
  font-size: 10.5px;
  font-family: var(--font-mono);
  color: var(--ink-muted);
  background: var(--paper-alt);
  border-radius: var(--r-md);
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: var(--s-3);
  margin-top: auto;
  border-top: 1px solid var(--ink-border-soft);
}
.card-actions { display: flex; gap: 4px; }
.card-btn {
  border: 1px solid var(--ink-border);
  background: transparent;
  color: var(--ink-soft);
  padding: 4px 10px;
  font-size: 11.5px;
  border-radius: var(--r-md);
  transition: all var(--dur-fast) var(--ease);
}
.card-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
}
.card-btn.is-fav {
  color: var(--gold);
  border-color: var(--gold);
  background: #fff8e6;
}
.card-btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 26px;
  padding: 0;
  text-decoration: none;
  cursor: pointer;
}
.card-btn-link:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
}
.card-id {
  font-size: 10.5px;
  font-family: var(--font-mono);
  color: var(--ink-subtle);
}

/* ============================================
   EMPTY / LOADING STATES
   ============================================ */
.empty-state {
  padding: var(--s-9) 0;
  text-align: center;
}
.empty-state-inner {
  max-width: 420px;
  margin: 0 auto;
}
.empty-state-emoji {
  font-size: 64px;
  margin-bottom: var(--s-4);
  opacity: 0.6;
}
.empty-state h3 {
  font-family: var(--font-serif);
  font-size: 22px;
  margin-bottom: var(--s-3);
}
.empty-state p {
  color: var(--ink-muted);
  margin-bottom: var(--s-5);
}
.btn {
  display: inline-block;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--ink-border);
  background: #fff;
  color: var(--ink);
  border-radius: var(--r-md);
  transition: all var(--dur) var(--ease);
  cursor: pointer;
}
.btn:hover { border-color: var(--ink); }
.btn-primary {
  background: var(--accent);
  color: var(--paper);
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.loading-state {
  padding: var(--s-8) 0;
  text-align: center;
  color: var(--ink-muted);
  font-size: 14px;
}
.loader {
  width: 28px;
  height: 28px;
  margin: 0 auto var(--s-4);
  border: 2px solid var(--ink-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================
   HELP SECTION
   ============================================ */
.help-section {
  padding: var(--s-8) 0 var(--s-9);
  border-top: 1px solid var(--ink-border);
  background: var(--paper-alt);
}
.help-header { text-align: center; margin-bottom: var(--s-7); }
.help-header h2 {
  font-family: var(--font-display);
  font-size: clamp(26px, 3.2vw, 36px);
  font-style: italic;
  font-weight: 400;
  margin-bottom: var(--s-2);
}
.help-subtitle {
  font-family: var(--font-serif);
  font-size: 15px;
  color: var(--ink-muted);
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s-5);
  margin-bottom: var(--s-7);
}
.help-card {
  background: var(--paper);
  padding: var(--s-6);
  border: 1px solid var(--ink-border);
  border-radius: var(--r-lg);
  position: relative;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.help-card:hover { transform: translateY(-2px); box-shadow: var(--sh-2); }
.help-step {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 18px;
  font-style: italic;
  color: var(--paper);
  background: var(--accent);
  border-radius: 50%;
  margin-bottom: var(--s-4);
}
.help-card h3 {
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 600;
  margin-bottom: var(--s-3);
}
.help-card > p {
  color: var(--ink-soft);
  margin-bottom: var(--s-4);
  font-size: 14px;
  line-height: 1.6;
}
.help-list { padding-left: 0; }
.help-list li {
  position: relative;
  padding-left: 18px;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--ink-soft);
}
.help-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  width: 10px;
  height: 1px;
  background: var(--accent);
}
.help-list code {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 4px;
  background: var(--paper-alt);
  border-radius: var(--r-sm);
}
.help-footer {
  display: flex;
  justify-content: center;
}
.help-tip {
  max-width: 720px;
  padding: var(--s-4) var(--s-5);
  background: #fff;
  border: 1px solid var(--ink-border);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md);
  font-size: 13.5px;
  color: var(--ink-soft);
  line-height: 1.6;
}
.inline-link {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--accent);
  padding: 0 4px;
}
.inline-link:hover { background: var(--accent-bg); text-decoration: none; }

/* ============================================
   FOOTER
   ============================================ */
.site-footer {
  padding: var(--s-7) 0 var(--s-6);
  background: var(--ink);
  color: var(--paper);
}
.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-6);
  flex-wrap: wrap;
}
.footer-brand-area {
  display: flex;
  align-items: center;
  gap: var(--s-5);
  flex-wrap: wrap;
}
.footer-brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}
.footer-brand .brand-mark { color: var(--paper); font-size: 28px; }
.footer-brand strong { font-family: var(--font-serif); font-size: 16px; color: var(--paper); }
.footer-brand small { font-size: 11px; color: rgba(245, 244, 237, 0.55); }
.footer-tagline {
  font-size: 13px;
  color: rgba(245, 244, 237, 0.6);
  line-height: 1.6;
  max-width: 360px;
  margin: 0;
}
.footer-source {
  font-size: 12px;
  color: rgba(245, 244, 237, 0.5);
}
.footer-source p { margin: 0; }
.footer-link {
  color: rgba(245, 244, 237, 0.7);
  text-decoration: underline;
  text-decoration-color: rgba(245, 244, 237, 0.3);
}
.footer-link:hover { color: var(--paper); }

/* ============================================
   MODAL
   ============================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--s-7) var(--s-5);
  animation: modalIn var(--dur) var(--ease);
  overflow-y: auto;
}
.modal[hidden] { display: none; }
@keyframes modalIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(31, 29, 24, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-dialog {
  position: relative;
  width: 100%;
  max-width: 920px;
  background: var(--paper);
  border-radius: 10px;
  box-shadow: var(--sh-3);
  animation: modalDialogIn var(--dur-slow) var(--ease);
}
@keyframes modalDialogIn {
  from { transform: translateY(20px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}
.modal-close {
  position: absolute;
  top: 14px; right: 16px;
  width: 36px; height: 36px;
  border: 1px solid var(--ink-border);
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 22px;
  line-height: 1;
  border-radius: 50%;
  transition: all var(--dur-fast) var(--ease);
  z-index: 5;
}
.modal-close:hover {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.modal-content { padding: 0; }

/* Modal Preview Hero */
.modal-hero {
  padding: var(--s-7) var(--s-7) var(--s-6);
  border-bottom: 1px solid var(--ink-border);
  background:
    radial-gradient(ellipse at top right, rgba(27, 54, 93, 0.04), transparent 60%),
    linear-gradient(to bottom, var(--paper), var(--paper));
  border-radius: 10px 10px 0 0;
}
.modal-hero .modal-badge {
  display: inline-block;
  margin-bottom: var(--s-3);
  padding: 3px 10px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  font-family: var(--font-sans);
}
.modal-hero h1 {
  font-family: var(--font-serif);
  font-size: 34px;
  font-weight: 600;
  margin-bottom: var(--s-2);
}
.modal-hero .modal-subtitle {
  font-family: var(--font-serif);
  font-size: 15px;
  color: var(--ink-muted);
  margin-bottom: var(--s-4);
}
.modal-hero .modal-id {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-muted);
  padding: 3px 8px;
  background: var(--paper-alt);
  border-radius: var(--r-sm);
}

.modal-hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-4);
  margin-top: var(--s-5);
  padding-top: var(--s-4);
  border-top: 1px solid var(--ink-border-soft);
}
.modal-hero-meta .meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.modal-hero-meta .meta-item span:first-child {
  font-size: 11px;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.modal-hero-meta .meta-item span:last-child {
  font-size: 14px;
  color: var(--ink);
  font-family: var(--font-serif);
}

/* Dark modal hero */
.modal-hero.is-dark {
  color: #fff;
}
.modal-hero.is-dark .modal-badge {
  color: rgba(255,255,255,0.85);
  border-color: rgba(255,255,255,0.45);
}
.modal-hero.is-dark h1 {
  color: #fff;
}
.modal-hero.is-dark .modal-subtitle {
  color: rgba(255,255,255,0.7);
}
.modal-hero.is-dark .modal-id {
  color: rgba(255,255,255,0.75);
  background: rgba(255,255,255,0.12);
}
.modal-hero.is-dark .modal-hero-meta {
  border-top-color: rgba(255,255,255,0.15);
}
.modal-hero.is-dark .modal-hero-meta .meta-item span:first-child {
  color: rgba(255,255,255,0.6);
}
.modal-hero.is-dark .modal-hero-meta .meta-item span:last-child {
  color: #fff;
}

/* Modal Body */
.modal-body {
  padding: var(--s-6) var(--s-7) var(--s-7);
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s-6);
}
.modal-section h3 {
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  margin-bottom: var(--s-3);
  padding-bottom: var(--s-2);
  border-bottom: 1px solid var(--ink-border-soft);
}

.modal-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.modal-tag {
  display: inline-block;
  padding: 4px 10px;
  font-size: 11.5px;
  font-family: var(--font-mono);
  color: var(--ink-soft);
  background: var(--paper-alt);
  border: 1px solid var(--ink-border-soft);
  border-radius: var(--r-md);
}

.modal-short {
  font-family: var(--font-serif);
  font-size: 15px;
  color: var(--ink-soft);
  line-height: 1.7;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}
.modal-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--ink-border);
  background: #fff;
  color: var(--ink);
  border-radius: var(--r-md);
  transition: all var(--dur-fast) var(--ease);
}
.modal-action-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.modal-action-btn.is-primary {
  background: var(--accent);
  color: var(--paper);
  border-color: var(--accent);
}
.modal-action-btn.is-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--paper); }
.modal-action-btn.is-fav { border-color: var(--gold); color: var(--gold); background: #fff8e6; }

/* Example Info Panel */
.modal-example {
  background: #fff;
  border: 1px solid var(--ink-border);
  border-radius: var(--r-md);
  padding: var(--s-4) var(--s-5);
}
.example-row {
  display: flex;
  gap: var(--s-4);
  padding: 8px 0;
  border-bottom: 1px solid var(--ink-border-soft);
}
.example-row:last-child { border-bottom: none; }
.example-row .label {
  flex-shrink: 0;
  width: 120px;
  font-size: 11.5px;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-top: 2px;
}
.example-row .value {
  flex: 1;
  font-size: 13.5px;
  color: var(--ink-soft);
}
.example-row .value code {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 2px 6px;
  background: var(--paper-alt);
  border-radius: var(--r-sm);
}

/* ── Modal Tabs ── */
.modal-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--ink-border);
  background: var(--paper-alt);
  padding: 0 var(--s-7);
}
.modal-tab {
  padding: var(--s-3) var(--s-5);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
  font-family: var(--font-sans);
  white-space: nowrap;
}
.modal-tab:hover { color: var(--ink); }
.modal-tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* ── Modal Tab Panels ── */
.modal-tab-panel[hidden] { display: none; }

/* ── Modal File Viewer ── */
.modal-file-viewer {
  height: 55vh;
  min-height: 360px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}
.modal-code {
  margin: 0;
  padding: var(--s-5) var(--s-6);
  height: 100%;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--ink);
  background: #faf9f6;
  border: none;
  white-space: pre-wrap;
  word-break: break-word;
}
.modal-code code {
  font-family: inherit;
  font-size: inherit;
  background: none;
  padding: 0;
}

/* ============================================
   TOAST
   ============================================ */
.toast {
  position: fixed;
  bottom: var(--s-5);
  left: 50%;
  transform: translateX(-50%);
  padding: var(--s-3) var(--s-4);
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  border-radius: var(--r-md);
  box-shadow: var(--sh-3);
  z-index: 200;
  animation: toastIn var(--dur) var(--ease);
  pointer-events: none;
}
.toast[hidden] { display: none; }
@keyframes toastIn {
  from { transform: translate(-50%, 10px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* ============================================
   RESPONSIVE
   ============================================ */

/* Large desktop */
@media (min-width: 1100px) {
  .main { grid-template-columns: var(--sidebar-w-lg) 1fr; }
}

/* Tablet */
@media (max-width: 960px) {
  .main {
    grid-template-columns: 1fr;
    gap: var(--s-5);
  }
  .filters {
    position: static;
    max-height: none;
    overflow: visible;
    padding: var(--s-4);
    background: var(--paper-alt);
    border: 1px solid var(--ink-border);
    border-radius: var(--r-lg);
  }
  .hero-stats { grid-template-columns: repeat(3, 1fr); gap: var(--s-3); }
  .help-grid { grid-template-columns: 1fr; }
  .footer-inner { flex-direction: column; align-items: flex-start; }
}

/* Mobile */
@media (max-width: 720px) {
  .site-header { position: static; }
  .header-inner { height: auto; padding: var(--s-3) var(--s-5); flex-direction: column; align-items: stretch; gap: var(--s-3); }
  .primary-nav { overflow-x: auto; justify-content: flex-start; -webkit-overflow-scrolling: touch; }
  .primary-nav::-webkit-scrollbar { display: none; }
  .nav-link { white-space: nowrap; padding: 6px 12px; font-size: 12.5px; flex-shrink: 0; }

  .hero { padding: var(--s-6) 0 var(--s-5); }
  .hero-title { font-size: 28px; }
  .hero-subtitle { font-size: 14.5px; margin-bottom: var(--s-4); }
  .hero-search { margin-bottom: var(--s-4); }
  .hero-stats { grid-template-columns: repeat(3, 1fr); gap: var(--s-2); }
  .stat strong { font-size: 22px; }

  .main { padding-top: var(--s-5); padding-bottom: var(--s-7); }
  .result-header {
    flex-direction: column;
    align-items: stretch;
  }
  .result-tools {
    justify-content: space-between;
    width: 100%;
  }
  .template-grid {
    grid-template-columns: 1fr;
  }
  .template-grid.is-list .template-card {
    grid-template-columns: 48px 1fr;
  }
  .template-grid.is-list .card-actions { grid-column: 1 / -1; justify-content: flex-end; }

  .help-card { padding: var(--s-5); }
  .footer-inner { flex-direction: column; align-items: flex-start; gap: var(--s-4); }

  .modal { padding: var(--s-4) var(--s-2); }
  .modal-hero { padding: var(--s-5) var(--s-4) var(--s-4); }
  .modal-hero h1 { font-size: 24px; }
  .modal-body { padding: var(--s-4) var(--s-4) var(--s-5); }
  .modal-close { top: 10px; right: 10px; width: 32px; height: 32px; font-size: 18px; }
}

@media (max-width: 420px) {
  .hero-stats { grid-template-columns: repeat(2, 1fr); }
  .container { padding: 0 var(--s-4); }
}

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

/* Focus styles */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-md);
}
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline-offset: 2px;
}
