body {
    margin: 0;
    overflow: hidden;
    background: #000;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #fff;
}
canvas {
    display: block;
    width: 100vw;
    height: 100vh;
    touch-action: none; /* Prevent default touch behaviors (scrolling, zooming) */
}

/* Toggle Button */
.panel-toggle {
    position: fixed;
    top: 15px;
    right: 15px;
    width: 44px;
    height: 44px;
    background: rgba(10, 10, 30, 0.9);
    border: 1px solid rgba(100, 150, 255, 0.4);
    border-radius: 6px;
    color: #88aaff;
    font-size: 20px;
    cursor: pointer;
    z-index: 1001;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 15px rgba(100, 150, 255, 0.3);
    transition: all 0.3s ease;
    touch-action: manipulation;
}

.panel-toggle:hover {
    background: rgba(20, 20, 40, 0.95);
    border-color: rgba(120, 170, 255, 0.6);
    box-shadow: 0 0 20px rgba(100, 150, 255, 0.5);
}

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

.toggle-icon {
    line-height: 1;
}

/* Control Panel Styling */
#controlPanel {
    position: fixed;
    top: 0;
    right: 0;
    width: 280px;
    max-width: 90vw;
    height: 100vh;
    max-height: 100vh;
    box-sizing: border-box; /* padding included in height so bottom padding scrolls into view */
    background: rgba(10, 10, 30, 0.95);
    border-left: 1px solid rgba(100, 150, 255, 0.3);
    padding: 20px;
    box-shadow: none;
    backdrop-filter: blur(10px);
    z-index: 1000;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch; /* iOS momentum scrolling */
    overscroll-behavior-y: contain;    /* Don't propagate scroll to page */
    touch-action: pan-y;               /* Allow vertical scroll gestures */
    transform: translateX(100%);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

#controlPanel.panel-open {
    transform: translateX(0);
    box-shadow: -5px 0 30px rgba(100, 150, 255, 0.2),
                inset 0 0 20px rgba(100, 150, 255, 0.05);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(100, 150, 255, 0.2);
}

.panel-close {
    background: transparent;
    border: none;
    color: #88aaff;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
    touch-action: manipulation;
}

.panel-close:hover {
    background: rgba(100, 150, 255, 0.2);
    color: #aaccff;
}

.panel-close:active {
    transform: scale(0.9);
}

#controlPanel h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #88aaff;
    text-shadow: 0 0 10px rgba(136, 170, 255, 0.5);
}

.control-section {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(100, 150, 255, 0.2);
}

.control-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.control-label {
    font-size: 12px;
    color: #aaa;
    margin-bottom: 8px;
    display: block;
}

button {
    background: linear-gradient(135deg, rgba(60, 80, 150, 0.6), rgba(40, 60, 120, 0.6));
    border: 1px solid rgba(100, 150, 255, 0.4);
    color: #fff;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.3s ease;
    width: 100%;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.3);
}

button:hover {
    background: linear-gradient(135deg, rgba(80, 100, 180, 0.7), rgba(60, 80, 150, 0.7));
    border-color: rgba(120, 170, 255, 0.6);
    box-shadow: 0 0 15px rgba(100, 150, 255, 0.4);
}

button:active {
    transform: scale(0.98);
}

button.reset {
    background: linear-gradient(135deg, rgba(150, 60, 80, 0.6), rgba(120, 40, 60, 0.6));
    border-color: rgba(255, 100, 150, 0.4);
}

button.reset:hover {
    background: linear-gradient(135deg, rgba(180, 80, 100, 0.7), rgba(150, 60, 80, 0.7));
    border-color: rgba(255, 120, 170, 0.6);
    box-shadow: 0 0 15px rgba(255, 100, 150, 0.4);
}

input[type="range"] {
    width: 100%;
    margin: 8px 0;
    cursor: pointer;
    -webkit-appearance: none;
    background: transparent;
}

input[type="range"]::-webkit-slider-track {
    width: 100%;
    height: 5px;
    background: #5580cc;
    border-radius: 2px;
}

input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 5px;
    background: #5580cc;
    border-radius: 2px;
}

input[type="range"]::-moz-range-track {
    width: 100%;
    height: 5px;
    background: #5580cc;
    border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 28px;
    width: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(100, 150, 255, 0.8), rgba(80, 120, 200, 0.8));
    border: 1px solid rgba(120, 170, 255, 0.6);
    cursor: pointer;
    margin-top: -12px;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: linear-gradient(135deg, rgba(120, 170, 255, 0.9), rgba(100, 140, 220, 0.9));
    box-shadow: 0 0 10px rgba(100, 150, 255, 0.5);
}

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

.value-display {
    font-size: 11px;
    color: #88aaff;
    text-align: right;
    margin-top: 4px;
}

select {
    width: 100%;
    padding: 10px 8px;
    background: rgba(30, 30, 60, 0.8);
    border: 1px solid rgba(100, 150, 255, 0.3);
    color: #ccc;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
}

select:hover {
    border-color: rgba(120, 170, 255, 0.5);
    background: rgba(40, 40, 80, 0.8);
}

select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

select option {
    background: rgba(20, 20, 40, 0.95);
    color: #ccc;
}

.key-hints {
    font-size: 11px;
    color: #666;
    margin-top: 10px;
    line-height: 1.6;
}

.key-hints kbd {
    background: rgba(50, 50, 80, 0.6);
    padding: 2px 6px;
    border-radius: 3px;
    border: 1px solid rgba(100, 150, 255, 0.2);
    font-family: monospace;
    font-size: 10px;
}

/* Toggle Switch Styling */
.toggle-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.toggle-container:last-child {
    margin-bottom: 0;
}

.toggle-label {
    font-size: 13px;
    color: #ccc;
}

.toggle-switch {
    position: relative;
    width: 48px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(60, 60, 100, 0.5);
    border: 1px solid rgba(100, 150, 255, 0.3);
    transition: all 0.3s ease;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background: rgba(150, 150, 180, 0.8);
    border: 1px solid rgba(120, 170, 255, 0.4);
    transition: all 0.3s ease;
    border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
    background: linear-gradient(135deg, rgba(80, 120, 200, 0.6), rgba(60, 100, 180, 0.6));
    border-color: rgba(120, 170, 255, 0.6);
    box-shadow: 0 0 10px rgba(100, 150, 255, 0.3);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(24px);
    background: linear-gradient(135deg, rgba(150, 200, 255, 0.9), rgba(120, 170, 255, 0.9));
    border-color: rgba(150, 200, 255, 0.8);
    box-shadow: 0 0 8px rgba(120, 170, 255, 0.6);
}

.toggle-slider:hover {
    border-color: rgba(120, 170, 255, 0.5);
}

/* Version badge at bottom of panel */
.panel-version {
    margin-top: 20px;
    padding-top: 12px;
    border-top: 1px solid rgba(100, 150, 255, 0.1);
    font-size: 10px;
    color: rgba(100, 150, 255, 0.35);
    text-align: right;
    letter-spacing: 1px;
    font-family: monospace;
}

/* Responsive: Mobile vs Desktop */
@media (max-width: 768px) {
    /* Mobile: Panel hidden by default, toggle visible */
    #controlPanel {
        width: 85vw;
        max-width: 320px;
    }

    .panel-toggle {
        display: flex;
    }

    /* Larger touch targets on mobile */
    button, select, input[type="range"] {
        min-height: 44px;
    }

    .toggle-switch {
        width: 52px;
        height: 28px;
    }

    .toggle-slider:before {
        height: 20px;
        width: 20px;
    }

    .toggle-switch input:checked + .toggle-slider:before {
        transform: translateX(24px);
    }
}

@media (min-width: 769px) {
    /* Desktop: Panel visible by default, but can be toggled */
    .panel-toggle {
        display: flex;
        /* Keep same size as mobile (44px) - no overrides needed */
    }

    #controlPanel {
        width: 280px;
        height: auto;
        max-height: calc(100vh - 40px);
        top: 20px;
        right: 20px;
        border-radius: 8px;
        border-left: 1px solid rgba(100, 150, 255, 0.3);
        /* Ensure panel fully hides when closed - account for right offset */
        transform: translateX(calc(100% + 20px));
    }

    #controlPanel.panel-open {
        transform: translateX(0);
    }

    .panel-header {
        margin-bottom: 15px;
    }

    .panel-close {
        display: none;
    }
}
