/* ============================================================
   FCM Orbits — TikTok-style vertical video feed
   ============================================================ */

/* ── Google Font ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ── CSS Custom Properties ── */
:root {
    --reels-bg:           #000000;
    --reels-surface:      #111111;
    --reels-border:       rgba(255,255,255,0.08);
    --reels-text:         #ffffff;
    --reels-text-muted:   rgba(255,255,255,0.6);
    --reels-accent:       #059669; /* Premium Deep Green */
    --reels-accent-hover: #10b981;
    --reels-overlay-bg:   rgba(0, 0, 0, 0.4);
    --reels-sidebar-bg:   rgba(0, 0, 0, 0.2);
    --reels-glass:        rgba(255, 255, 255, 0.1);
    --reels-gold:         #ffd700;
    --reels-header-h:     56px;
    --reels-filter-h:     48px;
    --reels-sidebar-w:    72px;
    --reels-radius:       16px;
    --reels-transition:   0.22s cubic-bezier(0.4,0,0.2,1);
    --font:               'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

html, body {
    height: 100%;
    background: var(--reels-bg);
    color: var(--reels-text);
    font-family: var(--font);
    overflow: hidden; /* Feed handles its own scroll */
    -webkit-font-smoothing: antialiased;
}

.fcm-reels-body {
    background: var(--reels-bg);
}

a { color: inherit; text-decoration: none; }
button { border: none; background: none; cursor: pointer; color: inherit; font-family: inherit; }
img { display: block; }

/* ── App Container ── */
#fcm-reels-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    position: relative;
    overflow: hidden;
}

/* ============================================================
   HEADER
   ============================================================ */
.reels-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 100;
    height: var(--reels-header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: linear-gradient(180deg, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0) 100%);
    backdrop-filter: blur(0px); /* Transparent top gradient */
    border-bottom: none;
}

.reels-header__logo .site-logo {
    max-height: 32px;
    width: auto;
}

.reels-header__logo .site-name {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: #fff;
}

.reels-header__title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: #fff;
}

.reels-icon-img {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

.reels-beta-badge {
    font-size: 10px;
    text-transform: uppercase;
    background: var(--reels-accent);
    color: #fff;
    padding: 1px 6px;
    border-radius: 4px;
    vertical-align: middle;
    margin-left: 4px;
    font-weight: 800;
    letter-spacing: 0.5px;
}

.reels-header__actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ── Buttons ── */
.reels-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 100px;
    font-size: 13px;
    font-weight: 600;
    transition: opacity var(--reels-transition), transform var(--reels-transition);
    cursor: pointer;
}

.reels-btn:hover { opacity: 0.85; transform: scale(0.97); }

.reels-btn--primary {
    background: var(--reels-accent);
    color: #fff;
}

.reels-btn--ghost {
    background: rgba(255,255,255,0.1);
    color: var(--reels-text);
    border: 1px solid var(--reels-border);
}

/* ============================================================
   FILTER BAR
   ============================================================ */
.reels-filter-bar {
    position: fixed;
    top: var(--reels-header-h);
    left: 0; right: 0;
    z-index: 99;
    height: var(--reels-filter-h);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    overflow-x: auto;
    scrollbar-width: none;
    background: linear-gradient(180deg, rgba(0,0,0,0.6) 0%, rgba(0,0,0,0) 100%);
}

.reels-filter-bar::-webkit-scrollbar { display: none; }

.reels-filter-chip {
    flex-shrink: 0;
    padding: 5px 14px;
    border-radius: 100px;
    font-size: 13px;
    font-weight: 500;
    background: rgba(255,255,255,0.12);
    color: var(--reels-text-muted);
    border: 1px solid rgba(255,255,255,0.1);
    transition: all var(--reels-transition);
    cursor: pointer;
    white-space: nowrap;
}

.reels-filter-chip:hover,
.reels-filter-chip.active {
    background: var(--reels-accent);
    color: #fff;
    border-color: var(--reels-accent);
    box-shadow: 0 0 12px var(--reels-accent-glow);
}

/* ============================================================
   FEED CONTAINER
   ============================================================ */
.reels-feed {
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* Slides wrapper — vertical snap scroll */
.reels-slides {
    height: 100%;
    width: 100%;
    overflow-y: scroll;
    scroll-snap-type: y mandatory;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.reels-slides::-webkit-scrollbar { display: none; }

/* ============================================================
   REEL SLIDE
   ============================================================ */
.reel-slide {
    position: relative;
    height: 100%;
    width: 100%;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    display: flex;
    align-items: stretch;
    background: #000;
    overflow: hidden;
}

/* ── Video ── */
.reel-video-wrap {
    position: absolute;
    inset: 0;
}

.reel-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    background: #000;
}

/* Tap overlay for pause/play */
.reel-tap-overlay {
    position: absolute;
    inset: 0;
    z-index: 2;
    cursor: pointer;
}

/* Pause indicator (shows briefly on pause) */
.reel-pause-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.5);
    z-index: 3;
    font-size: 52px;
    color: rgba(255,255,255,0.85);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s, transform 0.15s;
    text-shadow: 0 0 20px rgba(0,0,0,0.5);
}

.reel-slide.is-paused .reel-pause-indicator {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* ── Dark gradient overlay ── */
.reel-slide::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    background: linear-gradient(
        to top,
        rgba(0,0,0,0.85) 0%,
        rgba(0,0,0,0.3) 40%,
        rgba(0,0,0,0.1) 65%,
        rgba(0,0,0,0.0) 100%
    );
    pointer-events: none;
}

/* ── Progress Bar ── */
.reel-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: rgba(255,255,255,0.2);
    z-index: 10;
}

.reel-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--reels-accent);
    transition: width 0.1s linear;
    border-radius: 2px;
}

/* ── Per-video Loading Spinner ── */
.reel-video-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 4;
    display: none; /* Shown via JS */
    pointer-events: none;
}

.reel-slide.is-loading .reel-video-loading {
    display: block;
}

.reel-slide.is-loading .reel-video-loading {
    display: block;
}

/* ── Info Overlay (left/bottom) ── */
.reel-overlay {
    position: absolute;
    bottom: 80px;
    left: 0;
    right: var(--reels-sidebar-w);
    z-index: 5;
    padding: 0 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.reel-author {
    display: flex;
    align-items: center;
    gap: 10px;
}

.reel-author__avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.8);
    object-fit: cover;
    box-shadow: 0 2px 12px rgba(0,0,0,0.4);
    transition: transform var(--reels-transition);
}

.reel-author__avatar:hover { transform: scale(1.05); }

.reel-author__meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.reel-author__name {
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

.reel-author__name:hover { text-decoration: underline; }

.reel-author__space {
    display: inline-block;
    font-size: 11px;
    font-weight: 500;
    color: rgba(255,255,255,0.75);
    background: rgba(255,255,255,0.12);
    border-radius: 100px;
    padding: 2px 8px;
    border: 1px solid rgba(255,255,255,0.15);
}

.reel-description {
    font-size: 14px;
    line-height: 1.45;
    color: rgba(255,255,255,0.9);
    text-shadow: 0 1px 4px rgba(0,0,0,0.6);
    max-height: 4.5em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

/* ── Right Action Sidebar ── */
.reel-actions {
    position: absolute;
    right: 12px;
    bottom: 80px;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.reel-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: transform var(--reels-transition), background var(--reels-transition);
    position: relative;
}

.reel-action-btn:hover {
    background: rgba(255,255,255,0.1);
    transform: scale(1.1);
}

.reel-action-btn:active { transform: scale(0.92); }

.reel-action-btn__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(0,0,0,0.35);
    backdrop-filter: blur(8px);
    font-size: 20px;
    border: 1.5px solid rgba(255,255,255,0.25);
    transition: all var(--reels-transition);
}

.reel-action-btn__icon svg {
    width: 24px;
    height: 24px;
}

.reel-action-btn__count,
.reel-action-btn__label {
    font-size: 11px;
    font-weight: 600;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

/* Custom Image Icons */
.reel-custom-icon {
    width: 28px;
    height: 28px;
    object-fit: contain;
    filter: brightness(0) invert(1) drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.reels-share-platform img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    margin-bottom: 4px;
    filter: brightness(0) invert(1);
}

.reel-pause-indicator img {
    width: 64px;
    height: 64px;
    object-fit: contain;
}

/* Like button active state */
.reel-like-btn.is-liked .reel-action-btn__icon {
    background: var(--reels-accent);
    border-color: var(--reels-accent);
    box-shadow: 0 0 16px var(--reels-accent-glow);
    animation: likePop 0.3s cubic-bezier(0.175,0.885,0.32,1.275);
}

.reel-like-btn.is-liked .reel-action-btn__icon svg {
    fill: #fff;
    stroke: #fff;
}

@keyframes likePop {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* ============================================================
   MUTE BUTTON
   ============================================================ */
.reels-mute-btn {
    position: fixed;
    top: calc(var(--reels-header-h) + var(--reels-filter-h) + 12px);
    right: 16px;
    z-index: 200;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all var(--reels-transition);
    cursor: pointer;
    color: #fff;
}

.reels-mute-btn:hover {
    background: rgba(255,255,255,0.15);
    transform: scale(1.05);
}

/* ============================================================
   LOADER & EMPTY STATE
   ============================================================ */
.reels-loader,
.reels-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--reels-text-muted);
    z-index: 50;
    background: var(--reels-bg);
}

.reels-loader__spinner {
    width: 44px;
    height: 44px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: var(--reels-accent);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.reels-loader p {
    font-size: 14px;
    font-weight: 500;
}

.reels-empty__icon {
    font-size: 64px;
    opacity: 0.4;
}

.reels-empty h3 {
    font-size: 20px;
    font-weight: 700;
    color: var(--reels-text);
}

.reels-empty p {
    font-size: 14px;
    text-align: center;
    max-width: 260px;
    line-height: 1.6;
}

/* Sentinel for infinite scroll */
.reels-sentinel {
    height: 1px;
}

/* ============================================================
   SHARE MODAL
   ============================================================ */
.reels-modal {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0 0 env(safe-area-inset-bottom);
}

.reels-modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    cursor: pointer;
}

.reels-modal__content {
    position: relative;
    width: 100%;
    max-width: 480px;
    background: #1a1a1a;
    border-radius: var(--reels-radius) var(--reels-radius) 0 0;
    padding: 24px 20px 32px;
    border-top: 1px solid var(--reels-border);
    animation: slideUp 0.3s cubic-bezier(0.4,0,0.2,1);
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

.reels-modal__content h3 {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 16px;
    text-align: center;
    color: var(--reels-accent);
}

.reels-modal__close {
    position: absolute;
    top: 16px;
    right: 16px;
    font-size: 16px;
    color: var(--reels-text-muted);
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background var(--reels-transition);
}

.reels-modal__close:hover { background: rgba(255,255,255,0.1); }

.reels-share-preview {
    width: 100%;
    height: 180px;
    background: #111;
    border-radius: 12px;
    margin-bottom: 20px;
    overflow: hidden;
    display: none;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}
.reels-share-preview-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.reels-share-url {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.reels-share-url input {
    flex: 1;
    background: rgba(255,255,255,0.07);
    border: 1px solid var(--reels-border);
    border-radius: 8px;
    color: var(--reels-accent);
    font-family: var(--font);
    font-size: 13px;
    padding: 10px 12px;
    outline: none;
}

.reels-share-platforms {
    display: flex;
    gap: 10px;
}

.reels-share-platform {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 8px;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--reels-border);
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    transition: all var(--reels-transition);
    cursor: pointer;
    color: var(--reels-text);
}

.reels-share-platform:hover {
    background: rgba(255,255,255,0.12);
    border-color: rgba(255,255,255,0.2);
    transform: translateY(-2px);
}

.reels-share-platform span {
    font-size: 24px;
}

/* ============================================================
   SLIDE ENTRANCE ANIMATION
   ============================================================ */
.reel-slide {
    animation: reel-fade-in 0.3s ease forwards;
}

@keyframes reel-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (min-width: 768px) {
    body.fcm-reels-body {
        background: #0a0a0a; /* Dark background outside the feed */
        display: flex;
        align-items: center;
        justify-content: center;
    }

    #fcm-reels-app {
        width: 100%;
        max-width: 450px;
        height: 100vh;
        max-height: 900px;
        position: relative;
        background: var(--reels-bg);
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.9);
        border-left: 1px solid rgba(255, 255, 255, 0.08);
        border-right: 1px solid rgba(255, 255, 255, 0.08);
    }
    
    .reels-header, .reels-filter-bar {
        position: absolute;
        width: 100%;
        max-width: 100%; /* Inherits from #fcm-reels-app */
    }
}

/* ============================================================
   UTILITY
   ============================================================ */
.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0);
    white-space: nowrap; border: 0;
}
