/* --- Base & Fonts --- */
body {
    margin: 0;
    padding: 0;
    /* Neural network radial gradient background (blue-green) matching the image */
    background: radial-gradient(circle at center, #03384c 0%, #025065 40%, #016c75 75%, #00796b 100%);
    color: #ffffff;
    font-family: 'IBM Plex Sans Arabic', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* Center content vertically */
    min-height: 100vh;
    box-sizing: border-box;
    overflow-x: hidden;
    position: relative;
}

/* Neural Network Elements */
body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100%25' height='100%25'%3E%3Cdefs%3E%3CfilterUnits filterUnits='userSpaceOnUse' height='100%25' width='100%25' x='0' y='0'%3E%3CfeGaussianBlur in='SourceGraphic' stdDeviation='2'/%3E%3C/filter%3E%3C/defs%3E%3Crect width='100%25' height='100%25' fill='none'/%3E%3Cg fill='none' stroke='rgba(255,255,255,0.15)' stroke-width='1'%3E%3Cpath d='M30,90 L60,50 M50,90 L80,60 M80,40 L40,20 M120,30 L150,80 M160,20 L180,60 M90,15 L60,60 M30,20 L80,90'/%3E%3C/g%3E%3Cg fill='rgba(255,255,255,0.2)' filter='url(%23filter)'%3E%3Ccircle cx='30' cy='90' r='3'/%3E%3Ccircle cx='60' cy='50' r='2'/%3E%3Ccircle cx='50' cy='90' r='2'/%3E%3Ccircle cx='80' cy='60' r='3'/%3E%3Ccircle cx='80' cy='40' r='2'/%3E%3Ccircle cx='40' cy='20' r='3'/%3E%3Ccircle cx='120' cy='30' r='2'/%3E%3Ccircle cx='150' cy='80' r='3'/%3E%3Ccircle cx='160' cy='20' r='2'/%3E%3Ccircle cx='180' cy='60' r='3'/%3E%3Ccircle cx='90' cy='15' r='2'/%3E%3Ccircle cx='60' cy='60' r='3'/%3E%3Ccircle cx='30' cy='20' r='2'/%3E%3Ccircle cx='80' cy='90' r='3'/%3E%3C/g%3E%3C/svg%3E");
    background-repeat: repeat;
    opacity: 0.7;
}

/* Network Animation - Random Dots */
@keyframes float {
    0% {
        transform: translateY(0) translateX(0);
    }

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

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

.network-dot {
    position: absolute;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.4);
    animation: float 10s infinite ease-in-out;
}

/* --- Titles --- */
#titleContainer {
    text-align: left;
    margin-bottom: 25px;
    align-self: flex-start;
    margin-left: 10%;
    max-width: 45%;
}

#titleContainer h1 {
    margin: 0;
    font-size: 3.5em;
    color: #ffffff;
    font-weight: 700;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);
}

#titleContainer p {
    margin: 12px 0 0 0;
    font-size: 1.4em;
    color: rgba(255, 255, 255, 0.85);
}

/* --- Loader --- */
#loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(240, 240, 240, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    color: #333;
    font-size: 1.3em;
    text-align: center;
}

.spinner {
    border: 7px solid #ccc;
    border-top: 7px solid #00796b;
    /* Match title color */
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 1.2s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

#loader-status {
    font-weight: 500;
}

/* --- Main Container --- */
#container {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.6s ease-in-out;
    width: 90%;
    max-width: 1200px;
    box-sizing: border-box;
}

#container.loaded {
    opacity: 1;
}

/* --- Wrapper for Video Area --- */
#videoAndMeterWrapper {
    position: relative;
    width: 45%;
    margin-left: auto;
    margin-right: 10%;
}

/* --- Happy Meter (Improved Look) --- */
#happyMeterContainer {
    position: absolute;
    top: 20px;
    right: 20px;
    /* Consistent spacing */
    width: auto;
    min-width: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(0, 0, 0, 0.5);
    /* Lighter, more opaque */
    backdrop-filter: blur(5px);
    /* Frosted glass effect */
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    /* More rounded */
    padding: 12px;
    height: auto;
    z-index: 50;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    /* Softer shadow */
}

#happyMeterTitle {
    color: rgba(255, 255, 255, 0.9);
    font-size: 1em;
    /* Clearer title */
    margin-bottom: 10px;
    text-align: center;
    font-weight: 600;
    /* Bolder */
}

#happyMeterBar {
    width: 40px;
    /* Wider bar */
    height: 240px;
    /* Taller bar */
    background-color: rgba(0, 0, 0, 0.2);
    /* Lighter grey */
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: flex-end;
    border: 1px solid rgba(255, 255, 255, 0.2);
    /* Subtle border */
}

#happyMeterFill {
    width: 100%;
    height: 0%;
    /* Smoother gradient */
    background: linear-gradient(to top, #ff5252, #ffeb3b, #4caf50);
    background-size: 100% 300%;
    background-position: 0% 100%;
    border-radius: 7px;
    /* Match outer radius */
    transition: height 0.5s ease-out, background-position 0.5s ease-out;
}

#happyMeterPercentage {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.9em;
    color: rgba(255, 255, 255, 0.9);
    font-weight: bold;
    z-index: 1;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
    /* Make text readable */
}

/* --- Video Feed & Canvas Overlays --- */
#videoContainer {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    border: none;
    border-radius: 12px;
    overflow: hidden;
    background-color: rgba(0, 0, 0, 0.2);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
}

#videoInput,
#overlayCanvas,
#handOverlayCanvas {
    /* Added handOverlayCanvas */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#videoInput {
    object-fit: cover;
    transform: scaleX(-1);
}

#overlayCanvas {
    z-index: 10;
    background-color: transparent;
    pointer-events: none;
}

/* Face - no pointer events */
#handOverlayCanvas {
    z-index: 9;
    background-color: transparent;
    pointer-events: none;
}

/* Hands behind face - no pointer events */

/* --- Status Display --- */
#statusDisplay {
    position: absolute;
    bottom: 20px;
    /* Position at bottom */
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(98, 196, 98, 0.8);
    /* Darker for better visibility */
    color: #ffffff;
    padding: 12px 24px;
    /* More padding */
    border-radius: 25px;
    /* More rounded */
    font-size: 1.5em;
    /* Larger */
    font-weight: 600;
    /* Bolder */
    z-index: 60;
    /* Above meter */
    opacity: 0;
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out, background-color 0.3s ease-in-out;
    /* Add transform transition */
    pointer-events: none;
    /* Don't block clicks if needed */
    min-width: 200px;
    /* Ensure space */
    text-align: center;
    transform: translateX(-50%) translateY(10px);
    /* Start slightly lower */
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    /* Add shadow for depth */
    border: 1px solid rgba(255, 255, 255, 0.4);
}

#statusDisplay.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    /* Move up to final position */
}

/* Special styling for smile progress indicator */
#statusDisplay:not(.visible) {
    opacity: 0;
}

#statusDisplay[data-smile-progress="true"] {
    background-color: rgba(76, 175, 80, 0.85);
    /* Green background for smile progress */
    border: 2px solid #ffffff;
}

/* --- Quote Display --- */
#quoteContainer {
    margin-top: 20px;
    padding: 15px 25px;
    background-color: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    min-height: 35px;
    width: 100%;
    max-width: 800px;
    text-align: center;
    box-sizing: border-box;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

#quoteDisplay {
    margin: 0;
    font-style: italic;
    color: rgba(255, 255, 255, 0.9);
    opacity: 1;
    transition: opacity 0.5s ease-in-out;
}

#quoteDisplay.fade-out {
    opacity: 0;
}

/* --- Snapshot Button (HIDDEN - for fallback/testing) --- */
#snapshotButton {
    display: none;
}

/* Hide the manual button */
#snapshotSaveFeedback {
    /* Keep for status messages if needed */
    margin-top: 5px;
    margin-bottom: 15px;
    text-align: center;
    font-size: 1em;
    /* Larger feedback text */
    color: #00796b;
    font-weight: 500;
    min-height: 1.4em;
    /* Adjust for larger font */
    width: 100%;
    max-width: 800px;
    transition: opacity 0.4s ease-out;
    opacity: 1;
}

#snapshotSaveFeedback.hidden {
    opacity: 0;
}

/* --- Snapshot Fly-off Animation --- */
.snapshot-fly-off {
    position: fixed;
    z-index: 200;
    transition: opacity 0.5s ease-out, transform 0.5s ease-out;
    pointer-events: none;
    border-radius: 8px;
    border: 2px solid rgb(82, 145, 162);
    box-shadow: 0 0 15px rgba(82, 145, 162, 0.4);
    background-color: #f4f7f6;
}

@keyframes flyAndFade {
    0% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }

    100% {
        transform: translateY(-120vh) scale(0.3);
        opacity: 0;
    }
}

.flying {
    animation: flyAndFade 1.2s ease-in forwards;
}

/* --- Snapshot Preview Modal --- */
.modal {
    display: none;
    /* Initially hidden */
    position: fixed;
    z-index: 900;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.75);
    /* Darker backdrop */
    /* Use Flexbox for centering */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
    opacity: 0;
    /* Start hidden for transition */
    transition: opacity 0.4s ease-in-out;
    pointer-events: none;
    /* Initially not interactive */
}

.modal.visible {
    opacity: 1;
    pointer-events: auto;
    /* Become interactive */
}

.modal-content {
    /* Improved modal styling */
    background-color: #ffffff;
    margin: auto;
    padding: 30px;
    /* More padding */
    border: none;
    border-radius: 15px;
    /* More rounded */
    width: 90%;
    max-width: 550px;
    /* Wider for image + text */
    color: #333;
    position: relative;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    /* Center text */
    /* Animation */
    transform: scale(0.9);
    transition: transform 0.3s ease-out;
}

.modal.visible .modal-content {
    transform: scale(1);
    /* Scale up when visible */
}

/* No close button needed for zero-click */
.modal-content h2 {
    margin-top: 0;
    color: #00796b;
    text-align: center;
    margin-bottom: 20px;
    /* More space */
    font-size: 1.8em;
    font-weight: 600;
}

#dialogSnapshotImage {
    max-width: 100%;
    height: auto;
    /* Maintain aspect ratio */
    max-height: 35vh;
    /* Limit height relative to viewport */
    border-radius: 8px;
    /* Rounded corners */
    margin-bottom: 25px;
    /* More space */
    display: block;
    border: 2px solid #eee;
    /* Subtle border */
    object-fit: contain;
}

#dialogInstruction {
    /* Specific area for instruction */
    font-size: 1.4em;
    /* Larger instruction */
    font-weight: 500;
    color: #d32f2f;
    /* Reddish color for action */
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1.4;
    /* Improve readability */
}

#dialogInstruction .thumb-icon {
    font-size: 1.6em;
    /* Bigger icon */
    margin: 0 10px;
    display: inline-block;
    animation: bounceThumb 1.5s infinite ease-in-out;
}

@keyframes bounceThumb {

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

    50% {
        transform: translateY(-8px);
    }
}

#dialogTimer {
    /* Timer for decision */
    font-size: 1.1em;
    /* Slightly larger */
    color: #555555;
    /* Darker grey */
    margin-bottom: 20px;
    font-weight: 500;
}

/* No buttons needed in the zero-click version */
.dialog-actions {
    display: none;
}

/* --- Error Message --- */
#errorMessage {
    color: #d9534f;
    margin-top: 15px;
    font-weight: bold;
    text-align: center;
    display: none;
    width: 100%;
    max-width: 800px;
    background-color: rgba(255, 235, 238, 0.9);
    /* Light red background */
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #d9534f;
}

/* Network animation container */
#network-animation {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
}

/* Main wrapper for the two-column layout */
#main-wrapper {
    display: flex;
    width: 95%;
    max-width: 1600px;
    margin: 0;
    justify-content: space-between;
    align-items: center;
    min-height: 100vh;
}

/* Left section with title and QR code */
#left-section {
    width: 40%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
}

/* Right section with video and mood meter */
#right-section {
    width: 55%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* QR Code Container */
#qrCodeContainer {
    margin-top: 30px;
    background-color: transparent;
    padding: 15px;
    border-radius: 12px;
    align-self: flex-start;
    transition: transform 0.3s ease;
}

#qrCodeContainer:hover {
    transform: translateY(-5px);
}

#qrCodeCanvas {
    display: block;
    border-radius: 4px;
}

/* Logos Container */
#logosContainer {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 25px;
    margin-top: 30px;
    align-self: flex-start;
}

.partner-logo {
    height: 40px;
    width: auto;
    opacity: 0.9;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.partner-logo:hover {
    opacity: 1;
    transform: translateY(-3px);
}

/* Mood Status Bar */
#moodStatusBar {
    width: 100%;
    background-color: #3498db;
    color: white;
    padding: 12px 20px;
    margin-top: 20px;
    border-radius: 8px;
    text-align: center;
    font-weight: 500;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Title Container - Overrides */
#titleContainer {
    margin-left: 0;
    text-align: left;
    max-width: 100%;
}

#titleContainer h1 {
    font-size: 3.8em;
    line-height: 1.1;
    margin-bottom: 15px;
}

/* Video Container - Overrides */
#videoAndMeterWrapper {
    width: 100%;
    margin: 0;
}

/* Responsive adjustments */
@media (max-width: 992px) {
    #main-wrapper {
        flex-direction: column;
        align-items: center;
        padding: 20px 0;
    }

    #left-section,
    #right-section {
        width: 90%;
        margin-bottom: 30px;
    }

    #titleContainer {
        text-align: center;
        align-items: center;
        max-width: 100%;
        margin-left: 0;
    }

    #titleContainer h1 {
        font-size: 3em;
    }

    #titleContainer p {
        font-size: 1.2em;
    }

    #qrCodeContainer {
        align-self: center;
        margin-top: 25px;
    }

    /* Ensure the loader remains centered */
    #loader {
        padding: 20px;
    }
}

@media (max-width: 576px) {
    #main-wrapper {
        padding: 15px 0;
    }

    #titleContainer h1 {
        font-size: 2.5em;
    }

    #qrCodeCanvas {
        width: 150px;
        height: 150px;
    }
}