.prism-maker-template-gallery {
    --prism-gallery-card-bg: rgba(15, 23, 42, 0.54);
    --prism-gallery-card-hover-bg: rgba(15, 23, 42, 0.76);
    --prism-gallery-card-selected-bg: rgba(16, 185, 129, 0.11);
    --prism-gallery-border: rgba(148, 163, 184, 0.22);
    --prism-gallery-thumbnail-border: rgba(148, 163, 184, 0.18);
    --prism-gallery-text: #e2e8f0;
    --prism-gallery-title: #f8fafc;
    --prism-gallery-description: rgba(226, 232, 240, 0.72);
    --prism-gallery-accent: #10b981;
    --prism-gallery-accent-rgb: 16, 185, 129;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

html[data-theme="light"] .prism-maker-template-gallery {
    --prism-gallery-card-bg: #ffffff;
    --prism-gallery-card-hover-bg: #f8fafc;
    --prism-gallery-card-selected-bg: rgba(180, 83, 9, 0.10);
    --prism-gallery-border: #d8dee8;
    --prism-gallery-thumbnail-border: #d8dee8;
    --prism-gallery-text: #334155;
    --prism-gallery-title: #0f172a;
    --prism-gallery-description: #475569;
    --prism-gallery-accent: #b45309;
    --prism-gallery-accent-rgb: 180, 83, 9;
}

.prism-maker-template-gallery__topbar {
    display: grid;
    grid-template-columns: minmax(190px, 1.4fr) minmax(150px, 1fr) minmax(130px, 180px) auto;
    gap: 12px;
    align-items: center;
}

.prism-maker-template-gallery__intro { min-width: 0; }
.prism-maker-template-gallery__title { color: var(--prism-gallery-title); font-weight: 800; font-size: .95rem; }
.prism-maker-template-gallery__hint { color: var(--prism-gallery-description); font-size: .78rem; line-height: 1.35; margin-top: 3px; }

.prism-maker-template-gallery .prism-template-gallery__grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.prism-maker-template-gallery .prism-template-card {
    appearance: none;
    border: 1px solid var(--prism-gallery-border);
    background: var(--prism-gallery-card-bg);
    color: var(--prism-gallery-text);
    border-radius: 8px;
    padding: 10px;
    text-align: left;
    cursor: pointer;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 9px;
    transition: border-color .15s ease, background .15s ease, transform .15s ease;
}

.prism-maker-template-gallery .prism-template-card:hover,
.prism-maker-template-gallery .prism-template-card:focus-visible {
    border-color: rgba(var(--prism-gallery-accent-rgb), .68);
    background: var(--prism-gallery-card-hover-bg);
    outline: none;
    transform: translateY(-1px);
}

.prism-maker-template-gallery .prism-template-card.is-selected {
    border-color: var(--prism-gallery-accent);
    box-shadow: 0 0 0 1px rgba(var(--prism-gallery-accent-rgb), .56);
    background: var(--prism-gallery-card-selected-bg);
}

.prism-maker-template-gallery .prism-template-card__meta {
    min-height: 78px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.prism-maker-template-gallery .prism-template-card__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.prism-maker-template-gallery .prism-template-card__title {
    font-size: .92rem;
    line-height: 1.2;
    font-weight: 750;
    color: var(--prism-gallery-title);
}

.prism-maker-template-gallery .prism-template-card__description {
    color: var(--prism-gallery-description);
    font-size: .76rem;
    line-height: 1.32;
}

.prism-maker-template-gallery .prism-template-card__action {
    margin-top: auto;
    padding-top: 6px;
    color: var(--prism-gallery-accent);
    font-size: .76rem;
    font-weight: 800;
}

/* Example previews: lay the visual out at its NATIVE size, then scale the whole frame down.
 *
 * An iframe does not shrink its document — it just gives it a smaller viewport. These previews
 * were sized width:100%/height:100% into a ~300px card, so the template's
 * `.visual-stage{width:min(1080px,100%);min-height:520px}` collapsed to ~300px wide while keeping
 * its 520px height, overflowed a 169px-tall box and was cut off. Type stayed at full size inside a
 * narrow column, which is why it also read as oversized. Both symptoms, one cause.
 *
 * So the iframe is given the room the template was designed for — 1080px stage plus the 28px body
 * padding either side — and transform-scaled to fit the card. Layout happens at the size the
 * design assumes; only the pixels shrink. --preview-native-* stay in one place so a change to the
 * template stage width has a single edit site. */
.prism-maker-template-preview {
    --preview-native-width: 1136px;
    --preview-native-height: 576px;

    display: block;
    position: relative;
    width: 100%;
    /* Match the content's own proportions rather than an unrelated 16:9, or the scaled frame
       leaves a band of dead space inside the card. */
    aspect-ratio: 1136 / 576;
    container-type: inline-size;
    overflow: hidden;
    border: 1px solid var(--prism-gallery-thumbnail-border);
    border-radius: 7px;
    background: #f8fafc;
    pointer-events: none;
}

.prism-maker-template-preview iframe {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: var(--preview-native-width);
    height: var(--preview-native-height);
    border: 0;
    pointer-events: none;
    transform: scale(calc(100cqw / var(--preview-native-width)));
    transform-origin: top left;
}

.prism-maker-template-confirm {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.1rem;
    border: 1px solid rgba(var(--prism-gallery-accent-rgb), .45);
    border-radius: 12px;
    background: rgba(var(--prism-gallery-accent-rgb), .08);
}

.prism-maker-template-confirm strong { display: block; color: var(--prism-gallery-title); font-size: .9rem; }
.prism-maker-template-confirm span { display: block; color: var(--prism-gallery-description); font-size: .78rem; margin-top: .25rem; }
.prism-maker-template-confirm__actions { display: flex; flex: 0 0 auto; align-items: center; gap: .35rem; }

@media (max-width: 1050px) {
    .prism-maker-template-gallery__topbar { grid-template-columns: minmax(190px, 1fr) minmax(150px, 1fr) auto; }
    .prism-maker-template-gallery__intro { grid-column: 1 / -1; }
}

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

@media (max-width: 600px) {
    .prism-maker-template-gallery__topbar { grid-template-columns: 1fr; }
    .prism-maker-template-gallery .prism-template-gallery__grid { grid-template-columns: 1fr; }
    .prism-maker-template-confirm { align-items: flex-start; flex-direction: column; }
}
