/* =========================================================
   KitTheme: Template Hub (rowen.work/kittheme/templates)
   ---------------------------------------------------------
   Builds on home.css (tokens, nav, buttons, sections, footer) and
   fl-preview.css (the FL Browser panel every card is drawn with). The
   design system is kittheme/DESIGN.md: cards are surface-1 with a
   hairline and brighten a step on hover; the template's own artwork is
   the only color on the card.
   ========================================================= */

/* ---------- hero ---------- */
.tpl-hero { padding: clamp(44px, 5vw, 72px) 0 clamp(36px, 4vw, 52px); }
.tpl-hero-inner { max-width: 1200px; }
.tpl-hero .lede { max-width: 40em; }
.tpl-hero-note { margin: 18px 0 0; font-size: var(--fs-1); color: var(--text-3); }
.tpl-hero-note b { color: var(--text-2); font-weight: 600; }

/* ---------- toolbar ---------- */
.tpl-browse { padding-top: var(--sp-4); border-top: 1px solid var(--line); }
.tpl-toolbar { display: flex; flex-wrap: wrap; gap: 14px 16px; align-items: end; }
.tpl-search { flex: 1 1 320px; min-width: 0; }
.tpl-sort { flex: 0 0 auto; }
.tpl-label { display: block; margin: 0 0 6px; font-size: var(--fs-0); font-weight: 500; color: var(--text-3); }
.tpl-search-box { position: relative; }
.tpl-search-box svg { position: absolute; left: 13px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.tpl-search-box input, .tpl-sort select {
  width: 100%; min-height: 40px; padding: 0 12px 0 38px;
  border: 1px solid var(--line-strong); border-radius: var(--r-2);
  background: var(--bg-1); color: var(--text); font: inherit; font-size: var(--fs-1);
  transition: border-color var(--fast) ease, box-shadow var(--fast) ease;
}
.tpl-search-box input::placeholder { color: var(--text-3); }
.tpl-search-box input::-webkit-search-cancel-button { filter: invert(.8); }
.tpl-search-box input:hover, .tpl-sort select:hover { border-color: var(--line-hover); }
.tpl-sort select { padding: 0 36px 0 12px; min-width: 190px; appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%238b8e96' stroke-width='1.6' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center; }
.tpl-search-box input:focus, .tpl-sort select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .18); }

/* filter chips: selection is a surface step, not a tint */
.tpl-cats { display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0 0; }
.tpl-cat {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 32px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; background: transparent;
  color: var(--text-3); font: inherit; font-size: var(--fs-0); font-weight: 500; cursor: pointer;
  transition: border-color var(--fast) ease, color var(--fast) ease, background-color var(--fast) ease;
}
.tpl-cat:hover { color: var(--text); border-color: var(--line-strong); }
.tpl-cat[aria-pressed="true"], .tpl-cat-tag { color: var(--text); border-color: var(--line-strong); background: var(--bg-3); }
.tpl-cat small { font-size: 12px; font-weight: 400; color: var(--text-3); font-variant-numeric: tabular-nums; }
.tpl-cat[aria-pressed="true"] small { color: var(--text-2); }
.tpl-cat-tag span { font-size: 15px; line-height: 1; color: var(--text-3); }

/* ---------- section heads inside the browser ---------- */
.tpl-section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 18px; margin: var(--sp-5) 0 var(--sp-3); }
.tpl-section-head .kicker { flex: 1 1 100%; margin-bottom: 2px; }
.tpl-section-head h2 { margin: 0; }
.tpl-results-head h2 { font-size: clamp(22px, 1.2vw + 14px, 28px); letter-spacing: -.02em; }
.tpl-results { margin: 0; font-size: var(--fs-1); color: var(--text-3); }
.tpl-results b { color: var(--text-2); font-weight: 600; }
.tpl-featured[hidden] { display: none; }

/* ---------- cards ---------- */
.tpl-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.tpl-grid-featured { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.tpl-card {
  position: relative; display: flex; flex-direction: column; min-width: 0;
  border: 1px solid var(--line); border-radius: var(--r-3); background: var(--bg-1);
  transition: border-color var(--fast) ease, background-color var(--fast) ease;
}
.tpl-card:hover, .tpl-card:focus-within { border-color: var(--line-strong); background: var(--bg-2); }
.tpl-preview {
  position: relative; display: block; padding: 16px 16px 0; text-decoration: none; overflow: hidden;
  border-radius: var(--r-3) var(--r-3) 0 0; border-bottom: 1px solid var(--line);
  background: var(--bg-0);
}
/* 190px = the title bar plus three whole folder rows with their artwork
   (33 + 3 × 51), so a card never cuts a banner in half. */
.tpl-preview .fl-browser {
  width: 100%; height: 190px; box-shadow: 0 0 0 1px rgba(255, 255, 255, .05);
  border-radius: 4px 4px 0 0; border-bottom: 0; display: flex; flex-direction: column;
}
.tpl-preview .fl-list { flex: 1; min-height: 0; overflow: hidden; }
.tpl-preview .fl-hintbar { display: none; }
.tpl-preview:focus-visible { outline-offset: -2px; }
.tpl-flag {
  display: inline-block; margin-right: 8px; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; vertical-align: 1px;
  background: var(--bg-3); color: var(--text-2); border: 1px solid var(--line-strong);
}
.tpl-body { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px 16px; flex: 1; }
.tpl-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.tpl-name { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -.012em; line-height: 1.3; }
.tpl-name a { text-decoration: none; }
.tpl-name a:hover { text-decoration: underline; text-underline-offset: 3px; }
.tpl-category { flex: none; display: inline-flex; align-items: center; font-size: var(--fs-0); color: var(--text-3); }
.tpl-by { margin: -6px 0 0; display: flex; align-items: center; gap: 6px; font-size: var(--fs-1); color: var(--text-3); }
.tpl-by b { color: var(--text); font-weight: 500; }
.tpl-creator-name { text-decoration: none; }
.tpl-creator-name:hover b { text-decoration: underline; text-underline-offset: 3px; }
.tpl-creator-badge { display: inline-grid; place-items: center; width: 16px; height: 16px; --badge: var(--accent); }
.tpl-creator-badge svg { width: 16px; height: 16px; fill: var(--badge); }
.tpl-creator-badge .tick { fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.tpl-creator-badge[data-badge="founder"] { --badge: #e2b53a; }
.tpl-creator-badge[data-badge="verified"] { --badge: #9d7bff; }
.tpl-creator-badge[data-badge="kittheme"] { --badge: var(--accent-hi); }
.tpl-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tpl-detail-actions .btn small { font-size: 12px; font-weight: 400; opacity: .8; }
.tpl-desc { margin: 0; font-size: var(--fs-1); line-height: 1.5; color: var(--text-2); }
.tpl-tags { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.tpl-tag {
  display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12.5px; text-decoration: none;
  color: var(--text-2); background: var(--bg-2); border: 1px solid var(--line);
  transition: border-color var(--fast) ease, color var(--fast) ease, background-color var(--fast) ease;
}
.tpl-tag:hover { color: var(--text); border-color: var(--line-strong); }
.tpl-tag[aria-current="true"] { color: var(--text); border-color: var(--line-hover); background: var(--bg-3); }
.tpl-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: auto; padding-top: 6px; font-size: var(--fs-0); color: var(--text-3); font-variant-numeric: tabular-nums; }
.tpl-meta span { display: inline-flex; align-items: center; gap: 5px; }
.tpl-meta svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
/* Open in editor across the top; Preview and Download share the row below. */
.tpl-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 4px; }
.tpl-actions .btn { min-width: 0; padding-inline: 10px; }
.tpl-actions .tpl-act-open { grid-column: 1 / -1; background: var(--bg-3); }
.tpl-actions .tpl-act-open:hover { background: var(--bg-4); }
.tpl-actions .btn-soon { opacity: .55; cursor: not-allowed; }
.tpl-actions .btn-soon:hover { background: var(--bg-1); border-color: var(--line-strong); }

/* ---------- empty state ---------- */
.tpl-empty { display: grid; justify-items: center; gap: 8px; padding: var(--sp-5) 20px; text-align: center; border: 1px solid var(--line); border-radius: var(--r-3); background: var(--bg-1); }
.tpl-empty-title { margin: 0; font-size: var(--fs-3); font-weight: 600; letter-spacing: -.011em; }
.tpl-empty-text { margin: 0 0 8px; color: var(--text-2); }

/* ---------- upload section ---------- */
.tpl-upload-grid { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: clamp(28px, 5vw, 72px); align-items: start; }
.tpl-upload .section-lede { margin-bottom: 24px; }
.tpl-upload-files { margin: 20px 0 0; max-width: 46ch; font-size: var(--fs-1); color: var(--text-3); line-height: 1.55; }
.tpl-upload-files b { color: var(--text-2); font-weight: 600; }
.tpl-rules { padding: 20px 22px; border: 1px solid var(--line); border-radius: var(--r-3); background: var(--bg-1); font-size: var(--fs-1); color: var(--text-2); }
.tpl-rules-title { margin: 0 0 10px; color: var(--text); font-weight: 600; line-height: 1.5; }
.tpl-rules ul { margin: 0; padding: 0 0 0 18px; display: grid; gap: 4px; }

/* ---------- dialogs ---------- */
.tpl-dialog {
  width: min(100% - 32px, 720px); max-height: calc(100vh - 32px); margin: auto; padding: 0;
  border: 1px solid var(--line-strong); border-radius: var(--r-4);
  background: var(--bg-2); color: var(--text); box-shadow: var(--edge), var(--shadow-float);
  overflow-y: auto; overflow-x: hidden;
}
.tpl-dialog[open] { animation: tpl-dialog-in 200ms var(--ease); }
@keyframes tpl-dialog-in { from { opacity: 0; transform: translateY(6px); } }
.tpl-dialog::backdrop { background: rgba(5, 5, 7, .72); }
.tpl-dialog-inner { position: relative; padding: clamp(20px, 3vw, 32px); }
.tpl-close {
  position: absolute; right: 14px; top: 14px; z-index: 2; width: 32px; height: 32px;
  border: 1px solid var(--line-strong); border-radius: var(--r-2); background: var(--bg-1);
  color: var(--text-2); font: inherit; font-size: 20px; line-height: 1; cursor: pointer;
  transition: color var(--fast) ease, border-color var(--fast) ease;
}
.tpl-close:hover { color: var(--text); border-color: var(--line-hover); }

/* detail */
.tpl-detail { width: min(100% - 32px, 960px); }
.tpl-detail-grid { display: grid; grid-template-columns: minmax(0, 6fr) minmax(0, 6fr); gap: clamp(20px, 3vw, 36px); }
.tpl-detail-stage {
  display: grid; place-items: start center; padding: clamp(16px, 2.5vw, 28px); min-width: 0; overflow: hidden;
  border-radius: var(--r-3); border: 1px solid var(--line);
  background: var(--bg-0);
}
.tpl-detail-stage .fl-browser { width: 100%; max-width: 380px; box-shadow: 0 12px 32px rgba(0, 0, 0, .45), 0 0 0 1px rgba(255, 255, 255, .05); }
.tpl-detail-stage .fl-list { min-height: 200px; }
.tpl-detail-copy { display: grid; gap: 14px; align-content: start; min-width: 0; }
.tpl-detail-copy .kicker { margin: 0; }
.tpl-detail-copy h2 { margin: 0; padding-right: 40px; font-size: clamp(24px, 1.4vw + 14px, 32px); }
.tpl-detail-copy .tpl-by { margin: -4px 0 0; }
.tpl-detail-copy .tpl-desc { font-size: var(--fs-2); }
.tpl-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tpl-stat { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-2); background: var(--bg-1); }
.tpl-stat b { display: block; font-size: var(--fs-3); font-weight: 600; font-variant-numeric: tabular-nums; }
.tpl-stat span { font-size: 12px; color: var(--text-3); }
.tpl-detail-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.tpl-detail-actions .btn-soon { opacity: .55; cursor: not-allowed; }
.tpl-detail-actions .btn-soon:hover { background: var(--bg-1); border-color: var(--line-strong); }
.tpl-soon-note { margin: -4px 0 0; font-size: var(--fs-0); color: var(--text-3); }
.tpl-included { margin: 4px 0 0; border-top: 1px solid var(--line); }
.tpl-included summary { padding: 12px 0; cursor: pointer; font-weight: 500; color: var(--text-2); list-style: none; display: flex; align-items: center; gap: 8px; }
.tpl-included summary:hover { color: var(--text); }
.tpl-included summary::-webkit-details-marker { display: none; }
.tpl-included summary::before { content: "▸"; font-size: 11px; color: var(--text-3); transition: transform var(--fast) ease; }
.tpl-included[open] summary::before { transform: rotate(90deg); }
.tpl-included ul { margin: 0 0 12px; padding: 0 0 0 18px; display: grid; gap: 4px; font-size: var(--fs-1); color: var(--text-2); }
.tpl-included p { margin: 0 0 12px; font-size: var(--fs-1); color: var(--text-2); line-height: 1.55; }

/* upload form */
.tpl-upload-dialog { width: min(100% - 32px, 640px); }
.tpl-form { display: grid; gap: 16px; margin: 0; }
.tpl-form .kicker { margin: 0; }
.tpl-form h2 { margin: 0; padding-right: 40px; font-size: clamp(22px, 1.4vw + 14px, 28px); }
.tpl-form-lede { margin: -6px 0 4px; color: var(--text-2); font-size: var(--fs-1); }
.tpl-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tpl-field { display: grid; gap: 6px; min-width: 0; }
.tpl-field label { font-size: var(--fs-0); font-weight: 500; }
.tpl-optional { margin-left: 6px; font-weight: 400; color: var(--text-3); }
.tpl-field input, .tpl-field textarea, .tpl-field select {
  width: 100%; min-height: 40px; padding: 9px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--r-2);
  background: var(--bg-1); color: var(--text); font: inherit; font-size: var(--fs-1);
  transition: border-color var(--fast) ease, box-shadow var(--fast) ease;
}
.tpl-field input:hover, .tpl-field textarea:hover, .tpl-field select:hover { border-color: var(--line-hover); }
.tpl-field textarea { resize: vertical; }
.tpl-field input[type="file"] { padding: 6px 8px; color: var(--text-2); font-size: var(--fs-0); }
.tpl-field input[type="file"]::file-selector-button { margin-right: 10px; padding: 5px 11px; border: 1px solid var(--line-strong); border-radius: var(--r-1); background: var(--bg-2); color: var(--text); font: inherit; font-size: var(--fs-0); font-weight: 500; cursor: pointer; }
.tpl-field input:focus, .tpl-field textarea:focus, .tpl-field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .18); }
.tpl-field input::placeholder, .tpl-field textarea::placeholder { color: var(--text-3); }
.tpl-field.is-invalid input, .tpl-field.is-invalid textarea, .tpl-field.is-invalid select { border-color: #e07070; }
.tpl-hint { font-size: 12.5px; color: var(--text-3); }
.tpl-check { display: flex; gap: 12px; align-items: flex-start; font-size: var(--fs-1); color: var(--text-2); line-height: 1.5; cursor: pointer; }
.tpl-check input { flex: none; width: 17px; height: 17px; margin: 3px 0 0; accent-color: var(--primary); }
.tpl-check.is-invalid { color: #f0a0a0; }
.tpl-form-status { margin: 0; min-height: 1.5em; font-size: var(--fs-1); color: var(--text-2); line-height: 1.5; }
.tpl-form-status.is-error { color: #f0a0a0; }
.tpl-form-status.is-ok { color: #9be3b8; }
.tpl-form-status a { color: var(--accent); }
/* Signed out, or no username yet: what to do first instead of the form. */
.tpl-up-gate { display: grid; gap: 8px; padding: 16px 18px; border: 1px solid var(--line-strong); border-radius: var(--r-3); background: var(--bg-1); color: var(--text-2); font-size: var(--fs-1); }
.tpl-up-gate p { margin: 0; line-height: 1.55; }
.tpl-up-gate .tpl-up-gate-title { color: var(--text); font-weight: 600; font-size: var(--fs-2); }
.tpl-up-gate-actions { border-top: 0; padding-top: 0; justify-content: flex-start; }
.tpl-up-gate-actions .btn { margin-top: 6px; }
.tpl-up-fields { display: grid; gap: 16px; }
.tpl-up-fields[hidden] { display: none; }
.tpl-up-as { margin: -8px 0 0; font-size: var(--fs-1); color: var(--text-3); }
.tpl-up-as b { color: var(--text); font-weight: 600; }
.tpl-up-as span { color: var(--text-2); }
/* Detail: creator link, report and remove. */
.tpl-creator-link { margin: -8px 0 0; font-size: var(--fs-0); color: var(--text-3); }
.tpl-creator-link a { color: var(--text-2); text-underline-offset: 3px; }
.tpl-creator-link a:hover { color: var(--text); }
.tpl-detail-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 14px; padding-top: 10px; border-top: 1px solid var(--line); font-size: var(--fs-0); color: var(--text-3); }
.tpl-detail-foot .linkbtn { font-size: var(--fs-0); padding-left: 0; }
.tpl-danger { color: #f0a0a0; }
.tpl-danger:hover { color: #ffc0c0; }
.tpl-report { display: grid; gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: var(--r-2); background: var(--bg-1); }
.tpl-report[hidden] { display: none; }
.tpl-report-actions { display: flex; justify-content: flex-end; gap: 8px; }
.tpl-report-done { margin: 0; padding: 12px 14px; border-radius: var(--r-2); background: var(--bg-1); color: #9be3b8; font-size: var(--fs-1); }
.tpl-form-rules { margin: 0; }
.tpl-form-rules ul { margin-bottom: 4px; }
.tpl-form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 4px; border-top: 1px solid var(--line); margin-top: 4px; }
.tpl-form-actions .btn { margin-top: 12px; }

/* toast */
.tpl-toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 50; transform: translateX(-50%);
  max-width: min(92vw, 480px); padding: 11px 16px; border-radius: var(--r-2);
  border: 1px solid var(--line-strong); background: var(--bg-4); color: var(--text);
  font-size: var(--fs-1); box-shadow: var(--shadow-float);
  animation: tpl-toast-in 160ms var(--ease);
}
@keyframes tpl-toast-in { from { opacity: 0; transform: translate(-50%, 6px); } }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .tpl-upload-grid { grid-template-columns: 1fr; }
  .tpl-detail-grid { grid-template-columns: 1fr; }
  .tpl-detail-stage { order: -1; }
}
@media (max-width: 640px) {
  .tpl-grid, .tpl-grid-featured { grid-template-columns: 1fr; }
  .tpl-toolbar { align-items: stretch; }
  .tpl-sort { flex: 1 1 100%; }
  .tpl-sort select { min-width: 0; }
  .tpl-row { grid-template-columns: 1fr; }
  .tpl-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .tpl-stat { padding: 8px 10px; }
  .tpl-stat b { font-size: var(--fs-2); }
  .tpl-dialog { width: calc(100% - 16px); max-height: calc(100vh - 16px); }
  .tpl-form-actions { flex-direction: column-reverse; }
  .tpl-form-actions .btn { width: 100%; }
  .tpl-hero .actions .btn { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: reduce) {
  .tpl-card, .tpl-cat, .tpl-tag, .tpl-included summary::before, .tpl-close { transition: none; }
  .tpl-toast, .tpl-dialog[open] { animation: none; }
}
