:root {
    --primary-dark: #2E3440;
    --secondary-dark: #3B4252;
    --tertiary-dark: #434C5E;
    --light-gray: #D8DEE9;
    --accent-blue: #88C0D0;
    --paper-texture: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'%3E%3Cg fill-opacity='0.03'%3E%3Cpolygon fill='%23000' points='50 0 60 40 100 50 60 60 50 100 40 60 0 50 40 40'/%3E%3C/g%3E%3C/svg%3E");
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--light-gray);
    background-image: var(--paper-texture);
    color: var(--primary-dark);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Header Styles */
.header {
    background: var(--primary-dark);
    color: white;
    padding: 1rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.nav {
    display: flex;
    gap: 0.5rem;
}

.nav-btn {
    background: var(--accent-blue);
    border: none;
    color: white;
    padding: 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1rem;
}

.nav-btn:hover {
    background: #7bb3c7;
    transform: translateY(-2px);
}

/* Main Container */
.main-container {
    display: grid;
    grid-template-columns: 300px 1fr;
    min-height: calc(100vh - 80px);
    gap: 1rem;
    padding: 1rem;
    max-width: 1400px;
    margin: 0 auto;
}

/* Toolbar Styles */
.toolbar {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    height: fit-content;
    position: sticky;
    top: 100px;
    transition: opacity 0.3s ease;
}

.toolbar.hidden {
    opacity: 0.3;
}

.tool-group {
    margin-bottom: 2rem;
}

.tool-group h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--secondary-dark);
    font-weight: 600;
}

.tools {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.tool-btn {
    background: var(--light-gray);
    border: 2px solid transparent;
    padding: 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1.2rem;
    color: var(--primary-dark);
}

.tool-btn:hover {
    background: var(--accent-blue);
    color: white;
    transform: translateY(-2px);
}

.tool-btn.active {
    background: var(--primary-dark);
    color: white;
    border-color: var(--accent-blue);
}

.color-picker {
    width: 100%;
    height: 50px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 1rem;
}

.color-presets {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5rem;
}

.color-preset {
    width: 40px;
    height: 40px;
    border: 2px solid white;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.color-preset:hover {
    transform: scale(1.1);
}

.size-slider {
    width: 100%;
    margin-bottom: 0.5rem;
}

#sizeDisplay {
    font-weight: 600;
    color: var(--accent-blue);
}

/* Layers */
.layers-container {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 1rem;
}

.layer-item {
    background: var(--light-gray);
    padding: 0.75rem;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.layer-item.active {
    background: var(--accent-blue);
    color: white;
}

.opacity-slider {
    width: 60px;
}

.add-layer-btn {
    width: 100%;
    background: var(--secondary-dark);
    color: white;
    border: none;
    padding: 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.3s ease;
}

.add-layer-btn:hover {
    background: var(--primary-dark);
}

/* History */
.history-controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.history-controls button {
    flex: 1;
    background: var(--light-gray);
    border: none;
    padding: 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.history-controls button:hover {
    background: var(--accent-blue);
    color: white;
}

.history-timeline {
    height: 60px;
    background: var(--light-gray);
    border-radius: 6px;
    padding: 0.5rem;
    overflow-x: auto;
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.history-step {
    width: 8px;
    height: 40px;
    background: var(--secondary-dark);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.history-step.current {
    background: var(--accent-blue);
    height: 50px;
}

.history-step:hover {
    background: var(--primary-dark);
}

/* Canvas Container */
.canvas-container {
    background: white;
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    position: relative;
    overflow: hidden;
}

#drawingCanvas {
    display: block;
    border: 2px solid var(--light-gray);
    border-radius: 8px;
    cursor: crosshair;
    width: 100%;
    height: auto;
    max-height: 70vh;
    touch-action: none;
}

/* Custom Cursors */
#drawingCanvas.pencil-cursor {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z'/%3E%3C/svg%3E") 2 22, auto;
}

#drawingCanvas.brush-cursor {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M7 14c-1.66 0-3 1.34-3 3 0 1.31-1.16 2-2 2 .92 1.22 2.49 2 4 2 2.21 0 4-1.79 4-4 0-1.66-1.34-3-3-3zm13.71-9.37l-1.34-1.34c-.39-.39-1.02-.39-1.41 0L9 12.25 11.75 15l8.96-8.96c.39-.39.39-1.02 0-1.41z'/%3E%3C/svg%3E") 2 22, auto;
}

#drawingCanvas.eraser-cursor {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M16.24 3.56l4.95 4.94c.78.79.78 2.05 0 2.84L12 20.53a4.008 4.008 0 0 1-5.66 0L2.81 17c-.78-.79-.78-2.05 0-2.84l10.6-10.6c.79-.78 2.05-.78 2.83 0zm-4.95 4.95c-.59-.59-1.54-.59-2.12 0L5.93 12.75c-.59.59-.59 1.54 0 2.12l3.54 3.54c.59.59 1.54.59 2.12 0l3.54-3.54c.59-.59.59-1.54 0-2.12L11.29 8.51z'/%3E%3C/svg%3E") 12 12, auto;
}

.canvas-controls {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    display: flex;
    gap: 0.5rem;
}

.canvas-control-btn {
    background: var(--primary-dark);
    color: white;
    border: none;
    padding: 0.75rem;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.canvas-control-btn:hover {
    background: var(--accent-blue);
    transform: scale(1.1);
}

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

.gallery-modal.active,
.export-modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    border-bottom: 2px solid var(--light-gray);
    padding-bottom: 1rem;
}

.close-btn {
    background: var(--primary-dark);
    color: white;
    border: none;
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.gallery-item {
    background: var(--light-gray);
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.gallery-item:hover {
    transform: translateY(-4px);
}

.gallery-item img {
    width: 100%;
    height: 150px;
    object-fit: cover;
    border-radius: 6px;
    margin-bottom: 0.5rem;
}

.export-options,
.share-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.export-btn,
.share-btn {
    background: var(--accent-blue);
    color: white;
    border: none;
    padding: 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1rem;
}

.export-btn:hover,
.share-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

/* FAQ Section */
.faq-section {
    grid-column: 1 / -1;
    background: white;
    border-radius: 12px;
    padding: 2rem;
    margin-top: 2rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.faq-section h2 {
    color: var(--primary-dark);
    margin-bottom: 2rem;
    text-align: center;
}

.faq-item {
    border-bottom: 1px solid var(--light-gray);
    margin-bottom: 1rem;
}

.faq-question {
    width: 100%;
    background: none;
    border: none;
    padding: 1.5rem 0;
    text-align: left;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-dark);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: color 0.3s ease;
}

.faq-question:hover {
    color: var(--accent-blue);
}

.faq-icon {
    font-size: 1.5rem;
    transition: transform 0.3s ease;
}

.faq-question[aria-expanded="true"] .faq-icon {
    transform: rotate(45deg);
}

.faq-answer {
    padding: 0 0 1.5rem 0;
    color: var(--secondary-dark);
    line-height: 1.6;
    animation: fadeIn 0.3s ease;
}

.faq-answer[hidden] {
    display: none;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Footer */
footer {
    background: var(--primary-dark);
    color: white;
    text-align: center;
    padding: 2rem;
    margin-top: 3rem;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 1rem;
    }
    
    .header h1 {
        font-size: 1.2rem;
    }
    
    .main-container {
        grid-template-columns: 1fr;
        padding: 0.5rem;
        gap: 0.5rem;
    }
    
    .toolbar {
        position: static;
        padding: 1rem;
    }
    
    .tools {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .nav {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .nav-btn {
        padding: 0.5rem;
        font-size: 0.9rem;
    }
    
    .modal-content {
        padding: 1rem;
        margin: 1rem;
    }
    
    .export-options,
    .share-options {
        grid-template-columns: 1fr;
    }
    
    #drawingCanvas {
        max-height: 50vh;
    }
    
    .canvas-controls {
        bottom: 0.5rem;
        right: 0.5rem;
    }
    
    .canvas-control-btn {
        width: 40px;
        height: 40px;
        padding: 0.5rem;
    }
}

@media (max-width: 480px) {
    .color-presets {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .tools {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .history-controls {
        flex-direction: column;
    }
    
    .faq-question {
        font-size: 1rem;
        padding: 1rem 0;
    }
}

/* 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) {
    :root {
        --primary-dark: #000000;
        --secondary-dark: #333333;
        --light-gray: #ffffff;
        --accent-blue: #0066cc;
    }
}

/* Focus styles for accessibility */
button:focus,
input:focus,
.tool-btn:focus {
    outline: 3px solid var(--accent-blue);
    outline-offset: 2px;
}
