/* Template gallery (/templates and /templates/<slug>). */
.tg, .tg-detail { --tg-border: var(--color-border, #e2e8f0); --tg-primary: var(--color-primary, #1d4ed8); --tg-muted: var(--color-text-muted, #64748b); }
.tg .sr-only, .tg-hero .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tg-search { display: flex; gap: .5rem; max-width: 640px; margin: 1.5rem auto 0; }
.tg-search input { flex: 1; min-width: 0; padding: .8rem 1rem; font: inherit; border: 1px solid #cbd5e1; border-radius: 12px; background: #fff; }
.tg-search input:focus, .tg-filterform select:focus { outline: 3px solid rgba(29,78,216,.35); outline-offset: 1px; border-color: var(--tg-primary); }

.tg-cats { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 1.25rem; }
.tg-cat { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem .95rem; border: 1px solid #cbd5e1; border-radius: 999px; background: #fff; color: inherit; text-decoration: none; font-size: .92rem; }
.tg-cat small { color: var(--tg-muted); font-size: .78rem; }
.tg-cat:hover { border-color: var(--tg-primary); }
.tg-cat.is-on { background: var(--tg-primary); border-color: var(--tg-primary); color: #fff; }
.tg-cat.is-on small { color: rgba(255,255,255,.8); }
.tg-filters { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 1.5rem; margin-bottom: 1.5rem; }
.tg-filterform { display: flex; flex-wrap: wrap; gap: .75rem 1.25rem; }
.tg-filterform label { display: flex; align-items: center; gap: .5rem; font-size: .9rem; font-weight: 600; }
.tg-filterform select { padding: .5rem .7rem; font: inherit; font-weight: 400; border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; }
.tg-count { margin: 0; color: var(--tg-muted); font-size: .92rem; }
.tg-count a { margin-left: .5rem; }

.tg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 1.4rem; }
.tg-grid--4 { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.tg-card { background: #fff; border: 1px solid var(--tg-border); border-radius: 16px; overflow: hidden; display: flex; flex-direction: column; transition: transform .15s ease, box-shadow .15s ease; }
.tg-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md, 0 10px 30px rgba(15,23,42,.12)); }
.tg-card__img { position: relative; display: block; aspect-ratio: 4 / 3; background: #f1f5f9; overflow: hidden; border-bottom: 1px solid var(--tg-border); }
.tg-card__img img { width: 100%; height: 100%; object-fit: cover; object-position: top center; display: block; }
.tg-card__over { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(15,23,42,.45); color: #fff; font-weight: 700; opacity: 0; transition: opacity .15s ease; }
.tg-card__img:hover .tg-card__over, .tg-card__img:focus-visible .tg-card__over { opacity: 1; }
.tg-card__img:focus-visible { outline: 3px solid rgba(29,78,216,.55); outline-offset: -3px; }
.tg-card__body { padding: 1rem 1.1rem 1.15rem; display: flex; flex-direction: column; gap: .6rem; flex: 1; }
.tg-card__title { margin: 0; font-size: 1.08rem; line-height: 1.3; }
.tg-card__title a { color: inherit; text-decoration: none; }
.tg-card__title a:hover { color: var(--tg-primary); }
.tg-card__meta { display: flex; flex-wrap: wrap; gap: .35rem .6rem; margin: 0; font-size: .82rem; color: var(--tg-muted); }
.tg-tag { border-radius: 999px; padding: .05rem .55rem; background: #eef2ff; color: #3730a3; }
.tg-tag--github { background: #ecfdf5; color: #065f46; }
.tg-card__actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: auto; padding-top: .3rem; }
.tg-card__actions .btn { flex: 1 1 110px; min-width: 0; padding: .55rem .6rem; font-size: .9rem; text-align: center; justify-content: center; white-space: normal; }
.tg-pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 2rem; flex-wrap: wrap; }
.tg-empty { text-align: center; padding: 3rem 1rem; max-width: 560px; margin: 0 auto; }

.tg-how { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.25rem; margin-bottom: 2.5rem; }
.tg-how div { background: #fff; border: 1px solid var(--tg-border); border-radius: 16px; padding: 1.25rem; }
.tg-how span { display: inline-flex; width: 2rem; height: 2rem; align-items: center; justify-content: center; border-radius: 50%; background: var(--tg-primary); color: #fff; font-weight: 700; margin-bottom: .5rem; }
.tg-how h3 { margin: 0 0 .3rem; } .tg-how p { margin: 0; color: var(--tg-muted); }
.tg-cta { text-align: center; max-width: 700px; margin: 0 auto; }
.tg-cta .btn { margin: .4rem; }

/* ---- detail ---- */
.tg-detail { padding: calc(var(--header-height, 76px) + 1.5rem) 0 3rem; }
.tg-crumbs { font-size: .88rem; color: var(--tg-muted); margin-bottom: 1rem; }
.tg-crumbs a { color: inherit; }
.tg-detail__grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 2rem; align-items: start; }
.tg-viewer { background: #fff; border: 1px solid var(--tg-border); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow-md, 0 10px 30px rgba(15,23,42,.08)); }
.tg-tabs { display: flex; gap: .25rem; padding: .5rem .6rem 0; border-bottom: 1px solid var(--tg-border); background: #f8fafc; flex-wrap: wrap; }
.tg-tab { border: 0; background: transparent; font: inherit; font-size: .9rem; padding: .55rem .9rem; border-radius: 10px 10px 0 0; cursor: pointer; color: var(--tg-muted); text-decoration: none; }
.tg-tab.is-on { background: #fff; color: #0f172a; font-weight: 600; box-shadow: inset 0 -2px 0 var(--tg-primary); }
.tg-tab--link { margin-left: auto; color: var(--tg-primary); }
.tg-chrome { display: flex; align-items: center; gap: .4rem; padding: .55rem .9rem; background: #f1f5f9; border-bottom: 1px solid var(--tg-border); }
.tg-chrome i { width: 10px; height: 10px; border-radius: 50%; background: #cbd5e1; display: block; }
.tg-chrome span { margin-left: .6rem; flex: 1; background: #fff; border-radius: 999px; padding: .15rem .8rem; font-size: .8rem; color: var(--tg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-scroll { height: min(78vh, 760px); overflow-y: auto; overflow-x: hidden; background: #fff; }
.tg-scroll img { width: 100%; height: auto; display: block; }
.tg-scroll:focus-visible { outline: 3px solid rgba(29,78,216,.45); outline-offset: -3px; }
.tg-frame { display: block; width: 100%; height: min(78vh, 760px); border: 0; background: #fff; }
.tg-note { margin: 0; padding: .6rem 1rem; font-size: .82rem; color: var(--tg-muted); border-top: 1px solid var(--tg-border); background: #f8fafc; }
.tg-pane[hidden] { display: none; }
.tg-side { position: sticky; top: 120px; }
.tg-side__cat { margin: 0 0 .3rem; font-size: .85rem; color: var(--tg-muted); text-transform: uppercase; letter-spacing: .06em; }
.tg-side h1 { font-size: 1.7rem; line-height: 1.2; margin: 0 0 .75rem; }
.tg-side__desc { color: #475569; margin: 0 0 1.25rem; }
.tg-side__cta { width: 100%; text-align: center; justify-content: center; }
.tg-side__small { font-size: .85rem; color: var(--tg-muted); margin: .7rem 0 1rem; }
.tg-facts { list-style: none; margin: 0 0 1.25rem; padding: 0; display: grid; gap: .4rem; font-size: .92rem; }
.tg-facts li::before { content: "\2713"; color: #16a34a; font-weight: 700; margin-right: .5rem; }
.tg-credit { border: 1px solid var(--tg-border); background: #f8fafc; border-radius: 14px; padding: .9rem 1rem; font-size: .9rem; }
.tg-credit h2 { font-size: .95rem; margin: 0 0 .4rem; }
.tg-credit p { margin: 0 0 .4rem; }
.tg-credit__small { color: var(--tg-muted); font-size: .8rem; margin: 0; }
.tg-related { margin-top: 3rem; }
.tg-related h2 { margin: 0 0 1rem; font-size: 1.35rem; }

@media (max-width: 960px) {
    .tg-detail__grid { grid-template-columns: 1fr; }
    .tg-side { position: static; order: -1; }
    .tg-scroll, .tg-frame { height: 70vh; }
}
@media (max-width: 560px) {
    .tg-search { flex-direction: column; }
    .tg-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { .tg-card, .tg-card__over { transition: none; } .tg-card:hover { transform: none; } }
