/* ============================================
   ACCESSIBILITY UTILITIES
   ============================================ */
/* Visually hide content while keeping it accessible to screen readers. */
.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;
}

/* ============================================
   ROOT ELEMENTS - Prevent Layout Shifts
   ============================================ */
html {
    /* Lock the viewport */
    height: 100%;
    overflow: hidden;
    /* Prevent iOS text size adjustment */
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Arial', sans-serif;
    /* Dark background to match screens */
    background-color: #111418;
    color: #333;
    margin: 0;
    padding: 0;
    /* NO flexbox centering - screens handle their own layout */
    display: block;
    /* Fixed height - no min-height that could resize */
    height: 100%;
    /* Prevent any overflow that might cause layout shifts */
    overflow: hidden;
    /* Prevent iOS bounce scroll */
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
}

.container {
    background-color: #fff;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    text-align: center;
    max-width: 600px;
    width: 100%;
}

h1 {
    color: #4a90e2;
    margin-bottom: 10px;
}

.tagline {
    color: #666;
    margin-bottom: 30px;
}

.button {
    background-color: #4a90e2;
    color: white;
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s ease;
    margin: 5px;
}

.button:hover {
    background-color: #357ABD;
}

.button.hidden {
    display: none;
}

.auth-section,
.app-section,
.loading-section,
.result-section,
.error-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

.auth-section p,
.app-section p {
    margin-bottom: 20px;
}

/* Firebase UI */
#firebaseui-auth-container {
    margin-top: 20px;
}

/* Upload Area */
.upload-area {
    border: 2px dashed #ccc;
    border-radius: 10px;
    padding: 30px;
    margin-bottom: 20px;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

.upload-area:hover {
    border-color: #4a90e2;
}

.upload-button {
    display: inline-block;
    padding: 15px 30px;
    font-size: 18px;
}

.upload-hint {
    color: #888;
    margin-top: 10px;
}

input[type="file"] {
    display: none;
}

/* Loading Area - Artistic Brushstroke Animation */
.brush-loader {
    position: relative;
    width: 220px;
    height: 220px;
    /* Fixed margins to prevent layout shifts */
    margin: 0 auto 40px auto;
    /* Prevent any flex resizing */
    flex-shrink: 0;
    flex-grow: 0;
    /* Canvas background */
    background: radial-gradient(ellipse at center, rgba(25, 128, 230, 0.05) 0%, transparent 70%);
    border-radius: 12px;
}

/* Artistic brush stroke styles */
.brush-stroke {
    position: absolute;
    border-radius: 50% 20% 50% 20%;
    opacity: 0;
    transform-origin: left center;
    /* More realistic brush texture */
    filter: blur(0.5px);
}

/* Main colorful strokes - Fauvist palette */
.brush-stroke:nth-child(1) {
    top: 25%;
    left: 15%;
    width: 90px;
    height: 12px;
    background: linear-gradient(90deg,
            transparent 0%,
            #e63946 20%,
            #ff6b6b 50%,
            #e63946 80%,
            transparent 100%);
    transform: rotate(-12deg);
    animation: artisticStroke1 3s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.brush-stroke:nth-child(2) {
    top: 45%;
    left: 25%;
    width: 100px;
    height: 14px;
    background: linear-gradient(90deg,
            transparent 0%,
            #1980e6 15%,
            #4dabf7 50%,
            #1980e6 85%,
            transparent 100%);
    transform: rotate(18deg);
    animation: artisticStroke2 3s cubic-bezier(0.4, 0, 0.2, 1) 0.4s infinite;
}

.brush-stroke:nth-child(3) {
    top: 60%;
    left: 10%;
    width: 85px;
    height: 10px;
    background: linear-gradient(90deg,
            transparent 0%,
            #f4a261 20%,
            #ffb347 50%,
            #f4a261 80%,
            transparent 100%);
    transform: rotate(-22deg);
    animation: artisticStroke3 3s cubic-bezier(0.4, 0, 0.2, 1) 0.8s infinite;
}

.brush-stroke:nth-child(4) {
    top: 35%;
    left: 45%;
    width: 75px;
    height: 11px;
    background: linear-gradient(90deg,
            transparent 0%,
            #2a9d8f 15%,
            #52c7b8 50%,
            #2a9d8f 85%,
            transparent 100%);
    transform: rotate(8deg);
    animation: artisticStroke4 3s cubic-bezier(0.4, 0, 0.2, 1) 1.2s infinite;
}

.brush-stroke:nth-child(5) {
    top: 70%;
    left: 35%;
    width: 95px;
    height: 13px;
    background: linear-gradient(90deg,
            transparent 0%,
            #9b5de5 20%,
            #c77dff 50%,
            #9b5de5 80%,
            transparent 100%);
    transform: rotate(-8deg);
    animation: artisticStroke5 3s cubic-bezier(0.4, 0, 0.2, 1) 1.6s infinite;
}

/* Artistic stroke animations with paint drip effect */
@keyframes artisticStroke1 {
    0% {
        opacity: 0;
        transform: rotate(-12deg) scaleX(0) translateX(-10px);
        filter: blur(2px);
    }

    20% {
        opacity: 0.9;
        filter: blur(0.5px);
    }

    50% {
        opacity: 1;
        transform: rotate(-12deg) scaleX(1.1) translateX(0);
        filter: blur(0);
    }

    80% {
        opacity: 0.7;
        transform: rotate(-12deg) scaleX(1) translateX(5px);
    }

    100% {
        opacity: 0;
        transform: rotate(-12deg) scaleX(0.8) translateX(10px);
        filter: blur(1px);
    }
}

@keyframes artisticStroke2 {
    0% {
        opacity: 0;
        transform: rotate(18deg) scaleX(0) translateX(-15px);
        filter: blur(2px);
    }

    25% {
        opacity: 0.95;
        filter: blur(0.3px);
    }

    55% {
        opacity: 1;
        transform: rotate(18deg) scaleX(1.05) translateX(0);
        filter: blur(0);
    }

    85% {
        opacity: 0.6;
        transform: rotate(18deg) scaleX(0.95) translateX(8px);
    }

    100% {
        opacity: 0;
        transform: rotate(18deg) scaleX(0.7) translateX(15px);
        filter: blur(1.5px);
    }
}

@keyframes artisticStroke3 {
    0% {
        opacity: 0;
        transform: rotate(-22deg) scaleX(0) translateX(-8px);
        filter: blur(1.5px);
    }

    30% {
        opacity: 0.85;
        filter: blur(0.5px);
    }

    60% {
        opacity: 1;
        transform: rotate(-22deg) scaleX(1.15) translateX(0);
        filter: blur(0);
    }

    90% {
        opacity: 0.5;
    }

    100% {
        opacity: 0;
        transform: rotate(-22deg) scaleX(0.9) translateX(12px);
        filter: blur(2px);
    }
}

@keyframes artisticStroke4 {
    0% {
        opacity: 0;
        transform: rotate(8deg) scaleX(0) translateX(-12px);
        filter: blur(2px);
    }

    35% {
        opacity: 0.9;
        filter: blur(0.3px);
    }

    65% {
        opacity: 1;
        transform: rotate(8deg) scaleX(1.08) translateX(0);
        filter: blur(0);
    }

    100% {
        opacity: 0;
        transform: rotate(8deg) scaleX(0.85) translateX(10px);
        filter: blur(1.5px);
    }
}

@keyframes artisticStroke5 {
    0% {
        opacity: 0;
        transform: rotate(-8deg) scaleX(0) translateX(-10px);
        filter: blur(2px);
    }

    40% {
        opacity: 0.88;
        filter: blur(0.5px);
    }

    70% {
        opacity: 1;
        transform: rotate(-8deg) scaleX(1.12) translateX(0);
        filter: blur(0);
    }

    100% {
        opacity: 0;
        transform: rotate(-8deg) scaleX(0.75) translateX(8px);
        filter: blur(1.5px);
    }
}

/* Watercolor stain effect */
.wc {
    position: absolute;
    opacity: 0;
    mix-blend-mode: screen;
    animation: bloom var(--bdu, 1.8s) ease-out var(--bde) forwards;
}

@keyframes bloom {
    0% {
        opacity: 0;
        transform: scale(0.2);
        filter: blur(10px);
    }

    40% {
        opacity: 0.6;
        filter: blur(4px);
    }

    100% {
        opacity: var(--bo, 0.45);
        transform: scale(1);
        filter: blur(1px);
    }
}

/* SVG stroke containers */
.stroke-svg {
    position: absolute;
    overflow: visible;
}

/* Brush path base styles */
.brush-path {
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Draw animation for strokes */
.brush-path.draw {
    stroke-dasharray: var(--l);
    stroke-dashoffset: var(--l);
    animation: drawStroke var(--du) cubic-bezier(0.25, 0.1, 0.25, 1) var(--de) forwards;
}

@keyframes drawStroke {
    0% {
        stroke-dashoffset: var(--l);
        opacity: 0;
    }

    5% {
        opacity: 1;
    }

    100% {
        stroke-dashoffset: 0;
        opacity: 1;
    }
}

/* Wet paint effect underneath */
.brush-path.wet {
    animation: wetPaint 0.5s ease-out var(--wde) forwards;
    opacity: 0;
}

@keyframes wetPaint {
    0% {
        opacity: 0;
        filter: blur(3px);
    }

    100% {
        opacity: var(--wo, 0.4);
        filter: blur(1px);
    }
}

/* Paint splatters */
.splat {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    opacity: 0;
    animation: splatPop 0.3s ease-out var(--sde) forwards;
    box-shadow: 0 0 6px currentColor;
}

@keyframes splatPop {
    0% {
        opacity: 0;
        transform: scale(0);
    }

    60% {
        transform: scale(1.3);
    }

    100% {
        opacity: 0.85;
        transform: scale(1);
    }
}

/* ============================================
   SCREEN STYLES - Full viewport coverage
   ============================================ */

/* All screens take full viewport */
.screen.active {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
}

/* Processing screen - no scrolling, fixed layout */
#processing-screen.screen.active {
    overflow: hidden;
}

/* Fixed height for inspirational message to prevent text reflow */
#inspirational-message {
    min-height: 4rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Upload screen - allow scrolling when history section overflows */
#upload-screen.screen.active {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Result screen - allow scrolling for content (iOS needs -webkit-overflow-scrolling) */
#result-screen.screen.active {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.canvas-text {
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    color: #9dabb8;
    font-size: 14px;
    font-style: italic;
    white-space: nowrap;
}

#loading-message {
    font-size: 1.1em;
    color: #555;
    margin-top: 20px;
}

/* Reveal Animation for Result */
.artwork-reveal {
    animation: revealArtwork 1.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    transform-origin: center;
}

@keyframes revealArtwork {
    0% {
        opacity: 0;
        filter: blur(20px);
        transform: scale(0.95);
    }

    40% {
        opacity: 1;
        filter: blur(10px);
        transform: scale(0.97);
    }

    70% {
        filter: blur(3px);
        transform: scale(0.99);
    }

    100% {
        opacity: 1;
        filter: blur(0);
        transform: scale(1);
    }
}

/* Celebration effect (optional) */
.confetti-particle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #1980e6;
    opacity: 0;
    animation: confettiFall 1.5s ease-out forwards;
}

@keyframes confettiFall {
    0% {
        opacity: 1;
        transform: translateY(0) rotate(0deg);
    }

    100% {
        opacity: 0;
        transform: translateY(100px) rotate(360deg);
    }
}

/* Result Area */
.image-comparator {
    margin: 20px 0;
    border: 1px solid #eee;
    border-radius: 8px;
    overflow: hidden;
}

.action-buttons {
    margin-top: 20px;
}

/* Error Area */
.error-section {
    color: #d9534f;
    font-weight: bold;
}

.error-section button {
    background-color: #d9534f;
}

.error-section button:hover {
    background-color: #c9302c;
}

/* ============================================
   RESULT SCREEN - Adaptive Image Display
   ============================================ */

/* Image container adapts to image aspect ratio */
.image-display-container {
    /* Let image define the container size naturally */
    max-height: calc(100vh - 240px);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Ensure images display properly within container */
.image-display-container>img {
    max-width: 100%;
    max-height: calc(100vh - 240px);
    width: auto;
    height: auto;
    object-fit: contain;
}

/* Portrait images get more vertical space on mobile */
@media (max-width: 640px) {
    .image-display-container {
        max-height: calc(100vh - 200px);
    }

    .image-display-container>img {
        max-height: calc(100vh - 200px);
    }

    /* Compact buttons on mobile */
    #comparison-container .flex.gap-2.mb-3 button {
        padding: 0.375rem 0.75rem;
        font-size: 0.8125rem;
    }

    /* Smaller action buttons */
    #result-screen .flex.gap-3 button {
        height: 2.75rem;
        font-size: 0.875rem;
    }
}

/* ============================================
   HISTORY SECTION - Recent Artworks Grid
   ============================================ */

.history-card {
    animation: historyFadeIn 0.3s ease-out forwards;
    opacity: 0;
    background-color: #1a1d21;
    border: 1px solid #293038;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.history-card:hover {
    border-color: #1980e6;
    transform: scale(1.02);
}

@keyframes historyFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* History grid responsive */
@media (max-width: 640px) {
    #history-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 0.5rem !important;
    }
}

@media (min-width: 641px) and (max-width: 1024px) {
    #history-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}

/* ============================================
   LIGHTBOX - Full screen image viewer
   ============================================ */

.artwork-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.artwork-lightbox.active {
    opacity: 1;
}

.lightbox-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    cursor: pointer;
}

.lightbox-content {
    position: relative;
    z-index: 1;
    max-width: 95vw;
    max-height: 95vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-image {
    max-width: 90vw;
    max-height: 90vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    animation: lightboxZoomIn 0.3s ease-out forwards;
}

@keyframes lightboxZoomIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.artwork-lightbox:not(.active) .lightbox-image {
    animation: lightboxZoomOut 0.3s ease-in forwards;
}

@keyframes lightboxZoomOut {
    from {
        opacity: 1;
        transform: scale(1);
    }

    to {
        opacity: 0;
        transform: scale(0.8);
    }
}

.lightbox-close {
    position: absolute;
    top: -40px;
    right: 0;
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: background 0.2s ease, transform 0.2s ease;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.lightbox-close svg {
    width: 20px;
    height: 20px;
}

/* ============================================
   AUTH TABS - Sign In / Sign Up Toggle
   ============================================ */

.auth-tab {
    background: transparent;
    border: none;
    color: #9dabb8;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.3s ease;
}

.auth-tab:hover {
    color: #fff;
}

.auth-tab.active {
    color: #1980e6;
    border-bottom-color: #1980e6;
}