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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    min-height: 100vh;
    overflow: hidden;
    position: relative;
}

#advanced-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.4);
    padding: 10px 20px;
    font-size: 0.9rem;
    border-radius: 8px;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

#advanced-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

#sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 320px;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(20px);
    padding: 30px 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    transition: transform 0.3s ease;
    z-index: 100;
}

#sidebar.show {
    transform: translateX(0);
}

#sidebar:not(.show) {
    transform: translateX(-100%);
}

h1 {
    font-size: 2rem;
    margin-bottom: 0;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    text-align: left;
}

.subtitle {
    font-size: 0.9rem;
    opacity: 0.9;
    text-align: left;
}

#canvas-container {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 320px;
    overflow: hidden;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: left 0.3s ease;
}

#canvas-container.fullwidth {
    left: 0;
}

#video {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scaleX(-1);
    max-width: 100%;
    max-height: 100%;
    opacity: 0.3;
}

#motion-canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none; /* Hidden, used for motion detection */
}

#grid-canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0.8;
}

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

@keyframes pulse {
    0%, 100% {
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        transform: translate(-50%, -50%) scale(1.08);
    }
}

@keyframes shrinkOut {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    25% {
        transform: translate(-50%, -50%) scale(1.15);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }
}

@keyframes expandIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

#start-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: transparent;
    color: white;
    border: none;
    padding: 20px 60px;
    font-size: 1.5rem;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 500;
    animation: pulse 2s ease-in-out infinite;
    box-shadow: 0 0 30px rgba(255, 0, 255, 0.6),
                0 0 60px rgba(128, 0, 128, 0.4);
    font-weight: 600;
    letter-spacing: 1px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

#start-btn::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, #FF00FF 0%, #9D00FF 25%, #800080 50%, #9D00FF 75%, #FF00FF 100%);
    animation: rotateGradient 8s linear infinite;
    z-index: -1;
}

#start-btn::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    right: 2px;
    bottom: 2px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 50px;
    z-index: -1;
}

#start-btn:hover {
    animation: pulse 1.5s ease-in-out infinite;
    transform: translate(-50%, -50%) scale(1.1);
    filter: brightness(1.2);
    box-shadow: 0 0 40px rgba(255, 0, 255, 0.9),
                0 0 80px rgba(157, 0, 255, 0.7);
}

#start-btn:hover::before {
    animation: rotateGradient 5s linear infinite;
}

#start-btn.shrinking {
    animation: shrinkOut 0.5s ease-in-out forwards;
}

#start-btn.shrinking::before {
    animation: none !important;
}

#starting-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 1.5rem;
    font-weight: 600;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    z-index: 500;
}

#starting-message.show {
    opacity: 1;
    animation: fadeOut 0.5s ease-out 2s forwards;
}

#starting-message .dots::after {
    content: '.';
    animation: dotAnimation 0.6s steps(4, end) infinite;
}

@keyframes dotAnimation {
    0%, 25% {
        content: '.';
    }
    50% {
        content: '..';
    }
    75%, 100% {
        content: '...';
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
    }
}

#start-btn.moved {
    position: fixed;
    top: auto;
    left: auto;
    bottom: 70px;
    right: 20px;
    padding: 10px 20px;
    font-size: 0.9rem;
    border-radius: 8px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(10px);
    min-width: 108px;
    text-align: center;
    opacity: 0;
    transform: scale(0);
}

#start-btn.moved.expanding {
    animation: expandIn 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
}

#start-btn.moved {
    animation: none !important;
}

#start-btn.moved::before {
    animation: none !important;
}

#start-btn.moved.settled {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
    transition: transform 0.3s ease, background 0.3s ease;
}

#start-btn.moved.settled::before {
    animation: none !important;
}

#start-btn.moved.active {
    background: #f44336;
    box-shadow: 0 0 20px rgba(244, 67, 54, 0.6),
                0 0 40px rgba(244, 67, 54, 0.4);
}

#start-btn.moved.active::before {
    display: none;
}

#start-btn.moved:not(.active) {
    background: #4CAF50;
    box-shadow: 0 0 20px rgba(76, 175, 80, 0.6),
                0 0 40px rgba(76, 175, 80, 0.4);
}

#start-btn.moved:not(.active)::before {
    display: none;
}

#start-btn.moved.settled:hover {
    transform: scale(1.05) !important;
}

#start-btn.moved.settled.active:hover {
    background: #ff6b6b;
    box-shadow: 0 0 25px rgba(255, 107, 107, 0.7),
                0 0 50px rgba(255, 107, 107, 0.5);
}

#start-btn.moved.settled:not(.active):hover {
    background: #5cb85c;
    box-shadow: 0 0 25px rgba(92, 184, 92, 0.7),
                0 0 50px rgba(92, 184, 92, 0.5);
}

#settings, #musical-settings {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#musical-settings {
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

#musical-settings h3 {
    font-size: 1rem;
    margin-bottom: 8px;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 600;
}

#musical-settings h4 {
    font-size: 0.9rem;
    margin-top: 12px;
    margin-bottom: 8px;
    color: rgba(255, 255, 255, 0.8);
    font-weight: 600;
}

#settings label, #musical-settings label {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
}

#settings label span:first-child, #musical-settings label span:first-child {
    font-size: 0.85rem;
    opacity: 0.9;
}

#settings label span:last-child {
    font-size: 0.85rem;
    font-weight: 600;
}

/* New: Video settings spacing to match other sections */
#video-settings {
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 16px;
}

#video-settings h3 {
    font-size: 1rem;
    margin-bottom: 8px;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 600;
}

#video-settings label {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
}

#video-settings label span:first-child {
    font-size: 0.85rem;
    opacity: 0.9;
}

#video-settings label span:last-child {
    font-size: 0.85rem;
    font-weight: 600;
}

input[type="range"], select {
    width: 100%;
}

input[type="range"]:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

select {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 8px;
    border-radius: 4px;
    font-size: 0.9rem;
    cursor: pointer;
}

select:hover {
    background: rgba(255, 255, 255, 0.15);
}

select option {
    background: #333;
    color: white;
}

#trigger-mode-btn {
    background: linear-gradient(135deg, #ff6ec4 0%, #7873f5 100%);
    color: white;
    border: none;
    padding: 12px 20px;
    font-size: 0.9rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

#trigger-mode-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

#trigger-mode-btn:active {
    transform: translateY(0);
}

#trigger-mode-btn.single-mode {
    background: linear-gradient(135deg, #2196F3 0%, #1565C0 100%);
}

#compression-toggle {
    background: linear-gradient(135deg, #4CAF50 0%, #2E7D32 100%);
    color: white;
    border: none;
    padding: 12px 20px;
    font-size: 0.9rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

#compression-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

#compression-toggle:active {
    transform: translateY(0);
}

#compression-toggle.compression-off {
    background: linear-gradient(135deg, #757575 0%, #424242 100%);
}

#release-all-btn {
    color: white;
    border: none;
    padding: 12px 20px;
    font-size: 0.9rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

#release-all-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

#release-all-btn:active {
    transform: translateY(0);
}

#status {
    padding: 10px;
    background: rgba(0,0,0,0.3);
    border-radius: 8px;
    font-size: 0.85rem;
    text-align: center;
}

/* Recording Controls */
#record-btn {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: rgba(220, 53, 69, 0.9);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.4);
    padding: 12px 24px;
    font-size: 1rem;
    border-radius: 50px;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(220, 53, 69, 0.4);
}

#record-btn:hover {
    background: rgba(220, 53, 69, 1);
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(220, 53, 69, 0.6);
}

#record-btn.recording {
    background: rgba(220, 53, 69, 1);
    animation: recordPulse 1.5s ease-in-out infinite;
}

@keyframes recordPulse {
    0%, 100% {
        box-shadow: 0 4px 15px rgba(220, 53, 69, 0.4);
    }
    50% {
        box-shadow: 0 6px 25px rgba(220, 53, 69, 0.8);
    }
}

.record-icon {
    width: 12px;
    height: 12px;
    background: white;
    border-radius: 50%;
    display: inline-block;
}

#record-btn.recording .record-icon {
    border-radius: 2px;
    animation: recordBlink 1s ease-in-out infinite;
}

@keyframes recordBlink {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.3;
    }
}

/* QR Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 25px;
    border-radius: 20px;
    text-align: center;
    max-width: 90%;
    max-height: 90%;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content h2 {
    margin-bottom: 10px;
    font-size: 1.8rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.modal-content p {
    margin-bottom: 15px;
    font-size: 1.1rem;
    opacity: 0.9;
}

#qr-code {
    background: white;
    padding: 20px;
    border-radius: 10px;
    display: inline-block;
    margin: 15px auto;
}

#upload-status {
    margin: 20px 0;
    font-size: 1rem;
    opacity: 0.9;
}

#direct-link {
    color: white;
    text-decoration: underline;
    display: block;
    margin: 15px 0;
    font-size: 0.9rem;
}

#close-modal {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.4);
    padding: 12px 30px;
    font-size: 1rem;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 20px;
    transition: all 0.3s ease;
}

#close-modal:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

/* Mobile Share Modal */
.close-x {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-x:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

#mobile-share-status {
    margin: 20px 0;
    font-size: 1.1rem;
    opacity: 0.9;
}

#mobile-share-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

.mobile-share-btn {
    background: rgba(255, 255, 255, 0.9);
    color: #764ba2;
    border: none;
    padding: 16px 24px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.mobile-share-btn:hover {
    background: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.mobile-share-btn:active {
    transform: translateY(0);
}

@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    #sidebar {
        width: 100%;
        max-height: 50vh;
    }

    #sidebar:not(.show) {
        transform: translateY(-100%);
    }

    #advanced-toggle {
        bottom: 10px;
        right: 10px;
    }

    #record-btn {
        bottom: 70px;
        left: 50%;
        transform: translateX(-50%);
        padding: 12px 32px;
        white-space: nowrap;
    }

    #starting-message {
        text-align: center;
        width: 90%;
        max-width: 300px;
    }
}

/* Share buttons */
#share-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 15px 0;
    justify-content: center;
}

.share-platform-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.share-platform-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    filter: brightness(1.1);
}

.share-platform-btn:active {
    transform: translateY(0);
}

