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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #000;
    color: #fff;
    overflow: hidden;
    height: 100vh;
}

#app {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* Background Video */
#background-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
}

/* Display Mode Chip */
.mode-chip {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    z-index: 1000;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.mode-chip.image-mode {
    background: rgba(76, 175, 80, 0.8);
}

.mode-chip.text-mode {
    background: rgba(117, 117, 117, 0.8);
}

/* Floating Messages Container */
.floating-messages-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
    overflow: hidden;
    perspective: 1000px;
    perspective-origin: center center;
}

/* Floating Message Styles */
.floating-message {
    position: absolute;
    pointer-events: none;
    animation: floatAround 20s linear infinite;
    opacity: 0;
    animation-fill-mode: forwards;
}

.floating-message.text {
    background: rgba(47, 36, 193, 0.9);
    color: #FFD700;
    padding: 12px 20px;
    border-radius: 25px;
    font-size: 24px;
    font-weight: 700;
    box-shadow: 
        0 4px 15px rgba(47, 36, 193, 0.3),
        0 8px 30px rgba(47, 36, 193, 0.2),
        0 0 0 1px rgba(255, 255, 255, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.2),
        0 0 20px rgba(47, 36, 193, 0.4),
        0 0 40px rgba(47, 36, 193, 0.2);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    max-width: 300px;
    word-wrap: break-word;
    text-align: center;
    transform-style: preserve-3d;
    text-shadow: 
        -2px -2px 0 #000,
        2px -2px 0 #000,
        -2px 2px 0 #000,
        2px 2px 0 #000,
        -1px -1px 0 #000,
        1px -1px 0 #000,
        -1px 1px 0 #000,
        1px 1px 0 #000,
        0 0 4px rgba(0, 0, 0, 0.8),
        0 0 8px rgba(0, 0, 0, 0.6),
        0 0 12px rgba(0, 0, 0, 0.4);
    position: relative;
    /* Force 3D rendering */
    transform: translateZ(0);
    will-change: transform;
}

.floating-message.text::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, 
        rgba(255, 255, 255, 0.1) 0%, 
        rgba(255, 255, 255, 0.05) 50%, 
        rgba(0, 0, 0, 0.1) 100%);
    border-radius: 25px;
    z-index: -1;
    transform: translateZ(-1px);
}

.floating-message.text::after {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, 
        rgba(47, 36, 193, 0.3), 
        rgba(76, 175, 80, 0.3), 
        rgba(255, 193, 7, 0.3), 
        rgba(47, 36, 193, 0.3));
    border-radius: 27px;
    z-index: -2;
    transform: translateZ(-2px);
    animation: borderGlow 3s ease-in-out infinite alternate;
}

/* 3D text extrusion effect */
.floating-message.text::before {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(47, 36, 193, 0.9);
    color: #FFD700;
    padding: 12px 20px;
    border-radius: 25px;
    font-size: 24px;
    font-weight: 700;
    text-align: center;
    z-index: -1;
    transform: translateZ(-5px);
    opacity: 0.7;
    text-shadow: 
        -2px -2px 0 #000,
        2px -2px 0 #000,
        -2px 2px 0 #000,
        2px 2px 0 #000,
        -1px -1px 0 #000,
        1px -1px 0 #000,
        -1px 1px 0 #000,
        1px 1px 0 #000;
}

@keyframes borderGlow {
    0% {
        opacity: 0.3;
        transform: translateZ(-2px) scale(1);
    }
    100% {
        opacity: 0.6;
        transform: translateZ(-2px) scale(1.02);
    }
}

.floating-message.image {
    background: rgba(255, 255, 255, 0.9);
    padding: 8px;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.floating-message.image img {
    width: 200px;
    height: 200px;
    object-fit: cover;
    border-radius: 10px;
    display: block;
}

/* Floating Animation */
@keyframes floatAround {
    0% {
        opacity: 0;
        transform: translateY(100vh) rotate(0deg) rotateX(0deg) rotateY(0deg);
    }
    10% {
        opacity: 1;
    }
    25% {
        transform: translateY(75vh) rotate(90deg) rotateX(15deg) rotateY(10deg);
    }
    50% {
        transform: translateY(50vh) rotate(180deg) rotateX(0deg) rotateY(20deg);
    }
    75% {
        transform: translateY(25vh) rotate(270deg) rotateX(-15deg) rotateY(10deg);
    }
    90% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: translateY(-100px) rotate(360deg) rotateX(0deg) rotateY(0deg);
    }
}

/* Different floating patterns with 3D variations */
.floating-message:nth-child(odd) {
    animation: floatAround 25s linear infinite;
    animation-delay: 0s;
}

.floating-message:nth-child(even) {
    animation: floatAround 30s linear infinite;
    animation-delay: 5s;
}

.floating-message:nth-child(3n) {
    animation: floatAround 35s linear infinite;
    animation-delay: 10s;
}

.floating-message:nth-child(4n) {
    animation: floatAround 28s linear infinite;
    animation-delay: 15s;
}

/* 3D text-specific animations */
.floating-message.text:nth-child(odd) {
    animation: floatAround3D 25s linear infinite;
    animation-delay: 0s;
}

.floating-message.text:nth-child(even) {
    animation: floatAround3D 30s linear infinite;
    animation-delay: 5s;
}

.floating-message.text:nth-child(3n) {
    animation: floatAround3D 35s linear infinite;
    animation-delay: 10s;
}

.floating-message.text:nth-child(4n) {
    animation: floatAround3D 28s linear infinite;
    animation-delay: 15s;
}

/* Enhanced 3D floating animation for text */
@keyframes floatAround3D {
    0% {
        opacity: 0;
        transform: translateY(100vh) rotate(0deg) rotateX(0deg) rotateY(0deg) translateZ(0px) scale(0.8);
    }
    10% {
        opacity: 1;
        transform: translateY(90vh) rotate(36deg) rotateX(15deg) rotateY(10deg) translateZ(20px) scale(0.9);
    }
    20% {
        transform: translateY(80vh) rotate(72deg) rotateX(30deg) rotateY(20deg) translateZ(40px) scale(1.0);
    }
    30% {
        transform: translateY(70vh) rotate(108deg) rotateX(20deg) rotateY(30deg) translateZ(30px) scale(1.1);
    }
    40% {
        transform: translateY(60vh) rotate(144deg) rotateX(40deg) rotateY(40deg) translateZ(50px) scale(1.0);
    }
    50% {
        transform: translateY(50vh) rotate(180deg) rotateX(0deg) rotateY(50deg) translateZ(60px) scale(1.2);
    }
    60% {
        transform: translateY(40vh) rotate(216deg) rotateX(-20deg) rotateY(40deg) translateZ(50px) scale(1.1);
    }
    70% {
        transform: translateY(30vh) rotate(252deg) rotateX(-40deg) rotateY(30deg) translateZ(40px) scale(1.0);
    }
    80% {
        transform: translateY(20vh) rotate(288deg) rotateX(-15deg) rotateY(20deg) translateZ(30px) scale(0.9);
    }
    90% {
        opacity: 1;
        transform: translateY(10vh) rotate(324deg) rotateX(-5deg) rotateY(10deg) translateZ(20px) scale(0.8);
    }
    100% {
        opacity: 0;
        transform: translateY(-100px) rotate(360deg) rotateX(0deg) rotateY(0deg) translateZ(0px) scale(0.7);
    }
}

/* Controls */
#controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    z-index: 1000;
}

.control-btn {
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 10px 20px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.4);
    transform: translateY(-2px);
}

/* Message History */
#message-history {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    max-width: 600px;
    max-height: 70%;
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    backdrop-filter: blur(20px);
    z-index: 2000;
    overflow: hidden;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.history-header h3 {
    font-size: 18px;
    font-weight: 600;
}

#close-history {
    background: none;
    border: none;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s ease;
}

#close-history:hover {
    background: rgba(255, 255, 255, 0.1);
}

#history-content {
    padding: 20px;
    max-height: 400px;
    overflow-y: auto;
}

.message-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 10px;
    transition: all 0.3s ease;
}

.message-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.message-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
}

.message-content {
    font-size: 14px;
    line-height: 1.4;
}

.message-image {
    max-width: 100%;
    max-height: 200px;
    border-radius: 8px;
    margin-top: 10px;
}

/* Loading Indicator */
#loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 3000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

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

/* Notification */
#notification {
    position: absolute;
    top: 80px;
    right: 20px;
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    padding: 15px 20px;
    backdrop-filter: blur(20px);
    z-index: 3000;
    max-width: 300px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.notification-content {
    display: flex;
    align-items: center;
    gap: 10px;
}

#close-notification {
    background: none;
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s ease;
}

#close-notification:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Responsive Design */
@media (max-width: 768px) {
    #controls {
        bottom: 10px;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .control-btn {
        padding: 8px 16px;
        font-size: 12px;
    }
    
    #message-history {
        width: 95%;
        max-height: 80%;
    }
    
    .mode-chip {
        top: 10px;
        right: 10px;
        padding: 6px 12px;
        font-size: 12px;
    }
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    width: 90%;
    max-width: 800px;
    max-height: 90%;
    overflow: hidden;
    backdrop-filter: blur(20px);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header h3 {
    font-size: 20px;
    font-weight: 600;
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s ease;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.modal-body {
    padding: 20px;
    max-height: 70vh;
    overflow-y: auto;
}

.modal-body h4 {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 15px 0;
    color: rgba(255, 255, 255, 0.9);
}

/* Current Background Section */
.current-background {
    margin-bottom: 30px;
}

#current-background-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#current-background-name {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
    margin: 0;
}

/* Background Grid */
.background-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.background-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
}

.background-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.background-item.active {
    background: rgba(76, 175, 80, 0.2);
    border-color: rgba(76, 175, 80, 0.5);
}

.background-item video {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 10px;
}

.background-item .background-name {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    margin: 0;
    word-break: break-word;
}

.background-item .background-actions {
    margin-top: 10px;
    display: flex;
    gap: 5px;
    justify-content: center;
}

.background-item .action-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.background-item .action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.background-item .action-btn.set-btn {
    background: rgba(76, 175, 80, 0.3);
    border-color: rgba(76, 175, 80, 0.5);
}

.background-item .action-btn.delete-btn {
    background: rgba(244, 67, 54, 0.3);
    border-color: rgba(244, 67, 54, 0.5);
}

/* Upload Section */
.upload-section {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 20px;
}

.upload-area {
    border: 2px dashed rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 15px;
}

.upload-area:hover {
    border-color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.05);
}

.upload-area.dragover {
    border-color: rgba(76, 175, 80, 0.5);
    background: rgba(76, 175, 80, 0.1);
}

.upload-placeholder p {
    margin: 5px 0;
    color: rgba(255, 255, 255, 0.7);
}

.upload-hint {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
}

.upload-btn {
    background: rgba(76, 175, 80, 0.8);
    border: 1px solid rgba(76, 175, 80, 0.5);
    color: #fff;
    padding: 10px 20px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    width: 100%;
}

.upload-btn:hover {
    background: rgba(76, 175, 80, 1);
    transform: translateY(-2px);
}

.upload-btn:disabled {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    cursor: not-allowed;
    transform: none;
}

/* Loading States */
.background-item.loading {
    opacity: 0.6;
    pointer-events: none;
}

.background-item.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Scrollbar Styling */
#history-content::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
    width: 6px;
}

#history-content::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

#history-content::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

#history-content::-webkit-scrollbar-thumb:hover,
.modal-body::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}
