/*
 * Shared media styles for the public site.
 *   1. Whole-image frames for gallery viewers / grids / strips (.media-*).
 *   2. The shared lightbox (.ml*) — markup in components/public/media-lightbox.blade.php.
 * Hand-written (not Tailwind) because public/css/app.css is a prebuilt static file.
 * Colours come from the layout's :root tokens; the fallbacks only cover a missing token.
 */

[x-cloak] { display: none !important; }

/* ── 1. Whole-image frames ─────────────────────────────────────────────── */

/* A viewer box that always shows the full media, centred, on a quiet backdrop. */
.media-stage {
    aspect-ratio: 3 / 2;
    background: var(--color-charcoal, #1A1A1A);
}

/* Use instead of object-cover when the whole image must stay visible. */
.media-fit-contain {
    object-fit: contain;
    object-position: center;
}

/* Strip tile: a steady 4:3 box, the image inside is shown whole. */
.media-thumb-tile {
    aspect-ratio: 4 / 3;
    background: var(--color-beige, #F3EFEC);
}

/* Corner button that opens a media item in the lightbox. */
.media-enlarge {
    position: absolute;
    top: 0.75rem;
    inset-inline-end: 0.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border: 1px solid rgb(255 255 255 / 0.5);
    background: rgb(0 0 0 / 0.5);
    color: #fff;
    transition: background-color 0.2s;
}

.media-enlarge svg { width: 1.125rem; height: 1.125rem; }

@media (hover: hover) and (pointer: fine) {
    .media-enlarge:hover { background: rgb(0 0 0 / 0.75); }
}

/* ── 2. Lightbox ───────────────────────────────────────────────────────── */

.ml {
    --ml-ink: #fff;
    --ml-accent: var(--color-gold-on-dark, #D4AF37);
    --ml-surface: rgb(255 255 255 / 0.1);
    --ml-surface-hover: color-mix(in srgb, var(--ml-accent) 30%, transparent);
    --ml-gap: 0.75rem;

    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    color: var(--ml-ink);
    overscroll-behavior: contain;
}

.ml__backdrop {
    position: absolute;
    inset: 0;
    background: var(--color-charcoal, #1A1A1A);
}

.ml__bar,
.ml__stage,
.ml__foot { position: relative; }

.ml__bar {
    display: flex;
    align-items: center;
    gap: var(--ml-gap);
    padding: var(--ml-gap);
    padding-top: max(var(--ml-gap), env(safe-area-inset-top));
}

.ml__counter {
    margin: 0;
    min-width: 4.5rem;
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
    color: rgb(255 255 255 / 0.85);
}

/* Phone: counter + close share the first row, the toolbar slot wraps below. */
.ml__bar { flex-wrap: wrap; justify-content: space-between; }

.ml__tools {
    order: 3;
    flex: 1 0 100%;
    min-width: 0;
    display: flex;
    justify-content: center;
}

.ml__tools:empty { display: none; }

.ml__btn {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 9999px;
    background: var(--ml-surface);
    color: var(--ml-ink);
    transition: background-color 0.2s, color 0.2s;
}

.ml__bar > .ml__btn { margin-inline-start: auto; }

.ml__icon { width: 1.25rem; height: 1.25rem; }

.ml__stage {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-inline: var(--ml-gap);
    touch-action: pinch-zoom;
    overflow: hidden;
}

.ml__media {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
    transition: transform 0.2s ease-out;
}

.ml__media.is-dragging { transition: none; }

.ml__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgb(0 0 0 / 0.45);
}

.ml__nav--prev { inset-inline-start: var(--ml-gap); }
.ml__nav--next { inset-inline-end: var(--ml-gap); }

/* Chevrons point along the reading direction. */
[dir="rtl"] .ml__nav .ml__icon { transform: scaleX(-1); }

.ml__foot {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: var(--ml-gap);
    padding-bottom: max(var(--ml-gap), env(safe-area-inset-bottom));
}

.ml__caption {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    width: 100%;
    max-width: 64rem;
    font-size: 0.875rem;
}

.ml__caption-text { margin: 0; color: rgb(255 255 255 / 0.8); }

.ml__links { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; }

.ml__link {
    display: inline-flex;
    align-items: center;
    min-height: 1.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--ml-accent);
    transition: color 0.2s;
}

.ml__strip-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    min-height: 2.75rem;
    padding: 0 1rem;
    border-radius: 9999px;
    background: var(--ml-surface);
    font-size: 0.75rem;
    font-weight: 600;
    transition: background-color 0.2s, color 0.2s;
}

.ml__strip-chevron { width: 1rem; height: 1rem; transition: transform 0.2s; }
.ml__strip-chevron.is-open { transform: rotate(180deg); }

.ml__strip {
    width: 100%;
    max-height: 0;
    overflow: hidden;
    visibility: hidden;
    transition: max-height 0.25s ease-out, visibility 0s 0.25s;
}

.ml__strip.is-open {
    max-height: 6rem;
    visibility: visible;
    transition: max-height 0.25s ease-out;
}

.ml__strip-track {
    display: flex;
    gap: 0.5rem;
    padding: 0.25rem;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
    scrollbar-color: rgb(255 255 255 / 0.3) transparent;
}

.ml__thumb {
    position: relative;
    flex: none;
    width: 5rem;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    background: rgb(255 255 255 / 0.08);
    opacity: 0.55;
    outline: 2px solid transparent;
    outline-offset: -2px;
    transition: opacity 0.2s, outline-color 0.2s;
}

.ml__thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
}

.ml__thumb.is-current { opacity: 1; outline-color: var(--ml-accent); }

.ml__thumb-play {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgb(0 0 0 / 0.35);
}

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

@media (hover: hover) and (pointer: fine) {
    .ml__btn:hover,
    .ml__strip-toggle:hover { background: var(--ml-surface-hover); color: var(--ml-accent); }
    .ml__link:hover { color: var(--ml-ink); }
    .ml__thumb:hover { opacity: 1; }
}

/* Upright phone: prev / next get their own band under the media, so no image, video
   or native video control ever sits on top of them (and they never cover the media). */
@media (max-width: 767.98px) and (orientation: portrait) {
    .ml__stage { padding-bottom: calc(2.75rem + var(--ml-gap) * 2); }
    .ml__nav { top: auto; bottom: var(--ml-gap); transform: none; background: var(--ml-surface); }
}

@media (min-width: 768px) {
    .ml { --ml-gap: 1rem; }
    .ml__bar { flex-wrap: nowrap; }
    .ml__tools { order: 0; flex: 1; justify-content: flex-end; }
    .ml__thumb { width: 6.5rem; }
    .ml__strip.is-open { max-height: 7rem; }
    .ml__strip-track { justify-content: safe center; }
}

/* Phone held sideways: one row per bar, so the height goes to the media. */
@media (max-height: 500px) {
    .ml__bar { flex-wrap: nowrap; }
    .ml__tools { order: 0; flex: 1; justify-content: flex-end; }
    .ml__foot { flex-direction: row; flex-wrap: wrap; }
    .ml__caption { flex: 1; width: auto; min-width: 0; }
    .ml__strip-toggle { margin-inline: auto; }
}

@media (prefers-reduced-motion: reduce) {
    .ml__media,
    .ml__strip,
    .ml__strip.is-open,
    .ml__strip-chevron { transition: none; }
}
