/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #000;
    color: #fff;
    overflow: hidden;
    position: relative;
    height: 100vh;
}

/* Loading Screen */
.loader {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 50%, #7e57c2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease;
}

.loader.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader-content {
    text-align: center;
}

.loader-robot {
    display: block;
    animation: bounce 1s ease-in-out infinite;
}

.loader-robot img {
    display: block;
    width: 120px;
    height: 80px;
    object-fit: contain;
    filter: drop-shadow(0 4px 12px rgba(102, 126, 234, 0.4));
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

/* App Container */
.app-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* Desktop Header */
.desktop-header {
    position: fixed;
    left: 40px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    text-align: left;
    z-index: 100;
    max-width: 300px;
}

.desktop-header.visible {
    opacity: 1;
    visibility: visible;
}

.desktop-header h1 {
    font-family: 'Montserrat', sans-serif;
    font-size: 3.5rem;
    font-weight: 800;
    margin-bottom: 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.desktop-header p {
    font-family: 'Montserrat', sans-serif;
    font-size: 1.3rem;
    font-weight: 400;
    opacity: 0.8;
    line-height: 1.4;
    color: #e0e0e0;
}

/* Story Viewer */
.story-viewer {
    width: 100vw;
    height: 100vh;
    position: relative;
    background: #000;
    overflow: hidden;
}

/* Desktop adjustments */
@media (min-width: 768px) {
    .story-viewer {
        max-width: 400px;
        max-height: 80vh;
        width: 100%;
        border-radius: 12px;
        box-shadow: 0 20px 40px rgba(0,0,0,0.5);
    }
    
    /* Desktop gradient backgrounds */
    .app-container {
        background: 
            radial-gradient(ellipse at 20% 20%, rgba(74, 44, 125, 0.15) 0%, transparent 50%),
            radial-gradient(ellipse at 80% 80%, rgba(20, 184, 166, 0.15) 0%, transparent 50%),
            radial-gradient(ellipse at 50% 50%, rgba(244, 114, 182, 0.1) 0%, transparent 60%),
            linear-gradient(135deg, 
                rgba(26, 26, 46, 0.9) 0%, 
                rgba(74, 44, 125, 0.3) 25%, 
                rgba(20, 184, 166, 0.2) 50%, 
                rgba(244, 114, 182, 0.3) 75%, 
                rgba(26, 26, 46, 0.9) 100%
            );
        transition: background 0.6s ease;
    }
    
    /* Per-slide desktop background variations */
    .slide[data-slide="1"].active ~ * .app-container,
    body:has(.slide[data-slide="1"].active) .app-container {
        background: 
            radial-gradient(ellipse at 15% 85%, rgba(74, 44, 125, 0.2) 0%, transparent 40%),
            radial-gradient(ellipse at 85% 15%, rgba(20, 184, 166, 0.15) 0%, transparent 40%),
            linear-gradient(135deg, rgba(45, 27, 105, 0.8) 0%, rgba(20, 184, 166, 0.3) 100%);
    }
    
    .slide[data-slide="2"].active ~ * .app-container,
    body:has(.slide[data-slide="2"].active) .app-container {
        background: 
            radial-gradient(ellipse at 20% 80%, rgba(6, 182, 212, 0.2) 0%, transparent 50%),
            radial-gradient(ellipse at 80% 20%, rgba(251, 146, 60, 0.15) 0%, transparent 40%),
            linear-gradient(135deg, rgba(6, 182, 212, 0.3) 0%, rgba(251, 146, 60, 0.25) 100%);
    }
    
    .slide[data-slide="3"].active ~ * .app-container,
    body:has(.slide[data-slide="3"].active) .app-container {
        background: 
            radial-gradient(ellipse at 10% 90%, rgba(251, 146, 60, 0.2) 0%, transparent 50%),
            radial-gradient(ellipse at 90% 10%, rgba(147, 51, 234, 0.15) 0%, transparent 40%),
            linear-gradient(135deg, rgba(251, 146, 60, 0.3) 0%, rgba(147, 51, 234, 0.25) 100%);
    }
    
    .slide[data-slide="4"].active ~ * .app-container,
    body:has(.slide[data-slide="4"].active) .app-container {
        background: 
            radial-gradient(ellipse at 30% 70%, rgba(30, 58, 138, 0.2) 0%, transparent 50%),
            radial-gradient(ellipse at 70% 30%, rgba(245, 158, 11, 0.15) 0%, transparent 40%),
            linear-gradient(135deg, rgba(30, 58, 138, 0.3) 0%, rgba(245, 158, 11, 0.25) 100%);
    }
    
    .slide[data-slide="5"].active ~ * .app-container,
    body:has(.slide[data-slide="5"].active) .app-container {
        background: 
            radial-gradient(ellipse at 40% 60%, rgba(124, 58, 237, 0.2) 0%, transparent 50%),
            radial-gradient(ellipse at 60% 40%, rgba(236, 72, 153, 0.15) 0%, transparent 40%),
            linear-gradient(135deg, rgba(124, 58, 237, 0.3) 0%, rgba(236, 72, 153, 0.25) 100%);
    }
    
    .slide[data-slide="6"].active ~ * .app-container,
    body:has(.slide[data-slide="6"].active) .app-container {
        background: 
            radial-gradient(ellipse at 50% 20%, rgba(20, 184, 166, 0.2) 0%, transparent 50%),
            radial-gradient(ellipse at 20% 80%, rgba(109, 40, 217, 0.15) 0%, transparent 40%),
            linear-gradient(135deg, rgba(20, 184, 166, 0.3) 0%, rgba(109, 40, 217, 0.25) 100%);
    }
    
    .slide[data-slide="7"].active ~ * .app-container,
    body:has(.slide[data-slide="7"].active) .app-container {
        background: 
            radial-gradient(ellipse at 25% 25%, rgba(244, 114, 182, 0.15) 0%, transparent 30%),
            radial-gradient(ellipse at 75% 25%, rgba(20, 184, 166, 0.15) 0%, transparent 30%),
            radial-gradient(ellipse at 50% 75%, rgba(245, 158, 11, 0.15) 0%, transparent 30%),
            linear-gradient(135deg, 
                rgba(147, 51, 234, 0.25) 0%, 
                rgba(244, 114, 182, 0.2) 25%, 
                rgba(20, 184, 166, 0.2) 50%, 
                rgba(245, 158, 11, 0.2) 75%, 
                rgba(74, 44, 125, 0.25) 100%
            );
    }
}

.slides-container {
    width: 100%;
    height: 100%;
    position: relative;
}

.slide {
    position: absolute;
    inset: 0;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease, transform 0.4s ease;
    transform: scale(1.02);
    z-index: 1;
}

.slide.active {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
    z-index: 10;
}

.slide-image {
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-color: #000;
}

/* Mobile optimized images - prevent cropping with contain mode */
@media (max-width: 767px) {
    .slide-image {
        background-size: contain !important;
        background-position: center center !important;
        background-color: #1a1a2e;
        position: relative;
    }
    
    .slide[data-slide="1"] .slide-image {
        --slide-image: url('../images/webp/slide1_mobile.webp'), url('../images/optimized/slide1_mobile_opt.png');
        background-image: var(--slide-image);
        background-color: #1a1a2e;
    }
    .slide[data-slide="2"] .slide-image {
        --slide-image: url('../images/webp/slide2_mobile.webp'), url('../images/optimized/slide2_mobile_opt.png');
        background-image: var(--slide-image);
        background-color: #1a1a2e;
    }
    .slide[data-slide="3"] .slide-image {
        --slide-image: url('../images/webp/slide3_mobile.webp'), url('../images/optimized/slide3_mobile_opt.png');
        background-image: var(--slide-image);
        background-color: #1a1a2e;
    }
    .slide[data-slide="4"] .slide-image {
        --slide-image: url('../images/webp/slide4_mobile.webp'), url('../images/optimized/slide4_mobile_opt.png');
        background-image: var(--slide-image);
        background-color: #1a1a2e;
    }
    .slide[data-slide="5"] .slide-image {
        --slide-image: url('../images/webp/slide5_mobile.webp'), url('../images/optimized/slide5_mobile_opt.png');
        background-image: var(--slide-image);
        background-color: #1a1a2e;
    }
    .slide[data-slide="6"] .slide-image {
        --slide-image: url('../images/webp/slide6_mobile.webp'), url('../images/optimized/slide6_mobile_opt.png');
        background-image: var(--slide-image);
        background-color: #1a1a2e;
    }
    .slide[data-slide="7"] .slide-image {
        --slide-image: url('../images/webp/slide7_mobile.webp'), url('../images/optimized/slide7_mobile_opt.png');
        background-image: var(--slide-image);
        background-color: #1a1a2e;
    }
    
    /* Enhanced mobile visual effects */
    .slide-image {
        transition: all 0.4s ease;
    }
    
    /* Improved progress bar visibility on mobile */
    .progress-container {
        background: linear-gradient(to bottom, rgba(0,0,0,0.3), rgba(0,0,0,0.1), transparent);
        padding: 12px 8px 8px 8px;
    }
    
    .progress-bar {
        height: 3px;
        border-radius: 3px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    }
}

/* Desktop optimized images */
@media (min-width: 768px) {
    .slide-image {
        background-size: contain;
    }
    
    .slide[data-slide="1"] .slide-image {
        background-image: url('../images/webp/slide1_desktop.webp'), url('../images/optimized/slide1_desktop_opt.png');
    }
    .slide[data-slide="2"] .slide-image {
        background-image: url('../images/webp/slide2_desktop.webp'), url('../images/optimized/slide2_desktop_opt.png');
    }
    .slide[data-slide="3"] .slide-image {
        background-image: url('../images/webp/slide3_desktop.webp'), url('../images/optimized/slide3_desktop_opt.png');
    }
    .slide[data-slide="4"] .slide-image {
        background-image: url('../images/webp/slide4_desktop.webp'), url('../images/optimized/slide4_desktop_opt.png');
    }
    .slide[data-slide="5"] .slide-image {
        background-image: url('../images/webp/slide5_desktop.webp'), url('../images/optimized/slide5_desktop_opt.png');
    }
    .slide[data-slide="6"] .slide-image {
        background-image: url('../images/webp/slide6_desktop.webp'), url('../images/optimized/slide6_desktop_opt.png');
    }
    .slide[data-slide="7"] .slide-image {
        background-image: url('../images/webp/slide7_desktop.webp'), url('../images/optimized/slide7_desktop_opt.png');
    }
}

/* Progress Bar */
.progress-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 8px;
    display: flex;
    gap: 4px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.3), transparent);
}

.progress-bar {
    flex: 1;
    height: 2px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.progress-bar::after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 0;
    background: #fff;
    transition: width 5s linear;
}

.progress-bar.active::after {
    width: 100%;
}

.progress-bar.completed::after {
    width: 100%;
    transition: none;
}

/* Story Header */
.story-header {
    position: absolute;
    top: 20px;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-logo {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.brand-name {
    font-weight: 600;
    font-size: 14px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.story-time {
    font-size: 12px;
    opacity: 0.7;
}

/* Navigation Areas (Mobile) */
.nav-area {
    position: absolute;
    top: 60px;
    bottom: 80px;
    width: 30%;
    z-index: 50;
    cursor: pointer;
}

.nav-area.nav-prev {
    left: 0;
}

.nav-area.nav-next {
    right: 0;
}

/* Navigation Arrows (Desktop) */
.nav-arrow {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    cursor: pointer;
    color: white;
    transition: all 0.3s ease;
    z-index: 60;
}

.nav-arrow:hover {
    background: rgba(0, 0, 0, 0.7);
    transform: translateY(-50%) scale(1.1);
}

.nav-arrow.nav-prev {
    left: calc(50% - 280px);
}

.nav-arrow.nav-next {
    right: calc(50% - 280px);
}

/* Show navigation arrows on desktop */
@media (min-width: 768px) {
    .nav-arrow {
        display: flex;
    }
    
    .nav-area {
        display: none;
    }
}

/* Story Actions */
.story-actions {
    position: absolute;
    bottom: 20px;
    left: 20px;
    right: 20px;
    z-index: 100;
    display: none;
    animation: slideUp 0.3s ease;
}

.story-actions.visible {
    display: block;
}

.action-btn {
    display: block;
    width: 100%;
    padding: 16px 24px;
    background: #0095f6;
    color: white;
    text-align: center;
    text-decoration: none;
    border-radius: 30px;
    font-weight: 600;
    font-size: 16px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 149, 246, 0.3);
}

.action-btn:hover {
    background: #0186e0;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 149, 246, 0.4);
}

/* View Toggle Button */
.view-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 200;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    transition: all 0.3s ease;
}

.view-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

/* Hide view toggle on mobile */
@media (max-width: 767px) {
    .view-toggle {
        display: none;
    }
}

/* Theater Mode */
body.theater-mode {
    background: radial-gradient(ellipse at center, #1a1a1a 0%, #000 100%);
}

body.theater-mode .desktop-header {
    position: fixed;
    left: 40px;
    top: 40px;
    transform: none;
    text-align: left;
    z-index: 100;
    max-width: 300px;
}

body.theater-mode .desktop-header h1 {
    font-size: 2.5rem;
    margin-bottom: 12px;
}

body.theater-mode .desktop-header p {
    font-size: 1.1rem;
}

body.theater-mode .story-viewer {
    max-width: none;
    max-height: 85vh;
    width: auto;
    height: 85vh;
    aspect-ratio: 4/5;
}

/* Theater Side Previews */
.theater-prev,
.theater-next {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 200px;
    height: 60vh;
    opacity: 0;
    visibility: hidden;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.5s ease;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

body.theater-mode .theater-prev,
body.theater-mode .theater-next {
    opacity: 0.3;
    visibility: visible;
}

.theater-prev {
    left: 5%;
}

.theater-next {
    right: 5%;
}

.theater-prev:hover,
.theater-next:hover {
    opacity: 0.5;
    transform: translateY(-50%) scale(1.02);
}

.theater-prev::after,
.theater-next::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.3);
}

/* Theater Navigation Arrows */
body.theater-mode .nav-arrow.nav-prev {
    left: calc(50% - 350px);
}

body.theater-mode .nav-arrow.nav-next {
    right: calc(50% - 350px);
}

/* Theater Navigation Dots */
.nav-dots {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    gap: 8px;
    z-index: 100;
}

body.theater-mode .nav-dots {
    display: flex;
}

.nav-dot {
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
}

.nav-dot.active {
    background: #fff;
    transform: scale(1.2);
}

.nav-dot:hover {
    background: rgba(255, 255, 255, 0.6);
}

/* Auto-scroll Indicator */
.auto-scroll-indicator {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    padding: 8px 16px;
    border-radius: 20px;
    display: none;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    z-index: 100;
}

body.theater-mode .auto-scroll-indicator {
    display: flex;
}

.auto-scroll-indicator.visible {
    display: flex;
}

.auto-scroll-indicator .indicator-icon {
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Help Modal */
.help-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.help-modal.visible {
    display: flex;
}

.help-content {
    background: #1a1a1a;
    padding: 32px;
    border-radius: 16px;
    max-width: 400px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.help-content h3 {
    margin-bottom: 20px;
    font-size: 20px;
}

.help-content ul {
    list-style: none;
}

.help-content li {
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.help-content kbd {
    background: rgba(255, 255, 255, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 14px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Animations */
@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Mobile Theater Mode Responsive Styles */
@media (max-width: 767px) {
    body.theater-mode .desktop-header {
        position: fixed;
        left: 20px;
        top: 20px;
        transform: none;
        text-align: left;
        z-index: 100;
        max-width: 280px;
    }
    
    body.theater-mode .desktop-header h1 {
        font-size: 2rem;
        margin-bottom: 8px;
    }
    
    body.theater-mode .desktop-header p {
        font-size: 0.9rem;
    }
    
    body.theater-mode .story-viewer {
        max-width: none;
        max-height: 100vh;
        width: 100vw;
        height: 100vh;
        border-radius: 0;
    }
    
    body.theater-mode .nav-dots {
        display: flex;
        bottom: 20px;
    }
    
    body.theater-mode .auto-scroll-indicator {
        display: flex;
        bottom: 60px;
        font-size: 12px;
        padding: 6px 12px;
    }
    
    /* Hide theater side previews on mobile */
    body.theater-mode .theater-prev,
    body.theater-mode .theater-next {
        display: none;
    }
    
    /* Adjust navigation arrows for mobile theater mode */
    body.theater-mode .nav-arrow {
        display: none;
    }
}

/* Fullscreen Styles */
body:fullscreen .view-toggle {
    top: 40px;
    right: 40px;
}