* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    overflow: hidden;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.header {
    background: rgba(255, 255, 255, 0.95);
    padding: 0.75rem 2rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
}

.header h1 {
    font-size: 1.8rem;
    color: #333;
    margin: 0;
}

.header-info {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-left: auto;
}

/* Menu Bar */
.menu-bar {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.menu-item {
    position: relative;
}

.menu-button {
    background: transparent;
    border: none;
    padding: 0.6rem 1rem;
    font-size: 0.95rem;
    font-weight: 500;
    color: #333;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.menu-button:hover {
    background: #f0f0f0;
}

.menu-item:hover .dropdown-menu,
.dropdown-menu:hover {
    display: block;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 220px;
    padding: 0.5rem 0;
    z-index: 1000;
    margin-top: 0.25rem;
    /* Add a small invisible padding area to keep menu open */
}

.dropdown-menu::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 0;
    right: 0;
    height: 10px;
}

.dropdown-item {
    width: 100%;
    background: none;
    border: none;
    padding: 0.7rem 1rem;
    text-align: left;
    font-size: 0.9rem;
    color: #333;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dropdown-item:hover {
    background: #f5f5f5;
}

.dropdown-divider {
    height: 1px;
    background: #e0e0e0;
    margin: 0.5rem 0;
}

.dropdown-submenu {
    padding: 0.5rem 0;
}

.dropdown-label {
    display: block;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: #666;
}

.menu-icon {
    color: #667eea;
    font-weight: bold;
    min-width: 1rem;
}

.menu-icon.hidden {
    opacity: 0;
}

/* Main content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    gap: 1rem;
    padding: 1rem;
}

/* Sidebar */
.sidebar {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    width: 320px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 2px solid #eee;
}

.sidebar-header h2 {
    margin-bottom: 1rem;
    color: #333;
    font-size: 1.3rem;
}

.search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input {
    width: 100%;
    padding: 0.7rem 2.5rem 0.7rem 0.7rem;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 0.95rem;
    transition: border-color 0.3s;
}

.search-input:focus {
    outline: none;
    border-color: #667eea;
}

.clear-search {
    position: absolute;
    right: 0.5rem;
    background: none;
    border: none;
    color: #999;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: all 0.2s;
    opacity: 0;
    pointer-events: none;
}

.clear-search.visible {
    opacity: 1;
    pointer-events: auto;
}

.clear-search:hover {
    background: #f5f5f5;
    color: #667eea;
}

/* Categories */
.categories {
    padding: 1rem;
    border-bottom: 2px solid #eee;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    max-height: 150px;
    overflow-y: auto;
}

.category-btn {
    background: #f5f5f5;
    border: 2px solid transparent;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.3s;
    white-space: nowrap;
}

.category-btn:hover {
    background: #e8e8e8;
    transform: translateY(-2px);
}

.category-btn.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

/* Textures grid */
.textures-grid {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: 0.5rem;
    align-content: start;
}

.texture-item {
    width: 48px;
    height: 48px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    background: white;
    padding: 2px;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

.texture-item img {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

.texture-item:hover {
    transform: scale(1.1);
    border-color: #667eea;
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
    z-index: 10;
}

.texture-item.selected {
    border-color: #667eea;
    border-width: 3px;
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.5);
}

/* Canvas area */
.canvas-area {
    flex: 1;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.tool-btn {
    background: #f5f5f5;
    border: 2px solid #e0e0e0;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    font-weight: 500;
}

.tool-btn:hover {
    background: #e8e8e8;
    border-color: #667eea;
}

.zoom-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

#zoomLevel {
    font-weight: bold;
    color: #667eea;
    min-width: 50px;
    text-align: center;
    font-size: 0.9rem;
}

/* Canvas wrapper */
.canvas-wrapper {
    flex: 1;
    position: relative;
    overflow: auto;
    background: linear-gradient(to bottom, #87CEEB 0%, #B0D9F5 100%);
    border-radius: 8px;
    transition: background 0.5s ease;
}

/* Background variations */
.canvas-wrapper.bg-day-sun {
    background: linear-gradient(to bottom, #87CEEB 0%, #B0D9F5 100%);
}

.canvas-wrapper.bg-day {
    background: linear-gradient(to bottom, #87CEEB 0%, #B0D9F5 100%);
}

.canvas-wrapper.bg-night-moon {
    background: linear-gradient(to bottom, #0a1628 0%, #1a2744 100%);
}

.canvas-wrapper.bg-night-stars {
    background: linear-gradient(to bottom, #0a1628 0%, #1a2744 100%);
}

/* Sun and Moon (square, Minecraft style) */
.canvas-wrapper::before {
    content: '';
    position: absolute;
    width: 80px;
    height: 80px;
    top: 40px;
    right: 60px;
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
    z-index: 1;
    image-rendering: pixelated;
}

.canvas-wrapper.bg-day-sun::before {
    opacity: 1;
    background: linear-gradient(135deg, #FDB813 0%, #FFDD44 50%, #FDB813 100%);
    box-shadow: 0 0 60px rgba(253, 184, 19, 0.6);
}

.canvas-wrapper.bg-night-moon::before {
    opacity: 1;
    background: linear-gradient(135deg, #E8E8E8 0%, #FFFFFF 50%, #E8E8E8 100%);
    box-shadow: 0 0 50px rgba(232, 232, 232, 0.4);
}

/* Stars for starry night */
.canvas-wrapper.bg-night-stars::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image:
        /* Large stars (3px - was 2px) */
        radial-gradient(3px 3px at 20% 30%, white, transparent),
        radial-gradient(3px 3px at 60% 70%, white, transparent),
        radial-gradient(3px 3px at 90% 60%, white, transparent),
        radial-gradient(3px 3px at 15% 15%, white, transparent),
        radial-gradient(3px 3px at 75% 25%, white, transparent),
        radial-gradient(3px 3px at 40% 85%, white, transparent),
        radial-gradient(3px 3px at 85% 90%, white, transparent),
        radial-gradient(3px 3px at 10% 65%, white, transparent),
        radial-gradient(3px 3px at 55% 45%, white, transparent),
        radial-gradient(3px 3px at 30% 10%, white, transparent),
        radial-gradient(3px 3px at 48% 92%, white, transparent),
        radial-gradient(3px 3px at 82% 38%, white, transparent),
        radial-gradient(3px 3px at 5% 5%, white, transparent),
        radial-gradient(3px 3px at 95% 95%, white, transparent),
        radial-gradient(3px 3px at 28% 58%, white, transparent),
        radial-gradient(3px 3px at 72% 12%, white, transparent),
        radial-gradient(3px 3px at 18% 48%, white, transparent),
        radial-gradient(3px 3px at 62% 82%, white, transparent),
        radial-gradient(3px 3px at 35% 68%, white, transparent),
        radial-gradient(3px 3px at 88% 28%, white, transparent),
        /* Medium stars (2.25px - was 1.5px) */
        radial-gradient(2.25px 2.25px at 45% 55%, white, transparent),
        radial-gradient(2.25px 2.25px at 25% 75%, white, transparent),
        radial-gradient(2.25px 2.25px at 65% 35%, white, transparent),
        radial-gradient(2.25px 2.25px at 95% 15%, white, transparent),
        radial-gradient(2.25px 2.25px at 5% 40%, white, transparent),
        radial-gradient(2.25px 2.25px at 80% 80%, white, transparent),
        radial-gradient(2.25px 2.25px at 35% 20%, white, transparent),
        radial-gradient(2.25px 2.25px at 70% 95%, white, transparent),
        radial-gradient(2.25px 2.25px at 52% 8%, white, transparent),
        radial-gradient(2.25px 2.25px at 14% 72%, white, transparent),
        radial-gradient(2.25px 2.25px at 78% 48%, white, transparent),
        radial-gradient(2.25px 2.25px at 92% 78%, white, transparent),
        radial-gradient(2.25px 2.25px at 8% 92%, white, transparent),
        radial-gradient(2.25px 2.25px at 42% 38%, white, transparent),
        radial-gradient(2.25px 2.25px at 68% 58%, white, transparent),
        radial-gradient(2.25px 2.25px at 22% 42%, white, transparent),
        /* Small stars (1.5px - was 1px) */
        radial-gradient(1.5px 1.5px at 50% 50%, white, transparent),
        radial-gradient(1.5px 1.5px at 80% 10%, white, transparent),
        radial-gradient(1.5px 1.5px at 33% 80%, white, transparent),
        radial-gradient(1.5px 1.5px at 70% 40%, white, transparent),
        radial-gradient(1.5px 1.5px at 12% 50%, white, transparent),
        radial-gradient(1.5px 1.5px at 88% 45%, white, transparent),
        radial-gradient(1.5px 1.5px at 42% 15%, white, transparent),
        radial-gradient(1.5px 1.5px at 58% 90%, white, transparent),
        radial-gradient(1.5px 1.5px at 22% 22%, white, transparent),
        radial-gradient(1.5px 1.5px at 68% 68%, white, transparent),
        radial-gradient(1.5px 1.5px at 15% 88%, white, transparent),
        radial-gradient(1.5px 1.5px at 92% 32%, white, transparent),
        radial-gradient(1.5px 1.5px at 38% 62%, white, transparent),
        radial-gradient(1.5px 1.5px at 52% 78%, white, transparent),
        radial-gradient(1.5px 1.5px at 8% 18%, white, transparent),
        radial-gradient(1.5px 1.5px at 78% 58%, white, transparent),
        radial-gradient(1.5px 1.5px at 17% 35%, white, transparent),
        radial-gradient(1.5px 1.5px at 63% 25%, white, transparent),
        radial-gradient(1.5px 1.5px at 32% 52%, white, transparent),
        radial-gradient(1.5px 1.5px at 85% 65%, white, transparent),
        radial-gradient(1.5px 1.5px at 48% 72%, white, transparent),
        radial-gradient(1.5px 1.5px at 93% 8%, white, transparent),
        radial-gradient(1.5px 1.5px at 7% 28%, white, transparent),
        radial-gradient(1.5px 1.5px at 55% 5%, white, transparent),
        radial-gradient(1.5px 1.5px at 27% 95%, white, transparent),
        radial-gradient(1.5px 1.5px at 74% 88%, white, transparent),
        radial-gradient(1.5px 1.5px at 11% 62%, white, transparent),
        radial-gradient(1.5px 1.5px at 97% 52%, white, transparent),
        radial-gradient(1.5px 1.5px at 44% 44%, white, transparent),
        radial-gradient(1.5px 1.5px at 66% 77%, white, transparent),
        radial-gradient(1.5px 1.5px at 19% 8%, white, transparent),
        radial-gradient(1.5px 1.5px at 86% 22%, white, transparent);
    background-size: 100% 100%;
    pointer-events: none;
    opacity: 0.9;
    animation: twinkle 4s ease-in-out infinite;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.9; }
    50% { opacity: 0.5; }
}

/* Galactic cluster / Milky Way */
.galaxy-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease;
    z-index: 1;
}

.canvas-wrapper.bg-night-stars .galaxy-overlay {
    opacity: 1;
    background:
        radial-gradient(
            ellipse 150% 50% at 50% 50%,
            rgba(220, 230, 255, 0.18) 0%,
            rgba(180, 200, 255, 0.12) 20%,
            rgba(140, 170, 255, 0.07) 40%,
            rgba(100, 140, 255, 0.03) 60%,
            transparent 80%
        );
    transform: rotate(-12deg);
    animation: galaxyShift 25s ease-in-out infinite;
}

@keyframes galaxyShift {
    0%, 100% {
        opacity: 0.75;
        transform: rotate(-12deg) translateY(0);
    }
    50% {
        opacity: 0.55;
        transform: rotate(-14deg) translateY(-10px);
    }
}

.canvas-container {
    display: inline-block;
    position: relative;
    margin: 20px;
    transform-origin: top left;
}

#drawingCanvas,
#gridCanvas,
#previewCanvas {
    position: absolute;
    top: 0;
    left: 0;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

#gridCanvas,
#previewCanvas {
    pointer-events: none;
}

#previewCanvas {
    opacity: 0.7;
}

/* Current texture */
.current-texture {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: #f0f3ff;
    border: 2px solid #667eea;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.current-texture-preview {
    width: 40px;
    height: 40px;
    border: 2px solid #667eea;
    border-radius: 6px;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    image-rendering: pixelated;
}

.current-texture-preview img {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

.no-texture {
    font-size: 0.7rem;
    color: #999;
}

#currentTextureName {
    font-weight: 600;
    color: #667eea;
    font-size: 0.85rem;
    flex: 1;
}

.current-texture > span:first-child {
    font-size: 0.8rem;
    color: #666;
    font-weight: 500;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #5568d3;
}

/* Loading indicator */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: #667eea;
    font-size: 1.1rem;
}

/* Quick Toolbar */
.quick-toolbar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.quick-btn {
    background: #f5f5f5;
    border: 2px solid #e0e0e0;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.2s;
}

.quick-btn:hover {
    background: #e8e8e8;
    border-color: #667eea;
    transform: translateY(-1px);
}

.quick-btn.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

/* Layers in dropdown menu */
.layer-menu-item {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    width: 280px !important;
}

.layer-menu-item.active {
    background: #f0f3ff !important;
    font-weight: 600;
}

.layer-visibility-icon {
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    font-size: 1rem;
    margin-right: 0.5rem;
}

.layer-visibility-icon:hover {
    background: #f5f5f5;
}

.layer-menu-name {
    flex: 1;
    text-align: left;
}

.layer-menu-controls {
    display: flex;
    gap: 0.25rem;
}

.layer-move-btn {
    background: #f5f5f5;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    padding: 0.15rem 0.4rem;
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.2s;
}

.layer-move-btn:hover:not(:disabled) {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.layer-move-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.eraser-icon {
    display: none;
}

.eraser-icon.visible {
    display: inline;
}

/* Responsive */
@media (max-width: 1200px) {
    .sidebar {
        width: 280px;
    }
}

@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        max-height: 300px;
    }

    .textures-grid {
        grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    }

    .texture-item {
        width: 40px;
        height: 40px;
    }
}
