/* Public template gallery (/templates/) and detail pages. Tokens only; mobile first; everything stays inside its card. */
.tpl { padding-bottom: var(--space-8); }
.tpl .page-hero { padding-bottom: var(--space-4); }
.tpl-section { padding-top: var(--space-4); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Gallery layout: filters in a sidebar that stays in view on desktop; on phones they fold behind a Filter toggle above the grid. */
.tpl-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-5); align-items: start; }
.tpl-side, .tpl-main { min-width: 0; }
.tpl-filters { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-4); box-shadow: var(--shadow-sm); }
.tpl-search { position: relative; width: 100%; min-width: 0; color: var(--color-muted); }
.tpl-more { min-width: 0; }
.tpl-toggle { display: flex; align-items: center; gap: .5rem; min-height: 44px; padding: 0 1rem; border: 1px solid var(--color-border); border-radius: var(--radius-full); background: var(--color-white); font-weight: 600; cursor: pointer; list-style: none; width: max-content; max-width: 100%; }
.tpl-toggle::-webkit-details-marker { display: none; }
.tpl-toggle::after { content: ""; width: .5rem; height: .5rem; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg) translateY(-2px); margin-left: .25rem; }
.tpl-more[open] > .tpl-toggle::after { transform: rotate(-135deg) translateY(-1px); }
.tpl-toggle:focus-visible, .tpl-clear:focus-visible { outline: 2px solid var(--color-forest); outline-offset: 2px; }
.tpl-active { display: inline-grid; place-items: center; min-width: 1.4rem; height: 1.4rem; padding: 0 .35rem; border-radius: var(--radius-full); background: var(--color-forest-ink); color: var(--color-paper); font-size: .75rem; }
.tpl-active[hidden] { display: none; }
.tpl-more-body { display: grid; gap: var(--space-4); padding-top: var(--space-4); }
.tpl-clear { font-size: var(--text-sm); color: var(--color-forest-ink); font-weight: 600; justify-self: start; min-height: 32px; display: inline-flex; align-items: center; }
.tpl-chips small { margin-left: .35rem; opacity: .7; font-size: .8em; }
.tpl-search svg { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); pointer-events: none; }
.tpl-search input { width: 100%; min-height: 44px; padding: .55rem .9rem .55rem 2.5rem; font: inherit; color: var(--color-ink); background: var(--color-white); border: 1px solid var(--color-line); border-radius: var(--radius-full); }
.tpl-search input:focus-visible, .tpl-chips input:focus-visible + span, .tpl-device a:focus-visible, .tpl-pages a:focus-visible, .tpl-back:focus-visible, .tpl-card a:focus-visible { outline: 2px solid var(--color-forest); outline-offset: 2px; }
.tpl-chips { border: 0; padding: 0; margin: 0; min-width: 0; max-width: 100%; display: flex; flex-wrap: wrap; gap: .4rem; }
.tpl-chips legend { font-weight: 600; font-size: var(--text-sm); margin-bottom: .4rem; padding: 0; width: 100%; }
.tpl-chips label { position: relative; }
.tpl-chips input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.tpl-chips span { display: inline-flex; align-items: center; min-height: 40px; padding: .3rem .95rem; border-radius: var(--radius-full); border: 1px solid var(--color-border); background: var(--color-white); font-size: var(--text-sm); white-space: nowrap; }
.tpl-chips input:checked + span { background: var(--color-forest-ink); color: var(--color-paper); border-color: var(--color-forest-ink); }
.tpl-count { margin: 0 0 var(--space-4); color: var(--color-muted); font-size: var(--text-sm); }

/* Results fade as a block so a filter change isn't a hard swap; the sidebar stays put. */
.tpl-main { transition: opacity .2s ease; }
.tpl-main.is-fading { opacity: 0; pointer-events: none; }

.tpl-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-5); }
@media (min-width: 640px) { .tpl-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 960px) {
  .tpl-layout { grid-template-columns: 17.5rem minmax(0, 1fr); gap: var(--space-6); }
  .tpl-side { position: sticky; top: calc(var(--header-h) + var(--space-4)); max-height: calc(100vh - var(--header-h) - var(--space-6)); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; border-radius: var(--radius-lg); }
  .tpl-toggle { display: none; }
  .tpl-more-body { padding-top: var(--space-1); }
  .tpl-chips { gap: .35rem; }
  .tpl-chips span { min-height: 34px; padding: .2rem .8rem; }
}
.tpl-shot { position: relative; }
.tpl-badge { position: absolute; left: .75rem; top: .75rem; padding: .25rem .65rem; border-radius: var(--radius-full); background: var(--color-forest-ink); color: var(--color-paper); font-size: .75rem; font-weight: 600; box-shadow: var(--shadow-sm); }
.tpl-card { background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); min-width: 0; display: flex; flex-direction: column; }
.tpl-card[hidden], .tpl-empty[hidden] { display: none; }
.tpl-card.is-enter { animation: tpl-card-enter .22s ease both; animation-delay: var(--tpl-delay, 0ms); }
@keyframes tpl-card-enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.tpl-shot { display: block; aspect-ratio: 16 / 10; background: var(--color-paper-shade); border-bottom: 1px solid var(--color-border); overflow: hidden; }
.tpl-shot img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: top; opacity: 0; transition: opacity .22s ease, transform .25s ease; }
.tpl-shot img.is-loaded { opacity: 1; }
.tpl-card:hover .tpl-shot img { transform: scale(1.02); }
@media (prefers-reduced-motion: reduce) {
  .tpl-main, .tpl-main.is-fading { opacity: 1; transition: none; }
  .tpl-card.is-enter { animation: none; }
  .tpl-shot img { opacity: 1; transition: none; }
  .tpl-card:hover .tpl-shot img { transform: none; }
}
.tpl-card-body { padding: var(--space-5); min-width: 0; overflow-wrap: anywhere; }
.tpl-card-name { font-size: var(--text-h4); margin: 0 0 var(--space-1); }
.tpl-card-name a { color: var(--color-ink); text-decoration: none; }
.tpl-card-name a:hover { color: var(--color-forest); text-decoration: underline; }
.tpl-card-meta { margin: 0 0 var(--space-2); font-size: var(--text-sm); color: var(--color-gold); font-weight: 600; }
.tpl-card-summary { margin: 0; color: var(--color-muted); font-size: var(--text-sm); line-height: var(--text-sm-lh); }
.tpl-empty { background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-6); }

.tpl-cta { margin-top: var(--space-8); display: grid; gap: var(--space-5); background: var(--color-forest-mist); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-6); }
.tpl-cta h2 { font-size: var(--text-h3); margin: 0 0 var(--space-2); }
.tpl-cta p { margin: 0; color: var(--color-muted); max-width: 38rem; }
.tpl-cta-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); }
@media (min-width: 900px) { .tpl-cta { grid-template-columns: minmax(0, 1fr) auto; align-items: center; } }

/* Detail page */
.tpl-detail { padding-top: var(--space-6); }
.tpl-bar { display: grid; gap: var(--space-4); align-items: start; background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-5); box-shadow: var(--shadow-sm); margin-bottom: var(--space-4); }
.tpl-back { display: inline-flex; align-items: center; gap: .35rem; color: var(--color-forest-ink); font-weight: 600; text-decoration: none; min-height: 44px; }
.tpl-bar-main h1 { font-size: var(--text-h2); margin: 0 0 var(--space-1); }
.tpl-detail-summary { margin: 0; color: var(--color-muted); max-width: 44rem; }
.tpl-bar-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.tpl-device { display: inline-flex; border: 1px solid var(--color-border); border-radius: var(--radius-full); padding: 3px; background: var(--color-paper-shade); }
.tpl-device a { display: inline-flex; align-items: center; gap: .4rem; min-height: 40px; padding: 0 1rem; border-radius: var(--radius-full); color: var(--color-ink); text-decoration: none; font-weight: 600; font-size: var(--text-sm); }
.tpl-device a[aria-current="true"] { background: var(--color-white); box-shadow: var(--shadow-sm); }
.tpl-pages { display: flex; gap: .4rem; overflow-x: auto; max-width: 100%; padding: 2px 0 var(--space-3); }
.tpl-pages a { flex: none; min-height: 40px; display: inline-flex; align-items: center; padding: 0 1rem; border: 1px solid var(--color-border); border-radius: var(--radius-full); background: var(--color-white); color: var(--color-ink); text-decoration: none; font-size: var(--text-sm); }
.tpl-pages a[aria-current="page"] { background: var(--color-forest-ink); color: var(--color-paper); border-color: var(--color-forest-ink); }
.tpl-stage { background: var(--color-paper-shade); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-3); display: flex; justify-content: center; overflow: hidden; }
.tpl-frame { display: block; width: 100%; height: 78vh; min-height: 520px; border: 0; background: #fff; border-radius: var(--radius-md); }
.tpl-stage.is-mobile .tpl-frame { width: min(390px, 100%); height: min(78vh, 780px); border: 8px solid var(--color-ink); border-radius: 28px; }
.tpl-note { margin: var(--space-4) 0 0; color: var(--color-muted); font-size: var(--text-sm); max-width: 48rem; }
@media (min-width: 900px) { .tpl-bar { grid-template-columns: minmax(0, 1fr) auto; } .tpl-back { grid-column: 1 / -1; } }
@media (max-width: 640px) { .tpl-device { display: none; } .tpl-stage.is-mobile .tpl-frame { border-width: 0; border-radius: var(--radius-md); } .tpl-bar-actions .btn { width: 100%; justify-content: center; } }
