/**
 * Tile Grid Gallery - Frontend Styles
 */

/* Base Gallery Container */
.tgg-gallery {
    width: 100%;
    box-sizing: border-box;
}

.tgg-gallery *,
.tgg-gallery *::before,
.tgg-gallery *::after {
    box-sizing: border-box;
}

/* Gallery Item Base */
.tgg-gallery-item {
    position: relative;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border-radius: var(--tgg-radius, 8px);
}

.tgg-gallery-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.tgg-gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.5s ease;
}

.tgg-gallery-item:hover img {
    transform: scale(1.05);
}

/* Overlay */
.tgg-gallery-item::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0);
    transition: background 0.3s ease;
    pointer-events: none;
    border-radius: var(--tgg-radius, 8px);
}

.tgg-gallery-item:hover::after {
    background: rgba(0, 0, 0, 0.1);
}

/* ========================================
   Layout: Mosaic (タイルモザイク)
   ======================================== */
.tgg-gallery--mosaic {
    display: grid;
    grid-template-columns: repeat(var(--tgg-columns, 4), 1fr);
    grid-auto-rows: minmax(150px, auto);
    gap: var(--tgg-gap, 10px);
}

.tgg-gallery--mosaic .tgg-gallery-item:nth-child(7n+1) {
    grid-column: span 2;
    grid-row: span 2;
}

.tgg-gallery--mosaic .tgg-gallery-item:nth-child(7n+4) {
    grid-column: span 2;
}

.tgg-gallery--mosaic .tgg-gallery-item:nth-child(7n+6) {
    grid-row: span 2;
}

/* ========================================
   Layout: Circle (円形グリッド)
   ======================================== */
.tgg-gallery--circle {
    display: grid;
    grid-template-columns: repeat(var(--tgg-columns, 4), 1fr);
    gap: var(--tgg-gap, 10px);
}

.tgg-gallery--circle .tgg-gallery-item {
    aspect-ratio: 1;
    border-radius: 50% !important;
}

.tgg-gallery--circle .tgg-gallery-item::after {
    border-radius: 50% !important;
}

.tgg-gallery--circle .tgg-gallery-item:hover {
    transform: scale(1.08);
}

.tgg-gallery--circle .tgg-gallery-item:hover img {
    transform: scale(1.1);
}

/* ========================================
   Layout: Square (正方形タイル)
   ======================================== */
.tgg-gallery--square {
    display: grid;
    grid-template-columns: repeat(var(--tgg-columns, 4), 1fr);
    gap: var(--tgg-gap, 10px);
}

.tgg-gallery--square .tgg-gallery-item {
    aspect-ratio: 1;
}

/* 正方形は基本スタイルの角丸を継承 */

/* ========================================
   Layout: Column (タイルカラム/Masonry風)
   ======================================== */
.tgg-gallery--column {
    column-count: var(--tgg-columns, 4);
    column-gap: var(--tgg-gap, 10px);
}

.tgg-gallery--column .tgg-gallery-item {
    break-inside: avoid;
    margin-bottom: var(--tgg-gap, 10px);
}

/* カラムは基本スタイルの角丸を継承 */

.tgg-gallery--column .tgg-gallery-item img {
    height: auto;
}

/* ========================================
   Lightbox Styles
   ======================================== */
.tgg-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.tgg-lightbox.active {
    opacity: 1;
    visibility: visible;
}

.tgg-lightbox-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tgg-lightbox-image {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    opacity: 0;
    transform: scale(0.9);
    transition: opacity 0.3s ease, transform 0.3s ease;
    border-radius: 4px;
}

.tgg-lightbox.active .tgg-lightbox-image {
    opacity: 1;
    transform: scale(1);
}

.tgg-lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease, transform 0.3s ease;
    z-index: 10;
}

.tgg-lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.tgg-lightbox-close::before,
.tgg-lightbox-close::after {
    content: '';
    position: absolute;
    width: 24px;
    height: 2px;
    background: #fff;
}

.tgg-lightbox-close::before {
    transform: rotate(45deg);
}

.tgg-lightbox-close::after {
    transform: rotate(-45deg);
}

/* Navigation Arrows */
.tgg-lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease, transform 0.3s ease;
    z-index: 10;
}

.tgg-lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-50%) scale(1.1);
}

.tgg-lightbox-prev {
    left: 20px;
}

.tgg-lightbox-next {
    right: 20px;
}

.tgg-lightbox-nav::before {
    content: '';
    width: 14px;
    height: 14px;
    border-left: 3px solid #fff;
    border-bottom: 3px solid #fff;
}

.tgg-lightbox-prev::before {
    transform: rotate(45deg);
    margin-left: 4px;
}

.tgg-lightbox-next::before {
    transform: rotate(-135deg);
    margin-right: 4px;
}

/* Counter */
.tgg-lightbox-counter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Caption */
.tgg-lightbox-caption {
    position: absolute;
    bottom: 50px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: 16px;
    text-align: center;
    max-width: 80%;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 1024px) {
    .tgg-gallery--mosaic,
    .tgg-gallery--circle,
    .tgg-gallery--square {
        grid-template-columns: repeat(3, 1fr);
    }

    .tgg-gallery--column {
        column-count: 3;
    }
}

@media (max-width: 768px) {
    .tgg-gallery--mosaic,
    .tgg-gallery--circle,
    .tgg-gallery--square {
        grid-template-columns: repeat(2, 1fr);
    }

    .tgg-gallery--column {
        column-count: 2;
    }

    .tgg-gallery--mosaic .tgg-gallery-item:nth-child(7n+1),
    .tgg-gallery--mosaic .tgg-gallery-item:nth-child(7n+4) {
        grid-column: span 1;
    }

    .tgg-gallery--mosaic .tgg-gallery-item:nth-child(7n+6) {
        grid-row: span 1;
    }

    .tgg-lightbox-nav {
        width: 45px;
        height: 45px;
    }

    .tgg-lightbox-prev {
        left: 10px;
    }

    .tgg-lightbox-next {
        right: 10px;
    }
}

@media (max-width: 480px) {
    .tgg-gallery--mosaic,
    .tgg-gallery--circle,
    .tgg-gallery--square {
        grid-template-columns: repeat(2, 1fr);
    }

    .tgg-gallery--column {
        column-count: 1;
    }

    .tgg-lightbox-close {
        top: 10px;
        right: 10px;
        width: 40px;
        height: 40px;
    }
}

/* ========================================
   Loading State
   ======================================== */
.tgg-gallery-item--loading {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: tgg-shimmer 1.5s infinite;
}

@keyframes tgg-shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ========================================
   No JS Fallback
   ======================================== */
.no-js .tgg-gallery-item {
    cursor: default;
}

.no-js .tgg-lightbox {
    display: none;
}
