/* ==========================================================================
   MIRAI DEMO — TikTok-Style Immersive Mobile Showcase
   Engineered for Android & iOS Viewports (100dvh, 9:16 Aspect Ratio)
   Ultra-clean, High-Performance, Zero-Clutter Architecture
   ========================================================================== */

/* --- 1. CSS Reset & Typography --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-black: #000000;
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.72);
    --text-tertiary: rgba(255, 255, 255, 0.45);
    
    /* Clean accents */
    --accent: #ffffff;
    --glass-bg: rgba(20, 20, 24, 0.65);
    --glass-border: rgba(255, 255, 255, 0.12);
    
    /* Safe areas for Android & iOS */
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    
    /* Typography */
    --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter', system-ui, sans-serif;
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

html, body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    height: 100svh;
    overflow: hidden;
    position: fixed;
    inset: 0;
    background-color: var(--bg-black);
    color: var(--text-primary);
    font-family: var(--font);
    user-select: none;
    -webkit-user-select: none;
}

/* --- 2. Top Floating Navigation --- */
.floating-top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: max(var(--sat), 12px) 16px 12px;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.35) 60%, transparent 100%);
    pointer-events: none;
}

.top-bar-left, .top-bar-center, .top-bar-right {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: #fff;
    text-decoration: none;
}

.brand-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 8px #10b981;
    animation: pulse-live 2s infinite ease-in-out;
}

@keyframes pulse-live {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.6; }
}

.category-trigger-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
}
.category-trigger-btn:active {
    transform: scale(0.96);
    background: rgba(255, 255, 255, 0.2);
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 15px;
    text-decoration: none;
    transition: all 0.2s var(--ease-out);
}
.icon-btn:active {
    transform: scale(0.92);
    background: rgba(255, 255, 255, 0.25);
}

/* --- 3. Announcement Toast (Floating Non-intrusive) --- */
.announcement-toast {
    position: fixed;
    top: calc(max(var(--sat), 12px) + 52px);
    left: 50%;
    transform: translateX(-50%) translateY(0);
    z-index: 110;
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(18, 18, 22, 0.88);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 70, 70, 0.3);
    padding: 8px 16px;
    border-radius: 30px;
    font-size: 12px;
    font-weight: 500;
    color: #fff;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    transition: all 0.4s var(--ease-out);
    white-space: nowrap;
    max-width: 90vw;
}

.announcement-toast.dismissed {
    transform: translateX(-50%) translateY(-24px);
    opacity: 0;
    pointer-events: none;
}

.toast-close-btn {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* --- 4. Main TikTok Feed Container (100dvh snap-scroll) --- */
.feed-viewport {
    width: 100%;
    height: 100%;
    height: 100dvh;
    height: 100svh;
    overflow-y: scroll;
    overflow-x: hidden;
    scroll-snap-type: y mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    background: #000;
}
.feed-viewport::-webkit-scrollbar { display: none; }

@media (min-width: 601px) {
    .feed-viewport {
        display: flex;
        flex-direction: column;
        align-items: center;
    }
}

/* --- 5. Fullscreen Card --- */
.feed-card {
    position: relative;
    width: 100%;
    height: 100%;
    height: 100dvh;
    height: 100svh;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    overflow: hidden;
    background: #000;
    display: flex;
    justify-content: center;
}

@media (min-width: 601px) {
    .feed-card {
        max-width: 440px;
        box-shadow: 0 0 80px rgba(0, 0, 0, 0.9), 0 0 0 1px rgba(255, 255, 255, 0.08);
    }
}

/* --- 6. Media Layers (Smart Aspect Ratio Handling) --- */
.media-carousel {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: flex;
    transition: transform 0.35s var(--ease-out);
    will-change: transform;
}

.media-slide {
    position: relative;
    flex-shrink: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #000;
}

/* Blurred ambient background clone for landscape/square videos */
.media-ambient-bg {
    position: absolute;
    inset: -30px;
    width: calc(100% + 60px);
    height: calc(100% + 60px);
    object-fit: cover;
    filter: blur(35px) brightness(0.38);
    transform: scale(1.15);
    z-index: 1;
    pointer-events: none;
}

/* Main hero video / image */
.media-hero {
    position: relative;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 2;
    display: block;
}

/* Center play/pause indicator */
.play-indicator-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.6);
    z-index: 10;
    width: 68px;
    height: 68px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(16px);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 26px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.22s var(--ease-out);
}
.play-indicator-overlay.active {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* --- 7. Right Action Bar --- */
.action-rail {
    position: absolute;
    right: 12px;
    bottom: calc(max(var(--sab), 16px) + 84px);
    z-index: 40;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    pointer-events: auto;
}

.action-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    color: #fff;
}

.action-circle {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(24, 24, 28, 0.55);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: #fff;
    transition: transform 0.18s var(--ease-out), background 0.18s;
}
.action-item:active .action-circle {
    transform: scale(0.9);
    background: rgba(255, 255, 255, 0.25);
}

.action-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}

/* --- 8. Bottom Information & Integrated Overlay --- */
.bottom-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 30;
    padding: 0 16px calc(max(var(--sab), 16px) + 10px);
    background: linear-gradient(to top, 
        rgba(0, 0, 0, 0.96) 0%, 
        rgba(0, 0, 0, 0.78) 45%, 
        rgba(0, 0, 0, 0.25) 78%, 
        transparent 100%);
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bottom-info-block {
    pointer-events: auto;
    max-width: calc(100% - 64px);
    display: flex;
    flex-direction: column;
    gap: 5px;
}

/* Sleek Badges Row: Category + Generation Cost + Optional Example Pill */
.meta-badges-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.category-pill-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    color: #ffffff;
    letter-spacing: 0.02em;
}

.cost-pill-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 193, 7, 0.16);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 193, 7, 0.4);
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    color: #ffca28;
    letter-spacing: 0.02em;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
}

.example-counter-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    padding: 3px 9px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
}

/* Template headline: prominent, clean, never obscured */
.template-headline {
    font-size: 20px;
    font-weight: 800;
    line-height: 1.25;
    color: #ffffff;
    text-shadow: 0 2px 14px rgba(0, 0, 0, 0.95), 0 1px 4px rgba(0, 0, 0, 0.85);
    letter-spacing: -0.015em;
    word-break: break-word;
    margin: 1px 0;
}

.prompt-caption {
    font-size: 12px;
    line-height: 1.35;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
}

/* Inline Slide Dots (integrated smoothly below prompt) */
.inline-dots-row {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 2px 0;
    pointer-events: auto;
}

.inline-dot {
    width: 7px;
    height: 7px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.3);
    border: none;
    cursor: pointer;
    padding: 0;
    transition: all 0.25s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.inline-dot.active {
    width: 20px;
    background: #ffffff;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.7);
}

/* High-Converting Primary CTA Button */
.cta-generate-btn {
    pointer-events: auto;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #ffffff;
    color: #000000;
    padding: 12px 20px;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 700;
    text-decoration: none;
    letter-spacing: -0.01em;
    box-shadow: 0 4px 24px rgba(255, 255, 255, 0.25), 0 2px 8px rgba(0, 0, 0, 0.5);
    transition: transform 0.18s var(--ease-out), background 0.18s;
}
.cta-generate-btn:active {
    transform: scale(0.98);
    background: #ebebeb;
}

/* Secondary Fallback Deeplink Row */
.deeplink-fallback-row {
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 1px 2px 0 2px;
    width: 100%;
}

.fallback-copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.16);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #ffffff;
    font-size: 11.5px;
    font-weight: 600;
    padding: 6px 11px;
    border-radius: 10px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}
.fallback-copy-btn:hover {
    background: rgba(255, 255, 255, 0.16);
}
.fallback-copy-btn:active {
    transform: scale(0.96);
}
.fallback-copy-btn.copied {
    background: rgba(76, 175, 80, 0.25);
    border-color: rgba(76, 175, 80, 0.6);
    color: #81c784;
}

.fallback-hint {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.62);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
    text-align: right;
    line-height: 1.25;
    flex: 1;
}

/* Video playback progress line */
.video-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2.5px;
    background: rgba(255, 255, 255, 0.2);
    z-index: 50;
    pointer-events: none;
}
.video-progress-fill {
    height: 100%;
    width: 0%;
    background: #ffffff;
    transition: width 0.1s linear;
}

/* --- 10. Clean Empty State (When Owner Hasn't Added Templates Yet) --- */
.empty-feed-card {
    width: 100%;
    height: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    background: radial-gradient(circle at center, #111116 0%, #000000 100%);
    gap: 16px;
}

.empty-badge {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
}

.empty-title {
    font-size: 22px;
    font-weight: 800;
    color: #fff;
    letter-spacing: -0.02em;
}

.empty-desc {
    font-size: 14px;
    color: var(--text-secondary);
    max-width: 320px;
    line-height: 1.5;
}

.empty-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 280px;
    margin-top: 8px;
}

.admin-open-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    padding: 12px 18px;
    border-radius: 14px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid var(--glass-border);
    transition: all 0.2s;
}
.admin-open-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

.empty-hint {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 8px;
}

/* --- 11. Modals & Sheets --- */
.category-sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    z-index: 300;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s var(--ease-out);
    display: flex;
    align-items: flex-end;
    justify-content: center;
}
.category-sheet-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

.category-sheet {
    width: 100%;
    max-width: 500px;
    background: #141418;
    border-top: 1px solid var(--glass-border);
    border-radius: 24px 24px 0 0;
    padding: 16px 20px calc(max(var(--sab), 16px) + 20px);
    transform: translateY(100%);
    transition: transform 0.35s var(--ease-out);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}
.category-sheet-backdrop.active .category-sheet {
    transform: translateY(0);
}

.sheet-handle-bar {
    width: 38px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.25);
    margin: 0 auto 16px;
}

.sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.sheet-title {
    font-size: 17px;
    font-weight: 700;
    color: #fff;
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    overflow-y: auto;
}

.cat-tile {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
    color: #fff;
    text-align: left;
}
.cat-tile:active, .cat-tile.active {
    background: rgba(255, 255, 255, 0.16);
    border-color: #fff;
}
.cat-tile-title {
    font-size: 14px;
    font-weight: 600;
}
.cat-tile-count {
    font-size: 11px;
    color: var(--text-tertiary);
}

/* All Templates Search Modal */
.templates-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 400;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s var(--ease-out);
    display: flex;
    justify-content: center;
}
.templates-modal-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

.templates-modal {
    width: 100%;
    max-width: 520px;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: max(var(--sat), 16px) 16px max(var(--sab), 16px);
}

.search-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.search-input-box {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 10px 14px;
}
.search-input-box input {
    width: 100%;
    background: none;
    border: none;
    color: #fff;
    font-size: 14px;
    outline: none;
}
.search-input-box input::placeholder {
    color: var(--text-tertiary);
}

.modal-close-btn {
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.templates-scroll-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-right: 4px;
}

.template-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
}
.template-list-item:active {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.3);
}

.item-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.item-title {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}
.item-category {
    font-size: 11px;
    color: var(--text-tertiary);
}
.item-arrow {
    color: var(--text-tertiary);
    font-size: 16px;
}

/* Loading & Toast */
.feed-loader {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    transition: opacity 0.4s var(--ease-out);
}
.feed-loader.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader-spinner {
    width: 32px;
    height: 32px;
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.mini-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: rgba(20, 20, 24, 0.92);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s var(--ease-out);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
}
.mini-toast.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* Instant First Frame Poster Cover */
.media-poster-cover {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    z-index: 2;
    transition: opacity 0.35s ease, visibility 0.35s ease;
    pointer-events: none;
}

.media-poster-cover.hidden {
    opacity: 0;
    visibility: hidden;
}

/* Favorite Heart Pop & Active State */
.fav-btn.active .action-circle {
    background: rgba(233, 30, 99, 0.28);
    border-color: rgba(233, 30, 99, 0.65);
    box-shadow: 0 0 16px rgba(233, 30, 99, 0.45);
}

.fav-circle.heart-pop {
    animation: heartPop 0.45s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes heartPop {
    0% { transform: scale(1); }
    45% { transform: scale(1.4); }
    100% { transform: scale(1); }
}

/* Search Modal List Enhancements */
.item-title-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.item-fav-tag {
    font-size: 12px;
}
.item-meta-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 2px;
}
.item-cost {
    font-size: 11px;
    font-weight: 700;
    color: #ffca28;
    background: rgba(255, 193, 7, 0.12);
    border: 1px solid rgba(255, 193, 7, 0.25);
    padding: 1px 6px;
    border-radius: 6px;
}
