:root {
    --bg-deep: #050507;
    --text-primary: #ffffff;
    --text-secondary: #8a8a9b;
    --accent-core: #3b82f6;
    --accent-glow: rgba(59, 130, 246, 0.5);
    --surface-glass: rgba(255, 255, 255, 0.03);
    --border-glass: rgba(255, 255, 255, 0.08);
    --font-display: 'Space Grotesk', sans-serif;
    --font-body: 'Inter', sans-serif;
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    font-family: var(--font-body);
    color: var(--text-primary);
    overflow-x: hidden;
    height: 100%;
    width: 100%;
    -webkit-overflow-scrolling: touch;
    /* iOS smooth scrolling */
}

body {
    background-color: var(--bg-deep);
    position: relative;
    overflow-y: auto;
    /* Allow vertical scrolling */
}

/* Cinematic Background */
.cinematic-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    background:
        radial-gradient(ellipse at 20% 30%, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 70%, rgba(168, 85, 247, 0.12) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(59, 130, 246, 0.08) 0%, transparent 60%),
        linear-gradient(135deg, #0a0e27 0%, #1a1f3a 30%, #0f1419 60%, #000000 100%);
    animation: backgroundShift 20s ease-in-out infinite;
}

@keyframes backgroundShift {

    0%,
    100% {
        background-position: 0% 0%, 100% 100%, 50% 50%, 0% 0%;
    }

    50% {
        background-position: 100% 100%, 0% 0%, 60% 40%, 0% 0%;
    }
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.3;
    animation: float 20s ease-in-out infinite;
}

.orb-1 {
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.4) 0%, transparent 70%);
    top: -15%;
    right: -15%;
    animation: float 25s ease-in-out infinite;
}

.orb-2 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(168, 85, 247, 0.35) 0%, transparent 70%);
    bottom: -15%;
    left: -10%;
    animation: float 30s ease-in-out infinite reverse;
}

/* Add subtle noise texture overlay */
.cinematic-bg::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.03'/%3E%3C/svg%3E");
    opacity: 0.5;
    pointer-events: none;
}

/* Animated particles */
.cinematic-bg::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(2px 2px at 20% 30%, rgba(255, 255, 255, 0.3), transparent),
        radial-gradient(2px 2px at 60% 70%, rgba(99, 102, 241, 0.4), transparent),
        radial-gradient(1px 1px at 50% 50%, rgba(168, 85, 247, 0.3), transparent),
        radial-gradient(1px 1px at 80% 10%, rgba(255, 255, 255, 0.2), transparent),
        radial-gradient(2px 2px at 90% 60%, rgba(99, 102, 241, 0.3), transparent),
        radial-gradient(1px 1px at 33% 80%, rgba(255, 255, 255, 0.2), transparent);
    background-size: 200% 200%;
    background-position: 0% 0%;
    animation: particleFloat 40s ease-in-out infinite;
    opacity: 0.6;
}

@keyframes particleFloat {

    0%,
    100% {
        background-position: 0% 0%, 10% 20%, 20% 80%, 80% 10%, 95% 70%, 30% 90%;
    }

    50% {
        background-position: 100% 100%, 90% 80%, 80% 20%, 20% 90%, 5% 30%, 70% 10%;
    }
}

@keyframes float {

    0%,
    100% {
        transform: translate(0, 0) scale(1);
    }

    33% {
        transform: translate(40px, -40px) scale(1.1);
    }

    66% {
        transform: translate(-30px, 30px) scale(0.95);
    }
}

/* App Container */
.app-container {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-overflow-scrolling: touch;
    /* iOS smooth scrolling */
    padding: 2rem;
}

/* Top Bar */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.5rem;
    letter-spacing: 0.05em;
}

.brand-icon {
    color: var(--accent-core);
    text-shadow: 0 0 10px var(--accent-glow);
}

.system-status {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    letter-spacing: 0.1em;
    background: var(--surface-glass);
    padding: 0.5rem 1rem;
    border-radius: 100px;
    border: 1px solid var(--border-glass);
    backdrop-filter: blur(10px);
}

.status-dot {
    width: 6px;
    height: 6px;
    background-color: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 8px #10b981;
}

/* Main Stage */
.main-stage {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    position: relative;
    gap: 2rem;
}

.content-wrapper {
    width: 100%;
    max-width: 900px;
    position: relative;
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Image Viewport */
.image-viewport {
    position: relative;
    width: 100%;
    max-width: 900px;
    aspect-ratio: 16/9;
    margin: 0 auto;
    border-radius: 8px;
    overflow: hidden;
    background: rgba(10, 14, 39, 0.4);
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    transition: all 0.5s var(--ease-out-expo);
    display: flex;
    justify-content: center;
    align-items: center;
}

.image-viewport.viewport-hidden {
    opacity: 0;
    transform: scale(0.95);
    pointer-events: none;
}

.image-viewport.viewport-visible {
    animation: viewportSlideIn 0.6s var(--ease-out-expo) forwards;
}

@keyframes viewportSlideIn {
    0% {
        opacity: 0;
        transform: scale(0.95) translateY(20px);
    }

    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.viewport-overlay {
    position: absolute;
    inset: 0;
    box-shadow: inset 0 0 150px rgba(0, 0, 0, 0.8);
    pointer-events: none;
    z-index: 2;
}

#resultImage {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 1.5s var(--ease-out-expo), transform 1.5s var(--ease-out-expo);
    transform: scale(1.05);
}

#resultImage.visible {
    opacity: 1;
    transform: scale(1);
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    color: var(--text-secondary);
}

.scanner-ring {
    width: 60px;
    height: 60px;
    border: 1px solid var(--border-glass);
    border-radius: 50%;
    position: relative;
}

.scanner-ring::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    border: 2px solid transparent;
    border-top-color: var(--accent-core);
    /* Animation removed for idle state */
    transform: rotate(45deg);
}

.empty-text {
    font-family: var(--font-display);
    letter-spacing: 0.1em;
    font-size: 0.9rem;
    opacity: 0.7;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 90%;
    text-align: center;
}

@media (max-width: 768px) {
    .empty-text {
        font-size: 0.7rem;
        letter-spacing: 0.05em;
        max-width: 95%;
    }
}

/* Loader */
.generation-loader {
    position: absolute;
    inset: 0;
    background: rgba(5, 5, 7, 0.8);
    backdrop-filter: blur(20px);
    z-index: 10;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 2rem;
}

.progress-bar-container {
    width: 300px;
    height: 2px;
    background: var(--surface-glass);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--accent-core);
    width: 0%;
    box-shadow: 0 0 10px var(--accent-core);
    transition: width 0.3s linear;
}

.loader-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 90%;
    font-family: var(--font-display);
    font-size: 0.8rem;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
    padding: 0 1rem;
}

.loader-step {
    color: var(--text-primary);
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 70%;
    text-align: left;
}

@media (max-width: 768px) {
    .loader-info {
        flex-direction: column;
        gap: 0.5rem;
        font-size: 0.7rem;
        max-width: 95%;
        padding: 0 0.5rem;
    }

    .loader-step {
        font-size: 0.65rem;
        max-width: 100%;
        text-align: center;
        letter-spacing: 0.02em;
    }
}

/* Controls Layer */
.controls-layer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    pointer-events: none;
    width: 100%;
    max-width: 900px;
    z-index: 20;
}

.prompt-readout {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border-glass);
    max-width: 600px;
    width: 90%;
    text-align: center;
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.5s var(--ease-out-expo);
}

.prompt-readout.visible {
    transform: translateY(0);
    opacity: 1;
}

.readout-label {
    font-family: var(--font-display);
    font-size: 0.7rem;
    color: var(--accent-core);
    letter-spacing: 0.1em;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

.readout-text {
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text-primary);
}

/* Action Button */
.action-btn {
    pointer-events: auto;
    background: transparent;
    border: none;
    position: relative;
    padding: 1.2rem 3rem;
    cursor: pointer;
    overflow: hidden;
    border-radius: 100px;
    transition: transform 0.2s var(--ease-out-expo);
    width: max-content;
    flex-shrink: 0;
    z-index: 25;
}

.btn-bg {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    opacity: 0.9;
    border-radius: 100px;
    transition: opacity 0.3s;
}

.btn-text {
    position: relative;
    z-index: 2;
    color: white;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: 0.1em;
}

.btn-shine {
    position: absolute;
    top: 0;
    left: -100%;
    width: 50%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transform: skewX(-20deg);
    transition: left 0.5s;
    z-index: 1;
}

.action-btn:hover {
    transform: scale(1.05);
}

.action-btn:hover .btn-bg {
    opacity: 1;
    box-shadow: 0 0 30px var(--accent-glow);
}

.action-btn:hover .btn-shine {
    left: 150%;
}

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

.action-btn:disabled {
    filter: grayscale(0.8);
    cursor: not-allowed;
    transform: none;
}

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

.hidden {
    display: none !important;
}

/* Responsive */
@media (max-width: 768px) {
    .image-viewport {
        aspect-ratio: 4/5;
    }

    .orb-1 {
        width: 90vw;
        height: 90vw;
    }

    .orb-2 {
        width: 80vw;
        height: 80vw;
    }
}

/* History Panel */
.history-panel {
    position: absolute;
    right: 2rem;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    pointer-events: none;
    /* Allow clicks to pass through container */
    z-index: 30;
}

.loader-percentage {
    font-family: var(--font-display);
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 600;
}

@media (max-width: 768px) {
    .loader-percentage {
        font-size: 0.75rem;
    }
}

.history-label {
    font-family: var(--font-display);
    font-size: 0.7rem;
    color: var(--text-secondary);
    letter-spacing: 0.1em;
    text-align: right;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    position: absolute;
    right: -2rem;
    top: 0;
    height: 100%;
    pointer-events: auto;
}

.history-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    pointer-events: auto;
    max-height: 60vh;
    overflow-y: auto;
    padding-right: 0.5rem;
}

/* Scrollbar styling */
.history-grid::-webkit-scrollbar {
    width: 4px;
}

.history-grid::-webkit-scrollbar-track {
    background: transparent;
}

.history-grid::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.3);
    border-radius: 2px;
}

.history-grid::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.5);
}

.history-thumb {
    width: 80px;
    height: 45px;
    border-radius: 4px;
    border: 1px solid var(--border-glass);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s var(--ease-out-expo);
    position: relative;
    opacity: 0.6;
}

.history-thumb:hover {
    opacity: 1;
    border-color: var(--accent-core);
    box-shadow: 0 0 15px var(--accent-glow);
}

.history-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.history-thumb.active {
    border-color: var(--accent-core);
    opacity: 1;
    box-shadow: 0 0 10px var(--accent-glow);
}

@media (max-width: 768px) {
    .history-panel {
        position: relative;
        right: auto;
        top: auto;
        transform: none;
        flex-direction: row;
        width: 100%;
        justify-content: center;
        margin-bottom: 1rem;
    }

    .history-label {
        display: none;
    }

    .history-grid {
        flex-direction: row;
    }

    .history-thumb {
        width: 50px;
        height: 62px;
    }
}

/* Hero Section */
.hero-section {
    text-align: center;
    padding: 2rem;
    width: 100%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 1;
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.hero-section.hero-hidden {
    opacity: 0;
    transform: translate(-50%, -50%) translateY(-20px);
    pointer-events: none;
}

.hero-title {
    font-family: var(--font-display);
    font-size: 3rem;
    font-weight: 600;
    background: linear-gradient(135deg, #ffffff 0%, #a78bfa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 1rem;
    letter-spacing: -0.02em;
}

.hero-subtitle {
    font-family: var(--font-body);
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-bottom: 3rem;
    font-weight: 300;
}

.hero-hint {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    opacity: 0.6;
    animation: bounce 2s ease-in-out infinite;
}

.hint-icon {
    font-size: 1.5rem;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(10px);
    }
}

@media (max-width: 768px) {
    .hero-title {
        font-size: 2rem;
    }

    .hero-subtitle {
        font-size: 1rem;
    }
}

/* Mode Switcher */
.mode-switcher {
    display: flex;
    gap: 0.5rem;
    background: rgba(10, 14, 39, 0.6);
    padding: 0.5rem;
    border-radius: 100px;
    border: 1px solid rgba(99, 102, 241, 0.2);
    pointer-events: auto;
    margin-bottom: 1rem;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: none;
    border-radius: 100px;
    color: var(--text-secondary);
    font-family: var(--font-display);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s var(--ease-out-expo);
    letter-spacing: 0.05em;
}

.mode-btn:hover {
    color: var(--text-primary);
    background: rgba(99, 102, 241, 0.1);
}

.mode-btn.active {
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.mode-icon {
    font-size: 1.1rem;
}

/* Custom Prompt Input */
.custom-prompt-container {
    width: 100%;
    max-width: 600px;
    pointer-events: auto;
    margin-bottom: 1rem;
    opacity: 1;
    transform: translateY(0);
    transition: all 0.3s var(--ease-out-expo);
}

.custom-prompt-container.hidden {
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
    height: 0;
    margin: 0;
    overflow: hidden;
}

.custom-prompt-input {
    width: 100%;
    padding: 1rem 1.5rem;
    background: rgba(10, 14, 39, 0.6);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 100px;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.95rem;
    outline: none;
    transition: all 0.3s var(--ease-out-expo);
}

.custom-prompt-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

.custom-prompt-input:focus {
    border-color: var(--accent-core);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.2);
    background: rgba(10, 14, 39, 0.8);
}

@media (max-width: 768px) {
    .mode-switcher {
        width: 100%;
        justify-content: center;
    }

    .mode-btn {
        flex: 1;
        justify-content: center;
    }
}

/* Disabled state for custom prompt input */
.custom-prompt-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: rgba(99, 102, 241, 0.1);
}

/* iOS Safari fixes */
@supports (-webkit-touch-callout: none) {
    body {
        /* Prevent iOS Safari from disabling scrolling */
        position: relative;
        overflow-y: auto;
    }

    .app-container {
        /* Ensure proper height calculation on iOS */
        min-height: -webkit-fill-available;
    }
}