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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    overflow: hidden;
    background: #0f0f17;
    color: #ffffff;
}

/* Canvas */
#canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: block;
}

/* Webcam Container - Professional minimal design */
#webcamContainer {
    position: fixed;
    bottom: 24px;
    left: 24px;
    width: 280px;
    height: 210px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    z-index: 50;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    background: #000;
}

#webcam {
    width: 100% !;
    height: 100%;
    transform: scaleX(-1);
    object-fit: cover;
}

#handCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    transform: scaleX(-1);
}

.webcam-label {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(255, 255, 255, 0.95);
    color: #0f0f17;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

/* Mobile Menu Toggle Button */
.menu-toggle {
    display: none;
    /* Hidden by default on desktop */
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(99, 102, 241, 0.95);
    backdrop-filter: blur(24px);
    border: none;
    border-radius: 50px;
    padding: 14px 24px;
    cursor: pointer;
    z-index: 150;
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.menu-icon {
    width: 20px;
    height: 2px;
    background: white;
    position: relative;
    transition: all 0.3s ease;
}

.menu-icon::before,
.menu-icon::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 2px;
    background: white;
    transition: all 0.3s ease;
}

.menu-icon::before {
    top: -6px;
}

.menu-icon::after {
    top: 6px;
}

.menu-toggle.active .menu-icon {
    background: transparent;
}

.menu-toggle.active .menu-icon::before {
    top: 0;
    transform: rotate(45deg);
}

.menu-toggle.active .menu-icon::after {
    top: 0;
    transform: rotate(-45deg);
}

.menu-text {
    color: white;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

/* Control Panel - Professional Design */
.control-panel {
    position: fixed;
    top: 24px;
    right: 24px;
    width: 360px;
    max-height: calc(100vh - 48px);
    background: rgba(22, 22, 30, 0.95);
    backdrop-filter: blur(24px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 28px;
    overflow-y: auto;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
    z-index: 100;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.control-panel:hover {
    border-color: rgba(255, 255, 255, 0.12);
}

/* Custom Scrollbar - Professional */
.control-panel::-webkit-scrollbar {
    width: 5px;
}

.control-panel::-webkit-scrollbar-track {
    background: transparent;
}

.control-panel::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
}

.control-panel::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Panel Header - Professional Branding */
.panel-header {
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.panel-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 6px;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
    font-weight: 500;
    letter-spacing: 0.3px;
}

/* Sections - Clean Spacing */
.section {
    margin-bottom: 28px;
}

.section h3 {
    font-size: 12px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.85);
    margin-bottom: 14px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

/* Template Grid - Professional Cards */
.template-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.template-btn {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 14px 10px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    color: #ffffff;
}

.template-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateY(-1px);
}

.template-btn.active {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.5);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.08);
}

.template-btn .icon {
    font-size: 28px;
    filter: grayscale(0.2);
}

.template-btn.active .icon {
    filter: grayscale(0);
}

.template-btn .label {
    font-size: 11px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.7);
}

.template-btn.active .label {
    color: rgba(255, 255, 255, 0.95);
}

/* Color Picker - Professional */
.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 14px;
    background: rgba(255, 255, 255, 0.04);
    padding: 14px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

#colorPicker {
    width: 56px;
    height: 36px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    background: transparent;
}

#colorPicker::-webkit-color-swatch-wrapper {
    padding: 0;
}

#colorPicker::-webkit-color-swatch {
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
}

.color-label {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.85);
    flex: 1;
    font-weight: 500;
}

/* Sensitivity Control - Professional Slider */
.sensitivity-control {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.04);
    padding: 14px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.sensitivity-control input[type="range"] {
    flex: 1;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
}

.sensitivity-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: #6366f1;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2);
    transition: all 0.2s ease;
}

.sensitivity-control input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 0 0 6px rgba(99, 102, 241, 0.25);
}

.sensitivity-control input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: #6366f1;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2);
    border: none;
    transition: all 0.2s ease;
}

.sensitivity-control input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 0 0 6px rgba(99, 102, 241, 0.25);
}

.sensitivity-value {
    min-width: 44px;
    text-align: right;
    font-weight: 600;
    color: #6366f1;
    font-size: 13px;
}

/* Control Buttons - Professional */
.audio-controls,
.physics-controls {
    display: flex;
    gap: 10px;
}

.control-btn {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 12px 14px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: rgba(255, 255, 255, 0.85);
    font-size: 13px;
    font-weight: 500;
    flex: 1;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
}

.control-btn.active {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.5);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.08);
    color: #ffffff;
}

.control-btn .icon {
    font-size: 18px;
}

/* Status Display - Professional Cards */
.status-display {
    background: rgba(255, 255, 255, 0.04);
    border-radius: 10px;
    padding: 16px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.status-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.status-item:last-child {
    margin-bottom: 0;
}

.status-label {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.55);
    font-weight: 500;
}

.status-value {
    font-size: 12px;
    font-weight: 600;
    color: #6366f1;
    font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
}

/* Instructions - Clean Typography */
.instructions ul {
    list-style: none;
    padding: 0;
}

.instructions li {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.65);
    margin-bottom: 7px;
    padding-left: 0;
    line-height: 1.6;
}

.instructions li strong {
    color: rgba(255, 255, 255, 0.85);
    font-weight: 600;
}

/* Demo Hint - Subtle */
.demo-hint {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.45);
    margin-top: 8px;
    line-height: 1.5;
}

/* Loading Overlay - Professional */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #0f0f17;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.4s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(255, 255, 255, 0.08);
    border-top: 3px solid #6366f1;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 20px;
}

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

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

.loading-overlay p {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 500;
    letter-spacing: 0.3px;
}

/* Responsive Design - Comprehensive Mobile & Tablet Support */

/* Tablets (Portrait and Landscape) */
@media (max-width: 1024px) {
    .control-panel {
        width: 340px;
        max-height: calc(100vh - 80px);
    }

    #webcamContainer {
        width: 240px;
        height: 180px;
    }
}

/* Mobile Landscape & Small Tablets */
@media (max-width: 768px) {
    body {
        touch-action: pan-y;
    }

    /* Show menu toggle on mobile */
    .menu-toggle {
        display: flex;
    }

    .control-panel {
        width: calc(100vw - 32px);
        bottom: 16px;
        right: 16px;
        left: 16px;
        top: auto;
        max-height: 65vh;
        padding: 20px;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    }

    /* Collapsed state */
    .control-panel.collapsed {
        transform: translateY(calc(100% + 32px));
        opacity: 0;
        pointer-events: none;
    }

    .panel-header {
        margin-bottom: 20px;
        padding-bottom: 16px;
    }

    .panel-header h1 {
        font-size: 20px;
    }

    .subtitle {
        font-size: 11px;
    }

    .section {
        margin-bottom: 20px;
    }

    .section h3 {
        font-size: 11px;
        margin-bottom: 12px;
    }

    .template-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .template-btn {
        padding: 12px 8px;
    }

    .template-btn .icon {
        font-size: 24px;
    }

    .template-btn .label {
        font-size: 10px;
    }

    #webcamContainer {
        width: 200px;
        height: 150px;
        bottom: 16px;
        left: 16px;
    }

    .webcam-label {
        font-size: 9px;
        padding: 3px 8px;
    }

    .control-btn {
        padding: 10px 12px;
        font-size: 12px;
        min-height: 44px;
        /* Touch target minimum */
    }

    .control-btn .icon {
        font-size: 16px;
    }

    .instructions li {
        font-size: 11px;
        margin-bottom: 6px;
    }
}

/* Mobile Portrait */
@media (max-width: 480px) {
    .control-panel {
        width: calc(100vw - 24px);
        right: 12px;
        left: 12px;
        bottom: 12px;
        max-height: 70vh;
        padding: 16px;
    }

    .panel-header h1 {
        font-size: 18px;
    }

    .subtitle {
        font-size: 10px;
    }

    .section {
        margin-bottom: 16px;
    }

    .template-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }

    .template-btn {
        padding: 10px 6px;
    }

    .template-btn .icon {
        font-size: 22px;
    }

    .template-btn .label {
        font-size: 9px;
    }

    #webcamContainer {
        width: 160px;
        height: 120px;
        bottom: 12px;
        left: 12px;
    }

    .color-picker-wrapper,
    .sensitivity-control {
        padding: 12px;
    }

    .control-btn {
        padding: 10px;
        font-size: 11px;
    }

    .status-display {
        padding: 12px;
    }

    .status-label,
    .status-value {
        font-size: 11px;
    }

    .demo-hint {
        font-size: 10px;
    }
}

/* Small Mobile Portrait */
@media (max-width: 360px) {
    .control-panel {
        padding: 14px;
        max-height: 75vh;
    }

    .panel-header h1 {
        font-size: 16px;
    }

    .template-grid {
        gap: 5px;
    }

    .template-btn .icon {
        font-size: 20px;
    }

    .template-btn .label {
        font-size: 8px;
    }

    #webcamContainer {
        width: 140px;
        height: 105px;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {

    /* Enhance touch targets */
    .template-btn,
    .control-btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* Remove hover effects on touch devices */
    .template-btn:hover,
    .control-btn:hover {
        transform: none;
    }

    /* Active state for touch feedback */
    .template-btn:active {
        transform: scale(0.95);
        transition: transform 0.1s;
    }

    .control-btn:active {
        transform: scale(0.98);
        transition: transform 0.1s;
    }

    /* Improve scrolling */
    .control-panel {
        -webkit-overflow-scrolling: touch;
    }
}

/* Animations - Professional Transitions */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

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

.section {
    animation: fadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}