/* =========================================================
   media.css
   Mallory Grid Micro-interactions, Shimmer, Story Mode
   ========================================================= */

/* ─── Shimmer loading state ────────────────────────────────── */

.media-item .story-shimmer,
.media-item .shimmer-placeholder {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        rgba(212,175,55,0.0)   0%,
        rgba(212,175,55,0.08) 40%,
        rgba(212,175,55,0.15) 50%,
        rgba(212,175,55,0.08) 60%,
        rgba(212,175,55,0.0) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.6s infinite;
    border-radius: inherit;
    pointer-events: none;
    z-index: 5;
}

@keyframes shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position:  200% 0; }
}

/* Grid items: shimmer overlay while src not loaded */
.media-item img:not(.loaded) + .shimmer-layer,
.media-item.loading-placeholder::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        #e8ede9 25%,
        #f2f5f2 50%,
        #e8ede9 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: inherit;
}

/* ─── Magnetic tilt (grid items) ───────────────────────────── */
/* JS owns the transform. CSS only provides the transition baseline and shadow reaction. */

.media-item {
    will-change: transform;
    transform-style: preserve-3d;
    /* Precise per-property transition — "all" is intentionally avoided so JS tilt is instant */
    transition: transform 0.15s ease, box-shadow 0.3s ease;
}

/* Only box-shadow reacts to hover — transform is fully owned by JS _handleCardTilt */
.media-item:hover {
    box-shadow:
        0 24px 48px -8px rgba(8,28,21,0.18),
        0  8px 16px -4px rgba(8,28,21,0.12);
}

/* ─── Story Overlay ────────────────────────────────────────── */

.story-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: #040c08;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.story-overlay.story-exit {
    animation: storyFadeOut 0.4s ease forwards;
}

@keyframes storyFadeOut {
    to { opacity: 0; transform: scale(1.04); }
}

/* ─── Progress rail ────────────────────────────────────────── */

.story-progress-rail {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    gap: 2px;
    padding: 14px 16px 0;
    z-index: 10;
}

.story-seg {
    flex: 1;
    height: 2px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
    overflow: hidden;
}

.story-seg-fill {
    height: 100%;
    width: 0%;
    background: #D4AF37;
    border-radius: 2px;
}

/* ─── Story header ─────────────────────────────────────────── */

.story-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 24px 20px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 210;
    margin-top: 16px;
}

.story-title-badge {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.7);
    max-width: 60vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.story-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.story-close-btn,
.story-dl-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.1);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    pointer-events: auto;
    position: relative;
    z-index: 100;
}

.story-close-btn:hover,
.story-dl-btn:hover {
    background: rgba(255,255,255,0.22);
}

/* ─── Stage & card ─────────────────────────────────────────── */

.story-stage {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.story-card-wrap {
    position: relative;
    width: min(420px, 92vw);
    height: min(745px, 88vh);
    border-radius: 24px;
    /* overflow: hidden removed to allow 3D rotation corners to pass edges */
    perspective: 2000px;
}

.story-card {
    position: absolute;
    inset: 0;
    border-radius: 24px;
    overflow: hidden;
    transform-style: preserve-3d;
    will-change: transform, opacity;
    background: #0d1f16;
    box-shadow: 0 48px 96px -12px rgba(0,0,0,0.7);
    transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1), opacity 0.6s ease;
}

.story-media-el {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ─── Modal (viewer) overrides ─────────────────────────────── */
/* The modal viewer needs full-viewport sizing, not the small
   phone-frame dimensions used by story mode.                  */

#modal .story-card-wrap {
    width: 98vw;
    height: 94vh;
    max-width: 1600px;
    border-radius: 0;
    overflow: visible; /* CRITICAL for edge-to-edge 3D flip */
}

#modal .story-card {
    border-radius: 20px;
    background: transparent;
}

#modal .story-media-el {
    object-fit: contain;
    background: transparent;
}

/* 3-D Sweep States for Layered Navigation */
.entering-next {
    transform: perspective(2000px) rotateY(45deg) translateX(100%) scale(0.9);
    opacity: 0;
}

.entering-prev {
    transform: perspective(2000px) rotateY(-45deg) translateX(-100%) scale(0.9);
    opacity: 0;
}

.exiting-next {
    transform: perspective(2000px) rotateY(-45deg) translateX(-100%) scale(0.9);
    opacity: 0;
    pointer-events: none;
}

.exiting-prev {
    transform: perspective(2000px) rotateY(45deg) translateX(100%) scale(0.9);
    opacity: 0;
    pointer-events: none;
}

@keyframes flipInNext {
    0%   { transform: perspective(2000px) rotateY(40deg)  scale(0.85) translateX(30%); opacity: 0; }
    100% { transform: perspective(2000px) rotateY(0deg)   scale(1)    translateX(0);  opacity: 1; }
}

@keyframes flipOutNext {
    0%   { transform: perspective(2000px) rotateY(0deg)   scale(1)    translateX(0);  opacity: 1; }
    100% { transform: perspective(2000px) rotateY(-40deg) scale(0.85) translateX(-30%); opacity: 0; }
}

@keyframes flipInPrev {
    0%   { transform: perspective(2000px) rotateY(-40deg) scale(0.85) translateX(-30%); opacity: 0; }
    100% { transform: perspective(2000px) rotateY(0deg)   scale(1)    translateX(0);  opacity: 1; }
}

@keyframes flipOutPrev {
    0%   { transform: perspective(2000px) rotateY(0deg)  scale(1)    translateX(0);  opacity: 1; }
    100% { transform: perspective(2000px) rotateY(40deg) scale(0.85) translateX(30%); opacity: 0; }
}

/* Shimmer inside a story card while image loads */
.story-card .story-shimmer {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        #0d1f16 0%,
        #1B4332 40%,
        #2a6350 50%,
        #1B4332 60%,
        #0d1f16 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: 24px;
    z-index: 2;
}

/* ─── Tap zones ────────────────────────────────────────────── */

.story-tap-zones {
    position: absolute;
    inset: 0;
    display: flex;
    z-index: 5;
    pointer-events: none;
}

.story-tap-zone {
    flex: 1;
    cursor: pointer;
    pointer-events: auto;
}

/* ─── Counter ──────────────────────────────────────────────── */

.story-counter {
    position: absolute;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.4);
    z-index: 10;
    pointer-events: none;
}

/* ─── Story Mode button in header ──────────────────────────── */

.story-launch-btn {
    animation: storyPulse 2.8s ease-in-out infinite;
}

@keyframes storyPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(212,175,55,0); }
    50%       { box-shadow: 0 0 0 6px rgba(212,175,55,0.18); }
}

/* ─── Select circle pop ────────────────────────────────────── */

.select-circle {
    transition:
        transform    0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
        opacity      0.2s ease,
        background   0.2s ease,
        border-color 0.2s ease;
    background: rgba(0,0,0,0.3);
    border: 2px solid white;
    opacity: 0.6;
}

.select-circle svg {
    opacity: 0;
    transition: opacity 0.2s ease;
}

.media-item.selected .select-circle {
    background: #C8F04B !important;
    border-color: #C8F04B !important;
    opacity: 1 !important;
    transform: scale(1.1);
}

.media-item.selected .select-circle svg {
    opacity: 1;
    color: #000;
}

.media-item.selected {
    outline: 2px solid #C8F04B;
    outline-offset: -2px;
}

@keyframes circlePop {
    0%   { transform: scale(0.7); }
    60%  { transform: scale(1.2); }
    100% { transform: scale(1.1); }
}

/* ─── Media item entrance stagger ──────────────────────────── */

@keyframes mediaReveal {
    /* No opacity change — keeping items visible so masonry always gets real height.
       Only translate+scale so the entrance feel is preserved without zero-height frames. */
    from { transform: translateY(24px) scale(0.96); }
    to   { transform: translateY(0)    scale(1); }
}

.media-item {
    animation: mediaReveal 0.55s cubic-bezier(0.23, 1, 0.32, 1) both;
}

/* Stagger first 20 items */
.media-item:nth-child(1)  { animation-delay: 0.03s; }
.media-item:nth-child(2)  { animation-delay: 0.06s; }
.media-item:nth-child(3)  { animation-delay: 0.09s; }
.media-item:nth-child(4)  { animation-delay: 0.12s; }
.media-item:nth-child(5)  { animation-delay: 0.15s; }
.media-item:nth-child(6)  { animation-delay: 0.18s; }
.media-item:nth-child(7)  { animation-delay: 0.21s; }
.media-item:nth-child(8)  { animation-delay: 0.24s; }
.media-item:nth-child(9)  { animation-delay: 0.27s; }
.media-item:nth-child(10) { animation-delay: 0.30s; }
.media-item:nth-child(11) { animation-delay: 0.33s; }
.media-item:nth-child(12) { animation-delay: 0.36s; }
.media-item:nth-child(13) { animation-delay: 0.39s; }
.media-item:nth-child(14) { animation-delay: 0.42s; }
.media-item:nth-child(15) { animation-delay: 0.45s; }
.media-item:nth-child(16) { animation-delay: 0.48s; }
.media-item:nth-child(17) { animation-delay: 0.51s; }
.media-item:nth-child(18) { animation-delay: 0.54s; }
.media-item:nth-child(19) { animation-delay: 0.57s; }
.media-item:nth-child(20) { animation-delay: 0.60s; }

/* ─── Mobile adjustments ───────────────────────────────────── */

@media (max-width: 640px) {
    .story-card-wrap {
        width: 100vw;
        height: 100dvh;
        border-radius: 0;
    }
    .story-card {
        border-radius: 0;
    }
    .story-card .story-shimmer {
        border-radius: 0;
    }
    /* Modal viewer: full bleed on mobile too */
    #modal .story-card-wrap {
        width: 100vw;
        height: 100dvh;
        max-width: none;
        border-radius: 0;
    }
    #modal .story-card {
        border-radius: 0;
    }
}

/* ─── Mallory Grid (Bento System) ───────────────────────────── */

.mg-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: 72px;
    grid-auto-flow: dense;
    gap: 1px;
    background: #111;
    width: 100%;
}

.media-item {
    background: #0a0a0a;
    position: relative;
    cursor: pointer;
    overflow: hidden;
    /* Brutalist sharp edges */
    border-radius: 0 !important;
}

/* Module Span Classes */
.mg-hero { grid-column: span 6; grid-row: span 8; }
.mg-wide { grid-column: span 6; grid-row: span 4; }
.mg-tall { grid-column: span 3; grid-row: span 8; }
.mg-std  { grid-column: span 3; grid-row: span 4; }

/* Optimized Responsive Bento Spans */
@media (max-width: 1440px) {
    .mg-grid { grid-template-columns: repeat(8, 1fr); }
    .mg-hero { grid-column: span 4; grid-row: span 6; }
    .mg-wide { grid-column: span 4; grid-row: span 3; }
    .mg-tall { grid-column: span 2; grid-row: span 6; }
    .mg-std  { grid-column: span 2; grid-row: span 3; }
}

@media (max-width: 768px) {
    .mg-grid { grid-template-columns: repeat(4, 1fr); }
    .mg-hero { grid-column: span 4; grid-row: span 4; }
    .mg-wide { grid-column: span 4; grid-row: span 2; }
    .mg-tall { grid-column: span 2; grid-row: span 4; }
    .mg-std  { grid-column: span 2; grid-row: span 2; }
}

/* Video Indicators */
.video-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
}

.media-item:hover .video-overlay {
    background: rgba(0,0,0,0.4);
}

.video-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(0,0,0,0.6);
    color: #C8F04B;
    font-family: 'DM Mono', monospace;
    font-size: 8px;
    padding: 2px 6px;
    letter-spacing: 0.1em;
    border: 1px solid rgba(200, 240, 75, 0.3);
    z-index: 10;
}

.media-item img, 
.media-item video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

.media-item:hover img {
    transform: scale(1.04);
}

.media-item .img-wrap {
    width: 100%;
    height: 100%;
}