/* ==========================================================================
   Galería TakeOff — mosaico
   ========================================================================== */

.to-gallery {
    /* container-type habilita las unidades cqw, con las que calculamos la
       altura de fila a partir del ancho real de columna. */
    container-type: inline-size;
    width: 100%;
    margin: 0;
    padding: 0;
    background: var(--to-bg, #fff);
}

/* Galería a sangre: escapa del contenedor del tema. */
.to-gallery--fullbleed {
    width: 100vw;
    max-width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
}

/* --------------------------------------------------------------------------
   Retícula
   -------------------------------------------------------------------------- */

.to-gallery__grid {
    --cols: var(--to-cols, 4);
    --col-w: calc((100cqw - (var(--cols) - 1) * var(--to-gap, 6px)) / var(--cols));

    display: grid;
    grid-template-columns: repeat(var(--cols), 1fr);
    /* Fallback para navegadores sin unidades de contenedor. */
    grid-auto-rows: 22vw;
    grid-auto-rows: calc(var(--col-w) / var(--to-cell-aspect, 1));
    /* `dense` es lo que rellena los huecos al mezclar tamaños. */
    grid-auto-flow: dense;
    gap: var(--to-gap, 6px);
}

/* --------------------------------------------------------------------------
   Tile
   -------------------------------------------------------------------------- */

.to-tile {
    position: relative;
    grid-column: span var(--c, 1);
    grid-row: span var(--r, 1);
    margin: 0;
    padding: 0;
    overflow: hidden;
    border-radius: var(--to-radius, 0);
    background: #f2f0ed;
}

.to-gallery--single-mobile .to-tile {
    grid-column: span 1;
}

.to-tile__link {
    display: block;
    position: absolute;
    inset: 0;
    color: inherit;
    text-decoration: none;
}

.to-tile__media {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

/* Fotos, vídeos y miniaturas de YouTube se tratan exactamente igual: es lo que
   hace que un vídeo en bucle sea indistinguible de una foto. */
.to-tile__img,
.to-tile__video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: var(--fx, 50%) var(--fy, 50%);
    transition: transform .6s cubic-bezier(.2, .6, .2, 1);
    will-change: transform;
}

.to-tile__youtube {
    position: absolute;
    inset: 0;
}

.to-tile__youtube iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    pointer-events: none;
}

/* --------------------------------------------------------------------------
   Tile de texto  ("COLECCIÓN ~ Beau Rivage ~")
   -------------------------------------------------------------------------- */

.to-tile--text {
    background: var(--tile-bg, #fff);
    color: var(--tile-fg, #1c1a17);
    /* Sobre un fondo plano la viñeta se nota mucho más que sobre una foto,
       así que aquí va bastante más suave. */
    --to-vignette-alpha: .16;
    --to-vignette-blur: 52px;
}

.to-tile__text {
    position: absolute;
    inset: 0;
    transition: transform .55s cubic-bezier(.2, .6, .2, 1), letter-spacing .55s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .7em;
    padding: clamp(16px, 6%, 48px);
    text-align: center;
}

.to-tile__eyebrow {
    font-size: clamp(9px, 1.1cqw, 13px);
    letter-spacing: .28em;
    transition: letter-spacing .55s ease;
    text-transform: uppercase;
    opacity: .7;
}

.to-tile__heading {
    font-size: clamp(18px, 3.4cqw, 46px);
    line-height: 1.15;
    font-weight: 400;
    letter-spacing: .01em;
    text-wrap: balance;
}

/* --------------------------------------------------------------------------
   Overlay + caption
   -------------------------------------------------------------------------- */

/* Viñeta: sombra interior, que oscurece sólo los cantos y deja el centro
   limpio. Un radial-gradient se deformaría en los tiles 2x1. */
.to-tile__overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0;
    box-shadow: inset 0 0 var(--to-vignette-blur, 44px) var(--to-vignette-spread, 8px) rgba(0, 0, 0, var(--to-vignette-alpha, .34));
    transition: opacity .45s ease;
}

.to-tile__caption {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1em;
    font-size: clamp(10px, 1.1cqw, 13px);
    letter-spacing: .12em;
    text-transform: uppercase;
    line-height: 1.4;
}

.to-tile__title {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.to-tile__meta {
    flex: none;
    opacity: .75;
}

/* Caption debajo del tile, como en ejemplos/image (23).png */
.to-gallery--caption-below .to-tile--has-caption {
    background: var(--to-bg, #fff);
}

.to-gallery--caption-below .to-tile--has-caption .to-tile__media,
.to-gallery--caption-below .to-tile--has-caption .to-tile__overlay {
    bottom: 2.6em;
}

.to-gallery--caption-below .to-tile__caption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2.6em;
    align-items: center;
    color: inherit;
}

/* Pie centrado sobre la imagen, sólo al hover. */
.to-gallery--caption-center .to-tile__caption {
    position: absolute;
    inset: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .5em;
    padding: 1.2em;
    text-align: center;
    color: #fff;
    /* La viñeta sólo oscurece los cantos, así que el texto centrado se apoya
       en su propia sombra para mantener contraste sobre imágenes claras. */
    text-shadow: 0 1px 12px rgba(0, 0, 0, .55), 0 0 3px rgba(0, 0, 0, .4);
    opacity: 0;
    transform: translateY(.45em);
    transition: opacity .4s ease, transform .4s ease;
}

.to-gallery--caption-center .to-tile__title {
    flex: none;
    max-width: 100%;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    letter-spacing: .16em;
}

.to-gallery--caption-center .to-tile__meta {
    opacity: .9;
    letter-spacing: .1em;
}

/* Caption superpuesta, entrando desde abajo al hover. */
.to-gallery--caption-overlay .to-tile__caption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 1.2em;
    color: #fff;
    opacity: 0;
    transform: translateY(.6em);
    transition: opacity .4s ease, transform .4s ease;
}

.to-gallery--caption-overlay .to-tile--has-caption .to-tile__overlay {
    opacity: 0;
}

/* --------------------------------------------------------------------------
   Pie siempre visible
   Va después de las definiciones de posición para ganar el desempate de
   especificidad por orden de aparición.
   -------------------------------------------------------------------------- */

.to-gallery--cap-always .to-tile__caption {
    opacity: 1;
    transform: none;
}

/* El velo acompaña al pie: sin él, el texto claro se pierde sobre fotos claras.
   No aplica al pie «debajo del tile», que no se apoya en la imagen. */
.to-gallery--cap-always:not(.to-gallery--caption-below) .to-tile--has-caption .to-tile__overlay {
    opacity: 1;
}

/* --------------------------------------------------------------------------
   Hover
   -------------------------------------------------------------------------- */

@media (hover: hover) {
    .to-gallery--hover-zoom .to-tile:hover .to-tile__img,
    .to-gallery--hover-zoom .to-tile:hover .to-tile__video,
    .to-gallery--hover-both .to-tile:hover .to-tile__img,
    .to-gallery--hover-both .to-tile:hover .to-tile__video {
        transform: scale(1.045);
    }

    .to-gallery--hover-veil .to-tile:hover .to-tile__overlay,
    .to-gallery--hover-both .to-tile:hover .to-tile__overlay {
        opacity: 1;
    }

    .to-gallery--caption-overlay .to-tile:hover .to-tile__overlay,
    .to-gallery--caption-overlay .to-tile:focus-within .to-tile__overlay,
    .to-gallery--caption-center .to-tile:hover .to-tile__overlay,
    .to-gallery--caption-center .to-tile:focus-within .to-tile__overlay {
        opacity: 1;
    }

    .to-gallery--caption-center .to-tile:hover .to-tile__caption,
    .to-gallery--caption-center .to-tile:focus-within .to-tile__caption {
        opacity: 1;
        transform: none;
    }

    /* Los bloques de texto no tienen imagen que ampliar, así que su hover es el
       propio texto: se abre ligeramente y aparece la viñeta. */
    .to-tile--text:hover .to-tile__text,
    .to-tile--text:focus-within .to-tile__text {
        transform: scale(1.035);
    }

    .to-tile--text:hover .to-tile__eyebrow,
    .to-tile--text:focus-within .to-tile__eyebrow {
        letter-spacing: .36em;
    }

    .to-tile--text:hover .to-tile__overlay,
    .to-tile--text:focus-within .to-tile__overlay {
        opacity: 1;
    }

    .to-gallery--caption-overlay .to-tile:hover .to-tile__caption,
    .to-gallery--caption-overlay .to-tile:focus-within .to-tile__caption {
        opacity: 1;
        transform: none;
    }
}

/* En táctil la caption superpuesta debe verse siempre. */
@media (hover: none) {
    .to-gallery--caption-overlay .to-tile__caption,
    .to-gallery--caption-center .to-tile__caption {
        opacity: 1;
        transform: none;
    }

    .to-gallery--caption-overlay .to-tile--has-caption .to-tile__overlay,
    .to-gallery--caption-center .to-tile--has-caption .to-tile__overlay {
        opacity: 1;
    }
}

.to-tile__link:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: -4px;
}

/* --------------------------------------------------------------------------
   Cargar más
   -------------------------------------------------------------------------- */

.to-gallery__more {
    text-align: center;
    padding: 32px 0 8px;
}

.to-gallery__load-more {
    display: inline-block;
    padding: 13px 38px;
    font: inherit;
    font-size: 12px;
    letter-spacing: .18em;
    text-transform: uppercase;
    color: #1c1a17;
    background: transparent;
    border: 1px solid currentColor;
    border-radius: 0;
    cursor: pointer;
    transition: background .25s ease, color .25s ease;
}

.to-gallery__load-more:hover,
.to-gallery__load-more:focus-visible {
    background: #1c1a17;
    color: #fff;
}

.to-gallery__load-more[disabled] {
    opacity: .4;
    cursor: default;
}

.to-gallery__loader {
    text-align: center;
    padding: 16px 0;
}

.to-gallery__loader[hidden] {
    display: none;
}

.to-gallery__spinner {
    display: inline-block;
    width: 26px;
    height: 26px;
    border: 2px solid rgba(0, 0, 0, .15);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: to-spin .8s linear infinite;
}

@keyframes to-spin {
    to { transform: rotate(360deg); }
}

.to-gallery__sentinel {
    width: 100%;
    height: 1px;
    pointer-events: none;
}

/* --------------------------------------------------------------------------
   Breakpoints — cambia el nº de columnas, no la altura de fila
   -------------------------------------------------------------------------- */

@media (max-width: 1023px) {
    .to-gallery__grid { --cols: var(--to-cols-tablet, 3); }
}

@media (max-width: 767px) {
    .to-gallery__grid { --cols: var(--to-cols-mobile, 2); }
}

/* --------------------------------------------------------------------------
   Accesibilidad
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    .to-tile__img,
    .to-tile__video,
    .to-tile__overlay,
    .to-tile__caption,
    .to-tile__text,
    .to-tile__eyebrow {
        transition: none;
        transform: none;
    }

    .to-tile--text:hover .to-tile__text {
        transform: none;
    }

    .to-tile--text:hover .to-tile__eyebrow {
        letter-spacing: .28em;
    }

    .to-gallery--hover-zoom .to-tile:hover .to-tile__img,
    .to-gallery--hover-zoom .to-tile:hover .to-tile__video,
    .to-gallery--hover-both .to-tile:hover .to-tile__img,
    .to-gallery--hover-both .to-tile:hover .to-tile__video {
        transform: none;
    }

    .to-gallery__spinner { animation-duration: 2.4s; }
}

/* --------------------------------------------------------------------------
   Familias tipográficas de los bloques de texto
   Pilas del sistema: no cargan nada de fuera. Se amplían con el filtro PHP
   `takeoff_gallery_fonts` más el CSS correspondiente desde el tema.
   -------------------------------------------------------------------------- */

.to-tile--font-serif   { font-family: Georgia, 'Iowan Old Style', 'Times New Roman', Times, serif; }
.to-tile--font-sans    { font-family: 'Helvetica Neue', Helvetica, Arial, system-ui, sans-serif; }
.to-tile--font-display { font-family: 'Haettenschweiler', 'Arial Narrow', 'Franklin Gothic', Impact, sans-serif; }
.to-tile--font-script  { font-family: 'Snell Roundhand', 'Apple Chancery', 'Segoe Script', cursive; }
.to-tile--font-mono    { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; }
