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

:root {
    --primary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --secondary-gradient: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    --accent-gradient: linear-gradient(135deg, #ff6ec4 0%, #7873f5 100%);
    --purple-pink: linear-gradient(135deg, #c471f5 0%, #fa71cd 100%);
    --dark-bg: #0a0e27;
    --glass-bg: rgba(255, 105, 180, 0.08);
    --glass-border: rgba(255, 105, 180, 0.2);
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.8);
    --shadow-glow: 0 8px 32px rgba(255, 105, 180, 0.4);
    --pink: #ff69b4;
    --purple: #c471f5;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: radial-gradient(ellipse at bottom, #1b2735 0%, #090a0f 100%);
    color: var(--text-primary);
    overflow: hidden;
    width: 100vw;
    height: 100vh;
}

#canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
    z-index: 1;
}

#webcam {
    position: fixed;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

/* Toggle UI Button */
.toggle-ui-btn {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 100;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--purple-pink);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 8px 24px rgba(196, 113, 245, 0.5);
}

.toggle-ui-btn:hover {
    transform: scale(1.15) rotate(10deg);
    box-shadow: 0 12px 32px rgba(255, 105, 180, 0.7);
}

.toggle-ui-btn:active {
    transform: scale(0.95);
}

/* UI Overlay */
.ui-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    padding: 2rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr auto;
    gap: 1.5rem;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.ui-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}

.ui-overlay.auto-hide {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.info-panel,
.controls-panel,
.gesture-guide,
.templates-panel {
    background: linear-gradient(135deg, rgba(196, 113, 245, 0.15) 0%, rgba(255, 105, 180, 0.15) 100%);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 2px solid;
    border-image: linear-gradient(135deg, rgba(196, 113, 245, 0.5), rgba(255, 105, 180, 0.5)) 1;
    border-radius: 24px;
    padding: 1.5rem;
    box-shadow: 0 8px 32px rgba(196, 113, 245, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    pointer-events: auto;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.info-panel::before,
.controls-panel::before,
.gesture-guide::before,
.templates-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.5s;
}

.info-panel:hover::before,
.controls-panel:hover::before,
.gesture-guide:hover::before,
.templates-panel:hover::before {
    left: 100%;
}

.info-panel:hover,
.controls-panel:hover,
.gesture-guide:hover,
.templates-panel:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(255, 105, 180, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    border-image: linear-gradient(135deg, rgba(196, 113, 245, 0.8), rgba(255, 105, 180, 0.8)) 1;
}

.info-panel {
    grid-column: 1 / 2;
    grid-row: 1 / 2;
}

.title {
    font-size: 2rem;
    font-weight: 700;
    background: var(--purple-pink);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 1rem;
    text-shadow: 0 0 30px rgba(255, 105, 180, 0.5);
    animation: glow 2s ease-in-out infinite alternate;
}

@keyframes glow {
    from {
        filter: drop-shadow(0 0 5px rgba(196, 113, 245, 0.5));
    }

    to {
        filter: drop-shadow(0 0 15px rgba(255, 105, 180, 0.8));
    }
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ff4444;
    animation: pulse 2s ease-in-out infinite;
    box-shadow: 0 0 10px rgba(255, 68, 68, 0.5);
}

.status-dot.active {
    background: linear-gradient(135deg, #44ff88, #44ffff);
    box-shadow: 0 0 20px rgba(68, 255, 136, 0.8);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
        box-shadow: 0 0 10px currentColor;
    }

    50% {
        opacity: 0.7;
        transform: scale(1.2);
        box-shadow: 0 0 20px currentColor;
    }
}

.controls-panel {
    grid-column: 2 / 3;
    grid-row: 1 / 2;
}

.control-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid rgba(255, 105, 180, 0.2);
}

.control-item:last-child {
    border-bottom: none;
}

.control-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.control-value {
    font-size: 1.2rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 10px rgba(255, 110, 196, 0.3);
}

.gesture-guide {
    grid-column: 1 / 2;
    grid-row: 3 / 4;
}

.gesture-guide h3,
.templates-panel h3 {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 1rem;
    background: var(--purple-pink);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.gesture-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: all 0.3s ease;
    border-left: 3px solid transparent;
    padding-left: 0.5rem;
}

.gesture-item:hover {
    color: var(--text-primary);
    transform: translateX(8px);
    border-left-color: var(--pink);
}

.gesture-icon {
    font-size: 1.8rem;
    width: 2.5rem;
    text-align: center;
    filter: drop-shadow(0 0 8px rgba(255, 105, 180, 0.6));
}

.templates-panel {
    grid-column: 2 / 3;
    grid-row: 3 / 4;
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    gap: 0.75rem;
}

.template-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1.2rem 0.5rem;
    background: linear-gradient(135deg, rgba(196, 113, 245, 0.1), rgba(255, 105, 180, 0.1));
    border: 2px solid rgba(255, 105, 180, 0.2);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.template-card::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 105, 180, 0.3), transparent);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.template-card:hover::before {
    width: 200%;
    height: 200%;
}

.template-card:hover {
    background: linear-gradient(135deg, rgba(196, 113, 245, 0.25), rgba(255, 105, 180, 0.25));
    border-color: rgba(255, 105, 180, 0.6);
    transform: translateY(-8px) scale(1.08);
    box-shadow: 0 12px 32px rgba(255, 105, 180, 0.5);
}

.template-card.active {
    background: var(--purple-pink);
    border-color: transparent;
    box-shadow: 0 12px 40px rgba(196, 113, 245, 0.7), 0 0 30px rgba(255, 105, 180, 0.5);
    animation: activeGlow 2s ease-in-out infinite alternate;
}

@keyframes activeGlow {
    from {
        box-shadow: 0 12px 40px rgba(196, 113, 245, 0.7), 0 0 30px rgba(255, 105, 180, 0.5);
    }

    to {
        box-shadow: 0 12px 40px rgba(255, 105, 180, 0.9), 0 0 40px rgba(196, 113, 245, 0.7);
    }
}

.template-preview {
    font-size: 2.5rem;
    filter: grayscale(0.2);
    transition: all 0.3s ease;
    position: relative;
    z-index: 1;
}

.template-card:hover .template-preview,
.template-card.active .template-preview {
    filter: grayscale(0) drop-shadow(0 0 10px rgba(255, 255, 255, 0.8));
    transform: scale(1.2) rotate(5deg);
}

.template-card span {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    position: relative;
    z-index: 1;
}

.template-card.active span {
    color: var(--text-primary);
    font-weight: 700;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, #1b2735 0%, #090a0f 100%);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
}

.loading-content {
    text-align: center;
}

.loader {
    width: 70px;
    height: 70px;
    border: 5px solid rgba(255, 105, 180, 0.2);
    border-top: 5px solid var(--pink);
    border-right: 5px solid var(--purple);
    border-radius: 50%;
    margin: 0 auto 2rem;
    animation: spin 1s linear infinite, colorShift 3s ease-in-out infinite;
}

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

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

@keyframes colorShift {

    0%,
    100% {
        filter: drop-shadow(0 0 10px rgba(255, 105, 180, 0.8));
    }

    50% {
        filter: drop-shadow(0 0 20px rgba(196, 113, 245, 0.8));
    }
}

.loading-content h2 {
    font-size: 2rem;
    font-weight: 600;
    margin-bottom: 1rem;
    background: var(--purple-pink);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.loading-content p {
    font-size: 1rem;
    color: var(--text-secondary);
}

/* Responsive Design */
@media (max-width: 1024px) {
    .ui-overlay {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto;
        gap: 1rem;
        padding: 1rem;
    }

    .info-panel,
    .controls-panel,
    .gesture-guide,
    .templates-panel {
        grid-column: 1 / 2;
    }

    .info-panel {
        grid-row: 1 / 2;
    }

    .controls-panel {
        grid-row: 2 / 3;
    }

    .gesture-guide {
        grid-row: 3 / 4;
    }

    .templates-panel {
        grid-row: 4 / 5;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.info-panel,
.controls-panel,
.gesture-guide,
.templates-panel {
    animation: fadeIn 0.8s ease-out backwards;
}

.info-panel {
    animation-delay: 0.1s;
}

.controls-panel {
    animation-delay: 0.2s;
}

.gesture-guide {
    animation-delay: 0.3s;
}

.templates-panel {
    animation-delay: 0.4s;
}