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

body {
    font-family: 'Space Mono', monospace;
    background: #f5f5f5;
    overflow: hidden;
}

.app-container {
    display: grid;
    grid-template-columns: 280px 1fr 280px;
    height: 100vh;
    gap: 0;
}

/* Sidebar */
.sidebar {
    background: #ffffff;
    border-right: 1px solid #e0e0e0;
    overflow-y: auto;
    padding: 20px;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.sidebar-header h1 {
    font-size: 24px;
    margin-bottom: 30px;
    color: #000;
}

.sidebar-header h1 {
    margin-bottom: 0;
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    display: none; /* Hidden by default */
}

.sidebar-section {
    margin-bottom: 20px;
}

.sidebar-section h3 {
    font-size: 14px;
    margin-bottom: 12px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: #f5f5f5;
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    margin-bottom: 8px;
    transition: background 0.2s;
}

.section-header:hover {
    background: #e8e8e8;
}

.section-header h3 {
    margin: 0;
    font-size: 12px;
    color: #333;
}

.section-toggle {
    font-size: 18px;
    font-weight: bold;
    color: #666;
    transition: transform 0.2s;
}

.section-toggle.collapsed {
    transform: rotate(-90deg);
}

.section-content {
    max-height: 1000px;
    overflow: hidden;
    transition: max-height 0.3s ease-out, opacity 0.3s ease-out;
    opacity: 1;
}

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

/* File Upload */
.file-input {
    display: none;
}

.file-label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background: #000;
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.2s;
}

.file-label:hover {
    transform: translateY(-2px);
}

/* View Toggle */
.view-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.view-btn {
    padding: 10px;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Space Mono', monospace;
    font-size: 12px;
    transition: all 0.2s;
}

.view-btn.active {
    background: #000;
    color: #fff;
    border-color: #000;
}

.view-btn:hover:not(.active) {
    background: #e0e0e0;
}

/* Object Grid */
.object-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    max-height: 400px;
    overflow-y: auto;
}

.object-btn {
    padding: 12px 8px;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Space Mono', monospace;
    font-size: 11px;
    transition: all 0.2s;
}

.object-btn:hover {
    background: #000;
    color: #fff;
    border-color: #000;
    transform: translateY(-2px);
}

.object-btn.active {
    background: #000;
    color: #fff;
    border-color: #000;
}

/* Texture Grid */
.texture-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.texture-btn {
    padding: 10px;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Space Mono', monospace;
    font-size: 11px;
    transition: all 0.2s;
}

.texture-btn:hover {
    background: #000;
    color: #fff;
    border-color: #000;
}

/* Range Slider */
input[type="range"] {
    width: 100%;
    margin-top: 8px;
}

/* Tool Buttons */
.tool-btn {
    width: 100%;
    padding: 12px;
    margin-bottom: 8px;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Space Mono', monospace;
    font-size: 12px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tool-btn .icon {
    font-size: 16px;
}

.tool-btn:hover {
    background: #000;
    color: #fff;
    border-color: #000;
}

#generateFromImage {
    background: #0066ff;
    color: #fff;
    border: none;
}

#generateFromImage:hover:not(:disabled) {
    background: #0052cc;
}

#generateFromImage:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

#analysisProgress {
    padding: 8px;
    background: #f0f0f0;
    border-radius: 4px;
    text-align: center;
}

/* Canvas Area */
.canvas-area {
    position: relative;
    background: #fafafa;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Changed from auto to hidden to manage scrolling on canvas itself */
}

.canvas-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    gap: 12px;
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    justify-content: center;
    padding: 4px 12px;
    background: linear-gradient(to bottom, #fafafa, #f5f5f5);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    color: #333;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.toolbar-btn:hover {
    background: #f8f8f8;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    border-color: #ccc;
}

.toolbar-btn.active {
    background: #000;
    color: #fff;
    border-color: #000;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.toolbar-btn svg {
    pointer-events: none;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: #e0e0e0;
    margin: 0 4px;
}

.info-panel {
    display: flex;
    gap: 16px;
    font-size: 11px;
    color: #333;
}

.canvas-wrapper {
    position: relative;
    display: inline-block;
    min-width: 100%;
    min-height: 100%;
}

#canvas2d {
    flex: 1;
    cursor: none;
    display: block;
}

#canvas3d {
    flex: 1;
}

/* Properties Panel */
.properties-panel {
    background: #ffffff;
    border-left: 1px solid #e0e0e0;
    padding: 20px;
    overflow-y: auto;
    transition: transform 0.3s ease-in-out;
}

.properties-panel.hidden {
    transform: translateX(100%);
}

.properties-panel h3 {
    font-size: 14px;
    margin-bottom: 20px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.properties-panel .sidebar-header {
    margin-bottom: 20px;
}

.property-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.property-group label {
    display: flex;
    flex-direction: column;
    font-size: 12px;
    color: #666;
}

.property-group input {
    margin-top: 4px;
    padding: 8px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    font-family: 'Space Mono', monospace;
}

.property-group input[type="color"] {
    margin-top: 4px;
    padding: 4px;
    height: 40px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
}

.property-group input[type="range"] {
    margin-top: 8px;
    width: 100%;
}

.delete-btn {
    width: 100%;
    padding: 10px;
    margin-top: 20px;
    background: #ff4444;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Space Mono', monospace;
    transition: all 0.2s;
}

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

#eraserBtn {
    background: #ff6b6b;
    color: #fff;
}

#selectBtn {
    background: #4a90e2;
    color: #fff;
}

#selectBtn.active {
    background: #357ABD;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

#eraserBtn:hover {
    background: #ff5252;
}

#shapeFilledGroup {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #666;
    margin-top: 8px;
    cursor: pointer;
}

#shapeFilledGroup input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f5f5f5;
}

::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: #fff;
    padding: 30px;
    border-radius: 8px;
    min-width: 400px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
    margin-bottom: 20px;
    font-size: 20px;
    color: #000;
}

.export-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.export-format-btn {
    padding: 15px;
    background: #f5f5f5;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Space Mono', monospace;
    font-size: 14px;
    transition: all 0.2s;
}

.export-format-btn:hover {
    background: #000;
    color: #fff;
    border-color: #000;
    transform: translateY(-2px);
}

.modal-close {
    width: 100%;
    padding: 12px;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Space Mono', monospace;
    transition: all 0.2s;
}

.modal-close:hover {
    background: #e0e0e0;
}

/* Vertex snap guide */
.snap-indicator {
    position: absolute;
    width: 12px;
    height: 12px;
    border: 2px solid #00ff88;
    border-radius: 50%;
    background: rgba(0, 255, 136, 0.3);
    pointer-events: none;
    animation: pulse 0.6s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.6; }
}

/* Selection rectangle */
.selection-rectangle {
    position: absolute;
    border: 1px dashed #007bff;
    background-color: rgba(0, 123, 255, 0.1);
    pointer-events: none;
    z-index: 10000;
}

/* Custom cursor overlay */
.custom-cursor {
    position: fixed;
    width: 20px;
    height: 20px;
    pointer-events: none;
    z-index: 9999;
    transform: translate(-50%, -50%);
}

.custom-cursor::before,
.custom-cursor::after {
    content: '';
    position: absolute;
    background-color: currentColor;
}

.custom-cursor::before {
    width: 1px;
    height: 20px;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
}

.custom-cursor::after {
    width: 20px;
    height: 1px;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

.mirror-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 15px;
    margin-bottom: 10px;
}

.mirror-buttons .tool-btn {
    margin-bottom: 0;
    font-size: 10px;
    padding: 8px 4px;
}

/* Custom cursors */
#canvas2d {
    cursor: none;
}

#canvas2d.cursor-grab {
    cursor: grab !important;
}

#canvas2d.cursor-grabbing {
    cursor: grabbing !important;
}

#canvas2d.cursor-move {
    cursor: move !important;
}

.unit-select {
    width: 100%;
    padding: 8px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    font-family: 'Space Mono', monospace;
    font-size: 12px;
    background: #f5f5f5;
    cursor: pointer;
}

.unit-select:hover {
    background: #e0e0e0;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #666;
    margin-bottom: 8px;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.zoom-controls {
    margin-top: 12px;
}

/* Mobile Responsiveness */
@media (max-width: 1024px) {
    .app-container {
        grid-template-columns: 280px 1fr;
    }
    .properties-panel {
        position: fixed;
        right: 0;
        top: 0;
        height: 100vh;
        z-index: 1001;
        transform: translateX(100%);
        box-shadow: -2px 0 10px rgba(0,0,0,0.1);
    }
    .properties-panel.visible {
        transform: translateX(0);
    }
    .mobile-toggle {
        display: block !important;
    }
}

@media (max-width: 768px) {
    .app-container {
        grid-template-columns: 1fr;
    }
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        width: 85%;
        max-width: 320px;
        z-index: 1002;
        transform: translateX(-100%);
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        transition: transform 0.3s ease-in-out;
        padding: 16px;
    }
    .sidebar.visible {
        transform: translateX(0);
    }
    .sidebar-toggle {
        display: block;
    }
    .mobile-toggle {
        display: block;
    }

    .toolbar {
        display: none;
    }
    
    .canvas-header {
        justify-content: space-between;
        padding: 10px;
    }

    .properties-panel {
        width: 85%;
        max-width: 320px;
        padding: 16px;
    }
    
    /* Improved mobile sidebar styling */
    .sidebar-header h1 {
        font-size: 20px;
        margin-bottom: 0;
    }
    
    .section-header {
        padding: 12px 10px;
        background: #f8f8f8;
        border-radius: 8px;
        margin-bottom: 6px;
        border: 1px solid #e8e8e8;
    }
    
    .section-header h3 {
        font-size: 13px;
        font-weight: 600;
        color: #222;
        text-transform: none;
        letter-spacing: 0;
    }
    
    .section-toggle {
        font-size: 20px;
        font-weight: 700;
        color: #444;
    }
    
    /* Compact object grid for mobile */
    .object-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
        max-height: none;
    }
    
    .object-btn {
        padding: 10px 4px;
        font-size: 10px;
        border-radius: 6px;
        min-height: 50px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        background: #fafafa;
        border: 1px solid #e8e8e8;
    }
    
    .object-btn:active {
        transform: scale(0.95);
        background: #000;
        color: #fff;
    }
    
    /* Compact tool buttons */
    .tool-btn {
        padding: 10px 8px;
        font-size: 11px;
        border-radius: 6px;
        margin-bottom: 6px;
        background: #fafafa;
        border: 1px solid #e8e8e8;
    }
    
    .tool-btn .icon {
        font-size: 18px;
    }
    
    .tool-btn:active {
        transform: scale(0.97);
    }
    
    /* File label improvements */
    .file-label {
        padding: 10px;
        font-size: 11px;
        border-radius: 6px;
    }
    
    /* Compact checkbox labels */
    .checkbox-label {
        font-size: 11px;
        margin-bottom: 6px;
        padding: 4px;
    }
    
    /* Unit select */
    .unit-select {
        padding: 6px;
        font-size: 11px;
    }
    
    /* Sidebar sections spacing */
    .sidebar-section {
        margin-bottom: 10px;
    }
    
    .section-content {
        padding: 8px 4px;
    }
    
    /* View toggle */
    .view-toggle {
        gap: 6px;
    }
    
    .view-btn {
        padding: 8px;
        font-size: 11px;
        border-radius: 6px;
    }
    
    /* Texture grid */
    .texture-grid {
        gap: 6px;
    }
    
    .texture-btn {
        padding: 8px;
        font-size: 10px;
        border-radius: 6px;
    }
}

/* Mobile Bottom Toolbar */
.mobile-bottom-toolbar {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-top: 1px solid #e0e0e0;
    padding: 6px 8px 8px 8px;
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
}

.mobile-bottom-toolbar .toolbar-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}

.mobile-tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    background: #fafafa;
    border: 2px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    font-family: 'Space Mono', monospace;
    font-size: 9px;
    font-weight: 500;
    transition: all 0.2s;
    min-height: 62px;
    position: relative;
}

.mobile-tool-btn .icon {
    font-size: 24px;
    margin-bottom: 4px;
}

.mobile-tool-btn.active {
    background: linear-gradient(135deg, #000 0%, #333 100%);
    color: #fff;
    border-color: #000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transform: translateY(-2px);
}

.mobile-tool-btn:active {
    transform: scale(0.95);
}

/* Improved touch feedback */
.mobile-tool-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.1);
    border-radius: 10px;
    opacity: 0;
    transition: opacity 0.2s;
}

.mobile-tool-btn:active::before {
    opacity: 1;
}

/* Improved touch target sizes */
@media (max-width: 768px) {
    .toolbar-btn,
    .tool-btn {
        min-height: 44px;
        font-size: 11px;
    }
    
    .mobile-bottom-toolbar {
        display: block;
    }
    
    .fab-menu {
        display: block;
    }
    
    .canvas-area {
        padding-bottom: 76px;
    }
    
    /* Info panel adjustments */
    .info-panel {
        font-size: 10px;
        gap: 8px;
    }
    
    /* Property panel mobile improvements */
    .property-group {
        gap: 10px;
    }
    
    .property-group label {
        font-size: 11px;
    }
    
    .property-group input {
        padding: 6px;
        font-size: 12px;
    }
    
    .mirror-buttons {
        gap: 6px;
        margin-top: 12px;
    }
    
    .mirror-buttons .tool-btn {
        font-size: 9px;
        padding: 8px 4px;
    }
    
    .delete-btn {
        padding: 10px;
        font-size: 12px;
        margin-top: 16px;
    }
}

/* Touch feedback */
@media (hover: none) {
    .toolbar-btn:active,
    .tool-btn:active {
        transform: scale(0.95);
        background: #ddd;
    }
    
    .object-btn:active {
        transform: scale(0.95);
    }
    
    .section-header:active {
        background: #e0e0e0;
    }
}

/* Floating Action Button for Mobile */
.fab-menu {
    display: none;
    position: fixed;
    bottom: 80px;
    right: 16px;
    z-index: 999;
}

.fab-main {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #000;
    color: #fff;
    border: none;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: all 0.2s;
}

.fab-main:active {
    transform: scale(0.9);
}

.fab-options {
    position: absolute;
    bottom: 70px;
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
}

.fab-menu.open .fab-options {
    opacity: 1;
    pointer-events: all;
}

.fab-option {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #333;
    color: #fff;
    border: none;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transition: all 0.2s;
}

.fab-option:active {
    transform: scale(0.9);
}