/**
 * tk-tiktok-gallery — Front-end
 * Prefisso classi: .tk-ttg-*  (mai classi globali)
 */

:root {
    --tk-ttg-nav-radius: 50%;
    --tk-ttg-nav-bg-car: rgba(255,255,255,.92);
    --tk-ttg-nav-ico-car: #111;
    --tk-ttg-nav-bg-lb: rgba(255,255,255,.14);
    --tk-ttg-nav-bg-lb-hover: rgba(255,255,255,.28);
}

/* ── Griglia ─────────────────────────────────────────── */
.tk-ttg-gallery {
    --tk-ttg-cols: 3;
    --tk-ttg-gap: 6px;
    --tk-ttg-radius: 8px;
    position: relative;
    display: grid;
    grid-template-columns: repeat(var(--tk-ttg-cols), minmax(0, 1fr));
    gap: var(--tk-ttg-gap);
    margin: 0 0 18px;
}

.tk-ttg-item { min-width: 0; }

.tk-ttg-thumb-wrap {
    position: relative;
    display: block;
    overflow: hidden;
    border-radius: var(--tk-ttg-radius);
    background: #111;
    aspect-ratio: 9 / 16;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    text-decoration: none;
}

.tk-ttg-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform .35s cubic-bezier(.4,0,.2,1);
}
.tk-ttg-thumb-wrap:hover .tk-ttg-thumb { transform: scale(1.05); }

.tk-ttg-thumb-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 34px;
    background: linear-gradient(135deg, #25f4ee 0%, #fe2c55 100%);
}

/* ── Icona play ──────────────────────────────────────── */
.tk-ttg-play {
    position: absolute;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    width: 46px; height: 46px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    color: #fff;
    pointer-events: none;
    transition: transform .2s ease, opacity .2s ease;
    opacity: .95;
}
.tk-ttg-thumb-wrap:hover .tk-ttg-play { transform: translate(-50%, -50%) scale(1.12); opacity: 1; }
.tk-ttg-play svg { margin-left: 2px; }

.tk-ttg-play-tiktok  { background: linear-gradient(135deg, #25f4ee 0%, #fe2c55 100%); box-shadow: 0 4px 14px rgba(254,44,85,.4); }
.tk-ttg-play-filled  { background: rgba(0,0,0,.55); }
.tk-ttg-play-outline { background: rgba(0,0,0,.45); }
.tk-ttg-play-outline svg { fill: none; stroke: #fff; stroke-width: 2; stroke-linejoin: round; }
.tk-ttg-play-circle  { background: rgba(0,0,0,.5); border: 2px solid #fff; }
.tk-ttg-play-glass   { background: rgba(255,255,255,.2); border: 1px solid rgba(255,255,255,.35); backdrop-filter: blur(4px); }

/* ── Anteprima nella miniatura ───────────────────────── */
.tk-ttg-preview {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    background: #000;
    z-index: 2;
    animation: tk-ttg-fade .25s ease;
}
@keyframes tk-ttg-fade { from { opacity: 0; } to { opacity: 1; } }

/* Mentre l'anteprima gira, play e didascalia si tolgono di mezzo */
.tk-ttg-previewing .tk-ttg-play,
.tk-ttg-previewing .tk-ttg-overlay,
.tk-ttg-previewing .tk-ttg-duration { opacity: 0; }

/* Il click deve restare della miniatura, non finire nell'iframe */
.tk-ttg-previewing .tk-ttg-preview { pointer-events: none; }

/* ── Durata + didascalia ─────────────────────────────── */
.tk-ttg-duration {
    position: absolute;
    right: 8px; bottom: 8px;
    background: rgba(0,0,0,.6);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 4px;
    line-height: 1.5;
    letter-spacing: .3px;
}

.tk-ttg-overlay {
    position: absolute;
    inset: auto 0 0 0;
    padding: 26px 10px 10px;
    background: linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(0,0,0,.78) 100%);
    opacity: 0;
    transition: opacity .25s ease;
    pointer-events: none;
}
.tk-ttg-thumb-wrap:hover .tk-ttg-overlay { opacity: 1; }
.tk-ttg-caption {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: #fff;
    font-size: 12px;
    line-height: 1.45;
}

/* La didascalia con durata non deve finirci sotto */
.tk-ttg-item:has(.tk-ttg-duration) .tk-ttg-overlay { padding-bottom: 30px; }

/* ── Masonry ─────────────────────────────────────────── */
.tk-ttg-layout-masonry {
    display: block;
    column-count: var(--tk-ttg-cols);
    column-gap: var(--tk-ttg-gap);
}
.tk-ttg-layout-masonry .tk-ttg-item {
    break-inside: avoid;
    margin-bottom: var(--tk-ttg-gap);
}
.tk-ttg-layout-masonry .tk-ttg-thumb-wrap { aspect-ratio: auto; }
.tk-ttg-layout-masonry .tk-ttg-thumb { height: auto; }

/* ── Carousel ────────────────────────────────────────── */
.tk-ttg-layout-carousel {
    display: block;
    padding: 0 4px;
}
.tk-ttg-carousel-track {
    display: flex;
    gap: var(--tk-ttg-gap);
    overflow-x: auto;
    scroll-behavior: smooth;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.tk-ttg-carousel-track::-webkit-scrollbar { display: none; }
.tk-ttg-layout-carousel .tk-ttg-item {
    flex: 0 0 calc((100% - (var(--tk-ttg-cols) - 1) * var(--tk-ttg-gap)) / var(--tk-ttg-cols));
    scroll-snap-align: start;
}

.tk-ttg-carousel-prev,
.tk-ttg-carousel-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 4;
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    border: 0;
    border-radius: var(--tk-ttg-nav-radius);
    background: var(--tk-ttg-nav-bg-car);
    color: var(--tk-ttg-nav-ico-car);
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,.18);
    transition: transform .15s ease, opacity .15s ease;
}
.tk-ttg-carousel-prev { left: -6px; }
.tk-ttg-carousel-next { right: -6px; }
.tk-ttg-carousel-prev:hover,
.tk-ttg-carousel-next:hover { transform: translateY(-50%) scale(1.08); }
.tk-ttg-carousel-prev[disabled],
.tk-ttg-carousel-next[disabled] { opacity: 0; pointer-events: none; }

/* ── Footer / follow ─────────────────────────────────── */
.tk-ttg-footer { text-align: center; margin: 4px 0 20px; }
.tk-ttg-follow-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 22px;
    background: #111;
    color: #fff !important;
    border-radius: 50px;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none !important;
    transition: transform .15s ease, box-shadow .15s ease;
}
.tk-ttg-follow-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(254,44,85,.32);
    background: linear-gradient(135deg, #25f4ee 0%, #fe2c55 100%);
}

/* ── Errori (visibili solo agli amministratori) ──────── */
.tk-ttg-error {
    padding: 14px 18px;
    border-left: 4px solid #fe2c55;
    background: #fff5f7;
    color: #7f1d2b;
    font-size: 14px;
    border-radius: 6px;
    margin: 0 0 18px;
}

/* ── Lightbox ────────────────────────────────────────── */
.tk-ttg-lb {
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: rgba(0,0,0,.92);
    /* Colonna: player e didascalia impilati, così la didascalia non può
       finire sopra al video per quanto lungo sia il testo. */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 64px 16px 28px;
    box-sizing: border-box;
}
.tk-ttg-lb[hidden] { display: none; }

.tk-ttg-lb-content {
    position: relative;
    width: min(94vw, 420px);
    aspect-ratio: 9 / 16;
    max-height: calc(100vh - 150px);
    flex: 0 1 auto;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.tk-ttg-lb-content iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

.tk-ttg-lb-close,
.tk-ttg-lb-prev,
.tk-ttg-lb-next {
    position: absolute;
    display: flex; align-items: center; justify-content: center;
    border: 0;
    background: var(--tk-ttg-nav-bg-lb);
    color: #fff;
    cursor: pointer;
    border-radius: var(--tk-ttg-nav-radius);
    transition: background .15s ease, transform .15s ease;
}
.tk-ttg-lb-close:hover,
.tk-ttg-lb-prev:hover,
.tk-ttg-lb-next:hover { background: var(--tk-ttg-nav-bg-lb-hover); transform: scale(1.06); }

.tk-ttg-lb-close { top: 18px; right: 18px; width: 42px; height: 42px; font-size: 26px; line-height: 1; }
.tk-ttg-lb-prev  { left: 18px;  top: 50%; margin-top: -24px; width: 48px; height: 48px; }
.tk-ttg-lb-next  { right: 18px; top: 50%; margin-top: -24px; width: 48px; height: 48px; }
/* Le frecce sono ancorate al viewport, non al player: restano fuori dal video */
.tk-ttg-lb-close, .tk-ttg-lb-prev, .tk-ttg-lb-next { position: fixed; }

.tk-ttg-lb-caption {
    flex: 0 0 auto;
    max-width: min(92vw, 560px);
    color: #fff;
    font-size: 13px;
    line-height: 1.5;
    text-align: center;
    text-shadow: 0 1px 3px rgba(0,0,0,.8);
    /* Massimo 2 righe: le descrizioni TikTok sono lunghissime */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.tk-ttg-lb-caption:empty { display: none; }
.tk-ttg-lb-counter {
    position: fixed;
    top: 24px; left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,.75);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .5px;
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 782px) {
    .tk-ttg-gallery { --tk-ttg-cols: 2; }
    .tk-ttg-layout-masonry { column-count: 2; }
    .tk-ttg-layout-carousel .tk-ttg-item { flex-basis: calc((100% - var(--tk-ttg-gap)) / 2); }
    .tk-ttg-play { width: 40px; height: 40px; }
    .tk-ttg-lb-prev, .tk-ttg-lb-next { width: 40px; height: 40px; margin-top: -20px; }
    .tk-ttg-lb-prev { left: 6px; }
    .tk-ttg-lb-next { right: 6px; }
    .tk-ttg-lb { padding: 54px 0 20px; gap: 10px; }
    .tk-ttg-lb-content { width: 100vw; max-height: calc(100vh - 120px); border-radius: 0; }
    .tk-ttg-lb-caption { font-size: 12px; padding: 0 14px; }
}

@media (max-width: 480px) {
    .tk-ttg-gallery { --tk-ttg-cols: 1; }
    .tk-ttg-layout-masonry { column-count: 1; }
    .tk-ttg-layout-carousel .tk-ttg-item { flex-basis: 78%; }
}

@media (prefers-reduced-motion: reduce) {
    .tk-ttg-thumb, .tk-ttg-play, .tk-ttg-overlay, .tk-ttg-follow-btn { transition: none; }
    .tk-ttg-carousel-track { scroll-behavior: auto; }
}
