* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #0a0a0a;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
    height: 100vh;
    user-select: none;
}

/* Canvas fills the entire screen with grid */
#canvas-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        linear-gradient(rgba(40, 40, 40, 0.4) 1px, transparent 1px),
        linear-gradient(90deg, rgba(40, 40, 40, 0.4) 1px, transparent 1px),
        #0a0a0a;
    background-size: 50px 50px;
}

#sandbox {
    width: 100%;
    height: 100%;
    cursor: crosshair;
    image-rendering: pixelated;
    position: relative;
    z-index: 1;
}

#mod-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

/* ===== RESIZABLE SIDEBAR ===== */
#sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 220px;
    min-width: 160px;
    max-width: 500px;
    background: rgba(10, 10, 10, 0.5);
    backdrop-filter: blur(8px);
    border-right: 2px solid rgba(60, 60, 60, 0.4);
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow: hidden;
    animation: slideInLeft 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    transition: width 0.2s ease, border-color 0.3s ease;
}

#sidebar:hover {
    border-color: rgba(100, 100, 100, 0.5);
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Scrollable content area */
.sidebar-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(80, 80, 80, 0.5) transparent;
}

.sidebar-content::-webkit-scrollbar {
    width: 6px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: rgba(80, 80, 80, 0.5);
    border-radius: 3px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 100, 100, 0.7);
}

/* Resize handle */
#sidebar-resize {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 6px;
    cursor: ew-resize;
    background: transparent;
    transition: background 0.2s;
}

#sidebar-resize:hover,
#sidebar-resize.dragging {
    background: rgba(100, 100, 100, 0.5);
}

/* Sidebar header */
.sidebar-header {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(60, 60, 60, 0.3);
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-header h2 {
    font-size: 14px;
    font-weight: 600;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Category sections */
.category {
    border-bottom: 1px solid rgba(60, 60, 60, 0.2);
}

.category-header {
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: background 0.15s;
}

.category-header:hover {
    background: rgba(60, 60, 60, 0.15);
}

.category-header h3 {
    font-size: 11px;
    font-weight: 500;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.category-arrow {
    color: #555;
    font-size: 10px;
    transition: transform 0.2s;
}

.category.collapsed .category-arrow {
    transform: rotate(-90deg);
}

.category-items {
    animation: fadeInDown 0.3s ease;
    transform-origin: top;
}

.category.collapsed .category-items {
    display: none;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Element items grid */
.category-items {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
    gap: 6px;
    padding: 8px 10px 12px;
}

/* Element button */
.element-btn {
    aspect-ratio: 1;
    background: rgba(20, 20, 20, 0.6);
    border: 2px solid rgba(50, 50, 50, 0.4);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

.element-btn:hover {
    background: rgba(40, 40, 40, 0.7);
    border-color: rgba(80, 80, 80, 0.6);
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.element-btn:active {
    transform: translateY(-1px) scale(0.98);
    transition: all 0.1s;
}

.element-btn.active {
    background: rgba(60, 60, 60, 0.5);
    border-color: rgba(120, 120, 120, 0.8);
    box-shadow: 0 0 12px rgba(100, 100, 100, 0.4), inset 0 0 20px rgba(100, 100, 100, 0.1);
    animation: pulseGlow 2s ease-in-out infinite;
}

@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 12px rgba(100, 100, 100, 0.4); }
    50% { box-shadow: 0 0 18px rgba(120, 120, 120, 0.5); }
}

.element-btn .icon {
    width: 32px;
    height: 32px;
    image-rendering: pixelated;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.element-btn .label {
    font-size: 8px;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    text-align: center;
}

.element-btn:hover .label {
    color: #888;
}

.element-btn.active .label {
    color: #aaa;
}

/* ===== BOTTOM BAR ===== */
#bottom-bar {
    position: fixed;
    right: 15px;
    bottom: 15px;
    background: rgba(10, 10, 10, 0.5);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(60, 60, 60, 0.4);
    border-radius: 8px;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    z-index: 100;
    animation: slideInUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) 0.1s both;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

#bottom-bar:hover {
    border-color: rgba(100, 100, 100, 0.5);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.bottom-group {
    display: flex;
    gap: 8px;
}

.bottom-btn {
    padding: 8px 16px;
    background: rgba(30, 30, 30, 0.6);
    border: 1px solid rgba(60, 60, 60, 0.4);
    border-radius: 5px;
    color: #888;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.bottom-btn:hover {
    background: rgba(50, 50, 50, 0.7);
    color: #ccc;
    border-color: rgba(100, 100, 100, 0.6);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.bottom-btn:active {
    transform: translateY(0) scale(0.98);
    transition: all 0.1s;
}

.bottom-divider {
    width: 1px;
    height: 28px;
    background: rgba(60, 60, 60, 0.4);
}

/* Brush size slider */
.brush-control {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brush-control label {
    color: #666;
    font-size: 11px;
    white-space: nowrap;
}

.brush-control input[type="range"] {
    width: 90px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(60, 60, 60, 0.4);
    border-radius: 2px;
    outline: none;
}

.brush-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: linear-gradient(135deg, #888, #555);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.15s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.brush-control input[type="range"]::-webkit-slider-thumb:hover {
    background: linear-gradient(135deg, #aaa, #777);
    transform: scale(1.15);
}

/* FPS counter */
#fps {
    position: fixed;
    bottom: 15px;
    left: 240px;
    color: #333;
    font-size: 11px;
    font-family: monospace;
    z-index: 101;
}

/* Cursor preview */
#cursor-preview {
    position: fixed;
    pointer-events: none;
    border: 2px solid rgba(150, 150, 150, 0.5);
    border-radius: 50%;
    z-index: 1000;
    display: none;
}

/* Weather Canvas */
#weather-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

/* ===== PAUSE MENU ===== */
.pause-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    display: none;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.pause-overlay.active {
    display: block;
    opacity: 1;
    animation: fadeIn 0.4s ease;
}

.pause-overlay.active .pause-menu-nav {
    animation: slideInLeft 0.5s cubic-bezier(0.16, 1, 0.3, 1) 0.1s both;
}

.pause-overlay.active .pause-title {
    animation: fadeInDown 0.5s cubic-bezier(0.16, 1, 0.3, 1) 0.15s both;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.pause-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
}

.pause-menu-nav {
    position: absolute;
    left: 50px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 5px;
    z-index: 10;
}

.pause-title {
    font-size: 32px;
    font-weight: 300;
    letter-spacing: 6px;
    color: #7dd3fc;
    text-transform: uppercase;
    margin: 0 0 10px 0;
    padding-left: 20px;
    text-shadow: 0 2px 20px rgba(125, 211, 252, 0.3);
}

.pause-menu-nav .menu-divider {
    height: 1px;
    background: rgba(100, 100, 100, 0.2);
    margin: 10px 20px;
}

/* Hide old UI elements */
#elements-panel, #tools-panel, #filter-box, #toolbar, #reactions-info, #info {
    display: none;
}

/* ===== MODIFIERS BUTTON ===== */
.modifiers-btn {
    position: fixed;
    top: 15px;
    right: 15px;
    background: rgba(10, 10, 10, 0.7);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(60, 60, 60, 0.5);
    border-radius: 8px;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #888;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    z-index: 150;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    animation: slideInRight 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.modifiers-btn:hover {
    background: rgba(30, 30, 30, 0.8);
    border-color: rgba(100, 100, 100, 0.6);
    color: #ccc;
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.modifiers-btn.active {
    background: rgba(60, 60, 60, 0.6);
    border-color: rgba(120, 120, 120, 0.7);
    color: #fff;
}

.modifiers-btn svg {
    fill: currentColor;
}

.modifiers-btn .modifier-count {
    background: #FF6B6B;
    color: white;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== MODIFIERS PANEL ===== */
.modifiers-panel {
    position: fixed;
    top: 60px;
    right: 15px;
    width: 380px;
    max-height: calc(100vh - 100px);
    background: rgba(15, 15, 15, 0.95);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(60, 60, 60, 0.5);
    border-radius: 12px;
    z-index: 200;
    display: none;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    animation: fadeInScale 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modifiers-panel.active {
    display: flex;
}

.modifiers-header {
    padding: 16px 20px;
    border-bottom: 1px solid rgba(60, 60, 60, 0.3);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modifiers-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: #ccc;
    margin: 0;
}

.modifiers-close {
    background: none;
    border: none;
    color: #666;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}

.modifiers-close:hover {
    color: #fff;
}

.modifiers-desc {
    padding: 12px 20px;
    font-size: 11px;
    color: #666;
    border-bottom: 1px solid rgba(60, 60, 60, 0.2);
    margin: 0;
}

.modifiers-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(80, 80, 80, 0.5) transparent;
}

.modifiers-list::-webkit-scrollbar {
    width: 6px;
}

.modifiers-list::-webkit-scrollbar-track {
    background: transparent;
}

.modifiers-list::-webkit-scrollbar-thumb {
    background: rgba(80, 80, 80, 0.5);
    border-radius: 3px;
}

.modifier-category {
    margin-bottom: 8px;
}

.modifier-category h3 {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 8px 20px 6px;
    margin: 0;
}

.modifier-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 12px;
}

.modifier-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: rgba(25, 25, 25, 0.6);
    border: 1px solid rgba(50, 50, 50, 0.4);
    border-radius: 8px;
    transition: all 0.2s ease;
}

.modifier-item:hover {
    background: rgba(35, 35, 35, 0.7);
    border-color: rgba(80, 80, 80, 0.5);
}

.modifier-item.active {
    background: rgba(var(--modifier-color-rgb, 100, 100, 100), 0.15);
    border-color: var(--modifier-color, #888);
    box-shadow: 0 0 15px rgba(var(--modifier-color-rgb, 100, 100, 100), 0.2);
}

.modifier-icon {
    width: 36px;
    height: 36px;
    min-width: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(40, 40, 40, 0.6);
    border-radius: 8px;
    color: var(--modifier-color, #888);
}

.modifier-icon svg {
    width: 20px;
    height: 20px;
}

.modifier-info {
    flex: 1;
    min-width: 0;
}

.modifier-name {
    font-size: 13px;
    font-weight: 500;
    color: #ddd;
    margin-bottom: 2px;
}

.modifier-desc {
    font-size: 10px;
    color: #666;
    line-height: 1.3;
}

/* Toggle switch */
.modifier-toggle {
    position: relative;
}

.modifier-toggle input {
    display: none;
}

.modifier-toggle label {
    display: block;
    width: 44px;
    height: 24px;
    background: rgba(40, 40, 40, 0.8);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.modifier-toggle label::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    background: #555;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.modifier-toggle input:checked + label {
    background: var(--modifier-color, #4CAF50);
}

.modifier-toggle input:checked + label::after {
    left: 23px;
    background: #fff;
}

.modifiers-footer {
    padding: 12px 20px;
    border-top: 1px solid rgba(60, 60, 60, 0.3);
}

.modifiers-reset-btn {
    width: 100%;
    padding: 10px;
    background: rgba(80, 30, 30, 0.4);
    border: 1px solid rgba(150, 50, 50, 0.4);
    border-radius: 6px;
    color: #e57373;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modifiers-reset-btn:hover {
    background: rgba(120, 40, 40, 0.5);
    border-color: rgba(200, 60, 60, 0.5);
    color: #ff8a80;
}

/* ===== NIGHT MODE ===== */
body.night-mode #canvas-container {
    filter: brightness(0.4) contrast(1.2);
}

body.night-mode #sandbox {
    filter: saturate(0.8);
}

/* ===== RAINBOW MODE ===== */
body.rainbow-mode #sandbox {
    filter: hue-rotate(calc(var(--rainbow-hue, 0) * 1deg));
}
