/* =========================================================================
   Ambient Gallery 3D - Frontend CSS
   Skalowanie przez CSS custom properties per instancja.
   Wszystko scopowane do .ag3d-instance, by nie kolidować z motywem.
   ========================================================================= */

.ag3d-instance,
.ag3d-instance * {
    box-sizing: border-box;
}

.ag3d-instance {
    position: relative;
    width: 100%;
    height: var(--ag3d-h, 100vh);
    min-height: 400px;
    background: var(--ag3d-bg, #000);
    color: var(--ag3d-text, #fff);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    isolation: isolate;
}

/* --- AMBIENT BG --- */
.ag3d-ambient-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
    background-size: cover;
    background-position: center;
    filter: grayscale(var(--ag3d-amb-grayscale, 100%))
            blur(var(--ag3d-amb-blur, 15px))
            brightness(var(--ag3d-amb-brightness, 0.6))
            opacity(var(--ag3d-amb-opacity, 0.6));
    transition: background-image var(--ag3d-amb-transition, 1000ms) ease-in-out;
    will-change: background-image;
    pointer-events: none;
}

/* --- VIGNETTE --- */
.ag3d-vignette {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: radial-gradient(circle at center,
        rgba(0,0,0,0.2) 0%,
        rgba(0,0,0,calc(0.95 * var(--ag3d-vignette, 0.95))) 100%);
    pointer-events: none;
}

/* --- HEADER --- */
.ag3d-header {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    z-index: 5;
    text-shadow: 0 2px 10px rgba(0,0,0,1);
    pointer-events: none;
    padding: 0 20px;
    max-width: 100%;
}

.ag3d-title {
    font-weight: 300;
    letter-spacing: 5px;
    text-transform: uppercase;
    margin: 0 0 10px;
    color: var(--ag3d-text, #fff);
    font-size: clamp(1rem, 2vw, 1.5rem);
}

.ag3d-hint {
    margin: 0;
    font-size: 0.9rem;
    opacity: 0.85;
    background: rgba(0,0,0,0.55);
    padding: 5px 15px;
    border-radius: 20px;
    display: inline-block;
    border: 1px solid rgba(255,255,255,0.2);
}

/* --- SCENE / CAROUSEL --- */
.ag3d-scene {
    width: var(--ag3d-card-w-d);
    height: var(--ag3d-card-h-d);
    perspective: 1200px;
    position: relative;
    z-index: 3;
    margin-top: -20px;
}

.ag3d-carousel {
    width: 100%;
    height: 100%;
    position: absolute;
    transform-style: preserve-3d;
    transition: transform var(--ag3d-rotation, 1000ms) var(--ag3d-easing, cubic-bezier(0.2, 0.8, 0.2, 1));
    will-change: transform;
}

.ag3d-cell {
    position: absolute;
    width: var(--ag3d-card-w-d);
    height: var(--ag3d-card-h-d);
    left: 0;
    top: 0;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: #000;
    overflow: hidden;
    border-radius: var(--ag3d-radius, 12px);
    box-shadow: 0 0 30px rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    cursor: pointer;
    transition: box-shadow 0.3s, border-color 0.3s, transform 0.3s;
    transform-origin: center center;
    backface-visibility: hidden;
}

.ag3d-cell:hover {
    border-color: var(--ag3d-accent);
    box-shadow: 0 0 calc(50px * var(--ag3d-glow, 0.5)) var(--ag3d-accent);
}

.ag3d-cell-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s;
    display: block;
}

.ag3d-cell:hover .ag3d-cell-img {
    transform: scale(1.05);
}

/* --- CAPTION --- */
.ag3d-cell-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 20px;
    background: linear-gradient(to top, rgba(0,0,0,0.95), transparent);
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.3s;
    pointer-events: none;
}

.ag3d-cell:hover .ag3d-cell-caption,
.ag3d-cell.is-active .ag3d-cell-caption,
.ag3d--always-caption .ag3d-cell-caption {
    transform: translateY(0);
    opacity: 1;
}

.ag3d--no-caption .ag3d-cell-caption {
    display: none;
}

.ag3d-cell-caption h3 {
    font-size: 1.2rem;
    margin: 0 0 5px;
    color: var(--ag3d-accent);
}

.ag3d-cell-caption p {
    font-size: 0.85rem;
    line-height: 1.4;
    color: #ddd;
    margin: 0 0 12px;
}

.ag3d-cell-caption p:last-child {
    margin-bottom: 0;
}

/* =========================================================================
   CTA BUTTON
   ========================================================================= */
.ag3d-cta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    padding: 9px 18px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-decoration: none;
    line-height: 1;
    pointer-events: auto;
    cursor: pointer;
    transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease, gap 0.25s ease;
    font-family: inherit;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ag3d-cta:focus-visible {
    outline: 2px solid var(--ag3d-accent);
    outline-offset: 3px;
}

.ag3d-cta-label {
    overflow: hidden;
    text-overflow: ellipsis;
}

.ag3d-cta-arrow {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    transition: transform 0.25s ease;
}

.ag3d-cta:hover .ag3d-cta-arrow {
    transform: translateX(4px);
}

/* --- Styl: Filled (wypełniony, dominujący) --- */
.ag3d-cta--filled {
    background: var(--ag3d-accent);
    color: #0a0a0a;
    border: 1px solid var(--ag3d-accent);
    box-shadow: 0 4px 14px -4px rgba(0, 0, 0, 0.5),
                0 0 0 0 var(--ag3d-accent);
}

.ag3d-cta--filled:hover {
    background: #fff;
    color: #0a0a0a;
    border-color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px -4px rgba(0, 0, 0, 0.6),
                0 0 25px -8px var(--ag3d-accent);
}

/* --- Styl: Outline (obramowany, subtelny) --- */
.ag3d-cta--outline {
    background: rgba(0, 0, 0, 0.3);
    color: var(--ag3d-accent);
    border: 1.5px solid var(--ag3d-accent);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.ag3d-cta--outline:hover {
    background: var(--ag3d-accent);
    color: #0a0a0a;
    border-color: var(--ag3d-accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 18px -4px rgba(0, 0, 0, 0.5);
}

/* --- Styl: Text (sam tekst ze strzałką, minimalistyczny) --- */
.ag3d-cta--text {
    background: transparent;
    color: var(--ag3d-accent);
    border: none;
    padding: 6px 4px;
    border-bottom: 1px solid transparent;
    border-radius: 0;
    font-weight: 500;
}

.ag3d-cta--text:hover {
    border-bottom-color: var(--ag3d-accent);
    gap: 12px;
    text-shadow: 0 0 12px rgba(255, 255, 255, 0.15);
}

/* --- REFLECTION --- */
.ag3d--reflection .ag3d-scene::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    height: 50%;
    background: inherit;
    transform: scaleY(-1);
    opacity: 0.15;
    filter: blur(10px);
    pointer-events: none;
    z-index: -1;
    mask-image: linear-gradient(to bottom, rgba(0,0,0,0.5) 0%, transparent 80%);
    -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,0.5) 0%, transparent 80%);
}

/* --- THUMBNAILS --- */
.ag3d-thumbs {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    padding: 8px 12px;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-radius: 50px;
    border: 1px solid rgba(255,255,255,0.2);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    max-width: calc(100% - 80px); /* JS nadpisze dokładną szerokość */
    overflow: hidden;            /* ucinamy poziomy scrollbar */
    /* miękka maska po bokach — thumbnaile fade-out w obrębie kontenera */
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 35px, #000 calc(100% - 35px), transparent 100%);
            mask-image: linear-gradient(to right, transparent 0, #000 35px, #000 calc(100% - 35px), transparent 100%);
}

.ag3d-thumbs-track {
    display: flex;
    gap: 15px;
    padding: 8px 0; /* mieści scale aktywnej miniaturki w pionie */
    transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: transform;
}

.ag3d--thumbs-top .ag3d-thumbs {
    bottom: auto;
    top: 30px;
}

.ag3d--no-thumbs .ag3d-thumbs {
    display: none;
}

.ag3d-thumb {
    flex-shrink: 0;
    width: 70px;
    height: 40px;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    opacity: 0.5;
    transition: all 0.3s;
    position: relative;
    padding: 0;
    background: transparent;
}

.ag3d-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.ag3d-thumb.is-active {
    opacity: 1;
    border-color: var(--ag3d-accent);
    transform: scale(1.2);
    box-shadow: 0 0 15px var(--ag3d-accent);
    z-index: 2;
}

/* --- NAV BUTTONS --- */
.ag3d-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,0.4);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 6;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    padding: 0;
}

.ag3d-nav:hover {
    background: var(--ag3d-accent);
    color: #000;
    border-color: var(--ag3d-accent);
    transform: translateY(-50%) scale(1.1);
}

.ag3d-nav--prev { left: 40px; }
.ag3d-nav--next { right: 40px; }

.ag3d--no-nav .ag3d-nav { display: none; }

/* --- LIGHTBOX --- */
.ag3d-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.98);
    z-index: 999999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.ag3d-lightbox.is-active {
    opacity: 1;
    pointer-events: auto;
}

.ag3d-lightbox-stage {
    max-width: 90vw;
    max-height: 85vh;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ag3d-lightbox-img {
    max-width: 90vw;
    max-height: 85vh;
    border-radius: 5px;
    box-shadow: 0 0 50px rgba(0,0,0,0.8);
    transform: scale(0.9);
    transition: transform 0.3s;
    cursor: zoom-in;
}

.ag3d-lightbox.is-active .ag3d-lightbox-img {
    transform: scale(1);
}

.ag3d-lightbox.is-zoomed .ag3d-lightbox-img {
    transform: scale(2);
    cursor: zoom-out;
}

.ag3d-lightbox-close,
.ag3d-lightbox-prev,
.ag3d-lightbox-next {
    position: absolute;
    background: transparent;
    border: 0;
    color: #fff;
    cursor: pointer;
    transition: color 0.3s, transform 0.3s;
    line-height: 1;
}

.ag3d-lightbox-close {
    top: 30px;
    right: 30px;
    font-size: 50px;
}

.ag3d-lightbox-prev,
.ag3d-lightbox-next {
    top: 50%;
    transform: translateY(-50%);
    font-size: 40px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(255,255,255,0.05);
}

.ag3d-lightbox-prev { left: 30px; }
.ag3d-lightbox-next { right: 30px; }

.ag3d-lightbox-close:hover,
.ag3d-lightbox-prev:hover,
.ag3d-lightbox-next:hover {
    color: var(--ag3d-accent);
}

.ag3d-lightbox-caption {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.6);
    padding: 8px 20px;
    border-radius: 20px;
    color: #fff;
    font-size: 0.9rem;
    max-width: 90%;
    text-align: center;
}

/* --- HEADER HIDDEN --- */
.ag3d--no-header .ag3d-header { display: none; }

/* --- ENTRY ANIMATIONS --- */
.ag3d--anim-fade .ag3d-cell { animation: ag3dFadeIn 0.8s ease-out backwards; }
.ag3d--anim-scale .ag3d-cell { animation: ag3dScaleIn 0.8s ease-out backwards; }
.ag3d--anim-slide .ag3d-cell { animation: ag3dSlideUp 0.8s ease-out backwards; }

.ag3d-cell:nth-child(1) { animation-delay: 0.05s; }
.ag3d-cell:nth-child(2) { animation-delay: 0.10s; }
.ag3d-cell:nth-child(3) { animation-delay: 0.15s; }
.ag3d-cell:nth-child(4) { animation-delay: 0.20s; }
.ag3d-cell:nth-child(5) { animation-delay: 0.25s; }
.ag3d-cell:nth-child(6) { animation-delay: 0.30s; }
.ag3d-cell:nth-child(7) { animation-delay: 0.35s; }
.ag3d-cell:nth-child(8) { animation-delay: 0.40s; }

@keyframes ag3dFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes ag3dScaleIn {
    from { opacity: 0; transform: var(--ag3d-cell-tf, none) scale(0.7); }
    to   { opacity: 1; }
}
@keyframes ag3dSlideUp {
    from { opacity: 0; transform: var(--ag3d-cell-tf, none) translateY(40px); }
    to   { opacity: 1; }
}

/* =========================================================================
   RESPONSIVE - TABLET
   ========================================================================= */
@media (max-width: 1024px) {
    .ag3d-scene {
        width: var(--ag3d-card-w-t);
        height: var(--ag3d-card-h-t);
    }
    .ag3d-cell {
        width: var(--ag3d-card-w-t);
        height: var(--ag3d-card-h-t);
    }
    .ag3d-nav--prev { left: 15px; }
    .ag3d-nav--next { right: 15px; }
}

/* =========================================================================
   RESPONSIVE - MOBILE
   ========================================================================= */
@media (max-width: 768px) {
    .ag3d-scene {
        width: var(--ag3d-card-w-m);
        height: var(--ag3d-card-h-m);
        margin-top: 0;
    }
    .ag3d-cell {
        width: var(--ag3d-card-w-m);
        height: var(--ag3d-card-h-m);
    }
    .ag3d-instance:not(.ag3d--nav-mobile) .ag3d-nav { display: none; }
    .ag3d--nav-mobile .ag3d-nav {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    .ag3d-thumbs {
        bottom: 10px;
        padding: 5px 10px;
        -webkit-mask-image: linear-gradient(to right, transparent 0, #000 22px, #000 calc(100% - 22px), transparent 100%);
                mask-image: linear-gradient(to right, transparent 0, #000 22px, #000 calc(100% - 22px), transparent 100%);
    }
    .ag3d-thumbs-track {
        gap: 10px;
        padding: 6px 0;
    }
    .ag3d-thumb {
        width: 50px;
        height: 28px;
    }
    .ag3d-title {
        font-size: 1.1rem;
        letter-spacing: 3px;
    }
    .ag3d-hint {
        font-size: 0.75rem;
        padding: 4px 12px;
    }
    .ag3d-lightbox-close { top: 15px; right: 15px; font-size: 36px; }
    .ag3d-lightbox-prev { left: 10px; font-size: 26px; width: 44px; height: 44px; }
    .ag3d-lightbox-next { right: 10px; font-size: 26px; width: 44px; height: 44px; }

    /* CTA mniejszy na mobile */
    .ag3d-cta {
        font-size: 0.78rem;
        padding: 7px 14px;
        gap: 6px;
    }
    .ag3d-cell-caption {
        padding: 14px;
    }
    .ag3d-cell-caption h3 {
        font-size: 1rem;
    }
    .ag3d-cell-caption p {
        font-size: 0.78rem;
        margin-bottom: 8px;
    }
}

/* Prefers reduced motion */
@media (prefers-reduced-motion: reduce) {
    .ag3d-carousel,
    .ag3d-cell,
    .ag3d-cell-img,
    .ag3d-ambient-bg,
    .ag3d-cell-caption,
    .ag3d-lightbox,
    .ag3d-lightbox-img {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}
