:root {
    --bg-color: #fff;
    --text-color: #000;
    --panel-border: #8B5E3C;
    --panel-bg: #EAD5C1;
    --game-bg: #F9E0D2;
    --death-line: #E85B45;

    /* Spacing System */
    --space-xs: 4px;
    --space-s: 8px;
    --space-m: 12px;
    --space-l: 18px;
    --space-xl: 32px;

    --panel-padding: var(--space-m);
    --module-gap: var(--space-m);
    --column-gap: var(--space-m);
}

/* === UTILITY CLASSES FOR DYNAMIC ELEMENTS === */

/* Drop Graph Overlay */
.drop-graph-overlay {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 200px;
    height: 100px;
    background: rgba(0,0,0,0.75);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 4px;
    z-index: 50;
    pointer-events: none;
    overflow: hidden;
}

.drop-graph-canvas {
    width: 100%;
    height: 100%;
    display: block;
    image-rendering: pixelated;
}

/* FPS Display */
.fps-display {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    background: rgba(0,0,0,0.9);
    color: #0f0;
    font-family: monospace;
    font-size: 11px;
    padding: 12px 16px;
    border-radius: 4px;
    z-index: 99999;
    pointer-events: none;
    visibility: hidden;
    line-height: 1.6;
    min-width: 220px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

/* Shape Designer Placeholder */
.shape-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 60px;
    color: rgba(0,0,0,0.4);
    font-size: 12px;
    font-style: italic;
}

/* Form Controls - Common Patterns */
.form-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.form-row-flex {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-label {
    font-size: 11px;
    font-weight: bold;
}

.form-label-small {
    font-size: 10px;
    font-weight: bold;
}

/* Number Inputs */
.input-small {
    width: 60px;
    padding: 2px 5px;
    border: 1px solid rgba(0,0,0,0.15);
    border-radius: 3px;
    font-size: 11px;
}

.input-xsmall {
    width: 30px;
    padding: 2px 3px;
    border: 1px solid rgba(0,0,0,0.15);
    border-radius: 3px;
    font-size: 11px;
}

/* Full-width Inputs */
.input-full {
    width: 100%;
    box-sizing: border-box;
    padding: 3px 5px;
    border: 1px solid rgba(0,0,0,0.15);
    border-radius: 3px;
    font-size: 11px;
}

/* Button Small */
.btn-small {
    flex: unset;
    width: 76px;
    padding: 4px 6px;
}

/* Divider */
.divider {
    border: none;
    border-top: 1px solid rgba(0,0,0,0.1);
    margin: 6px 0;
}

/* Panel Header */
.panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0 2px;
    cursor: pointer;
    user-select: none;
}

.panel-header-arrow {
    font-size: 11px;
    display: inline-block;
    transition: none;
    opacity: 0.6;
}

/* Collapsible Section */
.collapsible-section {
    overflow: hidden;
    max-height: 500px;
    opacity: 1;
}

.collapsible-section.collapsed {
    max-height: 0;
    opacity: 0;
}

/* HR Flexible */
.hr-flex {
    flex: 1;
    border: none;
    border-top: 1px solid rgba(0,0,0,0.15);
    margin: 0;
}

#module-toggles {
    overflow: hidden;
    max-height: 280px;
    opacity: 1;
}
#module-toggles.collapsed {
    max-height: 0;
    opacity: 0;
    margin-top: 0 !important;
}
#modules-divider:has(+ #module-toggles.collapsed) #modules-arrow {
    transform: rotate(-180deg);
}

body { 
    display: flex; 
    gap: var(--column-gap); 
    padding: var(--space-xl) var(--space-l) var(--space-l); 
    margin: 0; 
    background: var(--bg-color); 
    color: var(--text-color); 
    align-items: flex-start; 
}
.sidebar { 
    width: 220px; 
    display: flex; 
    flex-direction: column; 
    gap: var(--module-gap); 
    flex-shrink: 0; 
}
.panel { 
    border: 2px solid var(--panel-border); 
    padding: var(--panel-padding); 
    background: var(--panel-bg); 
    border-radius: 8px; 
}
.game-wrapper {
    position: relative;
    width: 400px;
    height: 600px;
    border-left: 2px solid var(--panel-border);
    border-right: 2px solid var(--panel-border);
    border-bottom: 2px solid var(--panel-border);
    border-radius: 0 0 12px 12px;
    background: var(--game-bg);
    overflow: visible;
    cursor: none;
    margin-top: 25px;
    box-sizing: content-box;
}
.death-line { position: absolute; top: 80px; left: 0; width: 100%; border-top: 2px dashed var(--death-line); opacity: 0.6; z-index: 5; pointer-events: none; }
.game-container { position: absolute; bottom: 0; left: 0; width: 100%; height: 100%; overflow: visible; }
.circle {
    position: absolute; border: 1px solid #000; border-radius: 50%; box-sizing: border-box;
    pointer-events: none; top: 0; left: 0;
}
.dropping { z-index: 10; }
.preview-box { height: 100px; display: flex; align-items: center; justify-content: center; position: relative; }
.preview-box .circle { position: relative; } 
h2, h3, p { margin: 0 0 var(--space-s) 0; }
.restart-btn { margin-top: 10px; width: 100%; padding: 10px; background: var(--death-line); color: var(--bg-color); border: none; border-radius: 4px; cursor: pointer; font-weight: bold; }


/* Settings Dropdowns */
.settings { margin-top: -5px; margin-bottom: 15px; display: flex; flex-direction: column; gap: 5px; }
.settings label { font-size: 13px; font-weight: bold; }
.settings select { padding: 4px; border-radius: 4px; border: 1px solid var(--panel-border); background: var(--bg-color); color: var(--text-color); font-family: inherit; font-size: 13px; }

.custom-colors-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 6px;
    margin: 8px 0;
}
.color-picker-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    background: rgba(0,0,0,0.05);
    padding: 2px 4px;
    border-radius: 4px;
    min-width: 0;
}
.color-picker-row span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 4px;
}
.shape-name-input {
    width: 0;
    flex: 1;
    margin-right: 4px;
    font-size: 9px;
    background: transparent;
    border: none;
    border-bottom: 1px dotted var(--text-color);
    color: var(--text-color);
    font-family: inherit;
    outline: none;
    padding: 2px 0;
}
.shape-name-input:focus {
    border-bottom: 1px solid var(--text-color);
}
.color-picker-row input[type="color"] {
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    cursor: pointer;
    background: none;
    flex-shrink: 0;
}

.particle {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 200;
}

.game-over-screen {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    color: white;
    text-align: center;
    pointer-events: none;
}
.game-over-screen h2 {
    font-size: 5rem;
    margin-bottom: 0;
    color: var(--death-line);
    -webkit-text-stroke: 3px #000;
}
.game-over-screen p {
    font-size: 2rem;
    margin-bottom: 25px;
    font-weight: bold;
    -webkit-text-stroke: 1.5px #000;
}


/* Layout: left sidebar | game | right column (theme + sound stacked) */
body { align-items: flex-start; }
.sidebars-container { display: flex; flex-direction: row; gap: 16px; flex-shrink: 0; align-items: flex-start; }

/* Sound Designer panel */
.sound-editor-panel { display: flex; flex-direction: column; gap: var(--space-s); }

/* Navigation arrows */
.synth-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.synth-nav-btn { background: var(--panel-bg); border: 1px solid var(--panel-border); border-radius: 4px; cursor: pointer; padding: 2px 8px; font-size: 13px; }
.synth-nav-btn:hover { background: var(--death-line); color: white; }
.synth-nav-name { font-weight: bold; font-size: 12px; text-align: center; flex: 1; }
.synth-nav-name-input { background: none; border: 1px solid transparent; border-radius: 4px; font-weight: bold; font-size: 12px; text-align: center; flex: 1; color: var(--text-color); width: 80px; }
.synth-nav-name-input:hover { background: rgba(0,0,0,0.05); }
.synth-nav-name-input:focus { outline: none; border-color: var(--death-line); background: var(--bg-color); }
.synth-actions { display: flex; gap: 3px; margin-bottom: 5px; width: 100%; }
.synth-test-btn { flex: 1; padding: 6px 2px; background: rgba(0,0,0,0.12); color: var(--text-color); border: 1px solid var(--panel-border); border-radius: 4px; cursor: pointer; font-size: 10px; font-weight: bold; white-space: nowrap; }
.synth-test-btn:hover { background: var(--death-line); color: white; }

/* Oscillator type selector */
.osc-selector { display: flex; gap: 2px; margin-bottom: 6px; }
.osc-btn { flex: 1; font-size: 8px; padding: 3px 1px; background: var(--panel-bg); border: 1px solid var(--panel-border); border-radius: 3px; cursor: pointer; text-transform: capitalize; }
.osc-btn.active { background: var(--death-line); color: white; border-color: var(--death-line); }

/* Knob grid: 4 columns */
.knob-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-s) var(--space-xs); }
.knob-wrap { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.knob-label { font-size: 8px; font-weight: 700; text-transform: uppercase; opacity: 0.65; letter-spacing: 0.05em; }
.knob-svg { display: block; cursor: ns-resize; overflow: visible; }
.knob-val { width: 100%; font-size: 8px; text-align: center; background: var(--bg-color); border: 1px solid var(--panel-border); border-radius: 3px; padding: 1px 0; font-family: 'Courier New', monospace; color: var(--text-color); box-sizing: border-box; }
.knob-val::-webkit-inner-spin-button { display: none; }

.preset-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.preset-row label { font-size: 12px; font-weight: bold; flex-shrink: 0; }
.preset-row select { flex: 1; padding: 3px; font-size: 12px; border-radius: 4px; border: 1px solid var(--panel-border); background: var(--bg-color); color: var(--text-color); }

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-thumb { background: var(--panel-border); border-radius: 10px; }
/* Slider Grid for Particle Designer */
.slider-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-m);
    margin-top: var(--space-s);
}
.slider-wrap {
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.slider-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 9px;
    font-weight: bold;
    text-transform: uppercase;
    color: var(--text-color);
    opacity: 0.7;
}
.slider-val-text {
    font-family: 'Courier New', monospace;
    font-size: 10px;
}
.slider-input {
    width: 100%;
    height: 8px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(0,0,0,0.12);
    border-radius: 4px;
    outline: none;
    cursor: pointer;
}
.slider-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--death-line);
    border: 2px solid var(--panel-bg);
    border-radius: 50%;
}
.slider-input::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--death-line);
    border: 2px solid var(--panel-bg);
    border-radius: 50%;
}

.cursor-opacity-slider::-webkit-slider-thumb {
    background: var(--panel-border);
}

.cursor-opacity-slider::-moz-range-thumb {
    background: var(--panel-border);
}

.opacity-slider::-webkit-slider-thumb {
    background: var(--panel-border);
}

.opacity-slider::-moz-range-thumb {
    background: var(--panel-border);
}

.shape-designer-sidebar {
    width: 200px;
}
