/**
 * Whitesand gallery (page-gallery.php, assets/js/gallery.js). DESIGN.md §6.23.
 *
 * Without JavaScript: a plain photo grid under the page title.
 * With it (html.ws-gal-live): a full-screen wall you drag and zoom, a glass title panel at the
 * bottom inline-start, zoom lenses at the bottom inline-end, and a detail view.
 * Tokens: the shared .ws-ui set (components.css §5). One radius rule: 20px frames, pill buttons,
 * round lenses.
 */

.ws-gal {
    --g-tile-bg: #EEF2F3;
    --g-glass: rgba(249, 254, 255, 0.72);
    --g-glass-line: rgba(224, 224, 224, 0.6);
    --g-veil: rgba(249, 254, 255, 0.94);
    --g-shadow: 0 4px 24px -1px rgba(30, 30, 30, 0.06);
    display: flex;
    flex-direction: column;
    background: var(--p-bg);
    color: var(--p-ink);
}
html.dark .ws-gal {
    --g-tile-bg: #1B1B1B;
    --g-glass: rgba(30, 30, 30, 0.72);
    --g-glass-line: rgba(255, 255, 255, 0.12);
    --g-veil: rgba(18, 18, 18, 0.94);
    --g-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.36);
}

/* ---------------------------------------------------------------- shared pieces */

.ws-gal [hidden] { display: none !important; }

.ws-gal__glass {
    background: var(--g-glass);
    border: 1px solid var(--g-glass-line);
    box-shadow: var(--g-shadow);
    -webkit-backdrop-filter: blur(20px) saturate(140%);
    backdrop-filter: blur(20px) saturate(140%);
}
@media (prefers-reduced-transparency: reduce) {
    .ws-gal__glass { background: var(--p-bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
}

.ws-gal__lens {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--p-ink);
    cursor: pointer;
    transition: background-color 0.25s ease, transform 0.2s ease;
}
.ws-gal__lens:hover { background: var(--p-surface); }
.ws-gal__lens:active { transform: scale(0.94); }
.ws-gal__lens:focus-visible { outline: 1px solid var(--p-ink); outline-offset: 2px; }
.ws-gal__lens[disabled] { opacity: 0.35; cursor: default; }
.ws-gal__lens .ws-ico { width: 20px; height: 20px; }

/* ---------------------------------------------------------------- page title and filters */

.ws-gal__intro {
    order: -1;
    padding: clamp(24px, 4vw, 48px) var(--p-gutter) 8px;
    border: 0;
    background: none;
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}
.ws-gal__title {
    margin: 0;
    font-size: clamp(1.8rem, 1.2rem + 1.8vw, 2.6rem);
    font-weight: 300;
    line-height: 1.25;
    letter-spacing: -0.01em;
}
.ws-gal__title:lang(fa),
[dir="rtl"] .ws-gal__title { letter-spacing: 0; line-height: 1.5; }
.ws-gal__lead {
    margin: 8px 0 0;
    max-width: 34ch;
    font-size: 15px;
    line-height: 1.7;
}

.ws-gal__filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 16px;
}
.ws-gal__filters button {
    min-height: 36px;
    padding: 0 16px;
    border: 1px solid var(--p-line);
    border-radius: 9999px;
    background: transparent;
    color: var(--p-ink);
    font: inherit;
    font-size: 14px;
    cursor: pointer;
    transition: border-color 0.3s ease, background-color 0.3s ease, color 0.3s ease;
}
.ws-gal__filters button:hover { border-color: var(--p-ink); }
.ws-gal__filters button[aria-pressed="true"] { background: var(--p-ink); border-color: var(--p-ink); color: var(--p-bg); }
.ws-gal__filters button:focus-visible { outline: 1px solid var(--p-ink); outline-offset: 3px; }

/* ---------------------------------------------------------------- the wall: plain grid (no JavaScript) */

.ws-gal__stage { padding: 24px var(--p-gutter) clamp(64px, 8vw, 112px); }
.ws-gal__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(220px, 44vw), 1fr));
    gap: clamp(10px, 1.6vw, 20px);
    margin: 0;
    padding: 0;
    list-style: none;
}
.ws-gal__cell { margin: 0; aspect-ratio: 4 / 5; }
.ws-gal__cell.is-filtered { display: none; }

.ws-gal__tile {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: 20px;
    background: var(--g-tile-bg);
    color: inherit;
    -webkit-tap-highlight-color: transparent;
}
.ws-gal__tile::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow: inset 0 0 0 1px var(--p-line);
    pointer-events: none;
    transition: box-shadow 0.4s ease;
}
.ws-gal__tile img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
    -webkit-user-drag: none;
}
.ws-gal__tile:focus-visible { outline: 2px solid var(--p-ink); outline-offset: 4px; }
@media (hover: hover) and (pointer: fine) {
    .ws-gal__tile:hover img { transform: scale(1.03); }
    .ws-gal__tile:hover::after { box-shadow: inset 0 0 0 1px var(--p-soft); }
}

.ws-gal__empty {
    display: grid;
    justify-items: center;
    gap: 20px;
    padding: clamp(48px, 10vw, 120px) 0;
    color: var(--p-soft);
    text-align: center;
}
.ws-gal__empty-mark { display: block; width: 72px; opacity: 0.5; }
.ws-gal__empty-mark svg { width: 100%; height: auto; display: block; }

/* ---------------------------------------------------------------- the wall: live canvas */

html.ws-gal-live,
html.ws-gal-live body { height: 100%; overflow: hidden; overscroll-behavior: none; }

html.ws-gal-live .ws-gal__stage {
    position: fixed;
    inset: 0;
    z-index: 1;
    padding: 0;
    overflow: hidden;
    overflow: clip; /* not a scroll container, so focusing a tile never scrolls the wall */
    touch-action: none;
    cursor: grab;
    background: var(--p-bg);
}
html.ws-gal-live .ws-gal__stage.is-dragging { cursor: grabbing; }
html.ws-gal-live .ws-gal__stage.is-dragging * { -webkit-user-select: none; user-select: none; }
html.ws-gal-live .ws-gal__stage.is-dragging .ws-gal__tile { cursor: grabbing; }

/* Set in <head> before the first paint (functions.php): the wall layout is there from the start,
   the photos appear once gallery.js has placed them (no layout shift). */
html.ws-gal-boot .ws-gal__wall { opacity: 0; }

html.ws-gal-live .ws-gal__wall {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    /* No will-change: Chromium skips painting tiles of a layer this large (blank wall). */
}
html.ws-gal-live .ws-gal__grid { display: block; position: relative; }
html.ws-gal-live .ws-gal__cell {
    position: absolute;
    top: 0;
    left: 0;
    width: 280px;
    height: 350px;
    aspect-ratio: auto;
}

html.ws-gal-live .ws-gal__intro {
    position: fixed;
    bottom: 24px;
    inset-inline-start: 24px;
    z-index: 20;
    width: min(380px, calc(100vw - 48px));
    padding: 22px 24px 24px;
    border-radius: 24px;
    border: 1px solid var(--g-glass-line);
    background: var(--g-glass);
    box-shadow: var(--g-shadow);
    -webkit-backdrop-filter: blur(20px) saturate(140%);
    backdrop-filter: blur(20px) saturate(140%);
}
html.ws-gal-live .ws-gal__title { font-size: clamp(1.6rem, 1.3rem + 0.8vw, 2.1rem); }
html.ws-gal-live .ws-gal__lead { font-size: 14px; }

.ws-gal__zoom {
    position: fixed;
    bottom: 24px;
    inset-inline-end: 24px;
    z-index: 20;
    display: flex;
    gap: 2px;
    padding: 5px;
    border-radius: 9999px;
}
.ws-gal__zoom[hidden] { display: none; }

@media (max-width: 640px) {
    html.ws-gal-live .ws-gal__intro {
        bottom: 12px;
        inset-inline-start: 12px;
        width: calc(100vw - 24px);
        padding: 16px 18px 18px;
        border-radius: 20px;
    }
    html.ws-gal-live .ws-gal__lead { margin-top: 4px; transition: opacity 0.4s ease; }
    html.ws-gal-moved .ws-gal__lead { display: none; }
    html.ws-gal-live .ws-gal__filters { margin-top: 12px; }
    .ws-gal__zoom { display: none !important; } /* pinch to zoom on phones */
}

/* ---------------------------------------------------------------- detail view */

.ws-gal__detail {
    position: fixed;
    inset: 0;
    z-index: 70; /* above the header notch, below the booking panel (95) */
    display: grid;
    grid-template-columns: minmax(0, 7fr) minmax(320px, 5fr);
}
.ws-gal__detail[hidden] { display: none; }
.admin-bar .ws-gal__detail { top: 32px; }

.ws-gal__backdrop {
    position: absolute;
    inset: 0;
    background: var(--g-veil);
    -webkit-backdrop-filter: blur(24px);
    backdrop-filter: blur(24px);
}

.ws-gal__media {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: clamp(24px, 4vw, 64px);
    pointer-events: none;
}
.ws-gal__media > * { pointer-events: auto; }

.ws-gal__frame {
    position: relative;
    overflow: hidden;
    border-radius: 20px;
    background: var(--g-tile-bg);
    box-shadow: 0 0 0 1px var(--p-line);
    --pos: 50%;
}
.ws-gal__frame img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.ws-gal__before { clip-path: inset(0 calc(100% - var(--pos)) 0 0); }
[dir="rtl"] .ws-gal__before { clip-path: inset(0 0 0 calc(100% - var(--pos))); }
.ws-gal__frame.is-compare::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: var(--pos);
    width: 1px;
    background: rgba(249, 254, 255, 0.9);
    box-shadow: 0 0 0 0.5px rgba(18, 18, 18, 0.25);
    pointer-events: none;
}
[dir="rtl"] .ws-gal__frame.is-compare::after { left: auto; right: var(--pos); }

.ws-gal__compare {
    display: flex;
    align-items: center;
    gap: 14px;
    width: min(420px, 100%);
    font-size: 13px;
    color: var(--p-soft);
}
.ws-gal__compare[hidden] { display: none; }
.ws-gal__compare input {
    flex: 1;
    accent-color: var(--p-ink);
    cursor: ew-resize;
}

.ws-gal__text {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 14px;
    min-width: 0;
    padding: clamp(80px, 9vh, 112px) clamp(28px, 4vw, 56px) clamp(32px, 5vh, 56px);
    border-inline-start: 1px solid var(--p-line);
    overflow-y: auto;
}
.ws-gal__kind { margin: 0; font-size: 14px; }
.ws-gal__d-title {
    margin: 0;
    font-size: clamp(1.5rem, 1.1rem + 1.2vw, 2.25rem);
    font-weight: 300;
    line-height: 1.3;
    letter-spacing: -0.01em;
    outline: none;
}
[dir="rtl"] .ws-gal__d-title { letter-spacing: 0; line-height: 1.55; }
.ws-gal__note { margin: 0; max-width: 40ch; font-size: 15px; line-height: 1.75; }

.ws-gal__facts {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px 24px;
    margin: 6px 0 0;
    padding-top: 18px;
    border-top: 1px solid var(--p-line);
    font-size: 15px;
}
.ws-gal__facts dt { color: var(--p-soft); }
.ws-gal__facts dd { margin: 0; }
.ws-gal__consent { margin: 0; max-width: 44ch; font-size: 13px; line-height: 1.7; }
.ws-gal__actions:empty,
.ws-gal__actions:has(> [hidden]:only-child) { display: none; }
.ws-gal__actions { margin-top: 10px; }
.ws-gal__steps { display: flex; gap: 6px; margin-top: 18px; margin-inline-start: -10px; }

.ws-gal__close {
    position: absolute;
    top: 20px;
    inset-inline-end: 20px;
    z-index: 2;
    border: 1px solid var(--g-glass-line);
    background: var(--g-glass);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
}

@media (max-width: 900px) {
    .ws-gal__detail {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        align-content: start;
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    .ws-gal__backdrop { position: fixed; }
    .ws-gal__media { height: 58dvh; padding: 64px 16px 12px; }
    .ws-gal__text {
        justify-content: flex-start;
        padding: 20px var(--p-gutter) 40px;
        border-inline-start: 0;
        overflow: visible;
    }
    .ws-gal__close { position: fixed; top: 12px; inset-inline-end: 12px; }
}

/* ---------------------------------------------------------------- motion preferences */

@media (prefers-reduced-motion: reduce) {
    .ws-gal *,
    .ws-gal *::after { transition-duration: 0.01ms !important; }
    .ws-gal__tile:hover img { transform: none; }
}
