#mytemplateModal .modal-dialog{
    border-radius: 15px;
}
#mytemplateModal .modal-header{
    display:inline-block;
}
#mytemplateModal .modal-body{
    overflow:auto;
    height: 500px;
}
#mytemplateModal .template-card {
    position: relative;
    overflow: hidden;
    border-radius: 10px;
    margin-bottom: 0px;
    height: 100%;
}
#mytemplateModal .template-img {
    width: 100%;
    display: block;
    height: 100%;
    object-fit: cover;
}
#mytemplateModal .template-card {
    border: 1px solid transparent;
}
#mytemplateModal .template-card:hover {
    box-shadow: 0 3px 3px 1px #f4433647;
    border: 1px solid #F44336;
}
#mytemplateModal .hover-icons {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    
    display: flex;
    gap: 10px;

    opacity: 0;
    transition: 0.3s ease;
    
    pointer-events: none;
}

#mytemplateModal .template-card:hover .hover-icons {
    opacity: 1;
    pointer-events: auto;
    z-index: 2;
}

#mytemplateModal .template-card::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.3);
    opacity: 0;
    transition: 0.3s;
}

#mytemplateModal.template-card:hover::after {
    opacity: 1;
}

#mytemplateModal .icon {
    pointer-events: auto;
    background: white;
    border-radius: 50%;
    padding: 10px;
    cursor: pointer;
    font-size: 18px;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}
#previewImage {
    transition: 0.3s;
}
#previewImage:hover {
    transform: scale(1.02);
}
#mytemplateModal .custom-filter a.active {
    border: 1px solid #F44336;
    color: #F44336;
    background: rgb(244 67 54 / 3%);
}
#mytemplateModal .custom-filter a:hover {
    background: #f5f5f5;
    border-color: #f5f5f5;
}
#mytemplateModal .custom-filter a {
    display: inline-block;
    text-decoration: none;
    margin-right: 5px;
    font-size: 14px;
    padding: 6px 15px;
    border: 1px solid #ddd;
    color: #555;
    border-radius: 20px;
    min-width: 57px;
    text-align: center;
    margin-bottom:4px;
}
#mytemplateModal .custom-filter {
    margin-bottom: 20px;
}
/* Stage 1 fix: template buttons always visible on touch screens; hidden buttons can't be tapped by accident */
#mytemplateModal .template-card { cursor: pointer; }
#mytemplateModal .template-card:not(:hover) .hover-icons .icon { pointer-events: none; }
@media (hover: none) {
    #mytemplateModal .hover-icons { opacity: 1; pointer-events: auto; top: auto; bottom: 8px; left: auto; right: 8px; transform: none; }
    #mytemplateModal .template-card .hover-icons .icon { pointer-events: auto; width: 44px; height: 44px; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
}

/* Phase 5 (20 Nov 2026): show every template whole, at its true aspect ratio (no cropping into a fixed box),
   two per row on tablets/desktops and one per row on phones so poems are easier to read. */
#mytemplateModal .template-card { height: auto; background: #fff; }
#mytemplateModal .template-img { height: auto; max-height: none; object-fit: contain; aspect-ratio: auto; }
#mytemplateModal .gallery-item-custom { align-self: flex-start; }
/* Phase 6 (20 Nov 2026): large, sharp preview of the full-resolution template file */
#previewModal .modal-body { text-align: center; background: #f7f7f7; }
#previewModal #previewImage { width: 100%; height: auto; max-height: 72vh; object-fit: contain; }
#previewModal #previewImage:hover { transform: none; }
#previewModal .modal-footer .btn-success { font-weight: 700; padding: 10px 22px; font-size: 1.05rem; }
/* Phase 7 (20 Nov 2026): phones - gallery list fits short screens; large preview uses the full screen */
@media (max-width: 575.98px) {
#mytemplateModal .modal-body { height: auto; max-height: calc(100vh - 150px); }
#previewModal .modal-body { padding: 8px; display: flex; align-items: center; justify-content: center; }
#previewModal #previewImage { max-height: none; }
#previewModal .modal-footer { justify-content: space-between; }
#previewModal .modal-footer .btn { flex: 1 1 auto; }
}