/* CREATIVE STORY ENGINE - CONSOLIDATED FINAL */

:root {
    --transition-speed: 0.8s;
    --nature-green: #4a6741;
    --warm-paper: #fdfaf5;
}

/* --- Main Container --- */
.story-container {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #111;
    overflow: hidden;
    border-radius: 12px;
    touch-action: pan-y;
    box-shadow: 0 20px 40px rgba(0,0,0,0.4);
}

@media (max-width: 768px) {
    .story-container { aspect-ratio: 4 / 5; }
}

/* --- Progress Bar (Fix: Increased Z-Index for Nav priority) --- */
.story-progress-container {
    position: absolute;
    top: 0; left: 0; right: 0;
    padding: 15px 12px 25px 12px;
    display: flex;
    gap: 6px;
    z-index: 200; /* Must be higher than play-pause-overlay (110) */
    cursor: pointer;
}

.story-progress-segment {
    height: 3px;
    background: rgba(255,255,255,0.25);
    flex: 1;
    border-radius: 2px;
    position: relative;
}

.story-progress-fill {
    height: 100%;
    width: 0%;
    background: #fff;
    box-shadow: 0 0 8px rgba(255,255,255,0.5);
}

/* --- Navigation Thumbnail --- */
.story-nav-thumbnail {
    position: absolute;
    bottom: -85px;
    width: 140px; height: 80px;
    background: #fff;
    border: 3px solid #fff;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    overflow: hidden;
    display: none;
    pointer-events: none;
    transform: translateX(-50%);
    z-index: 210;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.story-nav-thumbnail img { width: 100%; height: 100%; object-fit: cover; }

/* --- The Stage & Slides --- */
.story-stage { width: 100%; height: 100%; position: relative; }

.story-slide {
    position: absolute;
    inset: 0;
    opacity: 0;
    pointer-events: none;
    display: flex;
    padding: 5% 8%;
    align-items: center;
    justify-content: center;
    gap: 30px;
    z-index: 1;
}

.story-slide.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 5;
}

/* --- Layout Flex Directions --- */
.img-left-cap-right { flex-direction: row; }
.cap-left-img-right { flex-direction: row-reverse; }
.img-top-cap-bottom { flex-direction: column; text-align: center; }
.cap-top-img-bottom { flex-direction: column-reverse; text-align: center; }
.img-only .story-caption { display: none; }
.img-only .img-group { flex: 1; width: 80%; }

/* --- Image Grouping --- */
.img-group { flex: 1.2; display: flex; align-items: center; justify-content: center; height: 100%; }
.img-group.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.img-group.grid-4 { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 12px; }

/* --- Window Reveal Logic --- */
.image-wrapper {
    position: relative;
    flex: 1.5;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transform: rotate(var(--rotation, 0deg));
    background: #fff;
    padding: 10px 10px 45px 10px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.4);
    animation: expandFrame var(--slide-duration, 20s) cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.main-img {
    position: relative;
    z-index: 2;
    width: 100%;
    height: 100%;
    object-fit: cover;
    animation: staticImage var(--slide-duration, 20s) cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes expandFrame {
    0% { transform: rotate(var(--rotation, 0deg)) scale(0.6); opacity: 0; }
    50%, 100% { transform: rotate(var(--rotation, 0deg)) scale(1); opacity: 1; }
}

@keyframes staticImage {
    0% { transform: scale(1.66); filter: blur(4px); }
    50%, 100% { transform: scale(1); filter: blur(0px); }
}

.blur-bg {
    position: absolute;
    inset: -50px;
    background-size: cover;
    background-position: center;
    filter: blur(5px) brightness(0.9);
    z-index: 1;
}

/* --- Border Presets --- */
[data-border-style="polaroid"] { background: #fff; padding: 20px; box-shadow: 0 8px 20px rgba(0,0,0,0.3); z-index: 10; }
[data-border-style="soft-edge"] .main-img { border-radius: 30px; filter: drop-shadow(0 0 15px rgba(255,255,255,0.4)); }
[data-border-style="bevel"] .main-img { border: 8px outset #eee; }
[data-border-style="shadow-only"] .main-img { filter: drop-shadow(0 15px 25px rgba(0,0,0,0.6)); }

/* --- Captions & Shapes --- */
.story-caption { flex: 1; z-index: 10; }
.caption-inner {
    background: var(--cap-bg, rgba(255,255,255,0.9));
    color: var(--cap-text, #333);
    padding: 25px;
    border-radius: 8px;
    font-size: 1.1rem;
    line-height: 1.5;
    backdrop-filter: blur(8px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.story-caption.star .caption-inner { clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); padding: 50px 40px; }
.story-caption.talk-bubble .caption-inner { clip-path: polygon(0% 0%, 100% 0%, 100% 75%, 75% 75%, 75% 100%, 50% 75%, 0% 75%); padding-bottom: 45px; }

/* --- Mobile Layout Override --- */
@media (max-width: 768px) {
    .story-slide { flex-direction: column !important; padding: 60px 20px 30px 20px; gap: 20px; }
    .img-group { width: 100%; flex: 0 0 auto; height: 50%; }
    .story-caption { width: 100%; flex: 1; display: flex; align-items: flex-start; justify-content: center; }
    .img-left-cap-right, .img-top-cap-bottom { flex-direction: column !important; }
    .cap-left-img-right, .cap-top-img-bottom { flex-direction: column-reverse !important; }
}

/* --- Animation Library --- */
.fade-in { animation: fadeIn 2s ease-out forwards; }
.fade-out { animation: fadeOut 2s ease-in forwards; }
.slide-in { animation: slideUp 2s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
.slide-out { animation: slideDown 2s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
.pop-in { animation: popIn 2s cubic-bezier(0.34, 1.56, 0.64, 1) forwards; }
.pop-out { animation: popOut 2s ease-in forwards; }
.reveal-in { animation: revealIn 2s ease-out forwards; }
.reveal-out { animation: revealOut 2s ease-in forwards; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes slideUp { from { transform: translateY(100px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes slideDown { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-100px); opacity: 0; } }
@keyframes popIn { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes popOut { from { transform: scale(1); opacity: 1; } to { transform: scale(1.2); opacity: 0; } }
@keyframes revealIn { from { filter: blur(20px); opacity: 0; transform: scale(1.1); } to { filter: blur(0); opacity: 1; transform: scale(1); } }
@keyframes revealOut { from { filter: blur(0); opacity: 1; } to { filter: blur(20px); opacity: 0; } }

.sun-in { animation: sunIn 2s ease-out forwards; }
@keyframes sunIn {
    0% { filter: sepia(1) brightness(2) saturate(0); opacity: 0; transform: scale(0.9); }
    100% { filter: sepia(0) brightness(1) saturate(1); opacity: 1; transform: scale(1); }
}

.book-in { animation: bookIn 2s ease-out forwards; perspective: 1000px; }
@keyframes bookIn {
    0% { transform: rotateX(-30deg); opacity: 0; transform-origin: top; }
    100% { transform: rotateX(0deg); opacity: 1; }
}

.fade-in, .fade-out, .slide-in, .slide-out, .pop-in, .pop-out {
    animation-duration: 2s !important;
    animation-fill-mode: forwards;
}

/* --- Controls --- */
.play-pause-overlay {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    z-index: 110; opacity: 0; transition: opacity 0.3s ease; cursor: pointer;
}
.story-container:hover .play-pause-overlay { opacity: 1; }
.cue-icon {
    width: 80px; height: 80px;
    background: rgba(0,0,0,0.6);
    border-radius: 50%;
    color: white; font-size: 2rem;
    display: flex; align-items: center; justify-content: center;
}