/* CSS Reset and base styles for mobile */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    font-size: 16px;
    background: #C0C0C0;
    color: #000000;
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    -webkit-user-select: none;
    user-select: none;
}

/* Mobile app container */
.mobile-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: #C0C0C0;
}

/* Mobile Header */
.mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: #C0C0C0;
    border-bottom: 2px solid;
    border-color: #404040 #DFDFDF #DFDFDF #404040;
    min-height: 56px;
    safe-area-inset-top: env(safe-area-inset-top);
}

.hamburger-menu {
    display: flex;
    flex-direction: column;
    gap: 3px;
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
}

.hamburger-menu span {
    width: 20px;
    height: 2px;
    background: #000000;
    transition: all 0.3s;
}

.app-title-mobile {
    font-weight: bold;
    font-size: 14px;
    flex: 1;
    text-align: center;
}

.canvas-info {
    font-size: 11px;
    color: #404040;
    font-family: monospace;
}

/* Slide Menu */
.slide-menu {
    position: fixed;
    top: 56px;
    left: -280px;
    width: 280px;
    height: calc(100vh - 56px);
    background: #C0C0C0;
    border-right: 2px solid;
    border-color: #404040 #DFDFDF #DFDFDF #404040;
    transition: left 0.3s ease;
    z-index: 1000;
    overflow-y: auto;
    padding: 16px;
}

.slide-menu.open {
    left: 0;
}

.menu-section {
    margin-bottom: 24px;
}

.menu-title {
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 8px;
    padding: 8px 12px;
    background: #A0A0A0;
    border: 2px solid;
    border-color: #404040 #DFDFDF #DFDFDF #404040;
}

.menu-button {
    display: block;
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 4px;
    background: #C0C0C0;
    border: 1px solid;
    border-color: #DFDFDF #404040 #404040 #DFDFDF;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s;
}

.menu-button:active {
    background: #A0A0A0;
    border-color: #404040 #DFDFDF #DFDFDF #404040;
}

/* Main Canvas Area */
.canvas-area {
    flex: 1;
    background: #A0A0A0;
    position: relative;
    overflow: hidden;
}

.canvas-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.canvas-wrapper {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border: 2px solid;
    border-color: #404040 #DFDFDF #DFDFDF #404040;
    background: white;
    user-select: none;
}

#mainCanvas, #gridCanvas {
    display: block;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    touch-action: none;
}

#gridCanvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

/* Tool Palette */
.tool-palette {
    background: #C0C0C0;
    border-top: 2px solid;
    border-color: #DFDFDF #404040 #404040 #DFDFDF;
    padding: 8px 0;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.tool-palette::-webkit-scrollbar {
    display: none;
}

.tool-strip {
    display: flex;
    gap: 8px;
    padding: 0 16px;
    min-width: max-content;
}

.tool-btn, .brush-size-btn, .pattern-toggle {
    min-width: 48px;
    height: 48px;
    background: #C0C0C0;
    border: 2px solid;
    border-color: #DFDFDF #404040 #404040 #DFDFDF;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.2s;
}

.tool-btn.active, .brush-size-btn.active {
    border-color: #404040 #DFDFDF #DFDFDF #404040;
    background: #A0A0A0;
}

.tool-btn:active, .brush-size-btn:active, .pattern-toggle:active {
    transform: scale(0.95);
}

.brush-size-btn {
    font-size: 12px;
    font-weight: bold;
}

/* Pattern Drawer */
.pattern-drawer {
    position: fixed;
    bottom: 112px;
    left: 0;
    right: 0;
    background: #C0C0C0;
    border-top: 2px solid;
    border-color: #DFDFDF #404040 #404040 #DFDFDF;
    padding: 16px;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 500;
}

.pattern-drawer.open {
    transform: translateY(0);
}

.pattern-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    max-width: 300px;
    margin: 0 auto;
}

.pattern-btn {
    width: 60px;
    height: 60px;
    border: 2px solid;
    border-color: #DFDFDF #404040 #404040 #DFDFDF;
    background: white;
    cursor: pointer;
    padding: 4px;
}

.pattern-btn.active {
    border-color: #404040 #DFDFDF #DFDFDF #404040;
}

.pattern-btn canvas {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

/* Size Selector Modal */
.size-selector-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-content {
    background: #C0C0C0;
    border: 2px solid;
    border-color: #DFDFDF #404040 #404040 #DFDFDF;
    padding: 24px;
    margin: 20px;
    max-width: 320px;
    width: 100%;
}

.modal-title {
    font-weight: bold;
    font-size: 16px;
    margin-bottom: 16px;
    text-align: center;
}

.size-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.size-option {
    padding: 12px;
    border: 2px solid;
    border-color: #DFDFDF #404040 #404040 #DFDFDF;
    background: #C0C0C0;
    cursor: pointer;
    font-size: 14px;
}

.size-option.active {
    border-color: #404040 #DFDFDF #DFDFDF #404040;
    background: #A0A0A0;
}

.modal-close {
    width: 100%;
    padding: 12px;
    border: 2px solid;
    border-color: #DFDFDF #404040 #404040 #DFDFDF;
    background: #C0C0C0;
    font-size: 14px;
    cursor: pointer;
}

/* AI Panel */
.ai-panel {
    position: fixed;
    top: 100%;
    left: 0;
    right: 0;
    height: 80vh;
    background: #C0C0C0;
    border-top: 2px solid;
    border-color: #DFDFDF #404040 #404040 #DFDFDF;
    transition: top 0.3s ease;
    z-index: 1500;
    overflow-y: auto;
}

.ai-panel.open {
    top: 20vh;
}

.ai-content {
    padding: 20px;
    max-width: 400px;
    margin: 0 auto;
}

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

.ai-header h2 {
    font-size: 18px;
    font-weight: bold;
}

.close-ai {
    width: 32px;
    height: 32px;
    border: 2px solid;
    border-color: #DFDFDF #404040 #404040 #DFDFDF;
    background: #C0C0C0;
    font-size: 18px;
    cursor: pointer;
}

.prompt-section {
    position: relative;
    margin-bottom: 20px;
}

.prompt-section label {
    display: block;
    font-weight: bold;
    margin-bottom: 8px;
}

#promptInput {
    width: 100%;
    height: 80px;
    padding: 12px;
    border: 2px solid;
    border-color: #404040 #DFDFDF #DFDFDF #404040;
    background: white;
    font-size: 14px;
    resize: none;
    font-family: inherit;
}

.voice-input {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border: 1px solid #CCC;
    background: #F0F0F0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.style-presets, .ai-size-section {
    margin-bottom: 20px;
}

.preset-title {
    font-weight: bold;
    margin-bottom: 8px;
}

.preset-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.preset-btn {
    padding: 10px 8px;
    border: 2px solid;
    border-color: #DFDFDF #404040 #404040 #DFDFDF;
    background: #C0C0C0;
    font-size: 12px;
    cursor: pointer;
}

.preset-btn.active {
    border-color: #404040 #DFDFDF #DFDFDF #404040;
    background: #A0A0A0;
}

.ai-size-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.ai-size-btn {
    padding: 10px 8px;
    border: 2px solid;
    border-color: #DFDFDF #404040 #404040 #DFDFDF;
    background: #C0C0C0;
    font-size: 12px;
    cursor: pointer;
}

.ai-size-btn.active {
    border-color: #404040 #DFDFDF #DFDFDF #404040;
    background: #A0A0A0;
}

.generate-btn {
    width: 100%;
    padding: 16px;
    background: #008000;
    color: white;
    border: 2px solid;
    border-color: #00C000 #004000 #004000 #00C000;
    font-weight: bold;
    font-size: 16px;
    cursor: pointer;
    margin-bottom: 16px;
}

.generate-btn:disabled {
    background: #808080;
    border-color: #A0A0A0 #606060 #606060 #A0A0A0;
    cursor: not-allowed;
}

.loading-section {
    text-align: center;
    margin-bottom: 16px;
}

.loading-bar {
    width: 100%;
    height: 20px;
    background: white;
    border: 2px solid;
    border-color: #404040 #DFDFDF #DFDFDF #404040;
    margin-bottom: 8px;
    position: relative;
    overflow: hidden;
}

.loading-progress {
    height: 100%;
    background: linear-gradient(45deg, #0000FF, #00FFFF);
    width: 0%;
    transition: width 0.3s;
}

.loading-text {
    font-size: 12px;
    color: #404040;
}

.suggestions {
    margin-top: 16px;
}

.suggestion-title {
    font-size: 12px;
    color: #404040;
    margin-bottom: 8px;
}

.suggestion-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.suggestion {
    padding: 6px 10px;
    background: #E0E0E0;
    border: 1px solid #808080;
    border-radius: 12px;
    font-size: 11px;
    cursor: pointer;
}

.suggestion:active {
    background: #D0D0D0;
}

/* Mobile Navigation Bar */
.mobile-nav {
    display: flex;
    background: #C0C0C0;
    border-top: 2px solid;
    border-color: #DFDFDF #404040 #404040 #DFDFDF;
    padding: 8px;
    gap: 8px;
    safe-area-inset-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
    flex: 1;
    height: 48px;
    background: #C0C0C0;
    border: 2px solid;
    border-color: #DFDFDF #404040 #404040 #DFDFDF;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
}

.nav-btn.generate-nav {
    background: #008000;
    color: white;
    border-color: #00C000 #004000 #004000 #00C000;
}

.nav-btn:active {
    transform: scale(0.95);
    background: #A0A0A0;
}

.nav-btn.generate-nav:active {
    background: #006000;
}

/* Gesture Hints */
.gesture-hints {
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 8px 16px;
    border-radius: 16px;
    font-size: 12px;
    z-index: 1000;
    transition: opacity 2s;
}

/* About Dialog */
.about-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.dialog-content {
    background: #C0C0C0;
    border: 2px solid;
    border-color: #DFDFDF #404040 #404040 #DFDFDF;
    padding: 20px;
    margin: 20px;
    max-width: 300px;
    text-align: center;
}

.dialog-title {
    font-weight: bold;
    margin-bottom: 16px;
    font-size: 16px;
}

.dialog-text {
    margin-bottom: 20px;
    font-size: 14px;
    line-height: 1.4;
}

.dialog-btn {
    padding: 10px 20px;
    border: 2px solid;
    border-color: #DFDFDF #404040 #404040 #DFDFDF;
    background: #C0C0C0;
    font-size: 14px;
    cursor: pointer;
}

/* Responsive adjustments */
@media (max-width: 320px) {
    .ai-content {
        padding: 16px;
    }
    
    .preset-buttons {
        grid-template-columns: 1fr;
    }
    
    .tool-strip {
        gap: 4px;
        padding: 0 12px;
    }
    
    .tool-btn, .brush-size-btn {
        min-width: 44px;
        height: 44px;
    }
}

@media (max-height: 600px) {
    .ai-panel.open {
        top: 0;
        height: 100vh;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    body {
        background: #404040;
    }
    
    .mobile-app {
        background: #404040;
    }
    
    .mobile-header, .slide-menu, .tool-palette, .pattern-drawer, .ai-panel, .mobile-nav {
        background: #404040;
        color: #FFFFFF;
    }
    
    .menu-title {
        background: #606060;
    }
    
    .menu-button, .tool-btn, .brush-size-btn, .pattern-toggle, .nav-btn {
        background: #404040;
        border-color: #606060 #202020 #202020 #606060;
        color: #FFFFFF;
    }
    
    .menu-button:active, .tool-btn.active, .brush-size-btn.active {
        background: #606060;
        border-color: #202020 #606060 #606060 #202020;
    }
}

/* Performance optimizations */
.canvas-wrapper {
    will-change: transform;
}

.tool-btn, .nav-btn {
    will-change: transform;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .tool-btn, .nav-btn, .menu-button {
        border-width: 3px;
    }
}