/* ===== CSS Custom Properties ===== */
:root {
    --text-color: #ffffff;
    --text-shadow: 0 2px 20px rgba(0, 0, 0, 0.8);
    --overlay-bg: rgba(0, 0, 0, 0.1);
    --transition-duration: 0.6s;
    --edge-blur-height: 150px;
}

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: #000;
    color: var(--text-color);
    line-height: 1.6;
    overflow-x: hidden;
}

/* ===== Story Container ===== */
#story-container {
    width: 100%;
}

/* ===== Frame Base Styles ===== */
.frame {
    position: relative;
    width: 100%;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* ===== Media Container (for images and videos) ===== */
.frame__media {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.frame__media img,
.frame__media video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

/* Portrait media - optional letterboxing style */
.frame--portrait .frame__media img,
.frame--portrait .frame__media video {
    object-fit: contain;
    background-color: #000;
}

/* Force cover for portrait if preferred */
.frame--portrait.frame--cover .frame__media img,
.frame--portrait.frame--cover .frame__media video {
    object-fit: cover;
}

/* ===== Sticky Parallax Text Frames ===== */
.frame--sticky-text {
    /* Extra height: 100vh (frame) + 50vh (delay) + text + 100vh (scroll away) */
    min-height: 300vh;
    display: block;
    overflow: visible;
}

.frame__sticky {
    position: sticky;
    top: 0;
    width: 100%;
    height: 100vh;
    overflow: hidden;
    z-index: 1;
}

.frame__sticky .frame__media {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.frame__sticky .frame__media video,
.frame__sticky .frame__media img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.frame__text-scroller {
    position: relative;
    z-index: 10;
    /* Start text below the viewport */
    margin-top: -100vh;
    /* Delay before text appears (extra scroll after frame loads) */
    padding-top: 100vh;
    /* Text must scroll completely off before frame unpins */
    padding-bottom: 50vh;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    pointer-events: none;
}

.frame__text-scroller .frame__text {
    pointer-events: auto;
    opacity: 1;
    transform: none;
    margin: 0 auto;
    max-width: 600px;
    padding: 2rem;
}

/* Text horizontal alignment for sticky frames */
.frame__text-scroller--left {
    align-items: flex-start;
    padding-left: 5%;
}

.frame__text-scroller--left .frame__text {
    margin: 0;
}

.frame__text-scroller--right {
    align-items: flex-end;
    padding-right: 5%;
}

.frame__text-scroller--right .frame__text {
    margin: 0;
}

/* Text vertical position for sticky frames */
/* Bottom: text appears at bottom of viewport while scrolling */
.frame__text-scroller--bottom .frame__text {
    margin-top: 60vh;
}

/* Top: text appears at top of viewport while scrolling */
.frame__text-scroller--top .frame__text {
    margin-top: 10vh;
}

/* Center: text appears in middle (default) */
.frame__text-scroller--center .frame__text {
    margin-top: 35vh;
}

/* ===== Color Background Frame ===== */
.frame--color {
    background-color: var(--frame-bg-color, #1a1a2e);
}

/* No text shadow on color frames (looks cleaner) */
.frame--color .frame__title,
.frame--color .frame__subtitle,
.frame--color .frame__body {
    text-shadow: none;
}

/* ===== Title Frame ===== */
.frame--title {
    background-color: var(--frame-bg-color, #1a1a2e);
}

.frame--title .frame__title,
.frame--title .frame__subtitle,
.frame--title .frame__body {
    text-shadow: none;
}

/* Title frame text is always visible */
.frame--title .frame__text {
    opacity: 1;
    transform: none;
}

/* ===== Smooth Edge Transitions ===== */
.frame::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: var(--edge-blur-height);
    background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.8) 0%,
        rgba(0, 0, 0, 0.4) 40%,
        transparent 100%
    );
    z-index: 2;
    pointer-events: none;
}

.frame::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--edge-blur-height);
    background: linear-gradient(
        to top,
        rgba(0, 0, 0, 0.8) 0%,
        rgba(0, 0, 0, 0.4) 40%,
        transparent 100%
    );
    z-index: 2;
    pointer-events: none;
}

/* First frame - no top gradient */
.frame:first-child::before {
    display: none;
}

/* Last frame - no bottom gradient */
.frame:last-child::after {
    display: none;
}

/* No gradients on color/title frames */
.frame--color::before,
.frame--color::after,
.frame--title::before,
.frame--title::after {
    display: none;
}

/* ===== Text Overlay ===== */
.frame__text {
    position: relative;
    z-index: 10;
    max-width: 800px;
    padding: 2rem;
    text-align: center;
    opacity: 0;
    transform: translateY(30px);
    transition:
        opacity var(--transition-duration) ease-out,
        transform var(--transition-duration) ease-out;
}

.frame.is-visible .frame__text {
    opacity: 1;
    transform: translateY(0);
}

/* Text with background box */
.frame__text--boxed {
    background: var(--overlay-bg);
    border-radius: 8px;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

/* Text Positioning */
.frame--text-top {
    align-items: flex-start;
}

.frame--text-top .frame__text {
    margin-top: 15vh;
}

.frame--text-center {
    align-items: center;
}

.frame--text-bottom {
    align-items: flex-end;
}

.frame--text-bottom .frame__text {
    margin-bottom: 15vh;
}

/* Text box horizontal position */
.frame--text-left {
    justify-content: flex-start;
}

.frame--text-left .frame__text {
    margin-left: 5vw;
}

.frame--text-right {
    justify-content: flex-end;
}

.frame--text-right .frame__text {
    margin-right: 5vw;
}

/* ===== Typography ===== */
.frame__title {
    font-size: clamp(2rem, 5vw, 4rem);
    font-weight: 700;
    margin-bottom: 1rem;
    text-shadow: var(--text-shadow);
    line-height: 1.2;
}

.frame__subtitle {
    font-size: clamp(1.2rem, 2.5vw, 1.8rem);
    font-weight: 400;
    margin-bottom: 1rem;
    text-shadow: var(--text-shadow);
    opacity: 0.9;
}

.frame__body {
    font-size: clamp(1rem, 1.5vw, 1.25rem);
    font-weight: 300;
    text-shadow: var(--text-shadow);
    opacity: 0.85;
    max-width: 600px;
    margin: 0 auto;
}

.frame--text-left .frame__body {
    margin: 0;
}

.frame--text-right .frame__body {
    margin: 0 0 0 auto;
}

/* ===== Scroll Indicator (optional, for first frame) ===== */
.scroll-indicator {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    opacity: 0.7;
    animation: bounce 2s infinite;
}

.scroll-indicator__text {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.scroll-indicator__arrow {
    width: 30px;
    height: 30px;
    border-right: 2px solid var(--text-color);
    border-bottom: 2px solid var(--text-color);
    transform: rotate(45deg);
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateX(-50%) translateY(0);
    }
    40% {
        transform: translateX(-50%) translateY(-10px);
    }
    60% {
        transform: translateX(-50%) translateY(-5px);
    }
}

/* ===== Tap to Start Overlay ===== */
.tap-to-start {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    cursor: pointer;
    transition: opacity 0.3s ease;
}

.tap-to-start__content {
    text-align: center;
    color: white;
    opacity: 0.9;
}

.tap-to-start__icon {
    width: 80px;
    height: 80px;
    border: 3px solid white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 15px;
    animation: pulse 2s infinite;
}

.tap-to-start__icon::after {
    content: '';
    width: 0;
    height: 0;
    border-left: 25px solid white;
    border-top: 15px solid transparent;
    border-bottom: 15px solid transparent;
    margin-left: 5px;
}

.tap-to-start__text {
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 2px;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.9;
    }
    50% {
        transform: scale(1.05);
        opacity: 1;
    }
}

.tap-to-start.is-hidden {
    opacity: 0;
    pointer-events: none;
}

/* ===== Responsive Adjustments ===== */
@media (max-width: 768px) {
    :root {
        --edge-blur-height: 100px;
    }

    .frame__text {
        padding: 1.5rem;
    }

    .frame--text-top .frame__text {
        margin-top: 10vh;
    }

    .frame--text-bottom .frame__text {
        margin-bottom: 10vh;
    }

    .frame--text-left .frame__text,
    .frame--text-right .frame__text {
        margin-left: 1rem;
        margin-right: 1rem;
    }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    .frame__text {
        transition: none;
        opacity: 1;
        transform: none;
    }

    .scroll-indicator {
        animation: none;
    }
}

/* ===== Auth Section ===== */
.auth-section {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2d2d2d;
}

.auth-container {
    text-align: center;
    padding: 3rem;
    max-width: 400px;
}

.auth-container h1 {
    font-size: clamp(2rem, 5vw, 3rem);
    margin-bottom: 1rem;
    font-weight: 700;
}

.auth-container p {
    font-size: 1.1rem;
    opacity: 0.8;
    margin-bottom: 2rem;
}

.auth-button {
    background: #fff;
    color: #1a1a2e;
    border: none;
    padding: 1rem 3rem;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.auth-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(255, 255, 255, 0.2);
}

.auth-loading {
    margin-top: 2rem;
}

/* ===== Logout Button ===== */
.logout-button {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 100;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    border-radius: 4px;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: background 0.2s, opacity 0.3s ease;
}

.logout-button:hover {
    background: rgba(0, 0, 0, 0.7);
}

/* ===== Stories Button ===== */
.stories-btn {
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 100;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    border-radius: 4px;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: background 0.2s, opacity 0.3s ease;
    text-decoration: none;
}

.stories-btn:hover {
    background: rgba(0, 0, 0, 0.7);
}

/* ===== Stories Index Page ===== */
.stories-index {
    min-height: 100vh;
    background: #1a1a1a;
    color: #fff;
    padding: 2rem;
}

.stories-header {
    text-align: center;
    padding: 2rem 0 3rem;
}

.stories-header__title {
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 700;
    margin: 0;
}

.stories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.story-card {
    background: #2d2d2d;
    border-radius: 12px;
    overflow: hidden;
    text-decoration: none;
    color: #fff;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.story-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.story-card__thumbnail {
    width: 100%;
    height: 200px;
    background-size: cover;
    background-position: center;
}

.story-card__content {
    padding: 1.5rem;
}

.story-card__date {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.6;
    margin-bottom: 0.5rem;
}

.story-card__title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0 0 0.5rem 0;
}

.story-card__subtitle {
    font-size: 0.9rem;
    opacity: 0.8;
    margin: 0;
    line-height: 1.4;
}

.stories-error {
    text-align: center;
    opacity: 0.6;
    grid-column: 1 / -1;
}

@media (max-width: 768px) {
    .stories-index {
        padding: 1rem;
    }

    .stories-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .story-card__thumbnail {
        height: 180px;
    }
}

/* ===== Utility ===== */
.hidden {
    display: none !important;
}
