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

:root {
    --primary-color: #d4710e;
    --background: #f5f0e8;
    --surface: #ebe3d5;
    --surface-dark: #d9cdb8;
    --text-primary: #32373c;
    --text-secondary: #6b5e4f;
    --error-color: #c0392b;
    --accent-gold: #d4a54a;
    --wood-light: #c49a6c;
    --wood-dark: #8b5e3c;
    --canvas-bg: #faf6ef;
    --shadow-warm: rgba(139, 94, 60, 0.15);
    --loading-bg: #000;
    --font-display: 'Playfair Display', Georgia, serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
    font-family: var(--font-body);
    background: var(--background);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Screen Management */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    background: var(--background);
}

.screen.active {
    opacity: 1;
    visibility: visible;
}

.screen-content {
    width: 90%;
    max-width: 500px;
    text-align: center;
    padding: 2rem;
}

/* Typography */
.app-title {
    font-family: var(--font-display);
    font-size: 2.8rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.app-subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 3rem;
    font-weight: 400;
}

/* Booth branding */
.booth-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.booth-brand-text {
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.booth-brand-logo {
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--primary-color);
    letter-spacing: 0.05em;
}

.booth-divider {
    width: 60px;
    height: 2px;
    background: var(--accent-gold);
    margin: 0 auto 2rem;
    border-radius: 1px;
}

/* Buttons */
.primary-btn,
.secondary-btn {
    padding: 1rem 2rem;
    font-family: var(--font-body);
    font-size: 1.05rem;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 56px;
    min-width: 200px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.primary-btn {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 16px rgba(212, 113, 14, 0.3);
}

.primary-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(212, 113, 14, 0.3);
}

.secondary-btn {
    background: var(--surface);
    color: var(--text-primary);
    margin-top: 1rem;
    border: 2px solid var(--surface-dark);
}

.secondary-btn:active {
    transform: scale(0.95);
    background: var(--surface-dark);
}

/* Theme Selection Screen */
.theme-title {
    font-family: var(--font-display);
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.theme-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-weight: 400;
}

#theme-screen .screen-content {
    max-width: 100%;
    padding: 1.5rem 0;
}

#theme-screen .booth-divider {
    margin-bottom: 1.5rem;
}

/* Carousel */
.theme-carousel {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 1rem;
    padding: 1rem calc(50% - 130px);
    margin-bottom: 0.5rem;
}

.theme-carousel::-webkit-scrollbar {
    display: none;
}

.theme-card {
    flex: 0 0 260px;
    scroll-snap-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--canvas-bg);
    border: 3px solid var(--surface-dark);
    border-radius: 16px;
    padding: 0;
    overflow: hidden;
    font-family: var(--font-body);
    transition: transform 0.3s ease, border-color 0.3s ease;
}

.theme-card.active {
    border-color: var(--primary-color);
    transform: scale(1.02);
}

.theme-card-image {
    width: 100%;
    aspect-ratio: 1;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.theme-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.theme-card-emoji {
    position: absolute;
    font-size: 4rem;
    pointer-events: none;
}

.theme-card-image img + .theme-card-emoji {
    display: none;
}

.theme-card-name {
    padding: 0.75rem 0.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    width: 100%;
}

/* Carousel pagination */
.carousel-pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin: 0.5rem 0;
}

.carousel-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--surface-dark);
    border: none;
    padding: 0;
    transition: background 0.2s ease, transform 0.2s ease;
}

.carousel-dot.active {
    background: var(--primary-color);
    transform: scale(1.3);
}

.carousel-hint {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    font-weight: 400;
}

#choose-theme-btn {
    margin-bottom: 0;
}

/* Loading & error states */
.theme-loading {
    color: var(--text-secondary);
    font-size: 1rem;
    text-align: center;
    padding: 2rem 0;
    flex: 0 0 100%;
}

.theme-error {
    color: var(--text-secondary);
    font-size: 1rem;
    text-align: center;
    padding: 2rem 0;
    flex: 0 0 100%;
}

.theme-retry-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    font-size: 1rem;
    font-family: var(--font-body);
}

/* Camera Screen */
#camera-screen {
    background: var(--text-primary);
}

.camera-container {
    position: relative;
    width: 90%;
    max-width: 500px;
    height: 65vh;
    max-height: 600px;
    background: black;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 2rem;
    border: 6px solid var(--wood-dark);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 0 0 2px var(--wood-light);
}

#camera-feed {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-controls {
    width: 90%;
    max-width: 500px;
    text-align: center;
}

.camera-instruction {
    font-size: 1rem;
    color: var(--surface);
    margin-bottom: 1.5rem;
    font-weight: 500;
}

#camera-screen .primary-btn {
    box-shadow: 0 4px 16px rgba(212, 113, 14, 0.5);
}

#camera-screen .secondary-btn {
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.8);
}

#camera-screen .secondary-btn:active {
    background: rgba(255, 255, 255, 0.1);
}

/* Preview Screen */
.preview-container img {
    transform: scaleX(-1);
}

/* Loading Screen */
#loading-screen {
    padding: 0;
    background: var(--loading-bg);
}

#loading-screen .screen-content {
    width: 100%;
    height: 100%;
    max-width: none;
    padding: 0;
}

/* Artist Animation Video */
.artist-animation {
    width: 100%;
    height: 100%;
    display: none;
    position: relative;
}

.artist-animation.active {
    display: block;
}

/* Fallback text visible while video is buffering */
.artist-animation::before {
    content: 'Creating your caricature...';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.7);
    font-family: var(--font-display);
    font-size: 1.25rem;
    animation: pulse 2s ease-in-out infinite;
    z-index: 0;
}

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

.artist-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    position: relative;
    z-index: 1;
}

@media (min-width: 768px) {
    .artist-video {
        object-fit: contain;
    }
}

/* Result & Preview Screens */
.result-title,
.preview-title {
    font-family: var(--font-display);
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.result-container,
.preview-container {
    width: 100%;
    max-width: 380px;
    margin: 0 auto 2rem;
    border-radius: 4px;
    overflow: hidden;
    border: 8px solid var(--wood-dark);
    box-shadow: 0 8px 32px var(--shadow-warm), inset 0 0 0 2px var(--wood-light);
    background: var(--canvas-bg);
    padding: 8px;
}

#result-image {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 2px;
}

/* Privacy notice on preview screen */
.privacy-notice {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 1.25rem;
    line-height: 1.4;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
}

.result-actions,
.preview-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
}

/* Share Buttons */
.share-row {
    text-align: center;
    margin-bottom: 1.5rem;
}

.share-primary-btn {
    width: 100%;
    max-width: 280px;
    margin: 0 auto 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.share-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    font-weight: 500;
}

.share-buttons {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
}

.share-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid var(--surface-dark);
    background: var(--canvas-bg);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    padding: 0;
}

.share-btn:active {
    transform: scale(0.9);
    background: var(--surface);
}

.share-btn svg {
    pointer-events: none;
}

/* Hidden share buttons (WhatsApp, TikTok, Snapchat) */
.share-btn-hidden {
    display: none;
}

/* Email Capture Screen */
.email-title {
    font-family: var(--font-display);
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.email-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-weight: 400;
}

.email-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1rem;
}

.email-input {
    width: 100%;
    max-width: 320px;
    padding: 1rem;
    font-family: var(--font-body);
    font-size: 1.05rem;
    border: 2px solid var(--surface-dark);
    border-radius: 12px;
    background: var(--canvas-bg);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s ease;
}

.email-input:focus {
    border-color: var(--primary-color);
}

.email-input.invalid {
    border-color: var(--error-color);
}

.terms-checkbox {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    max-width: 320px;
    text-align: left;
    cursor: pointer;
}

.terms-checkbox input[type="checkbox"] {
    margin-top: 0.15rem;
    accent-color: var(--primary-color);
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.terms-checkbox a {
    color: var(--primary-color);
    text-decoration: underline;
}

.email-submit-btn {
    margin-top: 0.5rem;
}

.email-error {
    color: var(--error-color);
    font-size: 0.85rem;
    min-height: 1.2em;
    max-width: 320px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 12px;
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 2000;
    pointer-events: none;
    max-width: 90%;
    text-align: center;
}

.toast.visible {
    opacity: 1;
}

/* Error Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(50, 40, 30, 0.75);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--canvas-bg);
    padding: 2rem;
    border-radius: 16px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    border: 3px solid var(--surface-dark);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
}

.modal-title {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--error-color);
}

.modal-message {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    line-height: 1.6;
}

/* Landscape Lock Overlay */
.landscape-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--background);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    text-align: center;
    padding: 2rem;
}

.landscape-overlay .rotate-icon {
    width: 60px;
    height: 90px;
    border: 3px solid var(--text-secondary);
    border-radius: 10px;
    margin-bottom: 1.5rem;
    position: relative;
    animation: rotatePhone 2s ease-in-out infinite;
}

.landscape-overlay .rotate-icon::after {
    content: '';
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 14px;
    height: 14px;
    border: 2px solid var(--text-secondary);
    border-radius: 50%;
}

@keyframes rotatePhone {
    0%, 100% { transform: rotate(0deg); }
    25%, 75% { transform: rotate(-90deg); }
}

.landscape-overlay p {
    font-family: var(--font-display);
    font-size: 1.3rem;
    color: var(--text-primary);
    font-weight: 700;
}

.landscape-overlay .rotate-hint {
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 400;
    margin-top: 0.5rem;
}

@media (orientation: landscape) and (max-height: 600px) {
    .landscape-overlay {
        display: flex;
    }
}

/* Responsive Design */
@media (max-width: 480px) {
    .app-title {
        font-size: 2.2rem;
    }

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

    .primary-btn,
    .secondary-btn {
        min-width: 160px;
        font-size: 1rem;
    }

    .camera-container {
        height: 60vh;
    }

}

/* Large screens (tablets, booth) */
@media (min-width: 768px) {
    .app-title {
        font-size: 3.5rem;
    }

    .app-subtitle {
        font-size: 1.3rem;
    }

    .primary-btn,
    .secondary-btn {
        font-size: 1.2rem;
        min-width: 240px;
        min-height: 64px;
    }

    .theme-carousel {
        padding: 1rem calc(50% - 160px);
    }

    .theme-card {
        flex: 0 0 320px;
    }

    .theme-title {
        font-size: 2.2rem;
    }
}
