:root {
    --bg-preset-1: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    --bg-preset-2: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
    --bg-preset-3: radial-gradient(circle at 50% 50%, #2a0845 0%, #6441A5 50%, #2a0845 100%);
    
    --panel-bg: rgba(20, 20, 35, 0.6);
    --panel-border: rgba(255, 255, 255, 0.08);
    --text-primary: #ffffff;
    --text-secondary: #a7a7a7;
    --input-bg: rgba(0, 0, 0, 0.3);
    --modal-bg: #1e1e2e;
}

body.light-mode {
    --panel-bg: rgba(255, 255, 255, 0.6);
    --panel-border: rgba(0, 0, 0, 0.1);
    --text-primary: #1e1e2e;
    --text-secondary: #4b5563;
    --input-bg: rgba(255, 255, 255, 0.5);
    --modal-bg: #f3f4f6;
}

@keyframes gradientMove {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    user-select: none;
    -webkit-user-select: none;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
    color: var(--text-primary);
}

.bg-layer {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: -1;
    background-size: cover;
    background-position: center;
}

.bg-dynamic {
    background-size: 400% 400%;
    animation: gradientMove 15s ease infinite;
}

#app-container {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#blur-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    z-index: 1;
    transition: backdrop-filter 0.3s;
}

#grid-scale-wrapper {
    width: 100%; height: 100%;
    max-width: calc(100% - 40px);
    max-height: calc(100% - 40px);
    position: relative;
    z-index: 10;
    transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1), height 0.4s cubic-bezier(0.25, 1, 0.5, 1);
    transform-origin: center center;
    display: flex;
    align-items: center;
    justify-content: center;
}

body.edit-mode #grid-scale-wrapper {
    height: calc(100% - 240px);
    transform: scale(0.95);
}

#grid-container {
    position: relative;
    width: 100%;
    height: 100%;
    margin: 0 auto;
}

.grid-cell-visual {
    position: absolute;
    background: rgba(255, 255, 255, 0.015);
    border: 1px dashed var(--panel-border);
    border-radius: 20px;
    display: none;
    pointer-events: none;
}
body.light-mode .grid-cell-visual { background: rgba(0, 0, 0, 0.015); }
body.edit-mode .grid-cell-visual { display: block; }

@keyframes widgetJiggle {
    0% { transform: rotate(-0.3deg); }
    100% { transform: rotate(0.3deg); }
}

.widget-wrapper {
    position: absolute;
    border-radius: 24px;
    padding: 2px;
    box-sizing: border-box;
    z-index: 20;
    cursor: grab;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    will-change: transform, left, top, width, height;
    transition: box-shadow 0.2s, left 0.3s cubic-bezier(0.25, 1, 0.5, 1), top 0.3s cubic-bezier(0.25, 1, 0.5, 1), width 0.3s cubic-bezier(0.25, 1, 0.5, 1), height 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}

body.edit-mode .widget-wrapper:not(.dragging):not(.resizing) {
    animation: widgetJiggle 0.25s ease-in-out infinite alternate;
}

.widget-content {
    width: 100%; height: 100%;
    border-radius: 22px;
    overflow: hidden;
    position: relative;
}

.widget-wrapper.dragging, .widget-wrapper.resizing {
    opacity: 0.85; z-index: 1000;
    box-shadow: 0 25px 50px rgba(0,0,0,0.5);
    animation: none !important; transition: none !important;
}
.widget-wrapper.dragging {
    cursor: grabbing !important;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.shake-locked {
    animation: shake 0.2s linear;
    border: 2px solid #ef4444 !important;
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.5) !important;
}

#ghost-guide {
    position: absolute;
    background: rgba(59, 130, 246, 0.15);
    border: 2px solid #3b82f6;
    border-radius: 24px;
    display: none; pointer-events: none; z-index: 5;
    transition: left 0.15s ease, top 0.15s ease, width 0.15s ease, height 0.15s ease;
}
#ghost-guide.active { display: block; }

.resize-handle {
    position: absolute; right: -6px; bottom: -6px; width: 28px; height: 28px;
    cursor: se-resize; display: none; z-index: 35;
    background: var(--panel-bg); border: 1px solid var(--panel-border);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-radius: 50%; touch-action: none;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
}
.resize-handle::after {
    content: ''; position: absolute; width: 6px; height: 6px;
    border-right: 2px solid var(--text-primary); border-bottom: 2px solid var(--text-primary);
    right: 9px; bottom: 9px; opacity: 0.8;
}
.resize-handle:hover { transform: scale(1.15); }
body.edit-mode .resize-handle { display: block; }

#delete-zone {
    position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
    background: rgba(239, 68, 68, 0.2); border: 1px solid rgba(239, 68, 68, 0.4);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    width: 54px; height: 54px; border-radius: 50%; color: white; font-size: 22px;
    display: flex; align-items: center; justify-content: center;
    z-index: 3000; opacity: 0; pointer-events: none;
    transition: transform 0.2s, background 0.2s, opacity 0.3s;
}
body.edit-mode #delete-zone { opacity: 1; pointer-events: auto; }
body.edit-mode #delete-zone.hovered { background: rgba(239, 68, 68, 0.6); transform: translateX(-50%) scale(1.2); }

#done-btn {
    position: fixed; top: -100px; left: 24px; background: #3b82f6; border: none;
    color: white; height: 50px; padding: 0 28px; border-radius: 16px;
    font-weight: 600; font-size: 14px; cursor: pointer; z-index: 2005;
    box-shadow: 0 10px 20px rgba(59, 130, 246, 0.3);
    transition: top 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
body.edit-mode #done-btn { top: 24px; }

#edit-panel {
    position: fixed; bottom: -400px; left: 50%; transform: translateX(-50%);
    width: 500px; max-width: calc(100% - 32px);
    background: var(--panel-bg); border: 1px solid var(--panel-border);
    backdrop-filter: blur(35px); -webkit-backdrop-filter: blur(35px);
    border-radius: 24px; padding: 16px; z-index: 2000;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.2);
    transition: bottom 0.4s cubic-bezier(0.25, 1, 0.5, 1);
    display: flex; flex-direction: column; gap: 14px; color: var(--text-primary);
}
body.edit-mode #edit-panel { bottom: 15px; }

.panel-tabs {
    display: flex; background: rgba(0,0,0,0.1); border-radius: 12px; padding: 4px;
}
.panel-tab {
    flex: 1; background: none; border: none; color: var(--text-secondary);
    padding: 8px; font-size: 13px; font-weight: 500; cursor: pointer; border-radius: 8px;
}
.panel-tab.active { background: var(--panel-border); color: var(--text-primary); }

.panel-content { display: none; }
.panel-content.active { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 4px; }

.store-item {
    background: var(--panel-border); border: 1px solid var(--panel-border);
    border-radius: 16px; padding: 12px; min-width: 84px; display: flex;
    flex-direction: column; align-items: center; gap: 6px; cursor: grab;
    touch-action: none;
}
.store-item-icon { font-size: 24px; }
.store-item-label { color: var(--text-primary); font-size: 11px; font-weight: 500; }

.folder-expanded-item { display: flex; flex-direction: column; align-items: center; text-decoration: none; color: var(--text-primary); width: 80px; text-align: center; touch-action: none; }
.folder-expanded-label { font-size: 12px; margin-top: 4px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.shape-btn.active { border-color: #3b82f6 !important; background: rgba(59,130,246,0.15) !important; box-shadow: 0 0 12px rgba(59,130,246,0.4); }

.color-swatch-container { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.color-swatch-btn { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 6px rgba(0,0,0,0.2); transition: transform 0.2s; touch-action: none; }
.color-swatch-btn:hover { transform: scale(1.15); }
.color-swatch-btn.active { border-color: var(--text-primary); transform: scale(1.1); }

.color-picker-wrapper {
    position: relative; width: 28px; height: 28px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; border: 2px solid transparent; overflow: hidden; transition: transform 0.2s;
    background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red); touch-action: none;
}
.color-picker-wrapper:hover { transform: scale(1.15); }
.color-picker-wrapper.active { border-color: var(--text-primary); transform: scale(1.1); }
.color-picker-wrapper::after { content: '+'; color: white; font-weight: 700; font-size: 20px; text-shadow: 0 1px 4px rgba(0,0,0,0.8); position: absolute; pointer-events: none; z-index: 2; background: transparent !important; }
.color-picker-wrapper input[type="color"] { position: absolute; opacity: 0; width: 300%; height: 300%; cursor: pointer; top: -100%; left: -100%; border: none; z-index: 1; padding: 0; margin: 0; }

.glass-toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.glass-toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0,0,0,0.3); border: 1px solid var(--panel-border); transition: .3s; border-radius: 24px; }
.toggle-slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px; background-color: var(--text-secondary); transition: .3s; border-radius: 50%; }
input:checked + .toggle-slider { background-color: rgba(59, 130, 246, 0.5); border-color: #3b82f6; }
input:checked + .toggle-slider:before { transform: translateX(20px); background-color: white; }

.modal-input { background: var(--input-bg); border: 1px solid var(--panel-border); padding: 8px; border-radius: 8px; color: var(--text-primary); width: 100%; }