* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    overflow: hidden;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    transition: all 0.3s ease;
    position: fixed;
    width: 100%;
    height: 100%;
    -webkit-overflow-scrolling: touch;
}

/* Header - Mobile optimized */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 70px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 1000;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
    border-radius: 0 0 20px 20px;
    padding-top: env(safe-area-inset-top);
}

.header h1 {
    font-size: 24px;
    font-weight: 700;
    color: #4f46e5;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.stress-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #64748b;
    font-weight: 600;
    font-size: 14px;
}

.stress-bar {
    width: 100px;
    height: 6px;
    background: rgba(148, 163, 184, 0.3);
    border-radius: 3px;
    overflow: hidden;
}

.stress-fill {
    height: 100%;
    background: linear-gradient(90deg, #06d6a0 0%, #4ade80 100%);
    transition: width 0.5s ease;
    border-radius: 3px;
    width: 0%;
}

.stress-text {
    font-size: 12px;
}

.settings-icon {
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.3s ease;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-icon:hover {
    background: rgba(99, 102, 241, 0.1);
    transform: rotate(45deg);
}

/* Mobile-optimized toy selector dropdown */
.toy-selector-dropdown {
    position: fixed;
    bottom: 80px;
    left: 20px;
    z-index: 999;
    margin-bottom: env(safe-area-inset-bottom);
}

.dropdown-trigger {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: none;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.dropdown-trigger:active {
    transform: scale(0.95);
}

.dropdown-trigger .toy-icon {
    font-size: 24px;
    line-height: 1;
}

.dropdown-trigger .dropdown-arrow {
    font-size: 8px;
    opacity: 0.6;
    margin-top: 2px;
}

.dropdown-menu {
    position: absolute;
    bottom: 70px;
    left: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 15px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    transform: translateY(20px) scale(0.9);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 200px;
}

.dropdown-menu.open {
    transform: translateY(0) scale(1);
    opacity: 1;
    visibility: visible;
}

.favorites-row {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.favorites-row .toy-option {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: rgba(99, 102, 241, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.toy-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toy-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 44px;
    background: transparent;
}

.toy-option:active {
    transform: scale(0.98);
}

.toy-option:hover, .toy-option.active {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.toy-option .toy-icon {
    font-size: 20px;
    width: 28px;
    text-align: center;
}

.toy-option .toy-name {
    font-weight: 500;
    font-size: 14px;
}

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

/* Bottom controls - Mobile optimized */
.bottom-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 999;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.1);
    padding-bottom: calc(15px + env(safe-area-inset-bottom));
}

.quick-actions {
    display: flex;
    gap: 12px;
}

.quick-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    border: none;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.session-info {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #64748b;
    font-weight: 600;
    font-size: 14px;
}

.stats-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: rgba(99, 102, 241, 0.1);
    border: none;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
}

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

/* Settings panel - Slide up from bottom */
.settings-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: 20px 20px 0 0;
    padding: 25px 20px;
    z-index: 10000;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.2);
    max-height: 70vh;
    overflow-y: auto;
    padding-bottom: calc(25px + env(safe-area-inset-bottom));
}

.settings-panel.open {
    transform: translateY(0);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e5e7eb;
}

.panel-header h3 {
    font-size: 20px;
    font-weight: 600;
    color: #374151;
}

.close-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(148, 163, 184, 0.1);
    border: none;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:active {
    transform: scale(0.95);
    background: rgba(148, 163, 184, 0.2);
}

.settings-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
}

.setting-item label {
    font-weight: 500;
    color: #374151;
    font-size: 16px;
}

.setting-item input[type="range"] {
    width: 120px;
    height: 6px;
    border-radius: 3px;
    background: rgba(148, 163, 184, 0.3);
    outline: none;
    cursor: pointer;
}

.setting-item input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.setting-item input[type="checkbox"] {
    width: 24px;
    height: 24px;
    cursor: pointer;
}

/* Stats overlay */
.stats-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.stats-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.stats-content {
    background: white;
    padding: 30px 25px;
    border-radius: 20px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 300px;
}

.stats-content h3 {
    margin-bottom: 20px;
    color: #374151;
    font-size: 22px;
    text-align: center;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
    padding: 10px 0;
    border-bottom: 1px solid #e5e7eb;
    font-size: 14px;
}

.stat-item:last-child {
    border-bottom: none;
    margin-bottom: 20px;
}

/* Gesture instructions overlay */
.gesture-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.gesture-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.gesture-content {
    background: white;
    padding: 30px 25px;
    border-radius: 20px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 320px;
}

.gesture-content h3 {
    margin-bottom: 20px;
    color: #374151;
    font-size: 20px;
    text-align: center;
}

.gesture-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 14px;
    align-items: center;
}

.gesture-item:last-child {
    margin-bottom: 20px;
}

/* Focus Mode */
body.focus-mode .header,
body.focus-mode .bottom-controls,
body.focus-mode .toy-selector-dropdown {
    opacity: 0.2;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

body.focus-mode .header:hover,
body.focus-mode .bottom-controls:hover,
body.focus-mode .toy-selector-dropdown:hover {
    opacity: 1;
    pointer-events: all;
}

/* Mobile-specific responsive design */
@media (max-width: 480px) {
    .header {
        height: 65px;
        padding: 0 15px;
    }
    
    .header h1 {
        font-size: 20px;
    }
    
    .stress-bar {
        width: 80px;
        height: 5px;
    }
    
    .stress-indicator {
        font-size: 12px;
        gap: 6px;
    }
    
    .dropdown-trigger {
        width: 56px;
        height: 56px;
    }
    
    .dropdown-trigger .toy-icon {
        font-size: 22px;
    }
    
    .toy-option .toy-name {
        font-size: 13px;
    }
    
    .quick-btn {
        width: 40px;
        height: 40px;
        font-size: 14px;
    }
    
    .bottom-controls {
        padding: 12px 15px;
    }
}

/* Landscape orientation adjustments */
@media (orientation: landscape) and (max-height: 500px) {
    .header {
        height: 50px;
    }
    
    .header h1 {
        font-size: 18px;
    }
    
    .toy-selector-dropdown {
        bottom: 60px;
        left: 15px;
    }
    
    .dropdown-trigger {
        width: 50px;
        height: 50px;
    }
    
    .dropdown-trigger .toy-icon {
        font-size: 20px;
    }
    
    .bottom-controls {
        padding: 10px 15px;
    }
    
    .quick-btn {
        width: 38px;
        height: 38px;
        font-size: 13px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .header,
    .dropdown-menu,
    .bottom-controls {
        background: rgba(30, 30, 30, 0.95);
        color: #e5e7eb;
    }
    
    .header h1 {
        color: #8b5cf6;
    }
    
    .stats-content,
    .settings-panel,
    .gesture-content {
        background: #1f2937;
        color: #e5e7eb;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .header,
    .dropdown-menu,
    .bottom-controls {
        border: 2px solid #000;
    }
    
    .quick-btn,
    .dropdown-trigger {
        border: 2px solid #000;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Animations */
@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

.toy-option:active {
    animation: pulse 0.2s ease;
}

/* Safe area insets for iPhone X and newer */
@supports (padding: max(0px)) {
    .header {
        padding-top: max(env(safe-area-inset-top), 10px);
    }
    
    .bottom-controls {
        padding-bottom: max(env(safe-area-inset-bottom), 15px);
    }
    
    .toy-selector-dropdown {
        margin-bottom: max(env(safe-area-inset-bottom), 0px);
    }
}