.template-library {
    position: relative;
    z-index: 12;
    width: min(100%, 78rem);
    margin: 2.6rem auto 0;
    padding: 0 var(--classic-page-pad) max(7rem, env(safe-area-inset-bottom));
}

.template-library__head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1.5rem;
    margin-bottom: 1rem;
}

.template-library__eyebrow {
    display: block;
    margin-bottom: .42rem;
    color: #64d5a4;
    font-size: .66rem;
    font-weight: 800;
    text-transform: uppercase;
}

.template-library h2 {
    margin: 0;
    max-width: 34rem;
    color: var(--t-text);
    font-size: 1.55rem;
    line-height: 1.12;
    font-weight: 730;
    letter-spacing: 0;
}

.template-library__intro {
    max-width: 24rem;
    margin: 0;
    color: var(--t-text-muted);
    font-size: .76rem;
    line-height: 1.55;
}

.template-library__tools {
    display: grid;
    grid-template-columns: minmax(12rem, 1fr) auto auto;
    gap: .55rem;
    margin-bottom: 1rem;
}

.template-library__search,
.template-library-dropdown__toggle {
    min-height: 2.75rem;
    border: 1px solid color-mix(in srgb, var(--t-border) 82%, transparent);
    border-radius: .7rem;
    background: color-mix(in srgb, var(--t-surface) 94%, transparent);
    color: var(--t-text);
    font: inherit;
    font-size: .76rem;
    outline: none;
    backdrop-filter: blur(18px);
}

.template-library__search { padding: 0 .9rem; }
.template-library__search:focus, .template-library-dropdown__toggle:focus { border-color: #64d5a4; }

.template-library-dropdown {
    position: relative;
    min-width: 10.5rem;
}

.template-library-dropdown__toggle {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: .7rem;
    padding: 0 .8rem 0 .9rem;
    cursor: pointer;
}

.template-library-dropdown__toggle span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.template-library-dropdown__toggle svg {
    width: .9rem;
    height: .9rem;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: .78;
    transition: transform 160ms ease;
}

.template-library-dropdown.is-open .template-library-dropdown__toggle svg { transform: rotate(180deg); }

.template-library-dropdown__menu {
    position: absolute;
    z-index: 30;
    left: 0;
    right: 0;
    top: calc(100% + .45rem);
    max-height: min(18rem, calc(100vh - 8rem));
    overflow: auto;
    padding: .38rem;
    border: 1px solid color-mix(in srgb, var(--t-border) 78%, transparent);
    border-radius: .75rem;
    background: color-mix(in srgb, #17191b 96%, var(--t-surface));
    box-shadow: 0 22px 60px rgb(0 0 0 / .36);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-.25rem) scale(.98);
    transform-origin: top;
    transition: opacity 140ms ease, transform 140ms ease, visibility 140ms ease;
    backdrop-filter: blur(20px);
}

.template-library-dropdown.is-open .template-library-dropdown__menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.template-library-dropdown__menu button {
    width: 100%;
    min-height: 2.35rem;
    display: flex;
    align-items: center;
    padding: 0 .72rem;
    border: 0;
    border-radius: .5rem;
    background: transparent;
    color: #f3f4f5;
    font: inherit;
    font-size: .74rem;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
}

.template-library-dropdown__menu button:hover,
.template-library-dropdown__menu button:focus-visible {
    outline: none;
    background: rgb(255 255 255 / .08);
}

.template-library-dropdown__menu button.is-active {
    background: color-mix(in srgb, var(--t-text) 14%, transparent);
    color: var(--t-text);
}

.template-library__grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .85rem;
}

.template-card {
    min-width: 0;
    overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--t-border) 82%, transparent);
    border-radius: .5rem;
    background: color-mix(in srgb, var(--t-surface) 96%, transparent);
    box-shadow: 0 18px 45px rgb(0 0 0 / .2);
    transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.template-card:hover, .template-card:focus-within {
    transform: translateY(-3px);
    border-color: color-mix(in srgb, #64d5a4 50%, var(--t-border));
    box-shadow: 0 24px 60px rgb(0 0 0 / .3);
}

.template-card__media {
    position: relative;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    background: #101214;
}

.template-card__media img, .template-card__media video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top;
}

.template-card__media video { opacity: 0; transition: opacity 160ms ease; }
.template-card.is-playing .template-card__media video { opacity: 1; }
.template-card__media::after {
    content: '';
    position: absolute;
    inset: auto 0 0;
    height: 34%;
    pointer-events: none;
    background: linear-gradient(transparent, rgb(0 0 0 / .52));
}

.template-card__preview {
    position: absolute;
    right: .55rem;
    bottom: .55rem;
    z-index: 2;
    min-height: 2rem;
    padding: 0 .65rem;
    border: 1px solid rgb(255 255 255 / .2);
    border-radius: .45rem;
    background: rgb(11 13 15 / .78);
    color: #fff;
    font-size: .64rem;
    font-weight: 700;
    cursor: pointer;
    backdrop-filter: blur(12px);
}

.template-card__body { padding: .85rem; }
.template-card__top { display: flex; align-items: flex-start; justify-content: space-between; gap: .7rem; }
.template-card h3 { margin: 0; color: var(--t-text); font-size: .92rem; line-height: 1.25; font-weight: 700; }
.template-card__author { margin-top: .18rem; color: var(--t-text-muted); font-size: .64rem; }
.template-card__description {
    min-height: 2.25rem;
    margin: .6rem 0 .7rem;
    overflow: hidden;
    color: var(--t-text-muted);
    font-size: .68rem;
    line-height: 1.55;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.template-card__tag {
    display: inline-flex;
    align-items: center;
    min-height: 1.55rem;
    padding: 0 .45rem;
    border: 1px solid color-mix(in srgb, var(--t-border) 88%, transparent);
    border-radius: .4rem;
    color: color-mix(in srgb, var(--t-text) 86%, transparent);
    background: color-mix(in srgb, #1f2225 88%, transparent);
    font-size: .58rem;
    font-weight: 750;
    text-transform: uppercase;
    white-space: nowrap;
}

.template-card__foot { display: flex; align-items: center; gap: .35rem; }
.template-card__metric, .template-card__install {
    min-height: 2.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .32rem;
    border-radius: .5rem;
    font: inherit;
    font-size: .66rem;
    font-weight: 700;
    cursor: pointer;
}
.template-card__metric {
    min-width: 2.65rem;
    padding: 0 .55rem;
    border: 1px solid var(--t-border);
    background: var(--t-surface-2);
    color: var(--t-text-muted);
}
.template-card__metric.is-active { color: #ff6f91; border-color: color-mix(in srgb, #ff6f91 44%, var(--t-border)); }
.template-card__install {
    flex: 1;
    padding: 0 .8rem;
    border: 0;
    background: var(--t-accent);
    color: var(--t-accent-text);
}
.template-card__install:disabled, .template-card__metric:disabled { opacity: .58; cursor: wait; }

.template-library__empty {
    grid-column: 1 / -1;
    min-height: 12rem;
    display: grid;
    place-items: center;
    border: 1px dashed var(--t-border);
    border-radius: .5rem;
    color: var(--t-text-muted);
    font-size: .78rem;
}

.template-comments { display: grid; gap: .7rem; }
.template-comments__list { max-height: 15rem; overflow: auto; display: grid; gap: .5rem; }
.template-comment { padding: .65rem; border: 1px solid var(--t-border); border-radius: .45rem; background: var(--t-surface-2); }
.template-comment strong { display: block; font-size: .68rem; }
.template-comment p { margin: .25rem 0 0; color: var(--t-text-muted); font-size: .7rem; line-height: 1.45; }
.template-comments textarea { width: 100%; min-height: 5rem; resize: vertical; box-sizing: border-box; padding: .7rem; border: 1px solid var(--t-border); border-radius: .5rem; background: var(--t-surface-2); color: var(--t-text); font: inherit; }

@media (max-width: 900px) {
    .template-library__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
    .template-library { margin-top: 1.7rem; padding-inline: .9rem; }
    .template-library__head { display: block; }
    .template-library__intro { margin-top: .65rem; }
    .template-library__tools { grid-template-columns: 1fr 1fr; }
    .template-library__search { grid-column: 1 / -1; }
    .template-library-dropdown { min-width: 0; }
    .template-library__grid { grid-template-columns: 1fr; gap: .7rem; }
    .template-card:hover { transform: none; }
}
